tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/lora/lorawan/common/stm32wlx.go (about) 1 //go:build stm32wlx 2 3 package common 4 5 import ( 6 "machine" 7 8 "tinygo.org/x/drivers/lora" 9 "tinygo.org/x/drivers/sx126x" 10 ) 11 12 const ( 13 FREQ = 868100000 14 LORA_DEFAULT_RXTIMEOUT_MS = 1000 15 LORA_DEFAULT_TXTIMEOUT_MS = 5000 16 ) 17 18 var ( 19 loraRadio *sx126x.Device 20 ) 21 22 var spi = machine.SPI3 23 24 func newRadioControl() sx126x.RadioController { 25 return sx126x.NewRadioControl() 26 } 27 28 // do sx126x setup here 29 func SetupLora() (lora.Radio, error) { 30 loraRadio = sx126x.New(spi) 31 loraRadio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262) 32 33 // Create radio controller for target 34 loraRadio.SetRadioController(newRadioControl()) 35 36 if state := loraRadio.DetectDevice(); !state { 37 return nil, errRadioNotFound 38 } 39 40 return loraRadio, nil 41 } 42 43 func FirmwareVersion() string { 44 return "sx126x" 45 } 46 47 func Lorarx() ([]byte, error) { 48 return loraRadio.Rx(LORA_DEFAULT_RXTIMEOUT_MS) 49 }