From f767fd5075628bcea3cd3a858e55e24f90caacdd Mon Sep 17 00:00:00 2001 From: lewis Date: Sat, 3 Sep 2022 23:38:40 +0800 Subject: [PATCH] Modified to be compatible with the new version of sdk, compatible with esp32s3 --- platformio.ini | 46 +++++++++++++++++++++++- src/mesh/generated/mesh.pb.h | 2 ++ src/mesh/http/WiFiAPClient.cpp | 15 +++++++- src/platform/esp32/ESP32CryptoEngine.cpp | 8 ++--- src/platform/esp32/architecture.h | 2 ++ src/sleep.cpp | 5 +++ variants/tbeam-s3/platformio.ini | 18 ++++++++++ variants/tbeam-s3/variant.h | 37 +++++++++++++++++++ 8 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 variants/tbeam-s3/platformio.ini create mode 100644 variants/tbeam-s3/variant.h diff --git a/platformio.ini b/platformio.ini index 20b319cdb..d03c75892 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,8 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam +; default_envs = tbeam +default_envs = tbeam-s3 ;default_envs = tbeam0.7 ;default_envs = heltec-v1 ;default_envs = heltec-v2.0 @@ -203,3 +204,46 @@ lib_deps = https://github.com/kokke/tiny-AES-c.git lib_ignore = mathertel/OneButton@^2.0.3 + + + +[esp32s3_base] +extends = arduino_base +platform = espressif32 +build_src_filter = + ${arduino_base.build_src_filter} - - - +upload_speed = 115200 +debug_init_break = tbreak setup + +# Remove -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL for low level BLE logging. +# See library directory for BLE logging possible values: .pio/libdeps/tbeam/NimBLE-Arduino/src/log_common/log_common.h +# This overrides the BLE logging default of LOG_LEVEL_INFO (1) from: .pio/libdeps/tbeam/NimBLE-Arduino/src/esp_nimble_cfg.h +build_flags = + ${arduino_base.build_flags} + -Wall + -Wextra + -Isrc/platform/esp32 + -lnimble -std=c++11 + -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG + -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL + -DAXP_DEBUG_PORT=Serial + -DCONFIG_BT_NIMBLE_ENABLED + -DCONFIG_NIMBLE_CPP_LOG_LEVEL=2 + -DCONFIG_BT_NIMBLE_MAX_CCCDS=20 + +lib_deps = + ${arduino_base.lib_deps} + ${networking_base.lib_deps} + ${environmental_base.lib_deps} + https://github.com/meshtastic/esp32_https_server.git + h2zero/NimBLE-Arduino@1.4.0 + arduino-libraries/NTPClient@^3.1.0 + lorol/LittleFS_esp32@^1.0.6 + ; https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460 + +lib_ignore = + segger_rtt + ESP32 BLE Arduino +platform_packages = + framework-arduinoespressif32 @ 3.20004.220825 diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index c00504c48..91a3ca831 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -73,6 +73,8 @@ typedef enum _HardwareModel { HardwareModel_M5STACK = 44, /* B&Q Consulting Station Edition G1: https://uniteng.com/wiki/doku.php?id=meshtastic:station */ HardwareModel_STATION_G1 = 45, + /* TODO: REPLACE */ + HardwareModel_TBEAM_S3_M2 = 46, /* Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. */ HardwareModel_PRIVATE_HW = 255 } HardwareModel; diff --git a/src/mesh/http/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp index 27bdb377a..830cd3ce7 100644 --- a/src/mesh/http/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -238,8 +238,10 @@ bool initWifi(bool forceSoftAP) WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); DEBUG_MSG("MY IP AP ADDRESS: %s\n", WiFi.softAPIP().toString().c_str()); +#if !CONFIG_IDF_TARGET_ESP32S3 // This is needed to improve performance. esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving +#endif dnsServer.start(53, "*", apIP); @@ -252,14 +254,19 @@ bool initWifi(bool forceSoftAP) WiFi.setHostname(ourHost); WiFi.onEvent(WiFiEvent); +#if !CONFIG_IDF_TARGET_ESP32S3 // This is needed to improve performance. esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving +#endif WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) { Serial.print("\nWiFi lost connection. Reason: "); + #if CONFIG_IDF_TARGET_ESP32S3 + Serial.println(info.wifi_sta_disconnected.reason); + wifiDisconnectReason = info.wifi_sta_disconnected.reason; + #else Serial.println(info.disconnected.reason); - /* If we are disconnected from the AP for some reason, save the error code. @@ -268,8 +275,14 @@ bool initWifi(bool forceSoftAP) https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-reason-code */ wifiDisconnectReason = info.disconnected.reason; + #endif + }, +#if CONFIG_IDF_TARGET_ESP32S3 + WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED); +#else WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); +#endif DEBUG_MSG("JOINING WIFI soon: ssid=%s\n", wifiName); wifiReconnect = new Periodic("WifiConnect", reconnectWiFi); diff --git a/src/platform/esp32/ESP32CryptoEngine.cpp b/src/platform/esp32/ESP32CryptoEngine.cpp index 2003a235b..60026c4db 100644 --- a/src/platform/esp32/ESP32CryptoEngine.cpp +++ b/src/platform/esp32/ESP32CryptoEngine.cpp @@ -1,16 +1,16 @@ #include "CryptoEngine.h" #include "configuration.h" +#if CONFIG_IDF_TARGET_ESP32S3 +#include "mbedtls/aes.h" +#else #include "crypto/includes.h" - #include "crypto/common.h" - // #include "esp_system.h" - #include "crypto/aes.h" #include "crypto/aes_wrap.h" #include "mbedtls/aes.h" - +#endif class ESP32CryptoEngine : public CryptoEngine diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index b408daf98..74b9d63a5 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -44,6 +44,8 @@ #define HW_VENDOR HardwareModel_TBEAM #elif defined(TBEAM_V07) #define HW_VENDOR HardwareModel_TBEAM0p7 +#elif defined(TBEAM_S3_M2) + #define HW_VENDOR HardwareModel_TBEAM_S3_M2 #elif defined(DIY_V1) #define HW_VENDOR HardwareModel_DIY_V1 #elif defined(RAK_11200) diff --git a/src/sleep.cpp b/src/sleep.cpp index bd908357c..57233d73d 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -284,7 +284,12 @@ void enableModemSleep() { static esp_pm_config_esp32_t esp32_config; // filled with zeros because bss + +#if CONFIG_IDF_TARGET_ESP32S3 + esp32_config.max_freq_mhz = CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ; +#else esp32_config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; +#endif esp32_config.min_freq_mhz = 20; // 10Mhz is minimum recommended esp32_config.light_sleep_enable = false; int rv = esp_pm_configure(&esp32_config); diff --git a/variants/tbeam-s3/platformio.ini b/variants/tbeam-s3/platformio.ini new file mode 100644 index 000000000..8bdf9df52 --- /dev/null +++ b/variants/tbeam-s3/platformio.ini @@ -0,0 +1,18 @@ +; The 1.0 release of the TBEAM board +[env:tbeam-s3] +extends = esp32s3_base +board = esp32-s3-devkitc-1 +lib_deps = + ${esp32s3_base.lib_deps} + lewisxhe/XPowersLib @ ^0.1.3 +build_flags = + ${esp32s3_base.build_flags} + -D TBEAM_S3_M2 + -DMBEDTLS_USE_PSA_CRYPTO + -I variants/tbeam-s3 + -DBOARD_HAS_PSRAM + -DARDUINO_USB_MODE=1 + -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_USB_DFU_ON_BOOT=1 + -DARDUINO_USB_MSC_ON_BOOT=1 + diff --git a/variants/tbeam-s3/variant.h b/variants/tbeam-s3/variant.h new file mode 100644 index 000000000..8e0616c55 --- /dev/null +++ b/variants/tbeam-s3/variant.h @@ -0,0 +1,37 @@ +// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep + +#define I2C_SDA 42 +#define I2C_SCL 41 + +#define BUTTON_PIN 43 // The middle button GPIO on the T-Beam +//#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented anywhere. +// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. + +#define LED_INVERTED 1 +// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 + +// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if +// not found then probe for SX1262 +#define USE_SX1262 +#define USE_SX1268 + +#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_RESET 5 +#define LORA_DIO1 1 // SX1262 IRQ +#define LORA_DIO2 4 // SX1262 BUSY +#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled + +#ifdef USE_SX1262 +#define SX126X_CS 10 // FIXME - we really should define LORA_CS instead +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_E22 // Not really an E22 but TTGO seems to be trying to clone that +// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface +// code) +#endif + +// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts +// and waking from light sleep +#define PMU_IRQ 40 +#define HAS_AXP2101 \ No newline at end of file