Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
esp32_rtc.h
Go to the documentation of this file.
1#pragma once
2
3#if defined(ARDUINO)
4
5#include "ersa/hal/rtc.h"
8
9namespace ersa {
10namespace hal {
11
17class Esp32Rtc : public IRtc {
18public:
20 Esp32Rtc(int sda = 6, int scl = 7);
21 ~Esp32Rtc() override = default;
22
23 Result<void> init() override;
24 TimePoint now() override;
25 Result<void> adjust(const TimePoint& time) override;
26 Result<void> setEpoch(uint32_t epochSeconds) override;
27 bool isHealthy() const override;
28 RtcDiagnostics diagnostics() override;
30 void resync() override;
31
32private:
33 int sda_, scl_;
34 ersa::drivers::rtc::Ds3231 rtc_;
35 CalendarTime cachedTime_{};
36 uint32_t lastReadMs_{0};
37 uint32_t lastRtcPollMs_{0};
38 bool online_{false};
39 bool oscillatorStopped_{false};
40 bool driftMeasured_{false};
41 int32_t lastDriftSeconds_{0};
42
43 static TimePoint toTimePoint(const CalendarTime& dt);
44 static CalendarTime toCalendarTime(const TimePoint& tp);
45 static bool valid(const CalendarTime& time);
46 bool readChipTime(CalendarTime& time);
47 bool writeChipTime(const CalendarTime& time);
48 bool responds();
49 void reconcile(uint32_t nowMs, bool force);
50};
51
52} // namespace hal
53} // namespace ersa
54
55#endif // ARDUINO
Definition calendar_time.h:11
void resync()
Definition watch_clock.cpp:31
void adjust(const CalendarTime &time)
Definition watch_clock.cpp:35
CalendarTime now()
Definition watch_clock.cpp:23
void setEpoch(uint32_t epochSeconds)
Definition watch_clock.cpp:39
Definition application.h:10