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

     1  //go:build nucleowl55jc
     2  
     3  /*
     4  Nucleo WL55JC1
     5  RFSwitch
     6  
     7  +-----------+---------+------------+------------+
     8  |           | FE_CTRL1 |  FE_CTRL2 |   FE_CTRL3 |
     9  |           |   (PC4)  |   (PC5)   |     (PC3)  |
    10  +-----------+----------+-----------+------------+
    11  |  TX_HP    |   LOW    |   HIGH    |    HIGH    |
    12  |  TX_LP    |   HIGH   |   HIGH    |    HIGH    |
    13  |  RX       |   HIGH   |   LOW     |    HIGH    |
    14  +-----------+----------+-----------+------------+
    15  */
    16  package sx126x
    17  
    18  import (
    19  	"machine"
    20  )
    21  
    22  // RadioControl for Nucleo WL55JC1 board.
    23  type RadioControl struct {
    24  	STM32RadioControl
    25  }
    26  
    27  func NewRadioControl() *RadioControl {
    28  	return &RadioControl{STM32RadioControl{}}
    29  }
    30  
    31  // Init pins needed for controlling rx/tx
    32  func (rc *RadioControl) Init() error {
    33  	machine.PC4.Configure(machine.PinConfig{Mode: machine.PinOutput})
    34  	machine.PC5.Configure(machine.PinConfig{Mode: machine.PinOutput})
    35  	machine.PC3.Configure(machine.PinConfig{Mode: machine.PinOutput})
    36  
    37  	return nil
    38  }
    39  
    40  func (rc *RadioControl) SetRfSwitchMode(mode int) error {
    41  	switch mode {
    42  
    43  	case RFSWITCH_TX_HP:
    44  		machine.PC4.Set(false)
    45  		machine.PC5.Set(true)
    46  		machine.PC3.Set(true)
    47  
    48  	case RFSWITCH_TX_LP:
    49  		machine.PC4.Set(true)
    50  		machine.PC5.Set(true)
    51  		machine.PC3.Set(true)
    52  
    53  	case RFSWITCH_RX:
    54  		machine.PC4.Set(true)
    55  		machine.PC5.Set(false)
    56  		machine.PC3.Set(true)
    57  	}
    58  
    59  	return nil
    60  }