summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-11-14 16:53:31 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-11-14 16:53:31 +0000
commit34288fea43407fcf4ff530dea89030d656055804 (patch)
treeff62742953f342849b7e21cc4b538de38f97ff1a
parente18125eec2bc4d48cb8857313b52d458bc352075 (diff)
downloadrockbox-34288fea43407fcf4ff530dea89030d656055804.tar.gz
rockbox-34288fea43407fcf4ff530dea89030d656055804.zip
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
-rw-r--r--apps/keymaps/keymap-h10.c8
-rw-r--r--apps/lang/english.lang2
-rw-r--r--firmware/drivers/rtc/rtc_e8564.c138
-rw-r--r--firmware/export/config-h10.h1
-rw-r--r--firmware/export/config-h10_5gb.h1
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[] = {
117 { ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE }, 117 { ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE },
118 { ACTION_SETTINGS_DEC, BUTTON_SCROLL_DOWN, BUTTON_NONE }, 118 { ACTION_SETTINGS_DEC, BUTTON_SCROLL_DOWN, BUTTON_NONE },
119 { ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, 119 { ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE },
120 { ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE }, 120 { ACTION_STD_PREV, BUTTON_FF, BUTTON_NONE },
121 { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, 121 { ACTION_STD_PREVREPEAT, BUTTON_FF|BUTTON_REPEAT, BUTTON_NONE },
122 { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE }, 122 { ACTION_STD_NEXT, BUTTON_REW, BUTTON_NONE },
123 { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, 123 { ACTION_STD_NEXTREPEAT, BUTTON_REW|BUTTON_REPEAT, BUTTON_NONE },
124 { ACTION_SETTINGS_RESET, BUTTON_PLAY, BUTTON_NONE }, 124 { ACTION_SETTINGS_RESET, BUTTON_PLAY, BUTTON_NONE },
125 125
126 LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD), 126 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 @@
4740 *: none 4740 *: none
4741 alarm: "PLAY=Set OFF=Cancel" 4741 alarm: "PLAY=Set OFF=Cancel"
4742 ipod*: "SELECT=Set MENU=Cancel" 4742 ipod*: "SELECT=Set MENU=Cancel"
4743 h10,h10_5gb: "SELECT=Set PREV=Cancel"
4743 </source> 4744 </source>
4744 <dest> 4745 <dest>
4745 *: none 4746 *: none
4746 alarm: "PLAY=Set OFF=Cancel" 4747 alarm: "PLAY=Set OFF=Cancel"
4747 ipod*: "SELECT=Set MENU=Cancel" 4748 ipod*: "SELECT=Set MENU=Cancel"
4749 h10,h10_5gb: "SELECT=Set PREV=Cancel"
4748 </dest> 4750 </dest>
4749 <voice> 4751 <voice>
4750 *: none 4752 *: 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 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum 10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum,
11 * Przemyslaw Holubowski
11 * 12 *
12 * All files in this archive are subject to the GNU General Public License. 13 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement. 14 * See the file COPYING in the source tree root for full license agreement.
@@ -25,12 +26,27 @@
25#include <stdbool.h> 26#include <stdbool.h>
26 27
27/* RTC registers */ 28/* RTC registers */
28#define RTC_CTRL1 0x00 29#define RTC_CTRL1 0x00
29#define RTC_CTRL2 0x01 30#define RTC_CTRL2 0x01
31#define RTC_ALARM_MINUTES 0x09
32#define RTC_ALARM_HOURS 0x0A
33#define RTC_ALARM_DAY 0x0B
34#define RTC_ALARM_WDAY 0x0C
35#define RTC_TIMER_CTRL 0x0E
36#define RTC_TIMER 0x0F
30 37
31/* Control 2 register flags */ 38/* Control 2 register flags */
32#define RTC_TF 0x04 39#define RTC_TIE 0x01
33#define RTC_AF 0x08 40#define RTC_AIE 0x02
41#define RTC_TF 0x04
42#define RTC_AF 0x08
43#define RTC_TI_TP 0x10
44
45/* Alarm registers flags */
46#define RTC_AE 0x80
47
48/* Timer register flags */
49#define RTC_TE 0x80
34 50
35void rtc_init(void) 51void rtc_init(void)
36{ 52{
@@ -82,3 +98,115 @@ int rtc_write_datetime(unsigned char* buf)
82 return 1; 98 return 1;
83} 99}
84 100
101void rtc_set_alarm(int h, int m)
102{
103 unsigned char buf[4]={0};
104 int rv=0;
105 int i=0;
106
107 /* clear alarm interrupt */
108 rv = i2c_readbytes(0x51,RTC_CTRL2,1,buf);
109 buf[0] &= RTC_AF;
110 pp_i2c_send(0x51, RTC_CTRL2,buf[0]);
111
112 /* prepare new alarm */
113 if( m >= 0 )
114 buf[0] = (((m/10) << 4) | m%10);
115 else
116 /* ignore minutes comparison query */
117 buf[0] = RTC_AE;
118
119 if( h >= 0 )
120 buf[1] = (((h/10) << 4) | h%10);
121 else
122 /* ignore hours comparison query */
123 buf[1] = RTC_AE;
124
125 /* ignore day and wday */
126 buf[2] = RTC_AE;
127 buf[3] = RTC_AE;
128
129 /* write new alarm */
130 for(;i<4;i++)
131 pp_i2c_send(0x51, RTC_ALARM_MINUTES+i,buf[i]);
132
133 /* note: alarm is not enabled at the point */
134}
135
136void rtc_get_alarm(int *h, int *m)
137{
138 unsigned char buf[4]={0};
139
140 /* get alarm preset */
141 i2c_readbytes(0x51, RTC_ALARM_MINUTES,4,buf);
142
143 *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f);
144 *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f);
145
146}
147
148bool rtc_enable_alarm(bool enable)
149{
150 unsigned char tmp=0;
151 int rv=0;
152
153 if(enable)
154 {
155 /* enable alarm interrupt */
156 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
157 tmp |= RTC_AIE;
158 pp_i2c_send(0x51, RTC_CTRL2,tmp);
159 }
160 else
161 {
162 /* disable alarm interrupt */
163 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
164 tmp &= ~RTC_AIE;
165 pp_i2c_send(0x51, RTC_CTRL2,tmp);
166 }
167
168 return false;
169}
170
171bool rtc_check_alarm_started(bool release_alarm)
172{
173 static bool alarm_state, run_before = false;
174 unsigned char tmp=0;
175 bool started;
176 int rv=0;
177
178 if (run_before)
179 {
180 started = alarm_state;
181 alarm_state &= ~release_alarm;
182 }
183 else
184 {
185 /* read Control 2 register which contains alarm flag */
186 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
187
188 alarm_state = started = tmp & (RTC_AF | RTC_AIE);
189
190 if(release_alarm)
191 {
192 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
193 /* clear alarm interrupt enable and alarm flag */
194 tmp &= ~(RTC_AF | RTC_AIE);
195 pp_i2c_send(0x51, RTC_CTRL2,tmp);
196 }
197 run_before = true;
198 }
199
200 return started;
201}
202
203bool rtc_check_alarm_flag(void)
204{
205 unsigned char tmp=0;
206 int rv=0;
207
208 /* read Control 2 register which contains alarm flag */
209 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
210
211 return (tmp & RTC_AF);
212}
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 @@
68/* define this if you have a real-time clock */ 68/* define this if you have a real-time clock */
69#ifndef BOOTLOADER 69#ifndef BOOTLOADER
70#define CONFIG_RTC RTC_E8564 70#define CONFIG_RTC RTC_E8564
71#define HAVE_RTC_ALARM
71#endif 72#endif
72 73
73/* Define this if you have a software controlled poweroff */ 74/* 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 @@
54/* define this if you have a real-time clock */ 54/* define this if you have a real-time clock */
55#ifndef BOOTLOADER 55#ifndef BOOTLOADER
56#define CONFIG_RTC RTC_E8564 56#define CONFIG_RTC RTC_E8564
57#define HAVE_RTC_ALARM
57#endif 58#endif
58 59
59/* Define this if you have a software controlled poweroff */ 60/* Define this if you have a software controlled poweroff */