Skip to content

Commit cf7d95c

Browse files
authored
Merge pull request #1509 from stevenlafl/tbeam-1w
Add LilyGO T-Beam 1W Support
2 parents e60fb14 + a9a8299 commit cf7d95c

10 files changed

Lines changed: 588 additions & 4 deletions

File tree

boards/t_beam_1w.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "esp32s3_out.ld",
5+
"memory_type": "qio_opi"
6+
},
7+
"core": "esp32",
8+
"extra_flags": [
9+
"-DBOARD_HAS_PSRAM",
10+
"-DLILYGO_TBEAM_1W",
11+
"-DARDUINO_USB_CDC_ON_BOOT=1",
12+
"-DARDUINO_USB_MODE=0",
13+
"-DARDUINO_RUNNING_CORE=1",
14+
"-DARDUINO_EVENT_RUNNING_CORE=1"
15+
],
16+
"f_cpu": "240000000L",
17+
"f_flash": "80000000L",
18+
"flash_mode": "qio",
19+
"psram_type": "opi",
20+
"hwids": [
21+
[
22+
"0x303A",
23+
"0x1001"
24+
]
25+
],
26+
"mcu": "esp32s3",
27+
"variant": "lilygo_tbeam_1w"
28+
},
29+
"connectivity": [
30+
"wifi",
31+
"bluetooth",
32+
"lora"
33+
],
34+
"debug": {
35+
"openocd_target": "esp32s3.cfg"
36+
},
37+
"frameworks": [
38+
"arduino"
39+
],
40+
"name": "LilyGo TBeam-1W",
41+
"upload": {
42+
"flash_size": "16MB",
43+
"maximum_ram_size": 327680,
44+
"maximum_size": 16777216,
45+
"require_upload_port": true,
46+
"speed": 921600
47+
},
48+
"url": "http://www.lilygo.cn/",
49+
"vendor": "LilyGo"
50+
}

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,14 @@ class HomeScreen : public UIScreen {
103103

104104
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
105105
// Convert millivolts to percentage
106-
const int minMilliVolts = 3000; // Minimum voltage (e.g., 3.0V)
107-
const int maxMilliVolts = 4200; // Maximum voltage (e.g., 4.2V)
106+
#ifndef BATT_MIN_MILLIVOLTS
107+
#define BATT_MIN_MILLIVOLTS 3000
108+
#endif
109+
#ifndef BATT_MAX_MILLIVOLTS
110+
#define BATT_MAX_MILLIVOLTS 4200
111+
#endif
112+
const int minMilliVolts = BATT_MIN_MILLIVOLTS;
113+
const int maxMilliVolts = BATT_MAX_MILLIVOLTS;
108114
int batteryPercentage = ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts);
109115
if (batteryPercentage < 0) batteryPercentage = 0; // Clamp to 0%
110116
if (batteryPercentage > 100) batteryPercentage = 100; // Clamp to 100%

examples/companion_radio/ui-orig/UITask.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
149149

150150
void UITask::renderBatteryIndicator(uint16_t batteryMilliVolts) {
151151
// Convert millivolts to percentage
152-
const int minMilliVolts = 3000; // Minimum voltage (e.g., 3.0V)
153-
const int maxMilliVolts = 4200; // Maximum voltage (e.g., 4.2V)
152+
#ifndef BATT_MIN_MILLIVOLTS
153+
#define BATT_MIN_MILLIVOLTS 3000
154+
#endif
155+
#ifndef BATT_MAX_MILLIVOLTS
156+
#define BATT_MAX_MILLIVOLTS 4200
157+
#endif
158+
const int minMilliVolts = BATT_MIN_MILLIVOLTS;
159+
const int maxMilliVolts = BATT_MAX_MILLIVOLTS;
154160
int batteryPercentage = ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts);
155161
if (batteryPercentage < 0) batteryPercentage = 0; // Clamp to 0%
156162
if (batteryPercentage > 100) batteryPercentage = 100; // Clamp to 100%
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "TBeam1WBoard.h"
2+
3+
void TBeam1WBoard::begin() {
4+
ESP32Board::begin();
5+
6+
// Power on radio module (must be done before radio init)
7+
pinMode(SX126X_POWER_EN, OUTPUT);
8+
digitalWrite(SX126X_POWER_EN, HIGH);
9+
radio_powered = true;
10+
delay(10); // Allow radio to power up
11+
12+
// RF switch RXEN pin handled by RadioLib via setRfSwitchPins()
13+
14+
// Initialize LED
15+
pinMode(LED_PIN, OUTPUT);
16+
digitalWrite(LED_PIN, LOW);
17+
18+
// Initialize fan control (on by default - 1W PA can overheat)
19+
pinMode(FAN_CTRL_PIN, OUTPUT);
20+
digitalWrite(FAN_CTRL_PIN, HIGH);
21+
}
22+
23+
void TBeam1WBoard::onBeforeTransmit() {
24+
// RF switching handled by RadioLib via SX126X_DIO2_AS_RF_SWITCH and setRfSwitchPins()
25+
digitalWrite(LED_PIN, HIGH); // TX LED on
26+
}
27+
28+
void TBeam1WBoard::onAfterTransmit() {
29+
digitalWrite(LED_PIN, LOW); // TX LED off
30+
}
31+
32+
uint16_t TBeam1WBoard::getBattMilliVolts() {
33+
// T-Beam 1W uses 7.4V battery with voltage divider
34+
// ADC reads through divider - adjust multiplier based on actual divider ratio
35+
analogReadResolution(12);
36+
uint32_t raw = 0;
37+
for (int i = 0; i < 8; i++) {
38+
raw += analogRead(BATTERY_PIN);
39+
}
40+
raw = raw / 8;
41+
// Assuming voltage divider ratio from ADC_MULTIPLIER
42+
// 3.3V reference, 12-bit ADC (4095 max)
43+
return static_cast<uint16_t>((raw * 3300 * ADC_MULTIPLIER) / 4095);
44+
}
45+
46+
const char* TBeam1WBoard::getManufacturerName() const {
47+
return "LilyGo T-Beam 1W";
48+
}
49+
50+
void TBeam1WBoard::powerOff() {
51+
// Turn off radio LNA (CTRL pin must be LOW when not receiving)
52+
digitalWrite(SX126X_RXEN, LOW);
53+
54+
// Turn off radio power
55+
digitalWrite(SX126X_POWER_EN, LOW);
56+
radio_powered = false;
57+
58+
// Turn off LED and fan
59+
digitalWrite(LED_PIN, LOW);
60+
digitalWrite(FAN_CTRL_PIN, LOW);
61+
62+
ESP32Board::powerOff();
63+
}
64+
65+
void TBeam1WBoard::setFanEnabled(bool enabled) {
66+
digitalWrite(FAN_CTRL_PIN, enabled ? HIGH : LOW);
67+
}
68+
69+
bool TBeam1WBoard::isFanEnabled() const {
70+
return digitalRead(FAN_CTRL_PIN) == HIGH;
71+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
#include <helpers/ESP32Board.h>
5+
#include "variant.h"
6+
7+
// LilyGo T-Beam 1W with SX1262 + external PA (XY16P35 module)
8+
//
9+
// Power architecture (LDO is separate chip on T-Beam board, not inside XY16P35):
10+
//
11+
// VCC (+4.0~+8.0V) ──┬──────────────────► XY16P35 VCC pin 5 (PA direct)
12+
// (USB or Battery) │
13+
// │ ┌───────────┐
14+
// └──►│ LDO Chip │──► +3.3V ──► XY16P35 (SX1262 + LNA)
15+
// │ EN=GPIO40 │
16+
// └───────────┘
17+
// LDO_EN (GPIO 40): H @ +1.2V~VIN, active high, not floating
18+
//
19+
// Control signals:
20+
// - LDO_EN (GPIO 40): HIGH enables LDO → powers SX1262 + LNA
21+
// - TCXO_EN (DIO3): HIGH enables TCXO (set to 1.8V per Meshtastic)
22+
// - CTL (GPIO 21): HIGH=RX (LNA on), LOW=TX (LNA off)
23+
// - DIO2: AUTO via SX126X_DIO2_AS_RF_SWITCH (TX path)
24+
//
25+
// Power notes:
26+
// - PA needs VCC 4.0-8.0V for full 32dBm output
27+
// - USB-C (3.9-6V) marginal; 7.4V battery recommended
28+
// - Battery must support 2A+ discharge for high-power TX
29+
30+
class TBeam1WBoard : public ESP32Board {
31+
private:
32+
bool radio_powered = false;
33+
34+
public:
35+
void begin();
36+
void onBeforeTransmit() override;
37+
void onAfterTransmit() override;
38+
uint16_t getBattMilliVolts() override;
39+
const char* getManufacturerName() const override;
40+
void powerOff() override;
41+
42+
// Fan control methods
43+
void setFanEnabled(bool enabled);
44+
bool isFanEnabled() const;
45+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
6+
#define USB_VID 0x303a
7+
#define USB_PID 0x1001
8+
9+
// Serial (USB CDC)
10+
static const uint8_t TX = 43;
11+
static const uint8_t RX = 44;
12+
13+
// I2C for OLED and sensors
14+
static const uint8_t SDA = 8;
15+
static const uint8_t SCL = 9;
16+
17+
// Default SPI mapped to Radio/SD
18+
static const uint8_t SS = 15; // LoRa CS
19+
static const uint8_t MOSI = 11;
20+
static const uint8_t MISO = 12;
21+
static const uint8_t SCK = 13;
22+
23+
// SD Card CS
24+
#define SDCARD_CS 10
25+
26+
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)