diff options
-rw-r--r-- | apps/alarm_menu.c | 4 | ||||
-rw-r--r-- | apps/lang/english.lang | 2 | ||||
-rw-r--r-- | apps/menus/settings_menu.c | 6 | ||||
-rw-r--r-- | apps/tree.c | 2 | ||||
-rw-r--r-- | firmware/drivers/pcf50605.c | 10 | ||||
-rw-r--r-- | firmware/drivers/rtc/rtc_ds1339_ds3231.c | 6 | ||||
-rw-r--r-- | firmware/drivers/rtc/rtc_m41st84w.c | 8 | ||||
-rw-r--r-- | firmware/drivers/rtc/rtc_pcf50605.c | 94 | ||||
-rw-r--r-- | firmware/export/config-fmrecorder.h | 2 | ||||
-rw-r--r-- | firmware/export/config-h120.h | 2 | ||||
-rw-r--r-- | firmware/export/config-ipod3g.h | 1 | ||||
-rw-r--r-- | firmware/export/config-ipod4g.h | 1 | ||||
-rw-r--r-- | firmware/export/config-ipodcolor.h | 1 | ||||
-rw-r--r-- | firmware/export/config-ipodmini.h | 1 | ||||
-rw-r--r-- | firmware/export/config-ipodmini2g.h | 1 | ||||
-rw-r--r-- | firmware/export/config-ipodnano.h | 1 | ||||
-rw-r--r-- | firmware/export/config-ipodvideo.h | 1 | ||||
-rw-r--r-- | firmware/export/config-recorderv2.h | 2 | ||||
-rw-r--r-- | firmware/export/rtc.h | 4 | ||||
-rw-r--r-- | firmware/powermgmt.c | 4 |
20 files changed, 124 insertions, 29 deletions
diff --git a/apps/alarm_menu.c b/apps/alarm_menu.c index d7377c20d6..47c28c43f4 100644 --- a/apps/alarm_menu.c +++ b/apps/alarm_menu.c @@ -18,7 +18,7 @@ ****************************************************************************/ #include "config.h" -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM #include <stdbool.h> @@ -165,4 +165,4 @@ bool alarm_screen(void) return false; } -#endif /* HAVE_ALARM_MOD */ +#endif /* HAVE_RTC_ALARM */ diff --git a/apps/lang/english.lang b/apps/lang/english.lang index c081e53ea7..08f06ba56b 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -5356,9 +5356,11 @@ user: <source> *: "PLAY=Set OFF=Cancel" + ipod*: "SELECT=Set MENU=Cancel" </source> <dest> *: "PLAY=Set OFF=Cancel" + ipod*: "SELECT=Set MENU=Cancel" </dest> <voice> *: "" diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 818271b623..92c169e43a 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -35,7 +35,7 @@ #include "talk.h" #include "sprintf.h" #include "powermgmt.h" -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM #include "alarm_menu.h" #endif #ifdef CONFIG_RTC @@ -250,7 +250,7 @@ static int sleep_timer(void) MENUITEM_FUNCTION(sleep_timer_call, ID2P(LANG_SLEEP_TIMER), sleep_timer, NULL, bitmap_icons_6x8[Icon_Menu_setting]); /* make it look like a setting to the user */ -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM MENUITEM_FUNCTION(alarm_screen_call, ID2P(LANG_ALARM_MOD_ALARM_MENU), (menu_function)alarm_screen, rtc_detect_callback, NOICON); #endif @@ -295,7 +295,7 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), #endif &poweroff, &sleep_timer_call, -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM &alarm_screen_call, #endif &limits_menu, diff --git a/apps/tree.c b/apps/tree.c index a8eaea6aa6..78fb1db76d 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -486,7 +486,7 @@ static void start_resume(bool just_powered_on) global_status.resume_index, global_status.resume_offset); -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM if ( rtc_check_alarm_started(true) ) { rtc_enable_alarm(false); do_resume = true; diff --git a/firmware/drivers/pcf50605.c b/firmware/drivers/pcf50605.c index 0610f41aec..cf4ea9fecb 100644 --- a/firmware/drivers/pcf50605.c +++ b/firmware/drivers/pcf50605.c @@ -89,10 +89,9 @@ int pcf50605_write(int address, unsigned char val) int pcf50605_write_multiple(int address, const unsigned char* buf, int count) { - /* TODO */ - (void)address; - (void)buf; - (void)count; + int i; + for (i = 0; i < count; i++) + pp_i2c_send(0x8, address + i, buf[i]); return 0; } @@ -102,7 +101,8 @@ int pcf50605_write_multiple(int address, const unsigned char* buf, int count) power on your iPod again. */ void pcf50605_standby_mode(void) { - pcf50605_write(OOCC1, GOSTDBY | CHGWAK | EXTONWAK); + const char mask = pcf50605_read(OOCC1) | GOSTDBY | CHGWAK | EXTONWAK; + pcf50605_write(OOCC1, mask); } void pcf50605_init(void) diff --git a/firmware/drivers/rtc/rtc_ds1339_ds3231.c b/firmware/drivers/rtc/rtc_ds1339_ds3231.c index df67fed735..7396c2e0a1 100644 --- a/firmware/drivers/rtc/rtc_ds1339_ds3231.c +++ b/firmware/drivers/rtc/rtc_ds1339_ds3231.c @@ -33,14 +33,14 @@ void rtc_init(void) /* read one byte from RTC; 0 on success */ rtc_detected = !sw_i2c_read(RTC_ADDR, 0, &byte, 1); -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM /* Check + save alarm bit first, before the power thread starts watching */ rtc_check_alarm_started(false); #endif } -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM /* check whether the unit has been started by the RTC alarm function */ /* (check for A2F, which => started using wakeup alarm) */ @@ -117,7 +117,7 @@ bool rtc_enable_alarm(bool enable) return false; /* all ok */ } -#endif /* HAVE_ALARM_MOD */ +#endif /* HAVE_RTC_ALARM */ int rtc_read_datetime(unsigned char* buf) { diff --git a/firmware/drivers/rtc/rtc_m41st84w.c b/firmware/drivers/rtc/rtc_m41st84w.c index 1d76867e13..4e861692d8 100644 --- a/firmware/drivers/rtc/rtc_m41st84w.c +++ b/firmware/drivers/rtc/rtc_m41st84w.c @@ -31,7 +31,7 @@ void rtc_init(void) { unsigned char data; -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM /* Check + save alarm bit first, before the power thread starts watching */ rtc_check_alarm_started(false); #endif @@ -52,7 +52,7 @@ void rtc_init(void) rtc_write(0x0c,data); } -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM /* Clear Trec bit, write-protecting the RTC for 200ms when shutting off */ /* without this, the alarm won't work! */ @@ -71,7 +71,7 @@ void rtc_init(void) #endif } -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM /* check whether the unit has been started by the RTC alarm function */ /* (check for AF, which => started using wakeup alarm) */ @@ -168,7 +168,7 @@ bool rtc_enable_alarm(bool enable) return false; /* all ok */ } -#endif /* HAVE_ALARM_MOD */ +#endif /* HAVE_RTC_ALARM */ int rtc_write(unsigned char address, unsigned char value) { diff --git a/firmware/drivers/rtc/rtc_pcf50605.c b/firmware/drivers/rtc/rtc_pcf50605.c index 1bc40146ff..fedcdd3cdf 100644 --- a/firmware/drivers/rtc/rtc_pcf50605.c +++ b/firmware/drivers/rtc/rtc_pcf50605.c @@ -24,8 +24,12 @@ #include "pcf50605.h" #include <stdbool.h> +/* Values which each disable one alarm time register */ +static char alarm_disable[] = { 0x7f, 0x7f, 0x3f, 0x07, 0x3f, 0x1f, 0xff }; + void rtc_init(void) { + rtc_check_alarm_started(false); } int rtc_read_datetime(unsigned char* buf) @@ -35,11 +39,93 @@ int rtc_read_datetime(unsigned char* buf) int rtc_write_datetime(unsigned char* buf) { - int i; + pcf50605_write_multiple(0x0a, buf, 7); + return 1; +} + +/** + * Checks the PCF interrupt 1 register bit 7 to see if an alarm interrupt has + * triggered since last we checked. + */ +bool rtc_check_alarm_flag(void) +{ + return pcf50605_read(0x02) & 0x80; +} - for (i=0;i<7;i++) { - pcf50605_write(0x0a+i, buf[i]); +/** + * Enables or disables the alarm. + * The Ipod bootloader clears all PCF interrupt registers and always enables + * the "wake on RTC" bit on OOCC1, so we have to rely on other means to find + * out if we just woke from an alarm. + * Return value is always false for us. + */ +bool rtc_enable_alarm(bool enable) +{ + if (enable) { + /* Tell the PCF to ignore everything but second, minute and hour, so + * that an alarm will trigger the next time the alarm time occurs. + */ + pcf50605_write_multiple(0x14, alarm_disable + 3, 4); + /* Unmask the alarm interrupt (might be unneeded) */ + pcf50605_write(0x5, pcf50605_read(0x5) & ~0x80); + /* Make sure wake on RTC is set */ + pcf50605_write(0x8, pcf50605_read(0x8) | 0x10); + } else { + /* We use this year to indicate a disabled alarm. If you happen to live + * around this time and are annoyed by this, feel free to seek out my + * grave and do something nasty to it. + */ + pcf50605_write(0x17, 0x99); } + return false; +} - return 1; +/** + * Check if alarm caused unit to start. + */ +bool rtc_check_alarm_started(bool release_alarm) +{ + static bool run_before = false, alarm_state; + bool rc; + + if (run_before) { + rc = alarm_state; + alarm_state &= ~release_alarm; + } else { + char rt[3], at[3]; + /* The Ipod bootloader seems to read (and thus clear) the PCF interrupt + * registers, so we need to find some other way to detect if an alarm + * just happened + */ + pcf50605_read_multiple(0x0a, rt, 3); + pcf50605_read_multiple(0x11, at, 3); + + /* If alarm time and real time match within 10 seconds of each other, we + * assume an alarm just triggered + */ + rc = alarm_state = rt[1] == at[1] && rt[2] == at[2] + && (rt[0] - at[0]) <= 10; + run_before = true; + } + return rc; +} + +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); } + +void rtc_get_alarm(int *h, int *m) +{ + char buf[2]; + + pcf50605_read_multiple(0x12, buf, 2); + /* Convert from BCD */ + *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f); + *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f); +} + diff --git a/firmware/export/config-fmrecorder.h b/firmware/export/config-fmrecorder.h index da2f7fbb87..1b7bd190d6 100644 --- a/firmware/export/config-fmrecorder.h +++ b/firmware/export/config-fmrecorder.h @@ -97,7 +97,7 @@ #define FIRMWARE_OFFSET_FILE_DATA 24 /* FM recorders can wake up from RTC alarm */ -#define HAVE_ALARM_MOD +#define HAVE_RTC_ALARM /* How to detect USB */ #define USB_FMRECORDERSTYLE 1 diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h index 9dccf22d0e..e899cd4c5a 100644 --- a/firmware/export/config-h120.h +++ b/firmware/export/config-h120.h @@ -48,7 +48,7 @@ #ifndef SIMULATOR /* RTC is autodetected on target only */ #define CONFIG_RTC RTC_DS1339_DS3231 -#define HAVE_ALARM_MOD +#define HAVE_RTC_ALARM #endif /* Define this if you have an remote lcd */ diff --git a/firmware/export/config-ipod3g.h b/firmware/export/config-ipod3g.h index d97b5ac886..4c9b61267f 100644 --- a/firmware/export/config-ipod3g.h +++ b/firmware/export/config-ipod3g.h @@ -48,6 +48,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-ipod4g.h b/firmware/export/config-ipod4g.h index 504de0f471..3790500063 100644 --- a/firmware/export/config-ipod4g.h +++ b/firmware/export/config-ipod4g.h @@ -54,6 +54,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h index 97b4301ce6..efe49fb6a7 100644 --- a/firmware/export/config-ipodcolor.h +++ b/firmware/export/config-ipodcolor.h @@ -45,6 +45,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-ipodmini.h b/firmware/export/config-ipodmini.h index df5da35f4c..4a6c6a5dcf 100644 --- a/firmware/export/config-ipodmini.h +++ b/firmware/export/config-ipodmini.h @@ -48,6 +48,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-ipodmini2g.h b/firmware/export/config-ipodmini2g.h index aa5bef2df0..a8033b1574 100644 --- a/firmware/export/config-ipodmini2g.h +++ b/firmware/export/config-ipodmini2g.h @@ -48,6 +48,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h index 52bdbe2890..2e727e463b 100644 --- a/firmware/export/config-ipodnano.h +++ b/firmware/export/config-ipodnano.h @@ -45,6 +45,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h index 6f68f1e756..765c33b2a4 100644 --- a/firmware/export/config-ipodvideo.h +++ b/firmware/export/config-ipodvideo.h @@ -45,6 +45,7 @@ /* define this if you have a real-time clock */ #ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#define HAVE_RTC_ALARM #endif /* Define this if you have a software controlled poweroff */ diff --git a/firmware/export/config-recorderv2.h b/firmware/export/config-recorderv2.h index f035f2dab0..0568879066 100644 --- a/firmware/export/config-recorderv2.h +++ b/firmware/export/config-recorderv2.h @@ -94,7 +94,7 @@ #define FIRMWARE_OFFSET_FILE_DATA 24 /* FM recorders can wake up from RTC alarm */ -#define HAVE_ALARM_MOD +#define HAVE_RTC_ALARM /* Define this if you have an FM Radio */ #define CONFIG_TUNER S1A0903X01 diff --git a/firmware/export/rtc.h b/firmware/export/rtc.h index 2f13cbb578..1b0d215371 100644 --- a/firmware/export/rtc.h +++ b/firmware/export/rtc.h @@ -47,13 +47,13 @@ int rtc_write(unsigned char address, unsigned char value); #endif /* RTC_M41ST84W */ -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM void rtc_set_alarm(int h, int m); void rtc_get_alarm(int *h, int *m); bool rtc_enable_alarm(bool enable); bool rtc_check_alarm_started(bool release_alarm); bool rtc_check_alarm_flag(void); -#endif /* HAVE_ALARM_MOD */ +#endif /* HAVE_RTC_ALARM */ #endif /* CONFIG_RTC */ diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 1a1d576e67..c2f9ca0bca 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -727,7 +727,7 @@ static int runcurrent(void) /* Check to see whether or not we've received an alarm in the last second */ -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM static void power_thread_rtc_process(void) { if (rtc_check_alarm_flag()) { @@ -823,7 +823,7 @@ static void power_thread_sleep(int ticks) power_off(); } -#ifdef HAVE_ALARM_MOD +#ifdef HAVE_RTC_ALARM power_thread_rtc_process(); #endif |