EU1KY AA
rtc2.h
Go to the documentation of this file.
1 /*
2  * DS RTC Library: DS1307 and DS3231 driver library
3  * (C) 2011 Akafugu Corporation
4  *
5  * This program is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 2 of the License, or (at your option) any later
8  * version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
13  *
14  */
15 
16 #ifndef DS1307_H
17 #define DS1307_H
18 
19 #include <stdbool.h>
20 #include "config.h"
21 //#include "twi.h"
22 
23 #define DS1307_SLAVE_ADDR 0b11010000
24 
41 struct tm {
42  int sec; // 0 to 59
43  int min; // 0 to 59
44  int hour; // 0 to 23
45  int mday; // 1 to 31
46  int mon; // 1 to 12
47  int year; // year-99
48  int wday; // 1-7
49 
50  // 12-hour clock data
51  bool am; // true for AM, false for PM
52  int twelveHour; // 12 hour clock time
53 };
54 
55 // statically allocated
56 extern struct tm _tm;
57 
58 // Initialize the RTC and autodetect type (DS1307 or DS3231)
59 void rtc_init(void);
60 
61 // Autodetection
62 bool rtc_is_ds1307(void);
63 bool rtc_is_ds3231(void);
64 
65 void rtc_set_ds1307(void);
66 void rtc_set_ds3231(void);
67 
68 // Get/set time
69 // Gets the time: Supports both 24-hour and 12-hour mode
70 struct tm* rtc_get_time(void);
71 // Gets the time: 24-hour mode only
72 void rtc_get_time_s(uint8_t* hour, uint8_t* min, uint8_t* sec);
73 // Sets the time: Supports both 24-hour and 12-hour mode
74 void rtc_set_time(struct tm* tm_);
75 // Sets the time: Supports 12-hour mode only
76 void rtc_set_time_s(uint8_t hour, uint8_t min, uint8_t sec);
77 
78 // start/stop clock running (DS1307 only)
79 void rtc_run_clock(bool run);
80 bool rtc_is_clock_running(void);
81 
82 // Read Temperature (DS3231 only)
83 void ds3231_get_temp_int(int8_t* i, uint8_t* f);
84 void rtc_force_temp_conversion(uint8_t block);
85 
86 // SRAM read/write DS1307 only
87 void rtc_get_sram(uint8_t* data);
88 void rtc_set_sram(uint8_t *data);
89 uint8_t rtc_get_sram_byte(uint8_t offset);
90 void rtc_set_sram_byte(uint8_t b, uint8_t offset);
91 
92  // Auxillary functions
94 
95 void rtc_SQW_enable(bool enable);
97 void rtc_osc32kHz_enable(bool enable);
98 
99 // Alarm functionality
100 void rtc_reset_alarm(void);
101 void rtc_set_alarm(struct tm* tm_);
102 void rtc_set_alarm_s(uint8_t hour, uint8_t min, uint8_t sec);
103 struct tm* rtc_get_alarm(void);
104 void rtc_get_alarm_s(uint8_t* hour, uint8_t* min, uint8_t* sec);
105 bool rtc_check_alarm(void);
106 
107 #endif
void rtc_set_sram_byte(uint8_t b, uint8_t offset)
Definition: rtc2.c:382
int year
Definition: rtc2.h:47
void rtc_set_time_s(uint8_t hour, uint8_t min, uint8_t sec)
Definition: rtc2.c:245
void rtc_init(void)
Definition: rtc2.c:115
void rtc_get_sram(uint8_t *data)
Definition: rtc2.c:356
void ds3231_get_temp_int(int8_t *i, uint8_t *f)
Definition: rtc2.c:290
struct tm _tm
Definition: rtc2.c:82
void rtc_set_alarm_s(uint8_t hour, uint8_t min, uint8_t sec)
Definition: rtc2.c:523
void rtc_get_time_s(uint8_t *hour, uint8_t *min, uint8_t *sec)
Definition: rtc2.c:195
void rtc_set_alarm(struct tm *tm_)
Definition: rtc2.c:553
bool rtc_check_alarm(void)
Definition: rtc2.c:584
uint8_t rtc_get_sram_byte(uint8_t offset)
Definition: rtc2.c:372
bool rtc_is_ds3231(void)
Definition: rtc2.c:143
int twelveHour
Definition: rtc2.h:52
#define enable
Definition: GPIO.h:30
Definition: rtc2.h:93
void rtc_osc32kHz_enable(bool enable)
Definition: rtc2.c:479
Definition: rtc2.h:93
int mday
Definition: rtc2.h:45
int min
Definition: rtc2.h:43
int sec
Definition: rtc2.h:42
RTC_SQW_FREQ
Definition: rtc2.h:93
void freq(void)
Definition: spectr.c:363
void rtc_force_temp_conversion(uint8_t block)
Definition: rtc2.c:320
void rtc_run_clock(bool run)
Definition: rtc2.c:263
bool rtc_is_ds1307(void)
Definition: rtc2.c:142
struct tm * rtc_get_alarm(void)
Definition: rtc2.c:573
void rtc_set_time(struct tm *tm_)
Definition: rtc2.c:219
void rtc_set_sram(uint8_t *data)
Definition: rtc2.c:364
Definition: rtc2.h:93
void rtc_get_alarm_s(uint8_t *hour, uint8_t *min, uint8_t *sec)
Definition: rtc2.c:559
struct tm * rtc_get_time(void)
Definition: rtc2.c:149
Definition: rtc2.h:41
int i
Definition: panvswr2.c:1675
void rtc_reset_alarm(void)
Definition: rtc2.c:506
void rtc_set_ds1307(void)
Definition: rtc2.c:146
int hour
Definition: rtc2.h:44
int wday
Definition: rtc2.h:48
bool am
Definition: rtc2.h:51
void rtc_SQW_enable(bool enable)
Definition: rtc2.c:390
void rtc_SQW_set_freq(enum RTC_SQW_FREQ freq)
Definition: rtc2.c:438
void rtc_set_ds3231(void)
Definition: rtc2.c:147
int mon
Definition: rtc2.h:46
Definition: rtc2.h:93
bool rtc_is_clock_running(void)
Definition: rtc2.c:280