mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-18 13:43:58 +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:
@@ -1,13 +1,9 @@
|
||||
//go:build gnse || lorae5 || nucleowl55jc
|
||||
//go:build !stm32wlx && sx126x
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"device/stm32"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
|
||||
rfswitch "tinygo.org/x/drivers/examples/sx126x/rfswitch"
|
||||
|
||||
"tinygo.org/x/drivers/lora"
|
||||
"tinygo.org/x/drivers/sx126x"
|
||||
@@ -23,23 +19,28 @@ var (
|
||||
loraRadio *sx126x.Device
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// do sx126x setup here
|
||||
func SetupLora() (lora.Radio, error) {
|
||||
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())
|
||||
|
||||
if state := loraRadio.DetectDevice(); !state {
|
||||
return nil, errRadioNotFound
|
||||
}
|
||||
|
||||
// Add interrupt handler for Radio IRQs
|
||||
intr := interrupt.New(stm32.IRQ_Radio_IRQ_Busy, radioIntHandler)
|
||||
intr.Enable()
|
||||
|
||||
loraConf := lora.Config{
|
||||
Freq: FREQ,
|
||||
Bw: lora.Bandwidth_500_0,
|
||||
@@ -59,11 +60,6 @@ func SetupLora() (lora.Radio, error) {
|
||||
return loraRadio, nil
|
||||
}
|
||||
|
||||
// radioIntHandler will take care of radio interrupts
|
||||
func radioIntHandler(intr interrupt.Interrupt) {
|
||||
loraRadio.HandleInterrupt()
|
||||
}
|
||||
|
||||
func FirmwareVersion() string {
|
||||
return "sx126x"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user