Skip to content

Commit 05bb260

Browse files
robert-hhdpgeorge
authored andcommitted
samd: Always provide the machine.RTC class.
Even if boards do not have a clock crystal. In that case, the clock quality will be very poor. Always having machine.RTC means that the date/time can be set in a way that is consistent with other ports. This commit also removes the special code in modutime.c for devices without the RTC class. Signed-off-by: Damien George <[email protected]>
1 parent d5c45a8 commit 05bb260

File tree

5 files changed

+5
-35
lines changed

5 files changed

+5
-35
lines changed

ports/samd/mcu/samd21/mpconfigmcu.h

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ unsigned long trng_random_u32(int delay);
3131
#define MICROPY_HW_UART_TXBUF (1)
3232
#endif
3333

34-
#ifndef MICROPY_PY_MACHINE_RTC
35-
#if MICROPY_HW_XOSC32K
36-
#define MICROPY_PY_MACHINE_RTC (1)
37-
#endif
38-
#endif
3934
#define MICROPY_PY_UOS_URANDOM (1)
4035

4136
#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU

ports/samd/mcu/samd51/mpconfigmcu.h

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32())
2929
unsigned long trng_random_u32(void);
3030

31-
#ifndef MICROPY_PY_MACHINE_RTC
32-
#if MICROPY_HW_XOSC32K
33-
#define MICROPY_PY_MACHINE_RTC (1)
34-
#endif
35-
#endif
36-
3731
#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU
3832
#define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1)
3933
#endif

ports/samd/modmachine.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define MICROPY_INCLUDED_SAMD_MODMACHINE_H
2828

2929
#include "py/obj.h"
30+
#include "shared/timeutils/timeutils.h"
3031

3132
extern const mp_obj_type_t machine_adc_type;
3233
extern const mp_obj_type_t machine_dac_type;
@@ -43,4 +44,6 @@ extern const mp_obj_type_t machine_rtc_type;
4344

4445
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
4546

47+
void rtc_gettime(timeutils_struct_time_t *tm);
48+
4649
#endif // MICROPY_INCLUDED_SAMD_MODMACHINE_H

ports/samd/modutime.c

+1-24
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,20 @@
2727
#include "py/runtime.h"
2828
#include "extmod/utime_mphal.h"
2929
#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"
3531

3632
// localtime([secs])
3733
STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
3834
timeutils_struct_time_t tm;
3935
mp_int_t seconds;
4036

41-
#if MICROPY_PY_MACHINE_RTC
42-
extern void rtc_gettime(timeutils_struct_time_t *tm);
4337
if (n_args == 0 || args[0] == mp_const_none) {
4438
rtc_gettime(&tm);
4539
} else {
4640
seconds = mp_obj_get_int(args[0]);
4741
timeutils_seconds_since_epoch_to_struct_time(seconds, &tm);
4842
}
4943

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
6044
mp_obj_t tuple[8] = {
6145
tuple[0] = mp_obj_new_int(tm.tm_year),
6246
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);
9074

9175
// time()
9276
STATIC mp_obj_t time_time(void) {
93-
#if MICROPY_PY_MACHINE_RTC
94-
extern void rtc_gettime(timeutils_struct_time_t *tm);
9577
timeutils_struct_time_t tm;
9678
rtc_gettime(&tm);
9779
return mp_obj_new_int_from_uint(timeutils_mktime(
9880
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
10481
}
10582
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
10683

ports/samd/mpconfigport.h

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#define MICROPY_PY_UZLIB (1)
9393
#define MICROPY_PY_UASYNCIO (1)
9494
#define MICROPY_PY_MACHINE_I2C (1)
95+
#define MICROPY_PY_MACHINE_RTC (1)
9596
#define MICROPY_PY_MACHINE_SOFTI2C (1)
9697
#define MICROPY_PY_MACHINE_SPI (1)
9798
#define MICROPY_PY_MACHINE_SOFTSPI (1)

0 commit comments

Comments
 (0)