LibDriver AMG8833
Loading...
Searching...
No Matches
driver_amg8833.c
Go to the documentation of this file.
1
36
37#include "driver_amg8833.h"
38
42#define CHIP_NAME "Panasonic AMG8833"
43#define MANUFACTURER_NAME "Panasonic"
44#define SUPPLY_VOLTAGE_MIN 3.0f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 5.0f
47#define TEMPERATURE_MIN 0.0f
48#define TEMPERATURE_MAX 80.0f
49#define DRIVER_VERSION 1000
50
54#define AMG8833_REG_PCTL 0x00
55#define AMG8833_REG_RST 0x01
56#define AMG8833_REG_FPSC 0x02
57#define AMG8833_REG_INTC 0x03
58#define AMG8833_REG_STAT 0x04
59#define AMG8833_REG_SCLR 0x05
60#define AMG8833_REG_AVE 0x07
61#define AMG8833_REG_INTHL 0x08
62#define AMG8833_REG_INTHH 0x09
63#define AMG8833_REG_INTLL 0x0A
64#define AMG8833_REG_INTLH 0x0B
65#define AMG8833_REG_IHYSL 0x0C
66#define AMG8833_REG_IHYSH 0x0D
67#define AMG8833_REG_TTHL 0x0E
68#define AMG8833_REG_TTHH 0x0F
69#define AMG8833_REG_INT0 0x10
70#define AMG8833_REG_INT1 0x11
71#define AMG8833_REG_INT2 0x12
72#define AMG8833_REG_INT3 0x13
73#define AMG8833_REG_INT4 0x14
74#define AMG8833_REG_INT5 0x15
75#define AMG8833_REG_INT6 0x16
76#define AMG8833_REG_INT7 0x17
77#define AMG8833_REG_T01L 0x80
78#define AMG8833_REG_T01H 0x81
79
91static uint8_t a_amg8833_iic_read(amg8833_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
92{
93 if (handle->iic_read(handle->iic_addr, reg, data, len) != 0) /* read the register */
94 {
95 return 1; /* return error */
96 }
97 else
98 {
99 return 0; /* success return 0 */
100 }
101}
102
114static uint8_t a_amg8833_iic_write(amg8833_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
115{
116 if (handle->iic_write(handle->iic_addr, reg, data, len) != 0) /* write the register */
117 {
118 return 1; /* return error */
119 }
120 else
121 {
122 return 0; /* success return 0 */
123 }
124}
125
136{
137 if (handle == NULL) /* check handle */
138 {
139 return 2; /* return error */
140 }
141
142 handle->iic_addr = (uint8_t)addr_pin; /* set pin */
143
144 return 0; /* success return 0 */
145}
146
157{
158 if (handle == NULL) /* check handle */
159 {
160 return 2; /* return error */
161 }
162
163 *addr_pin = (amg8833_address_t)(handle->iic_addr); /* get pin */
164
165 return 0; /* success return 0 */
166}
167
180{
181 uint8_t res, prev;
182
183 if (handle == NULL) /* check handle */
184 {
185 return 2; /* return error */
186 }
187 if (handle->debug_print == NULL) /* check debug_print */
188 {
189 return 3; /* return error */
190 }
191 if (handle->iic_init == NULL) /* check iic_init */
192 {
193 handle->debug_print("amg8833: iic_init is null.\n"); /* iic_init is null */
194
195 return 3; /* return error */
196 }
197 if (handle->iic_deinit == NULL) /* check iic_deinit */
198 {
199 handle->debug_print("amg8833: iic_deinit is null.\n"); /* iic_deinit is null */
200
201 return 3; /* return error */
202 }
203 if (handle->iic_read == NULL) /* check iic_read */
204 {
205 handle->debug_print("amg8833: iic_read is null.\n"); /* iic_read is null */
206
207 return 3; /* return error */
208 }
209 if (handle->iic_write == NULL) /* check iic_write */
210 {
211 handle->debug_print("amg8833: iic_write is null.\n"); /* iic_write is null */
212
213 return 3; /* return error */
214 }
215 if (handle->delay_ms == NULL) /* check delay_ms */
216 {
217 handle->debug_print("amg8833: delay_ms is null.\n"); /* delay_ms is null */
218
219 return 3; /* return error */
220 }
221 if (handle->receive_callback == NULL) /* check receive_callback */
222 {
223 handle->debug_print("amg8833: receive_callback is null.\n"); /* receive_callback is null */
224
225 return 3; /* return error */
226 }
227 if (handle->iic_init() != 0) /* iic init */
228 {
229 handle->debug_print("amg8833: iic init failed.\n"); /* iic init failed */
230
231 return 3; /* return error */
232 }
233 prev = 0x00; /* normal mode */
234 res = a_amg8833_iic_write(handle, AMG8833_REG_PCTL, (uint8_t *)&prev, 1); /* write pctl register */
235 if (res != 0) /* check result */
236 {
237 handle->debug_print("amg8833: write pctl register failed.\n"); /* write pctl register failed */
238 (void)handle->iic_deinit(); /* iic deinit */
239
240 return 1; /* return error */
241 }
242 handle->delay_ms(50); /* wait 50 ms */
243 prev = 0x3F; /* initial reset */
244 res = a_amg8833_iic_write(handle, AMG8833_REG_RST, (uint8_t *)&prev, 1); /* write rst register */
245 if (res != 0) /* check result */
246 {
247 handle->debug_print("amg8833: write rst register failed.\n"); /* write rst register failed */
248 (void)handle->iic_deinit(); /* iic deinit */
249
250 return 4; /* return error */
251 }
252 handle->delay_ms(2); /* wait 2 ms */
253 prev = 0x30; /* flag reset */
254 res = a_amg8833_iic_write(handle, AMG8833_REG_RST, (uint8_t *)&prev, 1); /* write rst register */
255 if (res != 0) /* check result */
256 {
257 handle->debug_print("amg8833: write rst register failed.\n"); /* write rst register failed */
258 (void)handle->iic_deinit(); /* iic deinit */
259
260 return 4; /* return error */
261 }
262 handle->inited = 1; /* flag finish initialization */
263
264 return 0; /* success return 0 */
265}
266
279{
280 uint8_t res, prev;
281
282 if (handle == NULL) /* check handle */
283 {
284 return 2; /* return error */
285 }
286 if (handle->inited != 1) /* check handle initialization */
287 {
288 return 3; /* return error */
289 }
290
291 prev = 0x10; /* sleep mode*/
292 res = a_amg8833_iic_write(handle, AMG8833_REG_PCTL, (uint8_t *)&prev, 1); /* write pctl register */
293 if (res != 0) /* check result */
294 {
295 handle->debug_print("amg8833: write pctl register failed.\n"); /* write pctl register failed */
296
297 return 4; /* return error */
298 }
299 res = handle->iic_deinit(); /* iic deinit */
300 if (res != 0) /* check result */
301 {
302 handle->debug_print("amg8833: iic deinit failed.\n"); /* iic deinit failed */
303
304 return 4; /* return error */
305 }
306 else
307 {
308 handle->iic_init = 0; /* flag close */
309
310 return 0; /* success return 0 */
311 }
312}
313
325{
326 uint8_t res, prev;
327
328 if (handle == NULL) /* check handle */
329 {
330 return 2; /* return error */
331 }
332 if (handle->inited != 1) /* check handle initialization */
333 {
334 return 3; /* return error */
335 }
336
337 res = a_amg8833_iic_read(handle, AMG8833_REG_STAT, (uint8_t *)&prev, 1); /* read stat register */
338 if (res != 0) /* check result */
339 {
340 handle->debug_print("amg8833: read stat register failed.\n"); /* read stat register failed */
341
342 return 1; /* return error */
343 }
344 res = a_amg8833_iic_write(handle, AMG8833_REG_SCLR, (uint8_t *)&prev, 1); /* write sclr register */
345 if (res != 0) /* check result */
346 {
347 handle->debug_print("amg8833: write sclr register failed.\n"); /* write sclr register failed */
348
349 return 1; /* return error */
350 }
351 if ((prev & (1 << AMG8833_STATUS_INTF)) != 0) /* if interrupt outbreak */
352 {
353 if (handle->receive_callback != NULL) /* if receive callback */
354 {
355 handle->receive_callback(AMG8833_STATUS_INTF); /* run callback */
356 }
357 }
358 if ((prev & (1 << AMG8833_STATUS_OVF_IRS)) != 0) /* if temperature output overflow */
359 {
360 if (handle->receive_callback != NULL) /* if receive callback */
361 {
362 handle->receive_callback(AMG8833_STATUS_OVF_IRS); /* run callback */
363 }
364 }
365 if ((prev & (1 << AMG8833_STATUS_OVF_THS)) != 0) /* if thermistor temperature output overflow */
366 {
367 if (handle->receive_callback != NULL) /* if receive callback */
368 {
369 handle->receive_callback(AMG8833_STATUS_OVF_THS); /* run callback */
370 }
371 }
372
373 return 0; /* success return 0 */
374}
375
388{
389 uint8_t res;
390 uint8_t prev;
391
392 if (handle == NULL) /* check handle */
393 {
394 return 2; /* return error */
395 }
396 if (handle->inited != 1) /* check handle initialization */
397 {
398 return 3; /* return error */
399 }
400
401 prev = mode; /* set the prev */
402 res = a_amg8833_iic_write(handle, AMG8833_REG_PCTL, (uint8_t *)&prev, 1); /* write pctl register */
403 if (res != 0) /* check result */
404 {
405 handle->debug_print("amg8833: write pctl register failed.\n"); /* write pctl register failed */
406
407 return 1; /* return error */
408 }
409
410 return 0; /* success return 0 */
411}
412
425{
426 uint8_t res;
427 uint8_t prev;
428
429 if (handle == NULL) /* check handle */
430 {
431 return 2; /* return error */
432 }
433 if (handle->inited != 1) /* check handle initialization */
434 {
435 return 3; /* return error */
436 }
437
438 res = a_amg8833_iic_read(handle, AMG8833_REG_PCTL, (uint8_t *)&prev, 1); /* read pctl register */
439 if (res != 0) /* check result */
440 {
441 handle->debug_print("amg8833: read pctl register failed.\n"); /* read pctl register failed */
442
443 return 1; /* return error */
444 }
445 *mode = (amg8833_mode_t)(prev); /* set the mode */
446
447 return 0; /* success return 0 */
448}
449
462{
463 uint8_t res;
464 uint8_t prev;
465
466 if (handle == NULL) /* check handle */
467 {
468 return 2; /* return error */
469 }
470 if (handle->inited != 1) /* check handle initialization */
471 {
472 return 3; /* return error */
473 }
474
475 prev = type; /* set the prev */
476 res = a_amg8833_iic_write(handle, AMG8833_REG_RST, (uint8_t *)&prev, 1); /* write rst register */
477 if (res != 0) /* check result */
478 {
479 handle->debug_print("amg8833: write rst register failed.\n"); /* write rst register failed */
480
481 return 1; /* return error */
482 }
483
484 return 0; /* success return 0 */
485}
486
499{
500 uint8_t res;
501 uint8_t prev;
502
503 if (handle == NULL) /* check handle */
504 {
505 return 2; /* return error */
506 }
507 if (handle->inited != 1) /* check handle initialization */
508 {
509 return 3; /* return error */
510 }
511
512 res = a_amg8833_iic_read(handle, AMG8833_REG_FPSC, (uint8_t *)&prev, 1); /* read fpsc register */
513 if (res != 0) /* check result */
514 {
515 handle->debug_print("amg8833: read fpsc register failed.\n"); /* read fpsc register failed */
516
517 return 1; /* return error */
518 }
519 prev &= ~(1 << 0); /* clear the config */
520 prev |= rate << 0; /* set the config */
521 res = a_amg8833_iic_write(handle, AMG8833_REG_FPSC, (uint8_t *)&prev, 1); /* write fpsc register */
522 if (res != 0) /* check result */
523 {
524 handle->debug_print("amg8833: write fpsc register failed.\n"); /* write fpsc register failed */
525
526 return 1; /* return error */
527 }
528
529 return 0; /* success return 0 */
530}
531
544{
545 uint8_t res;
546 uint8_t prev;
547
548 if (handle == NULL) /* check handle */
549 {
550 return 2; /* return error */
551 }
552 if (handle->inited != 1) /* check handle initialization */
553 {
554 return 3; /* return error */
555 }
556
557 res = a_amg8833_iic_read(handle, AMG8833_REG_FPSC, (uint8_t *)&prev, 1); /* read fpsc register */
558 if (res != 0) /* check result */
559 {
560 handle->debug_print("amg8833: read fpsc register failed.\n"); /* read fpsc register failed */
561
562 return 1; /* return error */
563 }
564 *rate = (amg8833_frame_rate_t)((prev >> 0) & 0x01); /* set the rate */
565
566 return 0; /* success return 0 */
567}
568
581{
582 uint8_t res;
583 uint8_t prev;
584
585 if (handle == NULL) /* check handle */
586 {
587 return 2; /* return error */
588 }
589 if (handle->inited != 1) /* check handle initialization */
590 {
591 return 3; /* return error */
592 }
593
594 res = a_amg8833_iic_read(handle, AMG8833_REG_INTC, (uint8_t *)&prev, 1); /* read intc register */
595 if (res != 0) /* check result */
596 {
597 handle->debug_print("amg8833: read intc register failed.\n"); /* read intc register failed */
598
599 return 1; /* return error */
600 }
601 prev &= ~(1 << 1); /* clear the config */
602 prev |= mode << 1; /* set the config */
603 res = a_amg8833_iic_write(handle, AMG8833_REG_INTC, (uint8_t *)&prev, 1); /* write intc register */
604 if (res != 0) /* check result */
605 {
606 handle->debug_print("amg8833: write intc register failed.\n"); /* write intc register failed */
607
608 return 1; /* return error */
609 }
610
611 return 0; /* success return 0 */
612}
613
626{
627 uint8_t res;
628 uint8_t prev;
629
630 if (handle == NULL) /* check handle */
631 {
632 return 2; /* return error */
633 }
634 if (handle->inited != 1) /* check handle initialization */
635 {
636 return 3; /* return error */
637 }
638
639 res = a_amg8833_iic_read(handle, AMG8833_REG_INTC, (uint8_t *)&prev, 1); /* read intc register */
640 if (res != 0) /* check result */
641 {
642 handle->debug_print("amg8833: read intc register failed.\n"); /* read intc register failed */
643
644 return 1; /* return error */
645 }
646 *mode = (amg8833_interrupt_mode_t)((prev >> 1) & 0x01); /* set the mode */
647
648 return 0; /* success return 0 */
649}
650
663{
664 uint8_t res;
665 uint8_t prev;
666
667 if (handle == NULL) /* check handle */
668 {
669 return 2; /* return error */
670 }
671 if (handle->inited != 1) /* check handle initialization */
672 {
673 return 3; /* return error */
674 }
675
676 res = a_amg8833_iic_read(handle, AMG8833_REG_INTC, (uint8_t *)&prev, 1); /* read intc register */
677 if (res != 0) /* check result */
678 {
679 handle->debug_print("amg8833: read intc register failed.\n"); /* read intc register failed */
680
681 return 1; /* return error */
682 }
683 prev &= ~(1 << 0); /* clear the config */
684 prev |= enable << 0; /* set the config */
685 res = a_amg8833_iic_write(handle, AMG8833_REG_INTC, (uint8_t *)&prev, 1); /* write intc register */
686 if (res != 0) /* check result */
687 {
688 handle->debug_print("amg8833: write intc register failed.\n"); /* write intc register failed */
689
690 return 1; /* return error */
691 }
692
693 return 0; /* success return 0 */
694}
695
708{
709 uint8_t res;
710 uint8_t prev;
711
712 if (handle == NULL) /* check handle */
713 {
714 return 2; /* return error */
715 }
716 if (handle->inited != 1) /* check handle initialization */
717 {
718 return 3; /* return error */
719 }
720
721 res = a_amg8833_iic_read(handle, AMG8833_REG_INTC, (uint8_t *)&prev, 1); /* read intc register */
722 if (res != 0) /* check result */
723 {
724 handle->debug_print("amg8833: read intc register failed.\n"); /* read intc register failed */
725
726 return 1; /* return error */
727 }
728 *enable = (amg8833_bool_t)((prev >> 0) & 0x01); /* get the bool */
729
730 return 0; /* success return 0 */
731}
732
744uint8_t amg8833_get_status(amg8833_handle_t *handle, uint8_t *status)
745{
746 uint8_t res;
747 uint8_t prev;
748
749 if (handle == NULL) /* check handle */
750 {
751 return 2; /* return error */
752 }
753 if (handle->inited != 1) /* check handle initialization */
754 {
755 return 3; /* return error */
756 }
757
758 res = a_amg8833_iic_read(handle, AMG8833_REG_STAT, (uint8_t *)&prev, 1); /* read stat register */
759 if (res != 0) /* check result */
760 {
761 handle->debug_print("amg8833: read stat register failed.\n"); /* read stat register failed */
762
763 return 1; /* return error */
764 }
765 *status = prev; /* set the status */
766
767 return 0; /* success return 0 */
768}
769
782{
783 uint8_t res;
784 uint8_t prev;
785
786 if (handle == NULL) /* check handle */
787 {
788 return 2; /* return error */
789 }
790 if (handle->inited != 1) /* check handle initialization */
791 {
792 return 3; /* return error */
793 }
794
795 prev = 1 << status; /* set the command */
796 res = a_amg8833_iic_write(handle, AMG8833_REG_SCLR, (uint8_t *)&prev, 1); /* write sclr register */
797 if (res != 0) /* check result */
798 {
799 handle->debug_print("amg8833: write sclr register failed.\n"); /* write sclr register failed */
800
801 return 1; /* return error */
802 }
803
804 return 0; /* success return 0 */
805}
806
819{
820 uint8_t res;
821 uint8_t prev;
822 uint8_t i;
823 uint8_t unlock_seq[] = {0x50, 0x45, 0x57};
824
825 if (handle == NULL) /* check handle */
826 {
827 return 2; /* return error */
828 }
829 if (handle->inited != 1) /* check handle initialization */
830 {
831 return 3; /* return error */
832 }
833
834 for (i = 0; i < 3; i++) /* write unlock seq */
835 {
836 prev = unlock_seq[i]; /* set seq */
837 res = a_amg8833_iic_write(handle, 0x1F, &prev, 1); /* write command */
838 if (res != 0) /* check result */
839 {
840 handle->debug_print("amg8833: write unlock sequence failed.\n"); /* write unlock sequence failed */
841
842 return 1; /* return error */
843 }
844 }
845
846 res = a_amg8833_iic_read(handle, AMG8833_REG_AVE, (uint8_t *)&prev, 1); /* read ave register */
847 if (res != 0) /* check result */
848 {
849 handle->debug_print("amg8833: read ave register failed.\n"); /* read ave register failed */
850
851 return 1; /* return error */
852 }
853 prev &= ~(1 << 5); /* clear the config */
854 prev |= mode << 5; /* set the config */
855 res = a_amg8833_iic_write(handle, AMG8833_REG_AVE, (uint8_t *)&prev, 1); /* write ave register */
856 if (res != 0) /* check result */
857 {
858 handle->debug_print("amg8833: write ave register failed.\n"); /* write ave register failed */
859
860 return 1; /* return error */
861 }
862
863 prev = 0x00; /* set lock seq */
864 res = a_amg8833_iic_write(handle, 0x1F, &prev, 1); /* write command */
865 if (res != 0) /* check result */
866 {
867 handle->debug_print("amg8833: write lock sequence failed.\n"); /* write lock sequence failed */
868
869 return 1; /* return error */
870 }
871
872 return 0; /* success return 0 */
873}
874
887{
888 uint8_t res;
889 uint8_t prev;
890
891 if (handle == NULL) /* check handle */
892 {
893 return 2; /* return error */
894 }
895 if (handle->inited != 1) /* check handle initialization */
896 {
897 return 3; /* return error */
898 }
899
900 res = a_amg8833_iic_read(handle, AMG8833_REG_AVE, (uint8_t *)&prev, 1); /* read ave register */
901 if (res != 0) /* check result */
902 {
903 handle->debug_print("amg8833: read ave register failed.\n"); /* read ave register failed */
904
905 return 1; /* return error */
906 }
907 *mode = (amg8833_average_mode_t)((prev >> 5) & 0x01); /* set the mode */
908
909 return 0; /* success return 0 */
910}
911
924{
925 uint8_t res;
926 uint8_t buf[2];
927
928 if (handle == NULL) /* check handle */
929 {
930 return 2; /* return error */
931 }
932 if (handle->inited != 1) /* check handle initialization */
933 {
934 return 3; /* return error */
935 }
936
937 buf[0] = (level >> 0) & 0xFF; /* get lower */
938 buf[1] = (level >> 8) & 0xF; /* get upper */
939 res = a_amg8833_iic_write(handle, AMG8833_REG_INTHL, (uint8_t *)&buf[0], 1); /* write inthl register */
940 if (res != 0) /* check result */
941 {
942 handle->debug_print("amg8833: write inthl register failed.\n"); /* write inthl register failed */
943
944 return 1; /* return error */
945 }
946 res = a_amg8833_iic_write(handle, AMG8833_REG_INTHH, (uint8_t *)&buf[1], 1); /* write inthh register */
947 if (res != 0) /* check result */
948 {
949 handle->debug_print("amg8833: write inthh register failed.\n"); /* write inthh register failed */
950
951 return 1; /* return error */
952 }
953
954 return 0; /* success return 0 */
955}
956
969{
970 uint8_t res;
971 uint8_t buf[2];
972
973 if (handle == NULL) /* check handle */
974 {
975 return 2; /* return error */
976 }
977 if (handle->inited != 1) /* check handle initialization */
978 {
979 return 3; /* return error */
980 }
981
982 res = a_amg8833_iic_read(handle, AMG8833_REG_INTHL, (uint8_t *)&buf[0], 1); /* read inthl register */
983 if (res != 0) /* check result */
984 {
985 handle->debug_print("amg8833: read inthl register failed.\n"); /* read inthl register failed */
986
987 return 1; /* return error */
988 }
989 res = a_amg8833_iic_read(handle, AMG8833_REG_INTHH, (uint8_t *)&buf[1], 1); /* read inthh register */
990 if (res != 0) /* check result */
991 {
992 handle->debug_print("amg8833: read inthh register failed.\n"); /* read inthh register failed */
993
994 return 1; /* return error */
995 }
996 if ((buf[1] & (1 << 3)) != 0) /* check negative */
997 {
998 *level = (int16_t)(((uint16_t)(buf[1]) << 8) |
999 ((uint16_t)(0xF) << 12) | (buf[0] << 0)); /* get the level */
1000 }
1001 else
1002 {
1003 *level = (int16_t)(((uint16_t)(buf[1]) << 8) | (buf[0] << 0)); /* get the level */
1004 }
1005
1006 return 0; /* success return 0 */
1007}
1008
1021{
1022 uint8_t res;
1023 uint8_t buf[2];
1024
1025 if (handle == NULL) /* check handle */
1026 {
1027 return 2; /* return error */
1028 }
1029 if (handle->inited != 1) /* check handle initialization */
1030 {
1031 return 3; /* return error */
1032 }
1033
1034 buf[0] = (level >> 0) & 0xFF; /* get lower */
1035 buf[1] = (level >> 8) & 0xF; /* get upper */
1036 res = a_amg8833_iic_write(handle, AMG8833_REG_INTLL, (uint8_t *)&buf[0], 1); /* write intll register */
1037 if (res != 0) /* check result */
1038 {
1039 handle->debug_print("amg8833: write intll register failed.\n"); /* write intll register failed */
1040
1041 return 1; /* return error */
1042 }
1043 res = a_amg8833_iic_write(handle, AMG8833_REG_INTLH, (uint8_t *)&buf[1], 1); /* write intlh register */
1044 if (res != 0) /* check result */
1045 {
1046 handle->debug_print("amg8833: write intlh register failed.\n"); /* write intlh register failed */
1047
1048 return 1; /* return error */
1049 }
1050
1051 return 0; /* success return 0 */
1052}
1053
1066{
1067 uint8_t res;
1068 uint8_t buf[2];
1069
1070 if (handle == NULL) /* check handle */
1071 {
1072 return 2; /* return error */
1073 }
1074 if (handle->inited != 1) /* check handle initialization */
1075 {
1076 return 3; /* return error */
1077 }
1078
1079 res = a_amg8833_iic_read(handle, AMG8833_REG_INTLL, (uint8_t *)&buf[0], 1); /* read intll register */
1080 if (res != 0) /* check result */
1081 {
1082 handle->debug_print("amg8833: read intll register failed.\n"); /* read intll register failed */
1083
1084 return 1; /* return error */
1085 }
1086 res = a_amg8833_iic_read(handle, AMG8833_REG_INTLH, (uint8_t *)&buf[1], 1); /* read intlh register */
1087 if (res != 0) /* check result */
1088 {
1089 handle->debug_print("amg8833: read intlh register failed.\n"); /* read intlh register failed */
1090
1091 return 1; /* return error */
1092 }
1093 if ((buf[1] & (1 << 3)) != 0) /* check negative */
1094 {
1095 *level = (int16_t)(((uint16_t)(buf[1]) << 8) |
1096 ((uint16_t)(0xF) << 12) | (buf[0] << 0)); /* get the level */
1097 }
1098 else
1099 {
1100 *level = (int16_t)(((uint16_t)(buf[1]) << 8) | (buf[0] << 0)); /* get the level */
1101 }
1102
1103 return 0; /* success return 0 */
1104}
1105
1118{
1119 uint8_t res;
1120 uint8_t buf[2];
1121
1122 if (handle == NULL) /* check handle */
1123 {
1124 return 2; /* return error */
1125 }
1126 if (handle->inited != 1) /* check handle initialization */
1127 {
1128 return 3; /* return error */
1129 }
1130
1131 buf[0] = (level >> 0) & 0xFF; /* get lower */
1132 buf[1] = (level >> 8) & 0xF; /* get upper */
1133 res = a_amg8833_iic_write(handle, AMG8833_REG_IHYSL, (uint8_t *)&buf[0], 1); /* write ihysl register */
1134 if (res != 0) /* check result */
1135 {
1136 handle->debug_print("amg8833: write ihysl register failed.\n"); /* write ihysl register failed */
1137
1138 return 1; /* return error */
1139 }
1140 res = a_amg8833_iic_write(handle, AMG8833_REG_IHYSH, (uint8_t *)&buf[1], 1); /* write ihysh register */
1141 if (res != 0) /* check result */
1142 {
1143 handle->debug_print("amg8833: write ihysh register failed.\n"); /* write ihysh register failed */
1144
1145 return 1; /* return error */
1146 }
1147
1148 return 0; /* success return 0 */
1149}
1150
1163{
1164 uint8_t res;
1165 uint8_t buf[2];
1166
1167 if (handle == NULL) /* check handle */
1168 {
1169 return 2; /* return error */
1170 }
1171 if (handle->inited != 1) /* check handle initialization */
1172 {
1173 return 3; /* return error */
1174 }
1175
1176 res = a_amg8833_iic_read(handle, AMG8833_REG_IHYSL, (uint8_t *)&buf[0], 1); /* read ihysl register */
1177 if (res != 0) /* check result */
1178 {
1179 handle->debug_print("amg8833: read ihysl register failed.\n"); /* read ihysl register failed */
1180
1181 return 1; /* return error */
1182 }
1183 res = a_amg8833_iic_read(handle, AMG8833_REG_IHYSH, (uint8_t *)&buf[1], 1); /* read ihysh register */
1184 if (res != 0) /* check result */
1185 {
1186 handle->debug_print("amg8833: read ihysh register failed.\n"); /* read ihysh register failed */
1187
1188 return 1; /* return error */
1189 }
1190 if ((buf[1] & (1 << 3)) != 0) /* check negative */
1191 {
1192 *level = (int16_t)(((uint16_t)(buf[1]) << 8) |
1193 ((uint16_t)(0xF) << 12) | (buf[0] << 0)); /* get the level */
1194 }
1195 else
1196 {
1197 *level = (int16_t)(((uint16_t)(buf[1]) << 8) | (buf[0] << 0)); /* get the level */
1198 }
1199
1200 return 0; /* success return 0 */
1201}
1202
1214uint8_t amg8833_interrupt_level_convert_to_register(amg8833_handle_t *handle, float temp, int16_t *reg)
1215{
1216 if (handle == NULL) /* check handle */
1217 {
1218 return 2; /* return error */
1219 }
1220 if (handle->inited != 1) /* check handle initialization */
1221 {
1222 return 3; /* return error */
1223 }
1224
1225 *reg = (int16_t)(temp / 0.25f); /* convert real data to register data */
1226
1227 return 0; /* success return 0 */
1228}
1229
1241uint8_t amg8833_interrupt_level_convert_to_data(amg8833_handle_t *handle, int16_t reg, float *temp)
1242{
1243 if (handle == NULL) /* check handle */
1244 {
1245 return 2; /* return error */
1246 }
1247 if (handle->inited != 1) /* check handle initialization */
1248 {
1249 return 3; /* return error */
1250 }
1251
1252 *temp = (float)(reg) * 0.25f; /* convert raw data to real data */
1253
1254 return 0; /* success return 0 */
1255}
1256
1269uint8_t amg8833_read_temperature(amg8833_handle_t *handle, int16_t *raw, float *temp)
1270{
1271 uint8_t res;
1272 uint8_t buf[2];
1273 int16_t data;
1274
1275 if (handle == NULL) /* check handle */
1276 {
1277 return 2; /* return error */
1278 }
1279 if (handle->inited != 1) /* check handle initialization */
1280 {
1281 return 3; /* return error */
1282 }
1283
1284 res = a_amg8833_iic_read(handle, AMG8833_REG_TTHL, (uint8_t *)&buf[0], 1); /* read tthl register */
1285 if (res != 0) /* check result */
1286 {
1287 handle->debug_print("amg8833: read tthl register failed.\n"); /* read tthl register failed */
1288
1289 return 1; /* return error */
1290 }
1291 res = a_amg8833_iic_read(handle, AMG8833_REG_TTHH, (uint8_t *)&buf[1], 1); /* read tthh register */
1292 if (res != 0) /* check result */
1293 {
1294 handle->debug_print("amg8833: read tthh register failed.\n"); /* read tthh register failed */
1295
1296 return 1; /* return error */
1297 }
1298 *raw = (int16_t)(((uint16_t)(buf[1] & 0xF) << 8) | (buf[0] << 0)); /* get the raw */
1299 data = (int16_t)(((uint16_t)(buf[1] & 0x7) << 8) | (buf[0] << 0)); /* get the raw */
1300 if ((buf[1] & 0x8) != 0) /* if negative */
1301 {
1302 data = data * (-1); /* x (-1) */
1303 }
1304 *temp = data * 0.0625f; /* convert the temperature */
1305
1306 return 0; /* success return 0 */
1307}
1308
1327uint8_t amg8833_read_temperature_array(amg8833_handle_t *handle, int16_t raw[8][8], float temp[8][8])
1328{
1329 uint8_t res;
1330 uint8_t i;
1331 uint8_t j;
1332 uint8_t buf[128];
1333
1334 if (handle == NULL) /* check handle */
1335 {
1336 return 2; /* return error */
1337 }
1338 if (handle->inited != 1) /* check handle initialization */
1339 {
1340 return 3; /* return error */
1341 }
1342
1343 res = a_amg8833_iic_read(handle, AMG8833_REG_T01L, (uint8_t *)buf, 128); /* read t01l register */
1344 if (res != 0) /* check result */
1345 {
1346 handle->debug_print("amg8833: read t01l register failed.\n"); /* read t01l register failed */
1347
1348 return 1; /* return error */
1349 }
1350 for (i = 0; i < 8; i++) /* run 8 times */
1351 {
1352 for (j = 0; j < 8; j++) /* run 8 times */
1353 {
1354 raw[7 - i][7 - j] = (int16_t)(((uint16_t)buf[i * 16 + j * 2 + 1] << 8) | /* get raw data */
1355 buf[i * 16 + j * 2 + 0]); /* get raw data */
1356 temp[7 - i][7 - j] = (float)raw[7 - i][7 - j] * 0.25f; /* get converted temperature */
1357 }
1358 }
1359
1360 return 0; /* success return 0 */
1361}
1362
1380uint8_t amg8833_get_interrupt_table(amg8833_handle_t *handle, uint8_t table[8][1])
1381{
1382 uint8_t res;
1383
1384 if (handle == NULL) /* check handle */
1385 {
1386 return 2; /* return error */
1387 }
1388 if (handle->inited != 1) /* check handle initialization */
1389 {
1390 return 3; /* return error */
1391 }
1392
1393 res = a_amg8833_iic_read(handle, AMG8833_REG_INT0, (uint8_t *)table[7], 1); /* read int0 register */
1394 if (res != 0) /* check result */
1395 {
1396 handle->debug_print("amg8833: read int0 register failed.\n"); /* read int0 register failed */
1397
1398 return 1; /* return error */
1399 }
1400 res = a_amg8833_iic_read(handle, AMG8833_REG_INT1, (uint8_t *)table[6], 1); /* read int1 register */
1401 if (res != 0) /* check result */
1402 {
1403 handle->debug_print("amg8833: read int1 register failed.\n"); /* read int1 register failed */
1404
1405 return 1; /* return error */
1406 }
1407 res = a_amg8833_iic_read(handle, AMG8833_REG_INT2, (uint8_t *)table[5], 1); /* read int2 register */
1408 if (res != 0) /* check result */
1409 {
1410 handle->debug_print("amg8833: read int2 register failed.\n"); /* read int2 register failed */
1411
1412 return 1; /* return error */
1413 }
1414 res = a_amg8833_iic_read(handle, AMG8833_REG_INT3, (uint8_t *)table[4], 1); /* read int3 register */
1415 if (res != 0) /* check result */
1416 {
1417 handle->debug_print("amg8833: read int3 register failed.\n"); /* read int3 register failed */
1418
1419 return 1; /* return error */
1420 }
1421 res = a_amg8833_iic_read(handle, AMG8833_REG_INT4, (uint8_t *)table[3], 1); /* read int4 register */
1422 if (res != 0) /* check result */
1423 {
1424 handle->debug_print("amg8833: read int4 register failed.\n"); /* read int4 register failed */
1425
1426 return 1; /* return error */
1427 }
1428 res = a_amg8833_iic_read(handle, AMG8833_REG_INT5, (uint8_t *)table[2], 1); /* read int5 register */
1429 if (res != 0) /* check result */
1430 {
1431 handle->debug_print("amg8833: read int5 register failed.\n"); /* read int5 register failed */
1432
1433 return 1; /* return error */
1434 }
1435 res = a_amg8833_iic_read(handle, AMG8833_REG_INT6, (uint8_t *)table[1], 1); /* read int6 register */
1436 if (res != 0) /* check result */
1437 {
1438 handle->debug_print("amg8833: read int6 register failed.\n"); /* read int6 register failed */
1439
1440 return 1; /* return error */
1441 }
1442 res = a_amg8833_iic_read(handle, AMG8833_REG_INT7, (uint8_t *)table[0], 1); /* read int7 register */
1443 if (res != 0) /* check result */
1444 {
1445 handle->debug_print("amg8833: read int7 register failed.\n"); /* read int7 register failed */
1446
1447 return 1; /* return error */
1448 }
1449
1450 return 0; /* success return 0 */
1451}
1452
1466uint8_t amg8833_set_reg(amg8833_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1467{
1468 if (handle == NULL) /* check handle */
1469 {
1470 return 2; /* return error */
1471 }
1472 if (handle->inited != 1) /* check handle initialization */
1473 {
1474 return 3; /* return error */
1475 }
1476
1477 return a_amg8833_iic_write(handle, reg, buf, len); /* write data */
1478}
1479
1493uint8_t amg8833_get_reg(amg8833_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1494{
1495 if (handle == NULL) /* check handle */
1496 {
1497 return 2; /* return error */
1498 }
1499 if (handle->inited != 1) /* check handle initialization */
1500 {
1501 return 3; /* return error */
1502 }
1503
1504 return a_amg8833_iic_read(handle, reg, buf, len); /* read data */
1505}
1506
1516{
1517 if (info == NULL) /* check handle */
1518 {
1519 return 2; /* return error */
1520 }
1521
1522 memset(info, 0, sizeof(amg8833_info_t)); /* initialize amg8833 info structure */
1523 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1524 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1525 strncpy(info->interface, "IIC", 8); /* copy interface name */
1526 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1527 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1528 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1529 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1530 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1531 info->driver_version = DRIVER_VERSION; /* set driver version */
1532
1533 return 0; /* success return 0 */
1534}
#define AMG8833_REG_IHYSH
#define AMG8833_REG_INT2
#define MAX_CURRENT
#define AMG8833_REG_FPSC
#define AMG8833_REG_SCLR
#define AMG8833_REG_INT5
#define AMG8833_REG_STAT
#define AMG8833_REG_TTHL
#define AMG8833_REG_RST
#define SUPPLY_VOLTAGE_MAX
#define AMG8833_REG_INT6
#define AMG8833_REG_INTHL
#define AMG8833_REG_INT3
#define TEMPERATURE_MAX
#define AMG8833_REG_INT7
#define AMG8833_REG_INTLH
#define AMG8833_REG_INT0
#define AMG8833_REG_T01L
#define AMG8833_REG_INTLL
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define AMG8833_REG_PCTL
chip register definition
#define AMG8833_REG_INT1
#define AMG8833_REG_IHYSL
#define AMG8833_REG_AVE
#define AMG8833_REG_INT4
#define AMG8833_REG_TTHH
#define CHIP_NAME
chip information definition
#define AMG8833_REG_INTHH
#define DRIVER_VERSION
#define AMG8833_REG_INTC
driver amg8833 header file
amg8833_address_t
amg8833 address enumeration definition
uint8_t amg8833_get_frame_rate(amg8833_handle_t *handle, amg8833_frame_rate_t *rate)
get the frame rate
amg8833_frame_rate_t
amg8833 frame rate enumeration definition
uint8_t amg8833_set_interrupt(amg8833_handle_t *handle, amg8833_bool_t enable)
enable or disable the interrupt
struct amg8833_handle_s amg8833_handle_t
amg8833 handle structure definition
amg8833_bool_t
amg8833 bool enumeration definition
uint8_t amg8833_get_status(amg8833_handle_t *handle, uint8_t *status)
get the status
uint8_t amg8833_clear_status(amg8833_handle_t *handle, amg8833_status_t status)
clear the interrupt status
amg8833_average_mode_t
amg8833 average mode enumeration definition
uint8_t amg8833_set_addr_pin(amg8833_handle_t *handle, amg8833_address_t addr_pin)
set the iic address pin
amg8833_mode_t
amg8833 mode enumeration definition
uint8_t amg8833_get_mode(amg8833_handle_t *handle, amg8833_mode_t *mode)
get the mode
uint8_t amg8833_get_interrupt_table(amg8833_handle_t *handle, uint8_t table[8][1])
get the interrupt table
uint8_t amg8833_deinit(amg8833_handle_t *handle)
close the chip
struct amg8833_info_s amg8833_info_t
amg8833 information structure definition
uint8_t amg8833_get_interrupt_hysteresis_level(amg8833_handle_t *handle, int16_t *level)
get the interrupt hysteresis level
uint8_t amg8833_interrupt_level_convert_to_data(amg8833_handle_t *handle, int16_t reg, float *temp)
convert the register raw data to the interrupt level
uint8_t amg8833_get_average_mode(amg8833_handle_t *handle, amg8833_average_mode_t *mode)
get the average_mode
uint8_t amg8833_reset(amg8833_handle_t *handle, amg8833_reset_type_t type)
reset the chip
uint8_t amg8833_set_interrupt_low_level(amg8833_handle_t *handle, int16_t level)
set the interrupt low level
uint8_t amg8833_get_interrupt_high_level(amg8833_handle_t *handle, int16_t *level)
get the interrupt high level
uint8_t amg8833_info(amg8833_info_t *info)
get chip's information
uint8_t amg8833_set_interrupt_mode(amg8833_handle_t *handle, amg8833_interrupt_mode_t mode)
set the interrupt mode
uint8_t amg8833_get_interrupt_mode(amg8833_handle_t *handle, amg8833_interrupt_mode_t *mode)
get the interrupt mode
uint8_t amg8833_read_temperature_array(amg8833_handle_t *handle, int16_t raw[8][8], float temp[8][8])
read the temperature array
uint8_t amg8833_set_mode(amg8833_handle_t *handle, amg8833_mode_t mode)
set the mode
uint8_t amg8833_get_addr_pin(amg8833_handle_t *handle, amg8833_address_t *addr_pin)
get the iic address pin
amg8833_reset_type_t
amg8833 reset type enumeration definition
amg8833_interrupt_mode_t
amg8833 interrupt mode enumeration definition
uint8_t amg8833_set_average_mode(amg8833_handle_t *handle, amg8833_average_mode_t mode)
set the average_mode
uint8_t amg8833_set_interrupt_high_level(amg8833_handle_t *handle, int16_t level)
set the interrupt high level
uint8_t amg8833_read_temperature(amg8833_handle_t *handle, int16_t *raw, float *temp)
read the temperature
uint8_t amg8833_get_interrupt_low_level(amg8833_handle_t *handle, int16_t *level)
get the interrupt low level
uint8_t amg8833_irq_handler(amg8833_handle_t *handle)
irq handler
uint8_t amg8833_get_interrupt(amg8833_handle_t *handle, amg8833_bool_t *enable)
get the interrupt status
uint8_t amg8833_set_frame_rate(amg8833_handle_t *handle, amg8833_frame_rate_t rate)
set the frame rate
uint8_t amg8833_interrupt_level_convert_to_register(amg8833_handle_t *handle, float temp, int16_t *reg)
convert the interrupt level to the register raw data
amg8833_status_t
amg8833 status enumeration definition
uint8_t amg8833_set_interrupt_hysteresis_level(amg8833_handle_t *handle, int16_t level)
set the interrupt hysteresis level
uint8_t amg8833_init(amg8833_handle_t *handle)
initialize the chip
@ AMG8833_STATUS_INTF
@ AMG8833_STATUS_OVF_THS
@ AMG8833_STATUS_OVF_IRS
uint8_t amg8833_set_reg(amg8833_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t amg8833_get_reg(amg8833_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]