From c06ab5fc490c3cbead3502766ba8d887d6b21a31 Mon Sep 17 00:00:00 2001 From: nogood Date: Fri, 3 Jul 2026 03:32:33 +0300 Subject: [PATCH 1/2] Added DIY_S3 E22P SuperMini board support --- boards/esp32-s3-supermini.json | 57 +++++++++++ .../DIYS3E22PSuperMiniBoard.cpp | 74 ++++++++++++++ .../DIYS3E22PSuperMiniBoard.h | 34 +++++++ variants/diy_s3_e22p_supermini/pins_arduino.h | 23 +++++ variants/diy_s3_e22p_supermini/platformio.ini | 98 +++++++++++++++++++ variants/diy_s3_e22p_supermini/target.cpp | 65 ++++++++++++ variants/diy_s3_e22p_supermini/target.h | 33 +++++++ variants/diy_s3_e22p_supermini/variant.h | 67 +++++++++++++ 8 files changed, 451 insertions(+) create mode 100644 boards/esp32-s3-supermini.json create mode 100644 variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.cpp create mode 100644 variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.h create mode 100644 variants/diy_s3_e22p_supermini/pins_arduino.h create mode 100644 variants/diy_s3_e22p_supermini/platformio.ini create mode 100644 variants/diy_s3_e22p_supermini/target.cpp create mode 100644 variants/diy_s3_e22p_supermini/target.h create mode 100644 variants/diy_s3_e22p_supermini/variant.h diff --git a/boards/esp32-s3-supermini.json b/boards/esp32-s3-supermini.json new file mode 100644 index 00000000..2fe9fb32 --- /dev/null +++ b/boards/esp32-s3-supermini.json @@ -0,0 +1,57 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-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", + "psram_type": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "ESP32-S3-SuperMini (4MB Quad, 2MB Quad PSRAM)", + "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://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.cpp b/variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.cpp new file mode 100644 index 00000000..0db11877 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.cpp @@ -0,0 +1,74 @@ +#include "DIYS3E22PSuperMiniBoard.h" + +void DIYS3E22PSuperMiniBoard::begin() { + ESP32Board::begin(); + + 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)) { // received a LoRa packet (while in deep sleep) + 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); + } + if (!radio_powered) { + // Power on radio module (must be done before radio init) + pinMode(P_LORA_EN, OUTPUT); + digitalWrite(P_LORA_EN, HIGH); + radio_powered = true; + delay(10); // Allow radio to power up + } +} + +void DIYS3E22PSuperMiniBoard::enterDeepSleep(uint32_t secs, int pin_wake_btn) { + esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); + + // Make sure the DIO1, NSS and LORA_EN GPIOs are hold on required levels during deep sleep + 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); + rtc_gpio_hold_en((gpio_num_t)P_LORA_EN); + + if (pin_wake_btn < 0) { + esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet + } else { + esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn + } + + if (secs > 0) { + esp_sleep_enable_timer_wakeup(secs * 1000000); + } + + // Finally set ESP32 into sleep + esp_deep_sleep_start(); // CPU halts here and never returns! +} + +void DIYS3E22PSuperMiniBoard::powerOff() { + // Turn off radio power + digitalWrite(P_LORA_EN, LOW); + radio_powered = false; + + enterDeepSleep(0); +} + +//uint16_t DIYS3E22PSuperMiniBoard::getBattMilliVolts() override { +// return 0; +//} +uint16_t DIYS3E22PSuperMiniBoard::getBattMilliVolts() { + analogReadResolution(10); + + uint32_t raw = 0; + for (int i = 0; i < 8; i++) { + raw += analogRead(PIN_VBAT_READ); + } + raw = raw / 8; + + return (adc_mult * (3.3 / 1024.0) * raw) * 1000; +} + +const char* DIYS3E22PSuperMiniBoard::getManufacturerName() const { + return "DIY_S3 E22P SuperMini"; +} \ No newline at end of file diff --git a/variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.h b/variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.h new file mode 100644 index 00000000..7533eb23 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include + +#ifndef ADC_MULTIPLIER + #define ADC_MULTIPLIER 2.110 +#endif + +class DIYS3E22PSuperMiniBoard : public ESP32Board { + +protected: + float adc_mult = ADC_MULTIPLIER; + +private: + bool radio_powered = false; + +public: + void begin(); + 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/diy_s3_e22p_supermini/pins_arduino.h b/variants/diy_s3_e22p_supermini/pins_arduino.h new file mode 100644 index 00000000..6d19af96 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/pins_arduino.h @@ -0,0 +1,23 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// Serial (USB CDC) +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +// I2C for OLED and sensors +static const uint8_t SDA = 6; +static const uint8_t SCL = 7; + +// Default SPI mapped to Radio/SD +static const uint8_t SS = 8; // LoRa CS +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/variants/diy_s3_e22p_supermini/platformio.ini b/variants/diy_s3_e22p_supermini/platformio.ini new file mode 100644 index 00000000..683fedb1 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/platformio.ini @@ -0,0 +1,98 @@ +[DIY_S3_E22P_SuperMini] +extends = esp32_base +board = esp32-s3-supermini +build_flags = + ${esp32_base.build_flags} + -I variants/diy_s3_e22p_supermini + -D DIY_S3_E22P_SUPERMINI + -D P_LORA_DIO_1=1 + -D P_LORA_BUSY=13 + -D P_LORA_RESET=12 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 + -D P_LORA_SCLK=9 + -D P_LORA_NSS=8 + -D P_LORA_EN=5 + -D PIN_USER_BTN=0 + -D PIN_VBAT_READ=3 +; -D P_LORA_TX_LED=48 +; -D PIN_STATUS_LED=48 + -D P_LORA_TX_NEOPIXEL_LED=48 +; -D HAS_NEOPIXEL +; -D NEOPIXEL_COUNT=1 +; -D NEOPIXEL_DATA=48 +; -D NEOPIXEL_TYPE=NEO_GRB+NEO_KHZ800 + -D SX126X_REGISTER_PATCH=1 + -D SX126X_RXEN=RADIOLIB_NC + -D SX126X_TXEN=RADIOLIB_NC + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 + -D SX126X_CURRENT_LIMIT=140 + -D USE_SX1262 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D LORA_TX_POWER=10 + -D MAX_LORA_TX_POWER=16 ; Allow setting up to 16dBm in companion radio + -D SX126X_RX_BOOSTED_GAIN=1 +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/diy_s3_e22p_supermini> + + +lib_deps = + ${esp32_base.lib_deps} + +[DIY_S3_E22P_SuperMini_oled] +extends = DIY_S3_E22P_SuperMini +build_flags = + ${DIY_S3_E22P_SuperMini.build_flags} + -D DIY_S3_E22P_SUPERMINI_OLED + -D PIN_BOARD_SDA=6 + -D PIN_BOARD_SCL=7 +# -D PIN_OLED_RESET=2 + -D DISPLAY_CLASS=SSD1306Display +build_src_filter= ${DIY_S3_E22P_SuperMini.build_src_filter} + + +lib_deps = + ${DIY_S3_E22P_SuperMini.lib_deps} + adafruit/Adafruit SSD1306 @ ^2.5.13 + +[env:DIY_S3_E22P_SuperMini_repeater] +extends = DIY_S3_E22P_SuperMini +build_flags = + ${DIY_S3_E22P_SuperMini.build_flags} + -D ADVERT_NAME='"DIY_S3 E22P SuperMini Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_S3_E22P_SuperMini.build_src_filter} + +<../examples/simple_repeater> +lib_deps = + ${DIY_S3_E22P_SuperMini.lib_deps} + ${esp32_ota.lib_deps} + +[env:DIY_S3_E22P_SuperMini_mqtt_repeater] +extends = DIY_S3_E22P_SuperMini +board_build.partitions = min_spiffs.csv +build_flags = + ${DIY_S3_E22P_SuperMini.build_flags} + -D ADVERT_NAME='"DIY_S3 E22P SuperMini Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 + -D WITH_MQTT_UPLINK=1 + -D MQTT_DEBUG=1 +; -D WIFI_SSID='"myssid"' +; -D WIFI_PWD='"mypwd"' + -D MQTT_DEFAULT_IATA='"UNSET"' + -D CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=1 +build_src_filter = ${DIY_S3_E22P_SuperMini.build_src_filter} + +<../examples/simple_repeater> + + + + +lib_deps = + ${DIY_S3_E22P_SuperMini.lib_deps} + ${esp32_ota.lib_deps} + diff --git a/variants/diy_s3_e22p_supermini/target.cpp b/variants/diy_s3_e22p_supermini/target.cpp new file mode 100644 index 00000000..0c5777d8 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/target.cpp @@ -0,0 +1,65 @@ +#include +#include "target.h" + +DIYS3E22PSuperMiniBoard 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); + +SensorManager sensors; + +#if defined(DISPLAY_CLASS) + DISPLAY_CLASS display; + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); +#endif + +bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + +#if defined(P_LORA_SCLK) + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); + bool success = radio.std_init(&spi); +#else + bool success = radio.std_init(); +#endif + + /* Myabe it's not needed for E22P + if (success) { + // E22P has internal PA requiring longer ramp time (>800us recommended) + // RADIOLIB_SX126X_PA_RAMP_800U = 0x05 + radio.setTxParams(LORA_TX_POWER, RADIOLIB_SX126X_PA_RAMP_800U); + } + */ + return success; +} + +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(int8_t dbm) { + radio.setOutputPower(dbm); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); // create new random identity +} + diff --git a/variants/diy_s3_e22p_supermini/target.h b/variants/diy_s3_e22p_supermini/target.h new file mode 100644 index 00000000..74bb79c8 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/target.h @@ -0,0 +1,33 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include +#include "DIYS3E22PSuperMiniBoard.h" + +#if defined(DISPLAY_CLASS) + #include + #include +#endif + +extern DIYS3E22PSuperMiniBoard board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern SensorManager sensors; + +#if defined(DISPLAY_CLASS) + extern DISPLAY_CLASS display; + extern MomentaryButton user_btn; +#endif + + +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(int8_t dbm); +mesh::LocalIdentity radio_new_identity(); + diff --git a/variants/diy_s3_e22p_supermini/variant.h b/variants/diy_s3_e22p_supermini/variant.h new file mode 100644 index 00000000..7518e2c8 --- /dev/null +++ b/variants/diy_s3_e22p_supermini/variant.h @@ -0,0 +1,67 @@ +#pragma once + +// I2C for OLED display +#define I2C_SDA 6 +#define I2C_SCL 7 + +// Buttons +#define BUTTON_PIN 0 // BUTTON 1 (boot) + +// SPI (shared by LoRa and SD) +#define SPI_MOSI 10 +#define SPI_SCK 9 +#define SPI_MISO 11 +#define SPI_CS 8 + +// LoRa Radio - SX1262 with 1W PA +#define USE_SX1262 +#define LORA_SCK SPI_SCK +#define LORA_MISO SPI_MISO +#define LORA_MOSI SPI_MOSI +#define LORA_CS SPI_CS +#define LORA_RESET 12 +#define LORA_DIO1 1 +#define LORA_BUSY 13 + +// CRITICAL: Radio power enable - MUST be HIGH before lora.begin()! +// GPIO 5 connected to E22P RF_EN powers the SX1262 + LNA + PA module +#define LORA_EN 5 + +#if not defined(P_LORA_EN) +#define P_LORA_EN LORA_EN +#endif + +#if defined(USE_SX1262) +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_BUSY +#define SX126X_RESET LORA_RESET + +// RF switching configuration for E22P module +// DIO2 controls PA and LNA (via SX126X_DIO2_AS_RF_SWITCH) +// Truth table: DIO2=1,CTRL=1 -> TX (PA on, LNA off, RADIO on) +// DIO2=0,CTRL=1 -> RX (PA off, LNA on, RADIO on) +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_RXEN RADIOLIB_NC // No need to control RX_EN via MCU +#define SX126X_TXEN RADIOLIB_NC // No need to control TX_EN via MCU + +// TCXO voltage - required for radio init +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +#define SX126X_MAX_POWER 22 +#endif + +// LED +#define LED_TX 48 +#if not defined(P_LORA_TX_LED) +#define P_LORA_TX_LED LED_TX +#endif + +// PA Ramp Time - E22P requires >800us stabilization (default is 200us) +// Value 0x05 = RADIOLIB_SX126X_PA_RAMP_800U +#define SX126X_PA_RAMP_US 0x05 + +// Display - SSD1306 OLED (128x64) +#define USE_SSD1306 +#define OLED_WIDTH 128 +#define OLED_HEIGHT 64 \ No newline at end of file From eadf036040f486114f96621d112336b9cd720083 Mon Sep 17 00:00:00 2001 From: Vladislav Mironov <57950551+glutesha@users.noreply.github.com> Date: Thu, 6 Aug 2026 19:52:44 +0300 Subject: [PATCH 2/2] Move board build partitions up to the board configuration Other environments won't build without this change --- variants/diy_s3_e22p_supermini/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/diy_s3_e22p_supermini/platformio.ini b/variants/diy_s3_e22p_supermini/platformio.ini index 683fedb1..9ee13f4f 100644 --- a/variants/diy_s3_e22p_supermini/platformio.ini +++ b/variants/diy_s3_e22p_supermini/platformio.ini @@ -1,4 +1,5 @@ [DIY_S3_E22P_SuperMini] +board_build.partitions = min_spiffs.csv extends = esp32_base board = esp32-s3-supermini build_flags = @@ -74,7 +75,6 @@ lib_deps = [env:DIY_S3_E22P_SuperMini_mqtt_repeater] extends = DIY_S3_E22P_SuperMini -board_build.partitions = min_spiffs.csv build_flags = ${DIY_S3_E22P_SuperMini.build_flags} -D ADVERT_NAME='"DIY_S3 E22P SuperMini Repeater"'