10 tm rtc_datetime_t::get_tm(
void)
const
26 void rtc_datetime_t::set_tm(tm& datetime)
28 date = rtc_date_t { datetime };
29 time = rtc_time_t { datetime };
32 static std::uint8_t bcd2ToByte(std::uint8_t
value)
37 static std::uint8_t byteToBcd2(std::uint8_t
value)
39 std::uint_fast8_t bcdhigh =
value / 10;
40 return (bcdhigh << 4) | (
value - (bcdhigh * 10));
63 std::uint8_t buf[7] = { 0 };
67 datetime->time.seconds = bcd2ToByte(buf[0] & 0x7f);
68 datetime->time.minutes = bcd2ToByte(buf[1] & 0x7f);
69 datetime->time.hours = bcd2ToByte(buf[2] & 0x3f);
71 datetime->date.date = bcd2ToByte(buf[3] & 0x3f);
72 datetime->date.weekDay = bcd2ToByte(buf[4] & 0x07);
73 datetime->date.month = bcd2ToByte(buf[5] & 0x1f);
74 datetime->date.year = bcd2ToByte(buf[6] & 0xff)
75 + ((0x80 & buf[5]) ? 1900 : 2000);
82 std::uint8_t buf[3] = { 0 };
86 time->seconds = bcd2ToByte(buf[0] & 0x7f);
87 time->minutes = bcd2ToByte(buf[1] & 0x7f);
88 time->hours = bcd2ToByte(buf[2] & 0x3f);
95 { byteToBcd2(time.seconds)
96 , byteToBcd2(time.minutes)
97 , byteToBcd2(time.hours)
104 std::uint8_t buf[4] = {0};
108 date->date = bcd2ToByte(buf[0] & 0x3f);
109 date->weekDay = bcd2ToByte(buf[1] & 0x07);
110 date->month = bcd2ToByte(buf[2] & 0x1f);
111 date->year = bcd2ToByte(buf[3] & 0xff)
112 + ((0x80 & buf[2]) ? 1900 : 2000);
118 std::uint8_t w = date.weekDay;
119 if (w > 6 && date.year >= 1900 && ((std::size_t)(date.month - 1)) < 12)
121 int32_t year = date.year;
122 int32_t month = date.month;
123 int32_t day = date.date;
128 int32_t ydiv100 = year / 100;
129 w = (year + (year >> 2) - ydiv100 + (ydiv100 >> 2) + (13 * month + 8) / 5 + day) % 7;
133 { byteToBcd2(date.date)
135 , (std::uint8_t)(byteToBcd2(date.month) + (date.year < 2000 ? 0x80 : 0))
136 , byteToBcd2(date.year % 100)
145 if (afterSeconds < 0)
153 std::uint8_t type_value = 0x82;
154 if (afterSeconds < 270)
156 if (afterSeconds > 255) { afterSeconds = 255; }
161 afterSeconds = (afterSeconds + 30) / div;
162 if (afterSeconds > 255) { afterSeconds = 255; }
170 return afterSeconds * div;
177 std::uint32_t raw = ~0;
180 bool irq_enable =
false;
182 if (time.minutes >= 0)
185 buf[0] = byteToBcd2(time.minutes) & 0x7f;
191 buf[1] = byteToBcd2(time.hours) & 0x3f;
210 std::uint32_t raw = ~0;
213 bool irq_enable =
false;
215 if (time.minutes >= 0)
218 buf[0] = byteToBcd2(time.minutes) & 0x7f;
224 buf[1] = byteToBcd2(time.hours) & 0x3f;
230 buf[2] = byteToBcd2(date.date) & 0x3f;
233 if (date.weekDay >= 0)
236 buf[3] = byteToBcd2(date.weekDay) & 0x07;
260 if (!
_init) {
return; }
266 if (!
_init) {
return; }
268 static constexpr
const std::uint8_t buf[4] = { 0x80, 0x80, 0x80, 0x80 };
280 #if !defined (M5UNIFIED_PC_BUILD)
286 t_st.tm_year = dt.date.year - 1900;
287 t_st.tm_mon = dt.date.month - 1;
288 t_st.tm_mday = dt.date.date;
289 t_st.tm_hour = dt.time.hours;
290 t_st.tm_min = dt.time.minutes;
291 t_st.tm_sec = dt.time.seconds;
294 char *oldtz = getenv(
"TZ");
295 setenv(
"TZ",
"GMT0", 1);
297 now.tv_sec = mktime(&t_st);
300 setenv(
"TZ", oldtz, 1);
305 settimeofday(&now, tz);
bool begin(i2c_port_t port_num, int pin_sda, int pin_scl)
bool bitOn(std::uint8_t reg, std::uint8_t bit) const
bool bitOff(std::uint8_t reg, std::uint8_t bit) const
bool readRegister(std::uint8_t reg, std::uint8_t *result, std::size_t length) const
std::uint8_t readRegister8(std::uint8_t reg) const
bool isEnabled(void) const
bool writeRegister8(std::uint8_t reg, std::uint8_t data) const
bool writeRegister(std::uint8_t reg, const std::uint8_t *data, std::size_t length) const
bool begin(I2C_Class *i2c=nullptr)
void setSystemTimeFromRtc(struct timezone *tz=nullptr)
rtc_date_t getDate(void) const
rtc_time_t getTime(void) const
rtc_datetime_t getDateTime(void) const
void setDate(const rtc_date_t &date)
void setTime(const rtc_time_t &time)
int setAlarmIRQ(int afterSeconds)