Skip to content

Commit f6019de

Browse files
Wio sx1262 support
1 parent 892265b commit f6019de

9 files changed

Lines changed: 72 additions & 7 deletions

File tree

examples/lora/lorawan/common/stm32wlx.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ var (
1919
loraRadio *sx126x.Device
2020
)
2121

22-
var spi = machine.SPI3
22+
var (
23+
spi = machine.SPI3
24+
rstPin = machine.NoPin
25+
)
2326

2427
func newRadioControl() sx126x.RadioController {
2528
return sx126x.NewRadioControl()
2629
}
2730

2831
// do sx126x setup here
2932
func SetupLora() (lora.Radio, error) {
30-
loraRadio = sx126x.New(spi)
33+
loraRadio = sx126x.New(spi, rstPin)
3134
loraRadio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
3235

3336
// Create radio controller for target

examples/sx126x/lora_continuous/lora_continuous.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ const FREQ = 868100000
1313

1414
var (
1515
loraRadio *sx126x.Device
16+
rstPin = machine.GP10
1617
)
1718

1819
func main() {
1920
println("\n# TinyGo Lora continuous Wave/Preamble test")
2021
println("# -----------------------------------------")
2122

2223
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
24+
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
2325

2426
// Create the driver
25-
loraRadio = sx126x.New(spi)
27+
loraRadio = sx126x.New(spi, rstPin)
2628
loraRadio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
2729

2830
// Create radio controller for target

examples/sx126x/lora_continuous/radio.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var (
1212
spi = machine.SPI0
1313
nssPin, busyPin, dio1Pin = machine.GP17, machine.GP10, machine.GP11
1414
rxPin, txLowPin, txHighPin = machine.GP13, machine.GP12, machine.GP12
15+
rstPin = machine.GP10
1516
)
1617

1718
func newRadioControl() sx126x.RadioController {

examples/sx126x/lora_continuous/radio_stm32wl.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
"tinygo.org/x/drivers/sx126x"
99
)
1010

11-
var spi = machine.SPI3
11+
var (
12+
spi = machine.SPI3
13+
rstPin = machine.NoPin
14+
)
1215

1316
func newRadioControl() sx126x.RadioController {
1417
return sx126x.NewRadioControl()

examples/sx126x/lora_rxtx/lora_rxtx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ func main() {
2727
println("\n# TinyGo Lora RX/TX test")
2828
println("# ----------------------")
2929
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
30+
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
3031

3132
// Create the driver
32-
loraRadio = sx126x.New(spi)
33+
loraRadio = sx126x.New(spi, rstPin)
3334
loraRadio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
3435

3536
// Create radio controller for target

examples/sx126x/lora_rxtx/radio.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var (
1212
spi = machine.SPI1
1313
nssPin, busyPin, dio1Pin = machine.GP13, machine.GP6, machine.GP7
1414
rxPin, txLowPin, txHighPin = machine.GP9, machine.GP8, machine.GP8
15+
rstPin = machine.GP10
1516
)
1617

1718
func newRadioControl() sx126x.RadioController {

examples/sx126x/lora_rxtx/radio_stm32wl.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
"tinygo.org/x/drivers/sx126x"
99
)
1010

11-
var spi = machine.SPI3
11+
var (
12+
spi = machine.SPI3
13+
rstPin = machine.NoPin
14+
)
1215

1316
func newRadioControl() sx126x.RadioController {
1417
return sx126x.NewRadioControl()

sx126x/radiocontrol_wio_sx1262.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build wio_sx1262
2+
3+
package sx126x
4+
5+
import (
6+
"machine"
7+
)
8+
9+
// NewRadioControlWio creates RadioControl configured for wio1262 module.
10+
// The board has RF_SW pin which controls RX/TX, but providing it is not required
11+
// if SetDio2AsRfSwitchCtrl is set to true (use machine.NoPin instead).
12+
// Additionally, the board requires following settings on initalization:
13+
/*
14+
radio.SetDio3AsTcxoCtrl(sx126x.SX126X_DIO3_OUTPUT_1_8, 500)
15+
radio.SetRegulatorMode(sx126x.SX126X_REGULATOR_DC_DC)
16+
radio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
17+
*/
18+
func NewRadioControlWio(nssPin, busyPin, dio1Pin, rfSw machine.Pin) *RadioControl {
19+
return &RadioControl{
20+
nssPin: nssPin,
21+
busyPin: busyPin,
22+
dio1Pin: dio1Pin,
23+
rxPin: rfSw,
24+
txLowPin: machine.NoPin,
25+
txHighPin: machine.NoPin,
26+
}
27+
}

sx126x/sx126x.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
313337
func (d *Device) GetIrqStatus() (irqStatus uint16) {
314338
r := d.ExecGetCommand(SX126X_CMD_GET_IRQ_STATUS, 2)

0 commit comments

Comments
 (0)