LibDriver INA226
Loading...
Searching...
No Matches
driver_ina226.c
Go to the documentation of this file.
1
36
37#include "driver_ina226.h"
38#include <math.h>
39
43#define CHIP_NAME "Texas Instruments INA226"
44#define MANUFACTURER_NAME "Texas Instruments"
45#define SUPPLY_VOLTAGE_MIN 2.7f
46#define SUPPLY_VOLTAGE_MAX 5.5f
47#define MAX_CURRENT 0.33f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 125.0f
50#define DRIVER_VERSION 1000
51
55#define INA226_REG_CONF 0x00
56#define INA226_REG_SHUNT_VOLTAGE 0x01
57#define INA226_REG_BUS_VOLTAGE 0x02
58#define INA226_REG_POWER 0x03
59#define INA226_REG_CURRENT 0x04
60#define INA226_REG_CALIBRATION 0x05
61#define INA226_REG_MASK 0x06
62#define INA226_REG_ALERT_LIMIT 0x07
63#define INA226_REG_MANUFACTURER 0xFE
64#define INA226_REG_DIE 0xFF
65
76static uint8_t a_ina226_iic_read(ina226_handle_t *handle, uint8_t reg, uint16_t *data)
77{
78 uint8_t buf[2];
79
80 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
81 if (handle->iic_read(handle->iic_addr, reg, (uint8_t *)buf, 2) != 0) /* read data */
82 {
83 return 1; /* return error */
84 }
85 else
86 {
87 *data = (uint16_t)buf[0] << 8 | buf[1]; /* get data */
88
89 return 0; /* success return 0 */
90 }
91}
92
103static uint8_t a_ina226_iic_write(ina226_handle_t *handle, uint8_t reg, uint16_t data)
104{
105 uint8_t buf[2];
106
107 buf[0] = (uint8_t)((data >> 8) & 0xFF); /* get MSB */
108 buf[1] = (uint8_t)((data >> 0) & 0xFF); /* get LSB */
109 if (handle->iic_write(handle->iic_addr, reg, (uint8_t *)buf, 2) != 0) /* write data */
110 {
111 return 1; /* return error */
112 }
113 else
114 {
115 return 0; /* success return 0 */
116 }
117}
118
128uint8_t ina226_set_resistance(ina226_handle_t *handle, double resistance)
129{
130 if (handle == NULL) /* check handle */
131 {
132 return 2; /* return error */
133 }
134
135 handle->r = resistance; /* set resistance */
136
137 return 0; /* success return 0 */
138}
139
149uint8_t ina226_get_resistance(ina226_handle_t *handle, double *resistance)
150{
151 if (handle == NULL) /* check handle */
152 {
153 return 2; /* return error */
154 }
155
156 *resistance = handle->r; /* get resistance */
157
158 return 0; /* success return 0 */
159}
160
171{
172 if (handle == NULL) /* check handle */
173 {
174 return 2; /* return error */
175 }
176
177 handle->iic_addr = (uint8_t)addr_pin; /* set pin */
178
179 return 0; /* success return 0 */
180}
181
192{
193 if (handle == NULL) /* check handle */
194 {
195 return 2; /* return error */
196 }
197
198 *addr_pin = (ina226_address_t)(handle->iic_addr); /* get pin */
199
200 return 0; /* success return 0 */
201}
202
214{
215 uint8_t res;
216 uint16_t prev;
217
218 if (handle == NULL) /* check handle */
219 {
220 return 2; /* return error */
221 }
222 if (handle->inited != 1) /* check handle initialization */
223 {
224 return 3; /* return error */
225 }
226
227 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
228 if (res != 0) /* check result */
229 {
230 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
231
232 return 1; /* return error */
233 }
234 prev &= ~(1 << 15); /* clear soft reset */
235 prev |= 1 << 15; /* set soft reset */
236
237 return a_ina226_iic_write(handle, INA226_REG_CONF, (uint16_t )prev); /* write config */
238}
239
252{
253 uint8_t res;
254 uint16_t prev;
255
256 if (handle == NULL) /* check handle */
257 {
258 return 2; /* return error */
259 }
260 if (handle->inited != 1) /* check handle initialization */
261 {
262 return 3; /* return error */
263 }
264
265 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
266 if (res != 0) /* check result */
267 {
268 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
269
270 return 1; /* return error */
271 }
272 prev &= ~(0x7 << 9); /* clear mode bits */
273 prev |= mode << 9; /* set mode bits */
274
275 return a_ina226_iic_write(handle, INA226_REG_CONF, (uint16_t )prev); /* write config */
276}
277
290{
291 uint8_t res;
292 uint16_t prev;
293
294 if (handle == NULL) /* check handle */
295 {
296 return 2; /* return error */
297 }
298 if (handle->inited != 1) /* check handle initialization */
299 {
300 return 3; /* return error */
301 }
302
303 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
304 if (res != 0) /* check result */
305 {
306 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
307
308 return 1; /* return error */
309 }
310 *mode = (ina226_avg_t)((prev >> 9) & 0x07); /* get mode */
311
312 return 0; /* success return 0 */
313}
314
327{
328 uint8_t res;
329 uint16_t prev;
330
331 if (handle == NULL) /* check handle */
332 {
333 return 2; /* return error */
334 }
335 if (handle->inited != 1) /* check handle initialization */
336 {
337 return 3; /* return error */
338 }
339
340 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
341 if (res != 0) /* check result */
342 {
343 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
344
345 return 1; /* return error */
346 }
347 prev &= ~(7 << 6); /* clear time bits */
348 prev |= t << 6; /* set time bits */
349
350 return a_ina226_iic_write(handle, INA226_REG_CONF, (uint16_t )prev); /* write config */
351}
352
365{
366 uint8_t res;
367 uint16_t prev;
368
369 if (handle == NULL) /* check handle */
370 {
371 return 2; /* return error */
372 }
373 if (handle->inited != 1) /* check handle initialization */
374 {
375 return 3; /* return error */
376 }
377
378 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
379 if (res != 0) /* check result */
380 {
381 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
382
383 return 1; /* return error */
384 }
385 *t = (ina226_conversion_time_t)((prev >> 6) & 0x07); /* get time */
386
387 return 0; /* success return 0 */
388}
389
402{
403 uint8_t res;
404 uint16_t prev;
405
406 if (handle == NULL) /* check handle */
407 {
408 return 2; /* return error */
409 }
410 if (handle->inited != 1) /* check handle initialization */
411 {
412 return 3; /* return error */
413 }
414
415 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
416 if (res != 0) /* check result */
417 {
418 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
419
420 return 1; /* return error */
421 }
422 prev &= ~(7 << 3); /* clear time bits */
423 prev |= t << 3; /* set time bits */
424
425 return a_ina226_iic_write(handle, INA226_REG_CONF, (uint16_t )prev); /* write config */
426}
427
440{
441 uint8_t res;
442 uint16_t prev;
443
444 if (handle == NULL) /* check handle */
445 {
446 return 2; /* return error */
447 }
448 if (handle->inited != 1) /* check handle initialization */
449 {
450 return 3; /* return error */
451 }
452
453 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
454 if (res != 0) /* check result */
455 {
456 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
457
458 return 1; /* return error */
459 }
460 *t = (ina226_conversion_time_t)((prev >> 3) & 0x07); /* get time */
461
462 return 0; /* success return 0 */
463}
464
477{
478 uint8_t res;
479 uint16_t prev;
480
481 if (handle == NULL) /* check handle */
482 {
483 return 2; /* return error */
484 }
485 if (handle->inited != 1) /* check handle initialization */
486 {
487 return 3; /* return error */
488 }
489
490 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
491 if (res != 0) /* check result */
492 {
493 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
494
495 return 1; /* return error */
496 }
497 prev &= ~(0x7 << 0); /* clear mode bit */
498 prev |= mode << 0; /* set mode bit */
499 res = a_ina226_iic_write(handle, INA226_REG_CONF, (uint16_t )prev); /* write config */
500 if (res != 0) /* check result */
501 {
502 handle->debug_print("ina226: write conf register failed.\n"); /* write conf register failed */
503
504 return 1; /* return error */
505 }
508 (mode == INA226_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED)) /* check triggered mode */
509 {
510 handle->trigger = 1; /* set 1 */
511 }
512 else
513 {
514 handle->trigger = 0; /* set 0 */
515 }
516
517 return 0; /* success return 0 */
518}
519
532{
533 uint8_t res;
534 uint16_t prev;
535
536 if (handle == NULL) /* check handle */
537 {
538 return 2; /* return error */
539 }
540 if (handle->inited != 1) /* check handle initialization */
541 {
542 return 3; /* return error */
543 }
544
545 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
546 if (res != 0) /* check result */
547 {
548 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
549
550 return 1; /* return error */
551 }
552 *mode = (ina226_mode_t)((prev >> 0) & 0x7); /* get mode */
553
554 return 0; /* success return 0 */
555}
556
569uint8_t ina226_get_die_id(ina226_handle_t *handle, uint16_t *device_id, uint8_t *die_revision_id)
570{
571 uint8_t res;
572 uint16_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_ina226_iic_read(handle, INA226_REG_DIE, (uint16_t *)&prev); /* read config */
584 if (res != 0) /* check result */
585 {
586 handle->debug_print("ina226: read die register failed.\n"); /* read die register failed */
587
588 return 1; /* return error */
589 }
590 *device_id = (prev >> 4) & 0xFFF; /* get device id */
591 *die_revision_id = prev & 0xF; /* get die revision id */
592
593 return 0; /* success return 0 */
594}
595
610uint8_t ina226_read_shunt_voltage(ina226_handle_t *handle, int16_t *raw, float *mV)
611{
612 uint8_t res;
613 union
614 {
615 uint16_t u;
616 int16_t s;
617 } u;
618 uint16_t prev;
619
620 if (handle == NULL) /* check handle */
621 {
622 return 2; /* return error */
623 }
624 if (handle->inited != 1) /* check handle initialization */
625 {
626 return 3; /* return error */
627 }
628
629 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
630 if (res != 0) /* check result */
631 {
632 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
633
634 return 1; /* return error */
635 }
636 if ((prev & (1 << 2)) != 0) /* check math overflow */
637 {
638 handle->debug_print("ina226: math overflow.\n"); /* math overflow */
639
640 return 4; /* return error */
641 }
642 if (handle->trigger != 0) /* trigger mode */
643 {
644 uint16_t i;
645 uint16_t timeout;
646
647 if ((prev & (1 << 3)) == 0) /* check last mask conversion ready flag */
648 {
649 timeout = INA226_READ_TIMEOUT; /* set timeout */
650 for (i = 0; i< timeout; i++) /* loop all */
651 {
652 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
653 if (res != 0) /* check result */
654 {
655 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
656
657 return 1; /* return error */
658 }
659 if ((prev & (1 << 3)) != 0) /* check conversion ready flag */
660 {
661 break; /* break */
662 }
663 handle->delay_ms(1); /* delay 1ms */
664 }
665 if (i >= timeout) /* check timeout */
666 {
667 handle->debug_print("ina226: read timeout.\n"); /* timeout */
668
669 return 5; /* return error */
670 }
671 }
672 handle->trigger = 0; /* set 0 */
673 }
674
675 res = a_ina226_iic_read(handle, INA226_REG_SHUNT_VOLTAGE, (uint16_t *)&u.u); /* read shunt voltage */
676 if (res != 0) /* check result */
677 {
678 handle->debug_print("ina226: read shunt voltage register failed.\n"); /* read shunt voltage register failed */
679
680 return 1; /* return error */
681 }
682 *raw = u.s; /* set the raw */
683 *mV = (float)(*raw) / 400.0f; /* set the converted data */
684
685 return 0; /* success return 0 */
686}
687
702uint8_t ina226_read_bus_voltage(ina226_handle_t *handle, uint16_t *raw, float *mV)
703{
704 uint8_t res;
705 uint16_t prev;
706
707 if (handle == NULL) /* check handle */
708 {
709 return 2; /* return error */
710 }
711 if (handle->inited != 1) /* check handle initialization */
712 {
713 return 3; /* return error */
714 }
715
716 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
717 if (res != 0) /* check result */
718 {
719 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
720
721 return 1; /* return error */
722 }
723 if ((prev & (1 << 2)) != 0) /* check math overflow */
724 {
725 handle->debug_print("ina226: math overflow.\n"); /* math overflow */
726
727 return 4; /* return error */
728 }
729 if (handle->trigger != 0) /* trigger mode */
730 {
731 uint16_t i;
732 uint16_t timeout;
733
734 if ((prev & (1 << 3)) == 0) /* check last mask conversion ready flag */
735 {
736 timeout = INA226_READ_TIMEOUT; /* set timeout */
737 for (i = 0; i< timeout; i++) /* loop all */
738 {
739 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
740 if (res != 0) /* check result */
741 {
742 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
743
744 return 1; /* return error */
745 }
746 if ((prev & (1 << 3)) != 0) /* check conversion ready flag */
747 {
748 break; /* break */
749 }
750 handle->delay_ms(1); /* delay 1ms */
751 }
752 if (i >= timeout) /* check timeout */
753 {
754 handle->debug_print("ina226: read timeout.\n"); /* timeout */
755
756 return 5; /* return error */
757 }
758 }
759 handle->trigger = 0; /* set 0 */
760 }
761
762 res = a_ina226_iic_read(handle, INA226_REG_BUS_VOLTAGE, (uint16_t *)raw); /* read bus voltage */
763 if (res != 0) /* check result */
764 {
765 handle->debug_print("ina226: read bus voltage register failed.\n"); /* read bus voltage register failed */
766
767 return 1; /* return error */
768 }
769 *mV = (float)(*raw) * 1.25f; /* set the converted data */
770
771 return 0; /* success return 0 */
772}
773
788uint8_t ina226_read_current(ina226_handle_t *handle, int16_t *raw, float *mA)
789{
790 uint8_t res;
791 union
792 {
793 uint16_t u;
794 int16_t s;
795 } u;
796 uint16_t prev;
797
798 if (handle == NULL) /* check handle */
799 {
800 return 2; /* return error */
801 }
802 if (handle->inited != 1) /* check handle initialization */
803 {
804 return 3; /* return error */
805 }
806
807 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
808 if (res != 0) /* check result */
809 {
810 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
811
812 return 1; /* return error */
813 }
814 if ((prev & (1 << 2)) != 0) /* check math overflow */
815 {
816 handle->debug_print("ina226: math overflow.\n"); /* math overflow */
817
818 return 4; /* return error */
819 }
820 if (handle->trigger != 0) /* trigger mode */
821 {
822 uint16_t i;
823 uint16_t timeout;
824
825 if ((prev & (1 << 3)) == 0) /* check last mask conversion ready flag */
826 {
827 timeout = INA226_READ_TIMEOUT; /* set timeout */
828 for (i = 0; i< timeout; i++) /* loop all */
829 {
830 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
831 if (res != 0) /* check result */
832 {
833 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
834
835 return 1; /* return error */
836 }
837 if ((prev & (1 << 3)) != 0) /* check conversion ready flag */
838 {
839 break; /* break */
840 }
841 handle->delay_ms(1); /* delay 1ms */
842 }
843 if (i >= timeout) /* check timeout */
844 {
845 handle->debug_print("ina226: read timeout.\n"); /* timeout */
846
847 return 5; /* return error */
848 }
849 }
850 handle->trigger = 0; /* set 0 */
851 }
852
853 res = a_ina226_iic_read(handle, INA226_REG_CURRENT, (uint16_t *)&u.u); /* read current */
854 if (res != 0) /* check result */
855 {
856 handle->debug_print("ina226: read current register failed.\n"); /* read current register failed */
857
858 return 1; /* return error */
859 }
860 *raw = u.s; /* set the raw */
861 *mA = (float)((double)(*raw) * handle->current_lsb * 1000); /* set the converted data */
862
863 return 0; /* success return 0 */
864}
865
880uint8_t ina226_read_power(ina226_handle_t *handle, uint16_t *raw, float *mW)
881{
882 uint8_t res;
883 uint16_t prev;
884
885 if (handle == NULL) /* check handle */
886 {
887 return 2; /* return error */
888 }
889 if (handle->inited != 1) /* check handle initialization */
890 {
891 return 3; /* return error */
892 }
893
894 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
895 if (res != 0) /* check result */
896 {
897 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
898
899 return 1; /* return error */
900 }
901 if ((prev & (1 << 2)) != 0) /* check math overflow */
902 {
903 handle->debug_print("ina226: math overflow.\n"); /* math overflow */
904
905 return 4; /* return error */
906 }
907 if (handle->trigger != 0) /* trigger mode */
908 {
909 uint16_t i;
910 uint16_t timeout;
911
912 if ((prev & (1 << 3)) == 0) /* check last mask conversion ready flag */
913 {
914 timeout = INA226_READ_TIMEOUT; /* set timeout */
915 for (i = 0; i< timeout; i++) /* loop all */
916 {
917 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
918 if (res != 0) /* check result */
919 {
920 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
921
922 return 1; /* return error */
923 }
924 if ((prev & (1 << 3)) != 0) /* check conversion ready flag */
925 {
926 break; /* break */
927 }
928 handle->delay_ms(1); /* delay 1ms */
929 }
930 if (i >= timeout) /* check timeout */
931 {
932 handle->debug_print("ina226: read timeout.\n"); /* timeout */
933
934 return 5; /* return error */
935 }
936 }
937 handle->trigger = 0; /* set 0 */
938 }
939
940 res = a_ina226_iic_read(handle, INA226_REG_POWER, (uint16_t *)raw); /* read power */
941 if (res != 0) /* check result */
942 {
943 handle->debug_print("ina226: read power register failed.\n"); /* read power register failed */
944
945 return 1; /* return error */
946 }
947 *mW = (float)((double)(*raw) * handle->current_lsb * 25.0 * 1000.0); /* set the converted data */
948
949 return 0; /* success return 0 */
950}
951
963uint8_t ina226_get_calibration(ina226_handle_t *handle, uint16_t *data)
964{
965 uint8_t res;
966
967 if (handle == NULL) /* check handle */
968 {
969 return 2; /* return error */
970 }
971 if (handle->inited != 1) /* check handle initialization */
972 {
973 return 3; /* return error */
974 }
975
976 res = a_ina226_iic_read(handle, INA226_REG_CALIBRATION, (uint16_t *)data); /* read calibration */
977 if (res != 0) /* check result */
978 {
979 handle->debug_print("ina226: read calibration register failed.\n"); /* read calibration register failed */
980
981 return 1; /* return error */
982 }
983
984 return 0; /* success return 0 */
985}
986
999uint8_t ina226_calculate_calibration(ina226_handle_t *handle, uint16_t *calibration)
1000{
1001 double v;
1002
1003 if (handle == NULL) /* check handle */
1004 {
1005 return 2; /* return error */
1006 }
1007 if (handle->inited != 1) /* check handle initialization */
1008 {
1009 return 3; /* return error */
1010 }
1011 if ((handle->r >= -0.000001f) && (handle->r <= 0.000001f)) /* check the r */
1012 {
1013 handle->debug_print("ina226: r can't be zero.\n"); /* r can't be zero */
1014
1015 return 4; /* return error */
1016 }
1017
1018 v = 0.08192; /* set max range */
1019 handle->current_lsb = v / handle->r / pow(2.0, 15.0); /* current lsb */
1020 *calibration = (uint16_t)(0.00512 / (v / pow(2.0, 15.0))); /* set calibration */
1021
1022 return 0; /* success return 0 */
1023}
1024
1036uint8_t ina226_set_calibration(ina226_handle_t *handle, uint16_t data)
1037{
1038 uint8_t res;
1039
1040 if (handle == NULL) /* check handle */
1041 {
1042 return 2; /* return error */
1043 }
1044 if (handle->inited != 1) /* check handle initialization */
1045 {
1046 return 3; /* return error */
1047 }
1048
1049 res = a_ina226_iic_write(handle, INA226_REG_CALIBRATION, data); /* write calibration */
1050 if (res != 0) /* check result */
1051 {
1052 handle->debug_print("ina226: write calibration register failed.\n"); /* write calibration register failed */
1053
1054 return 1; /* return error */
1055 }
1056
1057 return 0; /* success return 0 */
1058}
1059
1073{
1074 uint8_t res;
1075 uint16_t prev;
1076
1077 if (handle == NULL) /* check handle */
1078 {
1079 return 2; /* return error */
1080 }
1081 if (handle->inited != 1) /* check handle initialization */
1082 {
1083 return 3; /* return error */
1084 }
1085
1086 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1087 if (res != 0) /* check result */
1088 {
1089 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1090
1091 return 1; /* return error */
1092 }
1093 prev &= ~(1 << mask); /* clear settings */
1094 prev |= (enable << mask); /* set mask */
1095 res = a_ina226_iic_write(handle, INA226_REG_MASK, prev); /* write mask */
1096 if (res != 0) /* check result */
1097 {
1098 handle->debug_print("ina226: write mask register failed.\n"); /* write mask register failed */
1099
1100 return 1; /* return error */
1101 }
1102
1103 return 0; /* success return 0 */
1104}
1105
1119{
1120 uint8_t res;
1121 uint16_t prev;
1122
1123 if (handle == NULL) /* check handle */
1124 {
1125 return 2; /* return error */
1126 }
1127 if (handle->inited != 1) /* check handle initialization */
1128 {
1129 return 3; /* return error */
1130 }
1131
1132 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1133 if (res != 0) /* check result */
1134 {
1135 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1136
1137 return 1; /* return error */
1138 }
1139 *enable = (ina226_bool_t)((prev >> mask) & 0x01); /* get bool */
1140
1141 return 0; /* success return 0 */
1142}
1143
1156{
1157 uint8_t res;
1158 uint16_t prev;
1159
1160 if (handle == NULL) /* check handle */
1161 {
1162 return 2; /* return error */
1163 }
1164 if (handle->inited != 1) /* check handle initialization */
1165 {
1166 return 3; /* return error */
1167 }
1168
1169 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1170 if (res != 0) /* check result */
1171 {
1172 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1173
1174 return 1; /* return error */
1175 }
1176 prev &= ~(1 << 10); /* clear settings */
1177 prev |= (enable << 10); /* set mask */
1178 res = a_ina226_iic_write(handle, INA226_REG_MASK, prev); /* write mask */
1179 if (res != 0) /* check result */
1180 {
1181 handle->debug_print("ina226: write mask register failed.\n"); /* write mask register failed */
1182
1183 return 1; /* return error */
1184 }
1185
1186 return 0; /* success return 0 */
1187}
1188
1201{
1202 uint8_t res;
1203 uint16_t prev;
1204
1205 if (handle == NULL) /* check handle */
1206 {
1207 return 2; /* return error */
1208 }
1209 if (handle->inited != 1) /* check handle initialization */
1210 {
1211 return 3; /* return error */
1212 }
1213
1214 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1215 if (res != 0) /* check result */
1216 {
1217 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1218
1219 return 1; /* return error */
1220 }
1221 *enable = (ina226_bool_t)((prev >> 10) & 0x01); /* get bool */
1222
1223 return 0; /* success return 0 */
1224}
1225
1238{
1239 uint8_t res;
1240 uint16_t prev;
1241
1242 if (handle == NULL) /* check handle */
1243 {
1244 return 2; /* return error */
1245 }
1246 if (handle->inited != 1) /* check handle initialization */
1247 {
1248 return 3; /* return error */
1249 }
1250
1251 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1252 if (res != 0) /* check result */
1253 {
1254 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1255
1256 return 1; /* return error */
1257 }
1258 prev &= ~(1 << 1); /* clear settings */
1259 prev |= (pin << 1); /* set mask */
1260 res = a_ina226_iic_write(handle, INA226_REG_MASK, prev); /* write mask */
1261 if (res != 0) /* check result */
1262 {
1263 handle->debug_print("ina226: write mask register failed.\n"); /* write mask register failed */
1264
1265 return 1; /* return error */
1266 }
1267
1268 return 0; /* success return 0 */
1269}
1270
1283{
1284 uint8_t res;
1285 uint16_t prev;
1286
1287 if (handle == NULL) /* check handle */
1288 {
1289 return 2; /* return error */
1290 }
1291 if (handle->inited != 1) /* check handle initialization */
1292 {
1293 return 3; /* return error */
1294 }
1295
1296 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1297 if (res != 0) /* check result */
1298 {
1299 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1300
1301 return 1; /* return error */
1302 }
1303 *pin = (ina226_alert_polarity_t)((prev >> 1) & 0x01); /* get alert polarity pin */
1304
1305 return 0; /* success return 0 */
1306}
1307
1320{
1321 uint8_t res;
1322 uint16_t prev;
1323
1324 if (handle == NULL) /* check handle */
1325 {
1326 return 2; /* return error */
1327 }
1328 if (handle->inited != 1) /* check handle initialization */
1329 {
1330 return 3; /* return error */
1331 }
1332
1333 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1334 if (res != 0) /* check result */
1335 {
1336 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1337
1338 return 1; /* return error */
1339 }
1340 prev &= ~(1 << 0); /* clear settings */
1341 prev |= (enable << 0); /* set mask */
1342 res = a_ina226_iic_write(handle, INA226_REG_MASK, prev); /* write mask */
1343 if (res != 0) /* check result */
1344 {
1345 handle->debug_print("ina226: write mask register failed.\n"); /* write mask register failed */
1346
1347 return 1; /* return error */
1348 }
1349
1350 return 0; /* success return 0 */
1351}
1352
1365{
1366 uint8_t res;
1367 uint16_t prev;
1368
1369 if (handle == NULL) /* check handle */
1370 {
1371 return 2; /* return error */
1372 }
1373 if (handle->inited != 1) /* check handle initialization */
1374 {
1375 return 3; /* return error */
1376 }
1377
1378 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1379 if (res != 0) /* check result */
1380 {
1381 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1382
1383 return 1; /* return error */
1384 }
1385 *enable = (ina226_bool_t)((prev >> 0) & 0x01); /* get bool */
1386
1387 return 0; /* success return 0 */
1388}
1389
1401uint8_t ina226_set_alert_limit(ina226_handle_t *handle, uint16_t reg)
1402{
1403 uint8_t res;
1404
1405 if (handle == NULL) /* check handle */
1406 {
1407 return 2; /* return error */
1408 }
1409 if (handle->inited != 1) /* check handle initialization */
1410 {
1411 return 3; /* return error */
1412 }
1413
1414 res = a_ina226_iic_write(handle, INA226_REG_ALERT_LIMIT, reg); /* write config */
1415 if (res != 0) /* check result */
1416 {
1417 handle->debug_print("ina226: write alert limit register failed.\n"); /* write alert limit register failed */
1418
1419 return 1; /* return error */
1420 }
1421
1422 return 0; /* success return 0 */
1423}
1424
1436uint8_t ina226_get_alert_limit(ina226_handle_t *handle, uint16_t *reg)
1437{
1438 uint8_t res;
1439
1440 if (handle == NULL) /* check handle */
1441 {
1442 return 2; /* return error */
1443 }
1444 if (handle->inited != 1) /* check handle initialization */
1445 {
1446 return 3; /* return error */
1447 }
1448
1449 res = a_ina226_iic_read(handle, INA226_REG_ALERT_LIMIT, reg); /* read config */
1450 if (res != 0) /* check result */
1451 {
1452 handle->debug_print("ina226: read alert limit register failed.\n"); /* read alert limit register failed */
1453
1454 return 1; /* return error */
1455 }
1456
1457 return 0; /* success return 0 */
1458}
1459
1471uint8_t ina226_shunt_voltage_convert_to_register(ina226_handle_t *handle, float mV, uint16_t *reg)
1472{
1473 if (handle == NULL) /* check handle */
1474 {
1475 return 2; /* return error */
1476 }
1477 if (handle->inited != 1) /* check handle initialization */
1478 {
1479 return 3; /* return error */
1480 }
1481
1482 *reg = (uint16_t)(mV * 400.0f); /* convert real data to register data */
1483
1484 return 0; /* success return 0 */
1485}
1486
1498uint8_t ina226_shunt_voltage_convert_to_data(ina226_handle_t *handle, uint16_t reg, float *mV)
1499{
1500 if (handle == NULL) /* check handle */
1501 {
1502 return 2; /* return error */
1503 }
1504 if (handle->inited != 1) /* check handle initialization */
1505 {
1506 return 3; /* return error */
1507 }
1508
1509 *mV = (float)(reg) / 400.0f; /* convert real data to register data */
1510
1511 return 0; /* success return 0 */
1512}
1513
1525uint8_t ina226_bus_voltage_convert_to_register(ina226_handle_t *handle, float mV, uint16_t *reg)
1526{
1527 if (handle == NULL) /* check handle */
1528 {
1529 return 2; /* return error */
1530 }
1531 if (handle->inited != 1) /* check handle initialization */
1532 {
1533 return 3; /* return error */
1534 }
1535
1536 *reg = (uint16_t)(mV / 1.25f); /* convert real data to register data */
1537
1538 return 0; /* success return 0 */
1539}
1540
1552uint8_t ina226_bus_voltage_convert_to_data(ina226_handle_t *handle, uint16_t reg, float *mV)
1553{
1554 if (handle == NULL) /* check handle */
1555 {
1556 return 2; /* return error */
1557 }
1558 if (handle->inited != 1) /* check handle initialization */
1559 {
1560 return 3; /* return error */
1561 }
1562
1563 *mV = (float)(reg) * 1.25f; /* convert real data to register data */
1564
1565 return 0; /* success return 0 */
1566}
1567
1579uint8_t ina226_power_convert_to_register(ina226_handle_t *handle, float mW, uint16_t *reg)
1580{
1581 if (handle == NULL) /* check handle */
1582 {
1583 return 2; /* return error */
1584 }
1585 if (handle->inited != 1) /* check handle initialization */
1586 {
1587 return 3; /* return error */
1588 }
1589
1590 *reg = (uint16_t)((double)(mW) / (handle->current_lsb * 25.0 * 1000.0)); /* set the converted data */
1591
1592 return 0; /* success return 0 */
1593}
1594
1606uint8_t ina226_power_convert_to_data(ina226_handle_t *handle, uint16_t reg, float *mW)
1607{
1608 if (handle == NULL) /* check handle */
1609 {
1610 return 2; /* return error */
1611 }
1612 if (handle->inited != 1) /* check handle initialization */
1613 {
1614 return 3; /* return error */
1615 }
1616
1617 *mW = (float)((double)(reg) * handle->current_lsb * 25.0 * 1000.0); /* set the converted data */
1618
1619 return 0; /* success return 0 */
1620}
1621
1633{
1634 uint8_t res;
1635 uint16_t prev;
1636
1637 if (handle == NULL) /* check handle */
1638 {
1639 return 2; /* return error */
1640 }
1641 if (handle->inited != 1) /* check handle initialization */
1642 {
1643 return 3; /* return error */
1644 }
1645
1646 res = a_ina226_iic_read(handle, INA226_REG_MASK, (uint16_t *)&prev); /* read mask */
1647 if (res != 0) /* check result */
1648 {
1649 handle->debug_print("ina226: read mask register failed.\n"); /* read mask register failed */
1650
1651 return 1; /* return error */
1652 }
1653 if ((prev & (1 << 4)) != 0) /* check alert flag */
1654 {
1655 if ((prev & (1 << 15)) != 0) /* shunt voltage over voltage */
1656 {
1657 if (handle->receive_callback != NULL) /* check not null */
1658 {
1660 }
1661 }
1662 else if ((prev & (1 << 14)) != 0) /* shunt voltage under voltage */
1663 {
1664 if (handle->receive_callback != NULL) /* check not null */
1665 {
1667 }
1668 }
1669 else if ((prev & (1 << 13)) != 0) /* bus voltage over voltage */
1670 {
1671 if (handle->receive_callback != NULL) /* check not null */
1672 {
1673 handle->receive_callback(INA226_STATUS_BUS_VOLTAGE_OVER_VOLTAGE); /* run callback */
1674 }
1675 }
1676 else if ((prev & (1 << 12)) != 0) /* bus voltage under voltage */
1677 {
1678 if (handle->receive_callback != NULL) /* check not null */
1679 {
1681 }
1682 }
1683 else if ((prev & (1 << 11)) != 0) /* power over limit */
1684 {
1685 if (handle->receive_callback != NULL) /* check not null */
1686 {
1687 handle->receive_callback(INA226_STATUS_POWER_OVER_LIMIT); /* run callback */
1688 }
1689 }
1690 else
1691 {
1692 /* do nothing */
1693 }
1694 }
1695
1696 return 0; /* success return 0 */
1697}
1698
1712{
1713 uint8_t res;
1714 uint16_t prev;
1715
1716 if (handle == NULL) /* check handle */
1717 {
1718 return 2; /* return error */
1719 }
1720 if (handle->debug_print == NULL) /* check debug_print */
1721 {
1722 return 3; /* return error */
1723 }
1724 if (handle->iic_init == NULL) /* check iic_init */
1725 {
1726 handle->debug_print("ina226: iic_init is null.\n"); /* iic_init is null */
1727
1728 return 3; /* return error */
1729 }
1730 if (handle->iic_deinit == NULL) /* check iic_deinit */
1731 {
1732 handle->debug_print("ina226: iic_deinit is null.\n"); /* iic_deinit is null */
1733
1734 return 3; /* return error */
1735 }
1736 if (handle->iic_read == NULL) /* check iic_read */
1737 {
1738 handle->debug_print("ina226: iic_read is null.\n"); /* iic_read is null */
1739
1740 return 3; /* return error */
1741 }
1742 if (handle->iic_write == NULL) /* check iic_write */
1743 {
1744 handle->debug_print("ina226: iic_write is null.\n"); /* iic_write is null */
1745
1746 return 3; /* return error */
1747 }
1748 if (handle->delay_ms == NULL) /* check delay_ms */
1749 {
1750 handle->debug_print("ina226: delay_ms is null.\n"); /* delay_ms is null */
1751
1752 return 3; /* return error */
1753 }
1754 if (handle->receive_callback == NULL) /* check receive_callback */
1755 {
1756 handle->debug_print("ina226: receive_callback is null.\n"); /* receive_callback is null */
1757
1758 return 3; /* return error */
1759 }
1760
1761 if (handle->iic_init() != 0) /* iic init */
1762 {
1763 handle->debug_print("ina226: iic init failed.\n"); /* iic init failed */
1764
1765 return 1; /* return error */
1766 }
1767 res = a_ina226_iic_read(handle, INA226_REG_MANUFACTURER, (uint16_t *)&prev); /* read manufacturer */
1768 if (res != 0) /* check result */
1769 {
1770 handle->debug_print("ina226: read manufacturer failed.\n"); /* read manufacturer failed */
1771 (void)handle->iic_deinit(); /* iic deinit */
1772
1773 return 4; /* return error */
1774 }
1775 if (prev != 0x5449) /* check id */
1776 {
1777 handle->debug_print("ina226: id is invalid.\n"); /* id is invalid */
1778 (void)handle->iic_deinit(); /* iic deinit */
1779
1780 return 4; /* return error */
1781 }
1782 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read conf */
1783 if (res != 0) /* check result */
1784 {
1785 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
1786 (void)handle->iic_deinit(); /* iic deinit */
1787
1788 return 5; /* return error */
1789 }
1790 prev |= 1 << 15; /* set bit */
1791 res = a_ina226_iic_write(handle, INA226_REG_CONF, prev); /* write conf */
1792 if (res != 0) /* check result */
1793 {
1794 handle->debug_print("ina226: write conf register failed.\n"); /* write conf register failed */
1795 (void)handle->iic_deinit(); /* iic deinit */
1796
1797 return 5; /* return error */
1798 }
1799 handle->delay_ms(10); /* delay 10 ms */
1800 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read conf */
1801 if (res != 0) /* check result */
1802 {
1803 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
1804 (void)handle->iic_deinit(); /* iic deinit */
1805
1806 return 5; /* return error */
1807 }
1808 if ((prev & (1 << 15)) != 0) /* check the result */
1809 {
1810 handle->debug_print("ina226: soft reset failed.\n"); /* soft reset failed */
1811 (void)handle->iic_deinit(); /* iic deinit */
1812
1813 return 5; /* return error */
1814 }
1815 handle->trigger = 0; /* none */
1816 handle->inited = 1; /* flag inited */
1817
1818 return 0; /* success return 0 */
1819}
1820
1833{
1834 uint8_t res;
1835 uint16_t prev;
1836
1837 if (handle == NULL) /* check handle */
1838 {
1839 return 2; /* return error */
1840 }
1841 if (handle->inited != 1) /* check handle initialization */
1842 {
1843 return 3; /* return error */
1844 }
1845
1846 res = a_ina226_iic_read(handle, INA226_REG_CONF, (uint16_t *)&prev); /* read config */
1847 if (res != 0) /* check result */
1848 {
1849 handle->debug_print("ina226: read conf register failed.\n"); /* read conf register failed */
1850
1851 return 4; /* return error */
1852 }
1853 prev &= ~(0x07); /* clear mode */
1854 res = a_ina226_iic_write(handle, INA226_REG_CONF, (uint16_t )prev); /* write config */
1855 if (res != 0) /* check result */
1856 {
1857 handle->debug_print("ina226: write conf register failed.\n"); /* write conf register failed */
1858
1859 return 4; /* return error */
1860 }
1861 res = handle->iic_deinit(); /* iic deinit */
1862 if (res != 0) /* check result */
1863 {
1864 handle->debug_print("ina226: iic deinit failed.\n"); /* iic deinit failed */
1865
1866 return 1; /* return error */
1867 }
1868
1869 return 0; /* success return 0 */
1870}
1871
1884uint8_t ina226_set_reg(ina226_handle_t *handle, uint8_t reg, uint16_t data)
1885{
1886 if (handle == NULL) /* check handle */
1887 {
1888 return 2; /* return error */
1889 }
1890 if (handle->inited != 1) /* check handle initialization */
1891 {
1892 return 3; /* return error */
1893 }
1894
1895 return a_ina226_iic_write(handle, reg, data); /* write data */
1896}
1897
1910uint8_t ina226_get_reg(ina226_handle_t *handle, uint8_t reg, uint16_t *data)
1911{
1912 if (handle == NULL) /* check handle */
1913 {
1914 return 2; /* return error */
1915 }
1916 if (handle->inited != 1) /* check handle initialization */
1917 {
1918 return 3; /* return error */
1919 }
1920
1921 return a_ina226_iic_read(handle, reg, data); /* read data */
1922}
1923
1933{
1934 if (info == NULL) /* check handle */
1935 {
1936 return 2; /* return error */
1937 }
1938
1939 memset(info, 0, sizeof(ina226_info_t)); /* initialize ina226 info structure */
1940 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1941 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1942 strncpy(info->interface, "IIC", 8); /* copy interface name */
1943 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1944 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1945 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1946 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1947 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1948 info->driver_version = DRIVER_VERSION; /* set driver version */
1949
1950 return 0; /* success return 0 */
1951}
#define INA226_REG_DIE
#define MAX_CURRENT
#define INA226_REG_POWER
#define INA226_REG_MANUFACTURER
#define SUPPLY_VOLTAGE_MAX
#define INA226_REG_SHUNT_VOLTAGE
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define INA226_REG_ALERT_LIMIT
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define INA226_REG_CALIBRATION
#define INA226_REG_BUS_VOLTAGE
#define INA226_REG_MASK
#define INA226_REG_CONF
chip register definition
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define INA226_REG_CURRENT
driver ina226 header file
uint8_t ina226_calculate_calibration(ina226_handle_t *handle, uint16_t *calibration)
calculate the calibration
uint8_t ina226_get_addr_pin(ina226_handle_t *handle, ina226_address_t *addr_pin)
get the iic address pin
uint8_t ina226_set_bus_voltage_conversion_time(ina226_handle_t *handle, ina226_conversion_time_t t)
set bus voltage conversion time
uint8_t ina226_info(ina226_info_t *info)
get chip's information
uint8_t ina226_bus_voltage_convert_to_data(ina226_handle_t *handle, uint16_t reg, float *mV)
convert the register raw data to the bus voltage
uint8_t ina226_power_convert_to_data(ina226_handle_t *handle, uint16_t reg, float *mW)
convert the register raw data to the power
ina226_mask_t
ina226 mask enumeration definition
uint8_t ina226_bus_voltage_convert_to_register(ina226_handle_t *handle, float mV, uint16_t *reg)
convert the bus voltage to the register raw data
uint8_t ina226_read_current(ina226_handle_t *handle, int16_t *raw, float *mA)
read the current
uint8_t ina226_deinit(ina226_handle_t *handle)
close the chip
uint8_t ina226_set_conversion_ready_alert_pin(ina226_handle_t *handle, ina226_bool_t enable)
enable or disable conversion ready alert pin
uint8_t ina226_get_alert_latch(ina226_handle_t *handle, ina226_bool_t *enable)
get alert latch status
uint8_t ina226_get_bus_voltage_conversion_time(ina226_handle_t *handle, ina226_conversion_time_t *t)
get bus voltage conversion time
uint8_t ina226_set_mode(ina226_handle_t *handle, ina226_mode_t mode)
set the mode
uint8_t ina226_set_alert_polarity_pin(ina226_handle_t *handle, ina226_alert_polarity_t pin)
set alert polarity pin
uint8_t ina226_shunt_voltage_convert_to_register(ina226_handle_t *handle, float mV, uint16_t *reg)
convert the shunt voltage to the register raw data
#define INA226_READ_TIMEOUT
ina226 read timeout definition
uint8_t ina226_set_mask(ina226_handle_t *handle, ina226_mask_t mask, ina226_bool_t enable)
enable or disable mask
uint8_t ina226_get_conversion_ready_alert_pin(ina226_handle_t *handle, ina226_bool_t *enable)
get conversion ready alert pin status
uint8_t ina226_get_alert_limit(ina226_handle_t *handle, uint16_t *reg)
get alert limit
uint8_t ina226_set_addr_pin(ina226_handle_t *handle, ina226_address_t addr_pin)
set the iic address pin
uint8_t ina226_set_alert_latch(ina226_handle_t *handle, ina226_bool_t enable)
enable or disable alert latch
uint8_t ina226_read_power(ina226_handle_t *handle, uint16_t *raw, float *mW)
read the power
uint8_t ina226_set_average_mode(ina226_handle_t *handle, ina226_avg_t mode)
set average mode
uint8_t ina226_get_shunt_voltage_conversion_time(ina226_handle_t *handle, ina226_conversion_time_t *t)
get shunt voltage conversion time
uint8_t ina226_get_calibration(ina226_handle_t *handle, uint16_t *data)
get the calibration
uint8_t ina226_get_mode(ina226_handle_t *handle, ina226_mode_t *mode)
get the mode
ina226_address_t
ina226 address enumeration definition
struct ina226_handle_s ina226_handle_t
ina226 handle structure definition
uint8_t ina226_soft_reset(ina226_handle_t *handle)
soft reset the chip
uint8_t ina226_get_mask(ina226_handle_t *handle, ina226_mask_t mask, ina226_bool_t *enable)
get mask
uint8_t ina226_irq_handler(ina226_handle_t *handle)
irq handler
uint8_t ina226_get_alert_polarity_pin(ina226_handle_t *handle, ina226_alert_polarity_t *pin)
get alert polarity pin
ina226_mode_t
ina226 mode enumeration definition
uint8_t ina226_read_shunt_voltage(ina226_handle_t *handle, int16_t *raw, float *mV)
read the shunt voltage
uint8_t ina226_get_average_mode(ina226_handle_t *handle, ina226_avg_t *mode)
get average mode
uint8_t ina226_init(ina226_handle_t *handle)
initialize the chip
uint8_t ina226_get_resistance(ina226_handle_t *handle, double *resistance)
get the resistance
ina226_bool_t
ina226 bool enumeration definition
uint8_t ina226_set_shunt_voltage_conversion_time(ina226_handle_t *handle, ina226_conversion_time_t t)
set shunt voltage conversion time
uint8_t ina226_set_alert_limit(ina226_handle_t *handle, uint16_t reg)
set alert limit
ina226_conversion_time_t
uint8_t ina226_set_calibration(ina226_handle_t *handle, uint16_t data)
set the calibration
uint8_t ina226_shunt_voltage_convert_to_data(ina226_handle_t *handle, uint16_t reg, float *mV)
convert the register raw data to the shunt voltage
uint8_t ina226_set_resistance(ina226_handle_t *handle, double resistance)
set the resistance
uint8_t ina226_power_convert_to_register(ina226_handle_t *handle, float mW, uint16_t *reg)
convert the power to the register raw data
ina226_avg_t
ina226 average enumeration definition
ina226_alert_polarity_t
ina226 alert polarity enumeration definition
uint8_t ina226_get_die_id(ina226_handle_t *handle, uint16_t *device_id, uint8_t *die_revision_id)
get the die id
struct ina226_info_s ina226_info_t
ina226 information structure definition
uint8_t ina226_read_bus_voltage(ina226_handle_t *handle, uint16_t *raw, float *mV)
read the bus voltage
@ INA226_STATUS_BUS_VOLTAGE_OVER_VOLTAGE
@ INA226_STATUS_POWER_OVER_LIMIT
@ INA226_STATUS_SHUNT_VOLTAGE_UNDER_VOLTAGE
@ INA226_STATUS_BUS_VOLTAGE_UNDER_VOLTAGE
@ INA226_STATUS_SHUNT_VOLTAGE_OVER_VOLTAGE
@ INA226_MODE_BUS_VOLTAGE_TRIGGERED
@ INA226_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED
@ INA226_MODE_SHUNT_VOLTAGE_TRIGGERED
uint8_t ina226_set_reg(ina226_handle_t *handle, uint8_t reg, uint16_t data)
set the chip register
uint8_t ina226_get_reg(ina226_handle_t *handle, uint8_t reg, uint16_t *data)
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)
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]