mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Add LilyGo T-Beam 1W SX1262 board support
Add variant definition, board JSON, and TBeamBoard integration for the LilyGo T-Beam 1W with SX1262 radio and 1W PA. Includes: - Board variant with pin mappings for SX1262, GPS, OLED, fan control - AXP2101 PMU power rail configuration for T-Beam 1W - ADC-based battery voltage fallback (2S Li-ion, 7.4V nominal) - Temperature-based fan control for 1W PA cooling - GPIO fallback for GPS power when PMU is not present - Companion BLE, Repeater, Room Server, and ESPNow Bridge environments Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
parent
be780491ac
commit
e531f2dc3a
6 changed files with 471 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_1W_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "TBeamBoard.h"
|
||||
|
|
@ -125,11 +125,19 @@ void TBeamBoard::printPMU()
|
|||
|
||||
bool TBeamBoard::power_init()
|
||||
{
|
||||
#if defined(TBEAM_SUPREME_SX1262)
|
||||
Wire1.begin(PIN_BOARD_SDA1, PIN_BOARD_SCL1);
|
||||
delay(10);
|
||||
#endif
|
||||
|
||||
delay(20); // Give I2C bus time to stabilize before PMU access
|
||||
|
||||
if (!PMU) {
|
||||
#ifdef TBEAM_SUPREME_SX1262
|
||||
PMU = new XPowersAXP2101(PMU_WIRE_PORT, PIN_BOARD_SDA1, PIN_BOARD_SCL1, I2C_PMU_ADD);
|
||||
#if defined(TBEAM_SUPREME_SX1262)
|
||||
PMU = new XPowersAXP2101(Wire1, PIN_BOARD_SDA1, PIN_BOARD_SCL1, I2C_PMU_ADD);
|
||||
#else
|
||||
PMU = new XPowersAXP2101(PMU_WIRE_PORT, PIN_BOARD_SDA, PIN_BOARD_SCL, I2C_PMU_ADD);
|
||||
MESH_DEBUG_PRINTLN("[PMU] Trying AXP2101...");
|
||||
PMU = new XPowersAXP2101(Wire, PIN_BOARD_SDA, PIN_BOARD_SCL, I2C_PMU_ADD);
|
||||
#endif
|
||||
if (!PMU->init()) {
|
||||
MESH_DEBUG_PRINTLN("Warning: Failed to find AXP2101 power management");
|
||||
|
|
@ -140,7 +148,12 @@ bool TBeamBoard::power_init()
|
|||
}
|
||||
}
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP192(PMU_WIRE_PORT, PIN_BOARD_SDA, PIN_BOARD_SCL, I2C_PMU_ADD);
|
||||
#if defined(TBEAM_SUPREME_SX1262)
|
||||
PMU = new XPowersAXP192(Wire1, PIN_BOARD_SDA1, PIN_BOARD_SCL1, I2C_PMU_ADD);
|
||||
#else
|
||||
MESH_DEBUG_PRINTLN("[PMU] Trying AXP192...");
|
||||
PMU = new XPowersAXP192(Wire, PIN_BOARD_SDA, PIN_BOARD_SCL, I2C_PMU_ADD);
|
||||
#endif
|
||||
if (!PMU->init()) {
|
||||
MESH_DEBUG_PRINTLN("Warning: Failed to find AXP192 power management");
|
||||
delete PMU;
|
||||
|
|
@ -151,6 +164,19 @@ bool TBeamBoard::power_init()
|
|||
}
|
||||
|
||||
if (!PMU) {
|
||||
// XPowersLib calls Wire.end() when PMU object is deleted
|
||||
// Need to re-initialize Wire for other I2C devices
|
||||
#if !defined(TBEAM_SUPREME_SX1262)
|
||||
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
|
||||
#endif
|
||||
|
||||
#if defined(TBEAM_1W_SX1262) && defined(PIN_GPS_EN)
|
||||
MESH_DEBUG_PRINTLN("PMU not found - using GPIO fallback for GPS power");
|
||||
pinMode(PIN_GPS_EN, OUTPUT);
|
||||
digitalWrite(PIN_GPS_EN, HIGH);
|
||||
delay(100);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -158,9 +184,11 @@ bool TBeamBoard::power_init()
|
|||
|
||||
PMU->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
|
||||
|
||||
// Set up PMU interrupts
|
||||
// Set up PMU interrupts (T-Beam 1W has no PMU IRQ pin)
|
||||
#ifndef TBEAM_1W_SX1262
|
||||
pinMode(PIN_PMU_IRQ, INPUT_PULLUP);
|
||||
attachInterrupt(PIN_PMU_IRQ, setPmuFlag, FALLING);
|
||||
#endif
|
||||
|
||||
if (PMU->getChipModel() == XPOWERS_AXP192) {
|
||||
|
||||
|
|
@ -234,6 +262,29 @@ bool TBeamBoard::power_init()
|
|||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
PMU->disablePowerOutput(XPOWERS_VBACKUP);
|
||||
#elif defined(TBEAM_1W_SX1262)
|
||||
// T-Beam 1W configuration
|
||||
// Note: T-Beam 1W uses 7.4V battery and external LDO for radio
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC3);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC4);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO2);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO2);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO1, 3300); // OLED and peripheral power
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
delay(50);
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); // GPS power
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_VBACKUP, 3300); // GPS RTC backup
|
||||
PMU->enablePowerOutput(XPOWERS_VBACKUP);
|
||||
#else
|
||||
//Turn off unused power rails
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_1W_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
|
||||
// Define pin mappings BEFORE including ESP32Board.h so sleep() can use P_LORA_DIO_1
|
||||
#ifdef TBEAM_SUPREME_SX1262
|
||||
|
|
@ -45,6 +45,41 @@
|
|||
#define RTC_WIRE_PORT Wire1
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_1W_SX1262
|
||||
// LoRa radio module pins for TBeam 1W with SX1262 and 1W PA
|
||||
#define P_LORA_DIO_0 -1 //NC
|
||||
#define P_LORA_DIO_1 1 //SX1262 IRQ pin
|
||||
#define P_LORA_NSS 15 //SX1262 SS pin
|
||||
#define P_LORA_RESET 3 //SX1262 Reset pin
|
||||
#define P_LORA_BUSY 38 //SX1262 Busy pin
|
||||
#define P_LORA_SCLK 13 //SX1262 SCLK pin
|
||||
#define P_LORA_MISO 12 //SX1262 MISO pin
|
||||
#define P_LORA_MOSI 11 //SX1262 MOSI pin
|
||||
#define P_LORA_LDO_EN 40 //Radio LDO enable
|
||||
#define P_LORA_CTRL 21 //LNA power control
|
||||
#define P_LORA_TX_LED 18 //TX LED
|
||||
|
||||
// T-Beam 1W uses single I2C bus on GPIO 8/9 for ALL peripherals
|
||||
#define PIN_BOARD_SDA 8 //SDA for PMU, OLED, and peripherals
|
||||
#define PIN_BOARD_SCL 9 //SCL for PMU, OLED, and peripherals
|
||||
|
||||
#define PIN_PMU_IRQ -1 //No PMU IRQ on T-Beam 1W
|
||||
|
||||
#define PIN_GPS_RX 5
|
||||
#define PIN_GPS_TX 6
|
||||
#define PIN_GPS_EN 16
|
||||
#define PIN_GPS_PPS 7
|
||||
|
||||
#define PIN_FAN_CTRL 41 //Cooling fan control
|
||||
|
||||
//I2C addresses (single I2C bus)
|
||||
#define I2C_OLED_ADD 0x3C //SH1106 OLED I2C address
|
||||
#define I2C_PMU_ADD 0x34 //AXP2101 I2C address
|
||||
|
||||
#define PMU_WIRE_PORT Wire
|
||||
#define RTC_WIRE_PORT Wire
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_SX1262
|
||||
#define P_LORA_BUSY 32
|
||||
#endif
|
||||
|
|
@ -88,6 +123,12 @@
|
|||
#include "helpers/ESP32Board.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
// Forward declarations for fan control (defined in target.cpp)
|
||||
#ifdef TBEAM_1W_SX1262
|
||||
extern void activate_fan();
|
||||
extern void update_fan_control();
|
||||
#endif
|
||||
|
||||
class TBeamBoard : public ESP32Board {
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
//PhysicalLayer * pl;
|
||||
|
|
@ -125,6 +166,9 @@ public:
|
|||
#ifndef TBEAM_SUPREME_SX1262
|
||||
void onBeforeTransmit() override{
|
||||
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on - invert pin for SX1276
|
||||
#if defined(TBEAM_1W_SX1262) && defined(P_FAN_CTRL)
|
||||
activate_fan(); // Activate cooling fan for 1W PA
|
||||
#endif
|
||||
}
|
||||
void onAfterTransmit() override{
|
||||
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off - invert pin for SX1276
|
||||
|
|
@ -155,7 +199,50 @@ public:
|
|||
}
|
||||
|
||||
uint16_t getBattMilliVolts(){
|
||||
return PMU->getBattVoltage();
|
||||
if (PMU) {
|
||||
return PMU->getBattVoltage();
|
||||
}
|
||||
|
||||
#ifdef TBEAM_1W_SX1262
|
||||
// Fallback: ADC-based battery voltage reading for T-Beam 1W
|
||||
// GPIO 4 (ADC1_CH3) - per Meshtastic firmware variant
|
||||
const int BATTERY_ADC_PIN = 4;
|
||||
const float ADC_REFERENCE_VOLTAGE = 3300.0; // mV
|
||||
const float ADC_MULTIPLIER = 2.9333; // Per Meshtastic T-Beam 1W variant
|
||||
const int BATTERY_SENSE_SAMPLES = 30;
|
||||
static bool adc_initialized = false;
|
||||
|
||||
if (!adc_initialized) {
|
||||
pinMode(BATTERY_ADC_PIN, INPUT);
|
||||
analogReadResolution(12);
|
||||
analogSetAttenuation(ADC_11db);
|
||||
adc_initialized = true;
|
||||
}
|
||||
|
||||
uint32_t adc_sum = 0;
|
||||
for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) {
|
||||
adc_sum += analogRead(BATTERY_ADC_PIN);
|
||||
delayMicroseconds(100);
|
||||
}
|
||||
uint16_t adc_raw = adc_sum / BATTERY_SENSE_SAMPLES;
|
||||
|
||||
float battery_voltage_f = (adc_raw / 4095.0) * ADC_REFERENCE_VOLTAGE * ADC_MULTIPLIER;
|
||||
uint16_t battery_voltage = (uint16_t)battery_voltage_f;
|
||||
|
||||
static unsigned long last_debug = 0;
|
||||
if (millis() - last_debug > 10000) {
|
||||
Serial.printf("[BATTERY ADC] raw=%d, voltage=%.2fV (%.0fmV)\n", adc_raw, battery_voltage_f / 1000.0, battery_voltage_f);
|
||||
last_debug = millis();
|
||||
}
|
||||
|
||||
if (battery_voltage < 5500 || battery_voltage > 9000) {
|
||||
return 7400; // Out of range, return nominal
|
||||
}
|
||||
|
||||
return battery_voltage;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* getManufacturerName() const{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue