Skip to content

Commit

Permalink
Adjust default charge currents at different temperatures
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfeatherdev committed Apr 13, 2024
1 parent e9ea97f commit 637fac1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/Mainboard/BQ2562x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,37 @@ namespace PowerFeather
return _writeReg(Charger_Control_3_IBAT_PK, value);
}

bool BQ2562x::setTH456(TH456Setting setting)
{
return _writeReg(NTC_Control_1_TS_TH4_TH5_TH6, static_cast<uint8_t>(setting));
}

bool BQ2562x::setTempIset(TempPoint point, TempIset iset)
{
Register reg;

switch (point)
{
case TempPoint::Prewarm:
reg = NTC_Control_2_TS_ISET_PREWARM;
break;
case TempPoint::Precool:
reg = NTC_Control_2_TS_ISET_PRECOOL;
break;
case TempPoint::Warm:
reg = NTC_Control_0_TS_ISET_WARM;
break;
case TempPoint::Cool:
reg = NTC_Control_0_TS_ISET_COOL;
break;
default:
return false;
break;
}

return _writeReg(reg, static_cast<uint8_t>(iset));
}

bool BQ2562x::setupADC(bool enable, ADCRate rate, ADCSampling sampling, ADCAverage average, ADCAverageInit averageInit)
{
uint8_t value = enable << ADC_Control_ADC_EN.start;
Expand Down
35 changes: 34 additions & 1 deletion src/Mainboard/BQ2562x.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ namespace PowerFeather
Limit12A = 0x03
};

enum class TH456Setting : uint8_t
{
TH4_35_TH5_40_TH6_50 = 0x04,
};

enum class TempPoint : uint8_t
{
Cold,
Cool,
Precool,
Normal,
Prewarm,
Warm,
Hot
};

enum class TempIset : uint8_t
{
Suspend = 0x00,
Ichg20 = 0x01,
Ichg40 = 0x02,
NoChange = 0x03
};

BQ2562x(MasterI2C &i2c) : _i2c(i2c) {}

bool getWD(bool &enabled);
Expand Down Expand Up @@ -189,6 +213,8 @@ namespace PowerFeather
bool setITERM(uint16_t current);
bool setTopOff(TopOffTimer timer);
bool setIbatPk(IbatPkLimit limit);
bool setTH456(TH456Setting setting);
bool setTempIset(TempPoint point, TempIset iset);
bool setupADC(bool enable, ADCRate rate = ADCRate::Continuous, ADCSampling sampling = ADCSampling::Bits_9,
ADCAverage average = ADCAverage::Single, ADCAverageInit averageInit = ADCAverageInit::Existing);

Expand All @@ -213,8 +239,15 @@ namespace PowerFeather

const Register Charger_Control_3_IBAT_PK = { 0x19, 1, 6, 7 };

const Register NTC_Control_0_ = { 0x1a, 1, 0, 7 };
const Register NTC_Control_0 = { 0x1a, 1, 0, 7 };
const Register NTC_Control_0_TS_IGNORE = { 0x1a, 1, 7, 7 };
const Register NTC_Control_0_TS_ISET_WARM = { 0x1a, 1, 2, 3 };
const Register NTC_Control_0_TS_ISET_COOL = { 0x1a, 1, 0, 1 };

const Register NTC_Control_1_TS_TH4_TH5_TH6 = { 0x1b, 1, 2, 4 };

const Register NTC_Control_2_TS_ISET_PREWARM = { 0x1c, 1, 2, 3 };
const Register NTC_Control_2_TS_ISET_PRECOOL = { 0x1c, 1, 0, 1 };

const Register Charger_Status_0 = { 0x1d, 1, 0, 7 };
const Register Charger_Status_0_ADC_DONE = { 0x1d, 1, 6, 6 };
Expand Down
5 changes: 5 additions & 0 deletions src/Mainboard/Mainboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ namespace PowerFeather
RET_IF_FALSE(getCharger().enableWVBUS(true), Result::Failure);
RET_IF_FALSE(getCharger().setTopOff(BQ2562x::TopOffTimer::Timer17Min), Result::Failure);
RET_IF_FALSE(getCharger().setIbatPk(BQ2562x::IbatPkLimit::Limit3A), Result::Failure);
RET_IF_FALSE(getCharger().setTH456(BQ2562x::TH456Setting::TH4_35_TH5_40_TH6_50), Result::Failure);
RET_IF_FALSE(getCharger().setTempIset(BQ2562x::TempPoint::Precool, BQ2562x::TempIset::Ichg40), Result::Failure);
RET_IF_FALSE(getCharger().setTempIset(BQ2562x::TempPoint::Prewarm, BQ2562x::TempIset::Ichg40), Result::Failure);
RET_IF_FALSE(getCharger().setTempIset(BQ2562x::TempPoint::Cool, BQ2562x::TempIset::Ichg20), Result::Failure);
RET_IF_FALSE(getCharger().setTempIset(BQ2562x::TempPoint::Warm, BQ2562x::TempIset::Ichg20), Result::Failure);
RET_IF_FALSE(getCharger().enableInterrupts(false), Result::Failure);
if (_batteryCapacity)
{
Expand Down

0 comments on commit 637fac1

Please sign in to comment.