ina3221.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
63 #ifndef INA3221_H
64 #define INA3221_H
65 
66 #include <stdint.h>
67 
68 #include "periph/gpio.h"
69 #include "periph/i2c.h"
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 #define INA3221_NUM_CH (3)
77 #define INA3221_NUM_ALERTS (4)
83 typedef void (*ina3221_alert_cb_t)(void *arg);
84 
88 typedef enum ina3221_ret_val {
96 
100 typedef enum ina3221_dev_addr {
106 
110 typedef enum ina3221_channel {
111  INA3221_CH1 = (1 << 0),
112  INA3221_CH2 = (1 << 1),
113  INA3221_CH3 = (1 << 2)
115 
119 typedef enum ina3221_alert {
125 
129 typedef enum ina3221_mode {
139 #define INA3221_MODE_MASK (0x0007)
144 typedef enum ina3221_conv_time_shunt_adc {
154 #define INA3221_CONV_TIME_SADC_MASK (0x0038)
159 typedef enum ina3221_conv_time_bus_adc {
169 #define INA3221_CONV_TIME_BADC_MASK (0x01C0)
174 typedef enum ina3221_num_samples {
184 #define INA3221_NUM_SAMPLES_MASK (0x0E00)
189 typedef enum ina3221_enable_ch {
194 #define INA3221_ENABLE_CH_MASK (INA3221_ENABLE_CH1 \
195  | INA3221_ENABLE_CH2 \
196  | INA3221_ENABLE_CH3)
201 typedef enum ina3221_channel_state {
205 
209 typedef enum ina3221_enable_sum_ch {
214 #define INA3221_ENABLE_SUM_CH_MASK (INA3221_ENABLE_SUM_CH1 \
215  | INA3221_ENABLE_SUM_CH2 \
216  | INA3221_ENABLE_SUM_CH3)
221 typedef enum ina3221_enable_latch {
225 #define INA3221_ENABLE_LATCH_MASK (INA3221_ENABLE_WARN_LATCH \
226  | INA3221_ENABLE_CRIT_LATCH)
230 typedef struct {
232  uint8_t addr;
233  union {
234  struct {
235  gpio_t pin_warn;
236  gpio_t pin_crit;
237  gpio_t pin_tc;
238  gpio_t pin_pv;
239  } pins;
240  struct {
241  gpio_t alert_pins[INA3221_NUM_ALERTS];
242  } apins;
243  } upins;
244  /*
245  For each pin 1 bit states whether to use internal pull up resistors.
246  d = don´t care
247  [d][d][d][d][pu PV][pu TC][pu CRT][pu WRN]
248  */
249  uint8_t gpio_config;
250  uint16_t config;
251  uint16_t rshunt_mohm[INA3221_NUM_CH];
253 
254 /* ( INA3221_ENABLE_CH_1
255  | INA3221_ENABLE_CH_2
256  | INA3221_ENABLE_CH_2
257  | INA3221_NUM_SAMPLES_1
258  | INA3221_CONV_TIME_BADC_1100US
259  | INA3221_CONV_TIME_SADC_1100US
260  | INA3221_MODE_CONTINUOUS_SHUNT_BUS ) */
261 #define INA3221_DEFCONFIG (0x7127)
263 #define INA3221_RESET (0x8000)
265 #define INA3221_FLAG_CRIT_ALERT_CH1 (0x0200)
266 #define INA3221_FLAG_CRIT_ALERT_CH2 (0x0100)
267 #define INA3221_FLAG_CRIT_ALERT_CH3 (0x0080)
269 #define INA3221_FLAG_SHUNT_SUM_ALERT (0x0040)
271 #define INA3221_FLAG_WARN_ALERT_CH1 (0x0020)
272 #define INA3221_FLAG_WARN_ALERT_CH2 (0x0010)
273 #define INA3221_FLAG_WARN_ALERT_CH3 (0x0008)
275 #define INA3221_FLAG_POWER_VALID (0x0004)
277 #define INA3221_FLAG_TIMING_CONTROL (0x0002)
279 #define INA3221_FLAG_CONV_READY (0x0001)
281 #define INA3221_FLAGS_MASK (INA3221_FLAG_CRIT_ALERT_CH1 \
282  | INA3221_FLAG_CRIT_ALERT_CH2 \
283  | INA3221_FLAG_CRIT_ALERT_CH3 \
284  | INA3221_FLAG_SHUNT_SUM_ALERT \
285  | INA3221_FLAG_WARN_ALERT_CH1 \
286  | INA3221_FLAG_WARN_ALERT_CH2 \
287  | INA3221_FLAG_WARN_ALERT_CH3 \
288  | INA3221_FLAG_POWER_VALID \
289  | INA3221_FLAG_TIMING_CONTROL \
290  | INA3221_FLAG_CONV_READY)
295 typedef struct {
297 #if defined(MODULE_INA3221_ALERTS) || defined(DOXYGEN)
298  union {
299  struct {
304  };
305  struct {
307  };
308  };
309  union {
310  struct {
311  void *arg_warn_cb;
312  void *arg_crit_cb;
313  void *arg_tc_cb;
314  void *arg_pv_cb;
315  };
316  struct {
317  void *alert_callback_arguments[INA3221_NUM_ALERTS];
318  };
319  };
320 #endif /* MODULE_INA3221_ALERTS */
321 } ina3221_t;
322 
334 int ina3221_reset(ina3221_t *dev);
335 
352 int ina3221_init(ina3221_t *dev, const ina3221_params_t *params);
353 
354 #if defined(MODULE_INA3221_ALERTS) || defined(DOXYGEN)
355 
368  ina3221_alert_cb_t cb, void *arg);
369 
381  ina3221_alert_cb_t cb, void *arg)
382 {
383  return _ina3221_enable_alert(dev, INA3221_ALERT_WRN, cb, arg);
384 }
385 
398  void *arg)
399 {
400  return _ina3221_enable_alert(dev, INA3221_ALERT_CRT, cb, arg);
401 }
402 
415  void *arg)
416 {
417  return _ina3221_enable_alert(dev, INA3221_ALERT_TC, cb, arg);
418 }
419 
432  void *arg)
433 {
434  return _ina3221_enable_alert(dev, INA3221_ALERT_PV, cb, arg);
435 }
436 
448 
458 {
460 }
461 
471 {
473 }
474 
484 {
486 }
487 
497 {
499 }
500 
501 #endif /* MODULE_INA3221_ALERTS */
502 
513 int _ina3221_set_config(ina3221_t *dev, uint16_t cfg);
514 
527 static inline int ina3221_set_config(ina3221_t *dev,
532  ina3221_mode_t mode)
533 {
534  return _ina3221_set_config(dev, chs | ns | ctbadc | ctsadc | mode);
535 }
536 
545 int _ina3221_get_config(const ina3221_t *dev, uint16_t *cfg);
546 
559 static inline int ina3221_get_config(const ina3221_t *dev,
560  ina3221_enable_ch_t *chs,
564  ina3221_mode_t *mode)
565 {
566  uint16_t cfg = 0;
567  int ret = _ina3221_get_config(dev, &cfg);
568 
569  *chs = cfg & INA3221_ENABLE_CH_MASK;
570  *ns = cfg & INA3221_NUM_SAMPLES_MASK;
571  *ctbadc = cfg & INA3221_CONV_TIME_BADC_MASK;
572  *ctsadc = cfg & INA3221_CONV_TIME_SADC_MASK;
573  *mode = cfg & INA3221_MODE_MASK;
574  return ret;
575 }
576 
589 
600 static inline int ina3221_set_channel_state(ina3221_t *dev,
604 {
605  return _ina3221_set_enable_channel(dev,
606  (ch1 ? INA3221_ENABLE_CH1 : 0) |
607  (ch2 ? INA3221_ENABLE_CH2 : 0) |
608  (ch3 ? INA3221_ENABLE_CH3 : 0));
609 }
610 
620 
631 static inline int ina3221_get_channel_state(const ina3221_t *dev,
635 {
636  ina3221_enable_ch_t ech = 0;
637  int ret = _ina3221_get_enable_channel(dev, &ech);
638 
642  return ret;
643 }
644 
657 
667 
681 
692 
706 
717 
730 
739 int ina3221_get_mode(const ina3221_t *dev, ina3221_mode_t *mode);
740 
754 
765 static inline int ina3221_set_enable_sum_channel(const ina3221_t *dev,
769 {
771  (ch1 ? INA3221_ENABLE_SUM_CH1 : 0) |
772  (ch2 ? INA3221_ENABLE_SUM_CH2 : 0) |
773  (ch3 ? INA3221_ENABLE_SUM_CH3 : 0));
774 }
775 
788 
799 static inline int ina3221_get_enable_sum_channel(const ina3221_t *dev,
803 {
804  ina3221_enable_sum_ch_t esch = 0;
805  int ret = _ina3221_get_enable_sum_channel(dev, &esch);
806 
807  *ch1 =
808  (esch &
810  *ch2 =
811  (esch &
813  *ch3 =
814  (esch &
816  return ret;
817 }
818 
830 int ina3221_set_latch(const ina3221_t *dev, ina3221_enable_latch_t latch);
831 
842 int ina3221_get_latch(const ina3221_t *dev, ina3221_enable_latch_t *latch);
843 
859  int32_t in_uv);
860 
875  int32_t *out_uv);
876 
892  int32_t in_uv);
893 
908  int32_t *out_uv);
909 
922  int32_t in_uv);
923 
935  int32_t *out_uv);
936 
948 int ina3221_set_power_valid_upper_limit(const ina3221_t *dev, int32_t in_mv);
949 
960 int ina3221_get_power_valid_upper_limit(const ina3221_t *dev, int32_t *out_mv);
961 
973 int ina3221_set_power_valid_lower_limit(const ina3221_t *dev, int32_t in_mv);
974 
985 int ina3221_get_power_valid_lower_limit(const ina3221_t *dev, int32_t *out_mv);
986 
997 int ina3221_read_flags(const ina3221_t *dev, uint16_t *flags);
998 
1010 int ina3221_read_shunt_sum_uv(const ina3221_t *dev, int32_t *out_uv,
1011  uint16_t *flags);
1012 
1028  int32_t *out_uv, uint16_t *flags);
1029 
1045  int16_t *out_mv, uint16_t *flags);
1046 
1058  int32_t *in_uv, int32_t *out_ma);
1059 
1071 int ina3221_calculate_power_uw(int16_t *in_mv, int32_t *in_ua, uint8_t num,
1072  int32_t *out_mw);
1073 
1085 void ina3221_ch_align(ina3221_channel_t ch, const void *in_res, void *out_res,
1086  size_t res_val_size);
1087 
1093 #define INA3221_TRIGGER_SHUNT(dev) \
1094  ina3221_set_mode(dev, INA3221_MODE_TRIGGER_SHUNT_ONLY)
1095 
1101 #define INA3221_TRIGGER_BUS(dev) \
1102  ina3221_set_mode(dev, INA3221_MODE_TRIGGER_BUS_ONLY)
1103 
1109 #define INA3221_TRIGGER_SHUNT_AND_BUS(dev) \
1110  ina3221_set_mode(dev, INA3221_MODE_TRIGGER_SHUNT_BUS)
1111 
1112 #ifdef __cplusplus
1113 }
1114 #endif
1115 
1116 #endif /* INA3221_H */
1117 
ina3221_params_t::addr
uint8_t addr
I2C address.
Definition: ina3221.h:232
ina3221_disable_timing_control_alert
static int ina3221_disable_timing_control_alert(ina3221_t *dev)
Wrapper around.
Definition: ina3221.h:483
ina3221_enable_critical_alert
static int ina3221_enable_critical_alert(ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
Wrapper around.
Definition: ina3221.h:396
ina3221_get_conv_time_shunt_adc
int ina3221_get_conv_time_shunt_adc(const ina3221_t *dev, ina3221_conv_time_shunt_adc_t *cts)
Read currently applied shunt voltage ADC conversion time.
ina3221_set_conv_time_shunt_adc
int ina3221_set_conv_time_shunt_adc(ina3221_t *dev, ina3221_conv_time_shunt_adc_t cts)
Update conversion time of shunt voltage ADC and write to configuration register.
INA3221_MODE_TRIGGER_SHUNT_ONLY
@ INA3221_MODE_TRIGGER_SHUNT_ONLY
Trigger shunt voltage measurement only.
Definition: ina3221.h:131
ina3221_params_t::pin_crit
gpio_t pin_crit
Critical alert pin, becomes configured as input.
Definition: ina3221.h:236
INA3221_ENABLE_CH3
@ INA3221_ENABLE_CH3
Enable channel 3.
Definition: ina3221.h:192
INA3221_MODE_TRIGGER_BUS_ONLY
@ INA3221_MODE_TRIGGER_BUS_ONLY
Trigger bus voltage measurement only.
Definition: ina3221.h:132
INA3221_CONV_TIME_SADC_8244US
@ INA3221_CONV_TIME_SADC_8244US
8244 us
Definition: ina3221.h:152
INA3221_ENABLE_CRIT_LATCH
@ INA3221_ENABLE_CRIT_LATCH
Enable critical alert latch.
Definition: ina3221.h:223
INA3221_NUM_SAMPLES_64
@ INA3221_NUM_SAMPLES_64
64
Definition: ina3221.h:178
INA3221_CONV_TIME_BADC_588US
@ INA3221_CONV_TIME_BADC_588US
588 us
Definition: ina3221.h:163
ina3221_set_latch
int ina3221_set_latch(const ina3221_t *dev, ina3221_enable_latch_t latch)
Enable latches for critical/warning alert pins.
ina3221_dav_addr_t
enum ina3221_dev_addr ina3221_dav_addr_t
I2C device addresses.
INA3221_CONV_TIME_SADC_MASK
#define INA3221_CONV_TIME_SADC_MASK
ADC shunt voltage conversion times bit mask.
Definition: ina3221.h:154
ina3221_alert_cb_t
void(* ina3221_alert_cb_t)(void *arg)
INA3221 alert callback for alert pins CRT, WRN, TC, PV.
Definition: ina3221.h:83
INA3221_ADDR_01
@ INA3221_ADDR_01
A0 connected to VS
Definition: ina3221.h:102
INA3221_CONFIG_FAILED
@ INA3221_CONFIG_FAILED
Device configuration failed.
Definition: ina3221.h:94
ina3221_disable_power_valid_alert
static int ina3221_disable_power_valid_alert(ina3221_t *dev)
Wrapper around.
Definition: ina3221.h:496
ina3221_t
INA3221 device handle struct.
Definition: ina3221.h:295
INA3221_CONV_TIME_BADC_1100US
@ INA3221_CONV_TIME_BADC_1100US
1100 us
Definition: ina3221.h:164
INA3221_CONV_TIME_BADC_4156US
@ INA3221_CONV_TIME_BADC_4156US
4156 us
Definition: ina3221.h:166
ina3221_alert
ina3221_alert
Alert indices.
Definition: ina3221.h:119
INA3221_ENABLE_SUM_CH1
@ INA3221_ENABLE_SUM_CH1
Enable sum channel 1.
Definition: ina3221.h:210
INA3221_MODE_POWER_DOWN
@ INA3221_MODE_POWER_DOWN
Sleep mode.
Definition: ina3221.h:130
INA3221_ALERT_CRT
@ INA3221_ALERT_CRT
Critical alert.
Definition: ina3221.h:121
INA3221_MODE_CONTINUOUS_BUS_ONLY
@ INA3221_MODE_CONTINUOUS_BUS_ONLY
Continuous bus voltage measurement only.
Definition: ina3221.h:136
INA3221_ENABLE_SUM_CH2
@ INA3221_ENABLE_SUM_CH2
Enable sum channel 2.
Definition: ina3221.h:211
ina3221_get_power_valid_upper_limit
int ina3221_get_power_valid_upper_limit(const ina3221_t *dev, int32_t *out_mv)
Read bus voltage power valid upper limit.
INA3221_CONV_TIME_SADC_1100US
@ INA3221_CONV_TIME_SADC_1100US
1100 us
Definition: ina3221.h:149
ina3221_read_shunt_uv
int ina3221_read_shunt_uv(const ina3221_t *dev, ina3221_channel_t ch, int32_t *out_uv, uint16_t *flags)
Read shunt voltages for each channel in ch.
INA3221_ENABLE_WARN_LATCH
@ INA3221_ENABLE_WARN_LATCH
Enable warning alert latch.
Definition: ina3221.h:222
INA3221_CONV_TIME_BADC_140US
@ INA3221_CONV_TIME_BADC_140US
140 us
Definition: ina3221.h:160
ina3221_t::warn_cb
ina3221_alert_cb_t warn_cb
Warning alert callback: executed when WRN is pulled low.
Definition: ina3221.h:300
INA3221_CONV_TIME_BADC_204US
@ INA3221_CONV_TIME_BADC_204US
204 us
Definition: ina3221.h:161
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
ina3221_ret_val_t
enum ina3221_ret_val ina3221_ret_val_t
Return codes.
ina3221_channel_state_t
enum ina3221_channel_state ina3221_channel_state_t
Channel state enabled/disabled.
ina3221_get_latch
int ina3221_get_latch(const ina3221_t *dev, ina3221_enable_latch_t *latch)
Read enabled latches for critical/warning alert pins.
INA3221_OK
@ INA3221_OK
Everything is fine.
Definition: ina3221.h:89
ina3221_channel_t
enum ina3221_channel ina3221_channel_t
Channel flags.
ina3221_set_enable_sum_channel
static int ina3221_set_enable_sum_channel(const ina3221_t *dev, ina3221_channel_state_t ch1, ina3221_channel_state_t ch2, ina3221_channel_state_t ch3)
Wrapper around.
Definition: ina3221.h:765
ina3221_disable_critical_alert
static int ina3221_disable_critical_alert(ina3221_t *dev)
Wrapper around.
Definition: ina3221.h:470
INA3221_I2C_ERROR
@ INA3221_I2C_ERROR
I2C bus acquirenment failed.
Definition: ina3221.h:90
_ina3221_get_config
int _ina3221_get_config(const ina3221_t *dev, uint16_t *cfg)
Read currently saved configuration register value.
INA3221_RESET_FAILED
@ INA3221_RESET_FAILED
Device reset failed.
Definition: ina3221.h:93
ina3221_t::tc_cb
ina3221_alert_cb_t tc_cb
Timing control alert callback: executed when TC is pulled low.
Definition: ina3221.h:302
ina3221_set_num_samples
int ina3221_set_num_samples(ina3221_t *dev, ina3221_num_samples_t ns)
Update number of samples and write to configuration register.
ina3221_get_enable_sum_channel
static int ina3221_get_enable_sum_channel(const ina3221_t *dev, ina3221_channel_state_t *ch1, ina3221_channel_state_t *ch2, ina3221_channel_state_t *ch3)
Wrapper for.
Definition: ina3221.h:799
ina3221_get_mode
int ina3221_get_mode(const ina3221_t *dev, ina3221_mode_t *mode)
Read currently applied device operation mode.
ina3221_conv_time_shunt_adc_t
enum ina3221_conv_time_shunt_adc ina3221_conv_time_shunt_adc_t
ADC shunt voltage conversion times.
ina3221_set_conv_time_bus_adc
int ina3221_set_conv_time_bus_adc(ina3221_t *dev, ina3221_conv_time_bus_adc_t ctb)
Update conversion time of bus voltage ADC and write to configuration register.
_ina3221_get_enable_channel
int _ina3221_get_enable_channel(const ina3221_t *dev, ina3221_enable_ch_t *ech)
Read which channels are currently enabled.
_ina3221_disable_alert
int _ina3221_disable_alert(ina3221_t *dev, ina3221_alert_t alert)
Disable alert callback and argument for alert alert.
INA3221_CONV_TIME_SADC_204US
@ INA3221_CONV_TIME_SADC_204US
204 us
Definition: ina3221.h:146
_ina3221_set_config
int _ina3221_set_config(ina3221_t *dev, uint16_t cfg)
Write configuration register value to configuration register.
INA3221_MODE_POWER_DOWN_
@ INA3221_MODE_POWER_DOWN_
Also power down (see datasheet)
Definition: ina3221.h:134
ina3221_set_warn_alert_limit
int ina3221_set_warn_alert_limit(const ina3221_t *dev, ina3221_channel_t ch, int32_t in_uv)
Set warning shunt voltage alert limit to in_uv for each channel in ch.
ina3221_enable_timing_control_alert
static int ina3221_enable_timing_control_alert(ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
Wrapper around.
Definition: ina3221.h:413
_ina3221_set_enable_channel
int _ina3221_set_enable_channel(ina3221_t *dev, ina3221_enable_ch_t ech)
Enable channels.
INA3221_CH_ENABLE
@ INA3221_CH_ENABLE
Channel enabled.
Definition: ina3221.h:203
ina3221_set_crit_alert_limit
int ina3221_set_crit_alert_limit(const ina3221_t *dev, ina3221_channel_t ch, int32_t in_uv)
Set critical shunt voltage alert limit to in_uv for each channel in ch.
ina3221_enable_sum_ch
ina3221_enable_sum_ch
Enable shunt voltage sum calculation channel flags.
Definition: ina3221.h:209
ina3221_get_channel_state
static int ina3221_get_channel_state(const ina3221_t *dev, ina3221_channel_state_t *ch1, ina3221_channel_state_t *ch2, ina3221_channel_state_t *ch3)
Wrapper around _ina3221_get_enable_channel.
Definition: ina3221.h:631
ina3221_params_t::config
uint16_t config
Configuration.
Definition: ina3221.h:250
_ina3221_enable_alert
int _ina3221_enable_alert(ina3221_t *dev, ina3221_alert_t alert, ina3221_alert_cb_t cb, void *arg)
Enable alert callback and argument for alert alert.
ina3221_dev_addr
ina3221_dev_addr
I2C device addresses.
Definition: ina3221.h:100
INA3221_ENABLE_CH_MASK
#define INA3221_ENABLE_CH_MASK
Enable channel bit mask.
Definition: ina3221.h:194
INA3221_ADDR_11
@ INA3221_ADDR_11
A0 connected to SCL.
Definition: ina3221.h:104
ina3221_ch_align
void ina3221_ch_align(ina3221_channel_t ch, const void *in_res, void *out_res, size_t res_val_size)
Align in_res to the number of channels For example: ch = (INA3221_CH1 | INA3221_CH3) in_res = {value_...
INA3221_CH1
@ INA3221_CH1
Channel 1.
Definition: ina3221.h:111
_ina3221_set_enable_sum_channel
int _ina3221_set_enable_sum_channel(const ina3221_t *dev, ina3221_enable_sum_ch_t esch)
Enable channels for shunt voltage sum calculation.
ina3221_reset
int ina3221_reset(ina3221_t *dev)
Reset device, i.e.
ina3221_t::arg_crit_cb
void * arg_crit_cb
Argument for Critical alert callback.
Definition: ina3221.h:312
ina3221_get_conv_time_bus_adc
int ina3221_get_conv_time_bus_adc(const ina3221_t *dev, ina3221_conv_time_bus_adc_t *ctb)
Read currently applied bus voltage ADC conversion time.
ina3221_enable_sum_ch_t
enum ina3221_enable_sum_ch ina3221_enable_sum_ch_t
Enable shunt voltage sum calculation channel flags.
INA3221_CONV_TIME_BADC_2116US
@ INA3221_CONV_TIME_BADC_2116US
2116 us
Definition: ina3221.h:165
_ina3221_get_enable_sum_channel
int _ina3221_get_enable_sum_channel(const ina3221_t *dev, ina3221_enable_sum_ch_t *esch)
Read enabled channels for shunt voltage sum calculation.
INA3221_NUM_SAMPLES_MASK
#define INA3221_NUM_SAMPLES_MASK
Number of samples to calculate average shunt/bus voltage value bit mask.
Definition: ina3221.h:184
INA3221_ENABLE_CH1
@ INA3221_ENABLE_CH1
Enable channel 1.
Definition: ina3221.h:190
INA3221_NUM_SAMPLES_128
@ INA3221_NUM_SAMPLES_128
128
Definition: ina3221.h:179
INA3221_NUM_SAMPLES_256
@ INA3221_NUM_SAMPLES_256
256
Definition: ina3221.h:180
ina3221_read_shunt_sum_uv
int ina3221_read_shunt_sum_uv(const ina3221_t *dev, int32_t *out_uv, uint16_t *flags)
Read sum of shunt voltages.
INA3221_NUM_ALERTS
#define INA3221_NUM_ALERTS
Number of alerts.
Definition: ina3221.h:77
INA3221_CONV_TIME_BADC_332US
@ INA3221_CONV_TIME_BADC_332US
332 us
Definition: ina3221.h:162
INA3221_CONV_TIME_SADC_2116US
@ INA3221_CONV_TIME_SADC_2116US
2116 us
Definition: ina3221.h:150
INA3221_NUM_SAMPLES_512
@ INA3221_NUM_SAMPLES_512
512
Definition: ina3221.h:181
INA3221_CH2
@ INA3221_CH2
Channel 2.
Definition: ina3221.h:112
INA3221_NUM_CH
#define INA3221_NUM_CH
Number of channels.
Definition: ina3221.h:75
INA3221_NUM_SAMPLES_4
@ INA3221_NUM_SAMPLES_4
4
Definition: ina3221.h:176
ina3221_alert_t
enum ina3221_alert ina3221_alert_t
Alert indices.
ina3221_params_t::pin_warn
gpio_t pin_warn
Warning alert pin, becomes configured as input.
Definition: ina3221.h:235
INA3221_ALERT_TC
@ INA3221_ALERT_TC
Timing control.
Definition: ina3221.h:122
INA3221_BAD_MANUF_ID
@ INA3221_BAD_MANUF_ID
Read device manufacturer ID failed.
Definition: ina3221.h:91
ina3221_mode_t
enum ina3221_mode ina3221_mode_t
Device operation modes.
ina3221_t::arg_tc_cb
void * arg_tc_cb
Argument for Timing control alert callback.
Definition: ina3221.h:313
INA3221_MODE_MASK
#define INA3221_MODE_MASK
Device operation mode bit mask.
Definition: ina3221.h:139
INA3221_ALERT_WRN
@ INA3221_ALERT_WRN
Warning alert.
Definition: ina3221.h:120
ina3221_disable_warning_alert
static int ina3221_disable_warning_alert(ina3221_t *dev)
Wrapper around.
Definition: ina3221.h:457
INA3221_ADDR_00
@ INA3221_ADDR_00
A0 connected to GND.
Definition: ina3221.h:101
INA3221_CONV_TIME_SADC_140US
@ INA3221_CONV_TIME_SADC_140US
140 us
Definition: ina3221.h:145
ina3221_set_config
static int ina3221_set_config(ina3221_t *dev, ina3221_enable_ch_t chs, ina3221_num_samples_t ns, ina3221_conv_time_bus_adc_t ctbadc, ina3221_conv_time_shunt_adc_t ctsadc, ina3221_mode_t mode)
Wrapper around.
Definition: ina3221.h:527
ina3221_set_power_valid_lower_limit
int ina3221_set_power_valid_lower_limit(const ina3221_t *dev, int32_t in_mv)
Set bus voltage power valid lower limit to in_mv.
INA3221_BAD_DIE_ID
@ INA3221_BAD_DIE_ID
Read device DIE ID failed.
Definition: ina3221.h:92
ina3221_set_power_valid_upper_limit
int ina3221_set_power_valid_upper_limit(const ina3221_t *dev, int32_t in_mv)
Set bus voltage power valid upper limit to in_mv.
ina3221_calculate_power_uw
int ina3221_calculate_power_uw(int16_t *in_mv, int32_t *in_ua, uint8_t num, int32_t *out_mw)
Calculate power from bus voltage and current values.
ina3221_params_t
INA3221 device parameters.
Definition: ina3221.h:230
ina3221_num_samples_t
enum ina3221_num_samples ina3221_num_samples_t
Number of samples to calculate average shunt/bus voltage value.
ina3221_mode
ina3221_mode
Device operation modes.
Definition: ina3221.h:129
gpio.h
Low-level GPIO peripheral driver interface definitions.
ina3221_read_bus_mv
int ina3221_read_bus_mv(const ina3221_t *dev, ina3221_channel_t ch, int16_t *out_mv, uint16_t *flags)
Read bus voltages for each channel in ch.
ina3221_params_t::gpio_config
uint8_t gpio_config
Configure pull up resistors for gpio pins.
Definition: ina3221.h:249
INA3221_MODE_CONTINUOUS_SHUNT_ONLY
@ INA3221_MODE_CONTINUOUS_SHUNT_ONLY
Continuous shunt voltage measurement only.
Definition: ina3221.h:135
ina3221_set_channel_state
static int ina3221_set_channel_state(ina3221_t *dev, ina3221_channel_state_t ch1, ina3221_channel_state_t ch2, ina3221_channel_state_t ch3)
Wrapper around.
Definition: ina3221.h:600
INA3221_CONV_TIME_BADC_MASK
#define INA3221_CONV_TIME_BADC_MASK
ADC bus voltage conversion times bit mask.
Definition: ina3221.h:169
ina3221_t::arg_pv_cb
void * arg_pv_cb
Argument for Power Valid alert callback.
Definition: ina3221.h:314
INA3221_ALERT_PV
@ INA3221_ALERT_PV
Power valid alert.
Definition: ina3221.h:123
INA3221_MODE_CONTINUOUS_SHUNT_BUS
@ INA3221_MODE_CONTINUOUS_SHUNT_BUS
Continuous shunt and bus voltage measurement.
Definition: ina3221.h:137
ina3221_get_crit_alert_limit
int ina3221_get_crit_alert_limit(const ina3221_t *dev, ina3221_channel_t ch, int32_t *out_uv)
Read critical shunt voltage alert limit for each channel in ch.
ina3221_params_t::pin_tc
gpio_t pin_tc
Timing control alert pin, becomes configured as input.
Definition: ina3221.h:237
ina3221_enable_latch_t
enum ina3221_enable_latch ina3221_enable_latch_t
Enable latch flags.
INA3221_CONV_TIME_SADC_588US
@ INA3221_CONV_TIME_SADC_588US
588 us
Definition: ina3221.h:148
ina3221_t::params
ina3221_params_t params
Device parameters.
Definition: ina3221.h:296
INA3221_ENABLE_CH2
@ INA3221_ENABLE_CH2
Enable channel 2.
Definition: ina3221.h:191
INA3221_CONV_TIME_SADC_4156US
@ INA3221_CONV_TIME_SADC_4156US
4156 us
Definition: ina3221.h:151
INA3221_CONV_TIME_BADC_8244US
@ INA3221_CONV_TIME_BADC_8244US
8244 us
Definition: ina3221.h:167
ina3221_params_t::i2c
i2c_t i2c
I2C bus.
Definition: ina3221.h:231
ina3221_ret_val
ina3221_ret_val
Return codes.
Definition: ina3221.h:88
ina3221_conv_time_bus_adc_t
enum ina3221_conv_time_bus_adc ina3221_conv_time_bus_adc_t
ADC bus voltage conversion times.
ina3221_channel
ina3221_channel
Channel flags.
Definition: ina3221.h:110
ina3221_enable_power_valid_alert
static int ina3221_enable_power_valid_alert(ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
Wrapper around.
Definition: ina3221.h:430
ina3221_set_shunt_voltage_sum_alert_limit
int ina3221_set_shunt_voltage_sum_alert_limit(const ina3221_t *dev, int32_t in_uv)
Set shunt voltage sum alert limit to in_uv.
ina3221_get_num_samples
int ina3221_get_num_samples(const ina3221_t *dev, ina3221_num_samples_t *ns)
Read currently applied number of samples.
ina3221_calculate_current_ua
int ina3221_calculate_current_ua(const ina3221_t *dev, ina3221_channel_t ch, int32_t *in_uv, int32_t *out_ma)
Calculate current for each channel in ch.
ina3221_init
int ina3221_init(ina3221_t *dev, const ina3221_params_t *params)
Initialize device.
INA3221_NUM_SAMPLES_16
@ INA3221_NUM_SAMPLES_16
16
Definition: ina3221.h:177
INA3221_CH3
@ INA3221_CH3
Channel 3.
Definition: ina3221.h:113
INA3221_NUM_SAMPLES_1
@ INA3221_NUM_SAMPLES_1
1
Definition: ina3221.h:175
ina3221_read_flags
int ina3221_read_flags(const ina3221_t *dev, uint16_t *flags)
Read status flags.
ina3221_t::crit_cb
ina3221_alert_cb_t crit_cb
Critical alert callback: executed when CRT is pulled low.
Definition: ina3221.h:301
ina3221_get_warn_alert_limit
int ina3221_get_warn_alert_limit(const ina3221_t *dev, ina3221_channel_t ch, int32_t *out_uv)
Read warning shunt voltage alert limit for each channel in ch.
ina3221_t::pv_cb
ina3221_alert_cb_t pv_cb
Power Valid alert callback: executed when PV is pulled low.
Definition: ina3221.h:303
INA3221_CONV_TIME_SADC_332US
@ INA3221_CONV_TIME_SADC_332US
332 us
Definition: ina3221.h:147
ina3221_get_power_valid_lower_limit
int ina3221_get_power_valid_lower_limit(const ina3221_t *dev, int32_t *out_mv)
Read bus voltage power valid lower limit.
i2c.h
Low-level I2C peripheral driver interface definition.
INA3221_CH_DISABLE
@ INA3221_CH_DISABLE
Channel disabled.
Definition: ina3221.h:202
INA3221_MODE_TRIGGER_SHUNT_BUS
@ INA3221_MODE_TRIGGER_SHUNT_BUS
Trigger shunt and bus voltage measurement.
Definition: ina3221.h:133
ina3221_set_mode
int ina3221_set_mode(ina3221_t *dev, ina3221_mode_t mode)
Update device operation mode.
ina3221_get_config
static int ina3221_get_config(const ina3221_t *dev, ina3221_enable_ch_t *chs, ina3221_num_samples_t *ns, ina3221_conv_time_bus_adc_t *ctbadc, ina3221_conv_time_shunt_adc_t *ctsadc, ina3221_mode_t *mode)
Wrapper around.
Definition: ina3221.h:559
ina3221_enable_warning_alert
static int ina3221_enable_warning_alert(ina3221_t *dev, ina3221_alert_cb_t cb, void *arg)
Wrapper around.
Definition: ina3221.h:380
ina3221_enable_ch_t
enum ina3221_enable_ch ina3221_enable_ch_t
Enable channel flags.
INA3221_ADDR_10
@ INA3221_ADDR_10
A0 connected to SDA.
Definition: ina3221.h:103
ina3221_params_t::pin_pv
gpio_t pin_pv
Power valid alert pin, becomes configured as input.
Definition: ina3221.h:238
INA3221_ENABLE_SUM_CH3
@ INA3221_ENABLE_SUM_CH3
Enable sum channel 3.
Definition: ina3221.h:212
ina3221_t::arg_warn_cb
void * arg_warn_cb
Argument for Warning alert callback.
Definition: ina3221.h:311
ina3221_get_shunt_voltage_sum_alert_limit
int ina3221_get_shunt_voltage_sum_alert_limit(const ina3221_t *dev, int32_t *out_uv)
Read shunt voltage sum alert limit.
INA3221_NUM_SAMPLES_1024
@ INA3221_NUM_SAMPLES_1024
1024
Definition: ina3221.h:182