MAXIM DS3231 accurate Real Time Clock Library

Fork of DS3231 by remi cormier

Committer:
JackB
Date:
Mon Jul 23 12:25:27 2018 +0000
Revision:
3:1af2ff7cfe26
RTC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JackB 3:1af2ff7cfe26 1 /** mbded library for driving the PMAXIM ARM_RTC Real Time Clock
JackB 3:1af2ff7cfe26 2 * datasheet link : http://datasheets.maximintegrated.com/en/ds/ARM_RTC.pdf
JackB 3:1af2ff7cfe26 3 * breakout : MACETECH ChronoDot V2.1 High Precision RTC
JackB 3:1af2ff7cfe26 4 * remi cormier 2012
JackB 3:1af2ff7cfe26 5 * WARNING : sda and sdl should be pulled up with 2.2k resistor
JackB 3:1af2ff7cfe26 6 */
JackB 3:1af2ff7cfe26 7
JackB 3:1af2ff7cfe26 8 /** Example code
JackB 3:1af2ff7cfe26 9 * @code
JackB 3:1af2ff7cfe26 10 // ARM_RTC Library test program
JackB 3:1af2ff7cfe26 11 // remi cormier 2012
JackB 3:1af2ff7cfe26 12
JackB 3:1af2ff7cfe26 13 #include "mbed.h"
JackB 3:1af2ff7cfe26 14 #include "ARM_RTC.h"
JackB 3:1af2ff7cfe26 15
JackB 3:1af2ff7cfe26 16 Serial pc(USBTX, USBRX);
JackB 3:1af2ff7cfe26 17
JackB 3:1af2ff7cfe26 18 int hour;
JackB 3:1af2ff7cfe26 19 int minute;
JackB 3:1af2ff7cfe26 20 int second;
JackB 3:1af2ff7cfe26 21
JackB 3:1af2ff7cfe26 22 int dayOfWeek;
JackB 3:1af2ff7cfe26 23 int date;
JackB 3:1af2ff7cfe26 24 int month;
JackB 3:1af2ff7cfe26 25 int year;
JackB 3:1af2ff7cfe26 26
JackB 3:1af2ff7cfe26 27 ARM_RTC RTC(p28,p27);
JackB 3:1af2ff7cfe26 28
JackB 3:1af2ff7cfe26 29
JackB 3:1af2ff7cfe26 30 int main()
JackB 3:1af2ff7cfe26 31 {printf("\r\n\nARM_RTC Library test program\r\nremi cormier 2012\r\n\n");
JackB 3:1af2ff7cfe26 32
JackB 3:1af2ff7cfe26 33 RTC.setI2Cfrequency(400000);
JackB 3:1af2ff7cfe26 34
JackB 3:1af2ff7cfe26 35 //RTC.writeRegister(ARM_RTC_Aging_Offset,0); // uncomment to set Aging Offset 1LSB = approx. 0.1 ppm according from datasheet = 0.05 ppm @ 21 °C from my measurments
JackB 3:1af2ff7cfe26 36
JackB 3:1af2ff7cfe26 37 RTC.convertTemperature();
JackB 3:1af2ff7cfe26 38
JackB 3:1af2ff7cfe26 39 int reg=RTC.readRegister(ARM_RTC_Aging_Offset);
JackB 3:1af2ff7cfe26 40 if (reg>127)
JackB 3:1af2ff7cfe26 41 {reg=reg-256;}
JackB 3:1af2ff7cfe26 42 pc.printf("Aging offset : %i\r\n",reg);
JackB 3:1af2ff7cfe26 43
JackB 3:1af2ff7cfe26 44 pc.printf("OSF flag : %i",RTC.OSF());
JackB 3:1af2ff7cfe26 45 pc.printf("\r\n");
JackB 3:1af2ff7cfe26 46
JackB 3:1af2ff7cfe26 47 RTC.readDate(&date,&month,&year);
JackB 3:1af2ff7cfe26 48 pc.printf("date : %02i-%02i-%02i",date,month,year);
JackB 3:1af2ff7cfe26 49 pc.printf("\r\n");
JackB 3:1af2ff7cfe26 50
JackB 3:1af2ff7cfe26 51 //RTC.setTime(19,48,45); // uncomment to set time
JackB 3:1af2ff7cfe26 52
JackB 3:1af2ff7cfe26 53 RTC.readTime(&hour,&minute,&second);
JackB 3:1af2ff7cfe26 54 pc.printf("time : %02i:%02i:%02i",hour,minute,second);
JackB 3:1af2ff7cfe26 55 pc.printf("\r\n");
JackB 3:1af2ff7cfe26 56
JackB 3:1af2ff7cfe26 57 //RTC.setDate(6,22,12,2012); // uncomment to set date
JackB 3:1af2ff7cfe26 58
JackB 3:1af2ff7cfe26 59 RTC.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second);
JackB 3:1af2ff7cfe26 60 pc.printf("date time : %i / %02i-%02i-%02i %02i:%02i:%02i",dayOfWeek,date,month,year,hour,minute,second);
JackB 3:1af2ff7cfe26 61 pc.printf("\r\n");
JackB 3:1af2ff7cfe26 62
JackB 3:1af2ff7cfe26 63 pc.printf("temperature :%6.2f",RTC.readTemp());
JackB 3:1af2ff7cfe26 64 pc.printf("\r\n");
JackB 3:1af2ff7cfe26 65 }
JackB 3:1af2ff7cfe26 66 * @endcode
JackB 3:1af2ff7cfe26 67 */
JackB 3:1af2ff7cfe26 68
JackB 3:1af2ff7cfe26 69 /*
JackB 3:1af2ff7cfe26 70 http://www.cplusplus.com/reference/ctime/strftime/
JackB 3:1af2ff7cfe26 71 %a Abbreviated weekday name * Thu
JackB 3:1af2ff7cfe26 72 %A Full weekday name * Thursday
JackB 3:1af2ff7cfe26 73 %b Abbreviated month name * Aug
JackB 3:1af2ff7cfe26 74 %B Full month name * August
JackB 3:1af2ff7cfe26 75 %d Day of the month, zero-padded (01-31) 23
JackB 3:1af2ff7cfe26 76 %e Day of the month, space-padded ( 1-31) 23
JackB 3:1af2ff7cfe26 77 %F Short YYYY-MM-DD date, equivalent to %Y-%m-%d 2001-08-23
JackB 3:1af2ff7cfe26 78 %H Hour in 24h format (00-23) 14
JackB 3:1af2ff7cfe26 79 %j Day of the year (001-366) 235
JackB 3:1af2ff7cfe26 80 %m Month as a decimal number (01-12) 08
JackB 3:1af2ff7cfe26 81 %M Minute (00-59) 55
JackB 3:1af2ff7cfe26 82 %R 24-hour HH:MM time, equivalent to %H:%M 14:55
JackB 3:1af2ff7cfe26 83 %S Second (00-61) 02
JackB 3:1af2ff7cfe26 84 %T ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S 14:55:02
JackB 3:1af2ff7cfe26 85 %u ISO 8601 weekday as number with Monday as 1 (1-7) 4
JackB 3:1af2ff7cfe26 86 %V ISO 8601 week number (00-53) 34
JackB 3:1af2ff7cfe26 87 %w Weekday as a decimal number with Sunday as 0 (0-6) 4
JackB 3:1af2ff7cfe26 88 %W Week number with the first Monday as the first day of week one (00-53) 34
JackB 3:1af2ff7cfe26 89 %X Time representation * 14:55:02
JackB 3:1af2ff7cfe26 90 %y Year, last two digits (00-99) 01
JackB 3:1af2ff7cfe26 91 %Y Year 2001
JackB 3:1af2ff7cfe26 92
JackB 3:1af2ff7cfe26 93 http://www.cplusplus.com/reference/ctime/tm/
JackB 3:1af2ff7cfe26 94 Member Type Meaning Range
JackB 3:1af2ff7cfe26 95 tm_sec int seconds after the minute 0-61*
JackB 3:1af2ff7cfe26 96 tm_min int minutes after the hour 0-59
JackB 3:1af2ff7cfe26 97 tm_hour int hours since midnight 0-23
JackB 3:1af2ff7cfe26 98 tm_mday int day of the month 1-31
JackB 3:1af2ff7cfe26 99 tm_mon int months since January 0-11
JackB 3:1af2ff7cfe26 100 tm_year int years since 1900
JackB 3:1af2ff7cfe26 101 tm_wday int days since Sunday 0-6 (0 = Sunday)
JackB 3:1af2ff7cfe26 102 tm_yday int days since January 1 0-365
JackB 3:1af2ff7cfe26 103 tm_isdst int Daylight Saving Time flag
JackB 3:1af2ff7cfe26 104 The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect,
JackB 3:1af2ff7cfe26 105 zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
JackB 3:1af2ff7cfe26 106 * tm_sec is generally 0-59. The extra range is to accommodate for leap seconds in certain systems.
JackB 3:1af2ff7cfe26 107
JackB 3:1af2ff7cfe26 108 Member Type Meaning Range
JackB 3:1af2ff7cfe26 109 tm_sec int seconds after the minute 0-61*
JackB 3:1af2ff7cfe26 110 tm_min int minutes after the hour 0-59
JackB 3:1af2ff7cfe26 111 tm_hour int hours since midnight 0-23
JackB 3:1af2ff7cfe26 112 tm_mday int day of the month 1-31
JackB 3:1af2ff7cfe26 113 tm_mon int months since January 0-11
JackB 3:1af2ff7cfe26 114 tm_year int years since 1900
JackB 3:1af2ff7cfe26 115 tm_wday int days since Sunday 0-6
JackB 3:1af2ff7cfe26 116 tm_yday int days since January 1 0-365
JackB 3:1af2ff7cfe26 117 tm_isdst int Daylight Saving Time flag
JackB 3:1af2ff7cfe26 118
JackB 3:1af2ff7cfe26 119 http://www.epochconverter.com/programming/c
JackB 3:1af2ff7cfe26 120 Convert from epoch to human readable date
JackB 3:1af2ff7cfe26 121 time_t now;
JackB 3:1af2ff7cfe26 122 struct tm ts;
JackB 3:1af2ff7cfe26 123 char buf[80];
JackB 3:1af2ff7cfe26 124 // Get current time
JackB 3:1af2ff7cfe26 125 time(&now);
JackB 3:1af2ff7cfe26 126 // Format time, "ddd yyyy-mm-dd hh:mm:ss zzz"
JackB 3:1af2ff7cfe26 127 ts = *localtime(&now);
JackB 3:1af2ff7cfe26 128 strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
JackB 3:1af2ff7cfe26 129 printf("%s\n", buf);
JackB 3:1af2ff7cfe26 130
JackB 3:1af2ff7cfe26 131 Convert from human readable date to epoch
JackB 3:1af2ff7cfe26 132 struct tm t;
JackB 3:1af2ff7cfe26 133 time_t t_of_day;
JackB 3:1af2ff7cfe26 134 t.tm_year = 2011-1900;
JackB 3:1af2ff7cfe26 135 t.tm_mon = 7; // Month, 0 - jan
JackB 3:1af2ff7cfe26 136 t.tm_mday = 8; // Day of the month
JackB 3:1af2ff7cfe26 137 t.tm_hour = 16;
JackB 3:1af2ff7cfe26 138 t.tm_min = 11;
JackB 3:1af2ff7cfe26 139 t.tm_sec = 42;
JackB 3:1af2ff7cfe26 140 t.tm_isdst = -1; // Is DST on? 1 = yes, 0 = no, -1 = unknown
JackB 3:1af2ff7cfe26 141 t_of_day = mktime(&t);
JackB 3:1af2ff7cfe26 142 printf("seconds since the Epoch: %ld\n", (long) t_of_day)
JackB 3:1af2ff7cfe26 143
JackB 3:1af2ff7cfe26 144 Convert to struct tm
JackB 3:1af2ff7cfe26 145 time_t rawtime;
JackB 3:1af2ff7cfe26 146 struct tm * t;
JackB 3:1af2ff7cfe26 147 time(&rawtime);
JackB 3:1af2ff7cfe26 148 t = localtime(&rawtime);
JackB 3:1af2ff7cfe26 149 printf("%d\n", t->tm_sec);
JackB 3:1af2ff7cfe26 150
JackB 3:1af2ff7cfe26 151
JackB 3:1af2ff7cfe26 152 https://github.com/raburton/esp8266/blob/master/drivers/ARM_RTC.c
JackB 3:1af2ff7cfe26 153 https://github.com/raburton/esp8266/blob/master/drivers/ARM_RTC.h
JackB 3:1af2ff7cfe26 154
JackB 3:1af2ff7cfe26 155 */
JackB 3:1af2ff7cfe26 156 #include <mbed.h>
JackB 3:1af2ff7cfe26 157 #include "TableSummerTime.h"
JackB 3:1af2ff7cfe26 158 #include "TableDayLight.h"
JackB 3:1af2ff7cfe26 159
JackB 3:1af2ff7cfe26 160 #ifndef MBED_ARM_RTC_H
JackB 3:1af2ff7cfe26 161 #define MBED_ARM_RTC_H
JackB 3:1af2ff7cfe26 162
JackB 3:1af2ff7cfe26 163 //ARM_RTC 8 bit adress
JackB 3:1af2ff7cfe26 164 #define ARM_RTC_ADDR 0x68 // 0x68 << 1 = 0xD0
JackB 3:1af2ff7cfe26 165
JackB 3:1af2ff7cfe26 166 #define ARM_RTC_STAT_OSCILLATOR 0x80
JackB 3:1af2ff7cfe26 167 #define ARM_RTC_STAT_32KHZ 0x08
JackB 3:1af2ff7cfe26 168 #define ARM_RTC_STAT_BUSY 0x04
JackB 3:1af2ff7cfe26 169 #define ARM_RTC_STAT_ALARM_2 0x02
JackB 3:1af2ff7cfe26 170 #define ARM_RTC_STAT_ALARM_1 0x01
JackB 3:1af2ff7cfe26 171
JackB 3:1af2ff7cfe26 172 //ARM_RTC registers
JackB 3:1af2ff7cfe26 173 #define ARM_RTC_Seconds 0x00
JackB 3:1af2ff7cfe26 174 #define ARM_RTC_Minutes 0x01
JackB 3:1af2ff7cfe26 175 #define ARM_RTC_Hours 0x02
JackB 3:1af2ff7cfe26 176 // ARM_RTC Hours bits
JackB 3:1af2ff7cfe26 177 #define ARM_RTC_bit_AM_PM 0x20
JackB 3:1af2ff7cfe26 178 #define ARM_RTC_bit_12_24 0x40
JackB 3:1af2ff7cfe26 179
JackB 3:1af2ff7cfe26 180 #define ARM_RTC_Day 0x03
JackB 3:1af2ff7cfe26 181 #define ARM_RTC_Date 0x04
JackB 3:1af2ff7cfe26 182 #define ARM_RTC_Month_Century 0x05
JackB 3:1af2ff7cfe26 183 #define ARM_RTC_Year 0x06
JackB 3:1af2ff7cfe26 184
JackB 3:1af2ff7cfe26 185 #define ARM_RTC_Alarm1_Seconds 0x07
JackB 3:1af2ff7cfe26 186 #define ARM_RTC_Alarm1_Minutes 0x08
JackB 3:1af2ff7cfe26 187 #define ARM_RTC_Alarm1_Hours 0x09
JackB 3:1af2ff7cfe26 188 #define ARM_RTC_Alarm1_Day_Date 0x0A
JackB 3:1af2ff7cfe26 189
JackB 3:1af2ff7cfe26 190 #define ARM_RTC_Alarm2_Minutes 0x0B
JackB 3:1af2ff7cfe26 191 #define ARM_RTC_Alarm2_Hours 0x0C
JackB 3:1af2ff7cfe26 192 #define ARM_RTC_Alarm_2_Day_Date 0x0D
JackB 3:1af2ff7cfe26 193
JackB 3:1af2ff7cfe26 194 #define ARM_RTC_Control 0x0E
JackB 3:1af2ff7cfe26 195
JackB 3:1af2ff7cfe26 196 // ARM_RTC Control bits
JackB 3:1af2ff7cfe26 197 #define ARM_RTC_bit_A1IE 0x01
JackB 3:1af2ff7cfe26 198 #define ARM_RTC_bit_A2IE 0x02
JackB 3:1af2ff7cfe26 199 #define ARM_RTC_bit_INTCN 0x04
JackB 3:1af2ff7cfe26 200 #define ARM_RTC_bit_SQW_1Hz 0x00
JackB 3:1af2ff7cfe26 201 #define ARM_RTC_bit_SQW_1024Hz 0x08
JackB 3:1af2ff7cfe26 202 #define ARM_RTC_bit_SQW_4096Hz 0x10
JackB 3:1af2ff7cfe26 203 #define ARM_RTC_bit_SQW_8192Hz 0x18
JackB 3:1af2ff7cfe26 204 #define ARM_RTC_bit_CONV 0x20
JackB 3:1af2ff7cfe26 205 #define ARM_RTC_bit_BBSQW 0x40
JackB 3:1af2ff7cfe26 206 #define ARM_RTC_bit_EOSCb 0x80
JackB 3:1af2ff7cfe26 207
JackB 3:1af2ff7cfe26 208 #define ARM_RTC_CTRL_ALARM1_INT 0x01
JackB 3:1af2ff7cfe26 209 #define ARM_RTC_CTRL_ALARM2_INT 0x02
JackB 3:1af2ff7cfe26 210 #define ARM_RTC_CTRL_ALARM_INTS 0x04
JackB 3:1af2ff7cfe26 211 #define ARM_RTC_CTRL_SQWAVE_1HZ 0x00
JackB 3:1af2ff7cfe26 212 #define ARM_RTC_CTRL_SQWAVE_1024HZ 0x08
JackB 3:1af2ff7cfe26 213 #define ARM_RTC_CTRL_SQWAVE_4096HZ 0x10
JackB 3:1af2ff7cfe26 214 #define ARM_RTC_CTRL_SQWAVE_8192HZ 0x18
JackB 3:1af2ff7cfe26 215 #define ARM_RTC_CTRL_TEMPCONV 0x20
JackB 3:1af2ff7cfe26 216 #define ARM_RTC_CTRL_SQUAREWAVE_BB 0x40
JackB 3:1af2ff7cfe26 217 #define ARM_RTC_CTRL_OSCILLATOR 0x80
JackB 3:1af2ff7cfe26 218
JackB 3:1af2ff7cfe26 219 #define ARM_RTC_ALARM_NONE 0
JackB 3:1af2ff7cfe26 220 #define ARM_RTC_ALARM_1 1
JackB 3:1af2ff7cfe26 221 #define ARM_RTC_ALARM_2 2
JackB 3:1af2ff7cfe26 222 #define ARM_RTC_ALARM_BOTH 3
JackB 3:1af2ff7cfe26 223
JackB 3:1af2ff7cfe26 224 #define ARM_RTC_ALARM1_EVERY_SECOND 0
JackB 3:1af2ff7cfe26 225 #define ARM_RTC_ALARM1_MATCH_SEC 1
JackB 3:1af2ff7cfe26 226 #define ARM_RTC_ALARM1_MATCH_SECMIN 2
JackB 3:1af2ff7cfe26 227 #define ARM_RTC_ALARM1_MATCH_SECMINHOUR 3
JackB 3:1af2ff7cfe26 228 #define ARM_RTC_ALARM1_MATCH_SECMINHOURDAY 4
JackB 3:1af2ff7cfe26 229 #define ARM_RTC_ALARM1_MATCH_SECMINHOURDATE 5
JackB 3:1af2ff7cfe26 230
JackB 3:1af2ff7cfe26 231 #define ARM_RTC_ALARM2_EVERY_MIN 0
JackB 3:1af2ff7cfe26 232 #define ARM_RTC_ALARM2_MATCH_MIN 1
JackB 3:1af2ff7cfe26 233 #define ARM_RTC_ALARM2_MATCH_MINHOUR 2
JackB 3:1af2ff7cfe26 234 #define ARM_RTC_ALARM2_MATCH_MINHOURDAY 3
JackB 3:1af2ff7cfe26 235 #define ARM_RTC_ALARM2_MATCH_MINHOURDATE 4
JackB 3:1af2ff7cfe26 236
JackB 3:1af2ff7cfe26 237 #define ARM_RTC_ALARM_WDAY 0x40
JackB 3:1af2ff7cfe26 238 #define ARM_RTC_ALARM_NOTSET 0x80
JackB 3:1af2ff7cfe26 239
JackB 3:1af2ff7cfe26 240 #define ARM_RTC_ADDR_TIME 0x00
JackB 3:1af2ff7cfe26 241 #define ARM_RTC_ADDR_ALARM1 0x07
JackB 3:1af2ff7cfe26 242 #define ARM_RTC_ADDR_ALARM2 0x0b
JackB 3:1af2ff7cfe26 243 #define ARM_RTC_ADDR_CONTROL 0x0e
JackB 3:1af2ff7cfe26 244 #define ARM_RTC_ADDR_STATUS 0x0f
JackB 3:1af2ff7cfe26 245 #define ARM_RTC_ADDR_AGING 0x10
JackB 3:1af2ff7cfe26 246 #define ARM_RTC_ADDR_TEMP 0x11
JackB 3:1af2ff7cfe26 247
JackB 3:1af2ff7cfe26 248 #define ARM_RTC_SET 0
JackB 3:1af2ff7cfe26 249 #define ARM_RTC_CLEAR 1
JackB 3:1af2ff7cfe26 250 #define ARM_RTC_REPLACE 2
JackB 3:1af2ff7cfe26 251
JackB 3:1af2ff7cfe26 252 #define ARM_RTC_12HOUR_FLAG 0x40
JackB 3:1af2ff7cfe26 253 #define ARM_RTC_12HOUR_MASK 0x1f
JackB 3:1af2ff7cfe26 254 #define ARM_RTC_PM_FLAG 0x20
JackB 3:1af2ff7cfe26 255 #define ARM_RTC_MONTH_MASK 0x1f
JackB 3:1af2ff7cfe26 256
JackB 3:1af2ff7cfe26 257 #define ARM_RTC_Control_Status 0x0F
JackB 3:1af2ff7cfe26 258
JackB 3:1af2ff7cfe26 259 // ARM_RTC Control/Status bits
JackB 3:1af2ff7cfe26 260 #define ARM_RTC_bit_BSY 0x04
JackB 3:1af2ff7cfe26 261 #define ARM_RTC_bit_EN32kHz 0x08
JackB 3:1af2ff7cfe26 262 #define ARM_RTC_bit_OSF 0x80
JackB 3:1af2ff7cfe26 263
JackB 3:1af2ff7cfe26 264 #define ARM_RTC_Aging_Offset 0x10
JackB 3:1af2ff7cfe26 265 #define ARM_RTC_MSB_Temp 0x11
JackB 3:1af2ff7cfe26 266 #define ARM_RTC_LSB_Temp 0x12
JackB 3:1af2ff7cfe26 267
JackB 3:1af2ff7cfe26 268 #define NTP_OFFSET 2208988800ULL
JackB 3:1af2ff7cfe26 269
JackB 3:1af2ff7cfe26 270 /* Interface to MAXIM ARM_RTC RTC */
JackB 3:1af2ff7cfe26 271 class ARM_RTC
JackB 3:1af2ff7cfe26 272 {
JackB 3:1af2ff7cfe26 273 public :
JackB 3:1af2ff7cfe26 274 /** Create an instance of the ARM_RTC connected to specfied I2C pins
JackB 3:1af2ff7cfe26 275 *
JackB 3:1af2ff7cfe26 276 * @param sda The I2C data pin
JackB 3:1af2ff7cfe26 277 * @param scl The I2C clock pin
JackB 3:1af2ff7cfe26 278 */
JackB 3:1af2ff7cfe26 279 ARM_RTC();
JackB 3:1af2ff7cfe26 280
JackB 3:1af2ff7cfe26 281 bool checkTimeLost(void);
JackB 3:1af2ff7cfe26 282
JackB 3:1af2ff7cfe26 283 /** Set the time registers
JackB 3:1af2ff7cfe26 284 * @param seconds since 1900
JackB 3:1af2ff7cfe26 285 */
JackB 3:1af2ff7cfe26 286 void setDateTimeSecsSince1900(uint32_t secsSince1900);
JackB 3:1af2ff7cfe26 287
JackB 3:1af2ff7cfe26 288 /** Set the time registers
JackB 3:1af2ff7cfe26 289 * @param seconds since 1970
JackB 3:1af2ff7cfe26 290 */
JackB 3:1af2ff7cfe26 291 void setDateTimeSecsSince1970(uint32_t secsSince1970);
JackB 3:1af2ff7cfe26 292
JackB 3:1af2ff7cfe26 293 /** Set the time registers
JackB 3:1af2ff7cfe26 294 * @return seconds since 1970
JackB 3:1af2ff7cfe26 295 */
JackB 3:1af2ff7cfe26 296 uint32_t getDateTimeSecsSince1970(void);
JackB 3:1af2ff7cfe26 297 time_t getDateTimeSecsSince1970TZ(void);
JackB 3:1af2ff7cfe26 298
JackB 3:1af2ff7cfe26 299 /** Set the time zone
JackB 3:1af2ff7cfe26 300 * @param hours offset
JackB 3:1af2ff7cfe26 301 * @return void
JackB 3:1af2ff7cfe26 302 */
JackB 3:1af2ff7cfe26 303 void setTimeZone(double TZ);
JackB 3:1af2ff7cfe26 304
JackB 3:1af2ff7cfe26 305 /** Get the time zone
JackB 3:1af2ff7cfe26 306 * @param void
JackB 3:1af2ff7cfe26 307 * @return hours offset
JackB 3:1af2ff7cfe26 308 */
JackB 3:1af2ff7cfe26 309 double getTimeZone(void);
JackB 3:1af2ff7cfe26 310
JackB 3:1af2ff7cfe26 311 /** Set the date registers
JackB 3:1af2ff7cfe26 312 * // @param dayOfWeek : day of week
JackB 3:1af2ff7cfe26 313 * @param date
JackB 3:1af2ff7cfe26 314 * @param month
JackB 3:1af2ff7cfe26 315 * @param year
JackB 3:1af2ff7cfe26 316 */
JackB 3:1af2ff7cfe26 317 void setDate(int date, int month, int year);
JackB 3:1af2ff7cfe26 318
JackB 3:1af2ff7cfe26 319 /** Set the time registers
JackB 3:1af2ff7cfe26 320 * @param hours
JackB 3:1af2ff7cfe26 321 * @param minutes
JackB 3:1af2ff7cfe26 322 * @param seconds
JackB 3:1af2ff7cfe26 323 */
JackB 3:1af2ff7cfe26 324 void setTime(int hours, int minutes, int seconds);
JackB 3:1af2ff7cfe26 325
JackB 3:1af2ff7cfe26 326 /** Read the date and time and set system clock
JackB 3:1af2ff7cfe26 327 */
JackB 3:1af2ff7cfe26 328 void setSystemClock(void);
JackB 3:1af2ff7cfe26 329
JackB 3:1af2ff7cfe26 330 void readDateTime(void);
JackB 3:1af2ff7cfe26 331
JackB 3:1af2ff7cfe26 332 /** Set the time
JackB 3:1af2ff7cfe26 333 * @param hours
JackB 3:1af2ff7cfe26 334 * @param minutes
JackB 3:1af2ff7cfe26 335 * @param seconds
JackB 3:1af2ff7cfe26 336 * @param day
JackB 3:1af2ff7cfe26 337 * @param month
JackB 3:1af2ff7cfe26 338 * @param year
JackB 3:1af2ff7cfe26 339 */
JackB 3:1af2ff7cfe26 340 void setDateTime(int day, int month, int year, int hours, int minutes, int seconds);
JackB 3:1af2ff7cfe26 341
JackB 3:1af2ff7cfe26 342 /** Set the time registers
JackB 3:1af2ff7cfe26 343 * @param struct tm *time
JackB 3:1af2ff7cfe26 344 */
JackB 3:1af2ff7cfe26 345 void setDateTime(struct tm *time);
JackB 3:1af2ff7cfe26 346
JackB 3:1af2ff7cfe26 347 /** Get the time registers
JackB 3:1af2ff7cfe26 348 * @return struct tm *time
JackB 3:1af2ff7cfe26 349 */
JackB 3:1af2ff7cfe26 350 void getDateTime(struct tm *time);
JackB 3:1af2ff7cfe26 351 struct tm *getDateTime(void);
JackB 3:1af2ff7cfe26 352
JackB 3:1af2ff7cfe26 353 int getDayOfWeek(int date, int month, int year);
JackB 3:1af2ff7cfe26 354
JackB 3:1af2ff7cfe26 355 char * getDayOfWeekName(void);
JackB 3:1af2ff7cfe26 356
JackB 3:1af2ff7cfe26 357 char * getFormatedDateTime(char *format);
JackB 3:1af2ff7cfe26 358
JackB 3:1af2ff7cfe26 359 bool error;
JackB 3:1af2ff7cfe26 360
JackB 3:1af2ff7cfe26 361 bool getSummerTime(void);
JackB 3:1af2ff7cfe26 362
JackB 3:1af2ff7cfe26 363 int dayOfYearC(void);
JackB 3:1af2ff7cfe26 364 char * getSunRise(void);
JackB 3:1af2ff7cfe26 365 char * getSunSet(void);
JackB 3:1af2ff7cfe26 366 char * getDayLength(void);
JackB 3:1af2ff7cfe26 367 int getSunRiseMinute(void);
JackB 3:1af2ff7cfe26 368 int getSunSetMinute(void);
JackB 3:1af2ff7cfe26 369 bool checkSunRise(void);
JackB 3:1af2ff7cfe26 370
JackB 3:1af2ff7cfe26 371 void substr(char *s, char *d, int pos, int len);
JackB 3:1af2ff7cfe26 372 char * substr(char *s, int pos, int len);
JackB 3:1af2ff7cfe26 373
JackB 3:1af2ff7cfe26 374 int bcd2dec(int k); // bcd to decimal conversion
JackB 3:1af2ff7cfe26 375 int dec2bcd(int k); // decimal to bcd conversion
JackB 3:1af2ff7cfe26 376
JackB 3:1af2ff7cfe26 377 private :
JackB 3:1af2ff7cfe26 378 // I2C i2c;
JackB 3:1af2ff7cfe26 379 // char ARM_RTC_Address;
JackB 3:1af2ff7cfe26 380 // void decodeTime(int regHours, int regMinutes, int regSeconds,int *Hours, int *Minutes, int *Seconds);
JackB 3:1af2ff7cfe26 381 // void decodeDate(int regDate,int regMonth, int regYear, int *date, int *month, int *year);
JackB 3:1af2ff7cfe26 382
JackB 3:1af2ff7cfe26 383 char buffer[40];
JackB 3:1af2ff7cfe26 384
JackB 3:1af2ff7cfe26 385 uint32_t timeZoneOffset;
JackB 3:1af2ff7cfe26 386 char timeZoneName[32];
JackB 3:1af2ff7cfe26 387 bool dayLightSaving;
JackB 3:1af2ff7cfe26 388
JackB 3:1af2ff7cfe26 389 struct tm t;
JackB 3:1af2ff7cfe26 390 // t.tm_sec = -1;
JackB 3:1af2ff7cfe26 391 // t.tm_min = -1;
JackB 3:1af2ff7cfe26 392 // t.tm_hour = -1;
JackB 3:1af2ff7cfe26 393 // t.tm_mday = -1;
JackB 3:1af2ff7cfe26 394 // t.tm_wday = -1;
JackB 3:1af2ff7cfe26 395 // t.tm_yday = -1;
JackB 3:1af2ff7cfe26 396 // t.tm_mon = -1;
JackB 3:1af2ff7cfe26 397 // t.tm_year = -1;
JackB 3:1af2ff7cfe26 398
JackB 3:1af2ff7cfe26 399 time_t secondsEpoch;
JackB 3:1af2ff7cfe26 400
JackB 3:1af2ff7cfe26 401 struct DateTime{
JackB 3:1af2ff7cfe26 402 int year;
JackB 3:1af2ff7cfe26 403 int mon;
JackB 3:1af2ff7cfe26 404 int mday;
JackB 3:1af2ff7cfe26 405 int wday;
JackB 3:1af2ff7cfe26 406 int yday;
JackB 3:1af2ff7cfe26 407 int hour;
JackB 3:1af2ff7cfe26 408 int min;
JackB 3:1af2ff7cfe26 409 int sec;
JackB 3:1af2ff7cfe26 410 };
JackB 3:1af2ff7cfe26 411
JackB 3:1af2ff7cfe26 412
JackB 3:1af2ff7cfe26 413 };
JackB 3:1af2ff7cfe26 414
JackB 3:1af2ff7cfe26 415 #endif