#ifndef _NRF_INA226_H #define _NRF_INA226_H #include "define.h" #include "nrf_drv_gpiote.h" #define CFG_REG 0x00 // #define SV_REG 0x01 //分流电压, 此处分流电阻为 0.1欧 #define BV_REG 0x02 //总线电压 #define PWR_REG 0x03 //电源功率 #define CUR_REG 0x04 //电流 #define CAL_REG 0x05 //校准,设定满量程范围以及电流和功率测数的 #define ONFF_REG 0x06 //屏蔽 使能 警报配置和转换准备就绪 #define AL_REG 0x07 //包含与所选警报功能相比较的限定值 #define INA226_GET_ADDR 0xFF //包含唯一的芯片标识号 //#define INA226_ADDR1 0x80 #define INA226_RST 0xC000 //reset typedef void (*ina226_work_finish_func)(void); typedef enum { INA226_QUEUE_TIME=0, INA226_QUEUE_INT=1, }INA226_QUEUE_TYPE; typedef enum { INA226_AVG_1=0x00, INA226_AVG_4=0x01, INA226_AVG_16=0x02, INA226_AVG_64=0x03, INA226_AVG_128=0x04, INA226_AVG_256=0x05, INA226_AVG_512=0x06, INA226_AVG_1024=0x07, }ina226_averaging_mode_e; typedef enum { INA226_CONVERSION_140US=0x00, INA226_CONVERSION_204US=0x01, INA226_CONVERSION_332US=0x02, INA226_CONVERSION_588US=0x03, INA226_CONVERSION_1100US=0x04, INA226_CONVERSION_2116US=0x05, INA226_CONVERSION_4156US=0x06, INA226_CONVERSION_8244US=0x07, }ina226_conversion_time_e; typedef enum { INA226_OPERATION_SHUTDOWN=0x04, INA226_OPERATION_SHUNT_TRIG=0x05, INA226_OPERATION_BUS_TRIG=0x06, INA226_OPERATION_SHUNT_BUS_TRIG=0x07, }ina226_operating_mode_s; typedef struct { uint8_t idx; //下标 uint8_t ina226_addr; //i2c地址 ina226_averaging_mode_e avg_mode; //采样平均次数 ina226_conversion_time_e bus_conversion_time; //单次总线电压采样间隔 ina226_conversion_time_e shunt_conversion_time; //单次分流电压采样间隔 ina226_operating_mode_s operation_mode; //工作模式 double current_lsb; //电流分辨率 double shunt_res; //分流电阻阻值 float voltageVal; //mV float Shunt_voltage; //uV float Shunt_Current; //mA float powerVal; }ina226_struct; void ina226_timers_init(void); void ina226_alert_init(nrf_drv_gpiote_in_config_t *config,nrfx_gpiote_evt_handler_t evt_handler); void Set_Ina226_Queue(INA226_QUEUE_TYPE type); void INA226_Init_Idx(ina226_struct *ina226); void INA226_Init(ina226_struct *ina226); void INA226_Uinit(ina226_struct *ina226); void ina226_set_work_finish_func(ina226_work_finish_func func); void ina226_start(void); void ina226_stop(void); #endif //_NRF_INA226_H