1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/sx126x: add tx_pa_mode

BOARDs with RF switch might only support one of the TX modes, and
on init the BOARD needs to be configured accordingly and the correct
mode selected on TX.
This commit is contained in:
Francisco Molina 2021-11-04 21:54:40 +01:00
parent 70744a7a92
commit e17e3254e1
4 changed files with 29 additions and 14 deletions

View File

@ -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;

View File

@ -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}
/**@}*/

View File

@ -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);

View File

@ -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);