From 56d7eded4db8d2ec4784b6f1083a0a563106c808 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 15 May 2023 10:16:52 +0200 Subject: [PATCH] pico w: Add soft RTC support --- src/utility/time/RTCMillis.cpp | 4 ++-- src/utility/time/RTCMillis.h | 4 ++-- src/utility/time/TimeService.cpp | 31 ++++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/utility/time/RTCMillis.cpp b/src/utility/time/RTCMillis.cpp index 419236d1..91741678 100644 --- a/src/utility/time/RTCMillis.cpp +++ b/src/utility/time/RTCMillis.cpp @@ -15,7 +15,7 @@ a commercial license, send an email to license@arduino.cc. */ -#ifdef ARDUINO_ARCH_ESP8266 +#if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W) /************************************************************************************** * INCLUDE @@ -59,4 +59,4 @@ unsigned long RTCMillis::get() return _last_rtc_update_value; } -#endif /* ARDUINO_ARCH_ESP8266 */ +#endif /* ARDUINO_ARCH_ESP8266 || ARDUINO_RASPBERRY_PI_PICO_W */ diff --git a/src/utility/time/RTCMillis.h b/src/utility/time/RTCMillis.h index 1fa7e0f4..fce881fd 100644 --- a/src/utility/time/RTCMillis.h +++ b/src/utility/time/RTCMillis.h @@ -18,7 +18,7 @@ #ifndef ARDUINO_IOT_CLOUD_RTC_MILLIS_H_ #define ARDUINO_IOT_CLOUD_RTC_MILLIS_H_ -#ifdef ARDUINO_ARCH_ESP8266 +#if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W) /************************************************************************************** * INCLUDE @@ -45,6 +45,6 @@ class RTCMillis }; -#endif /* ARDUINO_ARCH_ESP8266 */ +#endif /* ARDUINO_ARCH_ESP8266 || ARDUINO_RASPBERRY_PI_PICO_W */ #endif /* ARDUINO_IOT_CLOUD_RTC_MILLIS_H_ */ diff --git a/src/utility/time/TimeService.cpp b/src/utility/time/TimeService.cpp index b0362cf8..82f3a693 100644 --- a/src/utility/time/TimeService.cpp +++ b/src/utility/time/TimeService.cpp @@ -34,7 +34,7 @@ #include #endif -#ifdef ARDUINO_ARCH_ESP8266 +#if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W) #include "RTCMillis.h" #endif @@ -50,7 +50,7 @@ RTCZero rtc; #endif -#ifdef ARDUINO_ARCH_ESP8266 +#if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W) RTCMillis rtc; #endif @@ -90,6 +90,12 @@ void renesas_setRTC(unsigned long time); unsigned long renesas_getRTC(); #endif +#ifdef ARDUINO_RASPBERRY_PI_PICO_W +void pico_w_initRTC(); +void pico_w_setRTC(unsigned long time); +unsigned long pico_w_getRTC(); +#endif + /************************************************************************************** * DEFINES **************************************************************************************/ @@ -342,6 +348,7 @@ void TimeServiceClass::initRTC() #elif defined (ARDUINO_ARCH_RENESAS) renesas_initRTC(); #elif defined (ARDUINO_RASPBERRY_PI_PICO_W) + pico_w_initRTC(); #else #error "RTC not available for this architecture" #endif @@ -360,6 +367,7 @@ void TimeServiceClass::setRTC(unsigned long time) #elif defined (ARDUINO_ARCH_RENESAS) renesas_setRTC(time); #elif defined (ARDUINO_RASPBERRY_PI_PICO_W) + pico_w_setRTC(time); #else #error "RTC not available for this architecture" #endif @@ -378,7 +386,7 @@ unsigned long TimeServiceClass::getRTC() #elif defined (ARDUINO_ARCH_RENESAS) return renesas_getRTC(); #elif defined (ARDUINO_RASPBERRY_PI_PICO_W) - return 1; + return pico_w_getRTC(); #else #error "RTC not available for this architecture" #endif @@ -513,6 +521,23 @@ unsigned long renesas_getRTC() } #endif +#ifdef ARDUINO_RASPBERRY_PI_PICO_W +void pico_w_initRTC() +{ + rtc.begin(); +} + +void pico_w_setRTC(unsigned long time) +{ + rtc.set(time); +} + +unsigned long pico_w_getRTC() +{ + return rtc.get(); +} +#endif + /****************************************************************************** * EXTERN DEFINITION ******************************************************************************/