LibDriver RX8025T
Loading...
Searching...
No Matches
driver_rx8025t.c
Go to the documentation of this file.
1
36
37#include "driver_rx8025t.h"
38
42#define CHIP_NAME "EPSON RX8025T"
43#define MANUFACTURER_NAME "EPSON"
44#define SUPPLY_VOLTAGE_MIN 1.6f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.90f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define RX8025T_REG_SEC 0x00
55#define RX8025T_REG_MIN 0x01
56#define RX8025T_REG_HOUR 0x02
57#define RX8025T_REG_WEEK 0x03
58#define RX8025T_REG_DAY 0x04
59#define RX8025T_REG_MONTH 0x05
60#define RX8025T_REG_YEAR 0x06
61#define RX8025T_REG_RAM 0x07
62#define RX8025T_REG_MIN_ALARM 0x08
63#define RX8025T_REG_HOUR_ALARM 0x09
64#define RX8025T_REG_WEEK_DAY_ALARM 0x0A
65#define RX8025T_REG_TIMER_COUNTER_0 0x0B
66#define RX8025T_REG_TIMER_COUNTER_1 0x0C
67#define RX8025T_REG_EXTENSION 0x0D
68#define RX8025T_REG_FLAG 0x0E
69#define RX8025T_REG_CONTROL 0x0F
70
74#define RX8025T_ADDRESS 0x64
75
86static uint8_t a_rx8025t_iic_write(rx8025t_handle_t *handle, uint8_t reg, uint8_t data)
87{
88 if (handle->iic_write(RX8025T_ADDRESS, reg, &data, 1) != 0) /* write data */
89 {
90 return 1; /* return error */
91 }
92
93 return 0; /* success return 0 */
94}
95
107static uint8_t a_rx8025t_iic_multiple_write(rx8025t_handle_t *handle, uint8_t reg, uint8_t *buf, uint8_t len)
108{
109 if (handle->iic_write(RX8025T_ADDRESS, reg, buf, len) != 0) /* write data */
110 {
111 return 1; /* return error */
112 }
113
114 return 0; /* success return 0 */
115}
116
128static uint8_t a_rx8025t_iic_multiple_read(rx8025t_handle_t *handle, uint8_t reg, uint8_t *buf, uint8_t len)
129{
130 if (handle->iic_read(RX8025T_ADDRESS, reg, buf, len) != 0) /* read data */
131 {
132 return 1; /* return error */
133 }
134
135 return 0; /* success return 0 */
136}
137
144static uint8_t a_rx8025t_hex2bcd(uint8_t val)
145{
146 uint8_t i, j, k;
147
148 i = val / 10; /* get tens place */
149 j = val % 10; /* get ones place */
150 k = j + (i << 4); /* set bcd */
151
152 return k; /* return bcd */
153}
154
161static uint8_t a_rx8025t_bcd2hex(uint8_t val)
162{
163 uint8_t temp;
164
165 temp = val & 0x0F; /* get ones place */
166 val = (val >> 4) & 0x0F; /* get tens place */
167 val = val * 10; /* set tens place */
168 temp = temp + val; /* get hex */
169
170 return temp; /* return hex */
171}
172
179static uint8_t a_week_convert(uint8_t data)
180{
181 uint8_t i;
182
183 for (i = 0; i < 8; i++) /* 8 bits */
184 {
185 if (((data >> i) & 0x1) != 0) /* check 1 */
186 {
187 break; /* break */
188 }
189 }
190
191 return i; /* return the index */
192}
193
206{
207 uint8_t res;
208 uint8_t prev;
209
210 if (handle == NULL) /* check handle */
211 {
212 return 2; /* return error */
213 }
214 if (handle->inited != 1) /* check handle initialization */
215 {
216 return 3; /* return error */
217 }
218
219 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
220 if (res != 0) /* check result */
221 {
222 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
223
224 return 1; /* return error */
225 }
226 prev &= ~(3 << 6); /* clear config */
227 prev |= interval << 6; /* set interval */
228 res = a_rx8025t_iic_write(handle, RX8025T_REG_CONTROL, prev); /* write control */
229 if (res != 0) /* check result */
230 {
231 handle->debug_print("rx8025t: write control failed.\n"); /* write control failed */
232
233 return 1; /* return error */
234 }
235
236 return 0; /* success return 0 */
237}
238
251{
252 uint8_t res;
253 uint8_t prev;
254
255 if (handle == NULL) /* check handle */
256 {
257 return 2; /* return error */
258 }
259 if (handle->inited != 1) /* check handle initialization */
260 {
261 return 3; /* return error */
262 }
263
264 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
265 if (res != 0) /* check result */
266 {
267 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
268
269 return 1; /* return error */
270 }
271 *interval = (rx8025t_temperature_compensation_interval_t)((prev >> 6) & 0x03); /* set the interval */
272
273 return 0; /* success return 0 */
274}
275
288{
289 uint8_t res;
290 uint8_t prev;
291
292 if (handle == NULL) /* check handle */
293 {
294 return 2; /* return error */
295 }
296 if (handle->inited != 1) /* check handle initialization */
297 {
298 return 3; /* return error */
299 }
300
301 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
302 if (res != 0) /* check result */
303 {
304 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
305
306 return 1; /* return error */
307 }
308 prev &= ~(1 << 5); /* clear config */
309 prev |= enable << 5; /* set bool */
310 res = a_rx8025t_iic_write(handle, RX8025T_REG_CONTROL, prev); /* write control */
311 if (res != 0) /* check result */
312 {
313 handle->debug_print("rx8025t: write control failed.\n"); /* write control failed */
314
315 return 1; /* return error */
316 }
317
318 return 0; /* success return 0 */
319}
320
333{
334 uint8_t res;
335 uint8_t prev;
336
337 if (handle == NULL) /* check handle */
338 {
339 return 2; /* return error */
340 }
341 if (handle->inited != 1) /* check handle initialization */
342 {
343 return 3; /* return error */
344 }
345
346 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
347 if (res != 0) /* check result */
348 {
349 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
350
351 return 1; /* return error */
352 }
353 *enable = (rx8025t_bool_t)((prev >> 5) & 0x01); /* set bool */
354
355 return 0; /* success return 0 */
356}
357
370{
371 uint8_t res;
372 uint8_t prev;
373
374 if (handle == NULL) /* check handle */
375 {
376 return 2; /* return error */
377 }
378 if (handle->inited != 1) /* check handle initialization */
379 {
380 return 3; /* return error */
381 }
382
383 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
384 if (res != 0) /* check result */
385 {
386 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
387
388 return 1; /* return error */
389 }
390 prev &= ~(1 << 4); /* clear config */
391 prev |= enable << 4; /* set bool */
392 res = a_rx8025t_iic_write(handle, RX8025T_REG_CONTROL, prev); /* write control */
393 if (res != 0) /* check result */
394 {
395 handle->debug_print("rx8025t: write control failed.\n"); /* write control failed */
396
397 return 1; /* return error */
398 }
399
400 return 0; /* success return 0 */
401}
402
415{
416 uint8_t res;
417 uint8_t prev;
418
419 if (handle == NULL) /* check handle */
420 {
421 return 2; /* return error */
422 }
423 if (handle->inited != 1) /* check handle initialization */
424 {
425 return 3; /* return error */
426 }
427
428 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
429 if (res != 0) /* check result */
430 {
431 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
432
433 return 1; /* return error */
434 }
435 *enable = (rx8025t_bool_t)((prev >> 4) & 0x01); /* set bool */
436
437 return 0; /* success return 0 */
438}
439
452{
453 uint8_t res;
454 uint8_t prev;
455
456 if (handle == NULL) /* check handle */
457 {
458 return 2; /* return error */
459 }
460 if (handle->inited != 1) /* check handle initialization */
461 {
462 return 3; /* return error */
463 }
464
465 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
466 if (res != 0) /* check result */
467 {
468 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
469
470 return 1; /* return error */
471 }
472 prev &= ~(1 << 3); /* clear config */
473 prev |= enable << 3; /* set bool */
474 res = a_rx8025t_iic_write(handle, RX8025T_REG_CONTROL, prev); /* write control */
475 if (res != 0) /* check result */
476 {
477 handle->debug_print("rx8025t: write control failed.\n"); /* write control failed */
478
479 return 1; /* return error */
480 }
481
482 return 0; /* success return 0 */
483}
484
497{
498 uint8_t res;
499 uint8_t prev;
500
501 if (handle == NULL) /* check handle */
502 {
503 return 2; /* return error */
504 }
505 if (handle->inited != 1) /* check handle initialization */
506 {
507 return 3; /* return error */
508 }
509
510 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
511 if (res != 0) /* check result */
512 {
513 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
514
515 return 1; /* return error */
516 }
517 *enable = (rx8025t_bool_t)((prev >> 3) & 0x01); /* set bool */
518
519 return 0; /* success return 0 */
520}
521
533{
534 uint8_t res;
535 uint8_t prev;
536
537 if (handle == NULL) /* check handle */
538 {
539 return 2; /* return error */
540 }
541 if (handle->inited != 1) /* check handle initialization */
542 {
543 return 3; /* return error */
544 }
545
546 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
547 if (res != 0) /* check result */
548 {
549 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
550
551 return 1; /* return error */
552 }
553 prev &= ~(1 << 0); /* clear config */
554 prev |= 1 << 0; /* set bool */
555 res = a_rx8025t_iic_write(handle, RX8025T_REG_CONTROL, prev); /* write control */
556 if (res != 0) /* check result */
557 {
558 handle->debug_print("rx8025t: write control failed.\n"); /* write control failed */
559
560 return 1; /* return error */
561 }
562
563 return 0; /* success return 0 */
564}
565
577{
578 uint8_t res;
579 uint8_t prev;
580
581 if (handle == NULL) /* check handle */
582 {
583 return 2; /* return error */
584 }
585 if (handle->inited != 1) /* check handle initialization */
586 {
587 return 3; /* return error */
588 }
589
590 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_CONTROL, &prev, 1); /* read control */
591 if (res != 0) /* check result */
592 {
593 handle->debug_print("rx8025t: read control failed.\n"); /* read control failed */
594
595 return 1; /* return error */
596 }
597 prev &= ~(1 << 0); /* clear config */
598 res = a_rx8025t_iic_write(handle, RX8025T_REG_CONTROL, prev); /* write control */
599 if (res != 0) /* check result */
600 {
601 handle->debug_print("rx8025t: write control failed.\n"); /* write control failed */
602
603 return 1; /* return error */
604 }
605
606 return 0; /* success return 0 */
607}
608
620uint8_t rx8025t_get_flag(rx8025t_handle_t *handle, uint8_t *flag)
621{
622 uint8_t res;
623 uint8_t prev;
624
625 if (handle == NULL) /* check handle */
626 {
627 return 2; /* return error */
628 }
629 if (handle->inited != 1) /* check handle initialization */
630 {
631 return 3; /* return error */
632 }
633
634 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_FLAG, &prev, 1); /* read flag */
635 if (res != 0) /* check result */
636 {
637 handle->debug_print("rx8025t: read flag failed.\n"); /* read flag failed */
638
639 return 1; /* return error */
640 }
641 *flag = prev; /* set flag */
642
643 return 0; /* success return 0 */
644}
645
658{
659 uint8_t res;
660 uint8_t prev;
661
662 if (handle == NULL) /* check handle */
663 {
664 return 2; /* return error */
665 }
666 if (handle->inited != 1) /* check handle initialization */
667 {
668 return 3; /* return error */
669 }
670
671 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
672 if (res != 0) /* check result */
673 {
674 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
675
676 return 1; /* return error */
677 }
678 prev &= ~(1 << 7); /* clear config */
679 prev |= enable << 7; /* set bool */
680 res = a_rx8025t_iic_write(handle, RX8025T_REG_EXTENSION, prev); /* write extension */
681 if (res != 0) /* check result */
682 {
683 handle->debug_print("rx8025t: write extension failed.\n"); /* write extension failed */
684
685 return 1; /* return error */
686 }
687
688 return 0; /* success return 0 */
689}
690
703{
704 uint8_t res;
705 uint8_t prev;
706
707 if (handle == NULL) /* check handle */
708 {
709 return 2; /* return error */
710 }
711 if (handle->inited != 1) /* check handle initialization */
712 {
713 return 3; /* return error */
714 }
715
716 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
717 if (res != 0) /* check result */
718 {
719 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
720
721 return 1; /* return error */
722 }
723 *enable = (rx8025t_bool_t)((prev >> 7) & 0x01); /* set bool */
724
725 return 0; /* success return 0 */
726}
727
740{
741 uint8_t res;
742 uint8_t prev;
743
744 if (handle == NULL) /* check handle */
745 {
746 return 2; /* return error */
747 }
748 if (handle->inited != 1) /* check handle initialization */
749 {
750 return 3; /* return error */
751 }
752
753 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
754 if (res != 0) /* check result */
755 {
756 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
757
758 return 1; /* return error */
759 }
760 prev &= ~(1 << 6); /* clear config */
761 prev |= alarm << 6; /* set alarm */
762 res = a_rx8025t_iic_write(handle, RX8025T_REG_EXTENSION, prev); /* write extension */
763 if (res != 0) /* check result */
764 {
765 handle->debug_print("rx8025t: write extension failed.\n"); /* write extension failed */
766
767 return 1; /* return error */
768 }
769
770 return 0; /* success return 0 */
771}
772
785{
786 uint8_t res;
787 uint8_t prev;
788
789 if (handle == NULL) /* check handle */
790 {
791 return 2; /* return error */
792 }
793 if (handle->inited != 1) /* check handle initialization */
794 {
795 return 3; /* return error */
796 }
797
798 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
799 if (res != 0) /* check result */
800 {
801 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
802
803 return 1; /* return error */
804 }
805 *alarm = (rx8025t_alarm_t)((prev >> 6) & 0x01); /* set alarm */
806
807 return 0; /* success return 0 */
808}
809
822{
823 uint8_t res;
824 uint8_t prev;
825
826 if (handle == NULL) /* check handle */
827 {
828 return 2; /* return error */
829 }
830 if (handle->inited != 1) /* check handle initialization */
831 {
832 return 3; /* return error */
833 }
834
835 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
836 if (res != 0) /* check result */
837 {
838 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
839
840 return 1; /* return error */
841 }
842 prev &= ~(1 << 5); /* clear config */
843 prev |= select << 5; /* set update select */
844 res = a_rx8025t_iic_write(handle, RX8025T_REG_EXTENSION, prev); /* write extension */
845 if (res != 0) /* check result */
846 {
847 handle->debug_print("rx8025t: write extension failed.\n"); /* write extension failed */
848
849 return 1; /* return error */
850 }
851
852 return 0; /* success return 0 */
853}
854
867{
868 uint8_t res;
869 uint8_t prev;
870
871 if (handle == NULL) /* check handle */
872 {
873 return 2; /* return error */
874 }
875 if (handle->inited != 1) /* check handle initialization */
876 {
877 return 3; /* return error */
878 }
879
880 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
881 if (res != 0) /* check result */
882 {
883 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
884
885 return 1; /* return error */
886 }
887 *select = (rx8025t_update_select_t)((prev >> 5) & 0x01); /* set update select */
888
889 return 0; /* success return 0 */
890}
891
904{
905 uint8_t res;
906 uint8_t prev;
907
908 if (handle == NULL) /* check handle */
909 {
910 return 2; /* return error */
911 }
912 if (handle->inited != 1) /* check handle initialization */
913 {
914 return 3; /* return error */
915 }
916
917 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
918 if (res != 0) /* check result */
919 {
920 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
921
922 return 1; /* return error */
923 }
924 prev &= ~(1 << 4); /* clear config */
925 prev |= enable << 4; /* set bool */
926 res = a_rx8025t_iic_write(handle, RX8025T_REG_EXTENSION, prev); /* write extension */
927 if (res != 0) /* check result */
928 {
929 handle->debug_print("rx8025t: write extension failed.\n"); /* write extension failed */
930
931 return 1; /* return error */
932 }
933
934 return 0; /* success return 0 */
935}
936
949{
950 uint8_t res;
951 uint8_t prev;
952
953 if (handle == NULL) /* check handle */
954 {
955 return 2; /* return error */
956 }
957 if (handle->inited != 1) /* check handle initialization */
958 {
959 return 3; /* return error */
960 }
961
962 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
963 if (res != 0) /* check result */
964 {
965 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
966
967 return 1; /* return error */
968 }
969 *enable = (rx8025t_bool_t)((prev >> 4) & 0x01); /* set bool */
970
971 return 0; /* success return 0 */
972}
973
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_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
1000 if (res != 0) /* check result */
1001 {
1002 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
1003
1004 return 1; /* return error */
1005 }
1006 prev &= ~(3 << 2); /* clear config */
1007 prev |= freq << 2; /* set frequency */
1008 res = a_rx8025t_iic_write(handle, RX8025T_REG_EXTENSION, prev); /* write extension */
1009 if (res != 0) /* check result */
1010 {
1011 handle->debug_print("rx8025t: write extension failed.\n"); /* write extension failed */
1012
1013 return 1; /* return error */
1014 }
1015
1016 return 0; /* success return 0 */
1017}
1018
1031{
1032 uint8_t res;
1033 uint8_t prev;
1034
1035 if (handle == NULL) /* check handle */
1036 {
1037 return 2; /* return error */
1038 }
1039 if (handle->inited != 1) /* check handle initialization */
1040 {
1041 return 3; /* return error */
1042 }
1043
1044 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
1045 if (res != 0) /* check result */
1046 {
1047 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
1048
1049 return 1; /* return error */
1050 }
1051 *freq = (rx8025t_square_wave_frequency_t)((prev >> 2) & 0x03); /* set frequency */
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_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
1082 if (res != 0) /* check result */
1083 {
1084 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
1085
1086 return 1; /* return error */
1087 }
1088 prev &= ~(3 << 0); /* clear config */
1089 prev |= clk << 0; /* set timer clock */
1090 res = a_rx8025t_iic_write(handle, RX8025T_REG_EXTENSION, prev); /* write extension */
1091 if (res != 0) /* check result */
1092 {
1093 handle->debug_print("rx8025t: write extension failed.\n"); /* write extension failed */
1094
1095 return 1; /* return error */
1096 }
1097
1098 return 0; /* success return 0 */
1099}
1100
1113{
1114 uint8_t res;
1115 uint8_t prev;
1116
1117 if (handle == NULL) /* check handle */
1118 {
1119 return 2; /* return error */
1120 }
1121 if (handle->inited != 1) /* check handle initialization */
1122 {
1123 return 3; /* return error */
1124 }
1125
1126 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_EXTENSION, &prev, 1); /* read extension */
1127 if (res != 0) /* check result */
1128 {
1129 handle->debug_print("rx8025t: read extension failed.\n"); /* read extension failed */
1130
1131 return 1; /* return error */
1132 }
1133 *clk = (rx8025t_timer_clock_t)((prev >> 0) & 0x03); /* set clock */
1134
1135 return 0; /* success return 0 */
1136}
1137
1150uint8_t rx8025t_set_timer_counter(rx8025t_handle_t *handle, uint16_t counter)
1151{
1152 uint8_t res;
1153 uint8_t buf[2];
1154
1155 if (handle == NULL) /* check handle */
1156 {
1157 return 2; /* return error */
1158 }
1159 if (handle->inited != 1) /* check handle initialization */
1160 {
1161 return 3; /* return error */
1162 }
1163 if (counter > 0x0FFF) /* check counter */
1164 {
1165 handle->debug_print("rx8025t: counter > 0x0FFF.\n"); /* counter > 0x0FFF */
1166
1167 return 4; /* return error */
1168 }
1169
1170 buf[0] = (counter >> 0) & 0xFF; /* set lsb */
1171 buf[1] = (counter >> 8) & 0xFF; /* set msb */
1172 res = a_rx8025t_iic_multiple_write(handle, RX8025T_REG_TIMER_COUNTER_0, buf, 2); /* write timer counter */
1173 if (res != 0) /* check result */
1174 {
1175 handle->debug_print("rx8025t: write timer counter failed.\n"); /* write timer counter failed */
1176
1177 return 1; /* return error */
1178 }
1179
1180 return 0; /* success return 0 */
1181}
1182
1194uint8_t rx8025t_get_timer_counter(rx8025t_handle_t *handle, uint16_t *counter)
1195{
1196 uint8_t res;
1197 uint8_t buf[2];
1198
1199 if (handle == NULL) /* check handle */
1200 {
1201 return 2; /* return error */
1202 }
1203 if (handle->inited != 1) /* check handle initialization */
1204 {
1205 return 3; /* return error */
1206 }
1207
1208 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_TIMER_COUNTER_0, buf, 2); /* read timer counter */
1209 if (res != 0) /* check result */
1210 {
1211 handle->debug_print("rx8025t: read timer counter failed.\n"); /* read timer counter failed */
1212
1213 return 1; /* return error */
1214 }
1215 *counter = (uint16_t)(((uint16_t)buf[1]) << 8) | buf[0]; /* set counter */
1216
1217 return 0; /* success return 0 */
1218}
1219
1231uint8_t rx8025t_set_ram(rx8025t_handle_t *handle, uint8_t data)
1232{
1233 uint8_t res;
1234 uint8_t prev;
1235
1236 if (handle == NULL) /* check handle */
1237 {
1238 return 2; /* return error */
1239 }
1240 if (handle->inited != 1) /* check handle initialization */
1241 {
1242 return 3; /* return error */
1243 }
1244
1245 prev = data; /* set raw */
1246 res = a_rx8025t_iic_write(handle, RX8025T_REG_RAM, prev); /* write raw */
1247 if (res != 0) /* check result */
1248 {
1249 handle->debug_print("rx8025t: write raw failed.\n"); /* write raw failed */
1250
1251 return 1; /* return error */
1252 }
1253
1254 return 0; /* success return 0 */
1255}
1256
1268uint8_t rx8025t_get_ram(rx8025t_handle_t *handle, uint8_t *data)
1269{
1270 uint8_t res;
1271 uint8_t prev;
1272
1273 if (handle == NULL) /* check handle */
1274 {
1275 return 2; /* return error */
1276 }
1277 if (handle->inited != 1) /* check handle initialization */
1278 {
1279 return 3; /* return error */
1280 }
1281
1282 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_RAM, &prev, 1); /* read raw */
1283 if (res != 0) /* check result */
1284 {
1285 handle->debug_print("rx8025t: read raw failed.\n"); /* read raw failed */
1286
1287 return 1; /* return error */
1288 }
1289 *data = prev; /* set data */
1290
1291 return 0; /* success return 0 */
1292}
1293
1307{
1308 uint8_t res;
1309 uint8_t reg;
1310 uint16_t year;
1311
1312 if (handle == NULL) /* check handle */
1313 {
1314 return 2; /* return error */
1315 }
1316 if (handle->inited != 1) /* check handle initialization */
1317 {
1318 return 3; /* return error */
1319 }
1320 if (t == NULL) /* check time */
1321 {
1322 handle->debug_print("rx8025t: time is null.\n"); /* time is null */
1323
1324 return 2; /* return error */
1325 }
1326
1327 if ((t->year < 2000) || (t->year > 2099)) /* check year */
1328 {
1329 handle->debug_print("rx8025t: year can't be over 2099 or less than 2000.\n"); /* year can't be over 2099 or less than 2000 */
1330
1331 return 4; /* return error */
1332 }
1333 if ((t->month == 0) || (t->month > 12)) /* check month */
1334 {
1335 handle->debug_print("rx8025t: month can't be zero or over than 12.\n"); /* month can't be zero or over than 12 */
1336
1337 return 4; /* return error */
1338 }
1339 if ((t->week == 0) || (t->week > 7)) /* check week */
1340 {
1341 handle->debug_print("rx8025t: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
1342
1343 return 4; /* return error */
1344 }
1345 if ((t->date == 0) || (t->date > 31)) /* check data */
1346 {
1347 handle->debug_print("rx8025t: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
1348
1349 return 4; /* return error */
1350 }
1351 if (t->hour > 23) /* check hour */
1352 {
1353 handle->debug_print("rx8025t: hour can't be over than 23.\n"); /* hour can't be over than 23 */
1354
1355 return 4; /* return error */
1356 }
1357 if (t->minute > 59) /* check minute */
1358 {
1359 handle->debug_print("rx8025t: minute can't be over than 59.\n"); /* minute can't be over than 59 */
1360
1361 return 4; /* return error */
1362 }
1363 if (t->second > 59) /* check second */
1364 {
1365 handle->debug_print("rx8025t: second can't be over than 59.\n"); /* second can't be over than 59 */
1366
1367 return 4; /* return error */
1368 }
1369
1370 res = a_rx8025t_iic_write(handle, RX8025T_REG_SEC, a_rx8025t_hex2bcd(t->second)); /* write second */
1371 if (res != 0) /* check result */
1372 {
1373 handle->debug_print("rx8025t: write second failed.\n"); /* write second failed */
1374
1375 return 1; /* return error */
1376 }
1377 res = a_rx8025t_iic_write(handle, RX8025T_REG_MIN, a_rx8025t_hex2bcd(t->minute)); /* write minute */
1378 if (res != 0) /* check result */
1379 {
1380 handle->debug_print("rx8025t: write minute failed.\n"); /* write minute failed */
1381
1382 return 1; /* return error */
1383 }
1384 res = a_rx8025t_iic_write(handle, RX8025T_REG_HOUR, a_rx8025t_hex2bcd(t->hour)); /* write hour */
1385 if (res != 0) /* check result */
1386 {
1387 handle->debug_print("rx8025t: write hour failed.\n"); /* write hour failed */
1388
1389 return 1; /* return error */
1390 }
1391 if (t->week == 7) /* sunday */
1392 {
1393 reg = 0; /* sunday set bit 0 */
1394 }
1395 else
1396 {
1397 reg = t->week; /* set week bit */
1398 }
1399 res = a_rx8025t_iic_write(handle, RX8025T_REG_WEEK, 1 << reg); /* write week */
1400 if (res != 0) /* check result */
1401 {
1402 handle->debug_print("rx8025t: write week failed.\n"); /* write week failed */
1403
1404 return 1; /* return error */
1405 }
1406 res = a_rx8025t_iic_write(handle, RX8025T_REG_DAY, a_rx8025t_hex2bcd(t->date)); /* write data */
1407 if (res != 0) /* check result */
1408 {
1409 handle->debug_print("rx8025t: write date failed.\n"); /* write date failed */
1410
1411 return 1; /* return error */
1412 }
1413 res = a_rx8025t_iic_write(handle, RX8025T_REG_MONTH, a_rx8025t_hex2bcd(t->month)); /* write month and century */
1414 if (res != 0) /* check result */
1415 {
1416 handle->debug_print("rx8025t: write century and month failed.\n"); /* write century and month failed */
1417
1418 return 1; /* return error */
1419 }
1420 year = t->year - 2000; /* year - 2000 */
1421 res = a_rx8025t_iic_write(handle, RX8025T_REG_YEAR, a_rx8025t_hex2bcd((uint8_t)year)); /* write year */
1422 if (res != 0) /* check result */
1423 {
1424 handle->debug_print("rx8025t: write year failed.\n"); /* write year failed */
1425
1426 return 1; /* return error */
1427 }
1428
1429 return 0; /* success return 0 */
1430}
1431
1444{
1445 uint8_t res;
1446 uint8_t buf[7];
1447
1448 if (handle == NULL) /* check handle */
1449 {
1450 return 2; /* return error */
1451 }
1452 if (handle->inited != 1) /* check handle initialization */
1453 {
1454 return 3; /* return error */
1455 }
1456 if (t == NULL) /* check time */
1457 {
1458 handle->debug_print("rx8025t: time is null.\n"); /* time is null */
1459
1460 return 2; /* return error */
1461 }
1462
1463 memset(buf, 0, sizeof(uint8_t) * 7); /* clear the buffer */
1464 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_SEC, (uint8_t *)buf, 7); /* multiple_read */
1465 if (res != 0) /* check result */
1466 {
1467 handle->debug_print("rx8025t: multiple read failed.\n"); /* multiple read failed */
1468
1469 return 1; /* return error */
1470 }
1471 t->year = a_rx8025t_bcd2hex(buf[6]) + 2000; /* get year */
1472 t->month = a_rx8025t_bcd2hex(buf[5] & 0x1F); /* get month */
1473 t->week = a_week_convert(buf[3] & 0x7F); /* get week */
1474 if (t->week == 0) /* check sunday */
1475 {
1476 t->week = 7; /* set sunday */
1477 }
1478 t->date = a_rx8025t_bcd2hex(buf[4] & 0x3F); /* get date */
1479 t->hour = a_rx8025t_bcd2hex(buf[2] & 0x3F); /* get hour */
1480 t->minute = a_rx8025t_bcd2hex(buf[1] & 0x7F); /* get minute */
1481 t->second = a_rx8025t_bcd2hex(buf[0] & 0x7F); /* get second */
1482
1483 return 0; /* success return 0 */
1484}
1485
1498uint8_t rx8025t_set_minute_alarm(rx8025t_handle_t *handle, uint8_t minute)
1499{
1500 uint8_t res;
1501
1502 if (handle == NULL) /* check handle */
1503 {
1504 return 2; /* return error */
1505 }
1506 if (handle->inited != 1) /* check handle initialization */
1507 {
1508 return 3; /* return error */
1509 }
1510 if (minute > 59) /* check minute */
1511 {
1512 handle->debug_print("rx8025t: minute can't be over than 59.\n"); /* minute can't be over than 59 */
1513
1514 return 4; /* return error */
1515 }
1516
1517 res = a_rx8025t_iic_write(handle, RX8025T_REG_MIN_ALARM, a_rx8025t_hex2bcd(minute)); /* write minute alarm */
1518 if (res != 0) /* check result */
1519 {
1520 handle->debug_print("rx8025t: write minute alarm failed.\n"); /* write minute alarm failed */
1521
1522 return 1; /* return error */
1523 }
1524
1525 return 0; /* success return 0 */
1526}
1527
1539uint8_t rx8025t_get_minute_alarm(rx8025t_handle_t *handle, uint8_t *minute)
1540{
1541 uint8_t res;
1542 uint8_t prev;
1543
1544 if (handle == NULL) /* check handle */
1545 {
1546 return 2; /* return error */
1547 }
1548 if (handle->inited != 1) /* check handle initialization */
1549 {
1550 return 3; /* return error */
1551 }
1552
1553 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_MIN_ALARM, (uint8_t *)&prev, 1); /* read minute alarm */
1554 if (res != 0) /* check result */
1555 {
1556 handle->debug_print("rx8025t: read minute alarm failed.\n"); /* read minute alarm failed */
1557
1558 return 1; /* return error */
1559 }
1560 *minute = a_rx8025t_bcd2hex(prev & 0x7F); /* set minute */
1561
1562 return 0; /* success return 0 */
1563}
1564
1577uint8_t rx8025t_set_hour_alarm(rx8025t_handle_t *handle, uint8_t hour)
1578{
1579 uint8_t res;
1580
1581 if (handle == NULL) /* check handle */
1582 {
1583 return 2; /* return error */
1584 }
1585 if (handle->inited != 1) /* check handle initialization */
1586 {
1587 return 3; /* return error */
1588 }
1589 if (hour > 23) /* check hour */
1590 {
1591 handle->debug_print("rx8025t: hour can't be over than 23.\n"); /* hour can't be over than 23 */
1592
1593 return 4; /* return error */
1594 }
1595
1596 res = a_rx8025t_iic_write(handle, RX8025T_REG_HOUR_ALARM, a_rx8025t_hex2bcd(hour)); /* write hour alarm */
1597 if (res != 0) /* check result */
1598 {
1599 handle->debug_print("rx8025t: write hour alarm failed.\n"); /* write hour alarm failed */
1600
1601 return 1; /* return error */
1602 }
1603
1604 return 0; /* success return 0 */
1605}
1606
1618uint8_t rx8025t_get_hour_alarm(rx8025t_handle_t *handle, uint8_t *hour)
1619{
1620 uint8_t res;
1621 uint8_t prev;
1622
1623 if (handle == NULL) /* check handle */
1624 {
1625 return 2; /* return error */
1626 }
1627 if (handle->inited != 1) /* check handle initialization */
1628 {
1629 return 3; /* return error */
1630 }
1631
1632 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_HOUR_ALARM, (uint8_t *)&prev, 1); /* read hour alarm */
1633 if (res != 0) /* check result */
1634 {
1635 handle->debug_print("rx8025t: read hour alarm failed.\n"); /* read hour alarm failed */
1636
1637 return 1; /* return error */
1638 }
1639 *hour = a_rx8025t_bcd2hex(prev & 0x3F); /* set hour */
1640
1641 return 0; /* success return 0 */
1642}
1643
1656uint8_t rx8025t_set_date_alarm(rx8025t_handle_t *handle, uint8_t date)
1657{
1658 uint8_t res;
1659
1660 if (handle == NULL) /* check handle */
1661 {
1662 return 2; /* return error */
1663 }
1664 if (handle->inited != 1) /* check handle initialization */
1665 {
1666 return 3; /* return error */
1667 }
1668 if ((date == 0) || (date > 31)) /* check data */
1669 {
1670 handle->debug_print("rx8025t: date can't be zero or over than 31.\n"); /* date can't be zero or over than 31 */
1671
1672 return 4; /* return error */
1673 }
1674
1675 res = a_rx8025t_iic_write(handle, RX8025T_REG_WEEK_DAY_ALARM, a_rx8025t_hex2bcd(date)); /* week day alarm */
1676 if (res != 0) /* check result */
1677 {
1678 handle->debug_print("rx8025t: week day alarm failed.\n"); /* week day alarm failed */
1679
1680 return 1; /* return error */
1681 }
1682
1683 return 0; /* success return 0 */
1684}
1685
1697uint8_t rx8025t_get_date_alarm(rx8025t_handle_t *handle, uint8_t *date)
1698{
1699 uint8_t res;
1700 uint8_t prev;
1701
1702 if (handle == NULL) /* check handle */
1703 {
1704 return 2; /* return error */
1705 }
1706 if (handle->inited != 1) /* check handle initialization */
1707 {
1708 return 3; /* return error */
1709 }
1710
1711 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_WEEK_DAY_ALARM, (uint8_t *)&prev, 1); /* read day alarm */
1712 if (res != 0) /* check result */
1713 {
1714 handle->debug_print("rx8025t: read day alarm failed.\n"); /* read day alarm failed */
1715
1716 return 1; /* return error */
1717 }
1718 *date = a_rx8025t_bcd2hex(prev & 0x3F); /* set date */
1719
1720 return 0; /* success return 0 */
1721}
1722
1735uint8_t rx8025t_set_week_alarm(rx8025t_handle_t *handle, uint8_t week)
1736{
1737 uint8_t res;
1738 uint8_t reg;
1739
1740 if (handle == NULL) /* check handle */
1741 {
1742 return 2; /* return error */
1743 }
1744 if (handle->inited != 1) /* check handle initialization */
1745 {
1746 return 3; /* return error */
1747 }
1748 if ((week == 0) || (week > 7)) /* check week */
1749 {
1750 handle->debug_print("rx8025t: week can't be zero or over than 7.\n"); /* week can't be zero or over than 7 */
1751
1752 return 4; /* return error */
1753 }
1754
1755 if (week == 7) /* sunday */
1756 {
1757 reg = 0; /* sunday set bit 0 */
1758 }
1759 else
1760 {
1761 reg = week; /* set week bit */
1762 }
1763 res = a_rx8025t_iic_write(handle, RX8025T_REG_WEEK_DAY_ALARM, 1 << reg); /* week day alarm */
1764 if (res != 0) /* check result */
1765 {
1766 handle->debug_print("rx8025t: week day alarm failed.\n"); /* week day alarm failed */
1767
1768 return 1; /* return error */
1769 }
1770
1771 return 0; /* success return 0 */
1772}
1773
1785uint8_t rx8025t_get_week_alarm(rx8025t_handle_t *handle, uint8_t *week)
1786{
1787 uint8_t res;
1788 uint8_t prev;
1789
1790 if (handle == NULL) /* check handle */
1791 {
1792 return 2; /* return error */
1793 }
1794 if (handle->inited != 1) /* check handle initialization */
1795 {
1796 return 3; /* return error */
1797 }
1798
1799 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_WEEK_DAY_ALARM, (uint8_t *)&prev, 1); /* read day alarm */
1800 if (res != 0) /* check result */
1801 {
1802 handle->debug_print("rx8025t: read day alarm failed.\n"); /* read day alarm failed */
1803
1804 return 1; /* return error */
1805 }
1806 *week = a_week_convert(prev & 0x7F); /* set week */
1807 if ((*week) == 0) /* check sunday */
1808 {
1809 (*week) = 7; /* set sunday */
1810 }
1811
1812 return 0; /* success return 0 */
1813}
1814
1826{
1827 uint8_t res;
1828
1829 if (handle == NULL) /* check handle */
1830 {
1831 return 2; /* return error */
1832 }
1833 if (handle->inited != 1) /* check handle initialization */
1834 {
1835 return 3; /* return error */
1836 }
1837
1838 res = a_rx8025t_iic_write(handle, RX8025T_REG_FLAG, 0x00); /* write flag */
1839 if (res != 0) /* check result */
1840 {
1841 handle->debug_print("rx8025t: write flag failed.\n"); /* write flag failed */
1842
1843 return 1; /* return error */
1844 }
1845
1846 return 0; /* success return 0 */
1847}
1848
1861{
1862 uint8_t res;
1863 uint8_t prev;
1864
1865 if (handle == NULL) /* check handle */
1866 {
1867 return 2; /* return error */
1868 }
1869 if (handle->inited != 1) /* check handle initialization */
1870 {
1871 return 3; /* return error */
1872 }
1873
1874 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_MIN_ALARM, (uint8_t *)&prev, 1); /* read minute alarm */
1875 if (res != 0) /* check result */
1876 {
1877 handle->debug_print("rx8025t: read minute alarm failed.\n"); /* read minute alarm failed */
1878
1879 return 1; /* return error */
1880 }
1881 prev &= ~(1 << 7); /* clear settings */
1882 prev |= enable << 7; /* set bool */
1883 res = a_rx8025t_iic_write(handle, RX8025T_REG_MIN_ALARM, prev); /* write minute alarm */
1884 if (res != 0) /* check result */
1885 {
1886 handle->debug_print("rx8025t: write minute alarm failed.\n"); /* write minute alarm failed */
1887
1888 return 1; /* return error */
1889 }
1890
1891 return 0; /* success return 0 */
1892}
1893
1906{
1907 uint8_t res;
1908 uint8_t prev;
1909
1910 if (handle == NULL) /* check handle */
1911 {
1912 return 2; /* return error */
1913 }
1914 if (handle->inited != 1) /* check handle initialization */
1915 {
1916 return 3; /* return error */
1917 }
1918
1919 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_MIN_ALARM, (uint8_t *)&prev, 1); /* read minute alarm */
1920 if (res != 0) /* check result */
1921 {
1922 handle->debug_print("rx8025t: read minute alarm failed.\n"); /* read minute alarm failed */
1923
1924 return 1; /* return error */
1925 }
1926 *enable = (rx8025t_bool_t)((prev >> 7) & 0x01); /* set bool */
1927
1928 return 0; /* success return 0 */
1929}
1930
1943{
1944 uint8_t res;
1945 uint8_t prev;
1946
1947 if (handle == NULL) /* check handle */
1948 {
1949 return 2; /* return error */
1950 }
1951 if (handle->inited != 1) /* check handle initialization */
1952 {
1953 return 3; /* return error */
1954 }
1955
1956 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_HOUR_ALARM, (uint8_t *)&prev, 1); /* read hour alarm */
1957 if (res != 0) /* check result */
1958 {
1959 handle->debug_print("rx8025t: read hour alarm failed.\n"); /* read hour alarm failed */
1960
1961 return 1; /* return error */
1962 }
1963 prev &= ~(1 << 7); /* clear settings */
1964 prev |= enable << 7; /* set bool */
1965 res = a_rx8025t_iic_write(handle, RX8025T_REG_HOUR_ALARM, prev); /* write hour alarm */
1966 if (res != 0) /* check result */
1967 {
1968 handle->debug_print("rx8025t: write hour alarm failed.\n"); /* write hour alarm failed */
1969
1970 return 1; /* return error */
1971 }
1972
1973 return 0; /* success return 0 */
1974}
1975
1988{
1989 uint8_t res;
1990 uint8_t prev;
1991
1992 if (handle == NULL) /* check handle */
1993 {
1994 return 2; /* return error */
1995 }
1996 if (handle->inited != 1) /* check handle initialization */
1997 {
1998 return 3; /* return error */
1999 }
2000
2001 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_HOUR_ALARM, (uint8_t *)&prev, 1); /* read hour alarm */
2002 if (res != 0) /* check result */
2003 {
2004 handle->debug_print("rx8025t: read hour alarm failed.\n"); /* read hour alarm failed */
2005
2006 return 1; /* return error */
2007 }
2008 *enable = (rx8025t_bool_t)((prev >> 7) & 0x01); /* set bool */
2009
2010 return 0; /* success return 0 */
2011}
2012
2025{
2026 uint8_t res;
2027 uint8_t prev;
2028
2029 if (handle == NULL) /* check handle */
2030 {
2031 return 2; /* return error */
2032 }
2033 if (handle->inited != 1) /* check handle initialization */
2034 {
2035 return 3; /* return error */
2036 }
2037
2038 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_WEEK_DAY_ALARM, (uint8_t *)&prev, 1); /* read week day alarm */
2039 if (res != 0) /* check result */
2040 {
2041 handle->debug_print("rx8025t: read week day alarm failed.\n"); /* read week day alarm failed */
2042
2043 return 1; /* return error */
2044 }
2045 prev &= ~(1 << 7); /* clear settings */
2046 prev |= enable << 7; /* set bool */
2047 res = a_rx8025t_iic_write(handle, RX8025T_REG_WEEK_DAY_ALARM, prev); /* write week day alarm */
2048 if (res != 0) /* check result */
2049 {
2050 handle->debug_print("rx8025t: write week day alarm failed.\n"); /* write week day alarm failed */
2051
2052 return 1; /* return error */
2053 }
2054
2055 return 0; /* success return 0 */
2056}
2057
2070{
2071 uint8_t res;
2072 uint8_t prev;
2073
2074 if (handle == NULL) /* check handle */
2075 {
2076 return 2; /* return error */
2077 }
2078 if (handle->inited != 1) /* check handle initialization */
2079 {
2080 return 3; /* return error */
2081 }
2082
2083 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_WEEK_DAY_ALARM, (uint8_t *)&prev, 1); /* read week day alarm */
2084 if (res != 0) /* check result */
2085 {
2086 handle->debug_print("rx8025t: read week day alarm failed.\n"); /* read week day alarm failed */
2087
2088 return 1; /* return error */
2089 }
2090 *enable = (rx8025t_bool_t)((prev >> 7) & 0x01); /* set bool */
2091
2092 return 0; /* success return 0 */
2093}
2094
2106{
2107 uint8_t res;
2108 uint8_t prev;
2109
2110 if (handle == NULL) /* check handle */
2111 {
2112 return 2; /* return error */
2113 }
2114 if (handle->inited != 1) /* check handle initialization */
2115 {
2116 return 3; /* return error */
2117 }
2118
2119 res = a_rx8025t_iic_multiple_read(handle, RX8025T_REG_FLAG, &prev, 1); /* read flag */
2120 if (res != 0) /* check result */
2121 {
2122 handle->debug_print("rx8025t: read flag failed.\n"); /* read flag failed */
2123
2124 return 1; /* return error */
2125 }
2126 res = a_rx8025t_iic_write(handle, RX8025T_REG_FLAG, 0x00); /* write flag */
2127 if (res != 0) /* check result */
2128 {
2129 handle->debug_print("rx8025t: write flag failed.\n"); /* write flag failed */
2130
2131 return 1; /* return error */
2132 }
2133 if ((prev & (1 << 5)) != 0) /* check update flag */
2134 {
2135 if (handle->receive_callback != NULL) /* check the callback */
2136 {
2137 handle->receive_callback(RX8025T_STATUS_UPDATE); /* run the callback */
2138 }
2139 }
2140 if ((prev & (1 << 4)) != 0) /* check timer flag */
2141 {
2142 if (handle->receive_callback != NULL) /* check the callback */
2143 {
2144 handle->receive_callback(RX8025T_STATUS_TIMER); /* run the callback */
2145 }
2146 }
2147 if ((prev & (1 << 3)) != 0) /* check alarm flag */
2148 {
2149 if (handle->receive_callback != NULL) /* check the callback */
2150 {
2151 handle->receive_callback(RX8025T_STATUS_ALARM); /* run the callback */
2152 }
2153 }
2154 if ((prev & (1 << 1)) != 0) /* check voltage low flag */
2155 {
2156 if (handle->receive_callback != NULL) /* check the callback */
2157 {
2158 handle->receive_callback(RX8025T_STATUS_VOLTAGE_LOW); /* run the callback */
2159 }
2160 }
2161 if ((prev & (1 << 0)) != 0) /* check voltage detection flag */
2162 {
2163 if (handle->receive_callback != NULL) /* check the callback */
2164 {
2165 handle->receive_callback(RX8025T_STATUS_VOLTAGE_DETECTION); /* run the callback */
2166 }
2167 }
2168
2169 return 0; /* success return 0 */
2170}
2171
2183{
2184 if (handle == NULL) /* check handle */
2185 {
2186 return 2; /* return error */
2187 }
2188 if (handle->debug_print == NULL) /* check debug_print */
2189 {
2190 return 3; /* return error */
2191 }
2192 if (handle->iic_init == NULL) /* check iic_init */
2193 {
2194 handle->debug_print("rx8025t: iic_init is null.\n"); /* iic_init is null */
2195
2196 return 3; /* return error */
2197 }
2198 if (handle->iic_deinit == NULL) /* check iic_deinit */
2199 {
2200 handle->debug_print("rx8025t: iic_deinit is null.\n"); /* iic_deinit is null */
2201
2202 return 3; /* return error */
2203 }
2204 if (handle->iic_write == NULL) /* check iic_write */
2205 {
2206 handle->debug_print("rx8025t: iic_write is null.\n"); /* iic_write is null */
2207
2208 return 3; /* return error */
2209 }
2210 if (handle->iic_read == NULL) /* check iic_read */
2211 {
2212 handle->debug_print("rx8025t: iic_read is null.\n"); /* iic_read is null */
2213
2214 return 3; /* return error */
2215 }
2216 if (handle->delay_ms == NULL) /* check delay_ms */
2217 {
2218 handle->debug_print("rx8025t: delay_ms is null.\n"); /* delay_ms is null */
2219
2220 return 3; /* return error */
2221 }
2222
2223 if (handle->iic_init() != 0) /* iic init */
2224 {
2225 handle->debug_print("rx8025t: iic init failed.\n"); /* iic init failed */
2226
2227 return 1; /* return error */
2228 }
2229 handle->inited = 1; /* flag finish initialization */
2230
2231 return 0; /* success return 0 */
2232}
2233
2245{
2246 if (handle == NULL) /* check handle */
2247 {
2248 return 2; /* return error */
2249 }
2250 if (handle->inited != 1) /* check handle initialization */
2251 {
2252 return 3; /* return error */
2253 }
2254
2255 if (handle->iic_deinit() != 0) /* iic deinit */
2256 {
2257 handle->debug_print("rx8025t: iic deinit failed.\n"); /* iic deinit failed */
2258
2259 return 1; /* return error */
2260 }
2261 handle->inited = 0; /* flag close */
2262
2263 return 0; /* success return 0 */
2264}
2265
2279uint8_t rx8025t_set_reg(rx8025t_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2280{
2281 if (handle == NULL) /* check handle */
2282 {
2283 return 2; /* return error */
2284 }
2285 if (handle->inited != 1) /* check handle initialization */
2286 {
2287 return 3; /* return error */
2288 }
2289
2290 if (handle->iic_write(RX8025T_ADDRESS, reg, buf, len) != 0) /* write data */
2291 {
2292 return 1; /* return error */
2293 }
2294
2295 return 0; /* success return 0 */
2296}
2297
2311uint8_t rx8025t_get_reg(rx8025t_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2312{
2313 if (handle == NULL) /* check handle */
2314 {
2315 return 2; /* return error */
2316 }
2317 if (handle->inited != 1) /* check handle initialization */
2318 {
2319 return 3; /* return error */
2320 }
2321
2322 if (handle->iic_read(RX8025T_ADDRESS, reg, buf, len) != 0) /* read data */
2323 {
2324 return 1; /* return error */
2325 }
2326
2327 return 0; /* success return 0 */
2328}
2329
2339{
2340 if (info == NULL) /* check handle */
2341 {
2342 return 2; /* return error */
2343 }
2344
2345 memset(info, 0, sizeof(rx8025t_info_t)); /* initialize rx8025t info structure */
2346 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2347 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2348 strncpy(info->interface, "IIC", 8); /* copy interface name */
2349 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2350 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2351 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2352 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2353 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2354 info->driver_version = DRIVER_VERSION; /* set driver version */
2355
2356 return 0; /* success return 0 */
2357}
#define RX8025T_REG_WEEK_DAY_ALARM
#define RX8025T_REG_WEEK
#define MAX_CURRENT
#define RX8025T_REG_DAY
#define RX8025T_REG_FLAG
#define RX8025T_REG_CONTROL
#define RX8025T_REG_MONTH
#define RX8025T_REG_TIMER_COUNTER_0
#define SUPPLY_VOLTAGE_MAX
#define RX8025T_REG_HOUR
#define RX8025T_ADDRESS
chip address definition
#define RX8025T_REG_SEC
chip register definition
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define RX8025T_REG_EXTENSION
#define RX8025T_REG_MIN_ALARM
#define RX8025T_REG_YEAR
#define RX8025T_REG_HOUR_ALARM
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define RX8025T_REG_RAM
#define RX8025T_REG_MIN
driver rx8025t header file
uint8_t rx8025t_get_square_wave_frequency(rx8025t_handle_t *handle, rx8025t_square_wave_frequency_t *freq)
get square wave frequency
uint8_t rx8025t_set_time(rx8025t_handle_t *handle, rx8025t_time_t *t)
set the current time
uint8_t rx8025t_get_flag(rx8025t_handle_t *handle, uint8_t *flag)
get flag
uint8_t rx8025t_set_update_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable update interrupt
uint8_t rx8025t_set_timer_counter(rx8025t_handle_t *handle, uint16_t counter)
set timer counter
uint8_t rx8025t_stop(rx8025t_handle_t *handle)
stop
uint8_t rx8025t_info(rx8025t_info_t *info)
get chip's information
uint8_t rx8025t_get_temperature_compensation_interval(rx8025t_handle_t *handle, rx8025t_temperature_compensation_interval_t *interval)
get the temperature compensation interval
uint8_t rx8025t_set_minute_alarm_mask(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable minute alarm mask
rx8025t_update_select_t
rx8025t update select enumeration definition
uint8_t rx8025t_get_update_select(rx8025t_handle_t *handle, rx8025t_update_select_t *select)
get update select
uint8_t rx8025t_get_minute_alarm_mask(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get minute alarm mask status
uint8_t rx8025t_get_update_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get update interrupt status
uint8_t rx8025t_set_ram(rx8025t_handle_t *handle, uint8_t data)
set ram
uint8_t rx8025t_set_timer_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable timer interrupt
rx8025t_square_wave_frequency_t
rx8025t square wave frequency enumeration definition
uint8_t rx8025t_set_hour_alarm(rx8025t_handle_t *handle, uint8_t hour)
set hour alarm
uint8_t rx8025t_set_alarm_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable alarm interrupt
uint8_t rx8025t_start(rx8025t_handle_t *handle)
start
uint8_t rx8025t_init(rx8025t_handle_t *handle)
initialize the chip
uint8_t rx8025t_get_test(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get test status
uint8_t rx8025t_clear_flag(rx8025t_handle_t *handle)
clear flag
rx8025t_alarm_t
rx8025t alarm enumeration definition
uint8_t rx8025t_get_alarm_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get alarm interrupt status
uint8_t rx8025t_get_date_alarm(rx8025t_handle_t *handle, uint8_t *date)
get date alarm
uint8_t rx8025t_get_hour_alarm(rx8025t_handle_t *handle, uint8_t *hour)
get hour alarm
uint8_t rx8025t_set_update_select(rx8025t_handle_t *handle, rx8025t_update_select_t select)
set update select
uint8_t rx8025t_get_ram(rx8025t_handle_t *handle, uint8_t *data)
get ram
struct rx8025t_time_s rx8025t_time_t
rx8025t time structure definition
uint8_t rx8025t_get_timer_interrupt(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get timer interrupt status
uint8_t rx8025t_set_week_alarm(rx8025t_handle_t *handle, uint8_t week)
set week alarm
uint8_t rx8025t_get_timer(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get timer status
uint8_t rx8025t_get_timer_counter(rx8025t_handle_t *handle, uint16_t *counter)
get timer counter
uint8_t rx8025t_set_test(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable test
uint8_t rx8025t_get_alarm_day_week(rx8025t_handle_t *handle, rx8025t_alarm_t *alarm)
get alarm day week
uint8_t rx8025t_set_hour_alarm_mask(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable hour alarm mask
rx8025t_timer_clock_t
rx8025t timer clock enumeration definition
uint8_t rx8025t_set_timer_clock(rx8025t_handle_t *handle, rx8025t_timer_clock_t clk)
set timer clock
uint8_t rx8025t_get_time(rx8025t_handle_t *handle, rx8025t_time_t *t)
get the current time
uint8_t rx8025t_get_week_alarm(rx8025t_handle_t *handle, uint8_t *week)
get week alarm
uint8_t rx8025t_get_hour_alarm_mask(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get hour alarm mask status
uint8_t rx8025t_set_square_wave_frequency(rx8025t_handle_t *handle, rx8025t_square_wave_frequency_t freq)
set square wave frequency
uint8_t rx8025t_set_week_day_alarm_mask(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable week day alarm mask
uint8_t rx8025t_set_temperature_compensation_interval(rx8025t_handle_t *handle, rx8025t_temperature_compensation_interval_t interval)
set the temperature compensation interval
uint8_t rx8025t_set_alarm_day_week(rx8025t_handle_t *handle, rx8025t_alarm_t alarm)
set alarm day week
uint8_t rx8025t_irq_handler(rx8025t_handle_t *handle)
irq handler
uint8_t rx8025t_get_timer_clock(rx8025t_handle_t *handle, rx8025t_timer_clock_t *clk)
get timer clock
rx8025t_bool_t
rx8025t bool enumeration definition
uint8_t rx8025t_set_minute_alarm(rx8025t_handle_t *handle, uint8_t minute)
set minute alarm
uint8_t rx8025t_set_timer(rx8025t_handle_t *handle, rx8025t_bool_t enable)
enable or disable timer
rx8025t_temperature_compensation_interval_t
rx8025t temperature compensation interval enumeration definition
uint8_t rx8025t_get_minute_alarm(rx8025t_handle_t *handle, uint8_t *minute)
get minute alarm
uint8_t rx8025t_get_week_day_alarm_mask(rx8025t_handle_t *handle, rx8025t_bool_t *enable)
get week day alarm mask status
struct rx8025t_handle_s rx8025t_handle_t
rx8025t handle structure definition
uint8_t rx8025t_set_date_alarm(rx8025t_handle_t *handle, uint8_t date)
set date alarm
uint8_t rx8025t_deinit(rx8025t_handle_t *handle)
close the chip
struct rx8025t_info_s rx8025t_info_t
rx8025t information structure definition
@ RX8025T_STATUS_TIMER
@ RX8025T_STATUS_ALARM
@ RX8025T_STATUS_UPDATE
@ RX8025T_STATUS_VOLTAGE_DETECTION
@ RX8025T_STATUS_VOLTAGE_LOW
uint8_t rx8025t_set_reg(rx8025t_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t rx8025t_get_reg(rx8025t_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)
uint32_t driver_version
char manufacturer_name[32]