From c0cb57be5c5c08774549cd7ee304eae8755b5af7 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Thu, 27 Mar 2025 21:28:06 +1100 Subject: [PATCH] * refactor: rtc_clock now defined by variants/*/target modules --- examples/companion_radio/main.cpp | 2 +- examples/simple_repeater/main.cpp | 12 ------------ examples/simple_room_server/main.cpp | 13 ------------- examples/simple_secure_chat/main.cpp | 2 +- variants/generic_espnow/target.cpp | 4 ++++ variants/generic_espnow/target.h | 1 + variants/heltec_v2/target.cpp | 6 ++++++ variants/heltec_v2/target.h | 2 ++ variants/heltec_v3/target.cpp | 6 ++++++ variants/heltec_v3/target.h | 2 ++ variants/lilygo_t3s3/target.cpp | 6 ++++++ variants/lilygo_t3s3/target.h | 2 ++ variants/lilygo_tbeam/target.cpp | 6 ++++++ variants/lilygo_tbeam/target.h | 2 ++ variants/lilygo_tlora_v2_1/target.cpp | 6 ++++++ variants/lilygo_tlora_v2_1/target.h | 2 ++ variants/promicro/target.cpp | 6 ++++++ variants/promicro/target.h | 2 ++ variants/rak4631/target.cpp | 6 ++++++ variants/rak4631/target.h | 2 ++ variants/station_g2/target.cpp | 6 ++++++ variants/station_g2/target.h | 2 ++ variants/t1000-e/target.cpp | 6 ++++++ variants/t1000-e/target.h | 2 ++ variants/t114/target.cpp | 6 ++++++ variants/t114/target.h | 2 ++ variants/techo/target.cpp | 6 ++++++ variants/techo/target.h | 2 ++ variants/xiao_c3/target.cpp | 6 ++++++ variants/xiao_c3/target.h | 2 ++ variants/xiao_s3_wio/target.cpp | 6 ++++++ variants/xiao_s3_wio/target.h | 2 ++ 32 files changed, 111 insertions(+), 27 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 02afdafa..f9171c0e 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -1422,7 +1422,7 @@ public: StdRNG fast_rng; SimpleMeshTables tables; -MyMesh the_mesh(radio_driver, fast_rng, *new VolatileRTCClock(), tables); +MyMesh the_mesh(radio_driver, fast_rng, *new VolatileRTCClock(), tables); // TODO: test with 'rtc_clock' in target.cpp void halt() { while (1) ; diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index dca1f631..67c58068 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -600,13 +599,6 @@ public: StdRNG fast_rng; SimpleMeshTables tables; -#ifdef ESP32 -ESP32RTCClock fallback_clock; -#else -VolatileRTCClock fallback_clock; -#endif -AutoDiscoverRTCClock rtc_clock(fallback_clock); - MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables); void halt() { @@ -620,10 +612,6 @@ void setup() { delay(1000); board.begin(); -#ifdef ESP32 - fallback_clock.begin(); -#endif - rtc_clock.begin(Wire); if (!radio_init()) { halt(); } diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 6d214a78..8a8232be 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -823,14 +822,6 @@ public: StdRNG fast_rng; SimpleMeshTables tables; - -#ifdef ESP32 -ESP32RTCClock fallback_clock; -#else -VolatileRTCClock fallback_clock; -#endif -AutoDiscoverRTCClock rtc_clock(fallback_clock); - MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables); void halt() { @@ -844,10 +835,6 @@ void setup() { delay(1000); board.begin(); -#ifdef ESP32 - fallback_clock.begin(); -#endif - rtc_clock.begin(Wire); if (!radio_init()) { halt(); } diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index 59072dc4..4b71811c 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -523,7 +523,7 @@ public: StdRNG fast_rng; SimpleMeshTables tables; -MyMesh the_mesh(radio_driver, fast_rng, *new VolatileRTCClock(), tables); +MyMesh the_mesh(radio_driver, fast_rng, *new VolatileRTCClock(), tables); // TODO: test with 'rtc_clock' in target.cpp void halt() { while (1) ; diff --git a/variants/generic_espnow/target.cpp b/variants/generic_espnow/target.cpp index b64383c7..a92b88ac 100644 --- a/variants/generic_espnow/target.cpp +++ b/variants/generic_espnow/target.cpp @@ -6,7 +6,11 @@ ESP32Board board; ESPNOWRadio radio_driver; +ESP32RTCClock rtc_clock; + bool radio_init() { + rtc_clock.begin(); + // NOTE: radio_driver.begin() is called by Dispatcher::begin(), so not needed here return true; // success } diff --git a/variants/generic_espnow/target.h b/variants/generic_espnow/target.h index 095e787d..16eeaa2e 100644 --- a/variants/generic_espnow/target.h +++ b/variants/generic_espnow/target.h @@ -5,6 +5,7 @@ extern ESP32Board board; extern ESPNOWRadio radio_driver; +extern ESP32RTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/heltec_v2/target.cpp b/variants/heltec_v2/target.cpp index 87f3fa9d..284fa600 100644 --- a/variants/heltec_v2/target.cpp +++ b/variants/heltec_v2/target.cpp @@ -12,11 +12,17 @@ HeltecV2Board board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #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); #endif diff --git a/variants/heltec_v2/target.h b/variants/heltec_v2/target.h index 8480c5b7..bfdb6132 100644 --- a/variants/heltec_v2/target.h +++ b/variants/heltec_v2/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern HeltecV2Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/heltec_v3/target.cpp b/variants/heltec_v3/target.cpp index 5cc5300d..768cd84c 100644 --- a/variants/heltec_v3/target.cpp +++ b/variants/heltec_v3/target.cpp @@ -12,11 +12,17 @@ HeltecV3Board board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/heltec_v3/target.h b/variants/heltec_v3/target.h index 075626a1..04fec40c 100644 --- a/variants/heltec_v3/target.h +++ b/variants/heltec_v3/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern HeltecV3Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/lilygo_t3s3/target.cpp b/variants/lilygo_t3s3/target.cpp index ac19506a..8e8b8e75 100644 --- a/variants/lilygo_t3s3/target.cpp +++ b/variants/lilygo_t3s3/target.cpp @@ -12,11 +12,17 @@ ESP32Board board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/lilygo_t3s3/target.h b/variants/lilygo_t3s3/target.h index dfd76c96..8eed467f 100644 --- a/variants/lilygo_t3s3/target.h +++ b/variants/lilygo_t3s3/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern ESP32Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/lilygo_tbeam/target.cpp b/variants/lilygo_tbeam/target.cpp index 5e63dcae..0852d69c 100644 --- a/variants/lilygo_tbeam/target.cpp +++ b/variants/lilygo_tbeam/target.cpp @@ -12,11 +12,17 @@ TBeamBoard board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #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); #endif diff --git a/variants/lilygo_tbeam/target.h b/variants/lilygo_tbeam/target.h index 070e5300..1fd68a84 100644 --- a/variants/lilygo_tbeam/target.h +++ b/variants/lilygo_tbeam/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern TBeamBoard board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/lilygo_tlora_v2_1/target.cpp b/variants/lilygo_tlora_v2_1/target.cpp index 4090ca52..740e0561 100644 --- a/variants/lilygo_tlora_v2_1/target.cpp +++ b/variants/lilygo_tlora_v2_1/target.cpp @@ -8,11 +8,17 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DI WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8); if (status != RADIOLIB_ERR_NONE) { diff --git a/variants/lilygo_tlora_v2_1/target.h b/variants/lilygo_tlora_v2_1/target.h index 610e7977..5c0910cb 100644 --- a/variants/lilygo_tlora_v2_1/target.h +++ b/variants/lilygo_tlora_v2_1/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern LilyGoTLoraBoard board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/promicro/target.cpp b/variants/promicro/target.cpp index fb282b19..9958c9eb 100644 --- a/variants/promicro/target.cpp +++ b/variants/promicro/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include FaketecBoard board; @@ -7,11 +8,16 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU WRAPPER_CLASS radio_driver(radio, board); +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/promicro/target.h b/variants/promicro/target.h index b0c69eeb..b66020d4 100644 --- a/variants/promicro/target.h +++ b/variants/promicro/target.h @@ -6,9 +6,11 @@ #include #include #include +#include extern FaketecBoard board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp index 3a25be56..17e76532 100644 --- a/variants/rak4631/target.cpp +++ b/variants/rak4631/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include RAK4631Board board; @@ -7,11 +8,16 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU WRAPPER_CLASS radio_driver(radio, board); +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/rak4631/target.h b/variants/rak4631/target.h index c36cd939..cd32c12d 100644 --- a/variants/rak4631/target.h +++ b/variants/rak4631/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern RAK4631Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/station_g2/target.cpp b/variants/station_g2/target.cpp index 5017ceaa..988ac4fc 100644 --- a/variants/station_g2/target.cpp +++ b/variants/station_g2/target.cpp @@ -12,11 +12,17 @@ StationG2Board board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/station_g2/target.h b/variants/station_g2/target.h index 9e52b24a..96fd5095 100644 --- a/variants/station_g2/target.h +++ b/variants/station_g2/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern StationG2Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/t1000-e/target.cpp b/variants/t1000-e/target.cpp index e71e5d44..afc0eadb 100644 --- a/variants/t1000-e/target.cpp +++ b/variants/t1000-e/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include T1000eBoard board; @@ -7,6 +8,9 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU WRAPPER_CLASS radio_driver(radio, board); +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif @@ -34,6 +38,8 @@ static const Module::RfSwitchMode_t rfswitch_table[] = { #endif bool radio_init() { + rtc_clock.begin(Wire); + #ifdef LR11X0_DIO3_TCXO_VOLTAGE float tcxo = LR11X0_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/t1000-e/target.h b/variants/t1000-e/target.h index b2331cab..7ffafded 100644 --- a/variants/t1000-e/target.h +++ b/variants/t1000-e/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern T1000eBoard board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/t114/target.cpp b/variants/t114/target.cpp index d474e25c..07a60688 100644 --- a/variants/t114/target.cpp +++ b/variants/t114/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include T114Board board; @@ -7,11 +8,16 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU WRAPPER_CLASS radio_driver(radio, board); +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/t114/target.h b/variants/t114/target.h index a6f98dbb..8d80c0ec 100644 --- a/variants/t114/target.h +++ b/variants/t114/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern T114Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/techo/target.cpp b/variants/techo/target.cpp index c5522799..ecffc37a 100644 --- a/variants/techo/target.cpp +++ b/variants/techo/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include TechoBoard board; @@ -7,11 +8,16 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU WRAPPER_CLASS radio_driver(radio, board); +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/techo/target.h b/variants/techo/target.h index 921657ff..4a66f24e 100644 --- a/variants/techo/target.h +++ b/variants/techo/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern TechoBoard board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/xiao_c3/target.cpp b/variants/xiao_c3/target.cpp index 2d2098f5..bab602cc 100644 --- a/variants/xiao_c3/target.cpp +++ b/variants/xiao_c3/target.cpp @@ -12,11 +12,17 @@ XiaoC3Board board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/xiao_c3/target.h b/variants/xiao_c3/target.h index d4b02364..c0a1eb32 100644 --- a/variants/xiao_c3/target.h +++ b/variants/xiao_c3/target.h @@ -6,9 +6,11 @@ #include #include #include +#include extern XiaoC3Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed(); diff --git a/variants/xiao_s3_wio/target.cpp b/variants/xiao_s3_wio/target.cpp index ac19506a..8e8b8e75 100644 --- a/variants/xiao_s3_wio/target.cpp +++ b/variants/xiao_s3_wio/target.cpp @@ -12,11 +12,17 @@ ESP32Board board; WRAPPER_CLASS radio_driver(radio, board); +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + #ifndef LORA_CR #define LORA_CR 5 #endif bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + #ifdef SX126X_DIO3_TCXO_VOLTAGE float tcxo = SX126X_DIO3_TCXO_VOLTAGE; #else diff --git a/variants/xiao_s3_wio/target.h b/variants/xiao_s3_wio/target.h index dfd76c96..8eed467f 100644 --- a/variants/xiao_s3_wio/target.h +++ b/variants/xiao_s3_wio/target.h @@ -5,9 +5,11 @@ #include #include #include +#include extern ESP32Board board; extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; bool radio_init(); uint32_t radio_get_rng_seed();