diff options
| author | Nils Wallménius <nils@rockbox.org> | 2009-09-26 14:58:32 +0000 |
|---|---|---|
| committer | Nils Wallménius <nils@rockbox.org> | 2009-09-26 14:58:32 +0000 |
| commit | c8b87d76eb506d374edd2631d4c29e4300be84c4 (patch) | |
| tree | 5d380f1f32f317afc579798c5fc4d988e9c48122 /firmware/drivers/rtc/rtc_s35390a.c | |
| parent | 66d5bd7cf8c10971578c643c16f72b51df4a1ddf (diff) | |
| download | rockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.zip rockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.tar.gz rockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.tar.bz2 rockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.tar.xz | |
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
Diffstat (limited to 'firmware/drivers/rtc/rtc_s35390a.c')
| -rw-r--r-- | firmware/drivers/rtc/rtc_s35390a.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/firmware/drivers/rtc/rtc_s35390a.c b/firmware/drivers/rtc/rtc_s35390a.c index 6bcf5c9..0b95431 100644 --- a/firmware/drivers/rtc/rtc_s35390a.c +++ b/firmware/drivers/rtc/rtc_s35390a.c @@ -58,35 +58,49 @@ void rtc_init(void) { } -int rtc_read_datetime(unsigned char* buf) +int rtc_read_datetime(struct tm *tm) { - unsigned char data[7]; + unsigned char buf[7]; int i, ret; - ret = i2c_read(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(data), data); - reverse_bits(data, sizeof(data)); + ret = i2c_read(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(buf), buf); + reverse_bits(buf, sizeof(buf)); buf[4] &= 0x3f; /* mask out p.m. flag */ - - for (i = 0; i < 7; i++) { - buf[i] = data[6 - i]; - } + + for (i = 0; i < sizeof(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 ret; } -int rtc_write_datetime(unsigned char* buf) +int rtc_write_datetime(const struct tm *tm) { - unsigned char data[7]; + unsigned char buf[7]; int i, ret; - for (i = 0; i < 7; i++) { - data[i] = buf[6 - i]; - } - - reverse_bits(data, sizeof(data)); - ret = i2c_write(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(data), data); - + 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++) + DEC2BCD(buf[i]); + + reverse_bits(buf, sizeof(buf)); + ret = i2c_write(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(buf), buf); + return ret; } |