summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/tree.c6
-rw-r--r--firmware/drivers/rtc.c29
-rw-r--r--firmware/export/rtc.h1
3 files changed, 33 insertions, 3 deletions
diff --git a/apps/tree.c b/apps/tree.c
index d59101f937..02899f87ca 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -60,6 +60,7 @@
60#include "filetree.h" 60#include "filetree.h"
61#include "dbtree.h" 61#include "dbtree.h"
62#include "recorder/recording.h" 62#include "recorder/recording.h"
63#include "rtc.h"
63 64
64#ifdef HAVE_LCD_BITMAP 65#ifdef HAVE_LCD_BITMAP
65#include "widgets.h" 66#include "widgets.h"
@@ -434,8 +435,11 @@ static bool ask_resume(bool ask_once)
434 return false; 435 return false;
435 } 436 }
436 437
438 if ( rtc_check_alarm_started(true) )
439 return true;
440
437 /* always resume? */ 441 /* always resume? */
438 if ( global_settings.resume == RESUME_ON ) 442 if ( global_settings.resume == RESUME_ON)
439 return true; 443 return true;
440 444
441 lcd_clear_display(); 445 lcd_clear_display();
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c
index d5b6c2fda6..5f60c23bdd 100644
--- a/firmware/drivers/rtc.c
+++ b/firmware/drivers/rtc.c
@@ -28,7 +28,13 @@
28 28
29void rtc_init(void) 29void rtc_init(void)
30{ 30{
31 unsigned char data; 31 unsigned char data;
32
33#ifdef HAVE_ALARM_MOD
34 /* Check + save alarm bit first, since something in rtc_init resets AF */
35 rtc_check_alarm_started(false);
36#endif
37
32 rtc_write(0x13, 0x10); /* 32 kHz square wave */ 38 rtc_write(0x13, 0x10); /* 32 kHz square wave */
33 39
34 /* Clear the Stop bit if it is set */ 40 /* Clear the Stop bit if it is set */
@@ -67,6 +73,25 @@ void rtc_init(void)
67 73
68#ifdef HAVE_ALARM_MOD 74#ifdef HAVE_ALARM_MOD
69 75
76/* check whether the unit has been started by the RTC alarm function */
77/* (check for AF, which => started using wakeup alarm) */
78bool rtc_check_alarm_started(bool release_alarm)
79{
80 static bool alarm_state, run_before;
81 bool rc;
82
83 if (run_before) {
84 rc = alarm_state;
85 alarm_state &= ~release_alarm;
86 } else {
87 /* This call resets AF, so we store the state for later recall */
88 rc = alarm_state = ((rtc_read(0x0f) & 0x40) != 0);
89 run_before = true;
90 }
91
92 return rc;
93}
94
70/* set alarm time registers to the given time (repeat once per day) */ 95/* set alarm time registers to the given time (repeat once per day) */
71void rtc_set_alarm(int h, int m) 96void rtc_set_alarm(int h, int m)
72{ 97{
@@ -114,7 +139,7 @@ bool rtc_enable_alarm(bool enable)
114 data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */ 139 data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */
115 rtc_write(0x0a, data); 140 rtc_write(0x0a, data);
116 141
117 /* check if alarm flag AF is off (as it sould be) */ 142 /* check if alarm flag AF is off (as it should be) */
118 if ((rtc_read(0x0f) & 0x40) != 0) /* on */ 143 if ((rtc_read(0x0f) & 0x40) != 0) /* on */
119 { 144 {
120 data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */ 145 data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */
diff --git a/firmware/export/rtc.h b/firmware/export/rtc.h
index fd1cd50274..7c2bd94d9c 100644
--- a/firmware/export/rtc.h
+++ b/firmware/export/rtc.h
@@ -31,6 +31,7 @@ int rtc_write(unsigned char address, unsigned char value);
31void rtc_set_alarm(int h, int m); 31void rtc_set_alarm(int h, int m);
32void rtc_get_alarm(int *h, int *m); 32void rtc_get_alarm(int *h, int *m);
33bool rtc_enable_alarm(bool enable); 33bool rtc_enable_alarm(bool enable);
34bool rtc_check_alarm_started(bool release_alarm);
34#endif /* HAVE_ALARM_MOD */ 35#endif /* HAVE_ALARM_MOD */
35 36
36#endif /* HAVE_RTC */ 37#endif /* HAVE_RTC */