Skip to content

Commit 00cca57

Browse files
committed
components/M5Unified: Update system time in M5.RTC.
Signed-off-by: lbuque <1102390310@qq.com>
1 parent d3ac577 commit 00cca57

6 files changed

Lines changed: 37 additions & 1 deletion

File tree

m5stack/components/M5Unified/mpy_m5unified.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,17 @@ static void in_i2c_init(void) {
502502
}
503503
}
504504

505+
void rtc_sync(struct timeval *tv_in) {
506+
struct timeval tv;
507+
if (tv_in == nullptr) {
508+
gettimeofday(&tv, NULL);
509+
} else {
510+
tv = *tv_in;
511+
}
512+
struct tm now;
513+
localtime_r(&tv.tv_sec, &now);
514+
M5.Rtc.setDateTime(&now);
515+
}
505516

506517
// TODO: pass configuration parameters
507518
mp_obj_t m5_begin(size_t n_args, const mp_obj_t *args) {
@@ -538,6 +549,9 @@ mp_obj_t m5_begin(size_t n_args, const mp_obj_t *args) {
538549
// set default font to DejaVu9, keep same style with UIFlow website UI design.
539550
M5.Display.setTextFont(&fonts::DejaVu9);
540551

552+
// get local time and sync to RTC IC
553+
rtc_sync(nullptr);
554+
541555
{
542556
for (uint8_t i = 0; i < 5; i++) {
543557
MP_STATE_PORT(wasClicked_cb)[i] = mp_const_none;

m5stack/components/M5Unified/mpy_m5unified.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include "mpy_m5als.h"
2323
#include "mpy_m5mic.h"
2424
#include "mic_config_t.h"
25+
#include <sys/time.h>
2526

27+
extern void rtc_sync(struct timeval *tv_in);
2628
extern mp_obj_t m5_begin(size_t n_args, const mp_obj_t *args);
2729
extern mp_obj_t m5_add_display(mp_obj_t i2c_bus_in, mp_obj_t addr_in, mp_obj_t dict);
2830
extern mp_obj_t m5_create_speaker(void);

m5stack/machine_rtc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
#include "machine_rtc.h"
4242
#include "uiflow_utility.h"
4343

44+
#ifndef NO_HAVE_RTC_SYNC
45+
#define NO_HAVE_RTC_SYNC 0
46+
#endif
47+
48+
#if NO_HAVE_RTC_SYNC == 0
49+
#include "mpy_m5unified.h"
50+
#endif
51+
4452
typedef struct _machine_rtc_obj_t {
4553
mp_obj_base_t base;
4654
} machine_rtc_obj_t;
@@ -141,6 +149,9 @@ static mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *ar
141149
);
142150
tv.tv_usec = mp_obj_get_int(items[7]);
143151
settimeofday(&tv, NULL);
152+
#if NO_HAVE_RTC_SYNC == 0
153+
rtc_sync(&tv);
154+
#endif
144155

145156
return mp_const_none;
146157
}
@@ -190,6 +201,9 @@ static mp_obj_t machine_rtc_local_datetime_helper(mp_uint_t n_args, const mp_obj
190201
#endif
191202
tv.tv_usec = mp_obj_get_int(items[7]);
192203
settimeofday(&tv, NULL);
204+
#if NO_HAVE_RTC_SYNC == 0
205+
rtc_sync(&tv);
206+
#endif
193207

194208
return mp_const_none;
195209
}

third-party/boards/ESPRESSIF_ESP32_S3_BOX_3/mpconfigboard.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
#define MICROPY_HW_USB_CDC_INTERFACE_STRING "Espressif ESP32-S3-BOX-3(UiFlow2)"
1313

1414
#define AUDIO_RECORDER_DOWN_CH (1)
15-
#define MICROPY_PY_MACHINE_I2S (0)
15+
#define MICROPY_PY_MACHINE_I2S (0)
16+
17+
#define NO_HAVE_RTC_SYNC (1)

third-party/boards/SEEED_STUDIO_XIAO_ESP32S3/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717

1818
#define MICROPY_HW_USB_CDC_INTERFACE_STRING "Seeed XIAO ESP32S3(UiFlow2)"
1919

20+
#define NO_HAVE_RTC_SYNC (1)
21+
2022
// If not enable LVGL, ignore this...
2123
#include "./../mpconfiglvgl.h"

third-party/boards/SEEED_STUDIO_XIAO_ESP32S3_Sense/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717

1818
#define MICROPY_HW_USB_CDC_INTERFACE_STRING "Seeed XIAO ESP32S3 Sense(UiFlow2)"
1919

20+
#define NO_HAVE_RTC_SYNC (1)
21+
2022
// If not enable LVGL, ignore this...
2123
#include "./../mpconfiglvgl.h"

0 commit comments

Comments
 (0)