Skip to content

Commit df15d78

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 CC3200, ESP32, MIMXRT and SAMD. The WiPy argument ordering is used. - Document the availability and the differing semantics for the STM32 and renesas-ra port. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 3953a82 commit df15d78

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

docs/library/machine.RTC.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ Methods
4242

4343
Initialise the RTC. Datetime is a tuple of the form:
4444

45-
``(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])``
45+
``(year, month, day, hour, minute, second, microsecond, tzinfo)``
46+
47+
Availability: CC3200, ESP32, MIMXRT, SAMD. The rtc.init() method at
48+
the stmm32 and renesas-ra ports just (re-)start the RTC and do not
49+
accept arguments.
4650

4751
.. method:: RTC.now()
4852

ports/esp32/machine_rtc.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
101101
return (mp_obj_t)&machine_rtc_obj;
102102
}
103103

104-
static mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *args) {
104+
static mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *args, int hour_index) {
105105
if (n_args == 1) {
106106
// Get time
107107

@@ -131,21 +131,28 @@ static mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *ar
131131
mp_obj_get_array_fixed_n(args[1], 8, &items);
132132

133133
struct timeval tv = {0};
134-
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]));
134+
tv.tv_sec = timeutils_seconds_since_epoch(
135+
mp_obj_get_int(items[0]),
136+
mp_obj_get_int(items[1]),
137+
mp_obj_get_int(items[2]),
138+
mp_obj_get_int(items[hour_index]),
139+
mp_obj_get_int(items[hour_index + 1]),
140+
mp_obj_get_int(items[hour_index + 2])
141+
);
135142
tv.tv_usec = mp_obj_get_int(items[7]);
136143
settimeofday(&tv, NULL);
137144

138145
return mp_const_none;
139146
}
140147
}
141148
static mp_obj_t machine_rtc_datetime(size_t n_args, const mp_obj_t *args) {
142-
return machine_rtc_datetime_helper(n_args, args);
149+
return machine_rtc_datetime_helper(n_args, args, 4);
143150
}
144151
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
145152

146153
static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
147154
mp_obj_t args[2] = {self_in, date};
148-
machine_rtc_datetime_helper(2, args);
155+
machine_rtc_datetime_helper(2, args, 3);
149156

150157
return mp_const_none;
151158
}

ports/mimxrt/machine_rtc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
185185
return (mp_obj_t)&machine_rtc_obj;
186186
}
187187

188-
static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) {
188+
static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args, int hour_index) {
189189
if (n_args == 1) {
190190
// Get date and time.
191191
snvs_lp_srtc_datetime_t srtc_date;
@@ -214,9 +214,9 @@ static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
214214
srtc_date.month = mp_obj_get_int(items[1]);
215215
srtc_date.day = mp_obj_get_int(items[2]);
216216
// Ignore weekday at items[3]
217-
srtc_date.hour = mp_obj_get_int(items[4]);
218-
srtc_date.minute = mp_obj_get_int(items[5]);
219-
srtc_date.second = mp_obj_get_int(items[6]);
217+
srtc_date.hour = mp_obj_get_int(items[hour_index]);
218+
srtc_date.minute = mp_obj_get_int(items[hour_index + 1]);
219+
srtc_date.second = mp_obj_get_int(items[hour_index + 2]);
220220
if (SNVS_LP_SRTC_SetDatetime(SNVS, &srtc_date) != kStatus_Success) {
221221
mp_raise_ValueError(NULL);
222222
}
@@ -226,13 +226,13 @@ static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
226226
}
227227

228228
static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
229-
return machine_rtc_datetime_helper(n_args, args);
229+
return machine_rtc_datetime_helper(n_args, args, 4);
230230
}
231231
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
232232

233233
static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
234234
mp_obj_t args[2] = {self_in, date};
235-
machine_rtc_datetime_helper(2, args);
235+
machine_rtc_datetime_helper(2, args, 3);
236236
return mp_const_none;
237237
}
238238
static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);

ports/samd/machine_rtc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
9393
return (mp_obj_t)&machine_rtc_obj;
9494
}
9595

96-
static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) {
96+
static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args, int hour_index) {
9797
// Rtc *rtc = RTC;
9898
if (n_args == 1) {
9999
// Get date and time.
@@ -120,9 +120,9 @@ static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
120120
RTC_MODE2_CLOCK_YEAR(mp_obj_get_int(items[0]) % 100) |
121121
RTC_MODE2_CLOCK_MONTH(mp_obj_get_int(items[1])) |
122122
RTC_MODE2_CLOCK_DAY(mp_obj_get_int(items[2])) |
123-
RTC_MODE2_CLOCK_HOUR(mp_obj_get_int(items[4])) |
124-
RTC_MODE2_CLOCK_MINUTE(mp_obj_get_int(items[5])) |
125-
RTC_MODE2_CLOCK_SECOND(mp_obj_get_int(items[6]));
123+
RTC_MODE2_CLOCK_HOUR(mp_obj_get_int(items[hour_index])) |
124+
RTC_MODE2_CLOCK_MINUTE(mp_obj_get_int(items[hour_index + 1])) |
125+
RTC_MODE2_CLOCK_SECOND(mp_obj_get_int(items[hour_index + 2]));
126126

127127
RTC->MODE2.CLOCK.reg = date;
128128
#if defined(MCU_SAMD21)
@@ -138,13 +138,13 @@ static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
138138
}
139139

140140
static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
141-
return machine_rtc_datetime_helper(n_args, args);
141+
return machine_rtc_datetime_helper(n_args, args, 4);
142142
}
143143
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime);
144144

145145
static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
146146
mp_obj_t args[2] = {self_in, date};
147-
machine_rtc_datetime_helper(2, args);
147+
machine_rtc_datetime_helper(2, args, 3);
148148
return mp_const_none;
149149
}
150150
static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);

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