mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-06 16:03:41 +00:00
8b3075fdba
Signed-off-by: deadprogram <ron@hybridgroup.com>
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
//go:build gnse
|
|
|
|
/*
|
|
Generic Node Sensor Edition
|
|
RFSwitch
|
|
|
|
Disable Switch : PB8=OFF PA0=OFF PA1=OFF
|
|
Enable RX : PB8=ON PA0=ON PA1=OFF
|
|
Enable TX RFO LP : PB8=ON PA0=ON PA1=ON
|
|
Enable TX RFO HP : PB8=ON PA0=OFF PA1=ON
|
|
*/
|
|
package rfswitch
|
|
|
|
import (
|
|
"machine"
|
|
|
|
"tinygo.org/x/drivers/sx126x"
|
|
)
|
|
|
|
type CustomSwitch struct {
|
|
}
|
|
|
|
var (
|
|
rfstate int
|
|
)
|
|
|
|
func (s CustomSwitch) InitRFSwitch() {
|
|
machine.RF_FE_CTRL1.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
machine.RF_FE_CTRL2.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
machine.RF_FE_CTRL3.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
rfstate = -1 //Unknown
|
|
}
|
|
|
|
func (s CustomSwitch) SetRfSwitchMode(mode int) error {
|
|
if mode == rfstate {
|
|
return nil
|
|
}
|
|
|
|
switch mode {
|
|
|
|
case sx126x.RFSWITCH_TX_HP:
|
|
machine.RF_FE_CTRL1.Set(false)
|
|
machine.RF_FE_CTRL2.Set(true)
|
|
machine.RF_FE_CTRL3.Set(true)
|
|
|
|
case sx126x.RFSWITCH_TX_LP:
|
|
machine.RF_FE_CTRL1.Set(true)
|
|
machine.RF_FE_CTRL2.Set(true)
|
|
machine.RF_FE_CTRL3.Set(true)
|
|
|
|
case sx126x.RFSWITCH_RX:
|
|
machine.RF_FE_CTRL1.Set(true)
|
|
machine.RF_FE_CTRL2.Set(false)
|
|
machine.RF_FE_CTRL3.Set(true)
|
|
}
|
|
|
|
rfstate = mode
|
|
|
|
return nil
|
|
}
|