From 2a8c27115c5b6b68f32e4e2ba094c374a9791f04 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Thu, 30 Apr 2020 15:04:52 +0300 Subject: [PATCH] fatfs: Use RTC clock for date/time --- nyx/nyx_gui/libs/fatfs/ffsystem.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/nyx/nyx_gui/libs/fatfs/ffsystem.c b/nyx/nyx_gui/libs/fatfs/ffsystem.c index fa44f8e..ce8927d 100644 --- a/nyx/nyx_gui/libs/fatfs/ffsystem.c +++ b/nyx/nyx_gui/libs/fatfs/ffsystem.c @@ -6,9 +6,11 @@ #include "ff.h" +#include "../../config/config.h" #include "../../mem/heap.h" +#include "../../rtc/max77620-rtc.h" - +extern nyx_config n_cfg; #if FF_USE_LFN == 3 /* Dynamic memory allocation */ @@ -37,3 +39,27 @@ void ff_memfree ( #endif +#if FF_FS_NORTC == 0 + +/*------------------------------------------------------------------------*/ +/* Get real time clock */ +/*------------------------------------------------------------------------*/ + +DWORD get_fattime ( + void +) +{ + rtc_time_t time; + + max77620_rtc_get_time(&time); + if (n_cfg.timeoff) + { + u32 epoch = (u32)((s32)max77620_rtc_date_to_epoch(&time, true) + (s32)n_cfg.timeoff); + max77620_rtc_epoch_to_date(epoch, &time); + } + + return (((DWORD)(time.year - 1980) << 25) | ((DWORD)time.month << 21) | ((DWORD)time.day << 16) | + ((DWORD)time.hour << 11) | ((DWORD)time.min << 5) | (time.sec >> 1)); +} + +#endif