semf
stm32rtc.h
Go to the documentation of this file.
1
10#ifndef SEMF_HARDWAREABSTRACTION_STM32_STM32RTC_H_
11#define SEMF_HARDWAREABSTRACTION_STM32_STM32RTC_H_
12
14
15#if defined(STM32) && defined(HAL_RTC_MODULE_ENABLED)
16#include <semf/system/rtc.h>
17namespace semf
18{
22class Stm32Rtc : public Rtc
23{
24public:
26 enum class ErrorCode : uint8_t
27 {
28 SetMillisecond_HalError = 0,
29 SetMillisecond_HalBusy,
30 SetMillisecond_HalTimeout,
31 SetSecond_HalError,
32 SetSecond_HalBusy,
33 SetSecond_HalTimeout,
34 SetMinute_HalError,
35 SetMinute_HalBusy,
36 SetMinute_HalTimeout,
37 SetHour_HalError,
38 SetHour_HalBusy,
39 SetHour_HalTimeout,
40 SetDay_HalError,
41 SetDay_HalBusy,
42 SetDay_HalTimeout,
43 SetMonth_HalError,
44 SetMonth_HalBusy,
45 SetMonth_HalTimeout,
46 SetYear_HalError,
47 SetYear_HalBusy,
48 SetYear_HalTimeout,
49 HalTime_HalError,
50 HalTime_HalBusy,
51 HalTime_HalTimeout,
52 HalDate_HalError,
53 HalDate_HalBusy,
54 HalDate_HalTimeout
55 };
56
61 explicit Stm32Rtc(RTC_HandleTypeDef& hrtc);
62 explicit Stm32Rtc(const Stm32Rtc& other) = delete;
63 virtual ~Stm32Rtc() = default;
64
65 uint16_t millisecond() override;
72 void setMillisecond(uint16_t millisecond) override;
73 uint8_t second() const override;
80 void setSecond(uint8_t second) override;
81 uint8_t minute() const override;
88 void setMinute(uint8_t minute) override;
89 uint8_t hour() const override;
96 void setHour(uint8_t hour) override;
97 uint8_t day() const override;
104 void setDay(uint8_t day) override;
105 uint8_t month() const override;
112 void setMonth(uint8_t month) override;
113 uint16_t year() const override;
120 void setYear(uint16_t year) override;
121
122private:
124 RTC_HandleTypeDef* m_hrtc;
132 RTC_TimeTypeDef halTime() const;
140 RTC_DateTypeDef halDate() const;
142 static constexpr Error::ClassID kSemfClassId = Error::ClassID::Stm32Rtc;
143};
144} /* namespace semf */
145#endif
146#endif /* SEMF_HARDWAREABSTRACTION_STM32_STM32RTC_H_ */
ClassID
Semf class IDs.
Definition: error.h:28
Interface for the real time clock.
Definition: rtc.h:23
Rtc implementation for STM32.
Definition: stm32rtc.h:23
void setYear(uint16_t year) override
For set a new date.
Definition: stm32rtc.cpp:242
virtual ~Stm32Rtc()=default
uint16_t year() const override
Get the current year.
Definition: stm32rtc.cpp:237
uint16_t millisecond() override
Get the milliseconds from the current time.
Definition: stm32rtc.cpp:21
void setDay(uint8_t day) override
For set a new date.
Definition: stm32rtc.cpp:178
uint8_t second() const override
Get the seconds from the current time.
Definition: stm32rtc.cpp:65
void setHour(uint8_t hour) override
For set a new time.
Definition: stm32rtc.cpp:142
uint8_t month() const override
Get the current month.
Definition: stm32rtc.cpp:205
uint8_t day() const override
Definition: stm32rtc.cpp:173
void setMonth(uint8_t month) override
For set a new date.
Definition: stm32rtc.cpp:210
Stm32Rtc(const Stm32Rtc &other)=delete
Stm32Rtc(RTC_HandleTypeDef &hrtc)
Constructor.
Definition: stm32rtc.cpp:16
uint8_t hour() const override
Get the hours from the current time.
Definition: stm32rtc.cpp:137
void setMinute(uint8_t minute) override
For set a new time.
Definition: stm32rtc.cpp:106
void setMillisecond(uint16_t millisecond) override
For set a new time.
Definition: stm32rtc.cpp:31
void setSecond(uint8_t second) override
For set a new time.
Definition: stm32rtc.cpp:70
uint8_t minute() const override
Get the minutes from the current time.
Definition: stm32rtc.cpp:101