SELKIELogger  1.0.0
I2C-INA219.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SELKIELoggerI2C_INA219
22 #define SELKIELoggerI2C_INA219
23 
24 #include <stdbool.h>
25 
43 #define INA219_REG_CONFIG 0x00
44 
46 #define INA219_REG_SHUNT 0x01
47 
49 #define INA219_REG_BUS 0x02
50 
52 #define INA219_REG_POWER 0x03
53 
55 #define INA219_REG_CURRENT 0x04
56 
58 #define INA219_REG_CALIBRATION 0x05
59 
61 
78 #define INA219_CONFIG_DEF 0x3DDF
79 
83 #define INA219_CONFIG_RESET 0x8000
84 
85 typedef struct {
86  float scale;
87  float offset;
88  float min;
89  float max;
91 
92 #define I2C_INA219_DEFAULTS \
93  { .scale = 1.0, .offset = 0.0, .min = -INFINITY, .max = INFINITY }
95 
102 bool i2c_ina219_configure(const int busHandle, const int devAddr);
103 
105 uint16_t i2c_ina219_read_configuration(const int busHandle, const int devAddr);
106 
108 float i2c_ina219_read_shuntVoltage(const int busHandle, const int devAddr, const void *opts);
109 
111 float i2c_ina219_read_busVoltage(const int busHandle, const int devAddr, const void *opts);
112 
114 float i2c_ina219_read_power(const int busHandle, const int devAddr, const void *opts);
115 
117 float i2c_ina219_read_current(const int busHandle, const int devAddr, const void *opts);
118 
120 #endif
float i2c_ina219_read_shuntVoltage(const int busHandle, const int devAddr, const void *opts)
Get voltage across the shunt resistor in millivolts.
Definition: I2C-INA219.c:77
bool i2c_ina219_configure(const int busHandle, const int devAddr)
Send configuration command to the specified device.
Definition: I2C-INA219.c:40
float i2c_ina219_read_current(const int busHandle, const int devAddr, const void *opts)
Get current flow through shunt resistor in amps.
Definition: I2C-INA219.c:173
float i2c_ina219_read_busVoltage(const int busHandle, const int devAddr, const void *opts)
Get bus voltage (at V- terminal) in volts.
Definition: I2C-INA219.c:115
uint16_t i2c_ina219_read_configuration(const int busHandle, const int devAddr)
Read configuration from device.
Definition: I2C-INA219.c:59
float i2c_ina219_read_power(const int busHandle, const int devAddr, const void *opts)
Get power consumption in watts.
Definition: I2C-INA219.c:148
float offset
Add this amount to received value.
Definition: I2C-INA219.h:87
float min
If not NaN, smallest value considered valid.
Definition: I2C-INA219.h:88
float max
If not NaN, largest value considered valid.
Definition: I2C-INA219.h:89
float scale
Scale received value by this quantity.
Definition: I2C-INA219.h:86