@@ -50,8 +50,15 @@ static const struct sx126x_config dev_config = {
5050#if HAVE_GPIO_RX_ENABLE
5151 .rx_enable = GPIO_DT_SPEC_INST_GET (0 , rx_enable_gpios ),
5252#endif
53+ #if HAVE_GPIO_FE_CTRL
54+ .fe_ctrl1_enable = GPIO_DT_SPEC_INST_GET (0 , fe_ctrl1_enable_gpios ),
55+ .fe_ctrl2_enable = GPIO_DT_SPEC_INST_GET (0 , fe_ctrl2_enable_gpios ),
56+ .fe_ctrl3_enable = GPIO_DT_SPEC_INST_GET (0 , fe_ctrl3_enable_gpios ),
57+ #endif
58+
5359};
5460
61+
5562static struct sx126x_data dev_data ;
5663
5764void SX126xWaitOnBusy (void );
@@ -253,29 +260,57 @@ void SX126xAntSwOff(void)
253260#endif
254261}
255262
263+ #if HAVE_GPIO_TX_ENABLE
256264static void sx126x_set_tx_enable (int value )
257265{
258- #if HAVE_GPIO_TX_ENABLE
259266 gpio_pin_set_dt (& dev_config .tx_enable , value );
260- #endif
261267}
268+ #endif
262269
270+ #if HAVE_GPIO_RX_ENABLE
263271static void sx126x_set_rx_enable (int value )
264272{
265- #if HAVE_GPIO_RX_ENABLE
266273 gpio_pin_set_dt (& dev_config .rx_enable , value );
274+ }
275+ #endif
276+
277+
278+ static void sx126x_set_fe_ctrl (int ctrl1 , int ctrl2 , int ctrl3 )
279+ {
280+ #if HAVE_GPIO_FE_CTRL
281+ gpio_pin_set_dt (& dev_config .fe_ctrl1_enable , ctrl1 );
282+ gpio_pin_set_dt (& dev_config .fe_ctrl2_enable , ctrl2 );
283+ gpio_pin_set_dt (& dev_config .fe_ctrl3_enable , ctrl3 );
267284#endif
268285}
269286
287+
270288RadioOperatingModes_t SX126xGetOperatingMode (void )
271289{
272290 return dev_data .mode ;
273291}
274292
293+ #if HAVE_GPIO_FE_CTRL
294+ static const enum {
295+ RFO_LP ,
296+ RFO_HP ,
297+ } pa_output = DT_INST_STRING_UPPER_TOKEN (0 , power_amplifier_output );
298+ #endif
299+
300+ #define LORA_NODE DT_NODELABEL(lora)
301+
302+
275303void SX126xSetOperatingMode (RadioOperatingModes_t mode )
276304{
277305 LOG_DBG ("SetOperatingMode: %s (%i)" , sx126x_mode_name (mode ), mode );
278306
307+ #if HAVE_GPIO_FE_CTRL
308+ const int off_fe_ctrl_lines [] = DT_PROP (LORA_NODE , off_fe_ctrl_lines );
309+ const int rx_fe_ctrl_lines [] = DT_PROP (LORA_NODE , rx_fe_ctrl_lines );
310+ const int txhp_fe_ctrl_lines [] = DT_PROP (LORA_NODE , txhp_fe_ctrl_lines );
311+ const int txlp_fe_ctrl_lines [] = DT_PROP (LORA_NODE , txlp_fe_ctrl_lines );
312+ #endif
313+
279314 dev_data .mode = mode ;
280315
281316 /* To avoid inadvertently putting the RF switch in an
@@ -284,24 +319,43 @@ void SX126xSetOperatingMode(RadioOperatingModes_t mode)
284319 */
285320 switch (mode ) {
286321 case MODE_TX :
322+ #if HAVE_GPIO_TX_ENABLE
287323 sx126x_set_rx_enable (0 );
288324 sx126x_set_tx_enable (1 );
325+ #endif
326+ #if HAVE_GPIO_FE_CTRL
327+ if (pa_output == RFO_LP ) {
328+ sx126x_set_fe_ctrl (txlp_fe_ctrl_lines [0 ], txlp_fe_ctrl_lines [1 ], txlp_fe_ctrl_lines [2 ]);
329+ } else {
330+ sx126x_set_fe_ctrl (txhp_fe_ctrl_lines [0 ], txhp_fe_ctrl_lines [1 ], txhp_fe_ctrl_lines [2 ]);
331+ }
332+ #endif
289333 break ;
290334
291335 case MODE_RX :
292336 case MODE_RX_DC :
293337 case MODE_CAD :
338+ #if HAVE_GPIO_TX_ENABLE
294339 sx126x_set_tx_enable (0 );
295340 sx126x_set_rx_enable (1 );
341+ #endif
342+ #if HAVE_GPIO_FE_CTRL
343+ sx126x_set_fe_ctrl (rx_fe_ctrl_lines [0 ], rx_fe_ctrl_lines [1 ], rx_fe_ctrl_lines [2 ]);
344+ #endif
296345 break ;
297346
298347 case MODE_SLEEP :
299348 /* Additionally disable the DIO1 interrupt to save power */
300349 sx126x_dio1_irq_disable (& dev_data );
301350 __fallthrough ;
302351 default :
352+ #if HAVE_GPIO_TX_ENABLE
303353 sx126x_set_rx_enable (0 );
304354 sx126x_set_tx_enable (0 );
355+ #endif
356+ #if HAVE_GPIO_FE_CTRL
357+ sx126x_set_fe_ctrl (off_fe_ctrl_lines [0 ], off_fe_ctrl_lines [1 ], off_fe_ctrl_lines [2 ]);
358+ #endif
305359 break ;
306360 }
307361}
@@ -437,7 +491,14 @@ static int sx126x_lora_init(const struct device *dev)
437491
438492 if (sx12xx_configure_pin (antenna_enable , GPIO_OUTPUT_INACTIVE ) ||
439493 sx12xx_configure_pin (rx_enable , GPIO_OUTPUT_INACTIVE ) ||
440- sx12xx_configure_pin (tx_enable , GPIO_OUTPUT_INACTIVE )) {
494+ sx12xx_configure_pin (tx_enable , GPIO_OUTPUT_INACTIVE )
495+ #if HAVE_GPIO_FE_CTRL
496+ || sx12xx_configure_pin (fe_ctrl1_enable , GPIO_OUTPUT_INACTIVE )
497+ || sx12xx_configure_pin (fe_ctrl2_enable , GPIO_OUTPUT_INACTIVE )
498+ || sx12xx_configure_pin (fe_ctrl3_enable , GPIO_OUTPUT_INACTIVE )
499+ #endif
500+ )
501+ {
441502 return - EIO ;
442503 }
443504
0 commit comments