Skip to content

Commit

Permalink
pico w: Add soft RTC support
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Sep 12, 2024
1 parent 30602e9 commit 56d7ede
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/utility/time/RTCMillis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
a commercial license, send an email to [email protected].
*/

#ifdef ARDUINO_ARCH_ESP8266
#if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W)

/**************************************************************************************
* INCLUDE
Expand Down Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions src/utility/time/RTCMillis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_ */
31 changes: 28 additions & 3 deletions src/utility/time/TimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <mbed_rtc_time.h>
#endif

#ifdef ARDUINO_ARCH_ESP8266
#if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W)
#include "RTCMillis.h"
#endif

Expand All @@ -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

Expand Down Expand Up @@ -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
**************************************************************************************/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
******************************************************************************/
Expand Down

0 comments on commit 56d7ede

Please sign in to comment.