mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-19 06:03:57 +00:00
sx126x: refactor to RadioController interface to more easily handle non-STM32WL boards and remove duplicated code
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
rfswitch "tinygo.org/x/drivers/examples/sx126x/rfswitch"
|
||||
|
||||
"tinygo.org/x/drivers/lora"
|
||||
"tinygo.org/x/drivers/sx126x"
|
||||
)
|
||||
@@ -24,12 +22,11 @@ func main() {
|
||||
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
|
||||
// Create the driver
|
||||
loraRadio = sx126x.New(machine.SPI3)
|
||||
loraRadio = sx126x.New(spi)
|
||||
loraRadio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
|
||||
|
||||
// Create RF Switch
|
||||
var radioSwitch rfswitch.CustomSwitch
|
||||
loraRadio.SetRfSwitch(radioSwitch)
|
||||
// Create radio controller for target
|
||||
loraRadio.SetRadioController(newRadioControl())
|
||||
|
||||
state := loraRadio.DetectDevice()
|
||||
if !state {
|
||||
@@ -76,6 +73,5 @@ func main() {
|
||||
|
||||
loraRadio.SetStandby()
|
||||
time.Sleep(60 * time.Second)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//go:build !stm32wlx
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/sx126x"
|
||||
)
|
||||
|
||||
var (
|
||||
spi = machine.SPI0
|
||||
nssPin, busyPin, dio0Pin, dio1Pin = machine.GP17, machine.GP20, machine.GP11, machine.GP10
|
||||
rxPin, txLowPin, txHighPin = machine.GP13, machine.GP12, machine.GP12
|
||||
)
|
||||
|
||||
func newRadioControl() sx126x.RadioController {
|
||||
return sx126x.NewRadioControl(nssPin, busyPin, dio0Pin, dio1Pin, rxPin, txLowPin, txHighPin)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//go:build stm32wlx
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/sx126x"
|
||||
)
|
||||
|
||||
var spi = machine.SPI3
|
||||
|
||||
func newRadioControl() sx126x.RadioController {
|
||||
return sx126x.NewRadioControl()
|
||||
}
|
||||
Reference in New Issue
Block a user