LibDriver INA226  1.0.0
INA226 full-featured driver
driver_ina226.h File Reference

driver ina226 header file More...

#include <stdio.h>
#include <stdint.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  ina226_handle_s
 ina226 handle structure definition More...
 
struct  ina226_info_s
 ina226 information structure definition More...
 

Macros

#define INA226_READ_TIMEOUT   1000
 ina226 read timeout definition More...
 
#define DRIVER_INA226_LINK_INIT(HANDLE, STRUCTURE)   memset(HANDLE, 0, sizeof(STRUCTURE))
 initialize ina226_handle_t structure More...
 
#define DRIVER_INA226_LINK_IIC_INIT(HANDLE, FUC)   (HANDLE)->iic_init = FUC
 link iic_init function More...
 
#define DRIVER_INA226_LINK_IIC_DEINIT(HANDLE, FUC)   (HANDLE)->iic_deinit = FUC
 link iic_deinit function More...
 
#define DRIVER_INA226_LINK_IIC_READ(HANDLE, FUC)   (HANDLE)->iic_read = FUC
 link iic_read function More...
 
#define DRIVER_INA226_LINK_IIC_WRITE(HANDLE, FUC)   (HANDLE)->iic_write = FUC
 link iic_write function More...
 
#define DRIVER_INA226_LINK_DELAY_MS(HANDLE, FUC)   (HANDLE)->delay_ms = FUC
 link delay_ms function More...
 
#define DRIVER_INA226_LINK_DEBUG_PRINT(HANDLE, FUC)   (HANDLE)->debug_print = FUC
 link debug_print function More...
 
#define DRIVER_INA226_LINK_RECEIVE_CALLBACK(HANDLE, FUC)   (HANDLE)->receive_callback = FUC
 link receive_callback function More...
 

Typedefs

typedef struct ina226_handle_s ina226_handle_t
 ina226 handle structure definition More...
 
typedef struct ina226_info_s ina226_info_t
 ina226 information structure definition More...
 

Enumerations

enum  ina226_address_t {
  INA226_ADDRESS_0 = (0x40 << 1) , INA226_ADDRESS_1 = (0x41 << 1) , INA226_ADDRESS_2 = (0x42 << 1) , INA226_ADDRESS_3 = (0x43 << 1) ,
  INA226_ADDRESS_4 = (0x44 << 1) , INA226_ADDRESS_5 = (0x45 << 1) , INA226_ADDRESS_6 = (0x46 << 1) , INA226_ADDRESS_7 = (0x47 << 1) ,
  INA226_ADDRESS_8 = (0x48 << 1) , INA226_ADDRESS_9 = (0x49 << 1) , INA226_ADDRESS_A = (0x4A << 1) , INA226_ADDRESS_B = (0x4B << 1) ,
  INA226_ADDRESS_C = (0x4C << 1) , INA226_ADDRESS_D = (0x4D << 1) , INA226_ADDRESS_E = (0x4E << 1) , INA226_ADDRESS_F = (0x4F << 1)
}
 ina226 address enumeration definition More...
 
enum  ina226_bool_t { INA226_BOOL_FALSE = 0x00 , INA226_BOOL_TRUE = 0x01 }
 ina226 bool enumeration definition More...
 
enum  ina226_avg_t {
  INA226_AVG_1 = 0 , INA226_AVG_4 = 1 , INA226_AVG_16 = 2 , INA226_AVG_64 = 3 ,
  INA226_AVG_128 = 4 , INA226_AVG_256 = 5 , INA226_AVG_512 = 6 , INA226_AVG_1024 = 7
}
 ina226 average enumeration definition More...
 
enum  ina226_conversion_time_t {
  INA226_CONVERSION_TIME_140_US = 0 , INA226_CONVERSION_TIME_204_US = 1 , INA226_CONVERSION_TIME_332_US = 2 , INA226_CONVERSION_TIME_588_US = 3 ,
  INA226_CONVERSION_TIME_1P1_MS = 4 , INA226_CONVERSION_TIME_2P116_MS = 5 , INA226_CONVERSION_TIME_4P156_MS = 6 , INA226_CONVERSION_TIME_8P244_MS = 7
}
 
enum  ina226_mode_t {
  INA226_MODE_POWER_DOWN = 0x0 , INA226_MODE_SHUNT_VOLTAGE_TRIGGERED = 0x1 , INA226_MODE_BUS_VOLTAGE_TRIGGERED = 0x2 , INA226_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED = 0x3 ,
  INA226_MODE_SHUTDOWN = 0x4 , INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS = 0x5 , INA226_MODE_BUS_VOLTAGE_CONTINUOUS = 0x6 , INA226_MODE_SHUNT_BUS_VOLTAGE_CONTINUOUS = 0x7
}
 ina226 mode enumeration definition More...
 
enum  ina226_status_t {
  INA226_STATUS_SHUNT_VOLTAGE_OVER_VOLTAGE = 15 , INA226_STATUS_SHUNT_VOLTAGE_UNDER_VOLTAGE = 14 , INA226_STATUS_BUS_VOLTAGE_OVER_VOLTAGE = 13 , INA226_STATUS_BUS_VOLTAGE_UNDER_VOLTAGE = 12 ,
  INA226_STATUS_POWER_OVER_LIMIT = 11
}
 ina226 status enumeration definition More...
 
enum  ina226_mask_t {
  INA226_MASK_SHUNT_VOLTAGE_OVER_VOLTAGE = 15 , INA226_MASK_SHUNT_VOLTAGE_UNDER_VOLTAGE = 14 , INA226_MASK_BUS_VOLTAGE_OVER_VOLTAGE = 13 , INA226_MASK_BUS_VOLTAGE_UNDER_VOLTAGE = 12 ,
  INA226_MASK_POWER_OVER_LIMIT = 11
}
 ina226 mask enumeration definition More...
 
enum  ina226_alert_polarity_t { INA226_ALERT_POLARITY_NORMAL = 0 , INA226_ALERT_POLARITY_INVERTED = 1 }
 ina226 alert polarity enumeration definition More...
 

Functions

uint8_t ina226_info (ina226_info_t *info)
 get chip's information More...
 
uint8_t ina226_set_addr_pin (ina226_handle_t *handle, ina226_address_t addr_pin)
 set the iic address pin More...
 
uint8_t ina226_get_addr_pin (ina226_handle_t *handle, ina226_address_t *addr_pin)
 get the iic address pin More...
 
uint8_t ina226_set_resistance (ina226_handle_t *handle, double resistance)
 set the resistance More...
 
uint8_t ina226_get_resistance (ina226_handle_t *handle, double *resistance)
 get the resistance More...
 
uint8_t ina226_irq_handler (ina226_handle_t *handle)
 irq handler More...
 
uint8_t ina226_init (ina226_handle_t *handle)
 initialize the chip More...
 
uint8_t ina226_deinit (ina226_handle_t *handle)
 close the chip More...
 
uint8_t ina226_soft_reset (ina226_handle_t *handle)
 soft reset the chip More...
 
uint8_t ina226_set_average_mode (ina226_handle_t *handle, ina226_avg_t mode)
 set average mode More...
 
uint8_t ina226_get_average_mode (ina226_handle_t *handle, ina226_avg_t *mode)
 get average mode More...
 
uint8_t ina226_set_bus_voltage_conversion_time (ina226_handle_t *handle, ina226_conversion_time_t t)
 set bus voltage conversion time More...
 
uint8_t ina226_get_bus_voltage_conversion_time (ina226_handle_t *handle, ina226_conversion_time_t *t)
 get bus voltage conversion time More...
 
uint8_t ina226_set_shunt_voltage_conversion_time (ina226_handle_t *handle, ina226_conversion_time_t t)
 set shunt voltage conversion time More...
 
uint8_t ina226_get_shunt_voltage_conversion_time (ina226_handle_t *handle, ina226_conversion_time_t *t)
 get shunt voltage conversion time More...
 
uint8_t ina226_set_mode (ina226_handle_t *handle, ina226_mode_t mode)
 set the mode More...
 
uint8_t ina226_get_mode (ina226_handle_t *handle, ina226_mode_t *mode)
 get the mode More...
 
uint8_t ina226_read_shunt_voltage (ina226_handle_t *handle, int16_t *raw, float *mV)
 read the shunt voltage More...
 
uint8_t ina226_read_bus_voltage (ina226_handle_t *handle, uint16_t *raw, float *mV)
 read the bus voltage More...
 
uint8_t ina226_read_power (ina226_handle_t *handle, uint16_t *raw, float *mW)
 read the power More...
 
uint8_t ina226_read_current (ina226_handle_t *handle, int16_t *raw, float *mA)
 read the current More...
 
uint8_t ina226_set_calibration (ina226_handle_t *handle, uint16_t data)
 set the calibration More...
 
uint8_t ina226_get_calibration (ina226_handle_t *handle, uint16_t *data)
 get the calibration More...
 
uint8_t ina226_calculate_calibration (ina226_handle_t *handle, uint16_t *calibration)
 calculate the calibration More...
 
uint8_t ina226_set_mask (ina226_handle_t *handle, ina226_mask_t mask, ina226_bool_t enable)
 enable or disable mask More...
 
uint8_t ina226_get_mask (ina226_handle_t *handle, ina226_mask_t mask, ina226_bool_t *enable)
 get mask More...
 
uint8_t ina226_set_conversion_ready_alert_pin (ina226_handle_t *handle, ina226_bool_t enable)
 enable or disable conversion ready alert pin More...
 
uint8_t ina226_get_conversion_ready_alert_pin (ina226_handle_t *handle, ina226_bool_t *enable)
 get conversion ready alert pin status More...
 
uint8_t ina226_set_alert_polarity_pin (ina226_handle_t *handle, ina226_alert_polarity_t pin)
 set alert polarity pin More...
 
uint8_t ina226_get_alert_polarity_pin (ina226_handle_t *handle, ina226_alert_polarity_t *pin)
 get alert polarity pin More...
 
uint8_t ina226_set_alert_latch (ina226_handle_t *handle, ina226_bool_t enable)
 enable or disable alert latch More...
 
uint8_t ina226_get_alert_latch (ina226_handle_t *handle, ina226_bool_t *enable)
 get alert latch status More...
 
uint8_t ina226_set_alert_limit (ina226_handle_t *handle, uint16_t reg)
 set alert limit More...
 
uint8_t ina226_get_alert_limit (ina226_handle_t *handle, uint16_t *reg)
 get alert limit More...
 
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 More...
 
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 More...
 
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 More...
 
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 More...
 
uint8_t ina226_power_convert_to_register (ina226_handle_t *handle, float mW, uint16_t *reg)
 convert the power to the register raw data More...
 
uint8_t ina226_power_convert_to_data (ina226_handle_t *handle, uint16_t reg, float *mW)
 convert the register raw data to the power More...
 
uint8_t ina226_get_die_id (ina226_handle_t *handle, uint16_t *device_id, uint8_t *die_revision_id)
 get the die id More...
 
uint8_t ina226_set_reg (ina226_handle_t *handle, uint8_t reg, uint16_t data)
 set the chip register More...
 
uint8_t ina226_get_reg (ina226_handle_t *handle, uint8_t reg, uint16_t *data)
 get the chip register More...
 

Detailed Description

driver ina226 header file

Copyright (c) 2015 - present LibDriver All rights reserved

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version
1.0.0
Author
Shifeng Li
Date
2025-01-29

history

Date Version Author Description
2025/01/29 1.0 Shifeng Li first upload

Definition in file driver_ina226.h.