AceTimeClock  1.2.0
Clock classes for Arduino that can synchronize from an NTP server or an RTC chip
Stm32F1Clock.h
1 /*
2  * MIT License
3  * Copyright (c) 2021 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_STM32_F1_CLOCK_H
7 #define ACE_TIME_STM32_F1_CLOCK_H
8 
9 // For EpoxyDuino, this class is simply stubbed out for testing purposes.
10 #if defined(STM32F1xx) || defined(EPOXY_DUINO)
11 
12 #include <stdint.h>
13 #if ! defined(EPOXY_DUINO)
14  #include "../hw/Stm32F1Rtc.h"
15 #endif
16 #include "Clock.h"
17 
18 namespace ace_time {
19 namespace clock {
20 
69 class Stm32F1Clock: public Clock {
70  public:
71  explicit Stm32F1Clock() {}
72 
74  void setup() {
75  #if ! defined(EPOXY_DUINO)
76  mStm32F1Rtc.begin();
77  #endif
78  }
79 
80  acetime_t getNow() const override {
81  #if defined(EPOXY_DUINO)
82  return mEpochSeconds;
83  #else
84  return mStm32F1Rtc.getTime();
85  #endif
86  }
87 
88  void setNow(acetime_t epochSeconds) override {
89  if (epochSeconds == kInvalidSeconds) return;
90  #if defined(EPOXY_DUINO)
91  mEpochSeconds = epochSeconds;
92  #else
93  mStm32F1Rtc.setTime(epochSeconds);
94  #endif
95  }
96 
97  private:
98  #if defined(EPOXY_DUINO)
99  uint32_t mEpochSeconds;
100  #else
101  mutable hw::Stm32F1Rtc mStm32F1Rtc;
102  #endif
103 };
104 
105 } // clock
106 } // ace_time
107 
108 #endif // #if defined(STM32F1xx) || defined(EPOXY_DUINO)
109 
110 #endif // #ifndef ACE_TIME_STM32F1_CLOCK_H
Abstract base class for objects that provide and store time.
Definition: Clock.h:19
static const acetime_t kInvalidSeconds
Error value returned by getNow() and other methods when this object is not yet initialized.
Definition: Clock.h:25
An implementation of Clock that is specialized for the LSE_CLOCK (Low Speed External clock) on the ST...
Definition: Stm32F1Clock.h:69
void setup()
Configure the clock.
Definition: Stm32F1Clock.h:74
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
Definition: Stm32F1Clock.h:80
void setNow(acetime_t epochSeconds) override
Set the time to the indicated seconds.
Definition: Stm32F1Clock.h:88