From 16b81d2a6c7a9ba6cd5275cfa909281b81c27d06 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 31 Jan 2025 11:46:19 +1100 Subject: [PATCH] * new target/envs: LilyGo_T3S3_sx1262, _repeater and _terminal_chat --- boards/t3_s3_v1_x.json | 45 +++++++++++++++++++++++ examples/simple_repeater/main.cpp | 4 +-- examples/simple_secure_chat/main.cpp | 2 +- platformio.ini | 54 +++++++++++++++++++++++++++- src/helpers/ESP32Board.h | 32 +++++++++++++++++ src/helpers/HeltecV3Board.h | 26 +++----------- 6 files changed, 138 insertions(+), 25 deletions(-) create mode 100644 boards/t3_s3_v1_x.json diff --git a/boards/t3_s3_v1_x.json b/boards/t3_s3_v1_x.json new file mode 100644 index 00000000..49f9171c --- /dev/null +++ b/boards/t3_s3_v1_x.json @@ -0,0 +1,45 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_LILYGO_T3_S3_V1_X", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_MODE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "LilyGo T3-S3 Radio", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.lilygo.cc", + "vendor": "LilyGo" +} \ No newline at end of file diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index ed73cbcb..74027d4b 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -19,7 +19,7 @@ /* ------------------------------ Config -------------------------------- */ -#define FIRMWARE_VER_TEXT "v2 (build: 30 Jan 2025)" +#define FIRMWARE_VER_TEXT "v2 (build: 31 Jan 2025)" #ifndef LORA_FREQ #define LORA_FREQ 915.0 @@ -60,7 +60,7 @@ #include #include static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) +#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) #include #include static ESP32Board board; diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index af905869..89e1e0e7 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -56,7 +56,7 @@ #include #include static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) +#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) #include #include static ESP32Board board; diff --git a/platformio.ini b/platformio.ini index 4a2867c4..ad373785 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,7 +17,7 @@ lib_deps = jgromes/RadioLib @ ^6.3.0 rweather/Crypto @ ^0.4.0 build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 - -D LORA_FREQ=867.5 + -D LORA_FREQ=915.8 -D LORA_BW=250 -D LORA_SF=10 build_src_filter = +<*.cpp> + @@ -246,6 +246,58 @@ lib_deps = adafruit/RTClib @ ^2.1.3 densaugeo/base64 @ ~1.4.0 +; ============= +[LilyGo_T3S3_sx1262] +extends = esp32_base +board = t3_s3_v1_x +build_flags = ${esp32_base.build_flags} + -D LILYGO_T3S3 + -D P_LORA_DIO_1=33 + -D P_LORA_NSS=7 + -D P_LORA_RESET=8 ; RADIOLIB_NC + -D P_LORA_BUSY=34 + -D P_LORA_SCLK=5 + -D P_LORA_MISO=3 + -D P_LORA_MOSI=6 + -D P_LORA_TX_LED=37 + -D PIN_VBAT_READ=1 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 + -D SX126X_CURRENT_LIMIT=130 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D LORA_TX_POWER=22 + +[env:LilyGo_T3S3_sx1262_Repeater] +extends = LilyGo_T3S3_sx1262 +build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} +<../examples/simple_repeater/main.cpp> +build_flags = + ${LilyGo_T3S3_sx1262.build_flags} + -D ADVERT_NAME="\"T3S3 Repeater\"" + -D ADVERT_LAT=-37.0 + -D ADVERT_LON=145.0 + -D ADMIN_PASSWORD="\"password\"" +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +lib_deps = + ${LilyGo_T3S3_sx1262.lib_deps} + adafruit/RTClib @ ^2.1.3 + +[env:LilyGo_T3S3_sx1262_terminal_chat] +extends = LilyGo_T3S3_sx1262 +build_flags = + ${LilyGo_T3S3_sx1262.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${LilyGo_T3S3_sx1262.lib_deps} + adafruit/RTClib @ ^2.1.3 + densaugeo/base64 @ ~1.4.0 + + ; ----------------- NRF52 --------------------- [nrf52_base] extends = arduino_base diff --git a/src/helpers/ESP32Board.h b/src/helpers/ESP32Board.h index 7b88b25e..9f50c0c7 100644 --- a/src/helpers/ESP32Board.h +++ b/src/helpers/ESP32Board.h @@ -16,12 +16,44 @@ public: void begin() { // for future use, sub-classes SHOULD call this from their begin() startup_reason = BD_STARTUP_NORMAL; + + #ifdef PIN_VBAT_READ + // battery read support + pinMode(PIN_VBAT_READ, INPUT); + adcAttachPin(PIN_VBAT_READ); + #endif + + #ifdef P_LORA_TX_LED + pinMode(P_LORA_TX_LED, OUTPUT); + digitalWrite(P_LORA_TX_LED, LOW); + #endif } uint8_t getStartupReason() const override { return startup_reason; } +#if defined(P_LORA_TX_LED) + void onBeforeTransmit() override { + digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on + } + void onAfterTransmit() override { + digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off + } +#endif + uint16_t getBattMilliVolts() override { + #ifdef PIN_VBAT_READ + analogReadResolution(12); + + uint32_t raw = 0; + for (int i = 0; i < 4; i++) { + raw += analogReadMilliVolts(PIN_VBAT_READ); + } + raw = raw / 4; + + return (2 * raw); + #else return 0; // not supported + #endif } const char* getManufacturerName() const override { diff --git a/src/helpers/HeltecV3Board.h b/src/helpers/HeltecV3Board.h index 657286ed..232ed414 100644 --- a/src/helpers/HeltecV3Board.h +++ b/src/helpers/HeltecV3Board.h @@ -1,6 +1,5 @@ #pragma once -#include "ESP32Board.h" #include // LoRa radio module pins for Heltec V3 @@ -19,6 +18,8 @@ #define PIN_ADC_CTRL_INACTIVE HIGH #define PIN_LED_BUILTIN 35 +#include "ESP32Board.h" + #include class HeltecV3Board : public ESP32Board { @@ -26,6 +27,8 @@ public: void begin() { ESP32Board::begin(); + pinMode(PIN_ADC_CTRL, OUTPUT); + esp_reset_reason_t reason = esp_reset_reason(); if (reason == ESP_RST_DEEPSLEEP) { long wakeup_source = esp_sleep_get_ext1_wakeup_status(); @@ -36,17 +39,6 @@ public: rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS); rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1); } - - // battery read support - pinMode(PIN_VBAT_READ, INPUT); - adcAttachPin(PIN_VBAT_READ); - analogReadResolution(10); - pinMode(PIN_ADC_CTRL, OUTPUT); - - #ifdef P_LORA_TX_LED - pinMode(P_LORA_TX_LED, OUTPUT); - digitalWrite(P_LORA_TX_LED, LOW); - #endif } void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) { @@ -72,16 +64,8 @@ public: esp_deep_sleep_start(); // CPU halts here and never returns! } -#if defined(P_LORA_TX_LED) - void onBeforeTransmit() override { - digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on - } - void onAfterTransmit() override { - digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off - } -#endif - uint16_t getBattMilliVolts() override { + analogReadResolution(10); digitalWrite(PIN_ADC_CTRL, PIN_ADC_CTRL_ACTIVE); uint32_t raw = 0;