mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 02:35:23 +03:00
fix bug in RTC leap year check
This commit is contained in:
parent
44f7660ea0
commit
28a2bc9d72
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user