8 #ifndef ACE_TIME_STM_RTC_CLOCK_H
9 #define ACE_TIME_STM_RTC_CLOCK_H
11 #if ! defined(EPOXY_DUINO)
12 #if defined(ARDUINO_ARCH_STM32)
16 #include "../hw/StmRtc.h"
17 #include "../hw/HardwareDateTime.h"
28 class StmRtcClock:
public Clock {
30 explicit StmRtcClock() {}
34 acetime_t getNow()
const override {
35 hw::HardwareDateTime hardwareDateTime;
36 mStmRtc.readDateTime(&hardwareDateTime);
37 return toDateTime(hardwareDateTime).toEpochSeconds();
40 void setNow(acetime_t epochSeconds)
override {
41 if (epochSeconds == kInvalidSeconds)
return;
43 LocalDateTime now = LocalDateTime::forEpochSeconds(epochSeconds);
44 mStmRtc.setDateTime(toHardwareDateTime(now));
48 bool isTimeSet()
const {
49 return mStmRtc.isTimeSet();
57 static LocalDateTime toDateTime(
const hw::HardwareDateTime& dt) {
58 return LocalDateTime::forComponents(
59 dt.year + LocalDate::kEpochYear, dt.month, dt.day,
60 dt.hour, dt.minute, dt.second);
68 static hw::HardwareDateTime toHardwareDateTime(
const LocalDateTime& dt) {
69 return hw::HardwareDateTime{(uint8_t) dt.yearTiny(), dt.month(),
70 dt.day(), dt.hour(), dt.minute(), dt.second(), dt.dayOfWeek()};
73 const hw::StmRtc mStmRtc;
79 #endif // #if defined(ARDUINO_ARCH_STM32)
80 #endif // #if ! defined(EPOXY_DUINO)
81 #endif // #ifndef ACE_TIME_STM_RTC_CLOCK_H