This commit is contained in:
mintylinux 2026-04-20 19:42:44 +12:00 committed by GitHub
commit ebe083ce32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 471 additions and 8 deletions

View file

@ -0,0 +1,145 @@
[T_Beam_1W_SX1262]
extends = esp32_base
board = t_beam_1w ; LILYGO T-Beam 1W ESP32S3 with SX1262 and 1W PA
build_flags =
${esp32_base.build_flags}
-I variants/lilygo_tbeam_1w_SX1262
-D TBEAM_1W_SX1262
-D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D SX126X_MAX_POWER=22
-D SX126X_PA_RAMP_TIME=0x05
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D DISPLAY_CLASS=SH1106Display
-D LORA_TX_POWER=22
-D P_LORA_NSS=15
-D P_LORA_RESET=3
-D P_LORA_DIO_1=1
-D P_LORA_BUSY=38
-D P_LORA_SCLK=13
-D P_LORA_MISO=12
-D P_LORA_MOSI=11
-D P_LORA_LDO_EN=40
-D P_LORA_CTRL=21
-D P_LORA_TX_LED=18
-D PIN_BOARD_SDA=8
-D PIN_BOARD_SCL=9
-D PIN_GPS_RX=5
-D PIN_GPS_TX=6
-D PIN_GPS_EN=16
-D PIN_GPS_PPS=7
-D PIN_USER_BTN=0
-D PIN_USER_BTN2=17
-D P_FAN_CTRL=41
-D ENV_INCLUDE_GPS=1
-D PERSISTANT_GPS=1
-D ENV_SKIP_GPS_DETECT=1
-D GPS_BAUD_RATE=9600
-D BATTERY_MIN_MILLIVOLTS=6000
-D BATTERY_MAX_MILLIVOLTS=8400
-D BATTERY_SERIES_CELLS=2
build_src_filter = ${esp32_base.build_src_filter}
+<../variants/lilygo_tbeam_1w_SX1262>
+<helpers/ui/SH1106Display.cpp>
+<helpers/esp32/TBeamBoard.cpp>
+<helpers/sensors>
board_build.partitions = min_spiffs.csv
lib_deps =
${esp32_base.lib_deps}
lewisxhe/XPowersLib @ ^0.2.7
adafruit/Adafruit SH110X @ ^2.1.13
stevemarple/MicroNMEA @ ^2.0.6
; === LILYGO T-Beam 1W with SX1262 environments ===
[env:T_Beam_1W_SX1262_repeater]
extends = T_Beam_1W_SX1262
build_flags =
${T_Beam_1W_SX1262.build_flags}
-D ADVERT_NAME='"T-Beam 1W SX1262 Repeater"'
-D ADVERT_LAT=0
-D ADVERT_LON=0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
-D MESH_PACKET_LOGGING=1
-D MESH_DEBUG=1
build_src_filter = ${T_Beam_1W_SX1262.build_src_filter}
+<../examples/simple_repeater>
lib_deps =
${T_Beam_1W_SX1262.lib_deps}
${esp32_ota.lib_deps}
[env:T_Beam_1W_SX1262_repeater_bridge_espnow]
extends = T_Beam_1W_SX1262
build_flags =
${T_Beam_1W_SX1262.build_flags}
-D ADVERT_NAME='"T-Beam 1W ESPNow Bridge"'
-D ADVERT_LAT=0
-D ADVERT_LON=0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
-D WITH_ESPNOW_BRIDGE=1
; -D BRIDGE_DEBUG=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${T_Beam_1W_SX1262.build_src_filter}
+<helpers/bridges/ESPNowBridge.cpp>
+<../examples/simple_repeater>
lib_deps =
${T_Beam_1W_SX1262.lib_deps}
${esp32_ota.lib_deps}
[env:T_Beam_1W_SX1262_room_server]
extends = T_Beam_1W_SX1262
build_flags =
${T_Beam_1W_SX1262.build_flags}
-D ADVERT_NAME='"T-Beam 1W Room"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D ROOM_PASSWORD='"hello"'
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${T_Beam_1W_SX1262.build_src_filter}
+<../examples/simple_room_server>
lib_deps =
${T_Beam_1W_SX1262.lib_deps}
${esp32_ota.lib_deps}
[env:T_Beam_1W_SX1262_companion_radio_usb]
extends = T_Beam_1W_SX1262
build_flags =
${T_Beam_1W_SX1262.build_flags}
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${T_Beam_1W_SX1262.build_src_filter}
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${T_Beam_1W_SX1262.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:T_Beam_1W_SX1262_companion_radio_ble]
extends = T_Beam_1W_SX1262
build_flags =
${T_Beam_1W_SX1262.build_flags}
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456
-D OFFLINE_QUEUE_SIZE=256
-D BLE_DEBUG_LOGGING=1
-D MESH_PACKET_LOGGING=8
-D MESH_DEBUG=1
-D GPS_NMEA_DEBUG=1
build_src_filter = ${T_Beam_1W_SX1262.build_src_filter}
+<helpers/esp32/*.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${T_Beam_1W_SX1262.lib_deps}
densaugeo/base64 @ ~1.4.0

View file

@ -0,0 +1,112 @@
#include <Arduino.h>
#include "target.h"
TBeamBoard board;
static bool fanRunning = false;
static uint32_t fanStartTime = 0;
static const uint32_t FAN_RUN_TIME_MS = 5000; // 5 seconds after transmission
#ifdef DISPLAY_CLASS
DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
#endif
static SPIClass spi;
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
WRAPPER_CLASS radio_driver(radio, board);
ESP32RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#else
EnvironmentSensorManager sensors;
#endif
void activate_fan() {
#ifdef P_FAN_CTRL
digitalWrite(P_FAN_CTRL, HIGH);
fanRunning = true;
fanStartTime = millis();
// #ifdef DEBUG_FAN
//Serial.printf("[FAN] Activated at %lu ms\n", fanStartTime);
//#endif
#endif
}
void update_fan_control() {
#ifdef P_FAN_CTRL
if (fanRunning) {
uint32_t currentTime = millis();
uint32_t elapsed;
// Handle millis() overflow
if (currentTime >= fanStartTime) {
elapsed = currentTime - fanStartTime;
} else {
elapsed = (UINT32_MAX - fanStartTime) + currentTime;
}
if (elapsed >= FAN_RUN_TIME_MS) {
digitalWrite(P_FAN_CTRL, LOW);
fanRunning = false;
// #ifdef DEBUG_FAN
// Serial.printf("[FAN] Deactivated after %lu ms\n", elapsed);
// #endif
}
}
#endif
}
bool radio_init() {
// Enable the radio LDO (must be HIGH to power on radio)
pinMode(P_LORA_LDO_EN, OUTPUT);
digitalWrite(P_LORA_LDO_EN, HIGH);
delay(10); // Give LDO time to stabilize
// Configure LNA control pin (LOW during TX/sleep, HIGH during RX)
pinMode(P_LORA_CTRL, OUTPUT);
digitalWrite(P_LORA_CTRL, HIGH); // Start in RX mode (LNA on)
// Enable cooling fan control
#ifdef P_FAN_CTRL
pinMode(P_FAN_CTRL, OUTPUT);
digitalWrite(P_FAN_CTRL, LOW); // Turn off fan initially
#endif
fallback_clock.begin();
rtc_clock.begin(Wire); // T-Beam 1W uses single I2C bus on Wire
// Reset fan timer
fanRunning = false;
fanStartTime = 0;
return radio.std_init(&spi);
}
uint32_t radio_get_rng_seed() {
return radio.random(0x7FFFFFFF);
}
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
radio.setFrequency(freq);
radio.setSpreadingFactor(sf);
radio.setBandwidth(bw);
radio.setCodingRate(cr);
}
void radio_set_tx_power(uint8_t dbm) {
radio.setOutputPower(dbm);
}
mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}

View file

@ -0,0 +1,29 @@
#pragma once
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include <helpers/radiolib/RadioLibWrappers.h>
#include <helpers/esp32/TBeamBoard.h>
#include <helpers/radiolib/CustomSX1262Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/sensors/EnvironmentSensorManager.h>
#ifdef DISPLAY_CLASS
#include <helpers/ui/SH1106Display.h>
extern DISPLAY_CLASS display;
#include <helpers/ui/MomentaryButton.h>
extern MomentaryButton user_btn;
#endif
extern TBeamBoard board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
extern EnvironmentSensorManager sensors;
bool radio_init();
uint32_t radio_get_rng_seed();
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
void radio_set_tx_power(uint8_t dbm);
mesh::LocalIdentity radio_new_identity();
void activate_fan(); // Activate cooling fan
void update_fan_control(); // Update fan state (call in main loop)