Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from MrFlexi/CoulombRegister
Browse files Browse the repository at this point in the history
New Coulomb functions to start/stop/clear coulomb counter via registe…
  • Loading branch information
lewisxhe authored Mar 6, 2020
2 parents bc58d06 + e2255f0 commit ffd77dd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
73 changes: 72 additions & 1 deletion src/axp20x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ uint32_t AXP20X_Class::getBattChargeCoulomb()
uint8_t buffer[4];
if (!_init)
return AXP_NOT_INIT;
_readByte(0xB1, 4, buffer);
_readByte(0xB0, 4, buffer);
return (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
}

Expand All @@ -387,6 +387,77 @@ float AXP20X_Class::getCoulombData()
return result;
}


//-------------------------------------------------------
// New Coulomb functions by MrFlexi
//-------------------------------------------------------

uint8_t AXP20X_Class::getCoulombRegister()
{
uint8_t buffer[1];
if (!_init)
return AXP_NOT_INIT;
_readByte(AXP202_COULOMB_CTL, 1, buffer);
return buffer[1];
}


int AXP20X_Class::setCoulombRegister(uint8_t val)
{
if (!_init)
return AXP_NOT_INIT;
_writeByte(AXP202_COULOMB_CTL, 1, &val);
return AXP_PASS;
}


int AXP20X_Class::EnableCoulombcounter(void)
{

if (!_init)
return AXP_NOT_INIT;
uint8_t val = 0x80;
_writeByte(AXP202_COULOMB_CTL, 1, &val);
return AXP_PASS;
}

int AXP20X_Class::DisableCoulombcounter(void)
{

if (!_init)
return AXP_NOT_INIT;
uint8_t val = 0x00;
_writeByte(AXP202_COULOMB_CTL, 1, &val);
return AXP_PASS;
}

int AXP20X_Class::StopCoulombcounter(void)
{

if (!_init)
return AXP_NOT_INIT;
uint8_t val = 0xB8;
_writeByte(AXP202_COULOMB_CTL, 1, &val);
return AXP_PASS;
}


int AXP20X_Class::ClearCoulombcounter(void)
{

if (!_init)
return AXP_NOT_INIT;
uint8_t val = 0xA0;
_writeByte(AXP202_COULOMB_CTL, 1, &val);
return AXP_PASS;
}

//-------------------------------------------------------
// END
//-------------------------------------------------------



uint8_t AXP20X_Class::getAdcSamplingRate()
{
//axp192 same axp202 aregister address 0x84
Expand Down
6 changes: 6 additions & 0 deletions src/axp20x.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ class AXP20X_Class
int setAdcSamplingRate(axp_adc_sampling_rate_t rate);
uint8_t getAdcSamplingRate();
float getCoulombData();
uint8_t getCoulombRegister();
int setCoulombRegister(uint8_t val);
int EnableCoulombcounter(void);
int DisableCoulombcounter(void);
int StopCoulombcounter(void);
int ClearCoulombcounter(void);


int setGPIOMode(axp_gpio_t gpio, axp_gpio_mode_t mode);
Expand Down

0 comments on commit ffd77dd

Please sign in to comment.