From 5fe84a78ac7ed793cc91f09bf08960a620a2df07 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Tue, 5 May 2020 19:16:16 +0300 Subject: [PATCH] rtc: Remove custom encoding --- bootloader/rtc/max77620-rtc.c | 36 ++++++------------------------- bootloader/rtc/max77620-rtc.h | 2 +- nyx/nyx_gui/frontend/gui.c | 2 +- nyx/nyx_gui/libs/fatfs/ffsystem.c | 2 +- nyx/nyx_gui/rtc/max77620-rtc.c | 36 ++++++------------------------- nyx/nyx_gui/rtc/max77620-rtc.h | 2 +- 6 files changed, 18 insertions(+), 62 deletions(-) diff --git a/bootloader/rtc/max77620-rtc.c b/bootloader/rtc/max77620-rtc.c index 385c936..04c6937 100644 --- a/bootloader/rtc/max77620-rtc.c +++ b/bootloader/rtc/max77620-rtc.c @@ -119,7 +119,7 @@ void max77620_rtc_epoch_to_date(u32 epoch, rtc_time_t *time) time->weekday = 0; //! TODO. } -u32 max77620_rtc_date_to_epoch(const rtc_time_t *time, bool hos_encoding) +u32 max77620_rtc_date_to_epoch(const rtc_time_t *time) { u32 year, month, epoch; @@ -128,39 +128,17 @@ u32 max77620_rtc_date_to_epoch(const rtc_time_t *time, bool hos_encoding) //Month of year month = time->month; - if (!hos_encoding) + // Month/Year offset. + if(month < 3) { - // Month/Year offset. - if(month < 3) - { - month += 12; - year--; - } - } - else - { - year -= 2000; - month++; - - // Month/Year offset. - if(month < 3) - { - month += 9; - year--; - } - else - month -= 3; + month += 12; + year--; } epoch = (365 * year) + (year >> 2) - (year / 100) + (year / 400); // Years to days. - if (!hos_encoding) - { - epoch += (30 * month) + (3 * (month + 1) / 5) + time->day; // Months to days. - epoch -= 719561; // Epoch time is 1/1/1970. - } - else - epoch += (30 * month) + ((3 * month + 2) / 5) + 59 + time->day; // Months to days. + epoch += (30 * month) + (3 * (month + 1) / 5) + time->day; // Months to days. + epoch -= 719561; // Epoch time is 1/1/1970. epoch *= 86400; // Days to seconds. epoch += (3600 * time->hour) + (60 * time->min) + time->sec; // Add hours, minutes and seconds. diff --git a/bootloader/rtc/max77620-rtc.h b/bootloader/rtc/max77620-rtc.h index 99199d2..8c3231e 100644 --- a/bootloader/rtc/max77620-rtc.h +++ b/bootloader/rtc/max77620-rtc.h @@ -72,6 +72,6 @@ typedef struct _rtc_time_t { void max77620_rtc_get_time(rtc_time_t *time); void max77620_rtc_stop_alarm(); void max77620_rtc_epoch_to_date(u32 epoch, rtc_time_t *time); -u32 max77620_rtc_date_to_epoch(const rtc_time_t *time, bool hos_encoding); +u32 max77620_rtc_date_to_epoch(const rtc_time_t *time); #endif /* _MFD_MAX77620_RTC_H_ */ diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index d4bce11..f5d6f4f 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -1145,7 +1145,7 @@ static void _update_status_bar(void *params) max77620_rtc_get_time(&time); if (n_cfg.timeoff) { - u32 epoch = (u32)((s32)max77620_rtc_date_to_epoch(&time, true) + (s32)n_cfg.timeoff); + u32 epoch = (u32)((s32)max77620_rtc_date_to_epoch(&time) + (s32)n_cfg.timeoff); max77620_rtc_epoch_to_date(epoch, &time); } soc_temp = tmp451_get_soc_temp(false); diff --git a/nyx/nyx_gui/libs/fatfs/ffsystem.c b/nyx/nyx_gui/libs/fatfs/ffsystem.c index ce8927d..3c02f40 100644 --- a/nyx/nyx_gui/libs/fatfs/ffsystem.c +++ b/nyx/nyx_gui/libs/fatfs/ffsystem.c @@ -54,7 +54,7 @@ DWORD get_fattime ( max77620_rtc_get_time(&time); if (n_cfg.timeoff) { - u32 epoch = (u32)((s32)max77620_rtc_date_to_epoch(&time, true) + (s32)n_cfg.timeoff); + u32 epoch = (u32)((s32)max77620_rtc_date_to_epoch(&time) + (s32)n_cfg.timeoff); max77620_rtc_epoch_to_date(epoch, &time); } diff --git a/nyx/nyx_gui/rtc/max77620-rtc.c b/nyx/nyx_gui/rtc/max77620-rtc.c index 385c936..04c6937 100644 --- a/nyx/nyx_gui/rtc/max77620-rtc.c +++ b/nyx/nyx_gui/rtc/max77620-rtc.c @@ -119,7 +119,7 @@ void max77620_rtc_epoch_to_date(u32 epoch, rtc_time_t *time) time->weekday = 0; //! TODO. } -u32 max77620_rtc_date_to_epoch(const rtc_time_t *time, bool hos_encoding) +u32 max77620_rtc_date_to_epoch(const rtc_time_t *time) { u32 year, month, epoch; @@ -128,39 +128,17 @@ u32 max77620_rtc_date_to_epoch(const rtc_time_t *time, bool hos_encoding) //Month of year month = time->month; - if (!hos_encoding) + // Month/Year offset. + if(month < 3) { - // Month/Year offset. - if(month < 3) - { - month += 12; - year--; - } - } - else - { - year -= 2000; - month++; - - // Month/Year offset. - if(month < 3) - { - month += 9; - year--; - } - else - month -= 3; + month += 12; + year--; } epoch = (365 * year) + (year >> 2) - (year / 100) + (year / 400); // Years to days. - if (!hos_encoding) - { - epoch += (30 * month) + (3 * (month + 1) / 5) + time->day; // Months to days. - epoch -= 719561; // Epoch time is 1/1/1970. - } - else - epoch += (30 * month) + ((3 * month + 2) / 5) + 59 + time->day; // Months to days. + epoch += (30 * month) + (3 * (month + 1) / 5) + time->day; // Months to days. + epoch -= 719561; // Epoch time is 1/1/1970. epoch *= 86400; // Days to seconds. epoch += (3600 * time->hour) + (60 * time->min) + time->sec; // Add hours, minutes and seconds. diff --git a/nyx/nyx_gui/rtc/max77620-rtc.h b/nyx/nyx_gui/rtc/max77620-rtc.h index 99199d2..8c3231e 100644 --- a/nyx/nyx_gui/rtc/max77620-rtc.h +++ b/nyx/nyx_gui/rtc/max77620-rtc.h @@ -72,6 +72,6 @@ typedef struct _rtc_time_t { void max77620_rtc_get_time(rtc_time_t *time); void max77620_rtc_stop_alarm(); void max77620_rtc_epoch_to_date(u32 epoch, rtc_time_t *time); -u32 max77620_rtc_date_to_epoch(const rtc_time_t *time, bool hos_encoding); +u32 max77620_rtc_date_to_epoch(const rtc_time_t *time); #endif /* _MFD_MAX77620_RTC_H_ */