From 0712c9522517dad0c6684c612f0c9e8e651284d1 Mon Sep 17 00:00:00 2001 From: iot49 Date: Mon, 9 Dec 2019 23:14:26 -0800 Subject: [PATCH 1/2] fix mtime on file creation --- ports/nrf/fatfs_port.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ports/nrf/fatfs_port.c b/ports/nrf/fatfs_port.c index 13ac21fb1b..83698fd19c 100644 --- a/ports/nrf/fatfs_port.c +++ b/ports/nrf/fatfs_port.c @@ -26,8 +26,18 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" +#include "lib/timeutils/timeutils.h" + +extern void common_hal_rtc_get_time(timeutils_struct_time_t *tm); +extern void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm); DWORD get_fattime(void) { - // TODO: Implement this function. For now, fake it. - return ((2016 - 1980) << 25) | ((12) << 21) | ((4) << 16) | ((00) << 11) | ((18) << 5) | (23 / 2); +#if CIRCUITPY_RTC + timeutils_struct_time_t tm; + common_hal_rtc_get_time(&tm); + return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | + (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); +#else + return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); +#endif } From 73b6e5d8e6e992eae027b76dc55ceb2ea907e672 Mon Sep 17 00:00:00 2001 From: iot49 Date: Tue, 10 Dec 2019 19:44:11 -0800 Subject: [PATCH 2/2] added correct include files --- ports/nrf/fatfs_port.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/nrf/fatfs_port.c b/ports/nrf/fatfs_port.c index 83698fd19c..cb1bfa8347 100644 --- a/ports/nrf/fatfs_port.c +++ b/ports/nrf/fatfs_port.c @@ -27,9 +27,8 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "lib/timeutils/timeutils.h" - -extern void common_hal_rtc_get_time(timeutils_struct_time_t *tm); -extern void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm); +#include "shared-bindings/rtc/RTC.h" +#include "shared-bindings/time/__init__.h" DWORD get_fattime(void) { #if CIRCUITPY_RTC