Add T-Beam 1W external LNA control
This commit is contained in:
1 parent
759a35fc4f
commit
366f6ab73d
5 files changed
+106
-2
No files matched your search
@@ -156,6 +156,45 @@ class CustomSX1262 : public SX1262 {
|
||||
return _rx_ps_rf_rx_disabled;
|
||||
}
|
||||
|
||||
// Select whether a host-controlled RXEN pin is asserted in receive mode.
|
||||
// Some FEM modules (notably the LilyGo T-Beam 1W XY16P35) expose their
|
||||
// external LNA supply on RXEN while DIO2 independently selects the RF
|
||||
// switch. Swapping RadioLib's table keeps the requested state intact
|
||||
// across RX, CAD, TX, standby, and duty-cycle transitions; a one-shot
|
||||
// digitalWrite() would be overwritten on the next mode change.
|
||||
bool setExternalRxLnaEnabled(bool enabled) {
|
||||
#if defined(SX126X_RXEN)
|
||||
#if defined(SX126X_TXEN)
|
||||
static constexpr uint32_t tx_en = SX126X_TXEN;
|
||||
#else
|
||||
static constexpr uint32_t tx_en = RADIOLIB_NC;
|
||||
#endif
|
||||
|
||||
static const uint32_t pins[Module::RFSWITCH_MAX_PINS] = {
|
||||
SX126X_RXEN, tx_en, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC,
|
||||
};
|
||||
static const Module::RfSwitchMode_t lna_enabled_table[] = {
|
||||
{ Module::MODE_IDLE, { LOW, LOW } },
|
||||
{ Module::MODE_RX, { HIGH, LOW } },
|
||||
{ Module::MODE_TX, { LOW, HIGH } },
|
||||
END_OF_MODE_TABLE,
|
||||
};
|
||||
static const Module::RfSwitchMode_t lna_disabled_table[] = {
|
||||
{ Module::MODE_IDLE, { LOW, LOW } },
|
||||
{ Module::MODE_RX, { LOW, LOW } },
|
||||
{ Module::MODE_TX, { LOW, HIGH } },
|
||||
END_OF_MODE_TABLE,
|
||||
};
|
||||
|
||||
this->mod->setRfSwitchTable(
|
||||
pins, enabled ? lna_enabled_table : lna_disabled_table);
|
||||
return true;
|
||||
#else
|
||||
(void)enabled;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// BUSY high means the chip is asleep (RX duty-cycle sleep window) or mid
|
||||
// command; any SPI access would stall until the chip's next listen window.
|
||||
bool isChipBusy() {
|
||||
|
||||
@@ -78,6 +78,25 @@ public:
|
||||
return ((CustomSX1262 *)_radio)->isRxPowerSavingRfRxDisabled();
|
||||
}
|
||||
|
||||
// Reconfigure through the normal bounded radio transition so RXEN is never
|
||||
// asserted while a transmission or unread packet owns the radio. The
|
||||
// selected table is then honored by every RadioLib mode transition.
|
||||
bool setExternalRxLnaEnabled(bool enabled) {
|
||||
#if defined(SX126X_RXEN)
|
||||
if (SX126X_RXEN == RADIOLIB_NC) return false;
|
||||
|
||||
uint8_t resume_rx = beginReconfigure();
|
||||
if (resume_rx > 1) return false;
|
||||
|
||||
bool success = ((CustomSX1262 *)_radio)->setExternalRxLnaEnabled(enabled);
|
||||
endReconfigure(resume_rx);
|
||||
return success;
|
||||
#else
|
||||
(void)enabled;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
int startReceiveMode() override {
|
||||
if (_rx_ps_armed) {
|
||||
@@ -118,7 +137,16 @@ protected:
|
||||
bool radioDeepInit() override {
|
||||
// std_init() re-runs RadioLib begin(), which starts with a hardware reset
|
||||
// via NRST - the only way out of a hard-locked chip (BUSY stuck high).
|
||||
return ((CustomSX1262 *)_radio)->std_init();
|
||||
bool success = ((CustomSX1262 *)_radio)->std_init();
|
||||
#if defined(TBEAM_1W)
|
||||
// std_init() restores RadioLib's default RXEN table. Reapply the T-Beam
|
||||
// 1W's persisted external-LNA selection before receive mode is re-armed.
|
||||
if (success && _board->canControlLoRaFemLna()) {
|
||||
success = ((CustomSX1262 *)_radio)->setExternalRxLnaEnabled(
|
||||
_board->isLoRaFemLnaEnabled());
|
||||
}
|
||||
#endif
|
||||
return success;
|
||||
}
|
||||
bool supportsRadioDeepInit() const override { return true; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user