summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/timefuncs.c13
-rw-r--r--firmware/drivers/fat.c20
-rw-r--r--firmware/drivers/rtc/rtc_ds1339_ds3231.c12
-rw-r--r--firmware/export/config-h120.h11
-rw-r--r--firmware/export/rtc.h7
5 files changed, 9 insertions, 54 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index 881bc23e53..e48aadd0a2 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -49,19 +49,6 @@ struct tm *get_time(void)
49#ifdef CONFIG_RTC 49#ifdef CONFIG_RTC
50 static long timeout = 0; 50 static long timeout = 0;
51 51
52#if CONFIG_RTC == RTC_DS1339_DS3231
53 if(!rtc_detected) {
54 tm.tm_sec = 0;
55 tm.tm_min = 0;
56 tm.tm_hour = 0;
57 tm.tm_mday = 1;
58 tm.tm_mon = 0;
59 tm.tm_year = 70;
60 tm.tm_wday = 1;
61 tm.tm_yday = 0; /* Not implemented for now */
62 tm.tm_isdst = -1; /* Not implemented for now */
63 } else
64#endif
65 /* Don't read the RTC more than once per second */ 52 /* Don't read the RTC more than once per second */
66 if (current_tick > timeout) { 53 if (current_tick > timeout) {
67 char rtcbuf[7]; 54 char rtcbuf[7];
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index e4e77627d0..e3e1a755cb 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -31,9 +31,6 @@
31#include "rbunicode.h" 31#include "rbunicode.h"
32#include "logf.h" 32#include "logf.h"
33#include "atoi.h" 33#include "atoi.h"
34#ifdef CONFIG_RTC
35#include "rtc.h"
36#endif
37 34
38#define BYTES2INT16(array,pos) \ 35#define BYTES2INT16(array,pos) \
39 (array[pos] | (array[pos+1] << 8 )) 36 (array[pos] | (array[pos+1] << 8 ))
@@ -948,10 +945,6 @@ static void fat_time(unsigned short* date,
948{ 945{
949#ifdef CONFIG_RTC 946#ifdef CONFIG_RTC
950 struct tm* tm = get_time(); 947 struct tm* tm = get_time();
951#if CONFIG_RTC == RTC_DS1339_DS3231
952 if(rtc_detected)
953 {
954#endif /* CONFIG_RTC == RTC_DS1339_DS3231 */
955 948
956 if (date) 949 if (date)
957 *date = ((tm->tm_year - 80) << 9) | 950 *date = ((tm->tm_year - 80) << 9) |
@@ -965,14 +958,7 @@ static void fat_time(unsigned short* date,
965 958
966 if (tenth) 959 if (tenth)
967 *tenth = (tm->tm_sec & 1) * 100; 960 *tenth = (tm->tm_sec & 1) * 100;
968 961#else
969#if CONFIG_RTC == RTC_DS1339_DS3231
970 }
971 else
972#endif /* CONFIG_RTC == RTC_DS1339_DS3231 */
973#endif /* CONFIG_RTC */
974#if !defined(CONFIG_RTC) || CONFIG_RTC == RTC_DS1339_DS3231
975 {
976 /* non-RTC version returns an increment from the supplied time, or a 962 /* non-RTC version returns an increment from the supplied time, or a
977 * fixed standard time/date if no time given as input */ 963 * fixed standard time/date if no time given as input */
978 bool next_day = false; 964 bool next_day = false;
@@ -1039,9 +1025,9 @@ static void fat_time(unsigned short* date,
1039 } 1025 }
1040 if (tenth) 1026 if (tenth)
1041 *tenth = 0; 1027 *tenth = 0;
1042 } 1028#endif /* CONFIG_RTC */
1043#endif /* !defined(CONFIG_RTC) || CONFIG_RTC == RTC_DS1339_DS3231 */
1044} 1029}
1030
1045static int write_long_name(struct fat_file* file, 1031static int write_long_name(struct fat_file* file,
1046 unsigned int firstentry, 1032 unsigned int firstentry,
1047 unsigned int numentries, 1033 unsigned int numentries,
diff --git a/firmware/drivers/rtc/rtc_ds1339_ds3231.c b/firmware/drivers/rtc/rtc_ds1339_ds3231.c
index 7396c2e0a1..e343c96169 100644
--- a/firmware/drivers/rtc/rtc_ds1339_ds3231.c
+++ b/firmware/drivers/rtc/rtc_ds1339_ds3231.c
@@ -22,17 +22,10 @@
22 22
23#define RTC_ADDR 0xD0 23#define RTC_ADDR 0xD0
24 24
25bool rtc_detected = false;
26
27void rtc_init(void) 25void rtc_init(void)
28{ 26{
29 char byte;
30
31 sw_i2c_init(); 27 sw_i2c_init();
32 28
33 /* read one byte from RTC; 0 on success */
34 rtc_detected = !sw_i2c_read(RTC_ADDR, 0, &byte, 1);
35
36#ifdef HAVE_RTC_ALARM 29#ifdef HAVE_RTC_ALARM
37 /* Check + save alarm bit first, before the power thread starts watching */ 30 /* Check + save alarm bit first, before the power thread starts watching */
38 rtc_check_alarm_started(false); 31 rtc_check_alarm_started(false);
@@ -72,7 +65,8 @@ bool rtc_check_alarm_flag(void)
72 sw_i2c_read(RTC_ADDR, 0x0f, buf, 1); 65 sw_i2c_read(RTC_ADDR, 0x0f, buf, 1);
73 if (buf[0] & 0x02) flag = true; 66 if (buf[0] & 0x02) flag = true;
74 67
75 rtc_enable_alarm(false); 68 buf[0] = 0x00;
69 sw_i2c_write(RTC_ADDR, 0x0f, buf, 1);
76 70
77 return flag; 71 return flag;
78} 72}
@@ -109,7 +103,7 @@ bool rtc_enable_alarm(bool enable)
109{ 103{
110 unsigned char buf[2]; 104 unsigned char buf[2];
111 105
112 buf[0] = enable ? 0x26 : 0x04; /* BBSQI INTCN A2IE vs INTCH only */ 106 buf[0] = enable ? 0x26 : 0x24; /* BBSQI INTCN A2IE vs INTCH only */
113 buf[1] = 0x00; /* reset alarm flags (and OSF for good measure) */ 107 buf[1] = 0x00; /* reset alarm flags (and OSF for good measure) */
114 108
115 sw_i2c_write(RTC_ADDR, 0x0e, buf, 2); 109 sw_i2c_write(RTC_ADDR, 0x0e, buf, 2);
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index 1791bdf78b..e7fb73ea0f 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -45,16 +45,7 @@
45/* Define this if you do software codec */ 45/* Define this if you do software codec */
46#define CONFIG_CODEC SWCODEC 46#define CONFIG_CODEC SWCODEC
47 47
48/* Set to 1 if you want to build with RTC support */ 48/* Define this if you have an remote lcd */
49#if 0
50#ifndef SIMULATOR
51/* RTC is autodetected on target only */
52#define CONFIG_RTC RTC_DS1339_DS3231
53#define HAVE_RTC_ALARM
54#endif
55#endif
56
57 /* Define this if you have an remote lcd */
58#define HAVE_REMOTE_LCD 49#define HAVE_REMOTE_LCD
59 50
60#define CONFIG_LCD LCD_S1D15E06 51#define CONFIG_LCD LCD_S1D15E06
diff --git a/firmware/export/rtc.h b/firmware/export/rtc.h
index 1b0d215371..eea83d85bb 100644
--- a/firmware/export/rtc.h
+++ b/firmware/export/rtc.h
@@ -20,7 +20,8 @@
20#define _RTC_H_ 20#define _RTC_H_
21 21
22#include <stdbool.h> 22#include <stdbool.h>
23#include <system.h> 23#include "system.h"
24#include "config.h"
24 25
25#ifdef CONFIG_RTC 26#ifdef CONFIG_RTC
26 27
@@ -28,10 +29,6 @@ extern const int dayname[];
28 29
29extern const int monthname[]; 30extern const int monthname[];
30 31
31#if CONFIG_RTC == RTC_DS1339_DS3231
32extern bool rtc_detected;
33#endif
34
35/* Common functions for all targets */ 32/* Common functions for all targets */
36void rtc_init(void); 33void rtc_init(void);
37int rtc_read_datetime(unsigned char* buf); 34int rtc_read_datetime(unsigned char* buf);