Motion_EC_Stm32_archived/Middlewares/Coulomb/coulomb.h

105 lines
3.4 KiB
C

/*
* coulomb.h
*
* Created on: Apr 27, 2020
* Author: oarap
*/
#ifndef _COULOMB_H_
#define _COULOMB_H_
#include "stdbool.h"
#include "i2c.h"
#include "stm32f1xx_hal.h"
#define COULOMB_ADDR (0x64 << 1) //device address
//#define COULOMB_WRITE_CMD 0x00 //coulomb write command
//#define COULOMB_READ_CMD 0x01 //coulomb read command
#define LTC2943_STATUS_REG 0x00
#define LTC2943_CONTROL_REG 0x01
#define LTC2943_ACCUM_CHARGE_MSB_REG 0x02
#define LTC2943_ACCUM_CHARGE_LSB_REG 0x03
#define LTC2943_CHARGE_THRESH_HIGH_MSB_REG 0x04
#define LTC2943_CHARGE_THRESH_HIGH_LSB_REG 0x05
#define LTC2943_CHARGE_THRESH_LOW_MSB_REG 0x06
#define LTC2943_CHARGE_THRESH_LOW_LSB_REG 0x07
#define LTC2943_VOLTAGE_MSB_REG 0x08
#define LTC2943_VOLTAGE_LSB_REG 0x09
#define LTC2943_VOLTAGE_THRESH_HIGH_MSB_REG 0x0A
#define LTC2943_VOLTAGE_THRESH_HIGH_LSB_REG 0x0B
#define LTC2943_VOLTAGE_THRESH_LOW_MSB_REG 0x0C
#define LTC2943_VOLTAGE_THRESH_LOW_LSB_REG 0x0D
#define LTC2943_CURRENT_MSB_REG 0x0E
#define LTC2943_CURRENT_LSB_REG 0x0F
#define LTC2943_CURRENT_THRESH_HIGH_MSB_REG 0x10
#define LTC2943_CURRENT_THRESH_HIGH_LSB_REG 0x11
#define LTC2943_CURRENT_THRESH_LOW_MSB_REG 0x12
#define LTC2943_CURRENT_THRESH_LOW_LSB_REG 0x13
#define LTC2943_TEMPERATURE_MSB_REG 0x14
#define LTC2943_TEMPERATURE_LSB_REG 0x15
#define LTC2943_TEMPERATURE_THRESH_HIGH_REG 0x16
#define LTC2943_TEMPERATURE_THRESH_LOW_REG 0x17
typedef struct
{
struct
{//原始数据
uint8_t status;
uint8_t control;
uint16_t accumulated_charge;
uint16_t charge_threshold_H; //充电阈值上限
uint16_t charge_threshold_L; //充电阈值下限
uint16_t voltage; //电压
uint16_t voltage_threshold_H; //电压阈值上限
uint16_t voltage_threshold_L; //电压阈值下限
uint16_t current; //电流
uint16_t current_threshold_H; //电流阈值上限
uint16_t current_threshold_L; //电流阈值下限
uint16_t temperature; //温度
uint8_t temperature_threshold_H; //温度阈值上限
uint8_t temperature_threshold_L; //温度阈值下限
}raw;
struct
{//实际数据(转换后)
struct
{
bool current_alret;
bool accumulated_charge_alert;
bool temperature_alret;
bool charge_alert_H;
bool charge_alert_L;
bool voltage_alert;
bool uvlo_alert;
}status;
float accumulated_charge;
float charge_threshold_H; //充电阈值上限
float charge_threshold_L; //充电阈值下限
float voltage; //电压
float voltage_threshold_H; //电压阈值上限
float voltage_threshold_L; //电压阈值下限
float current; //电流
float current_threshold_H; //电流阈值上限
float current_threshold_L; //电流阈值下限
float temperature; //温度
float temperature_threshold_H; //温度阈值上限
float temperature_threshold_L; //温度阈值下限
}actual;
}coulomb_t;
extern coulomb_t coulomb;
//bool is_coulomb_ready();
static HAL_StatusTypeDef coulomb_write_reg(uint8_t addr,uint8_t* pData);
static HAL_StatusTypeDef coulomb_read_reg(uint8_t addr,uint8_t* pData);
HAL_StatusTypeDef coulomb_read_status();
//bool coulomb_read_alcc();
#endif /* _COULOMB_H_ */