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 /* disable auto increment */
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
476 if (handle == NULL) /* check handle */
477 {
478 return 2; /* return error */
479 }
480 if (handle->inited != 1) /* check handle initialization */
481 {
482 return 3; /* return error */
483 }
484
485 handle->conf = handle->conf | 0x40; /* set output */
486 buf[0] = handle->conf; /* set conf */
487 buf[1] = data; /* set data */
488 res = handle->iic_write_cmd(handle->iic_addr, (uint8_t *)buf, 2); /* write data */
489 if (res != 0) /* check error */
490 {
491 handle->debug_print("pcf8591: write command failed.\n"); /* write failed */
492
493 return 1; /* return error */
494 }
495
496 return 0; /* success return 0 */
497}
498
510uint8_t pcf8591_dac_convert_to_register(pcf8591_handle_t *handle, float dac, uint8_t *reg)
511{
512 if (handle == NULL) /* check handle */
513 {
514 return 2; /* return error */
515 }
516 if (handle->inited != 1) /* check handle initialization */
517 {
518 return 3; /* return error */
519 }
520
521 *reg = (uint8_t)(dac / handle->ref_voltage * 256.0f); /* convert to register */
522
523 return 0; /* success return 0 */
524}
525
538uint8_t pcf8591_read(pcf8591_handle_t *handle, int16_t *raw, float *adc)
539{
540 uint8_t res;
541 uint8_t mode;
542 uint8_t channel;
543 uint8_t u_data;
544 int8_t s_data;
545 uint8_t buf[2];
546
547 if (handle == NULL) /* check handle */
548 {
549 return 2; /* return error */
550 }
551 if (handle->inited != 1) /* check handle initialization */
552 {
553 return 3; /* return error */
554 }
555
556 if ((handle->conf & (1 << 2)) != 0) /* check mode */
557 {
558 handle->debug_print("pcf8591: can't use this function.\n"); /* channel is invalid */
559
560 return 1;
561 }
562 mode = (handle->conf >> 4) & 0x03; /* check mode */
563 channel = handle->conf & 0x03; /* check channel */
564 if ((mode == 1) || (mode == 2)) /* if mode 1 mode 2 */
565 {
566 if (channel > 2) /* check channel */
567 {
568 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
569
570 return 1; /* return error */
571 }
572 }
573 if (mode == 3) /* if mode 3 */
574 {
575 if (channel > 1) /* check channel */
576 {
577 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
578
579 return 1; /* return error */
580 }
581 }
582 res = handle->iic_read_cmd(handle->iic_addr, (uint8_t *)buf, 2); /* read data */
583 if (res != 0) /* check error */
584 {
585 handle->debug_print("pcf8591: read command failed.\n"); /* read failed */
586
587 return 1; /* return error */
588 }
589 switch (mode) /* mode param */
590 {
591 case 0 : /* mode 0 */
592 {
593 if (channel == 0) /* channel 0 */
594 {
595 u_data = buf[1]; /* get data */
596 *raw = (int16_t)(u_data); /* get raw */
597 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
598 res = 0; /* successful */
599 }
600 else if (channel == 1) /* channel 1 */
601 {
602 u_data = buf[1]; /* get data */
603 *raw = (int16_t)(u_data); /* get raw */
604 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
605 res = 0; /* successful */
606 }
607 else if (channel == 2) /* channel 2 */
608 {
609 u_data = buf[1]; /* get data */
610 *raw = (int16_t)(u_data); /* get raw */
611 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
612 res = 0; /* successful */
613 }
614 else /* channel 3 */
615 {
616 u_data = buf[1]; /* get data */
617 *raw = (int16_t)(u_data); /* get raw */
618 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
619 res = 0; /* successful */
620 }
621
622 break; /* break */
623 }
624 case 1 : /* mode 1 */
625 {
626 if (channel == 0) /* channel 0 */
627 {
628 s_data = (int8_t)(buf[1]); /* get data */
629 *raw = (int16_t)(s_data); /* get raw */
630 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
631 res = 0; /* successful */
632 }
633 else if (channel == 1) /* channel 1 */
634 {
635 s_data = (int8_t)(buf[1]); /* get data */
636 *raw = (int16_t)(s_data); /* get raw */
637 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
638 res = 0; /* successful */
639 }
640 else if (channel == 2) /* channel */
641 {
642 s_data = (int8_t)(buf[1]); /* get data */
643 *raw = (int16_t)(s_data); /* get raw */
644 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
645 res = 0; /* successful */
646 }
647 else
648 {
649 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
650 res = 1; /* failed */
651 }
652
653 break; /* break */
654 }
655 case 2 : /* mode 2 */
656 {
657 if (channel == 0) /* channel 0 */
658 {
659 u_data = buf[1]; /* get data */
660 *raw = (int16_t)(u_data); /* get raw */
661 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
662 res = 0; /* successful */
663 }
664 else if (channel == 1) /* channel 1 */
665 {
666 u_data = buf[1]; /* get data */
667 *raw = (int16_t)(u_data); /* get raw */
668 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
669 res = 0; /* successful */
670 }
671 else if (channel == 2) /* channel 2 */
672 {
673 s_data = (int8_t)(buf[1]); /* get data */
674 *raw = (int16_t)(s_data); /* get raw */
675 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
676 res = 0; /* successful */
677 }
678 else
679 {
680 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
681 res = 1; /* failed */
682 }
683
684 break; /* break */
685 }
686 case 3 : /* mode 3 */
687 {
688 if (channel == 0) /* channel 0 */
689 {
690 s_data = (int8_t)(buf[1]); /* get data */
691 *raw = (int16_t)(s_data); /* get raw */
692 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
693 res = 0; /* successful */
694 }
695 else if (channel == 1) /* channel 1 */
696 {
697 s_data = (int8_t)(buf[1]); /* get data */
698 *raw = (int16_t)(s_data); /* get raw */
699 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
700 res = 0; /* successful */
701 }
702 else
703 {
704 handle->debug_print("pcf8591: channel is invalid.\n"); /* channel is invalid */
705 res = 1; /* failed */
706 }
707
708 break; /* break */
709 }
710 default :
711 {
712 handle->debug_print("pcf8591: mode is invalid.\n"); /* mode is invalid */
713 res = 1; /* failed */
714
715 break; /* break */
716 }
717 }
718
719 return res; /* return the result */
720}
721
735uint8_t pcf8591_multiple_read(pcf8591_handle_t *handle, int16_t *raw, float *adc, uint8_t *len)
736{
737 uint8_t res;
738 uint8_t mode;
739 uint8_t i;
740 uint8_t u_data;
741 int8_t s_data;
742 uint8_t buf[5];
743
744 if (handle == NULL) /* check handle */
745 {
746 return 2; /* return error */
747 }
748 if (handle->inited != 1) /* check handle initialization */
749 {
750 return 3; /* return error */
751 }
752
753 if ((handle->conf & (1 << 2)) == 0) /* check mode */
754 {
755 handle->debug_print("pcf8591: can't use this function.\n"); /* channel is invalid */
756
757 return 1; /* return error */
758 }
759 mode = (handle->conf >> 4) & 0x03; /* check mode */
760 if (mode == 0) /* mode 0 */
761 {
762 i = 4; /* 4 */
763 i = i<(*len) ? i : (*len); /* get min length */
764 }
765 else if (mode == 1) /* mode 1 */
766 {
767 i = 3; /* 3 */
768 i = i<(*len) ? i : (*len); /* get min length */
769 }
770 else if (mode == 2) /* mode 2 */
771 {
772 i = 3; /* 3 */
773 i = i<(*len) ? i : (*len);
774 } /* get min length */
775 else /* mode 3 */
776 {
777 i = 2; /* 2 */
778 i = i<(*len) ? i : (*len); /* get min length */
779 }
780
781 memset(buf, 0, sizeof(uint8_t) * 5); /* clear the buffer */
782 res = handle->iic_read_cmd(handle->iic_addr, buf, i + 1); /* read data */
783 if (res != 0) /* check error */
784 {
785 handle->debug_print("pcf8591: read command failed.\n"); /* read failed */
786
787 return 1; /* return error */
788 }
789 switch (mode) /* mode param */
790 {
791 case 0 : /* mode 0 */
792 {
793 u_data = buf[1]; /* get data */
794 *raw = (int16_t)(u_data); /* get raw */
795 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
796 raw++; /* raw address add */
797 adc++; /* adc address add */
798 u_data = buf[2]; /* get data */
799 *raw = (int16_t)(u_data); /* get raw */
800 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
801 raw++; /* raw address add */
802 adc++; /* adc address add */
803 u_data = buf[3]; /* get data */
804 *raw = (int16_t)(u_data); /* get raw */
805 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
806 raw++; /* raw address add */
807 adc++; /* adc address add */
808 u_data = buf[4]; /* get data */
809 *raw = (int16_t)(u_data); /* get raw */
810 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
811 *len = i; /* set length */
812 res = 0; /* successful */
813
814 break; /* break */
815 }
816 case 1 : /* mode 1 */
817 {
818 s_data = (int8_t)(buf[1]); /* get data */
819 *raw = (int16_t)(s_data); /* get raw */
820 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
821 raw++; /* raw address add */
822 adc++; /* adc address add */
823 s_data = (int8_t)(buf[2]); /* get data */
824 *raw = (int16_t)(s_data); /* get raw */
825 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
826 raw++; /* raw address add */
827 adc++; /* adc address add */
828 s_data = (int8_t)(buf[3]); /* get data */
829 *raw = (int16_t)(s_data); /* get raw */
830 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
831 *len = i; /* set length */
832 res = 0; /* successful */
833
834 break; /* break */
835 }
836 case 2 : /* mode 2 */
837 {
838 u_data = buf[1]; /* get data */
839 *raw = (int16_t)(u_data); /* get raw */
840 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
841 raw++; /* raw address add */
842 adc++; /* adc address add */
843 u_data = buf[2]; /* get data */
844 *raw = (int16_t)(u_data); /* get raw */
845 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
846 raw++; /* raw address add */
847 adc++; /* adc address add */
848 s_data = (int8_t)(buf[3]); /* get data */
849 *raw = (int16_t)(s_data); /* get raw */
850 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
851 *len = i; /* set length */
852 res = 0; /* successful */
853
854 break; /* break */
855 }
856 case 3 : /* mode 3 */
857 {
858 s_data = (int8_t)(buf[1]); /* get data */
859 *raw = (int16_t)(s_data); /* get raw */
860 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
861 raw++; /* raw address add */
862 adc++; /* adc address add */
863 s_data = (int8_t)(buf[2]); /* get data */
864 *raw = (int16_t)(s_data); /* get raw */
865 *adc = (float)(*raw) / 256.0f * handle->ref_voltage; /* convert to read data */
866 *len = i; /* set length */
867 res = 0; /* successful */
868
869 break; /* break */
870 }
871 default :
872 {
873 handle->debug_print("pcf8591: mode is invalid.\n"); /* mode is invalid */
874 res = 1; /* failed */
875
876 break; /* break */
877 }
878 }
879
880 return res; /* return the result */
881}
882
895uint8_t pcf8591_set_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
896{
897 if (handle == NULL) /* check handle */
898 {
899 return 2; /* return error */
900 }
901 if (handle->inited != 1) /* check handle initialization */
902 {
903 return 3; /* return error */
904 }
905
906 return handle->iic_write_cmd(handle->iic_addr, buf, len); /* write command */
907}
908
921uint8_t pcf8591_get_reg(pcf8591_handle_t *handle, uint8_t *buf, uint16_t len)
922{
923 if (handle == NULL) /* check handle */
924 {
925 return 2; /* return error */
926 }
927 if (handle->inited != 1) /* check handle initialization */
928 {
929 return 3; /* return error */
930 }
931
932 return handle->iic_read_cmd(handle->iic_addr, buf, len); /* read command */
933}
934
944{
945 if (info == NULL) /* check handle */
946 {
947 return 2; /* return error */
948 }
949
950 memset(info, 0, sizeof(pcf8591_info_t)); /* initialize pcf8591 info structure */
951 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
952 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
953 strncpy(info->interface, "IIC", 8); /* copy interface name */
954 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
955 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
956 info->max_current_ma = MAX_CURRENT; /* set maximum current */
957 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
958 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
959 info->driver_version = DRIVER_VERSION; /* set driver version */
960
961 return 0; /* success return 0 */
962}
#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]