fix bug in RTC leap year check

This commit is contained in:
Edward Emelianov 2023-01-14 16:57:07 +03:00
parent 44f7660ea0
commit 28a2bc9d72

View File

@ -54,7 +54,10 @@ int rtc_setdate(rtc_t *d){
if(d->year > 99) return FALSE; if(d->year > 99) return FALSE;
if(d->month > 12 || d->month == 0) 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->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; if(d->weekday > 7 || d->weekday == 0) return FALSE;
RTC->ICSR |= RTC_ICSR_INIT; RTC->ICSR |= RTC_ICSR_INIT;
WAITWHILE(!(RTC->ICSR & RTC_ICSR_INITF)); WAITWHILE(!(RTC->ICSR & RTC_ICSR_INITF));