summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/keymaps/keymap-x5.c3
-rw-r--r--firmware/drivers/rtc/rtc_pcf50606.c107
-rw-r--r--firmware/export/config/iaudiom5.h3
-rw-r--r--firmware/export/config/iaudiox5.h3
-rw-r--r--firmware/export/config/iriverh300.h3
-rw-r--r--manual/platform/iriverh300.tex7
-rw-r--r--manual/platform/keymap-iaudiomx5.tex6
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[] = {
{ ACTION_SETTINGS_DEC, BUTTON_RC_VOL_DOWN, BUTTON_NONE },
{ ACTION_SETTINGS_DECREPEAT, BUTTON_RC_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_PREV, BUTTON_RC_REW, 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_CANCEL, BUTTON_RC_REC, BUTTON_NONE },
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 @@
#include "pcf50606.h"
#include "timefuncs.h"
+/* Values which each disable one alarm time register */
+static const char alarm_disable[] = {
+ 0x7f, 0x7f, 0x3f, 0x07, 0x3f, 0x1f, 0xff
+};
+
void rtc_init(void)
{
+ rtc_check_alarm_started(false);
}
int rtc_read_datetime(struct tm *tm)
@@ -97,3 +103,104 @@ int rtc_write_datetime(const struct tm *tm)
return rc;
}
+/**
+ * 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)
+{
+ int oldlevel = disable_irq_save();
+ int rc = pcf50606_read(0x02) & 0x80;
+ restore_irq(oldlevel);
+ return rc;
+}
+
+/**
+ * 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.
+ */
+void rtc_enable_alarm(bool enable)
+{
+ int oldlevel = disable_irq_save();
+ 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.
+ */
+ pcf50606_write_multiple(0x14, alarm_disable + 3, 4);
+ /* Unmask the alarm interrupt (might be unneeded) */
+ pcf50606_write(0x5, pcf50606_read(0x5) & ~0x80);
+ /* Make sure wake on RTC is set when shutting down */
+ pcf50606_write(0x8, pcf50606_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.
+ */
+ pcf50606_write(0x17, 0x99);
+ /* Make sure we don't wake on RTC after shutting down */
+ pcf50606_write(0x8, pcf50606_read(0x8) & ~0x10);
+ }
+ restore_irq(oldlevel);
+ return;
+}
+
+/**
+ * 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
+ */
+ int oldlevel = disable_irq_save();
+ pcf50606_read_multiple(0x0a, rt, 3);
+ pcf50606_read_multiple(0x11, at, 3);
+ restore_irq(oldlevel);
+
+ /* 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;
+}
+
+
+/* set alarm time registers to the given time (repeat once per day) */
+void rtc_set_alarm(int h, int m)
+{
+ int oldlevel = disable_irq_save();
+ /* Set us to wake at the first second of the specified time */
+ pcf50606_write(0x11, 0);
+ /* Convert to BCD */
+ pcf50606_write(0x12, ((m/10) << 4) | m%10);
+ pcf50606_write(0x13, ((h/10) << 4) | h%10);
+ restore_irq(oldlevel);
+}
+
+/* read out the current alarm time */
+void rtc_get_alarm(int *h, int *m)
+{
+ char buf[2];
+
+ int oldlevel = disable_irq_save();
+ pcf50606_read_multiple(0x12, buf, 2);
+ restore_irq(oldlevel);
+ /* 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/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 @@
/* define this if you have a real-time clock */
#define CONFIG_RTC RTC_PCF50606
+/* define this if you have a real-time clock alarm */
+#define HAVE_RTC_ALARM
+
/* Define this if you have an remote lcd */
#define HAVE_REMOTE_LCD
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 @@
/* define this if you have a real-time clock */
#define CONFIG_RTC RTC_PCF50606
+/* define this if you have a real-time clock alarm */
+#define HAVE_RTC_ALARM
+
/* Define this if you have an remote lcd */
#define HAVE_REMOTE_LCD
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 @@
that needs spinups and can cause skips when shaked */
#define HAVE_DISK_STORAGE
+/* Define if the device can wake from an RTC alarm */
+#define HAVE_RTC_ALARM
+
/* Define this if you have an remote lcd */
#define HAVE_REMOTE_LCD
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 @@
% link external keymap file
\input{platform/keymap-iriverh100_h300.tex}
+% Unique to h300
+%
+%Button actions, Alarm screen
+\newcommand{\ActionAlarmSet}{\ButtonSelect{} or \ButtonPlay}
+\newcommand{\ActionAlarmCancel}{\ButtonPower{} or \ButtonRec}
+\newcommand{\ActionAlarmHoursInc}{\ButtonRight}
+\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 @@
\newcommand{\ActionSettingInc}{\ButtonUp}
\newcommand{\ActionSettingDec}{\ButtonDown}
+%Button actions, Alarm screen
+\newcommand{\ActionAlarmSet}{\ButtonSelect{} or \ButtonPlay}
+\newcommand{\ActionAlarmCancel}{\ButtonPower{} or \ButtonRec}
+\newcommand{\ActionAlarmHoursInc}{\ButtonRight}
+\newcommand{\ActionAlarmHoursDec}{\ButtonLeft}
+
%Button actions, Virtual Keyboard Context
\newcommand{\ActionKbdLeft}{\ButtonLeft}
\newcommand{\ActionKbdRight}{\ButtonRight}