Skip to content

Commit da8f36a

Browse files
Wio sx1262 support
1 parent 892265b commit da8f36a

6 files changed

Lines changed: 54 additions & 3 deletions

File tree

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_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 {

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: 20 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,24 @@ func (d *Device) SetDioIrqParams(irqMask, dio1Mask, dio2Mask, dio3Mask uint16) {
309310
d.ExecSetCommand(SX126X_CMD_SET_DIO_IRQ_PARAMS, p[:])
310311
}
311312

313+
func (d *Device) SetDio2AsRfSwitchCtrl(enable bool) {
314+
var p [1]uint8
315+
if enable {
316+
p[0] = 0x01
317+
}
318+
d.ExecSetCommand(SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, p[:])
319+
}
320+
321+
func (d *Device) SetDio3AsTcxoCtrl(voltage uint8, timeout uint32) {
322+
var p [5]uint8
323+
p[0] = voltage
324+
p[1] = uint8((timeout >> 24) & 0xFF)
325+
p[2] = uint8((timeout >> 16) & 0xFF)
326+
p[3] = uint8((timeout >> 8) & 0xFF)
327+
p[4] = uint8((timeout >> 0) & 0xFF)
328+
d.ExecSetCommand(SX126X_CMD_SET_DIO3_AS_TCXO_CTRL, p[:])
329+
}
330+
312331
// GetIrqStatus returns IRQ status
313332
func (d *Device) GetIrqStatus() (irqStatus uint16) {
314333
r := d.ExecGetCommand(SX126X_CMD_GET_IRQ_STATUS, 2)

0 commit comments

Comments
 (0)