-
-
Notifications
You must be signed in to change notification settings - Fork 848
Fix: Lillygo Tbeam 1W Fan Control and LNA Sequencing improvements #2418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 4 commits
018bed7
be9f674
2933d9e
6977a1d
414b5dc
73f4731
3d226a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,4 +229,7 @@ void loop() { | |
| ui_task.loop(); | ||
| #endif | ||
| rtc_clock.tick(); | ||
| #ifdef P_FAN_CTRL | ||
| update_fan_control(); | ||
| #endif | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,4 +113,7 @@ void loop() { | |
| ui_task.loop(); | ||
| #endif | ||
| rtc_clock.tick(); | ||
| #ifdef P_FAN_CTRL | ||
| update_fan_control(); | ||
| #endif | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,30 +3,49 @@ | |
| void TBeam1WBoard::begin() { | ||
| ESP32Board::begin(); | ||
|
|
||
| // Power on radio module (must be done before radio init) | ||
| // Power on radio module (must be done before radio init). | ||
| // Drive LOW first to ensure a clean SX1262 reset — on soft reboot the ESP32 | ||
| // GPIO glitch may be too brief to drain module capacitors, leaving the SX1262 | ||
| // in a stuck state. Holding LOW for 50ms guarantees a full power cycle. | ||
| pinMode(SX126X_POWER_EN, OUTPUT); | ||
| digitalWrite(SX126X_POWER_EN, LOW); | ||
| delay(50); | ||
| digitalWrite(SX126X_POWER_EN, HIGH); | ||
| radio_powered = true; | ||
| delay(10); // Allow radio to power up | ||
|
|
||
| // RF switch RXEN pin handled by RadioLib via setRfSwitchPins() | ||
| // Explicitly drive RXEN HIGH (LNA on) from boot, before RadioLib takes over. | ||
| // Without this the pin floats until the first startReceive() call. | ||
| pinMode(SX126X_RXEN, OUTPUT); | ||
| digitalWrite(SX126X_RXEN, HIGH); | ||
|
|
||
| // Initialize LED | ||
| pinMode(LED_PIN, OUTPUT); | ||
| digitalWrite(LED_PIN, LOW); | ||
|
|
||
| // Initialize fan control (on by default - 1W PA can overheat) | ||
| // Fan starts off; onAfterTransmit() enables it with a 30s cooldown timer | ||
| pinMode(FAN_CTRL_PIN, OUTPUT); | ||
| digitalWrite(FAN_CTRL_PIN, HIGH); | ||
| digitalWrite(FAN_CTRL_PIN, LOW); | ||
| } | ||
|
|
||
| void TBeam1WBoard::onBeforeTransmit() { | ||
| // RF switching handled by RadioLib via SX126X_DIO2_AS_RF_SWITCH and setRfSwitchPins() | ||
| digitalWrite(LED_PIN, HIGH); // TX LED on | ||
| digitalWrite(SX126X_RXEN, LOW); // disconnect LNA before PA ramps up | ||
| digitalWrite(LED_PIN, HIGH); | ||
| } | ||
|
|
||
| void TBeam1WBoard::onAfterTransmit() { | ||
| digitalWrite(LED_PIN, LOW); // TX LED off | ||
| digitalWrite(SX126X_RXEN, HIGH); // re-enable LNA immediately after TX | ||
| digitalWrite(LED_PIN, LOW); | ||
| // Keep fan running for 10s after TX | ||
| setFanEnabled(true); | ||
| _fan_off_millis = millis() + 10000; | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ie. here make this the board's loop() method
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I did this. Would I also need to add a loop function to every variant?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I answered my own question. Added a new virtual loop to the mainboard class so other variants compile and adjusted the tbeam 1w to override.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| void TBeam1WBoard::updateFan() { | ||
| if (_fan_off_millis > 0 && (long)(millis() - _fan_off_millis) >= 0) { | ||
| setFanEnabled(false); | ||
| _fan_off_millis = 0; | ||
| } | ||
| } | ||
|
|
||
| uint16_t TBeam1WBoard::getBattMilliVolts() { | ||
|
|
@@ -68,4 +87,4 @@ void TBeam1WBoard::setFanEnabled(bool enabled) { | |
|
|
||
| bool TBeam1WBoard::isFanEnabled() const { | ||
| return digitalRead(FAN_CTRL_PIN) == HIGH; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is probably time to introduce a new virtual MainBoard::loop(), and a no-op as default.
And have the TBeam1WBoard class override, and put the updateFan() logic there