AceTimeClock  1.3.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 
77 class Stm32F1Clock: public Clock {
78  public:
79  explicit Stm32F1Clock() {}
80 
82  void setup() {
83  #if ! defined(EPOXY_DUINO)
84  mStm32F1Rtc.begin();
85  #endif
86  }
87 
88  acetime_t getNow() const override {
89  #if defined(EPOXY_DUINO)
90  return mEpochSeconds;
91  #else
92  return mStm32F1Rtc.getTime();
93  #endif
94  }
95 
96  void setNow(acetime_t epochSeconds) override {
97  if (epochSeconds == kInvalidSeconds) return;
98  #if defined(EPOXY_DUINO)
99  mEpochSeconds = epochSeconds;
100  #else
101  mStm32F1Rtc.setTime(epochSeconds);
102  #endif
103  }
104 
105  private:
106  #if defined(EPOXY_DUINO)
107  uint32_t mEpochSeconds;
108  #else
109  mutable hw::Stm32F1Rtc mStm32F1Rtc;
110  #endif
111 };
112 
113 } // clock
114 } // ace_time
115 
116 #endif // #if defined(STM32F1xx) || defined(EPOXY_DUINO)
117 
118 #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:77
void setup()
Configure the clock.
Definition: Stm32F1Clock.h:82
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
Definition: Stm32F1Clock.h:88
void setNow(acetime_t epochSeconds) override
Set the time to the indicated seconds.
Definition: Stm32F1Clock.h:96