From 20410896608f1666d66f23c8a40790f69cdf06c8 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sat, 8 Aug 2026 16:05:56 +0700 Subject: [PATCH 1/8] Added heltec_v4_companion_radio_usb_ps_femon and heltec_v4_companion_radio_usb_ps_femoff --- variants/heltec_v4/platformio.ini | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/variants/heltec_v4/platformio.ini b/variants/heltec_v4/platformio.ini index 113ba24a0..12d772f20 100644 --- a/variants/heltec_v4/platformio.ini +++ b/variants/heltec_v4/platformio.ini @@ -199,6 +199,16 @@ lib_deps = ${heltec_v4_oled.lib_deps} densaugeo/base64 @ ~1.4.0 +[env:heltec_v4_companion_radio_usb_ps_femon] +extends = env:heltec_v4_companion_radio_usb +platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 + +[env:heltec_v4_companion_radio_usb_ps_femoff] +extends = env:heltec_v4_companion_radio_usb_ps_femon +build_flags = + ${env:heltec_v4_companion_radio_usb_ps_femon.build_flags} + -D RADIO_FEM_RXGAIN=0 ; undefined (default on), 1=on, 0=off + [env:heltec_v4_companion_radio_ble] extends = heltec_v4_oled build_flags = From e13fb6a42607df75042bd8e901fc4904cd2c3fe5 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 12:38:31 +0700 Subject: [PATCH 2/8] Added ; -D FORCE_GPS_ALIVE --- variants/rak4631/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 662a9a6ae..7279a6c51 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -13,6 +13,7 @@ build_flags = ${nrf52_base.build_flags} ; -D NRF52_POWER_MANAGEMENT -D PIN_BOARD_SCL=14 -D PIN_BOARD_SDA=13 +; -D FORCE_GPS_ALIVE // Do not off WB_IO2 if we want to keep other sensor / IO slots on -D PIN_GPS_EN=-1 -D PIN_OLED_RESET=-1 -D USE_SX1262 From 6334f602f1ab9df82e7e7fb3e3ffb74cc0576ea3 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 12:41:29 +0700 Subject: [PATCH 3/8] Added polling period and powersave of I2C GPS for RAK12500 --- .../sensors/EnvironmentSensorManager.cpp | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index e67a392e8..ffda2414e 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -200,16 +200,21 @@ public: void begin() override { } void stop() override { } void loop() override { - if (ublox_GNSS.getGnssFixOk(8)) { - _fix = true; - _lat = ublox_GNSS.getLatitude(2) / 10; - _lng = ublox_GNSS.getLongitude(2) / 10; - _alt = ublox_GNSS.getAltitude(2); - _sats = ublox_GNSS.getSIV(2); - } else { - _fix = false; + static long next_gps_update = 0; + if ((int32_t)(millis() - next_gps_update) >= 0) { + if (ublox_GNSS.getGnssFixOk(8)) { + _fix = true; + _lat = ublox_GNSS.getLatitude(2) / 10; + _lng = ublox_GNSS.getLongitude(2) / 10; + _alt = ublox_GNSS.getAltitude(2); + _sats = ublox_GNSS.getSIV(2); + } else { + _fix = false; + } + _epoch = ublox_GNSS.getUnixEpoch(2); + + next_gps_update = millis() + 1000; } - _epoch = ublox_GNSS.getUnixEpoch(2); } bool isEnabled() override { return true; } void setPinEn(int pin_en) override { _pin_en = pin_en; } @@ -882,9 +887,14 @@ void EnvironmentSensorManager::start_gps() { } #ifdef RAK_WISBLOCK_GPS - pinMode(gpsResetPin, OUTPUT); - digitalWrite(gpsResetPin, HIGH); // WB_IO2 - return; +#ifdef FORCE_GPS_ALIVE + // There is no UART command to enter power save for L76K + if (i2cGPSFlag) ublox_GNSS.powerSaveMode(false); +#else + pinMode(gpsResetPin, OUTPUT); + digitalWrite(gpsResetPin, HIGH); // WB_IO2 +#endif + return; #endif _location->begin(); @@ -906,7 +916,10 @@ void EnvironmentSensorManager::stop_gps() { } #ifdef RAK_WISBLOCK_GPS - #ifndef FORCE_GPS_ALIVE + #ifdef FORCE_GPS_ALIVE + // There is no UART command to enter power save for L76K + if(i2cGPSFlag) ublox_GNSS.powerSaveMode(false); + #else pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, LOW); // WB_IO2 #endif From 5859319cbf4b1db5a484689f37bc13f7d7f74743 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 23:30:56 +0700 Subject: [PATCH 4/8] Added Heltec V4 R8 --- boards/heltec_v4_r8.json | 43 +++ variants/heltec_v4_r8/HeltecV4R8Board.cpp | 86 ++++++ variants/heltec_v4_r8/HeltecV4R8Board.h | 39 +++ variants/heltec_v4_r8/LoRaFEMControl.cpp | 52 ++++ variants/heltec_v4_r8/LoRaFEMControl.h | 24 ++ variants/heltec_v4_r8/pins_arduino.h | 56 ++++ variants/heltec_v4_r8/platformio.ini | 348 ++++++++++++++++++++++ variants/heltec_v4_r8/target.cpp | 45 +++ variants/heltec_v4_r8/target.h | 31 ++ 9 files changed, 724 insertions(+) create mode 100644 boards/heltec_v4_r8.json create mode 100644 variants/heltec_v4_r8/HeltecV4R8Board.cpp create mode 100644 variants/heltec_v4_r8/HeltecV4R8Board.h create mode 100644 variants/heltec_v4_r8/LoRaFEMControl.cpp create mode 100644 variants/heltec_v4_r8/LoRaFEMControl.h create mode 100644 variants/heltec_v4_r8/pins_arduino.h create mode 100644 variants/heltec_v4_r8/platformio.ini create mode 100644 variants/heltec_v4_r8/target.cpp create mode 100644 variants/heltec_v4_r8/target.h diff --git a/boards/heltec_v4_r8.json b/boards/heltec_v4_r8.json new file mode 100644 index 000000000..6dd97c84b --- /dev/null +++ b/boards/heltec_v4_r8.json @@ -0,0 +1,43 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [["0x303A", "0x1001"]], + "mcu": "esp32s3", + "variant": "heltec_v4_r8" + }, + "connectivity": ["wifi", "bluetooth", "lora"], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": ["esp-builtin"], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": ["arduino", "espidf"], + "name": "heltec_wifi_lora_32 v4 r8 (16 MB FLASH, 8 MB PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://heltec.org/", + "vendor": "heltec" +} diff --git a/variants/heltec_v4_r8/HeltecV4R8Board.cpp b/variants/heltec_v4_r8/HeltecV4R8Board.cpp new file mode 100644 index 000000000..1fb123b2f --- /dev/null +++ b/variants/heltec_v4_r8/HeltecV4R8Board.cpp @@ -0,0 +1,86 @@ +#include "HeltecV4R8Board.h" + +void HeltecV4R8Board::begin() { + ESP32Board::begin(); + + periph_power.begin(); + periph_power.claim(); // R8 VEXT also feeds the LoRa antenna boost rail. + + loRaFEMControl.init(); + +#ifdef PIN_TOUCH_RST + pinMode(PIN_TOUCH_RST, OUTPUT); + digitalWrite(PIN_TOUCH_RST, HIGH); + delay(10); + digitalWrite(PIN_TOUCH_RST, LOW); + delay(100); + digitalWrite(PIN_TOUCH_RST, HIGH); +#endif + + esp_reset_reason_t reason = esp_reset_reason(); + if (reason == ESP_RST_DEEPSLEEP) { + long wakeup_source = esp_sleep_get_ext1_wakeup_status(); + if (wakeup_source & (1 << P_LORA_DIO_1)) { + startup_reason = BD_STARTUP_RX_PACKET; + } + + rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS); + rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1); + } +} + +void HeltecV4R8Board::onBeforeTransmit(void) { + digitalWrite(P_LORA_TX_LED, HIGH); + loRaFEMControl.setTxModeEnable(); +} + +void HeltecV4R8Board::onAfterTransmit(void) { + digitalWrite(P_LORA_TX_LED, LOW); + loRaFEMControl.setRxModeEnable(); +} + +void HeltecV4R8Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { + esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); + + rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); + rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); + + rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS); + loRaFEMControl.setRxModeEnableWhenMCUSleep(); + + if (pin_wake_btn < 0) { + esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); + } else { + esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); + } + + if (secs > 0) { + esp_sleep_enable_timer_wakeup(secs * 1000000); + } + + esp_deep_sleep_start(); +} + +void HeltecV4R8Board::powerOff() { + enterDeepSleep(0); +} + +uint16_t HeltecV4R8Board::getBattMilliVolts() { + analogReadResolution(12); + + uint32_t raw = 0; + for (int i = 0; i < 8; i++) { + raw += analogReadMilliVolts(PIN_VBAT_READ); + } + raw = raw / 8; + + return (adc_mult * raw); +} + +const char* HeltecV4R8Board::getManufacturerName() const { +#ifdef HELTEC_V4_R8_TFT + return "Heltec V4 R8 TFT"; +#else + return "Heltec V4 R8 OLED"; +#endif +} diff --git a/variants/heltec_v4_r8/HeltecV4R8Board.h b/variants/heltec_v4_r8/HeltecV4R8Board.h new file mode 100644 index 000000000..20811abb1 --- /dev/null +++ b/variants/heltec_v4_r8/HeltecV4R8Board.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include +#include "LoRaFEMControl.h" + +#ifndef ADC_MULTIPLIER + #define ADC_MULTIPLIER (4.9f * 1.035f) +#endif + +class HeltecV4R8Board : public ESP32Board { +protected: + float adc_mult = ADC_MULTIPLIER; + +public: + RefCountedDigitalPin periph_power; + LoRaFEMControl loRaFEMControl; + + HeltecV4R8Board() : periph_power(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE) { } + + void begin(); + void onBeforeTransmit(void) override; + void onAfterTransmit(void) override; + void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1); + void powerOff() override; + uint16_t getBattMilliVolts() override; + bool setAdcMultiplier(float multiplier) override { + if (multiplier == 0.0f) { + adc_mult = ADC_MULTIPLIER; + } else { + adc_mult = multiplier; + } + return true; + } + float getAdcMultiplier() const override { return adc_mult; } + const char* getManufacturerName() const override; +}; diff --git a/variants/heltec_v4_r8/LoRaFEMControl.cpp b/variants/heltec_v4_r8/LoRaFEMControl.cpp new file mode 100644 index 000000000..bb530de3c --- /dev/null +++ b/variants/heltec_v4_r8/LoRaFEMControl.cpp @@ -0,0 +1,52 @@ +#include "LoRaFEMControl.h" + +#include +#include +#include + +void LoRaFEMControl::init(void) { + pinMode(P_LORA_PA_POWER, OUTPUT); + digitalWrite(P_LORA_PA_POWER, HIGH); + rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_POWER); + + esp_reset_reason_t reason = esp_reset_reason(); + if (reason != ESP_RST_DEEPSLEEP) { + delay(1); + } + + rtc_gpio_hold_dis((gpio_num_t)P_LORA_KCT8103L_PA_CSD); + rtc_gpio_hold_dis((gpio_num_t)P_LORA_KCT8103L_PA_CTX); + + pinMode(P_LORA_KCT8103L_PA_CSD, OUTPUT); + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + pinMode(P_LORA_KCT8103L_PA_CTX, OUTPUT); + digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH); +} + +void LoRaFEMControl::setSleepModeEnable(void) { + digitalWrite(P_LORA_KCT8103L_PA_CSD, LOW); +} + +void LoRaFEMControl::setTxModeEnable(void) { + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + digitalWrite(P_LORA_KCT8103L_PA_CTX, HIGH); +} + +void LoRaFEMControl::setRxModeEnable(void) { + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH); +} + +void LoRaFEMControl::setRxModeEnableWhenMCUSleep(void) { + digitalWrite(P_LORA_PA_POWER, HIGH); + rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_POWER); + + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + rtc_gpio_hold_en((gpio_num_t)P_LORA_KCT8103L_PA_CSD); + digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH); + rtc_gpio_hold_en((gpio_num_t)P_LORA_KCT8103L_PA_CTX); +} + +void LoRaFEMControl::setLNAEnable(bool enabled) { + lna_enabled = enabled; +} diff --git a/variants/heltec_v4_r8/LoRaFEMControl.h b/variants/heltec_v4_r8/LoRaFEMControl.h new file mode 100644 index 000000000..961cfd070 --- /dev/null +++ b/variants/heltec_v4_r8/LoRaFEMControl.h @@ -0,0 +1,24 @@ +#pragma once + +typedef enum { + KCT8103L_PA, + OTHER_FEM_TYPES +} LoRaFEMType; + +class LoRaFEMControl { +public: + LoRaFEMControl() { } + virtual ~LoRaFEMControl() { } + void init(void); + void setSleepModeEnable(void); + void setTxModeEnable(void); + void setRxModeEnable(void); + void setRxModeEnableWhenMCUSleep(void); + void setLNAEnable(bool enabled); + bool isLnaCanControl(void) { return true; } + void setLnaCanControl(bool can_control) { } + LoRaFEMType getFEMType(void) const { return KCT8103L_PA; } + +private: + bool lna_enabled = false; +}; diff --git a/variants/heltec_v4_r8/pins_arduino.h b/variants/heltec_v4_r8/pins_arduino.h new file mode 100644 index 000000000..9e412aac5 --- /dev/null +++ b/variants/heltec_v4_r8/pins_arduino.h @@ -0,0 +1,56 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 17; +static const uint8_t SCL = 18; + +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +#endif diff --git a/variants/heltec_v4_r8/platformio.ini b/variants/heltec_v4_r8/platformio.ini new file mode 100644 index 000000000..70634f3d0 --- /dev/null +++ b/variants/heltec_v4_r8/platformio.ini @@ -0,0 +1,348 @@ +[Heltec_v4_r8] +extends = esp32_base +board = heltec_v4_r8 +build_flags = + ${esp32_base.build_flags} + ${sensor_base.build_flags} + -I variants/heltec_v4_r8 + -D HELTEC_V4_R8 + -D USE_SX1262 + -D ESP32_CPU_FREQ=80 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D P_LORA_DIO_1=14 + -D P_LORA_NSS=8 + -D P_LORA_RESET=12 + -D P_LORA_BUSY=13 + -D P_LORA_SCLK=9 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 + -D P_LORA_PA_POWER=7 + -D P_LORA_KCT8103L_PA_CSD=2 + -D P_LORA_KCT8103L_PA_CTX=5 + -D P_LORA_TX_LED=46 + -D PIN_USER_BTN=0 + -D PIN_VEXT_EN=40 + -D PIN_VEXT_EN_ACTIVE=LOW + -D ADC_MULTIPLIER=5.0715f + -D PIN_VBAT_READ=1 + -D LORA_TX_POWER=10 + -D MAX_LORA_TX_POWER=22 + -D SX126X_REGISTER_PATCH=1 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 + -D SX126X_CURRENT_LIMIT=140 + -D SX126X_RX_BOOSTED_GAIN=1 + -D PIN_GPS_RX=38 + -D PIN_GPS_TX=39 + -D PIN_GPS_EN=42 + -D PIN_GPS_EN_ACTIVE=LOW + -D ENV_INCLUDE_GPS=1 +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/heltec_v4_r8> + + +lib_deps = + ${esp32_base.lib_deps} + ${sensor_base.lib_deps} + +[heltec_v4_r8_oled] +extends = Heltec_v4_r8 +build_flags = + ${Heltec_v4_r8.build_flags} + -D HELTEC_V4_R8_OLED + -D PIN_BOARD_SDA=17 + -D PIN_BOARD_SCL=18 + -D PIN_OLED_RESET=21 +build_src_filter = ${Heltec_v4_r8.build_src_filter} +lib_deps = ${Heltec_v4_r8.lib_deps} + +[heltec_v4_r8_tft] +extends = Heltec_v4_r8 +build_flags = + ${Heltec_v4_r8.build_flags} + -D HELTEC_V4_R8_TFT + -D PIN_BOARD_SDA=17 + -D PIN_BOARD_SCL=18 + -D DISPLAY_SCALE_X=2.5 + -D DISPLAY_SCALE_Y=3.75 + -D PIN_TFT_RST=-1 + -D PIN_TFT_VDD_CTL=-1 + -D PIN_TFT_LEDA_CTL=44 + -D PIN_TFT_LEDA_CTL_ACTIVE=HIGH + -D PIN_TFT_CS=47 + -D PIN_TFT_DC=48 + -D PIN_TFT_SCL=16 + -D PIN_TFT_SDA=15 + -D PIN_TFT_MISO=45 + -D PIN_BUZZER=4 + -D PIN_TOUCH_RST=21 +build_src_filter = ${Heltec_v4_r8.build_src_filter} + + +lib_deps = + ${Heltec_v4_r8.lib_deps} + adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0 + end2endzone/NonBlockingRTTTL@^1.3.0 + +[env:heltec_v4_r8_repeater] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"Heltec R8 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + ${esp32_ota.lib_deps} + bakercp/CRC32 @ ^2.0.0 + +[env:heltec_v4_r8_room_server] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"Heltec R8 Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + +<../examples/simple_room_server> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_terminal_chat] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=1 +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_companion_radio_usb] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D DISPLAY_CLASS=SSD1306Display + -D ENABLE_USB_INTERFACE +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_companion_radio_ble] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D DISPLAY_CLASS=SSD1306Display + -D BLE_PIN_CODE=123456 + -D AUTO_SHUTDOWN_MILLIVOLTS=3400 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_companion_radio_ble_ps] +extends = env:heltec_v4_r8_companion_radio_ble +platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 + +[env:heltec_v4_r8_companion_radio_wifi] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D OFFLINE_QUEUE_SIZE=256 + -D DISPLAY_CLASS=SSD1306Display + -D WIFI_DEBUG_LOGGING=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"mypwd"' +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_sensor] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D ADVERT_NAME='"Heltec R8 Sensor"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D DISPLAY_CLASS=SSD1306Display +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + +<../examples/simple_sensor> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_tft_repeater] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D DISPLAY_CLASS=ST7789LCDDisplay + -D ADVERT_NAME='"Heltec R8 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + ${esp32_ota.lib_deps} + bakercp/CRC32 @ ^2.0.0 + +[env:heltec_v4_r8_tft_room_server] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D DISPLAY_CLASS=ST7789LCDDisplay + -D ADVERT_NAME='"Heltec R8 Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + +<../examples/simple_room_server> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_tft_terminal_chat] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=1 +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_companion_radio_usb] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D DISPLAY_CLASS=ST7789LCDDisplay + -D ENABLE_USB_INTERFACE +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_companion_radio_ble] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -I examples/companion_radio/ui-new + -D DISPLAY_CLASS=ST7789LCDDisplay + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D BLE_PIN_CODE=123456 + -D AUTO_SHUTDOWN_MILLIVOLTS=3400 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_companion_radio_wifi] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D OFFLINE_QUEUE_SIZE=256 + -D DISPLAY_CLASS=ST7789LCDDisplay + -D WIFI_DEBUG_LOGGING=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"mypwd"' +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_sensor] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D ADVERT_NAME='"Heltec R8 Sensor"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D DISPLAY_CLASS=ST7789LCDDisplay +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + +<../examples/simple_sensor> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_kiss_modem] +extends = Heltec_v4_r8 +build_src_filter = ${Heltec_v4_r8.build_src_filter} + +<../examples/kiss_modem/> + +[env:heltec_v4_r8_tft_kiss_modem] +extends = heltec_v4_r8_tft +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + +<../examples/kiss_modem/> diff --git a/variants/heltec_v4_r8/target.cpp b/variants/heltec_v4_r8/target.cpp new file mode 100644 index 000000000..0b38531e3 --- /dev/null +++ b/variants/heltec_v4_r8/target.cpp @@ -0,0 +1,45 @@ +#include +#include "target.h" + +HeltecV4R8Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +WRAPPER_CLASS radio_driver(radio, board); + +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#if ENV_INCLUDE_GPS + #include + MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock, GPS_RESET, GPS_EN, &board.periph_power); + EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); +#else + EnvironmentSensorManager sensors; +#endif + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display(&board.periph_power); + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); +#endif + +bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + +#if defined(P_LORA_SCLK) + return radio.std_init(&spi); +#else + return radio.std_init(); +#endif +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); +} diff --git a/variants/heltec_v4_r8/target.h b/variants/heltec_v4_r8/target.h new file mode 100644 index 000000000..2d1d7a5bb --- /dev/null +++ b/variants/heltec_v4_r8/target.h @@ -0,0 +1,31 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include +#include +#ifdef DISPLAY_CLASS + #ifdef HELTEC_V4_R8_OLED + #include + #elif defined(HELTEC_V4_R8_TFT) + #include + #endif + #include +#endif + +extern HeltecV4R8Board board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern EnvironmentSensorManager sensors; + +#ifdef DISPLAY_CLASS + extern DISPLAY_CLASS display; + extern MomentaryButton user_btn; +#endif + +bool radio_init(); +mesh::LocalIdentity radio_new_identity(); From 5a92e91498f21274cbffabc20355a8416e5909f4 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 23:31:30 +0700 Subject: [PATCH 5/8] Added ST7789LCD for Heltec v4 r8 --- src/helpers/ui/ST7789LCDDisplay.cpp | 8 ++++++-- src/helpers/ui/ST7789LCDDisplay.h | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/helpers/ui/ST7789LCDDisplay.cpp b/src/helpers/ui/ST7789LCDDisplay.cpp index dc75e9631..7a02668bc 100644 --- a/src/helpers/ui/ST7789LCDDisplay.cpp +++ b/src/helpers/ui/ST7789LCDDisplay.cpp @@ -1,5 +1,9 @@ #include "ST7789LCDDisplay.h" +#ifndef PIN_TFT_MISO + #define PIN_TFT_MISO -1 +#endif + #ifndef DISPLAY_ROTATION #define DISPLAY_ROTATION 3 #endif @@ -29,8 +33,8 @@ bool ST7789LCDDisplay::begin() { } // Im not sure if this is just a t-deck problem or not, if your display is slow try this. - #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) - displaySPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS); + #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) + displaySPI.begin(PIN_TFT_SCL, PIN_TFT_MISO, PIN_TFT_SDA, PIN_TFT_CS); #endif display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT); diff --git a/src/helpers/ui/ST7789LCDDisplay.h b/src/helpers/ui/ST7789LCDDisplay.h index 5b960ca19..03a6d3f12 100644 --- a/src/helpers/ui/ST7789LCDDisplay.h +++ b/src/helpers/ui/ST7789LCDDisplay.h @@ -8,7 +8,7 @@ #include class ST7789LCDDisplay : public DisplayDriver { - #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) + #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) SPIClass displaySPI; #endif Adafruit_ST7789 display; @@ -25,7 +25,7 @@ public: { _isOn = false; } -#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) +#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) ST7789LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64), displaySPI(HSPI), display(&displaySPI, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST), From 28331c110c24e2d012fb8efec58db8d707bb1a91 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 23:32:19 +0700 Subject: [PATCH 6/8] Added missing RXPowerSaving.h --- examples/simple_room_server/MyMesh.cpp | 5 +++-- examples/simple_sensor/SensorMesh.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 779628636..3f73c6a4b 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -1,4 +1,5 @@ #include "MyMesh.h" +#include "helpers/radiolib/RXPowerSaving.h" #define REPLY_DELAY_MILLIS 1500 #define PUSH_NOTIFY_DELAY_MILLIS 2000 @@ -651,8 +652,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc _prefs.flood_max_advert = 8; _prefs.interference_threshold = 0; // disabled _prefs.cad_enabled = 0; // hardware CAD before TX (off by default; 'set cad on') - _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; - _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; + _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; // RX PowerSaving + _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; // RX PowerSaving #ifdef ROOM_PASSWORD StrHelper::strncpy(_prefs.guest_password, ROOM_PASSWORD, sizeof(_prefs.guest_password)); #endif diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 2cb120d09..e446fd3df 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -1,4 +1,5 @@ #include "SensorMesh.h" +#include "helpers/radiolib/RXPowerSaving.h" /* ------------------------------ Config -------------------------------- */ @@ -730,8 +731,8 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise _prefs.flood_max = 64; _prefs.interference_threshold = 0; // disabled _prefs.cad_enabled = 0; // hardware CAD before TX (off by default; 'set cad on') - _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; - _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; + _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; // RX PowerSaving + _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; // RX PowerSaving // GPS defaults _prefs.gps_enabled = 0; From 14a7f5233febbc620450e8a97f74a82f6183f6cd Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Mon, 10 Aug 2026 19:32:08 +0700 Subject: [PATCH 7/8] Final PS 17 on PS16 branch --- build-iotthinks.sh | 50 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/build-iotthinks.sh b/build-iotthinks.sh index 85d681bda..61bd96b22 100644 --- a/build-iotthinks.sh +++ b/build-iotthinks.sh @@ -3,12 +3,13 @@ export FIRMWARE_VERSION="PowerSaving17" ############# Repeaters ############# # Commonly-used boards -## ESP32 - 17 boards +## ESP32 - 18 boards sh build.sh build-firmware \ Heltec_ct62_repeater \ Heltec_E290_repeater \ Heltec_v3_repeater \ heltec_v4_repeater \ +heltec_v4_r8_repeater \ heltec_tracker_v2_repeater \ Heltec_Wireless_Paper_repeater \ Heltec_Wireless_Tracker_repeater \ @@ -18,22 +19,24 @@ LilyGo_TBeam_1W_repeater \ Station_G2_repeater \ T_Beam_S3_Supreme_SX1262_repeater \ Tbeam_SX1262_repeater \ +ThinkNode_M5_Repeater \ Xiao_C3_repeater \ Xiao_C6_repeater_ \ Xiao_S3_repeater \ Xiao_S3_WIO_repeater -## NRF52 - 21 boards +## NRF52 - 22 boards sh build.sh build-firmware \ GAT562_30S_Mesh_Kit_repeater \ GAT562_Mesh_Tracker_Pro_repeater \ Heltec_mesh_solar_repeater \ Heltec_t096_repeater \ -Heltec_t1_repeater \ Heltec_t114_repeater \ +Heltec_t1_repeater \ ikoka_nano_nrf_22dbm_repeater \ ikoka_nano_nrf_30dbm_repeater \ ikoka_nano_nrf_33dbm_repeater \ +LilyGo_T-Echo_Card_repeater \ LilyGo_T-Echo_repeater \ ProMicro_repeater \ RAK_3401_repeater \ @@ -54,10 +57,11 @@ LilyGo_TLora_V2_1_1_6_repeater \ Tbeam_SX1276_repeater ############# Room Server ############# -# ESP32 - 7 boards +# ESP32 - 8 boards sh build.sh build-firmware \ Heltec_v3_room_server \ heltec_v4_room_server \ +heltec_v4_r8_room_server \ heltec_tracker_v2_room_server \ Heltec_Wireless_Paper_room_server \ Heltec_WSL3_room_server \ @@ -75,13 +79,15 @@ WioTrackerL1_room_server \ Xiao_nrf52_room_server ############# Companions BLE ############# -# NRF52 - 15 boards +# NRF52 - 17 boards sh build.sh build-firmware \ Heltec_t096_companion_radio_ble_femon \ Heltec_t096_companion_radio_ble_femoff \ Heltec_t1_companion_radio_ble \ Heltec_t114_companion_radio_ble \ +LilyGo_T-Echo_Card_companion_radio_ble \ LilyGo_T-Echo_companion_radio_ble \ +ProMicro_companion_radio_ble \ RAK_3401_companion_radio_ble \ RAK_4631_companion_radio_ble \ RAK_WisMesh_Tag_companion_radio_ble \ @@ -94,15 +100,16 @@ WioTrackerL1_companion_radio_ble \ Xiao_nrf52_companion_radio_ble ############# Companions BLE PS ############# -# ESP32 - 19 boards +# ESP32 - 21 boards sh build.sh build-firmware \ Heltec_ct62_companion_radio_ble_ps \ heltec_tracker_v2_companion_radio_ble_ps \ Heltec_v2_companion_radio_ble_ps \ Heltec_v3_companion_radio_ble_ps \ heltec_v4_3_companion_radio_ble_ps_femoff \ -heltec_v4_companion_radio_ble_ps \ +heltec_v4_companion_radio_ble_ps_femon \ heltec_v4_expansionkit_tft_companion_radio_ble_ps \ +heltec_v4_r8_companion_radio_ble_ps \ Heltec_Wireless_Paper_companion_radio_ble_ps \ Heltec_Wireless_Tracker_companion_radio_ble_ps \ Heltec_WSL3_companion_radio_ble_ps \ @@ -112,28 +119,49 @@ LilyGo_TLora_V2_1_1_6_companion_radio_ble_ps \ T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps \ Tbeam_SX1262_companion_radio_ble_ps \ Tbeam_SX1276_companion_radio_ble_ps \ +ThinkNode_M5_companion_radio_ble_ps \ Xiao_C3_companion_radio_ble_ps \ Xiao_S3_companion_radio_ble_ps \ Xiao_S3_WIO_companion_radio_ble_ps ############# Companions USB ############# sh build.sh build-firmware \ -Heltec_t096_companion_radio_usb +Heltec_t096_companion_radio_usb \ +heltec_v4_companion_radio_usb \ +heltec_v4_companion_radio_usb_ps_femoff \ +heltec_v4_companion_radio_usb_ps_femon ############# Sample builds ############# -# 14 boards +# 24 boards sh build.sh build-firmware \ Heltec_t096_companion_radio_ble_femon \ Heltec_t096_companion_radio_ble_femoff \ +Heltec_t096_companion_radio_usb \ Heltec_t096_repeater \ +Heltec_t114_companion_radio_ble \ +Heltec_t114_repeater \ Heltec_v3_companion_radio_ble_ps \ Heltec_v3_repeater \ heltec_v4_3_companion_radio_ble_ps_femoff \ -heltec_v4_companion_radio_ble_ps \ heltec_v4_repeater \ +RAK_3401_companion_radio_ble \ +RAK_3401_repeater \ RAK_4631_companion_radio_ble \ RAK_4631_repeater \ +SenseCap_Solar_companion_radio_ble \ +SenseCap_Solar_repeater \ +WioTrackerL1_companion_radio_ble \ +WioTrackerL1_repeater \ Xiao_C3_companion_radio_ble_ps \ Xiao_C3_repeater \ Xiao_C6_companion_radio_ble_ \ -Xiao_C6_repeater_ \ No newline at end of file +Xiao_C6_repeater_ \ +Xiao_nrf52_companion_radio_ble \ +Xiao_nrf52_repeater + +# 4 boards +sh build.sh build-firmware \ +heltec_v4_companion_radio_ble_ps_femon \ +heltec_v4_companion_radio_usb \ +heltec_v4_companion_radio_usb_ps_femoff \ +heltec_v4_companion_radio_usb_ps_femon \ No newline at end of file From fc660cc0616961713fd1bb830b44737e5af13d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Doma=C5=84ski?= Date: Mon, 10 Aug 2026 14:50:34 +0200 Subject: [PATCH 8/8] Fix RX_EN handling during RX power saving --- docs/cli_commands.md | 6 ++++++ examples/simple_repeater/MyMesh.cpp | 17 +++++++++++++++ examples/simple_repeater/MyMesh.h | 3 +++ src/helpers/CommonCLI.cpp | 23 ++++++++++++++++++++ src/helpers/CommonCLI.h | 7 ++++++ src/helpers/radiolib/CustomSX1262.h | 25 +++++++++++++++++++++- src/helpers/radiolib/CustomSX1262Wrapper.h | 23 ++++++++++++++++++++ src/helpers/radiolib/RadioLibWrappers.h | 3 +++ 8 files changed, 106 insertions(+), 1 deletion(-) diff --git a/docs/cli_commands.md b/docs/cli_commands.md index 9a19dcc27..0cbd518f8 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md @@ -280,7 +280,9 @@ This document provides an overview of CLI commands that can be sent to MeshCore #### View or change RX duty-cycle power saving **Usage:** - `get radio.rxps` +- `get radio.rxps.rfrx_disabled` - `get rxps.wd` +- `set radio.rxps.rfrx_disabled ` - `set radio.rxps off` - `set radio.rxps on` - `set radio.rxps conservative` @@ -294,9 +296,13 @@ This document provides an overview of CLI commands that can be sent to MeshCore - `rx_us`, `sleep_us`: Receive and sleep durations in microseconds (`1000`-`30000000`). - `level`: A power-saving level from `1` (most conservative) to `10` (least power saving). - `preamble`: LoRa preamble length in symbols; `16` or `32`. +- `state`: `on` or `off`. **Notes:** - `get rxps.wd` reports the RXPS watchdog's soft and hard recovery counts. +- `radio.rxps.rfrx_disabled` is a runtime-only diagnostic setting and resets to `off` after reboot. +- Its default `off` state keeps the host-controlled SX1262 receive path enabled during RX duty-cycle mode. Setting it to `on` reproduces the old missing-RF_RX behavior and can significantly reduce receive sensitivity, making remote commands harder to receive. +- `radio.rxps.rfrx_disabled` is supported only on SX1262 targets with a host-controlled RX enable pin. - `on` and `conservative` select level `1` with a 16-symbol preamble; `balanced` selects level `5` with a 16-symbol preamble. - Level-based settings automatically recalculate their timings when the spreading factor or bandwidth changes. Custom ` ` timings remain fixed. - The selected mode is applied immediately, persisted, and restored after reboot. diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 8502834c7..7971d66dc 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1076,6 +1076,23 @@ bool MyMesh::setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) { ok ? "" : " unsupported"); return ok; } + +bool MyMesh::supportsRxPowerSavingRfRxDisable() const { + return radio_driver.supportsRxPowerSavingRfRxDisable(); +} + +bool MyMesh::setRxPowerSavingRfRxDisabled(bool disabled) { + bool ok = radio_driver.setRxPowerSavingRfRxDisabled(disabled); + MESH_DEBUG_PRINTLN("RX Power Saving RF_RX control: %s, %s", + disabled ? "disabled" : "enabled", + ok ? "accepted" : "unsupported"); + return ok; +} + +bool MyMesh::isRxPowerSavingRfRxDisabled() const { + return radio_driver.isRxPowerSavingRfRxDisabled(); +} + void MyMesh::getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) { *soft = radio_driver.getRxPsWatchdogSoftCount(); *hard = radio_driver.getRxPsWatchdogHardCount(); diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 25e53795b..e58443529 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -220,6 +220,9 @@ public: void dumpLogFile() override; void setTxPower(int8_t power_dbm) override; bool setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) override; + bool supportsRxPowerSavingRfRxDisable() const override; + bool setRxPowerSavingRfRxDisabled(bool disabled) override; + bool isRxPowerSavingRfRxDisabled() const override; void getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) override; void formatNeighborsReply(char *reply) override; void removeNeighbor(const uint8_t* pubkey, int key_len) override; diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index a32051e38..577806d75 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -761,6 +761,23 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep } else { strcpy(reply, "Error: state must be on or off"); } + } else if (strncmp(config, "radio.rxps.rfrx_disabled ", 25) == 0) { + const char* value = &config[25]; + bool disabled; + if (strcmp(value, "on") == 0) { + disabled = true; + } else if (strcmp(value, "off") == 0) { + disabled = false; + } else { + strcpy(reply, "Error: state must be on or off"); + return; + } + + if (!_callbacks->setRxPowerSavingRfRxDisabled(disabled)) { + strcpy(reply, "Error: unsupported"); + } else { + sprintf(reply, "OK - radio.rxps.rfrx_disabled %s", disabled ? "on" : "off"); + } } else if (memcmp(config, "radio.rxps ", 11) == 0) { const char* value = &config[11]; uint8_t enable = _prefs->rx_powersaving_enabled; @@ -1121,6 +1138,12 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep } else { sprintf(reply, "> %s", _board->isLoRaFemLnaEnabled() ? "on" : "off"); } + } else if (strcmp(config, "radio.rxps.rfrx_disabled") == 0) { + if (!_callbacks->supportsRxPowerSavingRfRxDisable()) { + strcpy(reply, "Error: unsupported"); + } else { + sprintf(reply, "> %s", _callbacks->isRxPowerSavingRfRxDisabled() ? "on" : "off"); + } } else if (memcmp(config, "radio.rxps", 10) == 0) { ensureRxPowerSavingDefaults(_prefs); sprintf(reply, "> %s,%lu,%lu", _prefs->rx_powersaving_enabled ? "on" : "off", diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 6ec5aa013..7f60903df 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -137,6 +137,13 @@ public: return !enable; }; + virtual bool supportsRxPowerSavingRfRxDisable() const { return false; } + virtual bool setRxPowerSavingRfRxDisabled(bool disabled) { + (void)disabled; + return false; + } + virtual bool isRxPowerSavingRfRxDisabled() const { return false; } + virtual void getRxPsWatchdogCounts(uint32_t* soft, uint32_t* hard) { *soft = 0; *hard = 0; }; diff --git a/src/helpers/radiolib/CustomSX1262.h b/src/helpers/radiolib/CustomSX1262.h index f24604e85..7bf4902fb 100644 --- a/src/helpers/radiolib/CustomSX1262.h +++ b/src/helpers/radiolib/CustomSX1262.h @@ -6,6 +6,8 @@ #define SX126X_IRQ_PREAMBLE_DETECTED 0x04 class CustomSX1262 : public SX1262 { + bool _rx_ps_rf_rx_disabled = false; + public: CustomSX1262(Module *mod) : SX1262(mod) { } @@ -86,6 +88,27 @@ class CustomSX1262 : public SX1262 { return true; // success } + int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, + RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, + RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK) { + int16_t state = SX1262::startReceiveDutyCycle(rxPeriod, sleepPeriod, irqFlags, irqMask); + if (state == RADIOLIB_ERR_NONE && !_rx_ps_rf_rx_disabled) { + // RadioLib stages RX duty-cycle through standby, which leaves a + // host-controlled RXEN switch in IDLE. Keep the receive path enabled + // while the SX1262 alternates between its RX and sleep windows. + this->mod->setRfSwitchState(Module::MODE_RX); + } + return state; + } + + void setRxPowerSavingRfRxDisabled(bool disabled) { + _rx_ps_rf_rx_disabled = disabled; + } + + bool isRxPowerSavingRfRxDisabled() const { + return _rx_ps_rf_rx_disabled; + } + // BUSY high means the chip is asleep (RX duty-cycle sleep window) or mid // command; any SPI access would stall until the chip's next listen window. bool isChipBusy() { @@ -124,4 +147,4 @@ class CustomSX1262 : public SX1262 { readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1); return (rxGain == RADIOLIB_SX126X_RX_GAIN_BOOSTED); } -}; \ No newline at end of file +}; diff --git a/src/helpers/radiolib/CustomSX1262Wrapper.h b/src/helpers/radiolib/CustomSX1262Wrapper.h index 1c9c0ab68..bf3e50950 100644 --- a/src/helpers/radiolib/CustomSX1262Wrapper.h +++ b/src/helpers/radiolib/CustomSX1262Wrapper.h @@ -41,6 +41,29 @@ public: bool supportsRxPowerSaving() const override { return true; } + bool supportsRxPowerSavingRfRxDisable() const override { + #if defined(SX126X_RXEN) + return SX126X_RXEN != RADIOLIB_NC; + #else + return false; + #endif + } + + bool setRxPowerSavingRfRxDisabled(bool disabled) override { + if (!supportsRxPowerSavingRfRxDisable()) return false; + + if (_rx_ps_armed) stopReceiveDutyCycle(); + ((CustomSX1262 *)_radio)->setRxPowerSavingRfRxDisabled(disabled); + + // Re-arm the configured receive mode immediately without disturbing an + // unread RX interrupt or an in-flight transmission. + return setRxPowerSaving(_rx_ps_enabled, _rx_ps_rx_us, _rx_ps_sleep_us); + } + + bool isRxPowerSavingRfRxDisabled() const override { + return ((CustomSX1262 *)_radio)->isRxPowerSavingRfRxDisabled(); + } + protected: int startReceiveMode() override { if (_rx_ps_armed) { diff --git a/src/helpers/radiolib/RadioLibWrappers.h b/src/helpers/radiolib/RadioLibWrappers.h index 24f6da711..64f3fc7ef 100644 --- a/src/helpers/radiolib/RadioLibWrappers.h +++ b/src/helpers/radiolib/RadioLibWrappers.h @@ -101,6 +101,9 @@ public: void onSendFinished() override; bool isInRecvMode() const override; bool setRxPowerSaving(bool enabled, uint32_t rx_us, uint32_t sleep_us) override; + virtual bool supportsRxPowerSavingRfRxDisable() const { return false; } + virtual bool setRxPowerSavingRfRxDisabled(bool) { return false; } + virtual bool isRxPowerSavingRfRxDisabled() const { return false; } bool isChannelActive(); bool isReceiving() override {