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 Dec 23, 2024
1 parent 211dbdb commit 436ce34
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 @@ -21,7 +21,7 @@

#include "AIoTC_Config.h"

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

#include <Arduino.h>
#include "RTCMillis.h"
Expand Down Expand Up @@ -61,4 +61,4 @@ unsigned long RTCMillis::get()
return _last_rtc_update_value;
}

#endif /* HAS_NOTECARD || ARDUINO_ARCH_ESP8266 */
#endif /* HAS_NOTECARD || 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_

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

/**************************************************************************************
* INCLUDE
Expand All @@ -45,6 +45,6 @@ class RTCMillis

};

#endif /* HAS_NOTECARD || ARDUINO_ARCH_ESP8266 */
#endif /* HAS_NOTECARD || 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 @@ -27,7 +27,7 @@
#include "NTPUtils.h"
#include "TimeService.h"

#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W)
#include "RTCMillis.h"
#elif defined(ARDUINO_ARCH_SAMD)
#include <RTCZero.h>
Expand All @@ -41,7 +41,7 @@
* GLOBAL VARIABLES
**************************************************************************************/

#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined (ARDUINO_RASPBERRY_PI_PICO_W)
RTCMillis rtc;
#elif defined(ARDUINO_ARCH_SAMD)
RTCZero rtc;
Expand Down Expand Up @@ -89,6 +89,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

#endif /* HAS_NOTECARD */

/**************************************************************************************
Expand Down Expand Up @@ -356,6 +362,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 @@ -376,6 +383,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 @@ -396,7 +404,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 @@ -548,6 +556,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

#endif /* HAS_NOTECARD */

/******************************************************************************
Expand Down

0 comments on commit 436ce34

Please # to comment.