From 82b14fe07c8965c88ace0c54060c24972299eaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Feb 2023 22:54:07 +0100 Subject: [PATCH] Leaving this here in case someone ever needs int :-) --- arch/esp32/esp32c3.ini | 46 +++++++++++++++++++++++++++++++ src/mesh/http/ContentHandler.cpp | 2 +- src/modules/Modules.cpp | 2 +- src/modules/SerialModule.cpp | 2 +- src/modules/SerialModule.h | 2 +- src/platform/esp32/main-esp32.cpp | 7 +++++ src/sleep.cpp | 2 ++ 7 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 arch/esp32/esp32c3.ini diff --git a/arch/esp32/esp32c3.ini b/arch/esp32/esp32c3.ini new file mode 100644 index 000000000..08ab377df --- /dev/null +++ b/arch/esp32/esp32c3.ini @@ -0,0 +1,46 @@ +[esp32c3_base] +extends = arduino_base +platform = platformio/espressif32@^6.0.0 +build_src_filter = + ${arduino_base.build_src_filter} - - - - +upload_speed = 961200 +monitor_speed = 115200 +debug_init_break = tbreak setup +monitor_filters = esp32_exception_decoder +board_build.filesystem = littlefs + +# 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 + -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 + -DESP_OPENSSL_SUPPRESS_LEGACY_WARNING + ;-DDEBUG_HEAP + +lib_deps = + ${arduino_base.lib_deps} + ${networking_base.lib_deps} + ${environmental_base.lib_deps} + https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 + h2zero/NimBLE-Arduino@^1.4.0 + https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6 + caveman99/ESP32 Codec2@^1.0.1 + +lib_ignore = + segger_rtt + ESP32 BLE Arduino + +; customize the partition table +; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables +board_build.partitions = partition-table.csv \ No newline at end of file diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 8683f9cb1..0a93298b9 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -833,7 +833,7 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res) if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) { JSONObject thisNetwork; thisNetwork["ssid"] = new JSONValue(ssidArray); - thisNetwork["rssi"] = new JSONValue(WiFi.RSSI(i)); + thisNetwork["rssi"] = new JSONValue(int(WiFi.RSSI(i))); networkObjs.push_back(new JSONValue(thisNetwork)); } // Yield some cpu cycles to IP stack. diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 3247d02c1..30034b788 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -72,7 +72,7 @@ void setupModules() new AirQualityTelemetryModule(); } #endif -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) &&!defined(CONFIG_IDF_TARGET_ESP32C3) new SerialModule(); #endif #ifdef ARCH_ESP32 diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 5637f7eb1..b13e80015 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -44,7 +44,7 @@ */ -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #define RX_BUFFER 128 #define TIMEOUT 250 diff --git a/src/modules/SerialModule.h b/src/modules/SerialModule.h index 8c53d2064..5aa0f97b2 100644 --- a/src/modules/SerialModule.h +++ b/src/modules/SerialModule.h @@ -8,7 +8,7 @@ #include #include -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) class SerialModule : public StreamAPI, private concurrency::OSThread { diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index f6bd4f50e..4f627d270 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -178,6 +178,7 @@ void cpuDeepSleep(uint64_t msecToWake) Note: we don't isolate pins that are used for the LORA, LED, i2c, spi or the wake button */ +#if SOC_RTCIO_HOLD_SUPPORTED static const uint8_t rtcGpios[] = {/* 0, */ 2, /* 4, */ #ifndef USE_JTAG @@ -189,8 +190,10 @@ void cpuDeepSleep(uint64_t msecToWake) 36, 37 /* 38, 39 */}; + for (int i = 0; i < sizeof(rtcGpios); i++) rtc_gpio_isolate((gpio_num_t)rtcGpios[i]); +#endif // FIXME, disable internal rtc pullups/pulldowns on the non isolated pins. for inputs that we aren't using // to detect wake and in normal operation the external part drives them hard. @@ -200,7 +203,9 @@ void cpuDeepSleep(uint64_t msecToWake) #ifdef BUTTON_PIN // Only GPIOs which are have RTC functionality can be used in this bit map: 0,2,4,12-15,25-27,32-39. +#if SOC_RTCIO_HOLD_SUPPORTED uint64_t gpioMask = (1ULL << BUTTON_PIN); +#endif #ifdef BUTTON_NEED_PULLUP gpio_pullup_en((gpio_num_t)BUTTON_PIN); @@ -210,7 +215,9 @@ void cpuDeepSleep(uint64_t msecToWake) // FIXME change polarity in hw so we can wake on ANY_HIGH instead - that would allow us to use all three buttons (instead of // just the first) gpio_pullup_en((gpio_num_t)BUTTON_PIN); +#if SOC_PM_SUPPORT_EXT_WAKEUP esp_sleep_enable_ext1_wakeup(gpioMask, ESP_EXT1_WAKEUP_ALL_LOW); +#endif #endif esp_sleep_enable_timer_wakeup(msecToWake * 1000ULL); // call expects usecs diff --git a/src/sleep.cpp b/src/sleep.cpp index 77c8d7119..72d4974af 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -337,6 +337,8 @@ void enableModemSleep() esp32_config.max_freq_mhz = CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ; #elif CONFIG_IDF_TARGET_ESP32S2 esp32_config.max_freq_mhz = CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ; +#elif CONFIG_IDF_TARGET_ESP32C3 + esp32_config.max_freq_mhz = CONFIG_ESP32C3_DEFAULT_CPU_FREQ_MHZ; #else esp32_config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; #endif