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

driver/sx126x : Add set_rf_mode interface

This commit is contained in:
Akshai M 2021-07-07 13:38:23 +02:00
parent 8870a885cb
commit 17ad0fc5a7
3 changed files with 46 additions and 3 deletions

View File

@ -34,6 +34,20 @@
extern "C" {
#endif
/**
* * @note Forward declaration of the SX126x device descriptor
*/
typedef struct sx126x sx126x_t;
/**
* @brief RF switch states
*/
typedef enum {
SX126X_RF_MODE_RX,
SX126X_RF_MODE_TX_LPA,
SX126X_RF_MODE_TX_HPA,
} sx126x_rf_mode_t;
/**
* @brief Whether there's only one variant of this driver at compile time or
* not.
@ -76,12 +90,18 @@ typedef struct {
gpio_t dio1_pin; /**< Dio1 pin */
sx126x_reg_mod_t regulator; /**< Power regulator mode */
sx126x_type_t type; /**< Variant of sx126x */
#if IS_USED(MODULE_SX126X_RF_SWITCH)
/**
* @ brief Interface to set RF switch parameters
*/
void(*set_rf_mode)(sx126x_t *dev, sx126x_rf_mode_t rf_mode);
#endif
} sx126x_params_t;
/**
* @brief Device descriptor for the driver
*/
typedef struct {
struct sx126x {
netdev_t netdev; /**< Netdev parent struct */
sx126x_params_t *params; /**< Initialization parameters */
sx126x_pkt_params_lora_t pkt_params; /**< Lora packet parameters */
@ -89,7 +109,7 @@ typedef struct {
uint32_t channel; /**< Current channel frequency (in Hz) */
uint8_t rx_timeout; /**< Rx Timeout in terms of symbols */
bool radio_sleep; /**< Radio sleep status */
} sx126x_t;
};
/**
* @brief Setup the radio device

View File

@ -57,6 +57,10 @@ extern "C" {
#define SX126X_PARAM_REGULATOR SX126X_REG_MODE_DCDC
#endif
#ifndef SX126X_PARAM_SET_RF_MODE_CB
#define SX126X_PARAM_SET_RF_MODE_CB NULL
#endif
#ifndef SX126X_PARAM_TYPE
# if IS_USED(MODULE_SX1261)
# define SX126X_PARAM_TYPE SX126X_TYPE_SX1261
@ -73,13 +77,21 @@ extern "C" {
# endif
#endif
#if IS_USED(MODULE_SX126X_RF_SWITCH)
#define SX126X_SET_RF_MODE .set_rf_mode = SX126X_PARAM_SET_RF_MODE_CB
#else
#define SX126X_SET_RF_MODE
#endif
#define SX126X_PARAMS { .spi = SX126X_PARAM_SPI, \
.nss_pin = SX126X_PARAM_SPI_NSS, \
.reset_pin = SX126X_PARAM_RESET, \
.busy_pin = SX126X_PARAM_BUSY, \
.dio1_pin = SX126X_PARAM_DIO1, \
.type = SX126X_PARAM_TYPE, \
.regulator = SX126X_PARAM_REGULATOR }
.regulator = SX126X_PARAM_REGULATOR, \
SX126X_SET_RF_MODE }
/**@}*/
/**

View File

@ -311,6 +311,12 @@ static int _set_state(sx126x_t *dev, netopt_state_t state)
case NETOPT_STATE_IDLE:
case NETOPT_STATE_RX:
DEBUG("[sx126x] netdev: set NETOPT_STATE_RX state\n");
#if IS_USED(MODULE_SX126X_RF_SWITCH)
/* Refer Section 4.2 RF Switch in Application Note (AN5406) */
if (dev->params->set_rf_mode) {
dev->params->set_rf_mode(dev, SX126X_RF_MODE_RX);
}
#endif
sx126x_cfg_rx_boosted(dev, true);
int _timeout = (sx126x_symbol_to_msec(dev, dev->rx_timeout));
if (_timeout != 0) {
@ -323,6 +329,11 @@ static int _set_state(sx126x_t *dev, netopt_state_t state)
case NETOPT_STATE_TX:
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);
}
#endif
sx126x_set_tx(dev, 0);
break;