This is a library for the MAX17055 Li+ Battery Fuel Gauge.
Dependents: Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot
Fork of max17055 by
Diff: max17055.h
- Revision:
- 7:479a36909ced
- Parent:
- 6:5ced10109ebf
- Child:
- 8:ca8765c30ed2
--- a/max17055.h Thu Oct 05 02:37:59 2017 +0000 +++ b/max17055.h Tue Oct 10 00:06:40 2017 +0000 @@ -55,7 +55,7 @@ #define MAX17055_STATUS_POR (1 << 1) /// Model loading options -#define MODEL_LOADING_OPTION1 1 +#define MODEL_LOADING_OPTION1 1 //may need to move thisa to class definition #define MODEL_LOADING_OPTION2 2 #define MODEL_LOADING_OPTION3 3 @@ -97,67 +97,9 @@ * @endcode */ - /** - * @brief Saved Fuel Gauge Parameters - * @details Struct with saved fuel Gauge Parametrs - */ - -struct saved_fuel_gauge_params_t{ - int rcomp0; /**< Explain */ - int temp_co; /**< Explain */ - int full_cap_rep; /**< Explain */ - int cycles; /**< Explain */ - int full_cap_nom; /**< Explain */ - } ; - - /** - * @brief Saved Fuel Gauge Parameters - * @details Struct with saved fuel Gauge Parametrs - */ - struct max17055_platform_data{ - uint16_t designcap;/**< struct value 1 */ - uint16_t ichgterm; /**< struct value 2 */ - uint16_t vempty; /**< struct value 3 */ - int vcharge; /**< struct value 1 */ - uint16_t learncfg; /**< struct value 1 */ - uint16_t relaxcfg; /**< struct value 1 */ - uint16_t config; /**< struct value 1 */ - uint16_t config2; /**< struct value 1 */ - uint16_t fullsocthr;/**< struct value 1 */ - uint16_t tgain; /**< struct value 1 */ - uint16_t toff; /**< struct value 1 */ - uint16_t curve; /**< struct value 1 */ - uint16_t rcomp0; /**< struct value 1 */ - uint16_t tempco; /**< struct value 1 */ - uint16_t qrtable00; - uint16_t qrtable10; - uint16_t qrtable20; - uint16_t qrtable30; - - uint16_t dpacc; - uint16_t modelcfg; - - //uint16_t model_data[MAX17055_TABLE_SIZE]; - int (*get_charging_status)(void); - int model_option; - /** - * rsense in miliOhms. - * default 10 (if rsense = 0) as it is the recommended value by - * the datasheet although it can be changed by board designers. - */ - unsigned int rsense; - int volt_min; /**< in mV */ - int volt_max; /**< in mV */ - int temp_min; /**< in DegreC */ - int temp_max; /**< in DegreeC */ - int soc_max; /**< in percent */ - int soc_min; /**< in percent */ - int curr_max; /**< in mA */ - int curr_min; /**< in mA */ - } ; @@ -215,8 +157,7 @@ //Defined instance for external structs struct BATTERY::battery_cfg_t batt_con; - struct max17055_platform_data design_data; - struct saved_fuel_gauge_params_t fuelGauge_params; + @@ -225,67 +166,132 @@ * @details Enumerated register addresses */ enum Registers_e { - MAX17055_STATUS_REG = 0x00, /**< 0x00 */ - MAX17055_VALRTTH_REG = 0x01, /**< 0x01 */ - MAX17055_TALRTTH_REG = 0x02, /**< 0x02 */ - MAX17055_SALRTTH_REG = 0x03, /**< 0x04 */ - MAX17055_REPCAP_REG = 0x05, /**< 0x05 */ - MAX17055_REPSOC_REG = 0x06, /**< 0x06 */ - MAX17055_TEMP_REG = 0x08, /**< 0x07 */ - MAX17055_VCELL_REG = 0x09, /**< 0x08 */ - MAX17055_CURRENT_REG = 0x0A, /**< 0x0A */ - MAX17055_AVGCURRENT_REG = 0x0B, /**< 0x0B */ - MAX17055_REMCAP_REG = 0x0F, /**< 0x0F */ + STATUS_REG = 0x00, /**< 0x00 */ + VALRTTH_REG = 0x01, /**< 0x01 */ + TALRTTH_REG = 0x02, /**< 0x02 */ + SALRTTH_REG = 0x03, /**< 0x04 */ + REPCAP_REG = 0x05, /**< 0x05 */ + REPSOC_REG = 0x06, /**< 0x06 */ + TEMP_REG = 0x08, /**< 0x07 */ + VCELL_REG = 0x09, /**< 0x08 */ + CURRENT_REG = 0x0A, /**< 0x0A */ + AVGCURRENT_REG = 0x0B, /**< 0x0B */ + REMCAP_REG = 0x0F, /**< 0x0F */ + + FULLCAPREP_REG = 0x10, /**< 0x10 */ + TTE_REG = 0X11, /**< 0x11 */ + QRTABLE00_REG = 0x12, /**< 0x12 */ + FULLSOCTHR_REG = 0x13, /**< 0x13 */ + CYCLES_REG = 0x17, /**< 0x17 */ + DESIGNCAP_REG = 0x18, /**< 0x18 */ + AVGVCELL_REG = 0x19, /**< 0x19 */ + MAXMINVOLT_REG = 0x1B, /**< 0x1B */ + CONFIG_REG = 0x1D, /**< 0x1D */ + ICHGTERM_REG = 0x1E, /**< 0x1E */ - MAX17055_FULLCAPREP_REG = 0x10, /**< 0x10 */ - MAX17055_TTE_REG = 0X11, /**< 0x11 */ - MAX17055_QRTABLE00_REG = 0x12, /**< 0x12 */ - MAX17055_FULLSOCTHR_REG = 0x13, /**< 0x13 */ - MAX17055_CYCLES_REG = 0x17, - MAX17055_DESIGNCAP_REG = 0x18, - MAX17055_AVGVCELL_REG = 0x19, - MAX17055_MAXMINVOLT_REG = 0x1B, - MAX17055_CONFIG_REG = 0x1D, - MAX17055_ICHGTERM_REG = 0x1E, + VERSION_REG = 0x21, /**< 0x21 */ + QRTABLE10_REG = 0x22, + FULLCAPNOM_REG = 0x23, + LEARNCFG_REG = 0x28, + RELAXCFG_REG = 0x2A, + TGAIN_REG = 0x2C, + TOFF_REG = 0x2D, + + QRTABLE20_REG = 0x32, + RCOMP0_REG = 0x38, + TEMPCO_REG = 0x39, + VEMPTY_REG = 0x3A, + FSTAT_REG = 0x3D, - MAX17055_VERSION_REG = 0x21, - MAX17055_QRTABLE10_REG = 0x22, - MAX17055_FULLCAPNOM_REG = 0x23, - MAX17055_LEARNCFG_REG = 0x28, - MAX17055_RELAXCFG_REG = 0x2A, - MAX17055_TGAIN_REG = 0x2C, - MAX17055_TOFF_REG = 0x2D, + QRTABLE30_REG = 0x42, + DQACC_REG = 0x45, + DPACC_REG = 0x46, + VFSOC0_REG = 0x48, + QH0_REG = 0x4C, + QH_REG = 0x4D, + + VFSOC0_QH0_LOCK_REG = 0x60, + LOCK1_REG = 0x62, + LOCK2_REG = 0x63, + + MODELDATA_START_REG = 0x80, + + IALRTTH_REG = 0xB4, + CURVE_REG = 0xB9, + HIBCFG_REG = 0xBA, + CONFIG2_REG = 0xBB, + + MODELCFG_REG = 0xDB, - MAX17055_QRTABLE20_REG = 0x32, - MAX17055_RCOMP0_REG = 0x38, - MAX17055_TEMPCO_REG = 0x39, - MAX17055_VEMPTY_REG = 0x3A, - MAX17055_FSTAT_REG = 0x3D, + OCV_REG = 0xFB, + VFSOC_REG = 0xFF, + } ; + + + /** + * @brief Saved Fuel Gauge Parameters + * @details Struct with saved fuel Gauge Parametrs + */ + + struct platform_data{ //to clarify if Part of the class + uint16_t designcap;/**< struct value 1 */ + uint16_t ichgterm; /**< struct value 2 */ + uint16_t vempty; /**< struct value 3 */ + int vcharge; /**< struct value 1 */ - MAX17055_QRTABLE30_REG = 0x42, - MAX17055_DQACC_REG = 0x45, - MAX17055_DPACC_REG = 0x46, - MAX17055_VFSOC0_REG = 0x48, - MAX17055_QH0_REG = 0x4C, - MAX17055_QH_REG = 0x4D, + uint16_t learncfg; /**< struct value 1 */ + uint16_t relaxcfg; /**< struct value 1 */ + uint16_t config; /**< struct value 1 */ + uint16_t config2; /**< struct value 1 */ + uint16_t fullsocthr;/**< struct value 1 */ + uint16_t tgain; /**< struct value 1 */ + uint16_t toff; /**< struct value 1 */ + uint16_t curve; /**< struct value 1 */ + uint16_t rcomp0; /**< struct value 1 */ + uint16_t tempco; /**< struct value 1 */ + uint16_t qrtable00; + uint16_t qrtable10; + uint16_t qrtable20; + uint16_t qrtable30; + + uint16_t dpacc; + uint16_t modelcfg; - MAX17055_VFSOC0_QH0_LOCK_REG = 0x60, - MAX17055_LOCK1_REG = 0x62, - MAX17055_LOCK2_REG = 0x63, - - MAX17055_MODELDATA_START_REG = 0x80, + //uint16_t model_data[MAX17055_TABLE_SIZE]; + int (*get_charging_status)(void); + int model_option; + /** + * rsense in miliOhms. + * default 10 (if rsense = 0) as it is the recommended value by + * the datasheet although it can be changed by board designers. + */ + unsigned int rsense; + int volt_min; /**< in mV */ + int volt_max; /**< in mV */ + int temp_min; /**< in DegreC */ + int temp_max; /**< in DegreeC */ + int soc_max; /**< in percent */ + int soc_min; /**< in percent */ + int curr_max; /**< in mA */ + int curr_min; /**< in mA */ + } ; + + + /** + * @brief Saved Fuel Gauge Parameters + * @details It is recommended to save the learned capacity parameters + * every time bit 2 of the Cycles register toggles + * (so that it is saved every 64% change in the battery) + * so that if power is lost the values can easily be restored. + */ - MAX17055_IALRTTH_REG = 0xB4, - MAX17055_CURVE_REG = 0xB9, - MAX17055_HIBCFG_REG = 0xBA, - MAX17055_CONFIG2_REG = 0xBB, - - MAX17055_MODELCFG_REG = 0xDB, - - MAX17055_OCV_REG = 0xFB, - MAX17055_VFSOC_REG = 0xFF, - } ; - + struct saved_FG_params_t{ + int rcomp0; /**< Explain */ + int temp_co; /**< Explain */ + int full_cap_rep; /**< Explain */ + int cycles; /**< Explain */ + int full_cap_nom; /**< Explain */ + } ; @@ -315,7 +321,7 @@ * -1 on Failure */ - int max17055_poll_flag_clear(Registers_e reg_addr, int mask, int timeout); + int poll_flag_clear(Registers_e reg_addr, int mask, int timeout); /** @@ -350,7 +356,7 @@ */ - int init(max17055_platform_data des_data); + int init(platform_data des_data); //////////////////////////////////////////////////////////////////////////// @@ -361,14 +367,13 @@ * This function sends a request to access the internal * of the MAX17055 * - * \param[out] *temp - pointer? or Reference? to the volue of the temperature - * \retval 1 on success - * 0 on success + * + * \retval temperature value * -1 if errors exist */ - int get_temperature(int *temp); + int get_temperature(); //////////////////////////////////////////////////////////////////////////// @@ -384,6 +389,132 @@ uint16_t forcedExitHyberMode(); + + /** + * \brief EZ COnfing Init function + * \par Details + * This function implements the steps for the EZ confing m5 FuelGauge + * + * \retval returns TBD + * + */ + + + uint16_t EZconfig_init(platform_data des_data); + + /////////////////////////////////////////////////////////////////////////// + + /** + * \brief Get State Of Charge(SOC) Function for MAX17055 + * \par Details + * This function sends a request to access the internal + * of the MAX17055 + * + * \param[in] reg_addr - register address + * \param[out] reg_data - SOC data from the REPSOC_REG register + * \retval 1 on success + * + * -1 if errors exist + */ + + + int get_SOC(); + + //////////////////////////////////////////////////////////////////////////// + + /** + * \brief Get the remaining Time to Empty(TTE) Function for MAX17055 + * \par Details + * This function sends a request to access the internal register + * of the MAX17055 + * + * \retval tte_data - Time to Empty data from the TTE_REG register + * + * -1 if errors exist + */ + + + int get_TTE(); + + + //////////////////////////////////////////////////////////////////////////// + + /** + * \brief Get voltage of the cell Function for MAX17055 + * \par Details + * This function sends a request to access the internal register + * of the MAX17055 to read the voltage of the cell + * + * \retval vcell_data - vcell data from the VCELL_REG register + * + * -1 if errors exist + */ + + + int get_Vcell(); + + //////////////////////////////////////////////////////////////////////////// + + /** + * \brief Get current Function for MAX17055 + * \par Details + * This function sends a request to access the internal register + * of the MAX17055 to read the current register. + * + * \retval curr_data - vcell data from the VCELL_REG register + * + * -1 if errors exist + */ + + + int get_Current(platform_data des_data); + + //////////////////////////////////////////////////////////////////////////// + + /** + * \brief Get Average Current Function for MAX17055 + * \par Details + * This function sends a request to access the internal register + * of the MAX17055 to read the average current register. + * + * \retval curr_data - vcell data from the AVGCURRENT_REG register + * + * -1 if errors exist + */ + + + int get_AvgCurrent(platform_data des_data); + + //////////////////////////////////////////////////////////////////////////// + + /** + * \brief lsb_to_uvolts Converssion Function + * \par Details + * This function takes the lsb value of the register and convert it + * to uvolts + * + * \param[in] lsb - value of register lsb + * \retval lsb - converted lsb to uvolts + * + */ + + int lsb_to_uvolts(uint16_t lsb); + + + /////////////////////////////////////////////////////////////////////////////// + + /** + * \brief raw_current_to_uamp Converssion Function + * \par Details + * This function takes the raw current value of the register and + * converts it to uamps + * + * \param[in] curr - raw current value of register + * \retval res - converted raw current to uamps - Signed 2's complement + * + */ + + int raw_current_to_uamps(uint32_t curr, int rsense_value);