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 <damien@micropython.org>
This commit is contained in:
parent
d5c45a80d2
commit
05bb26010e
@ -31,11 +31,6 @@ unsigned long trng_random_u32(int delay);
|
||||
#define MICROPY_HW_UART_TXBUF (1)
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_MACHINE_RTC
|
||||
#if MICROPY_HW_XOSC32K
|
||||
#define MICROPY_PY_MACHINE_RTC (1)
|
||||
#endif
|
||||
#endif
|
||||
#define MICROPY_PY_UOS_URANDOM (1)
|
||||
|
||||
#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU
|
||||
|
@ -28,12 +28,6 @@
|
||||
#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (trng_random_u32())
|
||||
unsigned long trng_random_u32(void);
|
||||
|
||||
#ifndef MICROPY_PY_MACHINE_RTC
|
||||
#if MICROPY_HW_XOSC32K
|
||||
#define MICROPY_PY_MACHINE_RTC (1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU
|
||||
#define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1)
|
||||
#endif
|
||||
|
@ -27,6 +27,7 @@
|
||||
#define MICROPY_INCLUDED_SAMD_MODMACHINE_H
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
|
||||
extern const mp_obj_type_t machine_adc_type;
|
||||
extern const mp_obj_type_t machine_dac_type;
|
||||
@ -43,4 +44,6 @@ extern const mp_obj_type_t machine_rtc_type;
|
||||
|
||||
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
void rtc_gettime(timeutils_struct_time_t *tm);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SAMD_MODMACHINE_H
|
||||
|
@ -27,19 +27,13 @@
|
||||
#include "py/runtime.h"
|
||||
#include "extmod/utime_mphal.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "mphalport.h"
|
||||
|
||||
#if !MICROPY_PY_MACHINE_RTC
|
||||
uint32_t time_offset = 0;
|
||||
#endif // !MICROPY_PY_MACHINE_RTC
|
||||
#include "modmachine.h"
|
||||
|
||||
// localtime([secs])
|
||||
STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
|
||||
timeutils_struct_time_t tm;
|
||||
mp_int_t seconds;
|
||||
|
||||
#if MICROPY_PY_MACHINE_RTC
|
||||
extern void rtc_gettime(timeutils_struct_time_t *tm);
|
||||
if (n_args == 0 || args[0] == mp_const_none) {
|
||||
rtc_gettime(&tm);
|
||||
} else {
|
||||
@ -47,16 +41,6 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
|
||||
timeutils_seconds_since_epoch_to_struct_time(seconds, &tm);
|
||||
}
|
||||
|
||||
#else
|
||||
if (n_args == 0 || args[0] == mp_const_none) {
|
||||
seconds = mp_hal_ticks_ms_64() / 1000 + time_offset;
|
||||
} else {
|
||||
seconds = mp_obj_get_int(args[0]);
|
||||
time_offset = seconds - mp_hal_ticks_ms_64() / 1000;
|
||||
}
|
||||
timeutils_seconds_since_epoch_to_struct_time(seconds, &tm);
|
||||
|
||||
#endif // MICROPY_PY_MACHINE_RTC
|
||||
mp_obj_t tuple[8] = {
|
||||
tuple[0] = mp_obj_new_int(tm.tm_year),
|
||||
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);
|
||||
|
||||
// time()
|
||||
STATIC mp_obj_t time_time(void) {
|
||||
#if MICROPY_PY_MACHINE_RTC
|
||||
extern void rtc_gettime(timeutils_struct_time_t *tm);
|
||||
timeutils_struct_time_t tm;
|
||||
rtc_gettime(&tm);
|
||||
return mp_obj_new_int_from_uint(timeutils_mktime(
|
||||
tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec));
|
||||
|
||||
#else
|
||||
return mp_obj_new_int_from_uint(mp_hal_ticks_ms_64() / 1000 + time_offset);
|
||||
|
||||
#endif // MICROPY_PY_MACHINE_RTC
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
|
||||
|
||||
|
@ -92,6 +92,7 @@
|
||||
#define MICROPY_PY_UZLIB (1)
|
||||
#define MICROPY_PY_UASYNCIO (1)
|
||||
#define MICROPY_PY_MACHINE_I2C (1)
|
||||
#define MICROPY_PY_MACHINE_RTC (1)
|
||||
#define MICROPY_PY_MACHINE_SOFTI2C (1)
|
||||
#define MICROPY_PY_MACHINE_SPI (1)
|
||||
#define MICROPY_PY_MACHINE_SOFTSPI (1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user