fix(station-g3): expose FEM gain preferences

This commit is contained in:
agessaman
2026-08-06 15:29:14 -07:00
parent 623422694b
commit 23066573e5
12 changed files with 198 additions and 44 deletions
@@ -0,0 +1,69 @@
#include "LoRaFEMControl.h"
#include <Arduino.h>
#include <driver/rtc_io.h>
void LoRaFEMControl::init() {
#ifdef P_PA1_EN
rtc_gpio_hold_dis((gpio_num_t)P_PA1_EN);
pinMode(P_PA1_EN, OUTPUT);
setPAGainEnable(pa_gain_enabled);
#endif
#ifdef P_PRIMARY_LNA_EN
rtc_gpio_hold_dis((gpio_num_t)P_PRIMARY_LNA_EN);
pinMode(P_PRIMARY_LNA_EN, OUTPUT);
setRxModeEnable();
#endif
}
void LoRaFEMControl::setSleepModeEnable() {
#ifdef P_PA1_EN
// PA PL1 low/open selects the lower of the two hardware-jumper-selected levels.
digitalWrite(P_PA1_EN, !P_PA1_EN_ACTIVE);
#endif
#ifdef P_PRIMARY_LNA_EN
// Preserve the existing Station G3 power-off state.
digitalWrite(P_PRIMARY_LNA_EN, P_PRIMARY_LNA_EN_ACTIVE);
#endif
}
void LoRaFEMControl::setTxModeEnable() {
#ifdef P_PRIMARY_LNA_EN
digitalWrite(P_PRIMARY_LNA_EN, !P_PRIMARY_LNA_EN_ACTIVE);
#endif
}
void LoRaFEMControl::setRxModeEnable() {
#ifdef P_PRIMARY_LNA_EN
digitalWrite(P_PRIMARY_LNA_EN, lna_enabled ? P_PRIMARY_LNA_EN_ACTIVE : !P_PRIMARY_LNA_EN_ACTIVE);
#endif
}
void LoRaFEMControl::setLNAEnable(bool enabled) {
lna_enabled = enabled;
setRxModeEnable();
}
void LoRaFEMControl::setPAGainEnable(bool enabled) {
pa_gain_enabled = enabled;
#ifdef P_PA1_EN
digitalWrite(P_PA1_EN, enabled ? P_PA1_EN_ACTIVE : !P_PA1_EN_ACTIVE);
#endif
}
bool LoRaFEMControl::canControlLNA() const {
#ifdef P_PRIMARY_LNA_EN
return true;
#else
return false;
#endif
}
bool LoRaFEMControl::canControlPAGain() const {
#ifdef P_PA1_EN
return true;
#else
return false;
#endif
}
@@ -0,0 +1,20 @@
#pragma once
class LoRaFEMControl {
public:
void init();
void setSleepModeEnable();
void setTxModeEnable();
void setRxModeEnable();
void setLNAEnable(bool enabled);
void setPAGainEnable(bool enabled);
bool canControlLNA() const;
bool canControlPAGain() const;
bool isLNAEnabled() const { return lna_enabled; }
bool isPAGainEnabled() const { return pa_gain_enabled; }
private:
bool lna_enabled = true;
bool pa_gain_enabled = false;
};
+33 -2
View File
@@ -1,15 +1,46 @@
#include "StationG3Board.h"
void StationG3Board::powerOff() {
loRaFEMControl.setSleepModeEnable();
#ifdef P_PA1_EN
setPAModeHigh(false);
rtc_gpio_hold_en((gpio_num_t)P_PA1_EN);
#endif
#ifdef P_PRIMARY_LNA_EN
setPrimaryLNAControl(true);
rtc_gpio_hold_en((gpio_num_t)P_PRIMARY_LNA_EN);
#endif
ESP32Board::powerOff();
}
bool StationG3Board::setLoRaFemLnaEnabled(bool enable) {
if (!loRaFEMControl.canControlLNA()) {
return false;
}
loRaFEMControl.setLNAEnable(enable);
return true;
}
bool StationG3Board::canControlLoRaFemLna() const {
return loRaFEMControl.canControlLNA();
}
bool StationG3Board::isLoRaFemLnaEnabled() const {
return loRaFEMControl.isLNAEnabled();
}
bool StationG3Board::setLoRaFemPaGainEnabled(bool enable) {
if (!loRaFEMControl.canControlPAGain()) {
return false;
}
loRaFEMControl.setPAGainEnable(enable);
return true;
}
bool StationG3Board::canControlLoRaFemPaGain() const {
return loRaFEMControl.canControlPAGain();
}
bool StationG3Board::isLoRaFemPaGainEnabled() const {
return loRaFEMControl.isPAGainEnabled();
}
+15 -38
View File
@@ -3,45 +3,15 @@
#include <Arduino.h>
#include <helpers/ESP32Board.h>
#include <driver/rtc_io.h>
#ifndef P_PRIMARY_LNA_EN_ACTIVE
#define P_PRIMARY_LNA_EN_ACTIVE LOW
#endif
#ifndef P_PA1_EN_ACTIVE
#define P_PA1_EN_ACTIVE HIGH
#endif
#include "LoRaFEMControl.h"
class StationG3Board : public ESP32Board {
void setPAModeHigh(bool enabled) {
#ifdef P_PA1_EN
// Station G3 PA PL1 mode: LOW/open is PA low, HIGH/short is PA high.
digitalWrite(P_PA1_EN, enabled ? P_PA1_EN_ACTIVE : !P_PA1_EN_ACTIVE);
#endif
}
void setPrimaryLNAControl(bool enabled) {
#ifdef P_PRIMARY_LNA_EN
// Station G3 primary LNA mode is active-low: LOW/open is LNA on, HIGH/short is LNA off.
digitalWrite(P_PRIMARY_LNA_EN, enabled ? P_PRIMARY_LNA_EN_ACTIVE : !P_PRIMARY_LNA_EN_ACTIVE);
#endif
}
public:
LoRaFEMControl loRaFEMControl;
void begin() {
ESP32Board::begin();
#ifdef P_PA1_EN
rtc_gpio_hold_dis((gpio_num_t)P_PA1_EN);
pinMode(P_PA1_EN, OUTPUT);
setPAModeHigh(false);
#endif
#ifdef P_PRIMARY_LNA_EN
rtc_gpio_hold_dis((gpio_num_t)P_PRIMARY_LNA_EN);
pinMode(P_PRIMARY_LNA_EN, OUTPUT);
setPrimaryLNAControl(true);
#endif
loRaFEMControl.init();
esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
@@ -56,23 +26,30 @@ public:
}
void setPrimaryLNAEnable(bool enabled) {
setPrimaryLNAControl(enabled);
loRaFEMControl.setLNAEnable(enabled);
}
void setPrimaryPAHighPower(bool enabled) {
setPAModeHigh(enabled);
loRaFEMControl.setPAGainEnable(enabled);
}
void onBeforeTransmit() override {
ESP32Board::onBeforeTransmit();
setPrimaryLNAControl(false);
loRaFEMControl.setTxModeEnable();
}
void onAfterTransmit() override {
ESP32Board::onAfterTransmit();
setPrimaryLNAControl(true);
loRaFEMControl.setRxModeEnable();
}
bool setLoRaFemLnaEnabled(bool enable) override;
bool canControlLoRaFemLna() const override;
bool isLoRaFemLnaEnabled() const override;
bool setLoRaFemPaGainEnabled(bool enable) override;
bool canControlLoRaFemPaGain() const override;
bool isLoRaFemPaGainEnabled() const override;
void powerOff() override;
uint16_t getBattMilliVolts() override {
+2 -2
View File
@@ -17,11 +17,11 @@ build_flags =
-D P_LORA_SCLK=12
-D P_LORA_MISO=14
-D P_LORA_MOSI=13
-D P_PA1_EN=9 ; PA PL1 Mode: LOW/open is PA low, HIGH/short is PA high.
-D P_PA1_EN=9 ; PA PL1 Mode: LOW/open selects low level, HIGH/short selects high level.
-D P_PA1_EN_ACTIVE=HIGH
-D P_PRIMARY_LNA_EN=10 ; Primary Slot LNA Mode: LOW/open is LNA on, HIGH/short is LNA off.
-D P_PRIMARY_LNA_EN_ACTIVE=LOW
-D LORA_TX_POWER=7 ; configured as 7dbm, because the final output will be ~27dbm (~0.5w) if the PA is enabled.
-D LORA_TX_POWER=7 ; SX1262 input power to the Station G3 PA; final output depends on PA PL1/PL2 level.
-D MAX_LORA_TX_POWER=22
; -D P_LORA_TX_LED=35
-D PIN_BOARD_SDA=5