|
27 | 27 | #include "py/runtime.h"
|
28 | 28 | #include "extmod/utime_mphal.h"
|
29 | 29 | #include "shared/timeutils/timeutils.h"
|
30 |
| -#include "mphalport.h" |
31 |
| - |
32 |
| -#if !MICROPY_PY_MACHINE_RTC |
33 |
| -uint32_t time_offset = 0; |
34 |
| -#endif // !MICROPY_PY_MACHINE_RTC |
| 30 | +#include "modmachine.h" |
35 | 31 |
|
36 | 32 | // localtime([secs])
|
37 | 33 | STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
|
38 | 34 | timeutils_struct_time_t tm;
|
39 | 35 | mp_int_t seconds;
|
40 | 36 |
|
41 |
| - #if MICROPY_PY_MACHINE_RTC |
42 |
| - extern void rtc_gettime(timeutils_struct_time_t *tm); |
43 | 37 | if (n_args == 0 || args[0] == mp_const_none) {
|
44 | 38 | rtc_gettime(&tm);
|
45 | 39 | } else {
|
46 | 40 | seconds = mp_obj_get_int(args[0]);
|
47 | 41 | timeutils_seconds_since_epoch_to_struct_time(seconds, &tm);
|
48 | 42 | }
|
49 | 43 |
|
50 |
| - #else |
51 |
| - if (n_args == 0 || args[0] == mp_const_none) { |
52 |
| - seconds = mp_hal_ticks_ms_64() / 1000 + time_offset; |
53 |
| - } else { |
54 |
| - seconds = mp_obj_get_int(args[0]); |
55 |
| - time_offset = seconds - mp_hal_ticks_ms_64() / 1000; |
56 |
| - } |
57 |
| - timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); |
58 |
| - |
59 |
| - #endif // MICROPY_PY_MACHINE_RTC |
60 | 44 | mp_obj_t tuple[8] = {
|
61 | 45 | tuple[0] = mp_obj_new_int(tm.tm_year),
|
62 | 46 | tuple[1] = mp_obj_new_int(tm.tm_mon),
|
@@ -90,17 +74,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime);
|
90 | 74 |
|
91 | 75 | // time()
|
92 | 76 | STATIC mp_obj_t time_time(void) {
|
93 |
| - #if MICROPY_PY_MACHINE_RTC |
94 |
| - extern void rtc_gettime(timeutils_struct_time_t *tm); |
95 | 77 | timeutils_struct_time_t tm;
|
96 | 78 | rtc_gettime(&tm);
|
97 | 79 | return mp_obj_new_int_from_uint(timeutils_mktime(
|
98 | 80 | tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec));
|
99 |
| - |
100 |
| - #else |
101 |
| - return mp_obj_new_int_from_uint(mp_hal_ticks_ms_64() / 1000 + time_offset); |
102 |
| - |
103 |
| - #endif // MICROPY_PY_MACHINE_RTC |
104 | 81 | }
|
105 | 82 | STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
|
106 | 83 |
|
|
0 commit comments