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 -20.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
823 if (handle == NULL) /* check handle */
824 {
825 return 2; /* return error */
826 }
827 if (handle->inited != 1) /* check handle initialization */
828 {
829 return 3; /* return error */
830 }
831
832 res = a_amg8833_iic_read(handle, AMG8833_REG_AVE, (uint8_t *)&prev, 1); /* read ave register */
833 if (res != 0) /* check result */
834 {
835 handle->debug_print("amg8833: read ave register failed.\n"); /* read ave register failed */
836
837 return 1; /* return error */
838 }
839 prev &= ~(1 << 5); /* clear the config */
840 prev |= mode << 5; /* set the config */
841 res = a_amg8833_iic_write(handle, AMG8833_REG_AVE, (uint8_t *)&prev, 1); /* write ave register */
842 if (res != 0) /* check result */
843 {
844 handle->debug_print("amg8833: write ave register failed.\n"); /* write ave register failed */
845
846 return 1; /* return error */
847 }
848
849 return 0; /* success return 0 */
850}
851
864{
865 uint8_t res;
866 uint8_t prev;
867
868 if (handle == NULL) /* check handle */
869 {
870 return 2; /* return error */
871 }
872 if (handle->inited != 1) /* check handle initialization */
873 {
874 return 3; /* return error */
875 }
876
877 res = a_amg8833_iic_read(handle, AMG8833_REG_AVE, (uint8_t *)&prev, 1); /* read ave register */
878 if (res != 0) /* check result */
879 {
880 handle->debug_print("amg8833: read ave register failed.\n"); /* read ave register failed */
881
882 return 1; /* return error */
883 }
884 *mode = (amg8833_average_mode_t)((prev >> 5) & 0x01); /* set the mode */
885
886 return 0; /* success return 0 */
887}
888
901{
902 uint8_t res;
903 uint8_t buf[2];
904
905 if (handle == NULL) /* check handle */
906 {
907 return 2; /* return error */
908 }
909 if (handle->inited != 1) /* check handle initialization */
910 {
911 return 3; /* return error */
912 }
913
914 buf[0] = (level >> 0) & 0xFF; /* get lower */
915 buf[1] = (level >> 8) & 0xF; /* get upper */
916 res = a_amg8833_iic_write(handle, AMG8833_REG_INTHL, (uint8_t *)&buf[0], 1); /* write inthl register */
917 if (res != 0) /* check result */
918 {
919 handle->debug_print("amg8833: write inthl register failed.\n"); /* write inthl register failed */
920
921 return 1; /* return error */
922 }
923 res = a_amg8833_iic_write(handle, AMG8833_REG_INTHH, (uint8_t *)&buf[1], 1); /* write inthh register */
924 if (res != 0) /* check result */
925 {
926 handle->debug_print("amg8833: write inthh register failed.\n"); /* write inthh register failed */
927
928 return 1; /* return error */
929 }
930
931 return 0; /* success return 0 */
932}
933
946{
947 uint8_t res;
948 uint8_t buf[2];
949
950 if (handle == NULL) /* check handle */
951 {
952 return 2; /* return error */
953 }
954 if (handle->inited != 1) /* check handle initialization */
955 {
956 return 3; /* return error */
957 }
958
959 res = a_amg8833_iic_read(handle, AMG8833_REG_INTHL, (uint8_t *)&buf[0], 1); /* read inthl register */
960 if (res != 0) /* check result */
961 {
962 handle->debug_print("amg8833: read inthl register failed.\n"); /* read inthl register failed */
963
964 return 1; /* return error */
965 }
966 res = a_amg8833_iic_read(handle, AMG8833_REG_INTHH, (uint8_t *)&buf[1], 1); /* read inthh register */
967 if (res != 0) /* check result */
968 {
969 handle->debug_print("amg8833: read inthh register failed.\n"); /* read inthh register failed */
970
971 return 1; /* return error */
972 }
973 if ((buf[1] & (1 << 3)) != 0) /* check negative */
974 {
975 *level = (int16_t)(((uint16_t)(buf[1]) << 8) |
976 ((uint16_t)(0xF) << 12) | (buf[0] << 0)); /* get the level */
977 }
978 else
979 {
980 *level = (int16_t)(((uint16_t)(buf[1]) << 8) | (buf[0] << 0)); /* get the level */
981 }
982
983 return 0; /* success return 0 */
984}
985
998{
999 uint8_t res;
1000 uint8_t buf[2];
1001
1002 if (handle == NULL) /* check handle */
1003 {
1004 return 2; /* return error */
1005 }
1006 if (handle->inited != 1) /* check handle initialization */
1007 {
1008 return 3; /* return error */
1009 }
1010
1011 buf[0] = (level >> 0) & 0xFF; /* get lower */
1012 buf[1] = (level >> 8) & 0xF; /* get upper */
1013 res = a_amg8833_iic_write(handle, AMG8833_REG_INTLL, (uint8_t *)&buf[0], 1); /* write intll register */
1014 if (res != 0) /* check result */
1015 {
1016 handle->debug_print("amg8833: write intll register failed.\n"); /* write intll register failed */
1017
1018 return 1; /* return error */
1019 }
1020 res = a_amg8833_iic_write(handle, AMG8833_REG_INTLH, (uint8_t *)&buf[1], 1); /* write intlh register */
1021 if (res != 0) /* check result */
1022 {
1023 handle->debug_print("amg8833: write intlh register failed.\n"); /* write intlh register failed */
1024
1025 return 1; /* return error */
1026 }
1027
1028 return 0; /* success return 0 */
1029}
1030
1043{
1044 uint8_t res;
1045 uint8_t buf[2];
1046
1047 if (handle == NULL) /* check handle */
1048 {
1049 return 2; /* return error */
1050 }
1051 if (handle->inited != 1) /* check handle initialization */
1052 {
1053 return 3; /* return error */
1054 }
1055
1056 res = a_amg8833_iic_read(handle, AMG8833_REG_INTLL, (uint8_t *)&buf[0], 1); /* read intll register */
1057 if (res != 0) /* check result */
1058 {
1059 handle->debug_print("amg8833: read intll register failed.\n"); /* read intll register failed */
1060
1061 return 1; /* return error */
1062 }
1063 res = a_amg8833_iic_read(handle, AMG8833_REG_INTLH, (uint8_t *)&buf[1], 1); /* read intlh register */
1064 if (res != 0) /* check result */
1065 {
1066 handle->debug_print("amg8833: read intlh register failed.\n"); /* read intlh register failed */
1067
1068 return 1; /* return error */
1069 }
1070 if ((buf[1] & (1 << 3)) != 0) /* check negative */
1071 {
1072 *level = (int16_t)(((uint16_t)(buf[1]) << 8) |
1073 ((uint16_t)(0xF) << 12) | (buf[0] << 0)); /* get the level */
1074 }
1075 else
1076 {
1077 *level = (int16_t)(((uint16_t)(buf[1]) << 8) | (buf[0] << 0)); /* get the level */
1078 }
1079
1080 return 0; /* success return 0 */
1081}
1082
1095{
1096 uint8_t res;
1097 uint8_t buf[2];
1098
1099 if (handle == NULL) /* check handle */
1100 {
1101 return 2; /* return error */
1102 }
1103 if (handle->inited != 1) /* check handle initialization */
1104 {
1105 return 3; /* return error */
1106 }
1107
1108 buf[0] = (level >> 0) & 0xFF; /* get lower */
1109 buf[1] = (level >> 8) & 0xF; /* get upper */
1110 res = a_amg8833_iic_write(handle, AMG8833_REG_IHYSL, (uint8_t *)&buf[0], 1); /* write ihysl register */
1111 if (res != 0) /* check result */
1112 {
1113 handle->debug_print("amg8833: write ihysl register failed.\n"); /* write ihysl register failed */
1114
1115 return 1; /* return error */
1116 }
1117 res = a_amg8833_iic_write(handle, AMG8833_REG_IHYSH, (uint8_t *)&buf[1], 1); /* write ihysh register */
1118 if (res != 0) /* check result */
1119 {
1120 handle->debug_print("amg8833: write ihysh register failed.\n"); /* write ihysh register failed */
1121
1122 return 1; /* return error */
1123 }
1124
1125 return 0; /* success return 0 */
1126}
1127
1140{
1141 uint8_t res;
1142 uint8_t buf[2];
1143
1144 if (handle == NULL) /* check handle */
1145 {
1146 return 2; /* return error */
1147 }
1148 if (handle->inited != 1) /* check handle initialization */
1149 {
1150 return 3; /* return error */
1151 }
1152
1153 res = a_amg8833_iic_read(handle, AMG8833_REG_IHYSL, (uint8_t *)&buf[0], 1); /* read ihysl register */
1154 if (res != 0) /* check result */
1155 {
1156 handle->debug_print("amg8833: read ihysl register failed.\n"); /* read ihysl register failed */
1157
1158 return 1; /* return error */
1159 }
1160 res = a_amg8833_iic_read(handle, AMG8833_REG_IHYSH, (uint8_t *)&buf[1], 1); /* read ihysh register */
1161 if (res != 0) /* check result */
1162 {
1163 handle->debug_print("amg8833: read ihysh register failed.\n"); /* read ihysh register failed */
1164
1165 return 1; /* return error */
1166 }
1167 if ((buf[1] & (1 << 3)) != 0) /* check negative */
1168 {
1169 *level = (int16_t)(((uint16_t)(buf[1]) << 8) |
1170 ((uint16_t)(0xF) << 12) | (buf[0] << 0)); /* get the level */
1171 }
1172 else
1173 {
1174 *level = (int16_t)(((uint16_t)(buf[1]) << 8) | (buf[0] << 0)); /* get the level */
1175 }
1176
1177 return 0; /* success return 0 */
1178}
1179
1191uint8_t amg8833_interrupt_level_convert_to_register(amg8833_handle_t *handle, float temp, int16_t *reg)
1192{
1193 if (handle == NULL) /* check handle */
1194 {
1195 return 2; /* return error */
1196 }
1197 if (handle->inited != 1) /* check handle initialization */
1198 {
1199 return 3; /* return error */
1200 }
1201
1202 *reg = (int16_t)(temp / 0.25f); /* convert real data to register data */
1203
1204 return 0; /* success return 0 */
1205}
1206
1218uint8_t amg8833_interrupt_level_convert_to_data(amg8833_handle_t *handle, int16_t reg, float *temp)
1219{
1220 if (handle == NULL) /* check handle */
1221 {
1222 return 2; /* return error */
1223 }
1224 if (handle->inited != 1) /* check handle initialization */
1225 {
1226 return 3; /* return error */
1227 }
1228
1229 *temp = (float)(reg) * 0.25f; /* convert raw data to real data */
1230
1231 return 0; /* success return 0 */
1232}
1233
1246uint8_t amg8833_read_temperature(amg8833_handle_t *handle, int16_t *raw, float *temp)
1247{
1248 uint8_t res;
1249 uint8_t buf[2];
1250 int16_t data;
1251
1252 if (handle == NULL) /* check handle */
1253 {
1254 return 2; /* return error */
1255 }
1256 if (handle->inited != 1) /* check handle initialization */
1257 {
1258 return 3; /* return error */
1259 }
1260
1261 res = a_amg8833_iic_read(handle, AMG8833_REG_TTHL, (uint8_t *)&buf[0], 1); /* read tthl register */
1262 if (res != 0) /* check result */
1263 {
1264 handle->debug_print("amg8833: read tthl register failed.\n"); /* read tthl register failed */
1265
1266 return 1; /* return error */
1267 }
1268 res = a_amg8833_iic_read(handle, AMG8833_REG_TTHH, (uint8_t *)&buf[1], 1); /* read tthh register */
1269 if (res != 0) /* check result */
1270 {
1271 handle->debug_print("amg8833: read tthh register failed.\n"); /* read tthh register failed */
1272
1273 return 1; /* return error */
1274 }
1275 *raw = (int16_t)(((uint16_t)(buf[1] & 0xF) << 8) | (buf[0] << 0)); /* get the raw */
1276 data = (int16_t)(((uint16_t)(buf[1] & 0x7) << 8) | (buf[0] << 0)); /* get the raw */
1277 if ((buf[1] & 0x8) != 0) /* if negative */
1278 {
1279 data = data * (-1); /* x (-1) */
1280 }
1281 *temp = data * 0.0625f; /* convert the temperature */
1282
1283 return 0; /* success return 0 */
1284}
1285
1304uint8_t amg8833_read_temperature_array(amg8833_handle_t *handle, int16_t raw[8][8], float temp[8][8])
1305{
1306 uint8_t res;
1307 uint8_t i;
1308 uint8_t j;
1309 uint8_t buf[128];
1310
1311 if (handle == NULL) /* check handle */
1312 {
1313 return 2; /* return error */
1314 }
1315 if (handle->inited != 1) /* check handle initialization */
1316 {
1317 return 3; /* return error */
1318 }
1319
1320 res = a_amg8833_iic_read(handle, AMG8833_REG_T01L, (uint8_t *)buf, 128); /* read t01l register */
1321 if (res != 0) /* check result */
1322 {
1323 handle->debug_print("amg8833: read t01l register failed.\n"); /* read t01l register failed */
1324
1325 return 1; /* return error */
1326 }
1327 for (i = 0; i < 8; i++) /* run 8 times */
1328 {
1329 for (j = 0; j < 8; j++) /* run 8 times */
1330 {
1331 raw[7 - i][7 - j] = (int16_t)(((uint16_t)buf[i * 16 + j * 2 + 1] << 8) | /* get raw data */
1332 buf[i * 16 + j * 2 + 0]); /* get raw data */
1333 temp[7 - i][7 - j] = (float)raw[7 - i][7 - j] * 0.25f; /* get converted temperature */
1334 }
1335 }
1336
1337 return 0; /* success return 0 */
1338}
1339
1357uint8_t amg8833_get_interrupt_table(amg8833_handle_t *handle, uint8_t table[8][1])
1358{
1359 uint8_t res;
1360
1361 if (handle == NULL) /* check handle */
1362 {
1363 return 2; /* return error */
1364 }
1365 if (handle->inited != 1) /* check handle initialization */
1366 {
1367 return 3; /* return error */
1368 }
1369
1370 res = a_amg8833_iic_read(handle, AMG8833_REG_INT0, (uint8_t *)table[7], 1); /* read int0 register */
1371 if (res != 0) /* check result */
1372 {
1373 handle->debug_print("amg8833: read int0 register failed.\n"); /* read int0 register failed */
1374
1375 return 1; /* return error */
1376 }
1377 res = a_amg8833_iic_read(handle, AMG8833_REG_INT1, (uint8_t *)table[6], 1); /* read int1 register */
1378 if (res != 0) /* check result */
1379 {
1380 handle->debug_print("amg8833: read int1 register failed.\n"); /* read int1 register failed */
1381
1382 return 1; /* return error */
1383 }
1384 res = a_amg8833_iic_read(handle, AMG8833_REG_INT2, (uint8_t *)table[5], 1); /* read int2 register */
1385 if (res != 0) /* check result */
1386 {
1387 handle->debug_print("amg8833: read int2 register failed.\n"); /* read int2 register failed */
1388
1389 return 1; /* return error */
1390 }
1391 res = a_amg8833_iic_read(handle, AMG8833_REG_INT3, (uint8_t *)table[4], 1); /* read int3 register */
1392 if (res != 0) /* check result */
1393 {
1394 handle->debug_print("amg8833: read int3 register failed.\n"); /* read int3 register failed */
1395
1396 return 1; /* return error */
1397 }
1398 res = a_amg8833_iic_read(handle, AMG8833_REG_INT4, (uint8_t *)table[3], 1); /* read int4 register */
1399 if (res != 0) /* check result */
1400 {
1401 handle->debug_print("amg8833: read int4 register failed.\n"); /* read int4 register failed */
1402
1403 return 1; /* return error */
1404 }
1405 res = a_amg8833_iic_read(handle, AMG8833_REG_INT5, (uint8_t *)table[2], 1); /* read int5 register */
1406 if (res != 0) /* check result */
1407 {
1408 handle->debug_print("amg8833: read int5 register failed.\n"); /* read int5 register failed */
1409
1410 return 1; /* return error */
1411 }
1412 res = a_amg8833_iic_read(handle, AMG8833_REG_INT6, (uint8_t *)table[1], 1); /* read int6 register */
1413 if (res != 0) /* check result */
1414 {
1415 handle->debug_print("amg8833: read int6 register failed.\n"); /* read int6 register failed */
1416
1417 return 1; /* return error */
1418 }
1419 res = a_amg8833_iic_read(handle, AMG8833_REG_INT7, (uint8_t *)table[0], 1); /* read int7 register */
1420 if (res != 0) /* check result */
1421 {
1422 handle->debug_print("amg8833: read int7 register failed.\n"); /* read int7 register failed */
1423
1424 return 1; /* return error */
1425 }
1426
1427 return 0; /* success return 0 */
1428}
1429
1443uint8_t amg8833_set_reg(amg8833_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1444{
1445 if (handle == NULL) /* check handle */
1446 {
1447 return 2; /* return error */
1448 }
1449 if (handle->inited != 1) /* check handle initialization */
1450 {
1451 return 3; /* return error */
1452 }
1453
1454 return a_amg8833_iic_write(handle, reg, buf, len); /* write data */
1455}
1456
1470uint8_t amg8833_get_reg(amg8833_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1471{
1472 if (handle == NULL) /* check handle */
1473 {
1474 return 2; /* return error */
1475 }
1476 if (handle->inited != 1) /* check handle initialization */
1477 {
1478 return 3; /* return error */
1479 }
1480
1481 return a_amg8833_iic_read(handle, reg, buf, len); /* read data */
1482}
1483
1493{
1494 if (info == NULL) /* check handle */
1495 {
1496 return 2; /* return error */
1497 }
1498
1499 memset(info, 0, sizeof(amg8833_info_t)); /* initialize amg8833 info structure */
1500 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1501 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1502 strncpy(info->interface, "IIC", 8); /* copy interface name */
1503 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1504 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1505 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1506 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1507 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1508 info->driver_version = DRIVER_VERSION; /* set driver version */
1509
1510 return 0; /* success return 0 */
1511}
#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]