@@ -54,9 +54,10 @@ type Device struct {
5454}
5555
5656// New creates a new SX126x connection.
57- func New (spi drivers.SPI ) * Device {
57+ func New (spi drivers.SPI , rstPin machine. Pin ) * Device {
5858 return & Device {
5959 spi : spi ,
60+ rstPin : rstPin ,
6061 radioEventChan : make (chan lora.RadioEvent , RADIOEVENTCHAN_SIZE ),
6162 spiTxBuf : make ([]byte , SPI_BUFFER_SIZE ),
6263 spiRxBuf : make ([]byte , SPI_BUFFER_SIZE ),
@@ -309,6 +310,29 @@ func (d *Device) SetDioIrqParams(irqMask, dio1Mask, dio2Mask, dio3Mask uint16) {
309310 d .ExecSetCommand (SX126X_CMD_SET_DIO_IRQ_PARAMS , p [:])
310311}
311312
313+ // SetDio2AsRfSwitchCtrl configures if DIO2 is used to control an external RF switch.
314+ // When controlling the external RX switch, the pin DIO2 will toggle according to
315+ // the internal state machine (DIO2 = 0 in SLEEP, STDBY_RX, STDBY_XOSC, FS and RX modes,
316+ // DIO2 = 1 in TX mode). Otherwise DIO2 is free to be used as an IRQ.
317+ func (d * Device ) SetDio2AsRfSwitchCtrl (enable bool ) {
318+ var p [1 ]uint8
319+ if enable {
320+ p [0 ] = 0x01
321+ }
322+ d .ExecSetCommand (SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL , p [:])
323+ }
324+
325+ // SetDio3AsTcxoCtrl configures the DIO3 as an external TCXO voltage reference.
326+ func (d * Device ) SetDio3AsTcxoCtrl (voltage uint8 , timeout uint32 ) {
327+ var p [5 ]uint8
328+ p [0 ] = voltage
329+ p [1 ] = uint8 ((timeout >> 24 ) & 0xFF )
330+ p [2 ] = uint8 ((timeout >> 16 ) & 0xFF )
331+ p [3 ] = uint8 ((timeout >> 8 ) & 0xFF )
332+ p [4 ] = uint8 ((timeout >> 0 ) & 0xFF )
333+ d .ExecSetCommand (SX126X_CMD_SET_DIO3_AS_TCXO_CTRL , p [:])
334+ }
335+
312336// GetIrqStatus returns IRQ status
313337func (d * Device ) GetIrqStatus () (irqStatus uint16 ) {
314338 r := d .ExecGetCommand (SX126X_CMD_GET_IRQ_STATUS , 2 )
0 commit comments