From 34288fea43407fcf4ff530dea89030d656055804 Mon Sep 17 00:00:00 2001 From: Barry Wardell Date: Wed, 14 Nov 2007 16:53:31 +0000 Subject: [PATCH] FS#8157: H10 RTC alarm with some changes by me. The settings keymap had to be changed slightly, but it seems to work better for all setting screens with the new keymap. Thanks to git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15620 a1c6a512-1295-4272-9138-f99709370657 --- apps/keymaps/keymap-h10.c | 8 +- apps/lang/english.lang | 2 + firmware/drivers/rtc/rtc_e8564.c | 138 +++++++++++++++++++++++++++++-- firmware/export/config-h10.h | 1 + firmware/export/config-h10_5gb.h | 1 + 5 files changed, 141 insertions(+), 9 deletions(-) diff --git a/apps/keymaps/keymap-h10.c b/apps/keymaps/keymap-h10.c index 883b0d37d4..2ea934bd9a 100644 --- a/apps/keymaps/keymap-h10.c +++ b/apps/keymaps/keymap-h10.c @@ -117,10 +117,10 @@ static const struct button_mapping button_context_settings[] = { { ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE }, { ACTION_SETTINGS_DEC, BUTTON_SCROLL_DOWN, BUTTON_NONE }, { ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, - { ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE }, - { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, - { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE }, - { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_STD_PREV, BUTTON_FF, BUTTON_NONE }, + { ACTION_STD_PREVREPEAT, BUTTON_FF|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_STD_NEXT, BUTTON_REW, BUTTON_NONE }, + { ACTION_STD_NEXTREPEAT, BUTTON_REW|BUTTON_REPEAT, BUTTON_NONE }, { ACTION_SETTINGS_RESET, BUTTON_PLAY, BUTTON_NONE }, LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), diff --git a/apps/lang/english.lang b/apps/lang/english.lang index e79f865bde..1e7e5154bc 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -4740,11 +4740,13 @@ *: none alarm: "PLAY=Set OFF=Cancel" ipod*: "SELECT=Set MENU=Cancel" + h10,h10_5gb: "SELECT=Set PREV=Cancel" *: none alarm: "PLAY=Set OFF=Cancel" ipod*: "SELECT=Set MENU=Cancel" + h10,h10_5gb: "SELECT=Set PREV=Cancel" *: none diff --git a/firmware/drivers/rtc/rtc_e8564.c b/firmware/drivers/rtc/rtc_e8564.c index c3ae9349f4..0e81ee276d 100644 --- a/firmware/drivers/rtc/rtc_e8564.c +++ b/firmware/drivers/rtc/rtc_e8564.c @@ -7,7 +7,8 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum + * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum, + * Przemyslaw Holubowski * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. @@ -25,12 +26,27 @@ #include /* RTC registers */ -#define RTC_CTRL1 0x00 -#define RTC_CTRL2 0x01 +#define RTC_CTRL1 0x00 +#define RTC_CTRL2 0x01 +#define RTC_ALARM_MINUTES 0x09 +#define RTC_ALARM_HOURS 0x0A +#define RTC_ALARM_DAY 0x0B +#define RTC_ALARM_WDAY 0x0C +#define RTC_TIMER_CTRL 0x0E +#define RTC_TIMER 0x0F /* Control 2 register flags */ -#define RTC_TF 0x04 -#define RTC_AF 0x08 +#define RTC_TIE 0x01 +#define RTC_AIE 0x02 +#define RTC_TF 0x04 +#define RTC_AF 0x08 +#define RTC_TI_TP 0x10 + +/* Alarm registers flags */ +#define RTC_AE 0x80 + +/* Timer register flags */ +#define RTC_TE 0x80 void rtc_init(void) { @@ -82,3 +98,115 @@ int rtc_write_datetime(unsigned char* buf) return 1; } +void rtc_set_alarm(int h, int m) +{ + unsigned char buf[4]={0}; + int rv=0; + int i=0; + + /* clear alarm interrupt */ + rv = i2c_readbytes(0x51,RTC_CTRL2,1,buf); + buf[0] &= RTC_AF; + pp_i2c_send(0x51, RTC_CTRL2,buf[0]); + + /* prepare new alarm */ + if( m >= 0 ) + buf[0] = (((m/10) << 4) | m%10); + else + /* ignore minutes comparison query */ + buf[0] = RTC_AE; + + if( h >= 0 ) + buf[1] = (((h/10) << 4) | h%10); + else + /* ignore hours comparison query */ + buf[1] = RTC_AE; + + /* ignore day and wday */ + buf[2] = RTC_AE; + buf[3] = RTC_AE; + + /* write new alarm */ + for(;i<4;i++) + pp_i2c_send(0x51, RTC_ALARM_MINUTES+i,buf[i]); + + /* note: alarm is not enabled at the point */ +} + +void rtc_get_alarm(int *h, int *m) +{ + unsigned char buf[4]={0}; + + /* get alarm preset */ + i2c_readbytes(0x51, RTC_ALARM_MINUTES,4,buf); + + *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f); + *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f); + +} + +bool rtc_enable_alarm(bool enable) +{ + unsigned char tmp=0; + int rv=0; + + if(enable) + { + /* enable alarm interrupt */ + rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); + tmp |= RTC_AIE; + pp_i2c_send(0x51, RTC_CTRL2,tmp); + } + else + { + /* disable alarm interrupt */ + rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); + tmp &= ~RTC_AIE; + pp_i2c_send(0x51, RTC_CTRL2,tmp); + } + + return false; +} + +bool rtc_check_alarm_started(bool release_alarm) +{ + static bool alarm_state, run_before = false; + unsigned char tmp=0; + bool started; + int rv=0; + + if (run_before) + { + started = alarm_state; + alarm_state &= ~release_alarm; + } + else + { + /* read Control 2 register which contains alarm flag */ + rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); + + alarm_state = started = tmp & (RTC_AF | RTC_AIE); + + if(release_alarm) + { + rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); + /* clear alarm interrupt enable and alarm flag */ + tmp &= ~(RTC_AF | RTC_AIE); + pp_i2c_send(0x51, RTC_CTRL2,tmp); + } + run_before = true; + } + + return started; +} + +bool rtc_check_alarm_flag(void) +{ + unsigned char tmp=0; + int rv=0; + + /* read Control 2 register which contains alarm flag */ + rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); + + return (tmp & RTC_AF); +} diff --git a/firmware/export/config-h10.h b/firmware/export/config-h10.h index e1e0b54e28..aa60b106da 100644 --- a/firmware/export/config-h10.h +++ b/firmware/export/config-h10.h @@ -68,6 +68,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_E8564 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-h10_5gb.h b/firmware/export/config-h10_5gb.h index b7195221ca..e8f7d7562a 100644 --- a/firmware/export/config-h10_5gb.h +++ b/firmware/export/config-h10_5gb.h @@ -54,6 +54,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_E8564 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */