LibDriver DS1307
Loading...
Searching...
No Matches
driver_ds1307.c
Go to the documentation of this file.
1
36
37#include "driver_ds1307.h"
38
42#define CHIP_NAME "Maxim Integrated DS1307"
43#define MANUFACTURER_NAME "Maxim Integrated"
44#define SUPPLY_VOLTAGE_MIN 4.5f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 1.50f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define DS1307_REG_SECOND 0x00
55#define DS1307_REG_MINUTE 0x01
56#define DS1307_REG_HOUR 0x02
57#define DS1307_REG_WEEK 0x03
58#define DS1307_REG_DATE 0x04
59#define DS1307_REG_MONTH 0x05
60#define DS1307_REG_YEAR 0x06
61#define DS1307_REG_CONTROL 0x07
62#define DS1307_REG_RAM 0x08
63
67#define DS1307_ADDRESS 0xD0
68
79static uint8_t a_ds1307_iic_write(ds1307_handle_t *handle, uint8_t reg, uint8_t data)
80{
81 if (handle->iic_write(DS1307_ADDRESS, reg, &data, 1) != 0) /* write data */
82 {
83 return 1; /* return error */
84 }
85 else
86 {
87 return 0; /* success return 0 */
88 }
89}
90
102static uint8_t a_ds1307_iic_multiple_write(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint8_t len)
103{
104 if (handle->iic_write(DS1307_ADDRESS, reg, buf, len) != 0) /* write data */
105 {
106 return 1; /* return error */
107 }
108 else
109 { /* success return 0 */
110 return 0;
111 }
112}
113
125static uint8_t a_ds1307_iic_multiple_read(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint8_t len)
126{
127 if (handle->iic_read(DS1307_ADDRESS, reg, buf, len) != 0) /* read data */
128 {
129 return 1; /* return error */
130 }
131 else
132 { /* success return 0 */
133 return 0;
134 }
135}
136
143static uint8_t a_ds1307_hex2bcd(uint8_t val)
144{
145 uint8_t i, j, k;
146
147 i = val / 10; /* get tens place */
148 j = val % 10; /* get ones place */
149 k = j + (i << 4); /* set bcd */
150
151 return k; /* return bcd */
152}
153
160static uint8_t a_ds1307_bcd2hex(uint8_t val)
161{
162 uint8_t temp;
163
164 temp = val & 0x0F; /* get ones place */
165 val = (val >> 4) & 0x0F; /* get tens place */
166 val = val * 10; /* set tens place */
167 temp = temp + val; /* get hex */
168
169 return temp; /* return hex */
170}
171
185{
186 uint8_t res;
187 uint8_t reg;
188 uint16_t year;
189
190 if (handle == NULL) /* check handle */
191 {
192 return 2; /* return error */
193 }
194 if (handle->inited != 1) /* check handle initialization */
195 {
196 return 3; /* return error */
197 }
198 if (t == NULL) /* check time */
199 {
200 handle->debug_print("ds1307: time is null.\n"); /* time is null */
201
202 return 2; /* return error */
203 }
204 if (t->format == DS1307_FORMAT_12H) /* if 12H */
205 {
206 if ((t->year < 2000) || (t->year > 2100)) /* check year */
207 {
208 handle->debug_print("ds1307: year can't be over 2100 or less than 2000.\n"); /* year can't be over 2100 or less than 2000 */
209
210 return 4; /* return error */
211 }
212 if ((t->month == 0) || (t->month > 12)) /* check month */
213 {
214 handle->debug_print("ds1307: month can't be zero or over than 12.\n"); /* month can't be zero or over than 12 */
215
216 return 4; /* return error */
217 }
218 if ((t->week == 0) || (t->week > 7)) /* check week */
219 {
220 handle->debug_print("ds1307: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
221
222 return 4; /* return error */
223 }
224 if ((t->date == 0) || (t->date > 31)) /* check data */
225 {
226 handle->debug_print("ds1307: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
227
228 return 4; /* return error */
229 }
230 if ((t->hour < 1) || (t->hour > 12)) /* check hour */
231 {
232 handle->debug_print("ds1307: hour can't be over than 12 or less 1.\n"); /* hour can't be over than 12 or less 1 */
233
234 return 4; /* return error */
235 }
236 if (t->minute > 59) /* check minute */
237 {
238 handle->debug_print("ds1307: minute can't be over than 59.\n"); /* minute can't be over than 59 */
239
240 return 4; /* return error */
241 }
242 if (t->second > 59) /* check second */
243 {
244 handle->debug_print("ds1307: second can't be over than 59.\n"); /* second can't be over than 59 */
245
246 return 4; /* return error */
247 }
248 }
249 else if (t->format == DS1307_FORMAT_24H) /* if 24H */
250 {
251 if ((t->year < 2000) || (t->year > 2100)) /* check year */
252 {
253 handle->debug_print("ds1307: year can't be over 2100 or less than 2000.\n"); /* year can't be over 2100 or less than 2000 */
254
255 return 4; /* return error */
256 }
257 if ((t->month == 0) || (t->month > 12)) /* check month */
258 {
259 handle->debug_print("ds1307: month can't be zero or over than 12.\n"); /* month can't be zero or over than 12 */
260
261 return 4; /* return error */
262 }
263 if ((t->week == 0) || (t->week > 7)) /* check week */
264 {
265 handle->debug_print("ds1307: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
266
267 return 4; /* return error */
268 }
269 if ((t->date == 0) || (t->date > 31)) /* check data */
270 {
271 handle->debug_print("ds1307: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
272
273 return 4; /* return error */
274 }
275 if (t->hour > 23) /* check hour */
276 {
277 handle->debug_print("ds1307: hour can't be over than 23.\n"); /* hour can't be over than 23 */
278
279 return 4; /* return error */
280 }
281 if (t->minute > 59) /* check minute */
282 {
283 handle->debug_print("ds1307: minute can't be over than 59.\n"); /* minute can't be over than 59 */
284
285 return 4; /* return error */
286 }
287 if (t->second > 59) /* check second */
288 {
289 handle->debug_print("ds1307: second can't be over than 59.\n"); /* second can't be over than 59 */
290
291 return 4; /* return error */
292 }
293 }
294 else
295 {
296 handle->debug_print("ds1307: format is invalid.\n"); /* format is invalid */
297
298 return 4; /* return error */
299 }
300
301 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_SECOND, &reg, 1); /* read second */
302 if (res != 0) /* check result */
303 {
304 handle->debug_print("ds1307: read second failed.\n"); /* read second failed */
305
306 return 1; /* return error */
307 }
308 res = a_ds1307_iic_write(handle, DS1307_REG_SECOND, a_ds1307_hex2bcd(t->second) | (reg & (1 << 7))); /* write second */
309 if (res != 0) /* check result */
310 {
311 handle->debug_print("ds1307: write second failed.\n"); /* write second failed */
312
313 return 1; /* return error */
314 }
315 res = a_ds1307_iic_write(handle, DS1307_REG_MINUTE, a_ds1307_hex2bcd(t->minute)); /* write minute */
316 if (res != 0) /* check result */
317 {
318 handle->debug_print("ds1307: write minute failed.\n"); /* write minute failed */
319
320 return 1; /* return error */
321 }
322 if (t->format == DS1307_FORMAT_12H) /* if 12H */
323 {
324 reg = (uint8_t)((1 << 6) | (t->am_pm << 5) | a_ds1307_hex2bcd(t->hour)); /* set hour in 12H */
325 }
326 else /* if 24H */
327 {
328 reg = (0 << 6) | a_ds1307_hex2bcd(t->hour); /* set hour in 24H */
329 }
330 res = a_ds1307_iic_write(handle, DS1307_REG_HOUR, reg); /* write hour */
331 if (res != 0) /* check result */
332 {
333 handle->debug_print("ds1307: write hour failed.\n"); /* write hour failed */
334
335 return 1; /* return error */
336 }
337 res = a_ds1307_iic_write(handle, DS1307_REG_WEEK, a_ds1307_hex2bcd(t->week)); /* write week */
338 if (res != 0) /* check result */
339 {
340 handle->debug_print("ds1307: write week failed.\n"); /* write week failed */
341
342 return 1; /* return error */
343 }
344 res = a_ds1307_iic_write(handle, DS1307_REG_DATE, a_ds1307_hex2bcd(t->date)); /* write data */
345 if (res != 0) /* check result */
346 {
347 handle->debug_print("ds1307: write date failed.\n"); /* write date failed */
348
349 return 1; /* return error */
350 }
351 res = a_ds1307_iic_write(handle, DS1307_REG_MONTH, a_ds1307_hex2bcd(t->month)); /* write month and century */
352 if (res != 0) /* check result */
353 {
354 handle->debug_print("ds1307: write century and month failed.\n"); /* write century and month failed */
355
356 return 1; /* return error */
357 }
358 year = t->year - 2000; /* year - 2000 */
359 res = a_ds1307_iic_write(handle, DS1307_REG_YEAR, a_ds1307_hex2bcd((uint8_t)year)); /* write year */
360 if (res != 0) /* check result */
361 {
362 handle->debug_print("ds1307: write year failed.\n"); /* write year failed */
363
364 return 1; /* return error */
365 }
366
367 return 0; /* success return 0 */
368}
369
382{
383 uint8_t res;
384 uint8_t buf[7];
385
386 if (handle == NULL) /* check handle */
387 {
388 return 2; /* return error */
389 }
390 if (handle->inited != 1) /* check handle initialization */
391 {
392 return 3; /* return error */
393 }
394 if (t == NULL) /* check time */
395 {
396 handle->debug_print("ds1307: time is null.\n"); /* time is null */
397
398 return 2; /* return error */
399 }
400
401 memset(buf, 0, sizeof(uint8_t) * 7); /* clear the buffer */
402 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_SECOND, (uint8_t *)buf, 7); /* multiple_read */
403 if (res != 0) /* check result */
404 {
405 handle->debug_print("ds1307: multiple read failed.\n"); /* multiple read failed */
406
407 return 1; /* return error */
408 }
409 t->year = a_ds1307_bcd2hex(buf[6]) + 2000; /* get year */
410 t->month = a_ds1307_bcd2hex(buf[5] & 0x1F); /* get month */
411 t->week = a_ds1307_bcd2hex(buf[3] & 0x7); /* get week */
412 t->date = a_ds1307_bcd2hex(buf[4] & 0x3F); /* get date */
413 t->am_pm = (ds1307_am_pm_t)((buf[2] >> 5) & 0x01); /* get am pm */
414 t->format = (ds1307_format_t)((buf[2] >> 6) & 0x01); /* get format */
415 if (t->format == DS1307_FORMAT_12H) /* if 12H */
416 {
417 t->hour = a_ds1307_bcd2hex(buf[2] & 0x1F); /* get hour */
418 }
419 else
420 {
421 t->hour = a_ds1307_bcd2hex(buf[2] & 0x3F); /* get hour */
422 }
423 t->minute = a_ds1307_bcd2hex(buf[1]); /* get minute */
424 t->second = a_ds1307_bcd2hex(buf[0] & (~(1 << 7))); /* get second */
425
426 return 0; /* success return 0 */
427}
428
441{
442 uint8_t res;
443 uint8_t prev;
444
445 if (handle == NULL) /* check handle */
446 {
447 return 2; /* return error */
448 }
449 if (handle->inited != 1) /* check handle initialization */
450 {
451 return 3; /* return error */
452 }
453
454 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_SECOND, &prev, 1); /* read second */
455 if (res != 0) /* check result */
456 {
457 handle->debug_print("ds1307: read second failed.\n"); /* read second failed */
458
459 return 1; /* return error */
460 }
461 prev &= ~(1 << 7); /* clear config */
462 prev |= (!enable) << 7; /* set enable */
463 res = a_ds1307_iic_write(handle, DS1307_REG_SECOND, prev); /* write second */
464 if (res != 0) /* check result */
465 {
466 handle->debug_print("ds1307: write second failed.\n"); /* write second failed */
467
468 return 1; /* return error */
469 }
470
471 return 0; /* success return 0 */
472}
473
486{
487 uint8_t res;
488 uint8_t prev;
489
490 if (handle == NULL) /* check handle */
491 {
492 return 2; /* return error */
493 }
494 if (handle->inited != 1) /* check handle initialization */
495 {
496 return 3; /* return error */
497 }
498
499 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_SECOND, (uint8_t *)&prev, 1); /* multiple read */
500 if (res != 0) /* check result */
501 {
502 handle->debug_print("ds1307: read second failed.\n"); /* read second failed */
503
504 return 1; /* return error */
505 }
506 *enable = (ds1307_bool_t)(!((prev >> 7) & 0x01)); /* get enable */
507
508 return 0; /* success return 0 */
509}
510
523{
524 uint8_t res;
525 uint8_t prev;
526
527 if (handle == NULL) /* check handle */
528 {
529 return 2; /* return error */
530 }
531 if (handle->inited != 1) /* check handle initialization */
532 {
533 return 3; /* return error */
534 }
535
536 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_CONTROL, &prev, 1); /* read control */
537 if (res != 0) /* check result */
538 {
539 handle->debug_print("ds1307: read control failed.\n"); /* read control failed */
540
541 return 1; /* return error */
542 }
543 prev &= ~(1 << 7); /* clear config */
544 prev |= level << 7; /* set setting */
545 res = a_ds1307_iic_write(handle, DS1307_REG_CONTROL, prev); /* write control */
546 if (res != 0) /* check result */
547 {
548 handle->debug_print("ds1307: write control failed.\n"); /* write control failed */
549
550 return 1; /* return error */
551 }
552
553 return 0; /* success return 0 */
554}
555
568{
569 uint8_t res;
570 uint8_t prev;
571
572 if (handle == NULL) /* check handle */
573 {
574 return 2; /* return error */
575 }
576 if (handle->inited != 1) /* check handle initialization */
577 {
578 return 3; /* return error */
579 }
580
581 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_CONTROL, &prev, 1); /* read control */
582 if (res != 0) /* check result */
583 {
584 handle->debug_print("ds1307: read control failed.\n"); /* read control failed */
585
586 return 1; /* return error */
587 }
588 *level = (ds1307_output_level_t)((prev >> 7) & 0x01); /* set level */
589
590 return 0; /* success return 0 */
591}
592
605{
606 uint8_t res;
607 uint8_t prev;
608
609 if (handle == NULL) /* check handle */
610 {
611 return 2; /* return error */
612 }
613 if (handle->inited != 1) /* check handle initialization */
614 {
615 return 3; /* return error */
616 }
617
618 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_CONTROL, &prev, 1); /* read control */
619 if (res != 0) /* check result */
620 {
621 handle->debug_print("ds1307: read control failed.\n"); /* read control failed */
622
623 return 1; /* return error */
624 }
625 prev &= ~(1 << 4); /* clear config */
626 prev |= mode << 4; /* set setting */
627 res = a_ds1307_iic_write(handle, DS1307_REG_CONTROL, prev); /* write control */
628 if (res != 0) /* check result */
629 {
630 handle->debug_print("ds1307: write control failed.\n"); /* write control failed */
631
632 return 1; /* return error */
633 }
634
635 return 0; /* success return 0 */
636}
637
650{
651 uint8_t res;
652 uint8_t prev;
653
654 if (handle == NULL) /* check handle */
655 {
656 return 2; /* return error */
657 }
658 if (handle->inited != 1) /* check handle initialization */
659 {
660 return 3; /* return error */
661 }
662
663 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_CONTROL, &prev, 1); /* read control */
664 if (res != 0) /* check result */
665 {
666 handle->debug_print("ds1307: read control failed.\n"); /* read control failed */
667
668 return 1; /* return error */
669 }
670 *mode = (ds1307_output_mode_t)((prev >> 4) & 0x01); /* set mode */
671
672 return 0; /* success return 0 */
673}
674
687{
688 uint8_t res;
689 uint8_t prev;
690
691 if (handle == NULL) /* check handle */
692 {
693 return 2; /* return error */
694 }
695 if (handle->inited != 1) /* check handle initialization */
696 {
697 return 3; /* return error */
698 }
699
700 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_CONTROL, &prev, 1); /* read control */
701 if (res != 0) /* check result */
702 {
703 handle->debug_print("ds1307: read control failed.\n"); /* read control failed */
704
705 return 1; /* return error */
706 }
707 prev &= ~(3 << 0); /* clear config */
708 prev |= freq << 0; /* set setting */
709 res = a_ds1307_iic_write(handle, DS1307_REG_CONTROL, prev); /* write control */
710 if (res != 0) /* check result */
711 {
712 handle->debug_print("ds1307: write control failed.\n"); /* write control failed */
713
714 return 1; /* return error */
715 }
716
717 return 0; /* success return 0 */
718}
719
732{
733 uint8_t res;
734 uint8_t prev;
735
736 if (handle == NULL) /* check handle */
737 {
738 return 2; /* return error */
739 }
740 if (handle->inited != 1) /* check handle initialization */
741 {
742 return 3; /* return error */
743 }
744
745 res = a_ds1307_iic_multiple_read(handle, DS1307_REG_CONTROL, &prev, 1); /* read control */
746 if (res != 0) /* check result */
747 {
748 handle->debug_print("ds1307: read control failed.\n"); /* read control failed */
749
750 return 1; /* return error */
751 }
752 *freq = (ds1307_square_wave_frequency_t)(prev & 0x3); /* set freq */
753
754 return 0; /* success return 0 */
755}
756
772uint8_t ds1307_read_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
773{
774 uint8_t res;
775
776 if (handle == NULL) /* check handle */
777 {
778 return 2; /* return error */
779 }
780 if (handle->inited != 1) /* check handle initialization */
781 {
782 return 3; /* return error */
783 }
784 if (addr > 55) /* check addr */
785 {
786 handle->debug_print("ds1307: addr > 55.\n"); /* addr > 55 */
787
788 return 4; /* return error */
789 }
790 if (addr + len - 1 > 55) /* check len */
791 {
792 handle->debug_print("ds1307: len is invalid.\n"); /* len is invalid */
793
794 return 5; /* return error */
795 }
796
797 res = a_ds1307_iic_multiple_read(handle, (uint8_t)(DS1307_REG_RAM + addr),
798 buf, len); /* read ram */
799 if (res != 0) /* check result */
800 {
801 handle->debug_print("ds1307: read ram failed.\n"); /* read ram failed */
802
803 return 1; /* return error */
804 }
805
806 return 0; /* success return 0 */
807}
808
824uint8_t ds1307_write_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
825{
826 uint8_t res;
827
828 if (handle == NULL) /* check handle */
829 {
830 return 2; /* return error */
831 }
832 if (handle->inited != 1) /* check handle initialization */
833 {
834 return 3; /* return error */
835 }
836 if (addr > 55) /* check addr */
837 {
838 handle->debug_print("ds1307: addr > 55.\n"); /* addr > 55 */
839
840 return 4; /* return error */
841 }
842 if (addr + len - 1 > 55) /* check len */
843 {
844 handle->debug_print("ds1307: len is invalid.\n"); /* len is invalid */
845
846 return 5; /* return error */
847 }
848
849 res = a_ds1307_iic_multiple_write(handle, (uint8_t)(DS1307_REG_RAM + addr),
850 buf, len); /* write ram */
851 if (res != 0) /* check result */
852 {
853 handle->debug_print("ds1307: write ram failed.\n"); /* write ram failed */
854
855 return 1; /* return error */
856 }
857
858 return 0; /* success return 0 */
859}
860
872{
873 if (handle == NULL) /* check handle */
874 {
875 return 2; /* return error */
876 }
877 if (handle->debug_print == NULL) /* check debug_print */
878 {
879 return 3; /* return error */
880 }
881 if (handle->iic_init == NULL) /* check iic_init */
882 {
883 handle->debug_print("ds1307: iic_init is null.\n"); /* iic_init is null */
884
885 return 3; /* return error */
886 }
887 if (handle->iic_deinit == NULL) /* check iic_deinit */
888 {
889 handle->debug_print("ds1307: iic_deinit is null.\n"); /* iic_deinit is null */
890
891 return 3; /* return error */
892 }
893 if (handle->iic_write == NULL) /* check iic_write */
894 {
895 handle->debug_print("ds1307: iic_write is null.\n"); /* iic_write is null */
896
897 return 3; /* return error */
898 }
899 if (handle->iic_read == NULL) /* check iic_read */
900 {
901 handle->debug_print("ds1307: iic_read is null.\n"); /* iic_read is null */
902
903 return 3; /* return error */
904 }
905 if (handle->delay_ms == NULL) /* check delay_ms */
906 {
907 handle->debug_print("ds1307: delay_ms is null.\n"); /* delay_ms is null */
908
909 return 3; /* return error */
910 }
911
912 if (handle->iic_init() != 0) /* iic init */
913 {
914 handle->debug_print("ds1307: iic init failed.\n"); /* iic init failed */
915
916 return 1; /* return error */
917 }
918 handle->inited = 1; /* flag finish initialization */
919
920 return 0; /* success return 0 */
921}
922
934{
935 if (handle == NULL) /* check handle */
936 {
937 return 2; /* return error */
938 }
939 if (handle->inited != 1) /* check handle initialization */
940 {
941 return 3; /* return error */
942 }
943
944 if (handle->iic_deinit() != 0) /* iic deinit */
945 {
946 handle->debug_print("ds1307: iic deinit failed.\n"); /* iic deinit failed */
947
948 return 1; /* return error */
949 }
950 handle->inited = 0; /* flag close */
951
952 return 0; /* success return 0 */
953}
954
968uint8_t ds1307_set_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
969{
970 if (handle == NULL) /* check handle */
971 {
972 return 2; /* return error */
973 }
974 if (handle->inited != 1) /* check handle initialization */
975 {
976 return 3; /* return error */
977 }
978
979 if (handle->iic_write(DS1307_ADDRESS, reg, buf, len) != 0) /* write data */
980 {
981 return 1; /* return error */
982 }
983 else
984 {
985 return 0; /* success return 0 */
986 }
987}
988
1002uint8_t ds1307_get_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1003{
1004 if (handle == NULL) /* check handle */
1005 {
1006 return 2; /* return error */
1007 }
1008 if (handle->inited != 1) /* check handle initialization */
1009 {
1010 return 3; /* return error */
1011 }
1012
1013 if (handle->iic_read(DS1307_ADDRESS, reg, buf, len) != 0) /* read data */
1014 {
1015 return 1; /* return error */
1016 }
1017 else
1018 {
1019 return 0; /* success return 0 */
1020 }
1021}
1022
1032{
1033 if (info == NULL) /* check handle */
1034 {
1035 return 2; /* return error */
1036 }
1037
1038 memset(info, 0, sizeof(ds1307_info_t)); /* initialize ds1307 info structure */
1039 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1040 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1041 strncpy(info->interface, "IIC", 8); /* copy interface name */
1042 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1043 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1044 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1045 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1046 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1047 info->driver_version = DRIVER_VERSION; /* set driver version */
1048
1049 return 0; /* success return 0 */
1050}
#define DS1307_REG_HOUR
#define MAX_CURRENT
#define DS1307_REG_WEEK
#define DS1307_REG_YEAR
#define DS1307_REG_MONTH
#define DS1307_ADDRESS
chip address definition
#define SUPPLY_VOLTAGE_MAX
#define DS1307_REG_RAM
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define DS1307_REG_CONTROL
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define DS1307_REG_MINUTE
#define DS1307_REG_DATE
#define DS1307_REG_SECOND
chip register definition
driver ds1307 header file
uint8_t ds1307_info(ds1307_info_t *info)
get chip's information
ds1307_am_pm_t
ds1307 am pm enumeration definition
struct ds1307_info_s ds1307_info_t
ds1307 information structure definition
uint8_t ds1307_get_output_level(ds1307_handle_t *handle, ds1307_output_level_t *level)
get the output level
struct ds1307_handle_s ds1307_handle_t
ds1307 handle structure definition
ds1307_square_wave_frequency_t
ds1307 square wave frequency enumeration definition
uint8_t ds1307_get_square_wave_frequency(ds1307_handle_t *handle, ds1307_square_wave_frequency_t *freq)
get the square wave frequency
ds1307_format_t
ds1307 format enumeration definition
uint8_t ds1307_read_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
read ram
uint8_t ds1307_get_oscillator(ds1307_handle_t *handle, ds1307_bool_t *enable)
get the chip oscillator status
uint8_t ds1307_set_output_mode(ds1307_handle_t *handle, ds1307_output_mode_t mode)
set the output mode
struct ds1307_time_s ds1307_time_t
ds1307 time structure definition
uint8_t ds1307_get_output_mode(ds1307_handle_t *handle, ds1307_output_mode_t *mode)
get the output mode
uint8_t ds1307_set_oscillator(ds1307_handle_t *handle, ds1307_bool_t enable)
enable or disable the oscillator
uint8_t ds1307_init(ds1307_handle_t *handle)
initialize the chip
uint8_t ds1307_set_time(ds1307_handle_t *handle, ds1307_time_t *t)
set the current time
ds1307_output_level_t
ds1307 output level enumeration definition
uint8_t ds1307_write_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
write ram
uint8_t ds1307_set_output_level(ds1307_handle_t *handle, ds1307_output_level_t level)
set the output level
uint8_t ds1307_set_square_wave_frequency(ds1307_handle_t *handle, ds1307_square_wave_frequency_t freq)
set the square wave frequency
ds1307_bool_t
ds1307 bool enumeration definition
uint8_t ds1307_deinit(ds1307_handle_t *handle)
close the chip
uint8_t ds1307_get_time(ds1307_handle_t *handle, ds1307_time_t *t)
get the current time
ds1307_output_mode_t
ds1307 output mode enumeration definition
@ DS1307_FORMAT_12H
@ DS1307_FORMAT_24H
uint8_t ds1307_get_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t ds1307_set_reg(ds1307_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
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]
ds1307_am_pm_t am_pm
ds1307_format_t format