Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions drivers/lora/loramac_node/sx126x.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ RadioOperatingModes_t SX126xGetOperatingMode(void)
return dev_data.mode;
}

#if HAVE_GPIO_FE_CTRL
static const enum {
RFO_LP,
RFO_HP,
} pa_output = DT_INST_STRING_UPPER_TOKEN(0, power_amplifier_output);
#endif

#define LORA_NODE DT_NODELABEL(lora)


Expand Down Expand Up @@ -324,7 +317,7 @@ void SX126xSetOperatingMode(RadioOperatingModes_t mode)
sx126x_set_tx_enable(1);
#endif
#if HAVE_GPIO_FE_CTRL
if (pa_output == RFO_LP) {
if (sx126x_get_tx_power_mode() == RFO_LP) {
sx126x_set_fe_ctrl(txlp_fe_ctrl_lines[0], txlp_fe_ctrl_lines[1], txlp_fe_ctrl_lines[2]);
} else {
sx126x_set_fe_ctrl(txhp_fe_ctrl_lines[0], txhp_fe_ctrl_lines[1], txhp_fe_ctrl_lines[2]);
Expand Down
8 changes: 8 additions & 0 deletions drivers/lora/loramac_node/sx126x_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define HAVE_GPIO_TX_ENABLE DT_INST_NODE_HAS_PROP(0, tx_enable_gpios)
#define HAVE_GPIO_RX_ENABLE DT_INST_NODE_HAS_PROP(0, rx_enable_gpios)
#define HAVE_GPIO_FE_CTRL (DT_INST_NODE_HAS_PROP(0, fe_ctrl1_enable_gpios) && !DT_INST_NODE_HAS_PROP(0, tx_enable_gpios))
#define HAVE_PA_OUTPUT_LOCKED DT_INST_NODE_HAS_PROP(0, power_amplifier_output)

struct sx126x_config {
struct spi_dt_spec bus;
Expand Down Expand Up @@ -74,6 +75,13 @@ void sx126x_dio1_irq_disable(struct sx126x_data *dev_data);

void sx126x_set_tx_params(int8_t power, RadioRampTimes_t ramp_time);

enum sx126x_pa_output {
RFO_LP,
RFO_HP,
};

enum sx126x_pa_output sx126x_get_tx_power_mode(void);

int sx126x_variant_init(const struct device *dev);

#endif /* ZEPHYR_DRIVERS_SX126X_COMMON_H_ */
31 changes: 27 additions & 4 deletions drivers/lora/loramac_node/sx126x_stm32wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
#include <zephyr/irq.h>
LOG_MODULE_DECLARE(sx126x, CONFIG_LORA_LOG_LEVEL);

static const enum {
RFO_LP,
RFO_HP,
} pa_output = DT_INST_STRING_UPPER_TOKEN(0, power_amplifier_output);
#if HAVE_PA_OUTPUT_LOCKED
static enum sx126x_pa_output pa_output =
DT_INST_STRING_UPPER_TOKEN(0, power_amplifier_output);
static const bool pa_output_locked = true;
#else
static enum sx126x_pa_output pa_output = RFO_LP;
static const bool pa_output_locked = false;

Check failure on line 25 in drivers/lora/loramac_node/sx126x_stm32wl.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

INITIALISED_STATIC

drivers/lora/loramac_node/sx126x_stm32wl.c:25 do not initialise statics to false
#endif

void sx126x_reset(struct sx126x_data *dev_data)
{
Expand Down Expand Up @@ -53,6 +57,18 @@
void sx126x_set_tx_params(int8_t power, RadioRampTimes_t ramp_time)
{
uint8_t buf[2];
const int8_t lp_max = DT_INST_PROP(0, rfo_lp_max_power);

if (!pa_output_locked) {
/* Auto-select PA output based on requested power level */
if (power > lp_max) {
pa_output = RFO_HP;
} else {
pa_output = RFO_LP;
}
}

LOG_DBG("tx_params PA mode: %s", pa_output == RFO_LP ? "RFO_LP" : "RFO_HP");

if (pa_output == RFO_LP) {
const int8_t max_power = DT_INST_PROP(0, rfo_lp_max_power);
Expand Down Expand Up @@ -110,6 +126,8 @@
SX126xWriteRegister(REG_OCP, 0x38);
}

LOG_DBG("tx_params final: reg_power=%d ramp=%u", power, ramp_time);

buf[0] = power;
buf[1] = (uint8_t)ramp_time;
SX126xWriteCommand(RADIO_SET_TXPARAMS, buf, 2);
Expand All @@ -123,6 +141,11 @@
k_work_submit(&dev_data->dio1_irq_work);
}

enum sx126x_pa_output sx126x_get_tx_power_mode(void)
{
return pa_output;
}

int sx126x_variant_init(const struct device *dev)
{
IRQ_CONNECT(DT_INST_IRQN(0),
Expand Down
1 change: 0 additions & 1 deletion dts/bindings/lora/st,stm32wl-subghz-radio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ properties:

power-amplifier-output:
type: string
required: true
description: |
Selects between the low- and high-power power amplifier output pin.
enum:
Expand Down
Loading