RTC: use the full 8 byte

This commit is contained in:
d0k3 2017-11-09 00:21:18 +01:00
parent 3ccd81da2c
commit 463f2881da
2 changed files with 5 additions and 4 deletions

View File

@ -28,13 +28,13 @@ bool is_valid_dstime(DsTime* dstime) {
}
bool get_dstime(DsTime* dstime) {
return (I2C_readRegBuf(I2C_DEV_MCU, 0x30, (void*) dstime, 7));
return (I2C_readRegBuf(I2C_DEV_MCU, 0x30, (void*) dstime, sizeof(DsTime)));
}
bool set_dstime(DsTime* dstime) {
if (!is_valid_dstime(dstime)) return false;
for (u32 i = 0; i < 7; i++) {
if (i == 3) continue; // skip the unknown byte
for (u32 i = 0; i < sizeof(DsTime); i++) {
if ((i == 3) || (i == 7)) continue; // skip the unused bytes
if (!I2C_writeReg(I2C_DEV_MCU, 0x30+i, ((u8*)dstime)[i]))
return false;
}

View File

@ -12,10 +12,11 @@ typedef struct {
u8 bcd_s;
u8 bcd_m;
u8 bcd_h;
u8 unknown;
u8 weekday;
u8 bcd_D;
u8 bcd_M;
u8 bcd_Y;
u8 leap_count;
} __attribute__((packed)) DsTime;
bool is_valid_dstime(DsTime* dstime);