Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot
Fork of max17055 by
Revision 7:479a36909ced, committed 2017-10-10
- Comitter:
- fneirab
- Date:
- Tue Oct 10 00:06:40 2017 +0000
- Parent:
- 6:5ced10109ebf
- Child:
- 8:ca8765c30ed2
- Commit message:
- add functions and debugged for complete EZ config function to be completed.
Changed in this revision
| max17055.cpp | Show annotated file Show diff for this revision Revisions of this file |
| max17055.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/max17055.cpp Thu Oct 05 02:37:59 2017 +0000
+++ b/max17055.cpp Tue Oct 10 00:06:40 2017 +0000
@@ -112,16 +112,16 @@
int MAX17055::writeReg(Registers_e reg_addr, uint16_t reg_data)
{
-
+ uint16_t mask = 0x00FF;
uint8_t dataLSB;
uint8_t dataMSB;
- dataLSB = reg_data & 0x00FF;
- dataMSB = (reg_data >> 8) & 0x00FF;
+ dataLSB = reg_data & mask;
+ dataMSB = (reg_data >> 8) & mask;
- char add_plus_data[3] = {reg_addr, dataLSB, dataMSB};
+ char addr_plus_data[3] = {reg_addr, dataLSB, dataMSB};
- if ( m_i2cBus.write(I2C_W_ADRS, add_plus_data, 3, false) == 0)
+ if ( m_i2cBus.write(I2C_W_ADRS, addr_plus_data, 3, false) == 0)
return 1;
else
return 0;
@@ -143,8 +143,7 @@
int32_t MAX17055::readReg(Registers_e reg_addr, uint16_t &value)
{
int32_t result;
- //int16_t value2;
- //int16_t twoBytes;
+ uint16_t mask = 0x00FF;
char local_data[1];
local_data[0] = reg_addr;
char read_data[2];
@@ -153,7 +152,7 @@
if(result == 0) {
result = m_i2cBus.read(I2C_R_ADRS, read_data , 2, false);
if (result == 0) {
- value = ( ((read_data[1] & 0x00FF) << 8) + (read_data[0]));
+ value = ( ((read_data[1] & mask) << 8) + (read_data[0]));
result = 1;
}
}
@@ -200,7 +199,7 @@
if (ret<0)
return ret;
- else
+ else
return 1;
}
@@ -217,21 +216,21 @@
*/
-int MAX17055::init(max17055_platform_data des_data)
+int MAX17055::init(platform_data des_data)
{
int status, ret;
- uint16_t read_data, hibcfg_value, dpacc, reg;
+ uint16_t read_data, hibcfg_value, reg;
- status = readReg(MAX17055_VERSION_REG, read_data);
+ status = readReg(VERSION_REG, read_data);
if (status == 0)
return status; //Device is not present in the i2c Bus
/* Step 0: Check for POR */
/* Skip load model if POR bit is cleared */
- readReg(MAX17055_STATUS_REG, read_data);
+ readReg(STATUS_REG, read_data);
if (!(read_data & MAX17055_STATUS_POR ) )
return -1; //POR is not set. Skip Initialization.
@@ -239,57 +238,46 @@
/* Step 1: Check if FStat.DNR == 0 */
// Do not continue until FSTAT.DNR == 0
printf("step 0 check \r\n");
-
+
int time_out = 500;
- ret = max17055_poll_flag_clear (MAX17055_FSTAT_REG, MAX17055_FSTAT_DNR, time_out);
- if (ret < 0){
+ ret = poll_flag_clear(FSTAT_REG, MAX17055_FSTAT_DNR, time_out);
+ if (ret < 0) {
printf("Unsuccessful init: Data Not Ready!\n");
return ret;
}
/* Force exit from hibernate */
hibcfg_value = forcedExitHyberMode();
-
+
printf("step 1 check \r\n");
/* Step 2: Initialize configuration */
switch (1) {
case MODEL_LOADING_OPTION1:
/* Step 2.1: Option 1 EZ Config */
- writeReg(MAX17055_DESIGNCAP_REG, des_data.designcap);
- writeReg(MAX17055_DQACC_REG, des_data.designcap >> 5);
- writeReg(MAX17055_ICHGTERM_REG, des_data.ichgterm);
- writeReg(MAX17055_VEMPTY_REG, des_data.vempty);
-
- if (design_data.vcharge > 4275) { //Need to know what this 4275 is
- dpacc = (des_data.designcap >> 5) * 0xC800 / des_data.designcap;
- writeReg(MAX17055_DPACC_REG, dpacc);
- writeReg(MAX17055_MODELCFG_REG, 0x8400); //Why 0x8400
- } else {
- dpacc = (des_data.designcap >> 5) * 0xAC6A / des_data.designcap;
- writeReg(MAX17055_DPACC_REG, dpacc);
- writeReg(MAX17055_MODELCFG_REG, 0x8000);
- }
+ EZconfig_init(des_data);
/* Poll ModelCFG.ModelRefresh bit for clear */
- ret = max17055_poll_flag_clear(MAX17055_MODELCFG_REG, MAX17055_MODELCFG_REFRESH, 500);
+ int time_out = 500; //msec
+ ret = poll_flag_clear(MODELCFG_REG, MAX17055_MODELCFG_REFRESH, time_out);
if(ret < 0) {
//dev_err(priv->dev, "Option1 model refresh not completed!\n");
return ret;
}
+
break;
}
/* Restore original HibCfg */
- writeReg(MAX17055_HIBCFG_REG, hibcfg_value);
+ writeReg(HIBCFG_REG, hibcfg_value);
printf("Last section check \r\n");
/* Optional step - alert threshold initialization */
- //max17055_set_alert_thresholds(priv);
+ //set_alert_thresholds(priv);
/* Clear Status.POR */
- readReg(MAX17055_STATUS_REG, reg);
- write_and_verify_reg(MAX17055_STATUS_REG, (reg & ~MAX17055_STATUS_POR));
+ readReg(STATUS_REG, reg);
+ write_and_verify_reg(STATUS_REG, (reg & ~MAX17055_STATUS_POR));
return 1;
}
@@ -310,13 +298,13 @@
* -1 on Failure
*/
-int MAX17055::max17055_poll_flag_clear (Registers_e reg_addr, int mask, int timeout)
+int MAX17055::poll_flag_clear (Registers_e reg_addr, int mask, int timeout)
{
uint16_t data;
int ret;
do {
- wait(50);
+ wait_ms(10);
ret = readReg(reg_addr, data);
if(ret < 0)
return ret;
@@ -324,7 +312,7 @@
if(!(data & mask))
return 1;
- timeout -= 50;
+ timeout -= 10;
} while(timeout > 0);
return -1;
@@ -340,35 +328,31 @@
* This function sends a request to access the internal
* of the MAX17055
*
-* \param[in] reg_addr - register address
-* \param[out] reg_data - the variable that contains the data to write
-* to the register address
-* \retval 1 on success
*
+* \retval temperature value
* -1 if errors exist
*/
-int MAX17055::get_temperature(int *temp)
+int MAX17055::get_temperature()
{
int ret;
uint16_t data;
- ret = readReg(MAX17055_TEMP_REG, data);
+ ret = readReg(TEMP_REG, data);
if (ret < 0)
return ret;
- *temp = data;
/* The value is signed. */
- if (*temp & 0x8000)
- *temp |= 0xFFFF0000;
+ if (data & 0x8000)
+ data |= 0xFFFF0000;
/* The value is converted into centigrade scale */
/* Units of LSB = 1 / 256 degree Celsius */
- *temp >>= 8;
+ data >>= 8;
- return 1;
+ return data ;
}
@@ -389,18 +373,265 @@
uint16_t hibcfg;
/* Force exit from hibernate */
-
//STEP 0: Store original HibCFG value
- readReg(MAX17055_HIBCFG_REG, hibcfg);
+ readReg(HIBCFG_REG, hibcfg);
//STEP 1: Write to Soft-Wakeup Commannd Register
- writeReg(MAX17055_VFSOC0_QH0_LOCK_REG, 0x90); //Soft-Wakeup from hybernate
+ writeReg(VFSOC0_QH0_LOCK_REG, 0x90); //Soft-Wakeup from hybernate
//STEP 2: Write to Hibernate Configuration register
- writeReg(MAX17055_HIBCFG_REG, 0x0); //disable hibernate mode
+ writeReg(HIBCFG_REG, 0x0); //disable hibernate mode
//STEP 3:Write to Soft-Wakeup Commannd Register
- writeReg(MAX17055_VFSOC0_QH0_LOCK_REG, 0x0); //Clear All commnads
+ writeReg(VFSOC0_QH0_LOCK_REG, 0x0); //Clear All commnads
return hibcfg;
}
+
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+* \brief EZ COnfing Init function
+* \par Details
+* This function implements the steps for the EZ confing m5 FuelGauge
+*
+* \retval returns TBD
+*
+*/
+
+
+uint16_t MAX17055::EZconfig_init(platform_data des_data)
+{
+ const int charger_th = 4275;
+ const int chg_V_high = 51200;
+ const int chg_V_low = 44138;
+ const int param_EZ_FG1 = 0x8400;
+ const int param_EZ_FG2 = 0x8000;
+ int ret;
+ uint16_t dpacc;
+
+
+ /* Step 2.1: Option 1 EZ Config */
+ writeReg(DESIGNCAP_REG, des_data.designcap);
+ writeReg(DQACC_REG, des_data.designcap >> 5);
+ writeReg(ICHGTERM_REG, des_data.ichgterm);
+ writeReg(VEMPTY_REG, des_data.vempty);
+
+ if (des_data.vcharge > charger_th) {
+ dpacc = (des_data.designcap >> 5) * chg_V_high / des_data.designcap;
+ writeReg(DPACC_REG, dpacc);
+ writeReg(MODELCFG_REG, param_EZ_FG1); //Why 0x8400
+ } else {
+ dpacc = (des_data.designcap >> 5) * chg_V_low / des_data.designcap;
+ writeReg(DPACC_REG, dpacc);
+ writeReg(MODELCFG_REG, param_EZ_FG2);
+ }
+
+
+ return ret;
+
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+* \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 MAX17055::get_SOC()
+{
+
+ int ret;
+ uint16_t data;
+
+ ret = readReg(REPSOC_REG, data);
+ if (ret < 0)
+ return ret;
+
+ data = data >> 8; /* RepSOC LSB: 1/256 % */
+
+ return data;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+* \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 MAX17055::get_TTE()
+{
+
+ int ret;
+ uint16_t data;
+
+ ret = readReg(TTE_REG, data);
+ if (ret < 0)
+ return ret;
+ else
+ data = (data * 45) >> 3; /* TTE LSB: 5.625 sec */
+
+ return data;
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+
+/**
+* \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 MAX17055::get_Vcell()
+{
+
+ int ret;
+ uint16_t vcell_data;
+
+ ret = readReg(VCELL_REG, vcell_data);
+ if (ret < 0)
+ return ret;
+ else
+ //printf("Vcell Reg= %d \r\n",vcell_data);
+ ret = lsb_to_uvolts(vcell_data);
+ //printf("Vcell Conv= %d \r\n",ret);
+ return ret;
+
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+
+/**
+* \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 MAX17055::get_Current( platform_data des_data )
+{
+
+ int ret,design_rsense;
+ uint16_t data;
+
+ ret = readReg(CURRENT_REG, data);
+ if (ret < 0)
+ return ret;
+ else
+ design_rsense = des_data.rsense;
+ ret = raw_current_to_uamps((uint32_t)data, design_rsense);
+ return ret;
+
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+
+/**
+* \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 MAX17055::get_AvgCurrent( platform_data des_data )
+{
+
+ int ret, design_rsense;
+ uint16_t data;
+ uint32_t aveCurr_data;
+
+ ret = readReg(AVGCURRENT_REG, data);
+ if (ret < 0)
+ return ret;
+ else
+ aveCurr_data = data;
+ design_rsense = des_data.rsense;
+ aveCurr_data = raw_current_to_uamps(aveCurr_data, design_rsense);
+ return aveCurr_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 MAX17055:: lsb_to_uvolts(uint16_t lsb)
+{
+ int store;
+ store = (lsb * 625) / 8; /* 78.125uV per bit */
+ return store;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+* \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 MAX17055::raw_current_to_uamps(uint32_t curr, int rsense_value)
+{
+ int res = curr;
+ /* Negative */
+ if (res & 0x8000) {
+ res |= 0xFFFF0000;
+ } else {
+ res *= 1562500 /(rsense_value * 1000); //Change to interact with the rsense of customer
+ }
+ return res;
+}
\ No newline at end of file
--- 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);
