LibDriver PCF8563
Loading...
Searching...
No Matches
driver_pcf8563_output.c
Go to the documentation of this file.
1
36
38
39static pcf8563_handle_t gs_handle;
40static int8_t gs_time_zone = 0;
41
50{
51 uint8_t res;
52
53 /* link functions */
62
63 /* init pcf8563 */
64 res = pcf8563_init(&gs_handle);
65 if (res != 0)
66 {
67 pcf8563_interface_debug_print("pcf8563: init failed.\n");
68
69 return 1;
70 }
71
72 /* disable rtc stop */
74 if (res != 0)
75 {
76 pcf8563_interface_debug_print("pcf8563: set rtc stop failed.\n");
77 (void)pcf8563_deinit(&gs_handle);
78
79 return 1;
80 }
81
82 /* disable test mode */
84 if (res != 0)
85 {
86 pcf8563_interface_debug_print("pcf8563: set test mode failed.\n");
87 (void)pcf8563_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* disable power on reset */
94 if (res != 0)
95 {
96 pcf8563_interface_debug_print("pcf8563: set power on reset failed.\n");
97 (void)pcf8563_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* disable timer */
104 if (res != 0)
105 {
106 pcf8563_interface_debug_print("pcf8563: set timer enable failed.\n");
107 (void)pcf8563_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* disable minute alarm */
114 if (res != 0)
115 {
116 pcf8563_interface_debug_print("pcf8563: set minute alarm enable failed.\n");
117 (void)pcf8563_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* disable hour alarm */
124 if (res != 0)
125 {
126 pcf8563_interface_debug_print("pcf8563: set hour alarm enable failed.\n");
127 (void)pcf8563_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* disable day alarm */
134 if (res != 0)
135 {
136 pcf8563_interface_debug_print("pcf8563: set day alarm enable failed.\n");
137 (void)pcf8563_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* disable week alarm */
144 if (res != 0)
145 {
146 pcf8563_interface_debug_print("pcf8563: set week alarm enable failed.\n");
147 (void)pcf8563_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* disable timer interrupt */
154 if (res != 0)
155 {
156 pcf8563_interface_debug_print("pcf8563: set timer interrupt failed.\n");
157 (void)pcf8563_deinit(&gs_handle);
158
159 return 1;
160 }
161
162 /* disable alarm interrupt */
164 if (res != 0)
165 {
166 pcf8563_interface_debug_print("pcf8563: set alarm interrupt failed.\n");
167 (void)pcf8563_deinit(&gs_handle);
168
169 return 1;
170 }
171
172 /* disable clock out */
174 if (res != 0)
175 {
176 pcf8563_interface_debug_print("pcf8563: set clock out enable failed.\n");
177 (void)pcf8563_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 return 0;
183}
184
193{
194 if (pcf8563_deinit(&gs_handle) != 0)
195 {
196 return 1;
197 }
198
199 return 0;
200}
201
211{
212 /* set time */
213 if (pcf8563_set_time(&gs_handle, t) != 0)
214 {
215 return 1;
216 }
217
218 return 0;
219}
220
229uint8_t pcf8563_output_set_timestamp(time_t timestamp)
230{
232 struct tm *timeptr;
233
234 /* convert times */
235 timestamp += (time_t)(gs_time_zone * 3600);
236 timeptr = localtime(&timestamp);
237 t.date = (uint8_t)timeptr->tm_mday;
238 t.hour = (uint8_t)timeptr->tm_hour;
239 t.minute = (uint8_t)timeptr->tm_min;
240 t.month = (uint8_t)timeptr->tm_mon + 1;
241 t.second = (uint8_t)timeptr->tm_sec;
242 t.week = (uint8_t)timeptr->tm_wday;
243 t.year = (uint16_t)(timeptr->tm_year + 1900);
244
245 /* set time */
246 if (pcf8563_set_time(&gs_handle, &t) != 0)
247 {
248 return 1;
249 }
250
251 return 0;
252}
253
262{
263 gs_time_zone = zone;
264
265 return 0;
266}
267
277{
278 /* get time */
279 if (pcf8563_get_time(&gs_handle, t) != 0)
280 {
281 return 1;
282 }
283
284 return 0;
285}
286
295uint8_t pcf8563_output_get_timestamp(time_t *timestamp)
296{
298 struct tm timeptr;
299
300 /* get time */
301 if (pcf8563_get_time(&gs_handle, &t) != 0)
302 {
303 return 1;
304 }
305 timeptr.tm_year = t.year - 1900;
306 timeptr.tm_mon = t.month - 1;
307 timeptr.tm_wday = t.week;
308 timeptr.tm_mday = t.date;
309 timeptr.tm_hour = t.hour;
310 timeptr.tm_min = t.minute;
311 timeptr.tm_sec = t.second;
312
313 /* make time */
314 *timestamp = mktime(&timeptr) - gs_time_zone * 3600;
315
316 return 0;
317}
318
327{
328 *zone = gs_time_zone;
329
330 return 0;
331}
332
342uint8_t pcf8563_output_get_ascii_time(char *buf, uint8_t len)
343{
345
346 /* get time */
347 if (pcf8563_get_time(&gs_handle, &t) != 0)
348 {
349 return 1;
350 }
351
352 (void)snprintf(buf, len, "%04d-%02d-%02d %02d:%02d:%02d %d.\n", t.year, t.month, t.date, t.hour, t.minute, t.second, t.week);
353
354 return 0;
355}
356
366{
367 uint8_t res;
368
369 /* set the clock out */
370 res = pcf8563_set_clock_out(&gs_handle, clk);
371 if (res != 0)
372 {
373 return 1;
374 }
375
376 /* enable clock out */
378 if (res != 0)
379 {
380 return 1;
381 }
382
383 return 0;
384}
385
394{
395 uint8_t res;
396
397 /* disable clock out */
399 if (res != 0)
400 {
401 return 1;
402 }
403
404 return 0;
405}
driver pcf8563 output header file
uint8_t pcf8563_set_week_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable week alarm
uint8_t pcf8563_set_hour_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable hour alarm
uint8_t pcf8563_set_timer_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable timer enable
uint8_t pcf8563_deinit(pcf8563_handle_t *handle)
close the chip
uint8_t pcf8563_set_clock_out(pcf8563_handle_t *handle, pcf8563_clock_out_t clk)
set clock out
uint8_t pcf8563_set_timer_interrupt(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable timer interrupt
uint8_t pcf8563_set_test_mode(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable test mode
uint8_t pcf8563_set_clock_out_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable clock out enable
uint8_t pcf8563_init(pcf8563_handle_t *handle)
initialize the chip
pcf8563_clock_out_t
pcf8563 clock out enumeration definition
uint8_t pcf8563_set_time(pcf8563_handle_t *handle, pcf8563_time_t *t)
set the current time
struct pcf8563_time_s pcf8563_time_t
pcf8563 time structure definition
uint8_t pcf8563_set_alarm_interrupt(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable alarm interrupt
uint8_t pcf8563_set_day_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable day alarm
uint8_t pcf8563_set_minute_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable minute alarm
uint8_t pcf8563_set_rtc_stop(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable rtc stop
struct pcf8563_handle_s pcf8563_handle_t
pcf8563 handle structure definition
uint8_t pcf8563_get_time(pcf8563_handle_t *handle, pcf8563_time_t *t)
get the current time
uint8_t pcf8563_set_power_on_reset(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable power on reset
@ PCF8563_BOOL_TRUE
@ PCF8563_BOOL_FALSE
uint8_t pcf8563_output_enable(pcf8563_clock_out_t clk)
output example enable the output
uint8_t pcf8563_output_set_time(pcf8563_time_t *t)
output example set the time
uint8_t pcf8563_output_set_timestamp_time_zone(int8_t zone)
output example set the local time zone
uint8_t pcf8563_output_disable(void)
output example disable the output
uint8_t pcf8563_output_get_ascii_time(char *buf, uint8_t len)
output example get the ascii time
uint8_t pcf8563_output_set_timestamp(time_t timestamp)
output example set the time by a unix timestamp
uint8_t pcf8563_output_get_timestamp_time_zone(int8_t *zone)
output example get the local time zone
uint8_t pcf8563_output_get_timestamp(time_t *timestamp)
output example get the time in a unix timestamp
uint8_t pcf8563_output_get_time(pcf8563_time_t *t)
output example get the time
uint8_t pcf8563_output_init(void)
output example init
uint8_t pcf8563_output_deinit(void)
output example deinit
uint8_t pcf8563_interface_iic_init(void)
interface iic bus init
uint8_t pcf8563_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t pcf8563_interface_iic_deinit(void)
interface iic bus deinit
void pcf8563_interface_delay_ms(uint32_t ms)
interface delay ms
void pcf8563_interface_debug_print(const char *const fmt,...)
interface print format data
void pcf8563_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t pcf8563_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write