summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/rtc/rtc_pcf50605.c
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2009-09-26 14:58:32 +0000
committerNils Wallménius <nils@rockbox.org>2009-09-26 14:58:32 +0000
commitc8b87d76eb506d374edd2631d4c29e4300be84c4 (patch)
tree5d380f1f32f317afc579798c5fc4d988e9c48122 /firmware/drivers/rtc/rtc_pcf50605.c
parent66d5bd7cf8c10971578c643c16f72b51df4a1ddf (diff)
downloadrockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.tar.gz
rockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.tar.bz2
rockbox-c8b87d76eb506d374edd2631d4c29e4300be84c4.zip
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_pcf50605.c')
-rw-r--r--firmware/drivers/rtc/rtc_pcf50605.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/firmware/drivers/rtc/rtc_pcf50605.c b/firmware/drivers/rtc/rtc_pcf50605.c
index fe12766c4a..b030fba37a 100644
--- a/firmware/drivers/rtc/rtc_pcf50605.c
+++ b/firmware/drivers/rtc/rtc_pcf50605.c
@@ -36,14 +36,45 @@ void rtc_init(void)
rtc_check_alarm_started(false);
}
-int rtc_read_datetime(unsigned char* buf)
+int rtc_read_datetime(struct tm *tm)
{
- return pcf50605_read_multiple(0x0a, buf, 7);
+ unsigned int i;
+ int rc;
+ unsigned char buf[7];
+ rc = pcf50605_read_multiple(0x0a, buf, sizeof(buf));
+
+ for (i = 0; i < sizeof(buf); i++)
+ buf[i] = BCD2DEC(buf[i]);
+
+ tm->tm_sec = buf[0];
+ tm->tm_min = buf[1];
+ tm->tm_hour = buf[2];
+ tm->tm_wday = buf[3];
+ tm->tm_mday = buf[4];
+ tm->tm_mon = buf[5] - 1;
+ tm->tm_year = buf[6] + 100;
+
+ return rc;
}
-int rtc_write_datetime(unsigned char* buf)
+int rtc_write_datetime(const struct tm *tm)
{
- pcf50605_write_multiple(0x0a, buf, 7);
+ unsigned int i;
+ unsigned char buf[7];
+
+ buf[0] = tm->tm_sec;
+ buf[1] = tm->tm_min;
+ buf[2] = tm->tm_hour;
+ buf[3] = tm->tm_wday;
+ buf[4] = tm->tm_mday;
+ buf[5] = tm->tm_mon + 1;
+ buf[6] = tm->tm_year - 100;
+
+ for (i = 0; i < sizeof(buf); i++)
+ buf[i] = DEC2BCD(buf[i]);
+
+ pcf50605_write_multiple(0x0a, buf, sizeof(buf));
+
return 1;
}
@@ -121,17 +152,17 @@ void rtc_set_alarm(int h, int m)
/* Set us to wake at the first second of the specified time */
pcf50605_write(0x11, 0);
/* Convert to BCD */
- pcf50605_write(0x12, ((m/10) << 4) | m%10);
- pcf50605_write(0x13, ((h/10) << 4) | h%10);
+ pcf50605_write(0x12, DEC2BCD(m));
+ pcf50605_write(0x13, DEC2BCD(h));
}
void rtc_get_alarm(int *h, int *m)
{
char buf[2];
- pcf50605_read_multiple(0x12, buf, 2);
+ pcf50605_read_multiple(0x12, buf, sizeof(buf));
/* Convert from BCD */
- *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f);
- *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f);
+ *m = BCD2DEC(buf[0]);
+ *h = BCD2DEC(buf[1]);
}