LibDriver AS3935
Loading...
Searching...
No Matches
driver_as3935.c
Go to the documentation of this file.
1
36
37#include "driver_as3935.h"
38
42#define CHIP_NAME "AMS AS3935"
43#define MANUFACTURER_NAME "AMS"
44#define SUPPLY_VOLTAGE_MIN 2.4f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.35f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define AS3935_REG_NUMBER_0 0x00
55#define AS3935_REG_NUMBER_1 0x01
56#define AS3935_REG_NUMBER_2 0x02
57#define AS3935_REG_NUMBER_3 0x03
58#define AS3935_REG_NUMBER_4 0x04
59#define AS3935_REG_NUMBER_5 0x05
60#define AS3935_REG_NUMBER_6 0x06
61#define AS3935_REG_NUMBER_7 0x07
62#define AS3935_REG_NUMBER_8 0x08
63#define AS3935_REG_NUMBER_A 0x3A
64#define AS3935_REG_NUMBER_B 0x3B
65#define AS3935_REG_PRESET_DEFAULT 0x3C
66#define AS3935_REG_CALIB_RCO 0x3D
67
79static uint8_t a_as3935_iic_spi_read(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
80{
81 if (handle->iic_spi == AS3935_INTERFACE_IIC) /* iic interface */
82 {
83 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* read data */
84 {
85 return 1; /* return error */
86 }
87
88 return 0; /* success return 0 */
89 }
90 else /* spi interface */
91 {
92 uint8_t command;
93
94 command = (1 << 6) | (reg & 0x3F); /* set command */
95 if (handle->spi_read(command, buf, len) != 0) /* read data */
96 {
97 return 1; /* return error */
98 }
99
100 return 0; /* success return 0 */
101 }
102}
103
115static uint8_t a_as3935_iic_spi_write(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
116{
117 if (handle->iic_spi == AS3935_INTERFACE_IIC) /* iic interface */
118 {
119 if (handle->iic_write(handle->iic_addr, reg, buf, len) != 0) /* write data */
120 {
121 return 1; /* return error */
122 }
123
124 return 0; /* success return 0 */
125 }
126 else /* spi interface */
127 {
128 uint8_t command;
129
130 command = reg & 0x3F; /* set command */
131 if (handle->spi_write(command, buf, len) != 0) /* write data */
132 {
133 return 1; /* return error */
134 }
135
136 return 0; /* success return 0 */
137 }
138}
139
150{
151 if (handle == NULL) /* check handle */
152 {
153 return 2; /* return error */
154 }
155
156 handle->iic_spi = (uint8_t)interface; /* set interface */
157
158 return 0; /* success return 0 */
159}
160
171{
172 if (handle == NULL) /* check handle */
173 {
174 return 2; /* return error */
175 }
176
177 *interface = (as3935_interface_t)(handle->iic_spi); /* get interface */
178
179 return 0; /* success return 0 */
180}
181
192{
193 if (handle == NULL) /* check handle */
194 {
195 return 2; /* return error */
196 }
197
198 handle->iic_addr = (uint8_t)addr_pin; /* set pin */
199
200 return 0; /* success return 0 */
201}
202
213{
214 if (handle == NULL) /* check handle */
215 {
216 return 2; /* return error */
217 }
218
219 *addr_pin = (as3935_address_t)(handle->iic_addr); /* get pin */
220
221 return 0; /* success return 0 */
222}
223
236{
237 uint8_t res;
238 uint8_t prev;
239
240 if (handle == NULL) /* check handle */
241 {
242 return 2; /* return error */
243 }
244 if (handle->inited != 1) /* check handle initialization */
245 {
246 return 3; /* return error */
247 }
248
249 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_0, &prev, 1); /* read config */
250 if (res != 0) /* check the result */
251 {
252 handle->debug_print("as3935: read reg 0 failed.\n"); /* read reg 0 failed */
253
254 return 1; /* return error */
255 }
256 prev &= ~(1 << 0); /* clear settings */
257 prev |= enable << 0; /* set bool */
258 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_0, &prev, 1); /* write config */
259 if (res != 0) /* check the result */
260 {
261 handle->debug_print("as3935: write reg 0 failed.\n"); /* write reg 0 failed */
262
263 return 1; /* return error */
264 }
265
266 return 0; /* success return 0 */
267}
268
281{
282 uint8_t res;
283 uint8_t prev;
284
285 if (handle == NULL) /* check handle */
286 {
287 return 2; /* return error */
288 }
289 if (handle->inited != 1) /* check handle initialization */
290 {
291 return 3; /* return error */
292 }
293
294 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_0, &prev, 1); /* read config */
295 if (res != 0) /* check the result */
296 {
297 handle->debug_print("as3935: read reg 0 failed.\n"); /* read reg 0 failed */
298
299 return 1; /* return error */
300 }
301 *enable = (as3935_bool_t)((prev >> 0) & 0x01); /* get bool */
302
303 return 0; /* success return 0 */
304}
305
318{
319 uint8_t res;
320 uint8_t prev;
321
322 if (handle == NULL) /* check handle */
323 {
324 return 2; /* return error */
325 }
326 if (handle->inited != 1) /* check handle initialization */
327 {
328 return 3; /* return error */
329 }
330
331 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_0, &prev, 1); /* read config */
332 if (res != 0) /* check the result */
333 {
334 handle->debug_print("as3935: read reg 0 failed.\n"); /* read reg 0 failed */
335
336 return 1; /* return error */
337 }
338 prev &= ~(0x1F << 1); /* clear settings */
339 prev |= gain << 1; /* set gain */
340 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_0, &prev, 1); /* write config */
341 if (res != 0) /* check the result */
342 {
343 handle->debug_print("as3935: write reg 0 failed.\n"); /* write reg 0 failed */
344
345 return 1; /* return error */
346 }
347
348 return 0; /* success return 0 */
349}
350
363{
364 uint8_t res;
365 uint8_t prev;
366
367 if (handle == NULL) /* check handle */
368 {
369 return 2; /* return error */
370 }
371 if (handle->inited != 1) /* check handle initialization */
372 {
373 return 3; /* return error */
374 }
375
376 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_0, &prev, 1); /* read config */
377 if (res != 0) /* check the result */
378 {
379 handle->debug_print("as3935: read reg 0 failed.\n"); /* read reg 0 failed */
380
381 return 1; /* return error */
382 }
383 *gain = (as3935_afe_gain_t)((prev >> 1) & 0x1F); /* set gain */
384
385 return 0; /* success return 0 */
386}
387
400{
401 uint8_t res;
402 uint8_t prev;
403
404 if (handle == NULL) /* check handle */
405 {
406 return 2; /* return error */
407 }
408 if (handle->inited != 1) /* check handle initialization */
409 {
410 return 3; /* return error */
411 }
412
413 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_1, &prev, 1); /* read config */
414 if (res != 0) /* check the result */
415 {
416 handle->debug_print("as3935: read reg 1 failed.\n"); /* read reg 1 failed */
417
418 return 1; /* return error */
419 }
420 prev &= ~(0x7 << 4); /* clear settings */
421 prev |= level << 4; /* set level */
422 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_1, &prev, 1); /* write config */
423 if (res != 0) /* check the result */
424 {
425 handle->debug_print("as3935: write reg 1 failed.\n"); /* write reg 1 failed */
426
427 return 1; /* return error */
428 }
429
430 return 0; /* success return 0 */
431}
432
445{
446 uint8_t res;
447 uint8_t prev;
448
449 if (handle == NULL) /* check handle */
450 {
451 return 2; /* return error */
452 }
453 if (handle->inited != 1) /* check handle initialization */
454 {
455 return 3; /* return error */
456 }
457
458 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_1, &prev, 1); /* read config */
459 if (res != 0) /* check the result */
460 {
461 handle->debug_print("as3935: read reg 1 failed.\n"); /* read reg 1 failed */
462
463 return 1; /* return error */
464 }
465 *level = (as3935_noise_floor_level_t)((prev >> 4) & 0x07); /* set level */
466
467 return 0; /* success return 0 */
468}
469
482uint8_t as3935_set_watchdog_threshold(as3935_handle_t *handle, uint8_t threshold)
483{
484 uint8_t res;
485 uint8_t prev;
486
487 if (handle == NULL) /* check handle */
488 {
489 return 2; /* return error */
490 }
491 if (handle->inited != 1) /* check handle initialization */
492 {
493 return 3; /* return error */
494 }
495 if (threshold > 0x0F) /* check threshold */
496 {
497 handle->debug_print("as3935: threshold > 0x0F.\n"); /* threshold > 0x0F */
498
499 return 4; /* return error */
500 }
501
502 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_1, &prev, 1); /* read config */
503 if (res != 0) /* check the result */
504 {
505 handle->debug_print("as3935: read reg 1 failed.\n"); /* read reg 1 failed */
506
507 return 1; /* return error */
508 }
509 prev &= ~(0xF << 0); /* clear settings */
510 prev |= threshold << 0; /* set threshold */
511 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_1, &prev, 1); /* write config */
512 if (res != 0) /* check the result */
513 {
514 handle->debug_print("as3935: write reg 1 failed.\n"); /* write reg 1 failed */
515
516 return 1; /* return error */
517 }
518
519 return 0; /* success return 0 */
520}
521
533uint8_t as3935_get_watchdog_threshold(as3935_handle_t *handle, uint8_t *threshold)
534{
535 uint8_t res;
536 uint8_t prev;
537
538 if (handle == NULL) /* check handle */
539 {
540 return 2; /* return error */
541 }
542 if (handle->inited != 1) /* check handle initialization */
543 {
544 return 3; /* return error */
545 }
546
547 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_1, &prev, 1); /* read config */
548 if (res != 0) /* check the result */
549 {
550 handle->debug_print("as3935: read reg 1 failed.\n"); /* read reg 1 failed */
551
552 return 1; /* return error */
553 }
554 *threshold = (prev >> 0) & 0x0F; /* set threshold */
555
556 return 0; /* success return 0 */
557}
558
571{
572 uint8_t res;
573 uint8_t prev;
574
575 if (handle == NULL) /* check handle */
576 {
577 return 2; /* return error */
578 }
579 if (handle->inited != 1) /* check handle initialization */
580 {
581 return 3; /* return error */
582 }
583
584 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_2, &prev, 1); /* read config */
585 if (res != 0) /* check the result */
586 {
587 handle->debug_print("as3935: read reg 2 failed.\n"); /* read reg 2 failed */
588
589 return 1; /* return error */
590 }
591 prev &= ~(1 << 6); /* clear settings */
592 prev |= enable << 6; /* set bool */
593 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_2, &prev, 1); /* write config */
594 if (res != 0) /* check the result */
595 {
596 handle->debug_print("as3935: write reg 2 failed.\n"); /* write reg 2 failed */
597
598 return 1; /* return error */
599 }
600
601 return 0; /* success return 0 */
602}
603
616{
617 uint8_t res;
618 uint8_t prev;
619
620 if (handle == NULL) /* check handle */
621 {
622 return 2; /* return error */
623 }
624 if (handle->inited != 1) /* check handle initialization */
625 {
626 return 3; /* return error */
627 }
628
629 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_2, &prev, 1); /* read config */
630 if (res != 0) /* check the result */
631 {
632 handle->debug_print("as3935: read reg 2 failed.\n"); /* read reg 2 failed */
633
634 return 1; /* return error */
635 }
636 *enable = (as3935_bool_t)((prev >> 6) & 0x01); /* set bool */
637
638 return 0; /* success return 0 */
639}
640
653{
654 uint8_t res;
655 uint8_t prev;
656
657 if (handle == NULL) /* check handle */
658 {
659 return 2; /* return error */
660 }
661 if (handle->inited != 1) /* check handle initialization */
662 {
663 return 3; /* return error */
664 }
665
666 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_2, &prev, 1); /* read config */
667 if (res != 0) /* check the result */
668 {
669 handle->debug_print("as3935: read reg 2 failed.\n"); /* read reg 2 failed */
670
671 return 1; /* return error */
672 }
673 prev &= ~(3 << 4); /* clear settings */
674 prev |= number << 4; /* set number */
675 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_2, &prev, 1); /* write config */
676 if (res != 0) /* check the result */
677 {
678 handle->debug_print("as3935: write reg 2 failed.\n"); /* write reg 2 failed */
679
680 return 1; /* return error */
681 }
682
683 return 0; /* success return 0 */
684}
685
698{
699 uint8_t res;
700 uint8_t prev;
701
702 if (handle == NULL) /* check handle */
703 {
704 return 2; /* return error */
705 }
706 if (handle->inited != 1) /* check handle initialization */
707 {
708 return 3; /* return error */
709 }
710
711 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_2, &prev, 1); /* read config */
712 if (res != 0) /* check the result */
713 {
714 handle->debug_print("as3935: read reg 2 failed.\n"); /* read reg 2 failed */
715
716 return 1; /* return error */
717 }
718 *number = (as3935_lightning_min_number_t)((prev >> 4) & 0x03); /* set number */
719
720 return 0; /* success return 0 */
721}
722
735uint8_t as3935_set_spike_rejection(as3935_handle_t *handle, uint8_t rejection)
736{
737 uint8_t res;
738 uint8_t prev;
739
740 if (handle == NULL) /* check handle */
741 {
742 return 2; /* return error */
743 }
744 if (handle->inited != 1) /* check handle initialization */
745 {
746 return 3; /* return error */
747 }
748 if (rejection > 0x0F) /* check rejection */
749 {
750 handle->debug_print("as3935: rejection > 0x0F.\n"); /* rejection > 0x0F */
751
752 return 4; /* return error */
753 }
754
755 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_2, &prev, 1); /* read config */
756 if (res != 0) /* check the result */
757 {
758 handle->debug_print("as3935: read reg 2 failed.\n"); /* read reg 2 failed */
759
760 return 1; /* return error */
761 }
762 prev &= ~(0xF << 0); /* clear settings */
763 prev |= rejection << 0; /* set rejection */
764 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_2, &prev, 1); /* write config */
765 if (res != 0) /* check the result */
766 {
767 handle->debug_print("as3935: write reg 2 failed.\n"); /* write reg 2 failed */
768
769 return 1; /* return error */
770 }
771
772 return 0; /* success return 0 */
773}
774
786uint8_t as3935_get_spike_rejection(as3935_handle_t *handle, uint8_t *rejection)
787{
788 uint8_t res;
789 uint8_t prev;
790
791 if (handle == NULL) /* check handle */
792 {
793 return 2; /* return error */
794 }
795 if (handle->inited != 1) /* check handle initialization */
796 {
797 return 3; /* return error */
798 }
799
800 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_2, &prev, 1); /* read config */
801 if (res != 0) /* check the result */
802 {
803 handle->debug_print("as3935: read reg 2 failed.\n"); /* read reg 2 failed */
804
805 return 1; /* return error */
806 }
807 *rejection = (prev >> 0) & 0x0F; /* set rejection */
808
809 return 0; /* success return 0 */
810}
811
824{
825 uint8_t res;
826 uint8_t prev;
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
837 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_3, &prev, 1); /* read config */
838 if (res != 0) /* check the result */
839 {
840 handle->debug_print("as3935: read reg 3 failed.\n"); /* read reg 3 failed */
841
842 return 1; /* return error */
843 }
844 prev &= ~(3 << 6); /* clear settings */
845 prev |= division << 6; /* set division */
846 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_3, &prev, 1); /* write config */
847 if (res != 0) /* check the result */
848 {
849 handle->debug_print("as3935: write reg 3 failed.\n"); /* write reg 3 failed */
850
851 return 1; /* return error */
852 }
853
854 return 0; /* success return 0 */
855}
856
869{
870 uint8_t res;
871 uint8_t prev;
872
873 if (handle == NULL) /* check handle */
874 {
875 return 2; /* return error */
876 }
877 if (handle->inited != 1) /* check handle initialization */
878 {
879 return 3; /* return error */
880 }
881
882 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_3, &prev, 1); /* read config */
883 if (res != 0) /* check the result */
884 {
885 handle->debug_print("as3935: read reg 3 failed.\n"); /* read reg 3 failed */
886
887 return 1; /* return error */
888 }
889 *division = (as3935_frequency_division_ration_t)((prev >> 6) & 0x03); /* set division */
890
891 return 0; /* success return 0 */
892}
893
906{
907 uint8_t res;
908 uint8_t prev;
909
910 if (handle == NULL) /* check handle */
911 {
912 return 2; /* return error */
913 }
914 if (handle->inited != 1) /* check handle initialization */
915 {
916 return 3; /* return error */
917 }
918
919 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_3, &prev, 1); /* read config */
920 if (res != 0) /* check the result */
921 {
922 handle->debug_print("as3935: read reg 3 failed.\n"); /* read reg 3 failed */
923
924 return 1; /* return error */
925 }
926 prev &= ~(1 << 5); /* clear settings */
927 prev |= enable << 5; /* set bool */
928 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_3, &prev, 1); /* write config */
929 if (res != 0) /* check the result */
930 {
931 handle->debug_print("as3935: write reg 3 failed.\n"); /* write reg 3 failed */
932
933 return 1; /* return error */
934 }
935
936 return 0; /* success return 0 */
937}
938
951{
952 uint8_t res;
953 uint8_t prev;
954
955 if (handle == NULL) /* check handle */
956 {
957 return 2; /* return error */
958 }
959 if (handle->inited != 1) /* check handle initialization */
960 {
961 return 3; /* return error */
962 }
963
964 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_3, &prev, 1); /* read config */
965 if (res != 0) /* check the result */
966 {
967 handle->debug_print("as3935: read reg 3 failed.\n"); /* read reg 3 failed */
968
969 return 1; /* return error */
970 }
971 *enable = (as3935_bool_t)((prev >> 5) & 0x01); /* set bool */
972
973 return 0; /* success return 0 */
974}
975
988{
989 uint8_t res;
990 uint8_t prev;
991
992 if (handle == NULL) /* check handle */
993 {
994 return 2; /* return error */
995 }
996 if (handle->inited != 1) /* check handle initialization */
997 {
998 return 3; /* return error */
999 }
1000
1001 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_3, &prev, 1); /* read config */
1002 if (res != 0) /* check the result */
1003 {
1004 handle->debug_print("as3935: read reg 3 failed.\n"); /* read reg 3 failed */
1005
1006 return 1; /* return error */
1007 }
1008 *status = (as3935_interrupt_status_t)((prev >> 0) & 0x0F); /* set status */
1009
1010 return 0; /* success return 0 */
1011}
1012
1025{
1026 uint8_t res;
1027 uint8_t buf[3];
1028
1029 if (handle == NULL) /* check handle */
1030 {
1031 return 2; /* return error */
1032 }
1033 if (handle->inited != 1) /* check handle initialization */
1034 {
1035 return 3; /* return error */
1036 }
1037
1038 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_4, buf, 3); /* read config */
1039 if (res != 0) /* check the result */
1040 {
1041 handle->debug_print("as3935: read reg 4 failed.\n"); /* read reg 4 failed */
1042
1043 return 1; /* return error */
1044 }
1045 *energy = (uint32_t)((uint32_t)(buf[2] & 0x1F) << 16) |
1046 (uint32_t)((uint32_t)buf[1] << 8) | buf[0]; /* set energy */
1047
1048 return 0; /* success return 0 */
1049}
1050
1063uint8_t as3935_read_distance(as3935_handle_t *handle, uint8_t *raw, int8_t *km)
1064{
1065 uint8_t res;
1066 uint8_t prev;
1067
1068 if (handle == NULL) /* check handle */
1069 {
1070 return 2; /* return error */
1071 }
1072 if (handle->inited != 1) /* check handle initialization */
1073 {
1074 return 3; /* return error */
1075 }
1076
1077 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_7, &prev, 1); /* read config */
1078 if (res != 0) /* check the result */
1079 {
1080 handle->debug_print("as3935: read reg 7 failed.\n"); /* read reg 7 failed */
1081
1082 return 1; /* return error */
1083 }
1084 *raw = prev & 0x3F; /* set distance */
1085 if ((*raw) == 0x3F) /* check output of range */
1086 {
1087 *km = -1; /* set -1 */
1088 }
1089 else
1090 {
1091 switch (*raw) /* choose the distance */
1092 {
1093 case 0x01 : /* 0x01 */
1094 {
1095 *km = 0; /* convert to km */
1096
1097 break; /* break */
1098 }
1099 case 0x05 : /* 0x05 */
1100 {
1101 *km = 5; /* convert to km */
1102
1103 break; /* break */
1104 }
1105 case 0x06 : /* 0x06 */
1106 {
1107 *km = 6; /* convert to km */
1108
1109 break; /* break */
1110 }
1111 case 0x08 : /* 0x08 */
1112 {
1113 *km = 8; /* convert to km */
1114
1115 break; /* break */
1116 }
1117 case 0x0A : /* 0x0A */
1118 {
1119 *km = 10; /* convert to km */
1120
1121 break; /* break */
1122 }
1123 case 0x0C : /* 0x0C */
1124 {
1125 *km = 12; /* convert to km */
1126
1127 break; /* break */
1128 }
1129 case 0x0E : /* 0x0E */
1130 {
1131 *km = 14; /* convert to km */
1132
1133 break; /* break */
1134 }
1135 case 0x11 : /* 0x11 */
1136 {
1137 *km = 17; /* convert to km */
1138
1139 break; /* break */
1140 }
1141 case 0x14 : /* 0x14 */
1142 {
1143 *km = 20; /* convert to km */
1144
1145 break; /* break */
1146 }
1147 case 0x18 : /* 0x18 */
1148 {
1149 *km = 24; /* convert to km */
1150
1151 break; /* break */
1152 }
1153 case 0x1B : /* 0x1B */
1154 {
1155 *km = 27; /* convert to km */
1156
1157 break; /* break */
1158 }
1159 case 0x1F : /* 0x1F */
1160 {
1161 *km = 31; /* convert to km */
1162
1163 break; /* break */
1164 }
1165 case 0x22 : /* 0x22 */
1166 {
1167 *km = 34; /* convert to km */
1168
1169 break; /* break */
1170 }
1171 case 0x25 : /* 0x25 */
1172 {
1173 *km = 37; /* convert to km */
1174
1175 break; /* break */
1176 }
1177 case 0x28 : /* 0x28 */
1178 {
1179 *km = 40; /* convert to km */
1180
1181 break; /* break */
1182 }
1183 default : /* default */
1184 {
1185 *km = -1; /* error */
1186
1187 break; /* break */
1188 }
1189 }
1190 }
1191
1192 return 0; /* success return 0 */
1193}
1194
1207{
1208 uint8_t res;
1209 uint8_t prev;
1210
1211 if (handle == NULL) /* check handle */
1212 {
1213 return 2; /* return error */
1214 }
1215 if (handle->inited != 1) /* check handle initialization */
1216 {
1217 return 3; /* return error */
1218 }
1219
1220 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1221 if (res != 0) /* check the result */
1222 {
1223 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1224
1225 return 1; /* return error */
1226 }
1227 prev &= ~(1 << 7); /* clear settings */
1228 prev |= enable << 7; /* set bool */
1229 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_8, &prev, 1); /* write config */
1230 if (res != 0) /* check the result */
1231 {
1232 handle->debug_print("as3935: write reg 8 failed.\n"); /* write reg 8 failed */
1233
1234 return 1; /* return error */
1235 }
1236
1237 return 0; /* success return 0 */
1238}
1239
1252{
1253 uint8_t res;
1254 uint8_t prev;
1255
1256 if (handle == NULL) /* check handle */
1257 {
1258 return 2; /* return error */
1259 }
1260 if (handle->inited != 1) /* check handle initialization */
1261 {
1262 return 3; /* return error */
1263 }
1264
1265 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1266 if (res != 0) /* check the result */
1267 {
1268 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1269
1270 return 1; /* return error */
1271 }
1272 *enable = (as3935_bool_t)((prev >> 7) & 0x01); /* set bool */
1273
1274 return 0; /* success return 0 */
1275}
1276
1289{
1290 uint8_t res;
1291 uint8_t prev;
1292
1293 if (handle == NULL) /* check handle */
1294 {
1295 return 2; /* return error */
1296 }
1297 if (handle->inited != 1) /* check handle initialization */
1298 {
1299 return 3; /* return error */
1300 }
1301
1302 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1303 if (res != 0) /* check the result */
1304 {
1305 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1306
1307 return 1; /* return error */
1308 }
1309 prev &= ~(1 << 6); /* clear settings */
1310 prev |= enable << 6; /* set bool */
1311 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_8, &prev, 1); /* write config */
1312 if (res != 0) /* check the result */
1313 {
1314 handle->debug_print("as3935: write reg 8 failed.\n"); /* write reg 8 failed */
1315
1316 return 1; /* return error */
1317 }
1318
1319 return 0; /* success return 0 */
1320}
1321
1334{
1335 uint8_t res;
1336 uint8_t prev;
1337
1338 if (handle == NULL) /* check handle */
1339 {
1340 return 2; /* return error */
1341 }
1342 if (handle->inited != 1) /* check handle initialization */
1343 {
1344 return 3; /* return error */
1345 }
1346
1347 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1348 if (res != 0) /* check the result */
1349 {
1350 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1351
1352 return 1; /* return error */
1353 }
1354 *enable = (as3935_bool_t)((prev >> 6) & 0x01); /* set bool */
1355
1356 return 0; /* success return 0 */
1357}
1358
1371{
1372 uint8_t res;
1373 uint8_t prev;
1374
1375 if (handle == NULL) /* check handle */
1376 {
1377 return 2; /* return error */
1378 }
1379 if (handle->inited != 1) /* check handle initialization */
1380 {
1381 return 3; /* return error */
1382 }
1383
1384 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1385 if (res != 0) /* check the result */
1386 {
1387 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1388
1389 return 1; /* return error */
1390 }
1391 prev &= ~(1 << 5); /* clear settings */
1392 prev |= enable << 5; /* set bool */
1393 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_8, &prev, 1); /* write config */
1394 if (res != 0) /* check the result */
1395 {
1396 handle->debug_print("as3935: write reg 8 failed.\n"); /* write reg 8 failed */
1397
1398 return 1; /* return error */
1399 }
1400
1401 return 0; /* success return 0 */
1402}
1403
1416{
1417 uint8_t res;
1418 uint8_t prev;
1419
1420 if (handle == NULL) /* check handle */
1421 {
1422 return 2; /* return error */
1423 }
1424 if (handle->inited != 1) /* check handle initialization */
1425 {
1426 return 3; /* return error */
1427 }
1428
1429 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1430 if (res != 0) /* check the result */
1431 {
1432 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1433
1434 return 1; /* return error */
1435 }
1436 *enable = (as3935_bool_t)((prev >> 5) & 0x01); /* set bool */
1437
1438 return 0; /* success return 0 */
1439}
1440
1454{
1455 uint8_t res;
1456 uint8_t prev;
1457
1458 if (handle == NULL) /* check handle */
1459 {
1460 return 2; /* return error */
1461 }
1462 if (handle->inited != 1) /* check handle initialization */
1463 {
1464 return 3; /* return error */
1465 }
1466 if (cap > 0xF) /* check the result */
1467 {
1468 handle->debug_print("as3935: cap > 0xF.\n"); /* cap > 0xF */
1469
1470 return 4; /* return error */
1471 }
1472
1473 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1474 if (res != 0) /* check the result */
1475 {
1476 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1477
1478 return 1; /* return error */
1479 }
1480 prev &= ~(0xF << 0); /* clear settings */
1481 prev |= cap << 0; /* set cap */
1482 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_8, &prev, 1); /* write config */
1483 if (res != 0) /* check the result */
1484 {
1485 handle->debug_print("as3935: write reg 8 failed.\n"); /* write reg 8 failed */
1486
1487 return 1; /* return error */
1488 }
1489
1490 return 0; /* success return 0 */
1491}
1492
1505{
1506 uint8_t res;
1507 uint8_t prev;
1508
1509 if (handle == NULL) /* check handle */
1510 {
1511 return 2; /* return error */
1512 }
1513 if (handle->inited != 1) /* check handle initialization */
1514 {
1515 return 3; /* return error */
1516 }
1517
1518 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_8, &prev, 1); /* read config */
1519 if (res != 0) /* check the result */
1520 {
1521 handle->debug_print("as3935: read reg 8 failed.\n"); /* read reg 8 failed */
1522
1523 return 1; /* return error */
1524 }
1525 *cap = prev & 0x0F; /* set cap */
1526
1527 return 0; /* success return 0 */
1528}
1529
1542{
1543 uint8_t res;
1544 uint8_t prev;
1545
1546 if (handle == NULL) /* check handle */
1547 {
1548 return 2; /* return error */
1549 }
1550 if (handle->inited != 1) /* check handle initialization */
1551 {
1552 return 3; /* return error */
1553 }
1554
1555 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_A, &prev, 1); /* read config */
1556 if (res != 0) /* check the result */
1557 {
1558 handle->debug_print("as3935: read reg a failed.\n"); /* read reg a failed */
1559
1560 return 1; /* return error */
1561 }
1562 *enable = (as3935_bool_t)((prev >> 7) & 0x01); /* set bool */
1563
1564 return 0; /* success return 0 */
1565}
1566
1579{
1580 uint8_t res;
1581 uint8_t prev;
1582
1583 if (handle == NULL) /* check handle */
1584 {
1585 return 2; /* return error */
1586 }
1587 if (handle->inited != 1) /* check handle initialization */
1588 {
1589 return 3; /* return error */
1590 }
1591
1592 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_A, &prev, 1); /* read config */
1593 if (res != 0) /* check the result */
1594 {
1595 handle->debug_print("as3935: read reg a failed.\n"); /* read reg a failed */
1596
1597 return 1; /* return error */
1598 }
1599 *enable = (as3935_bool_t)((prev >> 6) & 0x01); /* set bool */
1600
1601 return 0; /* success return 0 */
1602}
1603
1616{
1617 uint8_t res;
1618 uint8_t prev;
1619
1620 if (handle == NULL) /* check handle */
1621 {
1622 return 2; /* return error */
1623 }
1624 if (handle->inited != 1) /* check handle initialization */
1625 {
1626 return 3; /* return error */
1627 }
1628
1629 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_B, &prev, 1); /* read config */
1630 if (res != 0) /* check the result */
1631 {
1632 handle->debug_print("as3935: read reg b failed.\n"); /* read reg b failed */
1633
1634 return 1; /* return error */
1635 }
1636 *enable = (as3935_bool_t)((prev >> 7) & 0x01); /* set bool */
1637
1638 return 0; /* success return 0 */
1639}
1640
1653{
1654 uint8_t res;
1655 uint8_t prev;
1656
1657 if (handle == NULL) /* check handle */
1658 {
1659 return 2; /* return error */
1660 }
1661 if (handle->inited != 1) /* check handle initialization */
1662 {
1663 return 3; /* return error */
1664 }
1665
1666 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_B, &prev, 1); /* read config */
1667 if (res != 0) /* check the result */
1668 {
1669 handle->debug_print("as3935: read reg b failed.\n"); /* read reg b failed */
1670
1671 return 1; /* return error */
1672 }
1673 *enable = (as3935_bool_t)((prev >> 6) & 0x01); /* set bool */
1674
1675 return 0; /* success return 0 */
1676}
1677
1689{
1690 uint8_t res;
1691 uint8_t prev;
1692
1693 if (handle == NULL) /* check handle */
1694 {
1695 return 2; /* return error */
1696 }
1697 if (handle->inited != 1) /* check handle initialization */
1698 {
1699 return 3; /* return error */
1700 }
1701
1702 prev = 0x96U; /* set all registers in default mode */
1703 res = a_as3935_iic_spi_write(handle, AS3935_REG_PRESET_DEFAULT, &prev, 1); /* write config */
1704 if (res != 0) /* check the result */
1705 {
1706 handle->debug_print("as3935: write command failed.\n"); /* write command failed */
1707
1708 return 1; /* return error */
1709 }
1710
1711 return 0; /* success return 0 */
1712}
1713
1725{
1726 uint8_t res;
1727 uint8_t prev;
1728
1729 if (handle == NULL) /* check handle */
1730 {
1731 return 2; /* return error */
1732 }
1733 if (handle->inited != 1) /* check handle initialization */
1734 {
1735 return 3; /* return error */
1736 }
1737
1738 prev = 0x96U; /* calibrates automatically the internal rc oscillators */
1739 res = a_as3935_iic_spi_write(handle, AS3935_REG_CALIB_RCO, &prev, 1); /* write config */
1740 if (res != 0) /* check the result */
1741 {
1742 handle->debug_print("as3935: write command failed.\n"); /* write command failed */
1743
1744 return 1; /* return error */
1745 }
1746
1747 return 0; /* success return 0 */
1748}
1749
1762{
1763 if (handle == NULL) /* check handle */
1764 {
1765 return 2; /* return error */
1766 }
1767 if (handle->inited != 1) /* check handle initialization */
1768 {
1769 return 3; /* return error */
1770 }
1771
1772 *reg = (uint8_t)(pf / 8.0f); /* convert real data to register data */
1773
1774 return 0; /* success return 0 */
1775}
1776
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 *pf = (float)(reg) * 8.0f; /* convert raw data to real data */
1800
1801 return 0; /* success return 0 */
1802}
1803
1812static uint8_t a_as3935_close(as3935_handle_t *handle)
1813{
1814 if (handle->iic_spi == AS3935_INTERFACE_IIC) /* iic interface */
1815 {
1816 if (handle->iic_deinit() != 0) /* iic deinit */
1817 {
1818 handle->debug_print("as3935: iic deinit failed.\n"); /* iic deinit failed */
1819
1820 return 1; /* return error */
1821 }
1822
1823 return 0; /* success return 0 */
1824 }
1825 else /* spi interface */
1826 {
1827 if (handle->spi_deinit() != 0) /* spi deinit */
1828 {
1829 handle->debug_print("as3935: spi deinit failed.\n"); /* spi deinit failed */
1830
1831 return 1; /* return error */
1832 }
1833
1834 return 0; /* success return 0 */
1835 }
1836}
1837
1849{
1850 if (handle == NULL) /* check handle */
1851 {
1852 return 2; /* return error */
1853 }
1854 if (handle->debug_print == NULL) /* check debug_print */
1855 {
1856 return 3; /* return error */
1857 }
1858 if (handle->iic_init == NULL) /* check iic_init */
1859 {
1860 handle->debug_print("as3935: iic_init is null.\n"); /* iic_init is null */
1861
1862 return 3; /* return error */
1863 }
1864 if (handle->iic_deinit == NULL) /* check iic_deinit */
1865 {
1866 handle->debug_print("as3935: iic_deinit is null.\n"); /* iic_deinit is null */
1867
1868 return 3; /* return error */
1869 }
1870 if (handle->iic_read == NULL) /* check iic_read */
1871 {
1872 handle->debug_print("as3935: iic_read is null.\n"); /* iic_read is null */
1873
1874 return 3; /* return error */
1875 }
1876 if (handle->iic_write == NULL) /* check iic_write */
1877 {
1878 handle->debug_print("as3935: iic_write is null.\n"); /* iic_write is null */
1879
1880 return 3; /* return error */
1881 }
1882 if (handle->spi_init == NULL) /* check spi_init */
1883 {
1884 handle->debug_print("as3935: spi_init is null.\n"); /* spi_init is null */
1885
1886 return 3; /* return error */
1887 }
1888 if (handle->spi_deinit == NULL) /* check spi_deinit */
1889 {
1890 handle->debug_print("as3935: spi_deinit is null.\n"); /* spi_deinit is null */
1891
1892 return 3; /* return error */
1893 }
1894 if (handle->spi_read == NULL) /* check spi_read */
1895 {
1896 handle->debug_print("as3935: spi_read is null.\n"); /* spi_read is null */
1897
1898 return 3; /* return error */
1899 }
1900 if (handle->spi_write == NULL) /* check spi_write */
1901 {
1902 handle->debug_print("as3935: spi_write is null.\n"); /* spi_write is null */
1903
1904 return 3; /* return error */
1905 }
1906 if (handle->delay_ms == NULL) /* check delay_ms */
1907 {
1908 handle->debug_print("as3935: delay_ms is null.\n"); /* delay_ms is null */
1909
1910 return 3; /* return error */
1911 }
1912 if (handle->receive_callback == NULL) /* check receive_callback */
1913 {
1914 handle->debug_print("as3935: receive_callback is null.\n"); /* receive_callback is null */
1915
1916 return 3; /* return error */
1917 }
1918
1919 if (handle->iic_spi == AS3935_INTERFACE_IIC) /* iic interface */
1920 {
1921 if (handle->iic_init() != 0) /* initialize iic bus */
1922 {
1923 handle->debug_print("as3935: iic init failed.\n"); /* iic init failed */
1924
1925 return 1; /* return error */
1926 }
1927 }
1928 else /* spi interface */
1929 {
1930 if (handle->spi_init() != 0) /* initialize spi bus */
1931 {
1932 handle->debug_print("as3935: spi init failed.\n"); /* spi init failed */
1933
1934 return 1; /* return error */
1935 }
1936 }
1937 handle->inited = 1; /* flag finish initialization */
1938
1939 return 0; /* success return 0 */
1940}
1941
1954{
1955 uint8_t res;
1956 uint8_t prev;
1957
1958 if (handle == NULL) /* check handle */
1959 {
1960 return 2; /* return error */
1961 }
1962 if (handle->inited != 1) /* check handle initialization */
1963 {
1964 return 3; /* return error */
1965 }
1966
1967 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_0, &prev, 1); /* read config */
1968 if (res != 0) /* check the result */
1969 {
1970 handle->debug_print("as3935: read reg 0 failed.\n"); /* read reg 0 failed */
1971
1972 return 4; /* return error */
1973 }
1974 prev &= ~(1 << 0); /* clear settings */
1975 prev |= 1 << 0; /* set bool */
1976 res = a_as3935_iic_spi_write(handle, AS3935_REG_NUMBER_0, &prev, 1); /* write config */
1977 if (res != 0) /* check the result */
1978 {
1979 handle->debug_print("as3935: write reg 0 failed.\n"); /* write reg 0 failed */
1980
1981 return 4; /* return error */
1982 }
1983 res = a_as3935_close(handle); /* close */
1984 if (res != 0) /* check result */
1985 {
1986 return 1; /* return error */
1987 }
1988
1989 handle->inited = 0; /* flag close */
1990
1991 return 0; /* success return 0 */
1992}
1993
2005{
2006 uint8_t res;
2007 uint8_t prev;
2008 uint8_t status;
2009
2010 if (handle == NULL) /* check handle */
2011 {
2012 return 2; /* return error */
2013 }
2014 if (handle->inited != 1) /* check handle initialization */
2015 {
2016 return 3; /* return error */
2017 }
2018
2019 handle->delay_ms(2); /* delay 2ms */
2020 res = a_as3935_iic_spi_read(handle, AS3935_REG_NUMBER_3, &prev, 1); /* read config */
2021 if (res != 0) /* check the result */
2022 {
2023 handle->debug_print("as3935: read reg 3 failed.\n"); /* read reg 3 failed */
2024
2025 return 1; /* return error */
2026 }
2027 status = ((prev >> 0) & 0x0F); /* set status */
2028
2029 if (status == (uint8_t)AS3935_INTERRUPT_STATUS_NOISE_LEVEL_TOO_HIGH) /* if noise level too high */
2030 {
2031 if (handle->receive_callback != NULL) /* if receive callback */
2032 {
2033 handle->receive_callback((uint8_t)AS3935_INTERRUPT_STATUS_NOISE_LEVEL_TOO_HIGH); /* run callback */
2034 }
2035 }
2036 if (status == (uint8_t)AS3935_INTERRUPT_STATUS_DISTURBER_DETECTED) /* if disturber detected */
2037 {
2038 if (handle->receive_callback != NULL) /* if receive callback */
2039 {
2040 handle->receive_callback((uint8_t)AS3935_INTERRUPT_STATUS_DISTURBER_DETECTED); /* run callback */
2041 }
2042 }
2043 if (status == (uint8_t)AS3935_INTERRUPT_STATUS_LIGHTNING_INTERRUPT) /* if lightning interrupt */
2044 {
2045 if (handle->receive_callback != NULL) /* if receive callback */
2046 {
2047 handle->receive_callback((uint8_t)AS3935_INTERRUPT_STATUS_LIGHTNING_INTERRUPT); /* run callback */
2048 }
2049 }
2050
2051 return 0; /* success return 0 */
2052}
2053
2067uint8_t as3935_set_reg(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2068{
2069 if (handle == NULL) /* check handle */
2070 {
2071 return 2; /* return error */
2072 }
2073 if (handle->inited != 1) /* check handle initialization */
2074 {
2075 return 3; /* return error */
2076 }
2077
2078 return a_as3935_iic_spi_write(handle, reg, buf, len); /* write data */
2079}
2080
2094uint8_t as3935_get_reg(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2095{
2096 if (handle == NULL) /* check handle */
2097 {
2098 return 2; /* return error */
2099 }
2100 if (handle->inited != 1) /* check handle initialization */
2101 {
2102 return 3; /* return error */
2103 }
2104
2105 return a_as3935_iic_spi_read(handle, reg, buf, len); /* read data */
2106}
2107
2117{
2118 if (info == NULL) /* check handle */
2119 {
2120 return 2; /* return error */
2121 }
2122
2123 memset(info, 0, sizeof(as3935_info_t)); /* initialize as3935 info structure */
2124 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2125 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2126 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
2127 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2128 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2129 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2130 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2131 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2132 info->driver_version = DRIVER_VERSION; /* set driver version */
2133
2134 return 0; /* success return 0 */
2135}
#define MAX_CURRENT
#define AS3935_REG_NUMBER_8
#define AS3935_REG_NUMBER_0
chip register definition
#define AS3935_REG_NUMBER_2
#define AS3935_REG_NUMBER_7
#define SUPPLY_VOLTAGE_MAX
#define AS3935_REG_NUMBER_4
#define TEMPERATURE_MAX
#define AS3935_REG_NUMBER_1
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define AS3935_REG_PRESET_DEFAULT
#define AS3935_REG_NUMBER_B
#define AS3935_REG_CALIB_RCO
#define CHIP_NAME
chip register definition
#define AS3935_REG_NUMBER_A
#define AS3935_REG_NUMBER_3
#define DRIVER_VERSION
driver as3935 header file
uint8_t as3935_set_frequency_division_ration(as3935_handle_t *handle, as3935_frequency_division_ration_t division)
set frequency division ration
uint8_t as3935_set_interface(as3935_handle_t *handle, as3935_interface_t interface)
set the chip interface
uint8_t as3935_set_clear_statistics(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable clear statistics
uint8_t as3935_set_power_down(as3935_handle_t *handle, as3935_bool_t enable)
set power down
uint8_t as3935_get_lightning_min_number(as3935_handle_t *handle, as3935_lightning_min_number_t *number)
get lightning min number
uint8_t as3935_get_watchdog_threshold(as3935_handle_t *handle, uint8_t *threshold)
get watchdog threshold
uint8_t as3935_get_spike_rejection(as3935_handle_t *handle, uint8_t *rejection)
get spike rejection
uint8_t as3935_set_watchdog_threshold(as3935_handle_t *handle, uint8_t threshold)
set watchdog threshold
uint8_t as3935_get_frequency_division_ration(as3935_handle_t *handle, as3935_frequency_division_ration_t *division)
get frequency division ration
uint8_t as3935_info(as3935_info_t *info)
get chip's information
uint8_t as3935_set_spike_rejection(as3935_handle_t *handle, uint8_t rejection)
set spike rejection
uint8_t as3935_get_noise_floor_level(as3935_handle_t *handle, as3935_noise_floor_level_t *level)
get noise floor level
uint8_t as3935_get_internal_tuning_capacitor(as3935_handle_t *handle, uint8_t *cap)
get internal tuning capacitor
uint8_t as3935_internal_tuning_capacitor_convert_to_register(as3935_handle_t *handle, float pf, uint8_t *reg)
convert the internal tuning capacitor to the register raw data
uint8_t as3935_get_clear_statistics(as3935_handle_t *handle, as3935_bool_t *enable)
get clear statistics status
uint8_t as3935_set_noise_floor_level(as3935_handle_t *handle, as3935_noise_floor_level_t level)
set noise floor level
uint8_t as3935_set_calibrate_rc_osc(as3935_handle_t *handle)
calibrate rc osc
uint8_t as3935_deinit(as3935_handle_t *handle)
close the chip
uint8_t as3935_get_power_down(as3935_handle_t *handle, as3935_bool_t *enable)
get power down
uint8_t as3935_get_interface(as3935_handle_t *handle, as3935_interface_t *interface)
get the chip interface
uint8_t as3935_set_afe_gain_boost(as3935_handle_t *handle, as3935_afe_gain_t gain)
set afe gain boost
as3935_interrupt_status_t
as3935 interrupt status enumeration definition
uint8_t as3935_read_single_lightning_energy(as3935_handle_t *handle, uint32_t *energy)
read single lightning energy
as3935_address_t
as3935 address enumeration definition
as3935_interface_t
as3935 interface enumeration definition
uint8_t as3935_set_mask_disturber(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable mask disturber
uint8_t as3935_get_mask_disturber(as3935_handle_t *handle, as3935_bool_t *enable)
get mask disturber status
uint8_t as3935_set_internal_tuning_capacitor(as3935_handle_t *handle, uint8_t cap)
set internal tuning capacitor
struct as3935_info_s as3935_info_t
as3935 information structure definition
uint8_t as3935_get_addr_pin(as3935_handle_t *handle, as3935_address_t *addr_pin)
get the iic address pin
uint8_t as3935_init(as3935_handle_t *handle)
initialize the chip
struct as3935_handle_s as3935_handle_t
as3935 handle structure definition
uint8_t as3935_get_interrupt_status(as3935_handle_t *handle, as3935_interrupt_status_t *status)
get interrupt status
uint8_t as3935_get_afe_gain_boost(as3935_handle_t *handle, as3935_afe_gain_t *gain)
get afe gain boost
uint8_t as3935_get_timer_rc_osc_calibration_done(as3935_handle_t *handle, as3935_bool_t *enable)
get timer rc osc calibration done status
as3935_frequency_division_ration_t
as3935 frequency division ration enumeration definition
uint8_t as3935_set_lightning_min_number(as3935_handle_t *handle, as3935_lightning_min_number_t number)
set lightning min number
uint8_t as3935_set_addr_pin(as3935_handle_t *handle, as3935_address_t addr_pin)
set the iic address pin
uint8_t as3935_get_system_rc_osc_calibration_done(as3935_handle_t *handle, as3935_bool_t *enable)
get system rc osc calibration done status
uint8_t as3935_set_system_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable system rc osc display on irq
as3935_noise_floor_level_t
as3935 noise floor level enumeration definition
uint8_t as3935_read_distance(as3935_handle_t *handle, uint8_t *raw, int8_t *km)
read distance
uint8_t as3935_set_lc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable lc osc display on irq
uint8_t as3935_get_system_rc_osc_calibration_not_ok(as3935_handle_t *handle, as3935_bool_t *enable)
get system rc osc calibration not ok status
uint8_t as3935_irq_handler(as3935_handle_t *handle)
irq handler
as3935_bool_t
as3935 bool enumeration definition
uint8_t as3935_get_display_lc_osc_on_irq(as3935_handle_t *handle, as3935_bool_t *enable)
get lc osc display on irq status
uint8_t as3935_reset_default(as3935_handle_t *handle)
reset to default
as3935_lightning_min_number_t
as3935 lightning min number enumeration definition
uint8_t as3935_internal_tuning_capacitor_convert_to_data(as3935_handle_t *handle, uint8_t reg, float *pf)
convert the register raw data to the internal tuning capacitor
uint8_t as3935_set_timer_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable timer rc osc display on irq
uint8_t as3935_get_timer_rc_osc_calibration_not_ok(as3935_handle_t *handle, as3935_bool_t *enable)
get timer rc osc calibration not ok status
as3935_afe_gain_t
as3935 afe gain enumeration definition
uint8_t as3935_get_timer_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t *enable)
get timer rc osc display on irq status
uint8_t as3935_get_system_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t *enable)
get system rc osc display on irq status
@ AS3935_INTERRUPT_STATUS_DISTURBER_DETECTED
@ AS3935_INTERRUPT_STATUS_LIGHTNING_INTERRUPT
@ AS3935_INTERRUPT_STATUS_NOISE_LEVEL_TOO_HIGH
@ AS3935_INTERFACE_IIC
uint8_t as3935_get_reg(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t as3935_set_reg(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(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]