tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/sx126x/radiocontrol_gnse.go (about)

     1  //go:build gnse
     2  
     3  /*
     4  Generic Node Sensor Edition
     5  RFSwitch
     6  
     7  Disable Switch   :  PB8=OFF PA0=OFF  PA1=OFF
     8  Enable RX        :  PB8=ON  PA0=ON   PA1=OFF
     9  Enable TX RFO LP :  PB8=ON  PA0=ON   PA1=ON
    10  Enable TX RFO HP :  PB8=ON  PA0=OFF  PA1=ON
    11  */
    12  package sx126x
    13  
    14  import (
    15  	"machine"
    16  )
    17  
    18  // RadioControl for GNSE board.
    19  type RadioControl struct {
    20  	STM32RadioControl
    21  }
    22  
    23  func NewRadioControl() *RadioControl {
    24  	return &RadioControl{STM32RadioControl{}}
    25  }
    26  
    27  // Init pins needed for controlling rx/tx
    28  func (rc *RadioControl) Init() error {
    29  	machine.PA0.Configure(machine.PinConfig{Mode: machine.PinOutput})
    30  	machine.PA1.Configure(machine.PinConfig{Mode: machine.PinOutput})
    31  	machine.PB8.Configure(machine.PinConfig{Mode: machine.PinOutput})
    32  
    33  	return nil
    34  }
    35  
    36  func (rc *RadioControl) SetRfSwitchMode(mode int) error {
    37  	switch mode {
    38  
    39  	case RFSWITCH_TX_HP:
    40  		machine.PA0.Set(false)
    41  		machine.PA1.Set(true)
    42  		machine.PB8.Set(true)
    43  
    44  	case RFSWITCH_TX_LP:
    45  		machine.PA0.Set(true)
    46  		machine.PA1.Set(true)
    47  		machine.PB8.Set(true)
    48  
    49  	case RFSWITCH_RX:
    50  		machine.PA0.Set(true)
    51  		machine.PA1.Set(false)
    52  		machine.PB8.Set(true)
    53  	}
    54  
    55  	return nil
    56  }