LibDriver INA226
Loading...
Searching...
No Matches
driver_ina226.h File Reference

driver ina226 header file More...

#include <stdio.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for driver_ina226.h:
This graph shows which files directly or indirectly include this file:

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
#define DRIVER_INA226_LINK_INIT(HANDLE, STRUCTURE)
 initialize ina226_handle_t structure
#define DRIVER_INA226_LINK_IIC_INIT(HANDLE, FUC)
 link iic_init function
#define DRIVER_INA226_LINK_IIC_DEINIT(HANDLE, FUC)
 link iic_deinit function
#define DRIVER_INA226_LINK_IIC_READ(HANDLE, FUC)
 link iic_read function
#define DRIVER_INA226_LINK_IIC_WRITE(HANDLE, FUC)
 link iic_write function
#define DRIVER_INA226_LINK_DELAY_MS(HANDLE, FUC)
 link delay_ms function
#define DRIVER_INA226_LINK_DEBUG_PRINT(HANDLE, FUC)
 link debug_print function
#define DRIVER_INA226_LINK_RECEIVE_CALLBACK(HANDLE, FUC)
 link receive_callback function

Typedefs

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

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

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.