add BQ27220

This commit is contained in:
mverch67 2025-07-02 09:16:45 +02:00
parent 11f5a7ea71
commit 912f496ce8
4 changed files with 28 additions and 5 deletions

View File

@ -55,7 +55,7 @@ lib_deps =
# renovate: datasource=git-refs depName=libpax packageName=https://github.com/dbinfrago/libpax gitBranch=master
https://github.com/dbinfrago/libpax/archive/3cdc0371c375676a97967547f4065607d4c53fd1.zip
# renovate: datasource=custom.pio depName=XPowersLib packageName=lewisxhe/library/XPowersLib
lewisxhe/XPowersLib@^0.2.7
lewisxhe/XPowersLib@^0.2.9
# renovate: datasource=git-refs depName=meshtastic-ESP32_Codec2 packageName=https://github.com/meshtastic/ESP32_Codec2 gitBranch=master
https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip
# renovate: datasource=custom.pio depName=rweather/Crypto packageName=rweather/library/Crypto

View File

@ -125,6 +125,10 @@ RAK9154Sensor rak9154Sensor;
#include <XPowersLib.h>
#endif
#ifdef HAS_BQ27220
#include "BQ27220.h"
#endif
#ifdef HAS_PMU
XPowersLibInterface *PMU = NULL;
#else
@ -1249,12 +1253,13 @@ bool Power::lipoInit()
#if defined(HAS_PPM) && HAS_PPM
/**
* Adapter class for BQ25896 Lipo battery charger.
* Adapter class for BQ25896/BQ27220 Lipo battery charger.
*/
class LipoCharger : public HasBatteryLevel
{
private:
XPowersPPM *ppm = nullptr;
BQ27220 *bq = nullptr;
public:
/**
@ -1293,11 +1298,23 @@ class LipoCharger : public HasBatteryLevel
// Turn on charging function
// If there is no battery connected, do not turn on the charging function
ppm->enableCharge();
return true;
} else {
LOG_WARN("PPM BQ25896 init failed");
delete ppm;
ppm = nullptr;
return false;
}
}
if (bq == nullptr) {
bq = new BQ27220;
bool result = bq->init(&Wire, BQ27220_I2C_SDA, BQ27220_I2C_SCL);
if (result) {
return true;
} else {
LOG_WARN("BQ27220 init failed");
delete bq;
bq = nullptr;
return false;
}
}
return false;
@ -1306,12 +1323,12 @@ class LipoCharger : public HasBatteryLevel
/**
* Battery state of charge, from 0 to 100 or -1 for unknown
*/
virtual int getBatteryPercent() override { return -1; }
virtual int getBatteryPercent() override { return bq->getChargePcnt(); }
/**
* The raw voltage of the battery in millivolts, or NAN if unknown
*/
virtual uint16_t getBattVoltage() override { return ppm->getBattVoltage(); }
virtual uint16_t getBattVoltage() override { return bq->getVolt(BQ27220::VOLT); }
/**
* return true if there is a battery installed in this unit

View File

@ -21,3 +21,4 @@ lib_deps =
https://github.com/ZinggJM/GxEPD2/archive/refs/tags/1.6.4.zip
https://github.com/CIRCUITSTATE/CSE_Touch/archive/b44f23b6f870b848f1fbe453c190879bc6cfaafa.zip
https://github.com/CIRCUITSTATE/CSE_CST328/archive/refs/tags/v0.0.4.zip
https://github.com/mverch67/BQ27220/archive/9249016527c19bea5ab38351c7d0f1ffe4c19dd9.zip

View File

@ -61,6 +61,11 @@
#define HAS_PPM 1
#define XPOWERS_CHIP_BQ25896
// battery quality management BQ27220
#define HAS_BQ27220 1
#define BQ27220_I2C_SDA SDA
#define BQ27220_I2C_SCL SCL
// LoRa
#define USE_SX1262
#define USE_SX1268