forked from len0rd/rockbox
FS#10569 RTC driver cleanup
Change the RTC drivers so that the rtc_(read|write)_datetime functions now deal directly with the tm struct instead of passing a string of bcd digits to/from (set|get)_time . This simplifies drivers for rtc's that do not use a bcd representation internally and cleans up some target specific code and #ifdefs in generic code. Implement simple stubs for the sim to avoid #ifdefing for that too. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22839 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
66d5bd7cf8
commit
c8b87d76eb
16 changed files with 452 additions and 373 deletions
|
|
@ -124,31 +124,49 @@ void rtc_init(void)
|
|||
|
||||
}
|
||||
|
||||
int rtc_read_datetime(unsigned char* buf)
|
||||
int rtc_read_datetime(struct tm *tm)
|
||||
{
|
||||
int i;
|
||||
unsigned char v[7];
|
||||
unsigned int i;
|
||||
int rc;
|
||||
unsigned char buf[7];
|
||||
|
||||
i = sw_i2c(SW_I2C_READ, RTC_CMD_DATA, v, 7);
|
||||
rc = sw_i2c(SW_I2C_READ, RTC_CMD_DATA, buf, sizeof(buf));
|
||||
|
||||
v[4] &= 0x3f; /* mask out p.m. flag */
|
||||
buf[4] &= 0x3f; /* mask out p.m. flag */
|
||||
|
||||
for(i=0; i<7; i++)
|
||||
buf[i] = v[6-i];
|
||||
|
||||
return i;
|
||||
for (i = 0; i < sizeof(buf); i++)
|
||||
buf[i] = BCD2DEC(buf[i]);
|
||||
|
||||
tm->tm_sec = buf[6];
|
||||
tm->tm_min = buf[5];
|
||||
tm->tm_hour = buf[4];
|
||||
tm->tm_wday = buf[3];
|
||||
tm->tm_mday = buf[2];
|
||||
tm->tm_mon = buf[1] - 1;
|
||||
tm->tm_year = buf[0] + 100;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int rtc_write_datetime(unsigned char* buf)
|
||||
int rtc_write_datetime(const struct tm *tm)
|
||||
{
|
||||
int i;
|
||||
unsigned char v[7];
|
||||
unsigned int i;
|
||||
int rc;
|
||||
unsigned char buf[7];
|
||||
|
||||
for(i=0; i<7; i++)
|
||||
v[i]=buf[6-i];
|
||||
|
||||
i = sw_i2c(SW_I2C_WRITE, RTC_CMD_DATA, v, 7);
|
||||
|
||||
return i;
|
||||
buf[6] = tm->tm_sec;
|
||||
buf[5] = tm->tm_min;
|
||||
buf[4] = tm->tm_hour;
|
||||
buf[3] = tm->tm_wday;
|
||||
buf[2] = tm->tm_mday;
|
||||
buf[1] = tm->tm_mon + 1;
|
||||
buf[0] = tm->tm_year - 100;
|
||||
|
||||
for (i = 0; i < sizeof(buf); i++)
|
||||
buf[i] = DEC2BCD(buf[i]);
|
||||
|
||||
rc = sw_i2c(SW_I2C_WRITE, RTC_CMD_DATA, buf, sizeof(buf));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue