-
Notifications
You must be signed in to change notification settings - Fork 3
/
radio.go
40 lines (30 loc) · 887 Bytes
/
radio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"machine"
"errors"
"tinygo.org/x/drivers/lora"
"tinygo.org/x/drivers/sx126x"
)
var (
spi = machine.SPI1
nssPin, busyPin, dio1Pin = machine.GP13, machine.GP7, machine.GP6
rxPin, txLowPin, txHighPin = machine.GP9, machine.GP8, machine.GP8
loraRadio *sx126x.Device
)
// do sx126x setup here
func setupLora() (lora.Radio, error) {
spi.Configure(machine.SPIConfig{
Mode: 0,
Frequency: 8 * 1e6,
SDO: machine.SPI1_SDO_PIN,
SDI: machine.SPI1_SDI_PIN,
SCK: machine.SPI1_SCK_PIN,
})
loraRadio = sx126x.New(spi)
loraRadio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
loraRadio.SetRadioController(sx126x.NewRadioControl(nssPin, busyPin, dio1Pin, rxPin, txLowPin, txHighPin))
if state := loraRadio.DetectDevice(); !state {
return nil, errors.New("LoRa radio not found")
}
return loraRadio, nil
}