Skip to content

Commit 0c50a73

Browse files
committed
ports/RTC: Rework the availability and interface of rtc.init().
- make the argument ordering of rtc.init() the same for the ports WiPy, ESP32 and MIMXRT. The WiPy argument ordering is used. - drop rtc.init() from the samd port. - Document the availability and the differing semantics for the STM32 and renesas-ra port.
1 parent 0580255 commit 0c50a73

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

docs/library/machine.RTC.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Methods
4444

4545
``(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])``
4646

47+
Availability: WiPy, ESP32, MIMXRT. The rtc.init() method at the stmm32 and renesas-ra
48+
ports just (re-)start the RTC and do not accept arguments.
49+
4750
.. method:: RTC.now()
4851

4952
Get get the current datetime tuple.

ports/esp32/machine_rtc.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
8484
return (mp_obj_t)&machine_rtc_obj;
8585
}
8686

87-
STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *args) {
87+
STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *args, int hour_index) {
8888
if (n_args == 1) {
8989
// Get time
9090

@@ -114,21 +114,28 @@ STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *ar
114114
mp_obj_get_array_fixed_n(args[1], 8, &items);
115115

116116
struct timeval tv = {0};
117-
tv.tv_sec = timeutils_seconds_since_epoch(mp_obj_get_int(items[0]), mp_obj_get_int(items[1]), mp_obj_get_int(items[2]), mp_obj_get_int(items[4]), mp_obj_get_int(items[5]), mp_obj_get_int(items[6]));
117+
tv.tv_sec = timeutils_seconds_since_epoch(
118+
mp_obj_get_int(items[0]),
119+
mp_obj_get_int(items[1]),
120+
mp_obj_get_int(items[2]),
121+
mp_obj_get_int(items[hour_index]),
122+
mp_obj_get_int(items[hour_index + 1]),
123+
mp_obj_get_int(items[hour_index + 2])
124+
);
118125
tv.tv_usec = mp_obj_get_int(items[7]);
119126
settimeofday(&tv, NULL);
120127

121128
return mp_const_none;
122129
}
123130
}
124131
STATIC mp_obj_t machine_rtc_datetime(size_t n_args, const mp_obj_t *args) {
125-
return machine_rtc_datetime_helper(n_args, args);
132+
return machine_rtc_datetime_helper(n_args, args, 4);
126133
}
127134
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
128135

129136
STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
130137
mp_obj_t args[2] = {self_in, date};
131-
machine_rtc_datetime_helper(2, args);
138+
machine_rtc_datetime_helper(2, args, 3);
132139

133140
#if MICROPY_HW_RTC_USER_MEM_MAX > 0
134141
if (rtc_user_mem_magic != MEM_MAGIC) {

ports/mimxrt/machine_rtc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
6868
return (mp_obj_t)&machine_rtc_obj;
6969
}
7070

71-
STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) {
71+
STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args, int hour_index) {
7272
if (n_args == 1) {
7373
// Get date and time.
7474
snvs_lp_srtc_datetime_t srtc_date;
@@ -97,9 +97,9 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
9797
srtc_date.month = mp_obj_get_int(items[1]);
9898
srtc_date.day = mp_obj_get_int(items[2]);
9999
// Ignore weekday at items[3]
100-
srtc_date.hour = mp_obj_get_int(items[4]);
101-
srtc_date.minute = mp_obj_get_int(items[5]);
102-
srtc_date.second = mp_obj_get_int(items[6]);
100+
srtc_date.hour = mp_obj_get_int(items[hour_index]);
101+
srtc_date.minute = mp_obj_get_int(items[hour_index + 1]);
102+
srtc_date.second = mp_obj_get_int(items[hour_index + 2]);
103103
if (SNVS_LP_SRTC_SetDatetime(SNVS, &srtc_date) != kStatus_Success) {
104104
mp_raise_ValueError(NULL);
105105
}
@@ -109,13 +109,13 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
109109
}
110110

111111
STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
112-
return machine_rtc_datetime_helper(n_args, args);
112+
return machine_rtc_datetime_helper(n_args, args, 4);
113113
}
114114
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
115115

116116
STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
117117
mp_obj_t args[2] = {self_in, date};
118-
machine_rtc_datetime_helper(2, args);
118+
machine_rtc_datetime_helper(2, args, 3);
119119
return mp_const_none;
120120
}
121121
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);

ports/samd/machine_rtc.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,6 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
144144
}
145145
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
146146

147-
STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
148-
mp_obj_t args[2] = {self_in, date};
149-
machine_rtc_datetime_helper(2, args);
150-
return mp_const_none;
151-
}
152-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);
153-
154147
// calibration(cal)
155148
// When the argument is a number in the range [-16 to 15], set the calibration value.
156149
STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) {
@@ -164,7 +157,6 @@ STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) {
164157
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration);
165158

166159
STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
167-
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_rtc_init_obj) },
168160
{ MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) },
169161
{ MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&machine_rtc_calibration_obj) },
170162
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy