diff options
-rw-r--r-- | apps/keymaps/keymap-x5.c | 3 | ||||
-rw-r--r-- | firmware/drivers/rtc/rtc_pcf50606.c | 107 | ||||
-rw-r--r-- | firmware/export/config/iaudiom5.h | 3 | ||||
-rw-r--r-- | firmware/export/config/iaudiox5.h | 3 | ||||
-rw-r--r-- | firmware/export/config/iriverh300.h | 3 | ||||
-rw-r--r-- | manual/platform/iriverh300.tex | 7 | ||||
-rw-r--r-- | manual/platform/keymap-iaudiomx5.tex | 6 |
7 files changed, 132 insertions, 0 deletions
diff --git a/apps/keymaps/keymap-x5.c b/apps/keymaps/keymap-x5.c index 235a6c6c74..fb2fbfa605 100644 --- a/apps/keymaps/keymap-x5.c +++ b/apps/keymaps/keymap-x5.c | |||
@@ -268,6 +268,9 @@ static const struct button_mapping remote_button_context_settings[] = { | |||
268 | { ACTION_SETTINGS_DEC, BUTTON_RC_VOL_DOWN, BUTTON_NONE }, | 268 | { ACTION_SETTINGS_DEC, BUTTON_RC_VOL_DOWN, BUTTON_NONE }, |
269 | { ACTION_SETTINGS_DECREPEAT, BUTTON_RC_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, | 269 | { ACTION_SETTINGS_DECREPEAT, BUTTON_RC_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, |
270 | { ACTION_STD_PREV, BUTTON_RC_REW, BUTTON_NONE }, | 270 | { ACTION_STD_PREV, BUTTON_RC_REW, BUTTON_NONE }, |
271 | { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE }, | ||
272 | { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE }, | ||
273 | { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE }, | ||
271 | { ACTION_STD_CANCEL, BUTTON_RC_REC, BUTTON_NONE }, | 274 | { ACTION_STD_CANCEL, BUTTON_RC_REC, BUTTON_NONE }, |
272 | 275 | ||
273 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) | 276 | LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) |
diff --git a/firmware/drivers/rtc/rtc_pcf50606.c b/firmware/drivers/rtc/rtc_pcf50606.c index 2c751e5b01..540ebfff06 100644 --- a/firmware/drivers/rtc/rtc_pcf50606.c +++ b/firmware/drivers/rtc/rtc_pcf50606.c | |||
@@ -26,8 +26,14 @@ | |||
26 | #include "pcf50606.h" | 26 | #include "pcf50606.h" |
27 | #include "timefuncs.h" | 27 | #include "timefuncs.h" |
28 | 28 | ||
29 | /* Values which each disable one alarm time register */ | ||
30 | static const char alarm_disable[] = { | ||
31 | 0x7f, 0x7f, 0x3f, 0x07, 0x3f, 0x1f, 0xff | ||
32 | }; | ||
33 | |||
29 | void rtc_init(void) | 34 | void rtc_init(void) |
30 | { | 35 | { |
36 | rtc_check_alarm_started(false); | ||
31 | } | 37 | } |
32 | 38 | ||
33 | int rtc_read_datetime(struct tm *tm) | 39 | int rtc_read_datetime(struct tm *tm) |
@@ -97,3 +103,104 @@ int rtc_write_datetime(const struct tm *tm) | |||
97 | return rc; | 103 | return rc; |
98 | } | 104 | } |
99 | 105 | ||
106 | /** | ||
107 | * Checks the PCF interrupt 1 register bit 7 to see if an alarm interrupt has | ||
108 | * triggered since last we checked. | ||
109 | */ | ||
110 | bool rtc_check_alarm_flag(void) | ||
111 | { | ||
112 | int oldlevel = disable_irq_save(); | ||
113 | int rc = pcf50606_read(0x02) & 0x80; | ||
114 | restore_irq(oldlevel); | ||
115 | return rc; | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * Enables or disables the alarm. | ||
120 | * The Ipod bootloader clears all PCF interrupt registers and always enables | ||
121 | * the "wake on RTC" bit on OOCC1, so we have to rely on other means to find | ||
122 | * out if we just woke from an alarm. | ||
123 | * Return value is always false for us. | ||
124 | */ | ||
125 | void rtc_enable_alarm(bool enable) | ||
126 | { | ||
127 | int oldlevel = disable_irq_save(); | ||
128 | if (enable) { | ||
129 | /* Tell the PCF to ignore everything but second, minute and hour, so | ||
130 | * that an alarm will trigger the next time the alarm time occurs. | ||
131 | */ | ||
132 | pcf50606_write_multiple(0x14, alarm_disable + 3, 4); | ||
133 | /* Unmask the alarm interrupt (might be unneeded) */ | ||
134 | pcf50606_write(0x5, pcf50606_read(0x5) & ~0x80); | ||
135 | /* Make sure wake on RTC is set when shutting down */ | ||
136 | pcf50606_write(0x8, pcf50606_read(0x8) | 0x10); | ||
137 | } else { | ||
138 | /* We use this year to indicate a disabled alarm. If you happen to live | ||
139 | * around this time and are annoyed by this, feel free to seek out my | ||
140 | * grave and do something nasty to it. | ||
141 | */ | ||
142 | pcf50606_write(0x17, 0x99); | ||
143 | /* Make sure we don't wake on RTC after shutting down */ | ||
144 | pcf50606_write(0x8, pcf50606_read(0x8) & ~0x10); | ||
145 | } | ||
146 | restore_irq(oldlevel); | ||
147 | return; | ||
148 | } | ||
149 | |||
150 | /** | ||
151 | * Check if alarm caused unit to start. | ||
152 | */ | ||
153 | bool rtc_check_alarm_started(bool release_alarm) | ||
154 | { | ||
155 | static bool run_before = false, alarm_state; | ||
156 | bool rc; | ||
157 | |||
158 | if (run_before) { | ||
159 | rc = alarm_state; | ||
160 | alarm_state &= ~release_alarm; | ||
161 | } else { | ||
162 | char rt[3], at[3]; | ||
163 | /* The Ipod bootloader seems to read (and thus clear) the PCF interrupt | ||
164 | * registers, so we need to find some other way to detect if an alarm | ||
165 | * just happened | ||
166 | */ | ||
167 | int oldlevel = disable_irq_save(); | ||
168 | pcf50606_read_multiple(0x0a, rt, 3); | ||
169 | pcf50606_read_multiple(0x11, at, 3); | ||
170 | restore_irq(oldlevel); | ||
171 | |||
172 | /* If alarm time and real time match within 10 seconds of each other, we | ||
173 | * assume an alarm just triggered | ||
174 | */ | ||
175 | rc = alarm_state = rt[1] == at[1] && rt[2] == at[2] | ||
176 | && (rt[0] - at[0]) <= 10; | ||
177 | run_before = true; | ||
178 | } | ||
179 | return rc; | ||
180 | } | ||
181 | |||
182 | |||
183 | /* set alarm time registers to the given time (repeat once per day) */ | ||
184 | void rtc_set_alarm(int h, int m) | ||
185 | { | ||
186 | int oldlevel = disable_irq_save(); | ||
187 | /* Set us to wake at the first second of the specified time */ | ||
188 | pcf50606_write(0x11, 0); | ||
189 | /* Convert to BCD */ | ||
190 | pcf50606_write(0x12, ((m/10) << 4) | m%10); | ||
191 | pcf50606_write(0x13, ((h/10) << 4) | h%10); | ||
192 | restore_irq(oldlevel); | ||
193 | } | ||
194 | |||
195 | /* read out the current alarm time */ | ||
196 | void rtc_get_alarm(int *h, int *m) | ||
197 | { | ||
198 | char buf[2]; | ||
199 | |||
200 | int oldlevel = disable_irq_save(); | ||
201 | pcf50606_read_multiple(0x12, buf, 2); | ||
202 | restore_irq(oldlevel); | ||
203 | /* Convert from BCD */ | ||
204 | *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f); | ||
205 | *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f); | ||
206 | } | ||
diff --git a/firmware/export/config/iaudiom5.h b/firmware/export/config/iaudiom5.h index f1ef78ae24..19c77ceb2d 100644 --- a/firmware/export/config/iaudiom5.h +++ b/firmware/export/config/iaudiom5.h | |||
@@ -98,6 +98,9 @@ | |||
98 | /* define this if you have a real-time clock */ | 98 | /* define this if you have a real-time clock */ |
99 | #define CONFIG_RTC RTC_PCF50606 | 99 | #define CONFIG_RTC RTC_PCF50606 |
100 | 100 | ||
101 | /* define this if you have a real-time clock alarm */ | ||
102 | #define HAVE_RTC_ALARM | ||
103 | |||
101 | /* Define this if you have an remote lcd */ | 104 | /* Define this if you have an remote lcd */ |
102 | #define HAVE_REMOTE_LCD | 105 | #define HAVE_REMOTE_LCD |
103 | 106 | ||
diff --git a/firmware/export/config/iaudiox5.h b/firmware/export/config/iaudiox5.h index 62f6d595e3..d74c4472e9 100644 --- a/firmware/export/config/iaudiox5.h +++ b/firmware/export/config/iaudiox5.h | |||
@@ -100,6 +100,9 @@ | |||
100 | /* define this if you have a real-time clock */ | 100 | /* define this if you have a real-time clock */ |
101 | #define CONFIG_RTC RTC_PCF50606 | 101 | #define CONFIG_RTC RTC_PCF50606 |
102 | 102 | ||
103 | /* define this if you have a real-time clock alarm */ | ||
104 | #define HAVE_RTC_ALARM | ||
105 | |||
103 | /* Define this if you have an remote lcd */ | 106 | /* Define this if you have an remote lcd */ |
104 | #define HAVE_REMOTE_LCD | 107 | #define HAVE_REMOTE_LCD |
105 | 108 | ||
diff --git a/firmware/export/config/iriverh300.h b/firmware/export/config/iriverh300.h index ce8f2151f0..0be9d0da7a 100644 --- a/firmware/export/config/iriverh300.h +++ b/firmware/export/config/iriverh300.h | |||
@@ -76,6 +76,9 @@ | |||
76 | that needs spinups and can cause skips when shaked */ | 76 | that needs spinups and can cause skips when shaked */ |
77 | #define HAVE_DISK_STORAGE | 77 | #define HAVE_DISK_STORAGE |
78 | 78 | ||
79 | /* Define if the device can wake from an RTC alarm */ | ||
80 | #define HAVE_RTC_ALARM | ||
81 | |||
79 | /* Define this if you have an remote lcd */ | 82 | /* Define this if you have an remote lcd */ |
80 | #define HAVE_REMOTE_LCD | 83 | #define HAVE_REMOTE_LCD |
81 | 84 | ||
diff --git a/manual/platform/iriverh300.tex b/manual/platform/iriverh300.tex index 1a5ac37654..8f48c5be40 100644 --- a/manual/platform/iriverh300.tex +++ b/manual/platform/iriverh300.tex | |||
@@ -27,3 +27,10 @@ | |||
27 | % link external keymap file | 27 | % link external keymap file |
28 | \input{platform/keymap-iriverh100_h300.tex} | 28 | \input{platform/keymap-iriverh100_h300.tex} |
29 | 29 | ||
30 | % Unique to h300 | ||
31 | % | ||
32 | %Button actions, Alarm screen | ||
33 | \newcommand{\ActionAlarmSet}{\ButtonSelect{} or \ButtonPlay} | ||
34 | \newcommand{\ActionAlarmCancel}{\ButtonPower{} or \ButtonRec} | ||
35 | \newcommand{\ActionAlarmHoursInc}{\ButtonRight} | ||
36 | \newcommand{\ActionAlarmHoursDec}{\ButtonLeft} | ||
diff --git a/manual/platform/keymap-iaudiomx5.tex b/manual/platform/keymap-iaudiomx5.tex index f4d4ec81f8..7b0838902a 100644 --- a/manual/platform/keymap-iaudiomx5.tex +++ b/manual/platform/keymap-iaudiomx5.tex | |||
@@ -49,6 +49,12 @@ | |||
49 | \newcommand{\ActionSettingInc}{\ButtonUp} | 49 | \newcommand{\ActionSettingInc}{\ButtonUp} |
50 | \newcommand{\ActionSettingDec}{\ButtonDown} | 50 | \newcommand{\ActionSettingDec}{\ButtonDown} |
51 | 51 | ||
52 | %Button actions, Alarm screen | ||
53 | \newcommand{\ActionAlarmSet}{\ButtonSelect{} or \ButtonPlay} | ||
54 | \newcommand{\ActionAlarmCancel}{\ButtonPower{} or \ButtonRec} | ||
55 | \newcommand{\ActionAlarmHoursInc}{\ButtonRight} | ||
56 | \newcommand{\ActionAlarmHoursDec}{\ButtonLeft} | ||
57 | |||
52 | %Button actions, Virtual Keyboard Context | 58 | %Button actions, Virtual Keyboard Context |
53 | \newcommand{\ActionKbdLeft}{\ButtonLeft} | 59 | \newcommand{\ActionKbdLeft}{\ButtonLeft} |
54 | \newcommand{\ActionKbdRight}{\ButtonRight} | 60 | \newcommand{\ActionKbdRight}{\ButtonRight} |