LibDriver DS3231
Loading...
Searching...
No Matches
driver_ds3231.c
Go to the documentation of this file.
1
37
38#include "driver_ds3231.h"
39
43#define CHIP_NAME "Maxim Integrated DS3231"
44#define MANUFACTURER_NAME "Maxim Integrated"
45#define SUPPLY_VOLTAGE_MIN 2.3f
46#define SUPPLY_VOLTAGE_MAX 5.5f
47#define MAX_CURRENT 0.65f
48#define TEMPERATURE_MIN -45.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
51
55#define DS3231_REG_SECOND 0x00
56#define DS3231_REG_MINUTE 0x01
57#define DS3231_REG_HOUR 0x02
58#define DS3231_REG_WEEK 0x03
59#define DS3231_REG_DATE 0x04
60#define DS3231_REG_MONTH 0x05
61#define DS3231_REG_YEAR 0x06
62#define DS3231_REG_ALARM1_SECOND 0x07
63#define DS3231_REG_ALARM1_MINUTE 0x08
64#define DS3231_REG_ALARM1_HOUR 0x09
65#define DS3231_REG_ALARM1_WEEK 0x0A
66#define DS3231_REG_ALARM2_MINUTE 0x0B
67#define DS3231_REG_ALARM2_HOUR 0x0C
68#define DS3231_REG_ALARM2_WEEK 0x0D
69#define DS3231_REG_CONTROL 0x0E
70#define DS3231_REG_STATUS 0x0F
71#define DS3231_REG_XTAL 0x10
72#define DS3231_REG_TEMPERATUREH 0x11
73#define DS3231_REG_TEMPERATUREL 0x12
74
78#define DS3231_ADDRESS 0xD0
79
90static uint8_t a_ds3231_iic_write(ds3231_handle_t *handle, uint8_t reg, uint8_t data)
91{
92 if (handle->iic_write(DS3231_ADDRESS, reg, &data, 1) != 0) /* write data */
93 {
94 return 1; /* return error */
95 }
96 else
97 {
98 return 0; /* success return 0 */
99 }
100}
101
113static uint8_t a_ds3231_iic_multiple_read(ds3231_handle_t *handle, uint8_t reg, uint8_t *buf, uint8_t len)
114{
115 if (handle->iic_read(DS3231_ADDRESS, reg, buf, len) != 0) /* read data */
116 {
117 return 1; /* return error */
118 }
119 else
120 { /* success return 0 */
121 return 0;
122 }
123}
124
131static uint8_t a_ds3231_hex2bcd(uint8_t val)
132{
133 uint8_t i, j, k;
134
135 i = val / 10; /* get tens place */
136 j = val % 10; /* get ones place */
137 k = j + (i << 4); /* set bcd */
138
139 return k; /* return bcd */
140}
141
148static uint8_t a_ds3231_bcd2hex(uint8_t val)
149{
150 uint8_t temp;
151
152 temp = val & 0x0F; /* get ones place */
153 val = (val >> 4) & 0x0F; /* get tens place */
154 val = val * 10; /* set tens place */
155 temp = temp + val; /* get hex */
156
157 return temp; /* return hex */
158}
159
173{
174 uint8_t res;
175 uint8_t reg;
176 uint8_t century;
177 uint16_t year;
178
179 if (handle == NULL) /* check handle */
180 {
181 return 2; /* return error */
182 }
183 if (handle->inited != 1) /* check handle initialization */
184 {
185 return 3; /* return error */
186 }
187 if (t == NULL) /* check time */
188 {
189 handle->debug_print("ds3231: time is null.\n"); /* time is null */
190
191 return 2; /* return error */
192 }
193 if (t->format == DS3231_FORMAT_12H) /* if 12H */
194 {
195 if ((t->year < 2000) || (t->year > 2199)) /* check year */
196 {
197 handle->debug_print("ds3231: year can't be over 2199 or less than 2000.\n"); /* year can't be over 2199 or less than 2000 */
198
199 return 4; /* return error */
200 }
201 if ((t->month == 0) || (t->month > 12)) /* check month */
202 {
203 handle->debug_print("ds3231: month can't be zero or over than 12.\n"); /* month can't be zero or over than 12 */
204
205 return 4; /* return error */
206 }
207 if ((t->week == 0) || (t->week > 7)) /* check week */
208 {
209 handle->debug_print("ds3231: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
210
211 return 4; /* return error */
212 }
213 if ((t->date == 0) || (t->date > 31)) /* check data */
214 {
215 handle->debug_print("ds3231: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
216
217 return 4; /* return error */
218 }
219 if ((t->hour < 1) || (t->hour > 12)) /* check hour */
220 {
221 handle->debug_print("ds3231: hour can't be over than 12 or less 1.\n"); /* hour can't be over than 12 or less 1 */
222
223 return 4; /* return error */
224 }
225 if (t->minute > 59) /* check minute */
226 {
227 handle->debug_print("ds3231: minute can't be over than 59.\n"); /* minute can't be over than 59 */
228
229 return 4; /* return error */
230 }
231 if (t->second > 59) /* check second */
232 {
233 handle->debug_print("ds3231: second can't be over than 59.\n"); /* second can't be over than 59 */
234
235 return 4; /* return error */
236 }
237 }
238 else if (t->format == DS3231_FORMAT_24H) /* if 24H */
239 {
240 if ((t->year < 2000) || (t->year > 2199)) /* check year */
241 {
242 handle->debug_print("ds3231: year can't be over 2199 or less than 2000.\n"); /* year can't be over 2199 or less than 2000 */
243
244 return 4; /* return error */
245 }
246 if ((t->month == 0) || (t->month > 12)) /* check month */
247 {
248 handle->debug_print("ds3231: month can't be zero or over than 12.\n"); /* month can't be zero or over than 12 */
249
250 return 4; /* return error */
251 }
252 if ((t->week == 0) || (t->week > 7)) /* check week */
253 {
254 handle->debug_print("ds3231: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
255
256 return 4; /* return error */
257 }
258 if ((t->date == 0) || (t->date > 31)) /* check data */
259 {
260 handle->debug_print("ds3231: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
261
262 return 4; /* return error */
263 }
264 if (t->hour > 23) /* check hour */
265 {
266 handle->debug_print("ds3231: hour can't be over than 23.\n"); /* hour can't be over than 23 */
267
268 return 4; /* return error */
269 }
270 if (t->minute > 59) /* check minute */
271 {
272 handle->debug_print("ds3231: minute can't be over than 59.\n"); /* minute can't be over than 59 */
273
274 return 4; /* return error */
275 }
276 if (t->second > 59) /* check second */
277 {
278 handle->debug_print("ds3231: second can't be over than 59.\n"); /* second can't be over than 59 */
279
280 return 4; /* return error */
281 }
282 }
283 else
284 {
285 handle->debug_print("ds3231: format is invalid.\n"); /* format is invalid */
286
287 return 4; /* return error */
288 }
289
290 res = a_ds3231_iic_write(handle, DS3231_REG_SECOND, a_ds3231_hex2bcd(t->second)); /* write second */
291 if (res != 0) /* check result */
292 {
293 handle->debug_print("ds3231: write second failed.\n"); /* write second failed */
294
295 return 1; /* return error */
296 }
297 res = a_ds3231_iic_write(handle, DS3231_REG_MINUTE, a_ds3231_hex2bcd(t->minute)); /* write minute */
298 if (res != 0) /* check result */
299 {
300 handle->debug_print("ds3231: write minute failed.\n"); /* write minute failed */
301
302 return 1; /* return error */
303 }
304 if (t->format == DS3231_FORMAT_12H) /* if 12H */
305 {
306 reg = (uint8_t)((1 << 6) | (t->am_pm << 5) | a_ds3231_hex2bcd(t->hour)); /* set hour in 12H */
307 }
308 else /* if 24H */
309 {
310 reg = (0 << 6) | a_ds3231_hex2bcd(t->hour); /* set hour in 24H */
311 }
312 res = a_ds3231_iic_write(handle, DS3231_REG_HOUR, reg); /* write hour */
313 if (res != 0) /* check result */
314 {
315 handle->debug_print("ds3231: write hour failed.\n"); /* write hour failed */
316
317 return 1; /* return error */
318 }
319 res = a_ds3231_iic_write(handle, DS3231_REG_WEEK, a_ds3231_hex2bcd(t->week)); /* write week */
320 if (res != 0) /* check result */
321 {
322 handle->debug_print("ds3231: write week failed.\n"); /* write week failed */
323
324 return 1; /* return error */
325 }
326 res = a_ds3231_iic_write(handle, DS3231_REG_DATE, a_ds3231_hex2bcd(t->date)); /* write data */
327 if (res != 0) /* check result */
328 {
329 handle->debug_print("ds3231: write date failed.\n"); /* write date failed */
330
331 return 1; /* return error */
332 }
333 year = t->year - 2000; /* year - 2000 */
334 if (year >= 100) /* check year */
335 {
336 century = 1; /* set century */
337 year -= 100; /* year -= 100 */
338 }
339 else
340 {
341 century = 0; /* set century 0 */
342 }
343 res = a_ds3231_iic_write(handle, DS3231_REG_MONTH, a_ds3231_hex2bcd(t->month) | (century << 7)); /* write month and century */
344 if (res != 0) /* check result */
345 {
346 handle->debug_print("ds3231: write century and month failed.\n"); /* write century and month failed */
347
348 return 1; /* return error */
349 }
350 res = a_ds3231_iic_write(handle, DS3231_REG_YEAR, a_ds3231_hex2bcd((uint8_t)year)); /* write year */
351 if (res != 0) /* check result */
352 {
353 handle->debug_print("ds3231: write year failed.\n"); /* write year failed */
354
355 return 1; /* return error */
356 }
357
358 return 0; /* success return 0 */
359}
360
373{
374 uint8_t res;
375 uint8_t buf[7];
376
377 if (handle == NULL) /* check handle */
378 {
379 return 2; /* return error */
380 }
381 if (handle->inited != 1) /* check handle initialization */
382 {
383 return 3; /* return error */
384 }
385 if (t == NULL) /* check time */
386 {
387 handle->debug_print("ds3231: time is null.\n"); /* time is null */
388
389 return 2; /* return error */
390 }
391
392 memset(buf, 0, sizeof(uint8_t) * 7); /* clear the buffer */
393 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_SECOND, (uint8_t *)buf, 7); /* multiple_read */
394 if (res != 0) /* check result */
395 {
396 handle->debug_print("ds3231: multiple read failed.\n"); /* multiple read failed */
397
398 return 1; /* return error */
399 }
400 t->year = a_ds3231_bcd2hex(buf[6]) + 2000 + ((buf[5] >> 7) & 0x01) * 100; /* get year */
401 t->month = a_ds3231_bcd2hex(buf[5]&0x1F); /* get month */
402 t->week = a_ds3231_bcd2hex(buf[3]); /* get week */
403 t->date = a_ds3231_bcd2hex(buf[4]); /* get date */
404 t->am_pm = (ds3231_am_pm_t)((buf[2] >> 5) & 0x01); /* get am pm */
405 t->format = (ds3231_format_t)((buf[2] >> 6) & 0x01); /* get format */
406 if (t->format == DS3231_FORMAT_12H) /* if 12H */
407 {
408 t->hour = a_ds3231_bcd2hex(buf[2] & 0x1F); /* get hour */
409 }
410 else
411 {
412 t->hour = a_ds3231_bcd2hex(buf[2] & 0x3F); /* get hour */
413 }
414 t->minute = a_ds3231_bcd2hex(buf[1]); /* get minute */
415 t->second = a_ds3231_bcd2hex(buf[0]); /* get second */
416
417 return 0; /* success return 0 */
418}
419
433{
434 uint8_t res;
435 uint8_t reg;
436
437 if (handle == NULL) /* check handle */
438 {
439 return 2; /* return error */
440 }
441 if (handle->inited != 1) /* check handle initialization */
442 {
443 return 3; /* return error */
444 }
445 if (t == NULL) /* check time */
446 {
447 handle->debug_print("ds3231: time is null.\n"); /* time is null */
448
449 return 2; /* return error */
450 }
451 if (t->format == DS3231_FORMAT_12H) /* if 12H */
452 {
453 if ((t->week == 0) || (t->week > 7)) /* check week */
454 {
455 handle->debug_print("ds3231: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
456
457 return 1; /* return error */
458 }
459 if ((t->date == 0) || (t->date > 31)) /* check data */
460 {
461 handle->debug_print("ds3231: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
462
463 return 1; /* return error */
464 }
465 if ((t->hour < 1) || (t->hour > 12)) /* check hour */
466 {
467 handle->debug_print("ds3231: hour can't be over than 12 or less 1.\n"); /* hour can't be over than 12 or less 1 */
468
469 return 1; /* return error */
470 }
471 if (t->minute > 59) /* check minute */
472 {
473 handle->debug_print("ds3231: minute can't be over than 59.\n"); /* minute can't be over than 59 */
474
475 return 1; /* return error */
476 }
477 if (t->second > 59) /* check second */
478 {
479 handle->debug_print("ds3231: second can't be over than 59.\n"); /* second can't be over than 59 */
480
481 return 1; /* return error */
482 }
483 }
484 else if (t->format == DS3231_FORMAT_24H) /* if 24H */
485 {
486 if ((t->week == 0) || (t->week > 7)) /* check week */
487 {
488 handle->debug_print("ds3231: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
489
490 return 1; /* return error */
491 }
492 if ((t->date == 0) || (t->date > 31)) /* check data */
493 {
494 handle->debug_print("ds3231: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
495
496 return 1; /* return error */
497 }
498 if (t->hour > 23) /* check hour */
499 {
500 handle->debug_print("ds3231: hour can't be over than 23.\n"); /* hour can't be over than 23 */
501
502 return 1; /* return error */
503 }
504 if (t->minute > 59) /* check minute */
505 {
506 handle->debug_print("ds3231: minute can't be over than 59.\n"); /* minute can't be over than 59 */
507
508 return 1; /* return error */
509 }
510 if (t->second > 59) /* check second */
511 {
512 handle->debug_print("ds3231: second can't be over than 59.\n"); /* second can't be over than 59 */
513
514 return 1; /* return error */
515 }
516 }
517 else
518 {
519 handle->debug_print("ds3231: format is invalid.\n"); /* format is invalid */
520
521 return 1; /* return error */
522 }
523
524 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM1_SECOND, a_ds3231_hex2bcd(t->second) | ((mode & 0x01) << 7)); /* write second */
525 if (res != 0) /* check result */
526 {
527 handle->debug_print("ds3231: write alarm1 second failed.\n"); /* write alarm1 second failed */
528
529 return 1; /* return error */
530 }
531 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM1_MINUTE, a_ds3231_hex2bcd(t->minute) | (((mode >> 1) & 0x01) << 7)); /* write minute */
532 if (res != 0) /* check result */
533 {
534 handle->debug_print("ds3231: write alarm1 minute failed.\n"); /* write alarm1 minute failed */
535
536 return 1; /* return error */
537 }
538 if (t->format == DS3231_FORMAT_12H) /* if 12H */
539 {
540 reg = (uint8_t)((((mode >> 2) & 0x01) << 7) | (1 << 6) | (t->am_pm << 5) | a_ds3231_hex2bcd(t->hour)); /* set hour in 12H */
541 }
542 else /* if 24H */
543 {
544 reg = (((mode >> 2) & 0x01) << 7) | a_ds3231_hex2bcd(t->hour); /* set hour in 24H */
545 }
546 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM1_HOUR, reg); /* write hour */
547 if (res != 0) /* check result */
548 {
549 handle->debug_print("ds3231: write alarm1 hour failed.\n"); /* write alarm1 hour failed */
550
551 return 1; /* return error */
552 }
553 if (mode >= DS3231_ALARM1_MODE_WEEK_HOUR_MINUTE_SECOND_MATCH) /* if week */
554 {
555 reg = (((mode >> 3) & 0x01) << 7) | (1 << 6) | a_ds3231_hex2bcd(t->week); /* set data in week */
556 }
557 else /* if day */
558 {
559 reg = (((mode >> 3) & 0x01) << 7) | a_ds3231_hex2bcd(t->date); /* set data in date */
560 }
561 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM1_WEEK, reg); /* write week */
562 if (res != 0) /* check result */
563 {
564 handle->debug_print("ds3231: write alarm1 week failed.\n"); /* write alarm1 week failed */
565
566 return 1; /* return error */
567 }
568
569 return 0; /* success return 0 */
570}
571
585{
586 uint8_t res;
587 uint8_t buf[4];
588
589 if (handle == NULL) /* check handle */
590 {
591 return 2; /* return error */
592 }
593 if (handle->inited != 1) /* check handle initialization */
594 {
595 return 3; /* return error */
596 }
597 if (t == NULL) /* check time */
598 {
599 handle->debug_print("ds3231: time is null.\n"); /* time is null */
600
601 return 2; /* return error */
602 }
603
604 memset(buf, 0, sizeof(uint8_t) * 4); /* clear the buffer */
605 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_ALARM1_SECOND, (uint8_t *)buf, 4); /* multiple_read */
606 if (res != 0) /* check result */
607 {
608 handle->debug_print("ds3231: multiple read failed.\n"); /* multiple read failed */
609
610 return 1; /* return error */
611 }
612 t->year = 0; /* get year */
613 t->month = 0; /* get month */
614 if (((buf[3] >> 6) & 0x01) != 0) /* if week */
615 {
616 t->week = a_ds3231_bcd2hex(buf[3] & 0x0F); /* get week */
617 t->date = 0; /* get data */
618 }
619 else /* if data */
620 {
621 t->week = 0; /* get week */
622 t->date = a_ds3231_bcd2hex(buf[3] & 0x3F); /* get data */
623 }
624 t->am_pm = (ds3231_am_pm_t)((buf[2] >> 5) & 0x01); /* get am pm */
625 t->format = (ds3231_format_t)((buf[2] >> 6) & 0x01); /* get format */
626 if (t->format == DS3231_FORMAT_12H) /* if 12H */
627 {
628 t->hour = a_ds3231_bcd2hex(buf[2]&0x1F); /* get hour */
629 }
630 else /* if 24H */
631 {
632 t->hour = a_ds3231_bcd2hex(buf[2]&0x3F); /* get hour */
633 }
634 t->minute = a_ds3231_bcd2hex(buf[1] & 0x7F); /* get minute */
635 t->second = a_ds3231_bcd2hex(buf[0] & 0x7F); /* get second */
636 *mode = (ds3231_alarm1_mode_t)(((buf[0]>>7)&0x01)<<0 | ((buf[1]>>7)&0x01)<<1 | ((buf[2]>>7)&0x01)<<2 | ((buf[3]>>7)&0x01)<<3 |
637 ((buf[3] >> 6)&0x01)<<4
638 ); /* get mode */
639
640 return 0; /* success return 0 */
641}
642
656{
657 uint8_t res;
658 uint8_t reg;
659
660 if (handle == NULL) /* check handle */
661 {
662 return 2; /* return error */
663 }
664 if (handle->inited != 1) /* check handle initialization */
665 {
666 return 3; /* return error */
667 }
668 if (t == NULL) /* check time */
669 {
670 handle->debug_print("ds3231: time is null.\n"); /* time is null */
671
672 return 2; /* return error */
673 }
674 if (t->format == DS3231_FORMAT_12H) /* if 12H */
675 {
676 if ((t->week == 0) || (t->week > 7)) /* check week */
677 {
678 handle->debug_print("ds3231: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
679
680 return 1; /* return error */
681 }
682 if ((t->date == 0) || (t->date > 31)) /* check data */
683 {
684 handle->debug_print("ds3231: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
685
686 return 1; /* return error */
687 }
688 if ((t->hour < 1) || (t->hour > 12)) /* check hour */
689 {
690 handle->debug_print("ds3231: hour can't be over than 12 or less 1.\n"); /* hour can't be over than 12 or less 1 */
691
692 return 1; /* return error */
693 }
694 if (t->minute > 59) /* check minute */
695 {
696 handle->debug_print("ds3231: minute can't be over than 59.\n"); /* minute can't be over than 59 */
697
698 return 1; /* return error */
699 }
700 }
701 else if (t->format == DS3231_FORMAT_24H) /* if 24H */
702 {
703 if ((t->week == 0) || (t->week > 7)) /* check week */
704 {
705 handle->debug_print("ds3231: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
706
707 return 1; /* return error */
708 }
709 if ((t->date == 0) || (t->date > 31)) /* check data */
710 {
711 handle->debug_print("ds3231: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
712
713 return 1; /* return error */
714 }
715 if (t->hour > 23) /* check hour */
716 {
717 handle->debug_print("ds3231: hour can't be over than 23.\n"); /* hour can't be over than 23 */
718
719 return 1; /* return error */
720 }
721 if (t->minute > 59) /* check minute */
722 {
723 handle->debug_print("ds3231: minute can't be over than 59.\n"); /* minute can't be over than 59 */
724
725 return 1; /* return error */
726 }
727 }
728 else
729 {
730 handle->debug_print("ds3231: format is invalid.\n"); /* format is invalid */
731
732 return 1; /* return error */
733 }
734
735 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM2_MINUTE, a_ds3231_hex2bcd(t->minute) | (((mode >> 0) & 0x01) << 7)); /* write minute */
736 if (res != 0) /* check result */
737 {
738 handle->debug_print("ds3231: write alarm2 minute failed.\n"); /* write alarm2 minute failed */
739
740 return 1; /* return error */
741 }
742 if (t->format == DS3231_FORMAT_12H) /* if 12H */
743 {
744 reg = (uint8_t)((((mode >> 1) & 0x01) << 7) | (1 << 6) | (t->am_pm << 5) | a_ds3231_hex2bcd(t->hour)); /* set hour in 12H */
745 }
746 else /* if 24H */
747 {
748 reg = (((mode >> 1) & 0x01) << 7) | a_ds3231_hex2bcd(t->hour); /* set hour in 24H */
749 }
750 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM2_HOUR, reg); /* write hour */
751 if (res != 0) /* check result */
752 {
753 handle->debug_print("ds3231: write alarm2 hour failed.\n"); /* write alarm2 hour failed */
754
755 return 1; /* return error */
756 }
757 if (mode >= (uint8_t)DS3231_ALARM2_MODE_WEEK_HOUR_MINUTE_MATCH) /* if week */
758 {
759 reg = (((mode >> 2) & 0x01) << 7) | (1 << 6) | a_ds3231_hex2bcd(t->week); /* set data in week */
760 }
761 else /* if day */
762 {
763 reg = (((mode >> 2) & 0x01) << 7) | a_ds3231_hex2bcd(t->date); /* set data in date */
764 }
765 res = a_ds3231_iic_write(handle, DS3231_REG_ALARM2_WEEK, reg); /* write week */
766 if (res != 0) /* check result */
767 {
768 handle->debug_print("ds3231: write alarm2 week failed.\n"); /* write alarm2 week failed */
769
770 return 1; /* return error */
771 }
772
773 return 0; /* success return 0 */
774}
775
789{
790 uint8_t res;
791 uint8_t buf[3];
792
793 if (handle == NULL) /* check handle */
794 {
795 return 2; /* return error */
796 }
797 if (handle->inited != 1) /* check handle initialization */
798 {
799 return 3; /* return error */
800 }
801 if (t == NULL) /* check time */
802 {
803 handle->debug_print("ds3231: time is null.\n"); /* time is null */
804
805 return 2; /* return error */
806 }
807
808 memset(buf, 0, sizeof(uint8_t) * 3); /* clear the buffer */
809 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_ALARM2_MINUTE, (uint8_t *)buf, 3); /* multiple read */
810 if (res != 0) /* check result */
811 {
812 handle->debug_print("ds3231: multiple read failed.\n"); /* multiple read failed */
813
814 return 1; /* return error */
815 }
816 t->year = 0; /* get year */
817 t->month = 0; /* get month */
818 if (((buf[2] >> 6) & 0x01) != 0) /* if week */
819 {
820 t->week = a_ds3231_bcd2hex(buf[2] & 0x0F); /* get week */
821 t->date = 0; /* get data */
822 }
823 else /* if data */
824 {
825 t->week = 0; /* get week */
826 t->date = a_ds3231_bcd2hex(buf[2] & 0x3F); /* get data */
827 }
828 t->am_pm = (ds3231_am_pm_t)((buf[1] >> 5) & 0x01); /* get am pm */
829 t->format = (ds3231_format_t)((buf[1] >> 6) & 0x01); /* get format */
830 if (t->format == DS3231_FORMAT_12H) /* if 12H */
831 {
832 t->hour = a_ds3231_bcd2hex(buf[1]&0x1F); /* get hour */
833 }
834 else /* if 24H */
835 {
836 t->hour = a_ds3231_bcd2hex(buf[1]&0x3F); /* get hour */
837 }
838 t->minute = a_ds3231_bcd2hex(buf[0] & 0x7F); /* get minute */
839 t->second = 0; /* get second */
840 *mode = (ds3231_alarm2_mode_t)(((buf[0]>>7)&0x01)<<0 | ((buf[1]>>7)&0x01)<<1 | ((buf[2]>>7)&0x01)<<2 | ((buf[2]>>6)&0x01)<<4); /* get mode */
841
842 return 0; /* success return 0 */
843}
844
857{
858 uint8_t res;
859 uint8_t prev;
860
861 if (handle == NULL) /* check handle */
862 {
863 return 2; /* return error */
864 }
865 if (handle->inited != 1) /* check handle initialization */
866 {
867 return 3; /* return error */
868 }
869
870 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple read */
871 if (res != 0) /* check result */
872 {
873 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
874
875 return 1; /* return error */
876 }
877 prev &= ~ (1 << 7); /* clear config */
878 prev |= (!enable) << 7; /* set enable */
879 res = a_ds3231_iic_write(handle, DS3231_REG_CONTROL, prev); /* write control */
880 if (res != 0) /* check result */
881 {
882 handle->debug_print("ds3231: write control failed.\n"); /* write control failed */
883
884 return 1; /* return error */
885 }
886
887 return 0; /* success return 0 */
888}
889
902{
903 uint8_t res;
904 uint8_t prev;
905
906 if (handle == NULL) /* check handle */
907 {
908 return 2; /* return error */
909 }
910 if (handle->inited != 1) /* check handle initialization */
911 {
912 return 3; /* return error */
913 }
914
915 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple read */
916 if (res != 0) /* check result */
917 {
918 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
919
920 return 1; /* return error */
921 }
922 *enable = (ds3231_bool_t)(!((prev >> 7) & 0x01)); /* get enable */
923
924 return 0; /* success return 0 */
925}
926
940{
941 uint8_t res;
942 uint8_t prev;
943
944 if (handle == NULL) /* check handle */
945 {
946 return 2; /* return error */
947 }
948 if (handle->inited != 1) /* check handle initialization */
949 {
950 return 3; /* return error */
951 }
952
953 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple_read */
954 if (res != 0) /* check result */
955 {
956 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
957
958 return 1; /* return error */
959 }
960 prev &= ~(1 << alarm); /* clear config */
961 prev |= enable << alarm; /* set enable */
962 res = a_ds3231_iic_write(handle, DS3231_REG_CONTROL, prev); /* write control */
963 if (res != 0) /* check result */
964 {
965 handle->debug_print("ds3231: write control failed.\n"); /* write control failed */
966
967 return 1; /* return error */
968 }
969
970 return 0; /* success return 0 */
971}
972
986{
987 uint8_t res;
988 uint8_t prev;
989
990 if (handle == NULL) /* check handle */
991 {
992 return 2; /* return error */
993 }
994 if (handle->inited != 1) /* check handle initialization */
995 {
996 return 3; /* return error */
997 }
998
999 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple_read */
1000 if (res != 0) /* check result */
1001 {
1002 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
1003
1004 return 1; /* return error */
1005 }
1006 *enable = (ds3231_bool_t)((prev >> alarm) & 0x01); /* get enable */
1007
1008 return 0; /* success return 0 */
1009}
1010
1023{
1024 uint8_t res;
1025 uint8_t prev;
1026
1027 if (handle == NULL) /* check handle */
1028 {
1029 return 2; /* return error */
1030 }
1031 if (handle->inited != 1) /* check handle initialization */
1032 {
1033 return 3; /* return error */
1034 }
1035
1036 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple_read */
1037 if (res != 0) /* check result */
1038 {
1039 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
1040
1041 return 1; /* return error */
1042 }
1043 prev &= ~(1 << 2); /* clear config */
1044 prev |= pin << 2; /* set pin */
1045 res = a_ds3231_iic_write(handle, DS3231_REG_CONTROL, prev); /* write control */
1046 if (res != 0) /* check result */
1047 {
1048 handle->debug_print("ds3231: write control failed.\n"); /* write control failed */
1049
1050 return 1; /* return error */
1051 }
1052
1053 return 0; /* success return 0 */
1054}
1055
1068{
1069 uint8_t res;
1070 uint8_t prev;
1071
1072 if (handle == NULL) /* check handle */
1073 {
1074 return 2; /* return error */
1075 }
1076 if (handle->inited != 1) /* check handle initialization */
1077 {
1078 return 3; /* return error */
1079 }
1080
1081 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple_read */
1082 if (res != 0) /* check result */
1083 {
1084 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
1085
1086 return 1; /* return error */
1087 }
1088 *pin = (ds3231_pin_t)((prev >> 2) & 0x01); /* get pin */
1089
1090 return 0; /* success return 0 */
1091}
1092
1105{
1106 uint8_t res;
1107 uint8_t prev;
1108
1109 if (handle == NULL) /* check handle */
1110 {
1111 return 2; /* return error */
1112 }
1113 if (handle->inited != 1) /* check handle initialization */
1114 {
1115 return 3; /* return error */
1116 }
1117
1118 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple_read */
1119 if (res != 0) /* check result */
1120 {
1121 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
1122
1123 return 1; /* return error */
1124 }
1125 prev &= ~(1 << 6); /* clear config */
1126 prev |= enable << 6; /* set enable */
1127 res = a_ds3231_iic_write(handle, DS3231_REG_CONTROL, prev); /* write control */
1128 if (res != 0) /* check result */
1129 {
1130 handle->debug_print("ds3231: write control failed.\n"); /* write control failed */
1131
1132 return 1; /* return error */
1133 }
1134
1135 return 0; /* success return 0 */
1136}
1137
1150{
1151 uint8_t res;
1152 uint8_t prev;
1153
1154 if (handle == NULL) /* check handle */
1155 {
1156 return 2; /* return error */
1157 }
1158 if (handle->inited != 1) /* check handle initialization */
1159 {
1160 return 3; /* return error */
1161 }
1162
1163 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple_read */
1164 if (res != 0) /* check result */
1165 {
1166 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
1167
1168 return 1; /* return error */
1169 }
1170 *enable = (ds3231_bool_t)((prev >> 6) & 0x01); /* get enable */
1171
1172 return 0; /* success return 0 */
1173}
1174
1187uint8_t ds3231_get_temperature(ds3231_handle_t *handle, int16_t *raw, float *s)
1188{
1189 uint8_t res;
1190 uint8_t prev;
1191 uint32_t times;
1192 uint8_t buf[2];
1193
1194 if (handle == NULL) /* check handle */
1195 {
1196 return 2; /* return error */
1197 }
1198 if (handle->inited != 1) /* check handle initialization */
1199 {
1200 return 3; /* return error */
1201 }
1202
1203 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
1204 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_CONTROL, (uint8_t *)&prev, 1); /* multiple read */
1205 if (res != 0) /* check result */
1206 {
1207 handle->debug_print("ds3231: read control failed.\n"); /* read control failed */
1208
1209 return 1; /* return error */
1210 }
1211 prev &= ~(1 << 5); /* clear config */
1212 prev |= 1 << 5; /* set enable */
1213 res = a_ds3231_iic_write(handle, DS3231_REG_CONTROL, prev); /* write control */
1214 if (res != 0) /* check result */
1215 {
1216 handle->debug_print("ds3231: write control failed.\n"); /* write control failed */
1217
1218 return 1; /* return error */
1219 }
1220 times = 500; /* set 5s */
1221 while (times != 0) /* check times */
1222 {
1223 handle->delay_ms(10); /* delay 10 ms */
1224 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
1225 if (res != 0) /* check result */
1226 {
1227 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1228
1229 return 1; /* return error */
1230 }
1231 if (((prev >> 2) & 0x01) == 0) /* check result */
1232 {
1233 break; /* break */
1234 }
1235 times--; /* times-- */
1236 }
1237 if (times == 0) /* if zero */
1238 {
1239 handle->debug_print("ds3231: read timeout.\n"); /* read timeout */
1240
1241 return 1; /* return error */
1242 }
1243 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_TEMPERATUREH, (uint8_t *)buf, 2); /* read temperature */
1244 if (res != 0) /* check result */
1245 {
1246 handle->debug_print("ds3231: read temperature failed.\n"); /* read temperature failed */
1247
1248 return 1; /* return error */
1249 }
1250 *raw = (int16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set raw temperature */
1251 *s = (float)((int8_t)(buf[0])) + (float)(buf[1] >> 6) * 0.25f; /* set converted temperature */
1252
1253 return 0; /* success return 0 */
1254}
1255
1267uint8_t ds3231_get_status(ds3231_handle_t *handle, uint8_t *status)
1268{
1269 uint8_t res;
1270
1271 if (handle == NULL) /* check handle */
1272 {
1273 return 2; /* return error */
1274 }
1275 if (handle->inited != 1) /* check handle initialization */
1276 {
1277 return 3; /* return error */
1278 }
1279
1280 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)status, 1); /* multiple read */
1281 if (res != 0) /* check result */
1282 {
1283 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1284
1285 return 1; /* return error */
1286 }
1287
1288 return 0; /* success return 0 */
1289}
1290
1302uint8_t ds3231_set_aging_offset(ds3231_handle_t *handle, int8_t offset)
1303{
1304 uint8_t res;
1305
1306 if (handle == NULL) /* check handle */
1307 {
1308 return 2; /* return error */
1309 }
1310 if (handle->inited != 1) /* check handle initialization */
1311 {
1312 return 3; /* return error */
1313 }
1314
1315 res = a_ds3231_iic_write(handle, DS3231_REG_XTAL, offset); /* write offset */
1316 if (res != 0) /* check result */
1317 {
1318 handle->debug_print("ds3231: write offset failed.\n"); /* write offset failed */
1319
1320 return 1; /* return error */
1321 }
1322
1323 return 0; /* success return 0 */
1324}
1325
1337uint8_t ds3231_get_aging_offset(ds3231_handle_t *handle, int8_t *offset)
1338{
1339 uint8_t res;
1340
1341 if (handle == NULL) /* check handle */
1342 {
1343 return 2; /* return error */
1344 }
1345 if (handle->inited != 1) /* check handle initialization */
1346 {
1347 return 3; /* return error */
1348 }
1349
1350 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_XTAL, (uint8_t *)offset, 1); /* read offset */
1351 if (res != 0) /* check result */
1352 {
1353 handle->debug_print("ds3231: read offset failed.\n"); /* read offset failed */
1354
1355 return 1; /* return error */
1356 }
1357
1358 return 0; /* success return 0 */
1359}
1360
1372uint8_t ds3231_aging_offset_convert_to_register(ds3231_handle_t *handle, float offset, int8_t *reg)
1373{
1374 if (handle == NULL) /* check handle */
1375 {
1376 return 2; /* return error */
1377 }
1378 if (handle->inited != 1) /* check handle initialization */
1379 {
1380 return 3; /* return error */
1381 }
1382
1383 *reg = (int8_t)(offset / 0.12f); /* convert real data to register data */
1384
1385 return 0; /* success return 0 */
1386}
1387
1399uint8_t ds3231_aging_offset_convert_to_data(ds3231_handle_t *handle, int8_t reg, float *offset)
1400{
1401 if (handle == NULL) /* check handle */
1402 {
1403 return 2; /* return error */
1404 }
1405 if (handle->inited != 1) /* check handle initialization */
1406 {
1407 return 3; /* return error */
1408 }
1409
1410 *offset = (float)(reg) * 0.12f; /* convert raw data to real data */
1411
1412 return 0; /* success return 0 */
1413}
1414
1426{
1427 uint8_t res, prev;
1428
1429 if (handle == NULL) /* check handle */
1430 {
1431 return 2; /* return error */
1432 }
1433 if (handle->inited != 1) /* check handle initialization */
1434 {
1435 return 3; /* return error */
1436 }
1437
1438 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)&prev, 1); /* multiple read */
1439 if (res != 0) /* check result */
1440 {
1441 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1442
1443 return 1; /* return error */
1444 } /* if oscillator stop */
1445 if ((prev & DS3231_STATUS_ALARM_2) != 0) /* if alarm 2 */
1446 {
1447 if (handle->receive_callback != NULL) /* if receive callback */
1448 {
1449 handle->receive_callback(DS3231_STATUS_ALARM_2); /* run callback */
1450 }
1451 }
1452 if ((prev & DS3231_STATUS_ALARM_1) != 0) /* if alarm 1 */
1453 {
1454 if (handle->receive_callback != NULL) /* if receive callback */
1455 {
1456 handle->receive_callback(DS3231_STATUS_ALARM_1); /* run callback */
1457 }
1458 }
1459
1460 return 0; /* success return 0 */
1461}
1462
1474{
1475 uint8_t res;
1476 uint8_t prev;
1477
1478 if (handle == NULL) /* check handle */
1479 {
1480 return 2; /* return error */
1481 }
1482 if (handle->debug_print == NULL) /* check debug_print */
1483 {
1484 return 3; /* return error */
1485 }
1486 if (handle->iic_init == NULL) /* check iic_init */
1487 {
1488 handle->debug_print("ds3231: iic_init is null.\n"); /* iic_init is null */
1489
1490 return 3; /* return error */
1491 }
1492 if (handle->iic_deinit == NULL) /* check iic_deinit */
1493 {
1494 handle->debug_print("ds3231: iic_deinit is null.\n"); /* iic_deinit is null */
1495
1496 return 3; /* return error */
1497 }
1498 if (handle->iic_write == NULL) /* check iic_write */
1499 {
1500 handle->debug_print("ds3231: iic_write is null.\n"); /* iic_write is null */
1501
1502 return 3; /* return error */
1503 }
1504 if (handle->iic_read == NULL) /* check iic_read */
1505 {
1506 handle->debug_print("ds3231: iic_read is null.\n"); /* iic_read is null */
1507
1508 return 3; /* return error */
1509 }
1510 if (handle->delay_ms == NULL) /* check delay_ms */
1511 {
1512 handle->debug_print("ds3231: delay_ms is null.\n"); /* delay_ms is null */
1513
1514 return 3; /* return error */
1515 }
1516 if (handle->receive_callback == NULL) /* check receive_callback */
1517 {
1518 handle->debug_print("ds3231: receive_callback is null.\n"); /* receive_callback is null */
1519
1520 return 3; /* return error */
1521 }
1522
1523 if (handle->iic_init() != 0) /* iic init */
1524 {
1525 handle->debug_print("ds3231: iic init failed.\n"); /* iic init failed */
1526
1527 return 1; /* return error */
1528 }
1529 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)&prev, 1); /* multiple_read */
1530 if (res != 0) /* check result */
1531 {
1532 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1533 (void)handle->iic_deinit(); /* iic deinit */
1534
1535 return 1; /* return error */
1536 }
1537 prev &= ~(1 << 7); /* clear config */
1538 res = a_ds3231_iic_write(handle, DS3231_REG_STATUS, prev); /* write status */
1539 if (res != 0) /* check result */
1540 {
1541 handle->debug_print("ds3231: write status failed.\n"); /* write status failed */
1542 (void)handle->iic_deinit(); /* iic deinit */
1543
1544 return 1; /* return error */
1545 }
1546 handle->inited = 1; /* flag finish initialization */
1547
1548 return 0; /* success return 0 */
1549}
1550
1562{
1563 if (handle == NULL) /* check handle */
1564 {
1565 return 2; /* return error */
1566 }
1567 if (handle->inited != 1) /* check handle initialization */
1568 {
1569 return 3; /* return error */
1570 }
1571
1572 if (handle->iic_deinit() != 0) /* iic deinit */
1573 {
1574 handle->debug_print("ds3231: iic deinit failed.\n"); /* iic deinit failed */
1575
1576 return 1; /* return error */
1577 }
1578 handle->inited = 0; /* flag close */
1579
1580 return 0; /* success return 0 */
1581}
1582
1595{
1596 uint8_t res;
1597 uint8_t prev;
1598
1599 if (handle == NULL) /* check handle */
1600 {
1601 return 2; /* return error */
1602 }
1603 if (handle->inited != 1) /* check handle initialization */
1604 {
1605 return 3; /* return error */
1606 }
1607
1608 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)&prev, 1); /* multiple_read */
1609 if (res != 0) /* check result */
1610 {
1611 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1612
1613 return 1; /* return error */
1614 }
1615 prev &= ~(1 << alarm); /* clear config */
1616 res = a_ds3231_iic_write(handle, DS3231_REG_STATUS, prev); /* write status */
1617 if (res != 0) /* check result */
1618 {
1619 handle->debug_print("ds3231: write status failed.\n"); /* write status failed */
1620
1621 return 1; /* return error */
1622 }
1623
1624 return 0; /* success return 0 */
1625}
1626
1639{
1640 uint8_t res;
1641 uint8_t prev;
1642
1643 if (handle == NULL) /* check handle */
1644 {
1645 return 2; /* return error */
1646 }
1647 if (handle->inited != 1) /* check handle initialization */
1648 {
1649 return 3; /* return error */
1650 }
1651
1652 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)&prev, 1); /* multiple read */
1653 if (res != 0) /* check result */
1654 {
1655 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1656
1657 return 1; /* return error */
1658 }
1659 prev &= ~(1 << 3); /* clear config */
1660 prev |= enable << 3; /* set enable */
1661 res = a_ds3231_iic_write(handle, DS3231_REG_STATUS, prev); /* write status */
1662 if (res != 0) /* check result */
1663 {
1664 handle->debug_print("ds3231: write status failed.\n"); /* write status failed */
1665
1666 return 1; /* return error */
1667 }
1668
1669 return 0; /* success return 0 */
1670}
1671
1684{
1685 uint8_t res;
1686 uint8_t prev;
1687
1688 if (handle == NULL) /* check handle */
1689 {
1690 return 2; /* return error */
1691 }
1692 if (handle->inited != 1) /* check handle initialization */
1693 {
1694 return 3; /* return error */
1695 }
1696
1697 res = a_ds3231_iic_multiple_read(handle, DS3231_REG_STATUS, (uint8_t *)&prev, 1); /* multiple read */
1698 if (res != 0) /* check result */
1699 {
1700 handle->debug_print("ds3231: read status failed.\n"); /* read status failed */
1701
1702 return 1; /* return error */
1703 }
1704 *enable = (ds3231_bool_t)((prev >> 3) & 0x01); /* get enable */
1705
1706 return 0; /* success return 0 */
1707}
1708
1722uint8_t ds3231_set_reg(ds3231_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1723{
1724 if (handle == NULL) /* check handle */
1725 {
1726 return 2; /* return error */
1727 }
1728 if (handle->inited != 1) /* check handle initialization */
1729 {
1730 return 3; /* return error */
1731 }
1732
1733 if (handle->iic_write(DS3231_ADDRESS, reg, buf, len) != 0) /* write data */
1734 {
1735 return 1; /* return error */
1736 }
1737 else
1738 {
1739 return 0; /* success return 0 */
1740 }
1741}
1742
1756uint8_t ds3231_get_reg(ds3231_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1757{
1758 if (handle == NULL) /* check handle */
1759 {
1760 return 2; /* return error */
1761 }
1762 if (handle->inited != 1) /* check handle initialization */
1763 {
1764 return 3; /* return error */
1765 }
1766
1767 if (handle->iic_read(DS3231_ADDRESS, reg, buf, len) != 0) /* read data */
1768 {
1769 return 1; /* return error */
1770 }
1771 else
1772 {
1773 return 0; /* success return 0 */
1774 }
1775}
1776
1786{
1787 if (info == NULL) /* check handle */
1788 {
1789 return 2; /* return error */
1790 }
1791
1792 memset(info, 0, sizeof(ds3231_info_t)); /* initialize ds3231 info structure */
1793 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1794 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1795 strncpy(info->interface, "IIC", 8); /* copy interface name */
1796 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1797 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1798 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1799 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1800 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1801 info->driver_version = DRIVER_VERSION; /* set driver version */
1802
1803 return 0; /* success return 0 */
1804}
#define DS3231_REG_MINUTE
#define DS3231_REG_YEAR
#define DS3231_REG_CONTROL
#define MAX_CURRENT
#define DS3231_REG_DATE
#define DS3231_REG_ALARM2_MINUTE
#define DS3231_REG_XTAL
#define DS3231_REG_ALARM2_WEEK
#define SUPPLY_VOLTAGE_MAX
#define DS3231_REG_HOUR
#define DS3231_ADDRESS
chip address definition
#define DS3231_REG_ALARM1_MINUTE
#define DS3231_REG_ALARM2_HOUR
#define TEMPERATURE_MAX
#define DS3231_REG_SECOND
chip register definition
#define MANUFACTURER_NAME
#define DS3231_REG_MONTH
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define DS3231_REG_ALARM1_HOUR
#define DS3231_REG_ALARM1_SECOND
#define DS3231_REG_TEMPERATUREH
#define DS3231_REG_ALARM1_WEEK
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define DS3231_REG_STATUS
#define DS3231_REG_WEEK
driver ds3231 header file
uint8_t ds3231_get_32khz_output(ds3231_handle_t *handle, ds3231_bool_t *enable)
get the 32KHz output status
uint8_t ds3231_get_pin(ds3231_handle_t *handle, ds3231_pin_t *pin)
get the chip pin function
uint8_t ds3231_set_aging_offset(ds3231_handle_t *handle, int8_t offset)
set the chip aging offset
uint8_t ds3231_get_temperature(ds3231_handle_t *handle, int16_t *raw, float *s)
get the chip temperature
uint8_t ds3231_set_pin(ds3231_handle_t *handle, ds3231_pin_t pin)
set the chip pin function
uint8_t ds3231_aging_offset_convert_to_data(ds3231_handle_t *handle, int8_t reg, float *offset)
convert a register raw data to a converted aging offset data
uint8_t ds3231_get_aging_offset(ds3231_handle_t *handle, int8_t *offset)
get the chip aging offset
uint8_t ds3231_aging_offset_convert_to_register(ds3231_handle_t *handle, float offset, int8_t *reg)
convert a aging offset value to a register raw data
uint8_t ds3231_set_32khz_output(ds3231_handle_t *handle, ds3231_bool_t enable)
enable or disable the 32KHz output
uint8_t ds3231_set_square_wave(ds3231_handle_t *handle, ds3231_bool_t enable)
enable or disable the square wave output
uint8_t ds3231_get_square_wave(ds3231_handle_t *handle, ds3231_bool_t *enable)
get the square wave output status
uint8_t ds3231_get_alarm_interrupt(ds3231_handle_t *handle, ds3231_alarm_t alarm, ds3231_bool_t *enable)
get the alarm interrupt status
uint8_t ds3231_set_alarm_interrupt(ds3231_handle_t *handle, ds3231_alarm_t alarm, ds3231_bool_t enable)
enable or disable the alarm interrupt
ds3231_alarm2_mode_t
ds3231 alarm2 enumeration definition
uint8_t ds3231_get_alarm1(ds3231_handle_t *handle, ds3231_time_t *t, ds3231_alarm1_mode_t *mode)
get the alarm1 time
ds3231_alarm1_mode_t
ds3231 alarm1 enumeration definition
uint8_t ds3231_set_alarm2(ds3231_handle_t *handle, ds3231_time_t *t, ds3231_alarm2_mode_t mode)
set the alarm2 time
uint8_t ds3231_alarm_clear(ds3231_handle_t *handle, ds3231_alarm_t alarm)
clear the alarm flag
uint8_t ds3231_set_alarm1(ds3231_handle_t *handle, ds3231_time_t *t, ds3231_alarm1_mode_t mode)
set the alarm1 time
uint8_t ds3231_get_alarm2(ds3231_handle_t *handle, ds3231_time_t *t, ds3231_alarm2_mode_t *mode)
get the alarm2 time
@ DS3231_ALARM2_MODE_WEEK_HOUR_MINUTE_MATCH
@ DS3231_ALARM1_MODE_WEEK_HOUR_MINUTE_SECOND_MATCH
ds3231_am_pm_t
ds3231 am pm enumeration definition
uint8_t ds3231_set_oscillator(ds3231_handle_t *handle, ds3231_bool_t enable)
enable or disable the oscillator
uint8_t ds3231_set_time(ds3231_handle_t *handle, ds3231_time_t *t)
set the current time
uint8_t ds3231_get_oscillator(ds3231_handle_t *handle, ds3231_bool_t *enable)
get the chip oscillator status
struct ds3231_time_s ds3231_time_t
ds3231 time structure definition
ds3231_alarm_t
ds3231 alarm enumeration definition
ds3231_format_t
ds3231 format enumeration definition
ds3231_pin_t
ds3231 pin enumeration definition
uint8_t ds3231_info(ds3231_info_t *info)
get chip's information
uint8_t ds3231_irq_handler(ds3231_handle_t *handle)
irq handler
struct ds3231_handle_s ds3231_handle_t
ds3231 handle structure definition
uint8_t ds3231_init(ds3231_handle_t *handle)
initialize the chip
struct ds3231_info_s ds3231_info_t
ds3231 information structure definition
uint8_t ds3231_get_time(ds3231_handle_t *handle, ds3231_time_t *t)
get the current time
uint8_t ds3231_deinit(ds3231_handle_t *handle)
close the chip
ds3231_bool_t
ds3231 bool enumeration definition
uint8_t ds3231_get_status(ds3231_handle_t *handle, uint8_t *status)
get the chip status
@ DS3231_FORMAT_24H
@ DS3231_FORMAT_12H
@ DS3231_STATUS_ALARM_1
@ DS3231_STATUS_ALARM_2
uint8_t ds3231_set_reg(ds3231_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t ds3231_get_reg(ds3231_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]
ds3231_am_pm_t am_pm
ds3231_format_t format