diff --git a/drivers/include/sx126x.h b/drivers/include/sx126x.h index 127c0f10bb..7968601b42 100644 --- a/drivers/include/sx126x.h +++ b/drivers/include/sx126x.h @@ -95,6 +95,7 @@ typedef struct { * @ brief Interface to set RF switch parameters */ void(*set_rf_mode)(sx126x_t *dev, sx126x_rf_mode_t rf_mode); + sx126x_rf_mode_t tx_pa_mode; /**< Power amplifier TX operating mode*/ #endif } sx126x_params_t; diff --git a/drivers/sx126x/include/sx126x_params.h b/drivers/sx126x/include/sx126x_params.h index bf40e87919..e0978d5dba 100644 --- a/drivers/sx126x/include/sx126x_params.h +++ b/drivers/sx126x/include/sx126x_params.h @@ -61,6 +61,10 @@ extern "C" { #define SX126X_PARAM_SET_RF_MODE_CB NULL #endif +#ifndef SX126X_PARAM_TX_PA_MODE +#define SX126X_PARAM_TX_PA_MODE SX126X_RF_MODE_TX_LPA +#endif + #ifndef SX126X_PARAM_TYPE # if IS_USED(MODULE_SX1261) # define SX126X_PARAM_TYPE SX126X_TYPE_SX1261 @@ -78,9 +82,11 @@ extern "C" { #endif #if IS_USED(MODULE_SX126X_RF_SWITCH) -#define SX126X_SET_RF_MODE .set_rf_mode = SX126X_PARAM_SET_RF_MODE_CB +#define SX126X_SET_RF_MODE .set_rf_mode = SX126X_PARAM_SET_RF_MODE_CB, +#define SX126X_TX_PA_MODE .tx_pa_mode = SX126X_PARAM_TX_PA_MODE #else #define SX126X_SET_RF_MODE +#define SX126X_TX_PA_MODE #endif #define SX126X_PARAMS { .spi = SX126X_PARAM_SPI, \ @@ -90,7 +96,8 @@ extern "C" { .dio1_pin = SX126X_PARAM_DIO1, \ .type = SX126X_PARAM_TYPE, \ .regulator = SX126X_PARAM_REGULATOR, \ - SX126X_SET_RF_MODE } + SX126X_SET_RF_MODE \ + SX126X_TX_PA_MODE} /**@}*/ diff --git a/drivers/sx126x/sx126x.c b/drivers/sx126x/sx126x.c index 9808f1666b..19f08fc21a 100644 --- a/drivers/sx126x/sx126x.c +++ b/drivers/sx126x/sx126x.c @@ -49,13 +49,6 @@ #define CONFIG_SX126X_RAMP_TIME_DEFAULT (SX126X_RAMP_10_US) #endif -const sx126x_pa_cfg_params_t sx1262_pa_cfg = { - .pa_duty_cycle = 0x02, - .hp_max = 0x02, - .device_sel = 0x00, - .pa_lut = 0x01 -}; - const sx126x_pa_cfg_params_t sx1268_pa_cfg = { .pa_duty_cycle = 0x04, .hp_max = 0x06, @@ -63,13 +56,20 @@ const sx126x_pa_cfg_params_t sx1268_pa_cfg = { .pa_lut = 0x01 }; -const sx126x_pa_cfg_params_t sx1261_pa_cfg = { +const sx126x_pa_cfg_params_t lpa_cfg = { .pa_duty_cycle = 0x04, .hp_max = 0x00, .device_sel = 0x01, .pa_lut = 0x01 }; +const sx126x_pa_cfg_params_t hpa_cfg = { + .pa_duty_cycle = 0x02, + .hp_max = 0x02, + .device_sel = 0x00, + .pa_lut = 0x01 +}; + void sx126x_setup(sx126x_t *dev, const sx126x_params_t *params, uint8_t index) { netdev_t *netdev = &dev->netdev; @@ -108,14 +108,21 @@ static void sx126x_init_default_config(sx126x_t *dev) * and are optimal for a TX output power of 14dBm. */ if (sx126x_is_llcc68(dev) || sx126x_is_sx1262(dev)) { - sx126x_set_pa_cfg(dev, &sx1262_pa_cfg); + sx126x_set_pa_cfg(dev, &hpa_cfg); } else if (sx126x_is_sx1268(dev)) { sx126x_set_pa_cfg(dev, &sx1268_pa_cfg); } - else { /* sx126x_is_sx1261(dev) or sx126x_is_stm32wl(dev) */ - sx126x_set_pa_cfg(dev, &sx1261_pa_cfg); + else if (sx126x_is_sx1261(dev)) { + sx126x_set_pa_cfg(dev, &lpa_cfg); } +#if IS_USED(MODULE_SX126X_RF_SWITCH) + if (dev->params->tx_pa_mode == SX126X_RF_MODE_TX_LPA){ + sx126x_set_pa_cfg(dev, &lpa_cfg); + } else { + sx126x_set_pa_cfg(dev, &hpa_cfg); + } +#endif sx126x_set_tx_params(dev, CONFIG_SX126X_TX_POWER_DEFAULT, CONFIG_SX126X_RAMP_TIME_DEFAULT); dev->mod_params.bw = (sx126x_lora_bw_t)(CONFIG_LORA_BW_DEFAULT + SX126X_LORA_BW_125); diff --git a/drivers/sx126x/sx126x_netdev.c b/drivers/sx126x/sx126x_netdev.c index 3fee95d5da..4d8ec8dc1a 100644 --- a/drivers/sx126x/sx126x_netdev.c +++ b/drivers/sx126x/sx126x_netdev.c @@ -333,7 +333,7 @@ static int _set_state(sx126x_t *dev, netopt_state_t state) DEBUG("[sx126x] netdev: set NETOPT_STATE_TX state\n"); #if IS_USED(MODULE_SX126X_RF_SWITCH) if (dev->params->set_rf_mode) { - dev->params->set_rf_mode(dev, SX126X_RF_MODE_TX_LPA); + dev->params->set_rf_mode(dev, dev->params->tx_pa_mode); } #endif sx126x_set_tx(dev, 0);