|
39 | 39 | #include "shared/timeutils/timeutils.h" |
40 | 40 | #include "modmachine.h" |
41 | 41 | #include "mphalport.h" |
| 42 | +#include "mpy_hal_boot.h" |
42 | 43 |
|
43 | 44 | #define RTC_ALARM_GROUP_CAPACITY (8) |
44 | 45 |
|
45 | | -#define UNIX_TIMESTAMP_AT_2000 (946684800) |
46 | | - |
47 | | -PMU_HandleTypeDef xt804_rtc_source; |
48 | | - |
49 | 46 | typedef struct _machine_rtc_obj_t { |
50 | 47 | mp_obj_base_t base; |
51 | 48 | } machine_rtc_obj_t; |
@@ -330,17 +327,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machi |
330 | 327 |
|
331 | 328 |
|
332 | 329 | STATIC mp_obj_t machine_rtc_timestamp(mp_obj_t self_in) { |
333 | | - RTC_TimeTypeDef rtctime; |
334 | | - HAL_PMU_RTC_GetTime(&xt804_rtc_source, &rtctime); |
335 | | - uint32_t seconds = timeutils_seconds_since_2000( |
336 | | - rtctime.Year + 2000, |
337 | | - rtctime.Month, |
338 | | - rtctime.Date, |
339 | | - rtctime.Hours, |
340 | | - rtctime.Minutes, |
341 | | - rtctime.Seconds |
342 | | - ); |
343 | | - return mp_obj_new_int_from_ll((uint64_t)seconds + UNIX_TIMESTAMP_AT_2000); |
| 330 | + uint32_t seconds = mp_hal_time_s(); |
| 331 | + return mp_obj_new_int_from_ll((uint64_t)seconds); |
344 | 332 | } |
345 | 333 | STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_timestamp_obj, machine_rtc_timestamp); |
346 | 334 |
|
@@ -607,7 +595,7 @@ const mp_obj_type_t machine_rtc_type = { |
607 | 595 | STATIC void machine_rtc_alarm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { |
608 | 596 | machine_rtc_alarm_obj_t *self = MP_OBJ_TO_PTR(self_in); |
609 | 597 | int id = MPY_ARRAY_INDEX(machine_rtc_alarms_obj, self) % RTC_ALARM_GROUP_CAPACITY; |
610 | | - mp_printf(print, "Alarm(id=%d, time=%ld)", id, self->alarm_datetime_s + UNIX_TIMESTAMP_AT_2000); |
| 598 | + mp_printf(print, "Alarm(id=%d, time=%ld)", id, self->alarm_datetime_s + TIMEUTILS_SECONDS_1970_TO_2000); |
611 | 599 | } |
612 | 600 |
|
613 | 601 | STATIC mp_obj_t machine_rtc_alarm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { |
|
0 commit comments