LibDriver MAX44009
Loading...
Searching...
No Matches
driver_max44009.c
Go to the documentation of this file.
1
36
37#include "driver_max44009.h"
38#include <math.h>
39
43#define CHIP_NAME "Analog Devices MAX44009"
44#define MANUFACTURER_NAME "Analog Devices"
45#define SUPPLY_VOLTAGE_MIN 1.7f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.0016f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 1000
51
55#define MAX44009_REG_INTERRUPT_STATUS 0x00
56#define MAX44009_REG_INTERRUPT_ENABLE 0x01
57#define MAX44009_REG_CONFIGURATION 0x02
58#define MAX44009_REG_LUX_READING_HIGH 0x03
59#define MAX44009_REG_LUX_READING_LOW 0x04
60#define MAX44009_REG_THRESHOLD_UPPER 0x05
61#define MAX44009_REG_THRESHOLD_LOWER 0x06
62#define MAX44009_REG_THRESHOLD_TIMER 0x07
63
75static uint8_t a_max44009_iic_read(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
76{
77 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* read the register */
78 {
79 return 1; /* return error */
80 }
81
82 return 0; /* success return 0 */
83}
84
96static uint8_t a_max44009_iic_write(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
97{
98 if (handle->iic_write(handle->iic_addr, reg, buf, len) != 0) /* write the register */
99 {
100 return 1; /* return error */
101 }
102
103 return 0; /* success return 0 */
104}
105
116{
117 if (handle == NULL) /* check handle */
118 {
119 return 2; /* return error */
120 }
121
122 handle->iic_addr = addr_pin; /* set iic addr */
123
124 return 0; /* success return 0 */
125}
126
137{
138 if (handle == NULL) /* check handle */
139 {
140 return 2; /* return error */
141 }
142
143 *addr_pin = (max44009_address_t)(handle->iic_addr); /*get iic address */
144
145 return 0; /* success return 0 */
146}
147
160{
161 uint8_t res;
162 uint8_t prev;
163
164 if (handle == NULL) /* check handle */
165 {
166 return 2; /* return error */
167 }
168 if (handle->inited != 1) /* check handle initialization */
169 {
170 return 3; /* return error */
171 }
172
173 res = a_max44009_iic_read(handle, MAX44009_REG_INTERRUPT_STATUS, &prev, 1); /* read data */
174 if (res != 0) /* check error */
175 {
176 handle->debug_print("max44009: get interrupt status failed.\n"); /* get interrupt status failed */
177
178 return 1; /* return error */
179 }
180 *enable = (max44009_bool_t)((prev >> 0) & 0x01); /* set bool */
181
182 return 0; /* success return 0 */
183}
184
197{
198 uint8_t res;
199 uint8_t prev;
200
201 if (handle == NULL) /* check handle */
202 {
203 return 2; /* return error */
204 }
205 if (handle->inited != 1) /* check handle initialization */
206 {
207 return 3; /* return error */
208 }
209
210 res = a_max44009_iic_read(handle, MAX44009_REG_INTERRUPT_ENABLE, &prev, 1); /* read data */
211 if (res != 0) /* check error */
212 {
213 handle->debug_print("max44009: get interrupt enable failed.\n"); /* get interrupt enable failed */
214
215 return 1; /* return error */
216 }
217 prev &= ~(1 << 0); /* clear settings */
218 prev |= ((uint8_t)(enable) & 0x01) << 0; /* set bool */
219 res = a_max44009_iic_write(handle, MAX44009_REG_INTERRUPT_ENABLE, &prev, 1); /* write data */
220 if (res != 0) /* check error */
221 {
222 handle->debug_print("max44009: set interrupt enable failed.\n"); /* set interrupt enable failed */
223
224 return 1; /* return error */
225 }
226
227 return 0; /* success return 0 */
228}
229
242{
243 uint8_t res;
244 uint8_t prev;
245
246 if (handle == NULL) /* check handle */
247 {
248 return 2; /* return error */
249 }
250 if (handle->inited != 1) /* check handle initialization */
251 {
252 return 3; /* return error */
253 }
254
255 res = a_max44009_iic_read(handle, MAX44009_REG_INTERRUPT_ENABLE, &prev, 1); /* read data */
256 if (res != 0) /* check error */
257 {
258 handle->debug_print("max44009: get interrupt enable failed.\n"); /* get interrupt enable failed */
259
260 return 1; /* return error */
261 }
262 *enable = (max44009_bool_t)((prev >> 0) & 0x01); /* set bool */
263
264 return 0; /* success return 0 */
265}
266
279{
280 uint8_t res;
281 uint8_t prev;
282
283 if (handle == NULL) /* check handle */
284 {
285 return 2; /* return error */
286 }
287 if (handle->inited != 1) /* check handle initialization */
288 {
289 return 3; /* return error */
290 }
291
292 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
293 if (res != 0) /* check error */
294 {
295 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
296
297 return 1; /* return error */
298 }
299 prev &= ~(1 << 7); /* clear settings */
300 prev |= ((uint8_t)(enable) & 0x01) << 7; /* set bool */
301 res = a_max44009_iic_write(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* write data */
302 if (res != 0) /* check error */
303 {
304 handle->debug_print("max44009: set configuration failed.\n"); /* set configuration failed */
305
306 return 1; /* return error */
307 }
308
309 return 0; /* success return 0 */
310}
311
324{
325 uint8_t res;
326 uint8_t 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_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
338 if (res != 0) /* check error */
339 {
340 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
341
342 return 1; /* return error */
343 }
344 *enable = (max44009_bool_t)((prev >> 7) & 0x1); /* set bool */
345
346 return 0; /* success return 0 */
347}
348
361{
362 uint8_t res;
363 uint8_t prev;
364
365 if (handle == NULL) /* check handle */
366 {
367 return 2; /* return error */
368 }
369 if (handle->inited != 1) /* check handle initialization */
370 {
371 return 3; /* return error */
372 }
373
374 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
375 if (res != 0) /* check error */
376 {
377 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
378
379 return 1; /* return error */
380 }
381 prev &= ~(1 << 6); /* clear settings */
382 prev |= ((uint8_t)(!enable) & 0x01) << 6; /* set bool */
383 res = a_max44009_iic_write(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* write data */
384 if (res != 0) /* check error */
385 {
386 handle->debug_print("max44009: set configuration failed.\n"); /* set configuration failed */
387
388 return 1; /* return error */
389 }
390
391 return 0; /* success return 0 */
392}
393
406{
407 uint8_t res;
408 uint8_t prev;
409
410 if (handle == NULL) /* check handle */
411 {
412 return 2; /* return error */
413 }
414 if (handle->inited != 1) /* check handle initialization */
415 {
416 return 3; /* return error */
417 }
418
419 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
420 if (res != 0) /* check error */
421 {
422 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
423
424 return 1; /* return error */
425 }
426 *enable = (max44009_bool_t)(!((prev >> 6) & 0x1)); /* set bool */
427
428 return 0; /* success return 0 */
429}
430
443{
444 uint8_t res;
445 uint8_t prev;
446
447 if (handle == NULL) /* check handle */
448 {
449 return 2; /* return error */
450 }
451 if (handle->inited != 1) /* check handle initialization */
452 {
453 return 3; /* return error */
454 }
455
456 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
457 if (res != 0) /* check error */
458 {
459 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
460
461 return 1; /* return error */
462 }
463 prev &= ~(1 << 3); /* clear settings */
464 prev |= ((uint8_t)(enable) & 0x01) << 3; /* set bool */
465 res = a_max44009_iic_write(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* write data */
466 if (res != 0) /* check error */
467 {
468 handle->debug_print("max44009: set configuration failed.\n"); /* set configuration failed */
469
470 return 1; /* return error */
471 }
472
473 return 0; /* success return 0 */
474}
475
488{
489 uint8_t res;
490 uint8_t prev;
491
492 if (handle == NULL) /* check handle */
493 {
494 return 2; /* return error */
495 }
496 if (handle->inited != 1) /* check handle initialization */
497 {
498 return 3; /* return error */
499 }
500
501 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
502 if (res != 0) /* check error */
503 {
504 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
505
506 return 1; /* return error */
507 }
508 *enable = (max44009_bool_t)((prev >> 3) & 0x1); /* set bool */
509
510 return 0; /* success return 0 */
511}
512
525{
526 uint8_t res;
527 uint8_t prev;
528
529 if (handle == NULL) /* check handle */
530 {
531 return 2; /* return error */
532 }
533 if (handle->inited != 1) /* check handle initialization */
534 {
535 return 3; /* return error */
536 }
537
538 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
539 if (res != 0) /* check error */
540 {
541 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
542
543 return 1; /* return error */
544 }
545 prev &= ~(7 << 0); /* clear settings */
546 prev |= ((uint8_t)(t) & 0x7) << 0; /* set time */
547 res = a_max44009_iic_write(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* write data */
548 if (res != 0) /* check error */
549 {
550 handle->debug_print("max44009: set configuration failed.\n"); /* set configuration failed */
551
552 return 1; /* return error */
553 }
554
555 return 0; /* success return 0 */
556}
557
570{
571 uint8_t res;
572 uint8_t prev;
573
574 if (handle == NULL) /* check handle */
575 {
576 return 2; /* return error */
577 }
578 if (handle->inited != 1) /* check handle initialization */
579 {
580 return 3; /* return error */
581 }
582
583 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
584 if (res != 0) /* check error */
585 {
586 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
587
588 return 1; /* return error */
589 }
590 *t = (max44009_integration_time_t)((prev >> 0) & 0x7); /* set time */
591
592 return 0; /* success return 0 */
593}
594
607{
608 uint8_t res;
609 uint8_t prev;
610
611 if (handle == NULL) /* check handle */
612 {
613 return 2; /* return error */
614 }
615 if (handle->inited != 1) /* check handle initialization */
616 {
617 return 3; /* return error */
618 }
619
620 prev = threshold; /* set threshold */
621 res = a_max44009_iic_write(handle, MAX44009_REG_THRESHOLD_UPPER, &prev, 1); /* write data */
622 if (res != 0) /* check error */
623 {
624 handle->debug_print("max44009: set upper threshold failed.\n"); /* set upper threshold failed */
625
626 return 1; /* return error */
627 }
628
629 return 0; /* success return 0 */
630}
631
644{
645 uint8_t res;
646 uint8_t prev;
647
648 if (handle == NULL) /* check handle */
649 {
650 return 2; /* return error */
651 }
652 if (handle->inited != 1) /* check handle initialization */
653 {
654 return 3; /* return error */
655 }
656
657 res = a_max44009_iic_read(handle, MAX44009_REG_THRESHOLD_UPPER, &prev, 1); /* read data */
658 if (res != 0) /* check error */
659 {
660 handle->debug_print("max44009: get upper threshold failed.\n"); /* get upper threshold failed */
661
662 return 1; /* return error */
663 }
664 *threshold = prev; /* set threshold */
665
666 return 0; /* success return 0 */
667}
668
681{
682 uint8_t res;
683 uint8_t prev;
684
685 if (handle == NULL) /* check handle */
686 {
687 return 2; /* return error */
688 }
689 if (handle->inited != 1) /* check handle initialization */
690 {
691 return 3; /* return error */
692 }
693
694 prev = threshold; /* set threshold */
695 res = a_max44009_iic_write(handle, MAX44009_REG_THRESHOLD_LOWER, &prev, 1); /* write data */
696 if (res != 0) /* check error */
697 {
698 handle->debug_print("max44009: set lower threshold failed.\n"); /* set lower threshold failed */
699
700 return 1; /* return error */
701 }
702
703 return 0; /* success return 0 */
704}
705
717uint8_t max44009_get_interrupt_low_threshold(max44009_handle_t *handle, uint8_t *threshold)
718{
719 uint8_t res;
720 uint8_t prev;
721
722 if (handle == NULL) /* check handle */
723 {
724 return 2; /* return error */
725 }
726 if (handle->inited != 1) /* check handle initialization */
727 {
728 return 3; /* return error */
729 }
730
731 res = a_max44009_iic_read(handle, MAX44009_REG_THRESHOLD_LOWER, &prev, 1); /* read data */
732 if (res != 0) /* check error */
733 {
734 handle->debug_print("max44009: get lower threshold failed.\n"); /* get lower threshold failed */
735
736 return 1; /* return error */
737 }
738 *threshold = prev; /* set threshold */
739
740 return 0; /* success return 0 */
741}
742
755{
756 uint8_t res;
757 uint8_t prev;
758
759 if (handle == NULL) /* check handle */
760 {
761 return 2; /* return error */
762 }
763 if (handle->inited != 1) /* check handle initialization */
764 {
765 return 3; /* return error */
766 }
767
768 prev = t; /* set threshold timer */
769 res = a_max44009_iic_write(handle, MAX44009_REG_THRESHOLD_TIMER, &prev, 1); /* write data */
770 if (res != 0) /* check error */
771 {
772 handle->debug_print("max44009: set threshold timer failed.\n"); /* set threshold timer failed */
773
774 return 1; /* return error */
775 }
776
777 return 0; /* success return 0 */
778}
779
792{
793 uint8_t res;
794 uint8_t prev;
795
796 if (handle == NULL) /* check handle */
797 {
798 return 2; /* return error */
799 }
800 if (handle->inited != 1) /* check handle initialization */
801 {
802 return 3; /* return error */
803 }
804
805 res = a_max44009_iic_read(handle, MAX44009_REG_THRESHOLD_TIMER, &prev, 1); /* read data */
806 if (res != 0) /* check error */
807 {
808 handle->debug_print("max44009: get threshold timer failed.\n"); /* get threshold timer failed */
809
810 return 1; /* return error */
811 }
812 *t = prev; /* set data */
813
814 return 0; /* success return 0 */
815}
816
828uint8_t max44009_threshold_convert_to_register(max44009_handle_t *handle, float lux, uint8_t *reg)
829{
830 uint16_t remain;
831 int xp;
832 float f;
833 float fraction;
834
835 if (handle == NULL) /* check handle */
836 {
837 return 2; /* return error */
838 }
839 if (handle->inited != 1) /* check handle initialization */
840 {
841 return 3; /* return error */
842 }
843
844 f = lux / 0.045f; /* convert */
845 fraction = frexpf(f, &xp); /* run frexp */
846 while ((xp > 0xF) || (fraction < 240.0f)) /* adjust params */
847 {
848 if (xp == 0) /* reach the min */
849 {
850 break; /* break */
851 }
852 if (fraction * 2.0f > 240.0f) /* reach the max */
853 {
854 break; /* break */
855 }
856 xp--; /* xp-- */
857 fraction *= 2.0f; /* fraction * 2 */
858 }
859 remain = (uint8_t)fraction; /* get the integer part */
860 remain >>= 4; /* right shift */
861 *reg = (((uint8_t)(xp & 0xF)) << 4) | (remain & 0x0F); /* convert real data to register data */
862
863 return 0; /* success return 0 */
864}
865
877uint8_t max44009_threshold_convert_to_data(max44009_handle_t *handle, uint8_t reg, float *lux)
878{
879 uint8_t exponent;
880 uint8_t fractional;
881
882 if (handle == NULL) /* check handle */
883 {
884 return 2; /* return error */
885 }
886 if (handle->inited != 1) /* check handle initialization */
887 {
888 return 3; /* return error */
889 }
890
891 exponent = (reg >> 4) & 0xF; /* set exponent */
892 fractional = (reg & 0xF) << 4; /* set fractional */
893 *lux = 0.045f * powf(2.0f, (float)exponent) * ((float)fractional); /* calculate lux */
894
895 return 0; /* success return 0 */
896}
897
909uint8_t max44009_timer_convert_to_register(max44009_handle_t *handle, float ms, uint8_t *reg)
910{
911 if (handle == NULL) /* check handle */
912 {
913 return 2; /* return error */
914 }
915 if (handle->inited != 1) /* check handle initialization */
916 {
917 return 3; /* return error */
918 }
919
920 *reg = (uint8_t)(ms / 100.0f); /* convert */
921
922 return 0; /* success return 0 */
923}
924
936uint8_t max44009_timer_convert_to_data(max44009_handle_t *handle, uint8_t reg, float *ms)
937{
938 if (handle == NULL) /* check handle */
939 {
940 return 2; /* return error */
941 }
942 if (handle->inited != 1) /* check handle initialization */
943 {
944 return 3; /* return error */
945 }
946
947 *ms = (float)(reg) * 100; /* convert */
948
949 return 0; /* success return 0 */
950}
951
963{
964 if (handle == NULL) /* check handle */
965 {
966 return 2; /* return error */
967 }
968 if (handle->debug_print == NULL) /* check debug_print */
969 {
970 return 3; /* return error */
971 }
972 if (handle->iic_init == NULL) /* check iic_init */
973 {
974 handle->debug_print("max44009: iic_init is null.\n"); /* iic_init is null */
975
976 return 3; /* return error */
977 }
978 if (handle->iic_deinit == NULL) /* check iic_deinit */
979 {
980 handle->debug_print("max44009: iic_deinit is null.\n"); /* iic_deinit is null */
981
982 return 3; /* return error */
983 }
984 if (handle->iic_read == NULL) /* check iic_read */
985 {
986 handle->debug_print("max44009: iic_read is null.\n"); /* iic_read is null */
987
988 return 3; /* return error */
989 }
990 if (handle->iic_write == NULL) /* check iic_write */
991 {
992 handle->debug_print("max44009: iic_write is null.\n"); /* iic_write is null */
993
994 return 3; /* return error */
995 }
996 if (handle->delay_ms == NULL) /* check delay_ms */
997 {
998 handle->debug_print("max44009: delay_ms is null.\n"); /* delay_ms is null */
999
1000 return 3; /* return error */
1001 }
1002
1003 if (handle->iic_init() != 0) /* iic init */
1004 {
1005 handle->debug_print("max44009: iic init failed.\n"); /* iic init failed */
1006
1007 return 1; /* return error */
1008 }
1009
1010 handle->inited = 1; /* flag finish initialization */
1011
1012 return 0; /* success return 0 */
1013}
1014
1027{
1028 uint8_t res;
1029 uint8_t prev;
1030
1031 if (handle == NULL) /* check handle */
1032 {
1033 return 2; /* return error */
1034 }
1035 if (handle->inited != 1) /* check handle initialization */
1036 {
1037 return 3; /* return error */
1038 }
1039
1040 res = a_max44009_iic_read(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* read data */
1041 if (res != 0) /* check error */
1042 {
1043 handle->debug_print("max44009: get configuration failed.\n"); /* get configuration failed */
1044
1045 return 4; /* return error */
1046 }
1047 prev &= ~(1 << 7); /* clear settings */
1048 res = a_max44009_iic_write(handle, MAX44009_REG_CONFIGURATION, &prev, 1); /* write data */
1049 if (res != 0) /* check error */
1050 {
1051 handle->debug_print("max44009: set configuration failed.\n"); /* set configuration failed */
1052
1053 return 4; /* return error */
1054 }
1055 res = handle->iic_deinit(); /* iic deinit */
1056 if (res != 0) /* check error */
1057 {
1058 handle->debug_print("max44009: iic deinit failed.\n"); /* iic deinit failed */
1059
1060 return 1; /* return error */
1061 }
1062 handle->inited = 0; /* flag closed */
1063
1064 return 0; /* success return 0 */
1065}
1066
1079uint8_t max44009_read(max44009_handle_t *handle, uint16_t *raw, float *lux)
1080{
1081 uint8_t res;
1082 uint8_t exponent;
1083 uint8_t mantissa;
1084 uint8_t buf[2];
1085
1086 if (handle == NULL) /* check handle */
1087 {
1088 return 2; /* return error */
1089 }
1090 if (handle->inited != 1) /* check handle initialization */
1091 {
1092 return 3; /* return error */
1093 }
1094
1095 res = a_max44009_iic_read(handle, MAX44009_REG_LUX_READING_HIGH, buf, 2); /* read data */
1096 if (res != 0) /* check error */
1097 {
1098 handle->debug_print("max44009: read data failed.\n"); /* read data failed */
1099
1100 return 1; /* return error */
1101 }
1102 *raw = (uint16_t)((uint16_t)(buf[0]) << 8) | buf[1]; /* set raw output */
1103 exponent = (buf[0] >> 4) & 0xF; /* get exponent */
1104 mantissa = ((buf[0] & 0xF) << 4) | (buf[1] & 0x0F); /* get mantissa */
1105 *lux = powf(2.0f, (float)exponent) * (float)mantissa * 0.045f; /* convert to lux */
1106
1107 return 0; /* success return 0 */
1108}
1109
1123uint8_t max44009_set_reg(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1124{
1125 if (handle == NULL) /* check handle */
1126 {
1127 return 2; /* return error */
1128 }
1129 if (handle->inited != 1) /* check handle initialization */
1130 {
1131 return 3; /* return error */
1132 }
1133
1134 if (a_max44009_iic_write(handle, reg, buf, len) != 0) /* iic write */
1135 {
1136 handle->debug_print("max44009: set reg failed.\n"); /* set reg failed */
1137
1138 return 1; /* return error */
1139 }
1140
1141 return 0; /* success return 0 */
1142}
1143
1157uint8_t max44009_get_reg(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1158{
1159 if (handle == NULL) /* check handle */
1160 {
1161 return 2; /* return error */
1162 }
1163 if (handle->inited != 1) /* check handle initialization */
1164 {
1165 return 3; /* return error */
1166 }
1167
1168 if (a_max44009_iic_read(handle, reg, buf, len) != 0) /* iic read */
1169 {
1170 handle->debug_print("max44009: get reg failed.\n"); /* get reg failed */
1171
1172 return 1; /* return error */
1173 }
1174
1175 return 0; /* success return 0 */
1176}
1177
1187{
1188 if (info == NULL) /* check handle */
1189 {
1190 return 2; /* return error */
1191 }
1192
1193 memset(info, 0, sizeof(max44009_info_t)); /* initialize max44009 info structure */
1194 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1195 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1196 strncpy(info->interface, "IIC", 8); /* copy interface name */
1197 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1198 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1199 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1200 info->temperature_max = TEMPERATURE_MAX; /* set maximum temperature */
1201 info->temperature_min = TEMPERATURE_MIN; /* set minimal temperature */
1202 info->driver_version = DRIVER_VERSION; /* set driver version */
1203
1204 return 0; /* success return 0 */
1205}
#define MAX44009_REG_LUX_READING_HIGH
#define MAX44009_REG_INTERRUPT_ENABLE
#define MAX_CURRENT
#define MAX44009_REG_THRESHOLD_UPPER
#define MAX44009_REG_INTERRUPT_STATUS
chip register definition
#define MAX44009_REG_THRESHOLD_TIMER
#define SUPPLY_VOLTAGE_MAX
#define MAX44009_REG_THRESHOLD_LOWER
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define MAX44009_REG_CONFIGURATION
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver max44009 header file
uint8_t max44009_get_current_div_8(max44009_handle_t *handle, max44009_bool_t *enable)
get current div 8
uint8_t max44009_read(max44009_handle_t *handle, uint16_t *raw, float *lux)
read data
uint8_t max44009_set_integration_time(max44009_handle_t *handle, max44009_integration_time_t t)
set integration time
uint8_t max44009_get_interrupt(max44009_handle_t *handle, max44009_bool_t *enable)
get interrupt status
max44009_integration_time_t
max44009 integration time enumeration definition
uint8_t max44009_timer_convert_to_data(max44009_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to timer
uint8_t max44009_set_current_div_8(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable current div 8
uint8_t max44009_get_interrupt_status(max44009_handle_t *handle, max44009_bool_t *enable)
get interrupt status
uint8_t max44009_set_interrupt_high_threshold(max44009_handle_t *handle, uint8_t threshold)
set interrupt high threshold
uint8_t max44009_get_interrupt_high_threshold(max44009_handle_t *handle, uint8_t *threshold)
get interrupt high threshold
uint8_t max44009_get_addr_pin(max44009_handle_t *handle, max44009_address_t *addr_pin)
get the address pin
struct max44009_handle_s max44009_handle_t
max44009 handle structure definition
uint8_t max44009_threshold_convert_to_register(max44009_handle_t *handle, float lux, uint8_t *reg)
convert the threshold to the register raw data
uint8_t max44009_get_auto_range(max44009_handle_t *handle, max44009_bool_t *enable)
get auto range
uint8_t max44009_set_addr_pin(max44009_handle_t *handle, max44009_address_t addr_pin)
set the address pin
uint8_t max44009_get_threshold_timer(max44009_handle_t *handle, uint8_t *t)
get threshold timer
uint8_t max44009_set_interrupt_low_threshold(max44009_handle_t *handle, uint8_t threshold)
set interrupt low threshold
uint8_t max44009_info(max44009_info_t *info)
get chip's information
struct max44009_info_s max44009_info_t
max44009 information structure definition
uint8_t max44009_set_continuous_mode(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable continuous mode
uint8_t max44009_get_continuous_mode(max44009_handle_t *handle, max44009_bool_t *enable)
get continuous mode stauts
max44009_address_t
max44009 address enumeration definition
uint8_t max44009_threshold_convert_to_data(max44009_handle_t *handle, uint8_t reg, float *lux)
convert the register raw data to the threshold
uint8_t max44009_set_interrupt(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable interrupt
uint8_t max44009_get_integration_time(max44009_handle_t *handle, max44009_integration_time_t *t)
get integration time
uint8_t max44009_deinit(max44009_handle_t *handle)
close the chip
uint8_t max44009_init(max44009_handle_t *handle)
initialize the chip
uint8_t max44009_get_interrupt_low_threshold(max44009_handle_t *handle, uint8_t *threshold)
get interrupt low threshold
uint8_t max44009_set_auto_range(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable auto range
uint8_t max44009_set_threshold_timer(max44009_handle_t *handle, uint8_t t)
set threshold timer
max44009_bool_t
max44009 bool enumeration definition
uint8_t max44009_timer_convert_to_register(max44009_handle_t *handle, float ms, uint8_t *reg)
convert the timer to the register raw data
uint8_t max44009_set_reg(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t max44009_get_reg(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
char manufacturer_name[32]