From 28a2bc9d7230af32e38c3b9cabb6d3cd17ccbba3 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Sat, 14 Jan 2023 16:57:07 +0300 Subject: [PATCH] fix bug in RTC leap year check --- G0:G070/RTC/rtc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/G0:G070/RTC/rtc.c b/G0:G070/RTC/rtc.c index 8ba2c06..9c5382a 100644 --- a/G0:G070/RTC/rtc.c +++ b/G0:G070/RTC/rtc.c @@ -54,7 +54,10 @@ int rtc_setdate(rtc_t *d){ if(d->year > 99) return FALSE; if(d->month > 12 || d->month == 0) return FALSE; if(d->day > maxdays[d->month - 1] || d->day == 0) return FALSE; - if(d->month == 2 && d->day == 29 && (d->year & 4) != 4) return FALSE; // not leap year + if(d->month == 2 && d->day == 29){ + uint8_t test = (d->year >> 2) << 2; + if(d->year != test) return FALSE; // not leap year + } if(d->weekday > 7 || d->weekday == 0) return FALSE; RTC->ICSR |= RTC_ICSR_INIT; WAITWHILE(!(RTC->ICSR & RTC_ICSR_INITF));