LibDriver PCF8591
Loading...
Searching...
No Matches
driver_pcf8591.c
Go to the documentation of this file.
1
37
38#include "driver_pcf8591.h"
39
43#define CHIP_NAME "NXP PCF8591"
44#define MANUFACTURER_NAME "NXP"
45#define SUPPLY_VOLTAGE_MIN 2.5f
46#define SUPPLY_VOLTAGE_MAX 6.0f
47#define MAX_CURRENT 50.0f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
51
62{
63 if (handle == NULL) /* check handle */
64 {
65 return 2; /* return error */
66 }
67
68 handle->iic_addr = 0x90; /* set iic addr */
69 handle->iic_addr |= addr_pin << 1; /* set iic address */
70
71 return 0; /* success return 0 */
72}
73
84{
85 if (handle == NULL) /* check handle */
86 {
87 return 2; /* return error */
88 }
89
90 *addr_pin = (pcf8591_address_t)((handle->iic_addr & (~0x90)) >> 1); /*get iic address */
91
92 return 0; /* success return 0 */
93}
94
107{
108 uint8_t res;
109 uint8_t prev_conf;
110
111 if (handle == NULL) /* check handle */
112 {
113 return 2; /* return error */
114 }
115 if (handle->inited != 1) /* check handle initialization */
116 {
117 return 3; /* return error */
118 }
119
120 prev_conf = handle->conf; /* save conf */
121 handle->conf &= ~(3 << 0); /* clear channel bits */
122 handle->conf |= channel << 0; /* set channel */
123 res = handle->iic_write_cmd(handle->iic_addr, (uint8_t *)&handle->conf, 1); /* write command */
124 if (res != 0) /* check error */
125 {
126 handle->debug_print("pcf8591: write command failed.\n"); /* write command failed */
127 handle->conf = prev_conf; /* recover conf */
128
129 return 1; /* return error */
130 }
131
132 return 0; /* success return 0 */
133}
134
146{
147 if (handle == NULL) /* check handle */
148 {
149 return 2; /* return error */
150 }
151 if (handle->inited != 1) /* check handle initialization */
152 {
153 return 3; /* return error */
154 }
155
156 *channel = (pcf8591_channel_t)(handle->conf & (3 << 0)); /* get channel */
157
158 return 0; /* success return 0 */
159}
160
173{
174 uint8_t res;
175 uint8_t prev_conf;
176
177 if (handle == NULL) /* check handle */
178 {
179 return 2; /* return error */
180 }
181 if (handle->inited != 1) /* check handle initialization */
182 {
183 return 3; /* return error */
184 }
185
186 prev_conf = handle->conf; /* save conf */
187 handle->conf &= ~(3 << 4); /* clear mode bits */
188 handle->conf |= mode << 4; /* set mode */
189 res = handle->iic_write_cmd(handle->iic_addr, (uint8_t *)&handle->conf, 1); /* write command */
190 if (res != 0) /* check error */
191 {
192 handle->debug_print("pcf8591: write command failed.\n"); /* write command failed */
193 handle->conf = prev_conf; /* recover conf */
194
195 return 1; /* return error */
196 }
197
198 return 0; /* success return 0 */
199}
200
212{
213 if (handle == NULL) /* check handle */
214 {
215 return 2; /* return error */
216 }
217 if (handle->inited != 1) /* check handle initialization */
218 {
219 return 3; /* return error */
220 }
221
222 *mode = (pcf8591_mode_t)((handle->conf >> 4) & 0x03); /* get mode */
223
224 return 0; /* success return 0 */
225}
226
239{
240 uint8_t res;
241 uint8_t prev_conf;
242
243 if (handle == NULL) /* check handle */
244 {
245 return 2; /* return error */
246 }
247 if (handle->inited != 1) /* check handle initialization */
248 {
249 return 3; /* return error */
250 }
251
252 prev_conf = handle->conf; /* save conf */
253 handle->conf &= ~(1 << 2); /* clear auto bit */
254 handle->conf |= enable << 2; /* set enable */
255 if (enable != 0) /* if enable auto increment */
256 {
257 handle->conf |= 0x40; /* set output bit */
258 }
259 else
260 {
261 handle->conf &= ~0x40; /* clear output bit */
262 }
263 res = handle->iic_write_cmd(handle->iic_addr, (uint8_t *)&handle->conf, 1); /* write command */
264 if (res != 0) /* check error */
265 {
266 handle->debug_print("pcf8591: write command failed.\n"); /* write command failed */
267 handle->conf = prev_conf; /* recover conf */
268
269 return 1; /* return error */
270 }
271
272 return 0; /* success return 0 */
273}
274
286{
287 if (handle == NULL) /* check handle */
288 {
289 return 2; /* return error */
290 }
291 if (handle->inited != 1) /* check handle initialization */
292 {
293 return 3; /* return error */
294 }
295
296 *enable = (pcf8591_bool_t)((handle->conf >> 2) & 0x01); /* get auto */
297
298 return 0; /* success return 0 */
299}
300
311uint8_t pcf8591_set_reference_voltage(pcf8591_handle_t *handle, float ref_voltage)
312{
313 if (handle == NULL) /* check handle */
314 {
315 return 2; /* return error */
316 }
317 if (handle->inited != 1) /* check handle initialization */
318 {
319 return 3; /* return error */
320 }
321
322 handle->ref_voltage = ref_voltage; /* set reference voltage */
323
324 return 0; /* success return 0 */
325}
326
337uint8_t pcf8591_get_reference_voltage(pcf8591_handle_t *handle, float *ref_voltage)
338{
339 if (handle == NULL) /* check handle */
340 {
341 return 2; /* return error */
342 }
343 if (handle->inited != 1) /* check handle initialization */
344 {
345 return 3; /* return error */
346 }
347
348 *ref_voltage = (float)(handle->ref_voltage); /* get ref voltage */
349
350 return 0; /* success return 0 */
351}
352
364{
365 if (handle == NULL) /* check handle */
366 {
367 return 2; /* return error */
368 }
369 if (handle->debug_print == NULL) /* check debug_print */
370 {
371 return 3; /* return error */
372 }
373 if (handle->iic_init == NULL) /* check iic_init */
374 {
375 handle->debug_print("pcf8591: iic_init is null.\n"); /* iic_init is null */
376
377 return 3; /* return error */
378 }
379 if (handle->iic_deinit == NULL) /* check iic_deinit */
380 {
381 handle->debug_print("pcf8591: iic_deinit is null.\n"); /* iic_deinit is null */
382
383 return 3; /* return error */
384 }
385 if (handle->iic_read_cmd == NULL) /* check iic_read_cmd */
386 {
387 handle->debug_print("pcf8591: iic_read_cmd is null.\n"); /* iic_read_cmd is null */
388
389 return 3; /* return error */
390 }
391 if (handle->iic_write_cmd == NULL) /* check iic_write_cmd */
392 {
393 handle->debug_print("pcf8591: iic_write_cmd is null.\n"); /* iic_write_cmd is null */
394
395 return 3; /* return error */
396 }
397 if (handle->delay_ms == NULL) /* check delay_ms */
398 {
399 handle->debug_print("pcf8591: delay_ms is null.\n"); /* delay_ms is null */
400
401 return 3; /* return error */
402 }
403
404 if (handle->iic_init() != 0) /* iic init */
405 {
406 handle->debug_print("pcf8591: iic init failed.\n"); /* iic init failed */
407
408 return 1; /* return error */
409 }
410 handle->inited = 1; /* flag finish initialization */
411
412 return 0; /* success return 0 */
413}
414
426{
427 uint8_t res;
428 uint8_t buf[2];
429
430 if (handle == NULL) /* check handle */
431 {
432 return 2; /* return error */
433 }
434 if (handle->inited != 1) /* check handle initialization */
435 {
436 return 3; /* return error */
437 }
438
439 buf[0] = 0x00; /* set conf */
440 buf[1] = 0x00; /* set 0x00 */
441 res = handle->iic_write_cmd(handle->iic_addr, (uint8_t *)buf, 2); /* write data */
442 if (res != 0) /* check error */
443 {
444 handle->debug_print("pcf8591: write command failed.\n"); /* write failed */
445
446 return 1; /* return error */
447 }
448 res = handle->iic_deinit(); /* iic deinit */
449 if (res != 0) /* check error */
450 {
451 handle->debug_print("pcf8591: iic deinit failed.\n"); /* iic deinit failed */
452
453 return 1; /* return error */
454 }
455 handle->inited = 0; /* flag closed */
456
457 return 0; /* success return 0 */
458}
459
471uint8_t pcf8591_write(pcf8591_handle_t *handle, uint8_t data)
472{
473 uint8_t res;
474 uint8_t buf[2];
475 uint8_t conf;
476
477 if (handle == NULL) /* check handle */
478 {
479 return 2; /* return error */
480 }
481 if (handle->inited != 1) /* check handle initialization */
482 {
483 return 3; /* return error */
484 }
485
486 conf = handle->conf | 0x40; /* set output */
487 buf[0] = conf; /* set conf */
488 buf[1] = data; /* set data */
489 res = handle->iic_write_cmd(handle->iic_addr, (uint8_t *)buf, 2); /* write data */
490 if (res != 0) /* check error */
491 {
492 handle->debug_print("pcf8591: write command failed.\n"); /* write failed */
493
494 return 1; /* return error */
495 }
496
497 return 0; /* success return 0 */
498}
499
511uint8_t pcf8591_dac_convert_to_register(pcf8591_handle_t *handle, float dac, uint8_t *reg)
512{
513 if (handle == NULL) /* check handle */
514 {
515 return 2; /* return error */
516 }
517 if (handle->inited != 1) /* check handle initialization */
518 {
519 return 3; /* return error */
520 }
521
522 *reg = (uint8_t)(dac / handle->ref_voltage * 255.0f); /* convert to register */
523
524 return 0; /* success return 0 */
525}
526
539uint8_t pcf8591_read(pcf8591_handle_t *handle, int16_t *raw, float *adc)
540{
541 uint8_t res;
542 uint8_t mode;
543 uint8_t channel;
544 uint8_t u_data;
545 int8_t s_data;
546 uint8_t buf[1];
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 if ((handle->conf & (1 << 2)) != 0) /* check mode */
558 {
559 handle->debug_print("pcf8591: can't use this function.\n"); /* channel is invalid */
560
561 return 1;
562 }
563 mode = (handle->conf >> 4) & 0x03; /* check mode */
564 channel = handle->conf & 0x03; /* check channel */
565 if ((mode == 1) || (mode == 2)) /* if mode 1 mode 2 */
566 {
567 if (channel > 2) /* check channel */
568 {
569 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
570
571 return 1; /* return error */
572 }
573 }
574 if (mode == 3) /* if mode 3 */
575 {
576 if (channel > 1) /* check channel */
577 {
578 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
579
580 return 1; /* return error */
581 }
582 }
583 res = handle->iic_read_cmd(handle->iic_addr, (uint8_t *)buf, 1); /* read data */
584 if (res != 0) /* check error */
585 {
586 handle->debug_print("pcf8591: read command failed.\n"); /* read failed */
587
588 return 1; /* return error */
589 }
590 switch (mode) /* mode param */
591 {
592 case 0 : /* mode 0 */
593 {
594 if (channel == 0) /* channel 0 */
595 {
596 u_data = buf[0]; /* get data */
597 *raw = (int16_t)(u_data); /* get raw */
598 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
599 res = 0; /* successful */
600 }
601 else if (channel == 1) /* channel 1 */
602 {
603 u_data = buf[0]; /* get data */
604 *raw = (int16_t)(u_data); /* get raw */
605 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
606 res = 0; /* successful */
607 }
608 else if (channel == 2) /* channel 2 */
609 {
610 u_data = buf[0]; /* get data */
611 *raw = (int16_t)(u_data); /* get raw */
612 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
613 res = 0; /* successful */
614 }
615 else /* channel 3 */
616 {
617 u_data = buf[0]; /* get data */
618 *raw = (int16_t)(u_data); /* get raw */
619 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
620 res = 0; /* successful */
621 }
622
623 break; /* break */
624 }
625 case 1 : /* mode 1 */
626 {
627 if (channel == 0) /* channel 0 */
628 {
629 s_data = (int8_t)(buf[0]); /* get data */
630 *raw = (int16_t)(s_data); /* get raw */
631 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
632 res = 0; /* successful */
633 }
634 else if (channel == 1) /* channel 1 */
635 {
636 s_data = (int8_t)(buf[0]); /* get data */
637 *raw = (int16_t)(s_data); /* get raw */
638 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
639 res = 0; /* successful */
640 }
641 else if (channel == 2) /* channel */
642 {
643 s_data = (int8_t)(buf[0]); /* get data */
644 *raw = (int16_t)(s_data); /* get raw */
645 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
646 res = 0; /* successful */
647 }
648 else
649 {
650 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
651 res = 1; /* failed */
652 }
653
654 break; /* break */
655 }
656 case 2 : /* mode 2 */
657 {
658 if (channel == 0) /* channel 0 */
659 {
660 u_data = buf[0]; /* get data */
661 *raw = (int16_t)(u_data); /* get raw */
662 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
663 res = 0; /* successful */
664 }
665 else if (channel == 1) /* channel 1 */
666 {
667 u_data = buf[0]; /* get data */
668 *raw = (int16_t)(u_data); /* get raw */
669 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
670 res = 0; /* successful */
671 }
672 else if (channel == 2) /* channel 2 */
673 {
674 s_data = (int8_t)(buf[0]); /* get data */
675 *raw = (int16_t)(s_data); /* get raw */
676 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
677 res = 0; /* successful */
678 }
679 else
680 {
681 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
682 res = 1; /* failed */
683 }
684
685 break; /* break */
686 }
687 case 3 : /* mode 3 */
688 {
689 if (channel == 0) /* channel 0 */
690 {
691 s_data = (int8_t)(buf[0]); /* get data */
692 *raw = (int16_t)(s_data); /* get raw */
693 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
694 res = 0; /* successful */
695 }
696 else if (channel == 1) /* channel 1 */
697 {
698 s_data = (int8_t)(buf[0]); /* get data */
699 *raw = (int16_t)(s_data); /* get raw */
700 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
701 res = 0; /* successful */
702 }
703 else
704 {
705 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
706 res = 1; /* failed */
707 }
708
709 break; /* break */
710 }
711 default :
712 {
713 handle->debug_print("pcf8591: mode is invalid.\n"); /* mode is invalid */
714 res = 1; /* failed */
715
716 break; /* break */
717 }
718 }
719
720 return res; /* return the result */
721}
722
736uint8_t pcf8591_multiple_read(pcf8591_handle_t *handle, int16_t *raw, float *adc, uint8_t *len)
737{
738 uint8_t res;
739 uint8_t mode;
740 uint8_t i, j;
741 uint8_t u_data;
742 int8_t s_data;
743 uint8_t buf[4];
744
745 if (handle == NULL) /* check handle */
746 {
747 return 2; /* return error */
748 }
749 if (handle->inited != 1) /* check handle initialization */
750 {
751 return 3; /* return error */
752 }
753
754 if ((handle->conf & (1 << 2)) == 0) /* check mode */
755 {
756 handle->debug_print("pcf8591: can't use this function.\n"); /* channel is invalid */
757
758 return 1; /* return error */
759 }
760 mode = (handle->conf >> 4) & 0x03; /* check mode */
761 if (mode == 0) /* mode 0 */
762 {
763 i = 4; /* 4 */
764 i = i<(*len) ? i : (*len); /* get min length */
765 }
766 else if (mode == 1) /* mode 1 */
767 {
768 i = 3; /* 3 */
769 i = i<(*len) ? i : (*len); /* get min length */
770 }
771 else if (mode == 2) /* mode 2 */
772 {
773 i = 3; /* 3 */
774 i = i<(*len) ? i : (*len);
775 } /* get min length */
776 else /* mode 3 */
777 {
778 i = 2; /* 2 */
779 i = i<(*len) ? i : (*len); /* get min length */
780 }
781
782 memset(buf, 0, sizeof(uint8_t) * 4); /* clear the buffer */
783 for (j = 0; j < i; j++)
784 {
785 res = handle->iic_read_cmd(handle->iic_addr, (uint8_t *)&buf[j], 1); /* read data */
786 if (res != 0) /* check error */
787 {
788 handle->debug_print("pcf8591: read command failed.\n"); /* read failed */
789
790 return 1; /* return error */
791 }
792 handle->delay_ms(5); /* delay 5 ms */
793 }
794 switch (mode) /* mode param */
795 {
796 case 0 : /* mode 0 */
797 {
798 u_data = buf[1]; /* get data */
799 *raw = (int16_t)(u_data); /* get raw */
800 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
801 raw++; /* raw address add */
802 adc++; /* adc address add */
803 u_data = buf[2]; /* get data */
804 *raw = (int16_t)(u_data); /* get raw */
805 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
806 raw++; /* raw address add */
807 adc++; /* adc address add */
808 u_data = buf[3]; /* get data */
809 *raw = (int16_t)(u_data); /* get raw */
810 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
811 raw++; /* raw address add */
812 adc++; /* adc address add */
813 u_data = buf[0]; /* get data */
814 *raw = (int16_t)(u_data); /* get raw */
815 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
816 *len = i; /* set length */
817 res = 0; /* successful */
818
819 break; /* break */
820 }
821 case 1 : /* mode 1 */
822 {
823 s_data = (int8_t)(buf[1]); /* get data */
824 *raw = (int16_t)(s_data); /* get raw */
825 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
826 raw++; /* raw address add */
827 adc++; /* adc address add */
828 s_data = (int8_t)(buf[2]); /* get data */
829 *raw = (int16_t)(s_data); /* get raw */
830 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
831 raw++; /* raw address add */
832 adc++; /* adc address add */
833 s_data = (int8_t)(buf[0]); /* get data */
834 *raw = (int16_t)(s_data); /* get raw */
835 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
836 *len = i; /* set length */
837 res = 0; /* successful */
838
839 break; /* break */
840 }
841 case 2 : /* mode 2 */
842 {
843 u_data = buf[1]; /* get data */
844 *raw = (int16_t)(u_data); /* get raw */
845 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
846 raw++; /* raw address add */
847 adc++; /* adc address add */
848 u_data = buf[2]; /* get data */
849 *raw = (int16_t)(u_data); /* get raw */
850 *adc = (float)(*raw) / 255.0f * handle->ref_voltage; /* convert to read data */
851 raw++; /* raw address add */
852 adc++; /* adc address add */
853 s_data = (int8_t)(buf[0]); /* get data */
854 *raw = (int16_t)(s_data); /* get raw */
855 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
856 *len = i; /* set length */
857 res = 0; /* successful */
858
859 break; /* break */
860 }
861 case 3 : /* mode 3 */
862 {
863 s_data = (int8_t)(buf[1]); /* get data */
864 *raw = (int16_t)(s_data); /* get raw */
865 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
866 raw++; /* raw address add */
867 adc++; /* adc address add */
868 s_data = (int8_t)(buf[0]); /* get data */
869 *raw = (int16_t)(s_data); /* get raw */
870 *adc = (float)(*raw) / 128.0f * handle->ref_voltage; /* convert to read data */
871 *len = i; /* set length */
872 res = 0; /* successful */
873
874 break; /* break */
875 }
876 default :
877 {
878 handle->debug_print("pcf8591: mode is invalid.\n"); /* mode is invalid */
879 res = 1; /* failed */
880
881 break; /* break */
882 }
883 }
884
885
886 return res; /* return the result */
887}
888
901uint8_t pcf8591_set_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
902{
903 if (handle == NULL) /* check handle */
904 {
905 return 2; /* return error */
906 }
907 if (handle->inited != 1) /* check handle initialization */
908 {
909 return 3; /* return error */
910 }
911
912 return handle->iic_write_cmd(handle->iic_addr, buf, len); /* write command */
913}
914
927uint8_t pcf8591_get_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
928{
929 if (handle == NULL) /* check handle */
930 {
931 return 2; /* return error */
932 }
933 if (handle->inited != 1) /* check handle initialization */
934 {
935 return 3; /* return error */
936 }
937
938 return handle->iic_read_cmd(handle->iic_addr, buf, len); /* read command */
939}
940
950{
951 if (info == NULL) /* check handle */
952 {
953 return 2; /* return error */
954 }
955
956 memset(info, 0, sizeof(pcf8591_info_t)); /* initialize pcf8591 info structure */
957 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
958 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
959 strncpy(info->interface, "IIC", 8); /* copy interface name */
960 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
961 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
962 info->max_current_ma = MAX_CURRENT; /* set maximum current */
963 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
964 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
965 info->driver_version = DRIVER_VERSION; /* set driver version */
966
967 return 0; /* success return 0 */
968}
#define MAX_CURRENT
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver pcf8591 header file
uint8_t pcf8591_dac_convert_to_register(pcf8591_handle_t *handle, float dac, uint8_t *reg)
convert a dac value to a register raw data
struct pcf8591_info_s pcf8591_info_t
pcf8591 information structure definition
uint8_t pcf8591_read(pcf8591_handle_t *handle, int16_t *raw, float *adc)
read data from the chip
uint8_t pcf8591_info(pcf8591_info_t *info)
get chip's information
uint8_t pcf8591_set_addr_pin(pcf8591_handle_t *handle, pcf8591_address_t addr_pin)
set the address pin
uint8_t pcf8591_get_channel(pcf8591_handle_t *handle, pcf8591_channel_t *channel)
get the adc channel
uint8_t pcf8591_write(pcf8591_handle_t *handle, uint8_t data)
write to the dac
uint8_t pcf8591_init(pcf8591_handle_t *handle)
initialize the chip
pcf8591_mode_t
pcf8591 mode definition
uint8_t pcf8591_get_auto_increment(pcf8591_handle_t *handle, pcf8591_bool_t *enable)
get the adc auto increment read mode
uint8_t pcf8591_multiple_read(pcf8591_handle_t *handle, int16_t *raw, float *adc, uint8_t *len)
read the multiple channel data from the chip
pcf8591_bool_t
pcf8591 bool enumeration definition
uint8_t pcf8591_set_mode(pcf8591_handle_t *handle, pcf8591_mode_t mode)
set the adc mode
uint8_t pcf8591_set_reference_voltage(pcf8591_handle_t *handle, float ref_voltage)
set the adc reference voltage
uint8_t pcf8591_set_channel(pcf8591_handle_t *handle, pcf8591_channel_t channel)
set the adc channel
uint8_t pcf8591_get_addr_pin(pcf8591_handle_t *handle, pcf8591_address_t *addr_pin)
get the address pin
pcf8591_address_t
pcf8591 address enumeration definition
uint8_t pcf8591_get_mode(pcf8591_handle_t *handle, pcf8591_mode_t *mode)
get the adc mode
uint8_t pcf8591_get_reference_voltage(pcf8591_handle_t *handle, float *ref_voltage)
get the adc reference voltage
uint8_t pcf8591_deinit(pcf8591_handle_t *handle)
close the chip
struct pcf8591_handle_s pcf8591_handle_t
pcf8591 handle structure definition
pcf8591_channel_t
pcf8591 channel definition
uint8_t pcf8591_set_auto_increment(pcf8591_handle_t *handle, pcf8591_bool_t enable)
set the adc auto increment read mode
uint8_t pcf8591_get_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
uint8_t pcf8591_set_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint32_t driver_version
char manufacturer_name[32]