#ifndef __INA226_H__ #define __INA226_H__ #include "common.h" #define INA226_USE_SOFT_IIC 0 #define INA226_NUM 1 #define INA226_READ_TIME_MS 1 #if (1==INA226_USE_SOFT_IIC) #define INA226_SDA_PIN P24 #define INA226_SCL_PIN P25 #define INA226_SOFT_WAIT_TIME 5 #define INA226_SDA_LEVEL(x) (INA226_SDA_PIN = x) #define INA226_SCL_LEVEL(x) (INA226_SCL_PIN = x) #define INA226_SDA_READ() (INA226_SDA_PIN) #else #define INA226_IIC IIC_1 #define INA226_HARD_WAIT_TIME 10 #endif #define INA226_CONFIG_REG 0x00 #define INA226_SHUNTVOT_REG 0x01 #define INA226_BUSVOT_REG 0x02 #define INA226_POWER_REG 0x03 #define INA226_CURRENT_REG 0x04 #define INA226_CALIBRATION_REG 0x05 #define INA226_DEF_ADDR 0x40 #define INA226_DEF_MODE {0x44, 0x4F} #define INA226_DEF_CAL {0x0D, 0x1B} typedef struct { uint8 addr; float max_current_A; float rshunt_mOhm; float vot_fix_k; float amp_fix_k; uint8 mode[2]; } INA226_Config; typedef struct { float c_lsb_mA; uint8 cal[2]; } INA226_Calibration; typedef struct { float voltage_V; float current_A; float power_W; float shunt_voltage_mV; float energy_J; float quantity_C; uint8 org_reg[4][2]; float past_voltage_V[10]; float past_current_A[10]; } INA226_Result; typedef struct { INA226_Config config; INA226_Calibration calibration; INA226_Result result; } INA226_t; extern INA226_t ina226[INA226_NUM]; void INA226_Init(INA226_t *ina226, uint8 addr, uint8 mode[2], float max_current_A, float rshunt_mOhm, float amp_fix_k, float vot_fix_k); void INA226_Read(INA226_t *ina226); #endif