Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions boards/esp32-s3-supermini.json
Original file line number Diff line number Diff line change
@@ -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"
}
74 changes: 74 additions & 0 deletions variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.cpp
Original file line number Diff line number Diff line change
@@ -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";
}
34 changes: 34 additions & 0 deletions variants/diy_s3_e22p_supermini/DIYS3E22PSuperMiniBoard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <Arduino.h>
#include <helpers/ESP32Board.h>
#include <driver/rtc_io.h>

#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;
};
23 changes: 23 additions & 0 deletions variants/diy_s3_e22p_supermini/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

#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 */
98 changes: 98 additions & 0 deletions variants/diy_s3_e22p_supermini/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[DIY_S3_E22P_SuperMini]
board_build.partitions = min_spiffs.csv
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>
+<helpers/sensors>
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}
+<helpers/ui/SSD1306Display.cpp>
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
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>
+<helpers/mqtt/*.cpp>
+<helpers/web/*.cpp>
lib_deps =
${DIY_S3_E22P_SuperMini.lib_deps}
${esp32_ota.lib_deps}

65 changes: 65 additions & 0 deletions variants/diy_s3_e22p_supermini/target.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <Arduino.h>
#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
}

33 changes: 33 additions & 0 deletions variants/diy_s3_e22p_supermini/target.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include <helpers/radiolib/RadioLibWrappers.h>
#include <DIYS3E22PSuperMiniBoard.h>
#include <helpers/radiolib/CustomSX1262Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h>
#include "DIYS3E22PSuperMiniBoard.h"

#if defined(DISPLAY_CLASS)
#include <helpers/ui/SSD1306Display.h>
#include <helpers/ui/MomentaryButton.h>
#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();

Loading