Various fixes and improvements (#182)
- Fix for `logMutex` bug where the `Mutex` constructor is not called when doing early boot logging (with `DEBUG` level logging) . The only way to make it work is to explicitly call the constructor in the logging wrapper function. - Fix for unPhone power states
This commit is contained in:
committed by
GitHub
parent
9fb8d45b2e
commit
bb7e79886f
@@ -8,24 +8,55 @@
|
||||
* https://gitlab.com/hamishcunningham/unphonelibrary/-/blob/main/unPhone.h?ref_type=heads
|
||||
*/
|
||||
namespace registers {
|
||||
static const uint8_t WATCHDOG = 0x05U; // Datasheet page 35: Charge end/timer cntrl
|
||||
static const uint8_t CHARGE_TERMINATION = 0x05U; // Datasheet page 35: Charge end/timer cntrl
|
||||
static const uint8_t OPERATION_CONTROL = 0x07U; // Datasheet page 37: Misc operation control
|
||||
static const uint8_t STATUS = 0x08U; // Datasheet page 38: System status
|
||||
static const uint8_t VERSION = 0x0AU; // Datasheet page 38: Vendor/part/revision status
|
||||
} // namespace registers
|
||||
|
||||
bool Bq24295::readChargeTermination(uint8_t& out) const {
|
||||
return readRegister8(registers::CHARGE_TERMINATION, out);
|
||||
}
|
||||
|
||||
// region Watchdog
|
||||
bool Bq24295::getWatchDog(uint8_t value) const {
|
||||
return readRegister8(registers::WATCHDOG, value);
|
||||
bool Bq24295::getWatchDogTimer(WatchDogTimer& out) const {
|
||||
uint8_t value;
|
||||
if (readChargeTermination(value)) {
|
||||
uint8_t relevant_bits = value & (BIT(4) | BIT(5));
|
||||
switch (relevant_bits) {
|
||||
case 0b000000:
|
||||
out = WatchDogTimer::Disabled;
|
||||
return true;
|
||||
case 0b010000:
|
||||
out = WatchDogTimer::Enabled40s;
|
||||
return true;
|
||||
case 0b100000:
|
||||
out = WatchDogTimer::Enabled80s;
|
||||
return true;
|
||||
case 0b110000:
|
||||
out = WatchDogTimer::Enabled160s;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Bq24295::setWatchDogBitOn(uint8_t mask) const {
|
||||
return bitOn(registers::WATCHDOG, mask);
|
||||
bool Bq24295::setWatchDogTimer(WatchDogTimer in) const {
|
||||
uint8_t value;
|
||||
if (readChargeTermination(value)) {
|
||||
uint8_t bits_to_set = 0b00110000 & static_cast<uint8_t>(in);
|
||||
uint8_t value_cleared = value & 0b11001111;
|
||||
uint8_t to_set = bits_to_set & value_cleared;
|
||||
TT_LOG_I(TAG, "WatchDogTimer: %02x -> %02x", value, to_set);
|
||||
return writeRegister8(registers::CHARGE_TERMINATION, to_set);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Bq24295::setWatchDogBitOff(uint8_t mask) const {
|
||||
return bitOff(registers::WATCHDOG, mask);
|
||||
}
|
||||
|
||||
// endregoin
|
||||
|
||||
@@ -51,14 +82,23 @@ bool Bq24295::getStatus(uint8_t& value) const {
|
||||
return readRegister8(registers::STATUS, value);
|
||||
}
|
||||
|
||||
bool Bq24295::isUsbPowerConnected() const {
|
||||
uint8_t status;
|
||||
if (getStatus(status)) {
|
||||
return (status & BIT(2)) != 0U;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Bq24295::getVersion(uint8_t& value) const {
|
||||
return readRegister8(registers::VERSION, value);
|
||||
}
|
||||
|
||||
void Bq24295::printInfo() const {
|
||||
uint8_t version, status;
|
||||
if (getStatus(status) && getVersion(version)) {
|
||||
TT_LOG_I(TAG, "Version %d, status %02x", version, status);
|
||||
uint8_t version, status, charge_termination;
|
||||
if (getStatus(status) && getVersion(version) && readChargeTermination(charge_termination)) {
|
||||
TT_LOG_I(TAG, "Version %d, status %02x, charge termination %02x", version, status, charge_termination);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to retrieve version and/or status");
|
||||
}
|
||||
|
||||
@@ -6,13 +6,25 @@
|
||||
|
||||
class Bq24295 : I2cDevice {
|
||||
|
||||
private:
|
||||
|
||||
bool readChargeTermination(uint8_t& out) const;
|
||||
|
||||
public:
|
||||
|
||||
enum class WatchDogTimer {
|
||||
Disabled = 0b000000,
|
||||
Enabled40s = 0b010000,
|
||||
Enabled80s = 0b100000,
|
||||
Enabled160s = 0b110000
|
||||
};
|
||||
|
||||
explicit Bq24295(i2c_port_t port) : I2cDevice(port, BQ24295_ADDRESS) {}
|
||||
|
||||
bool getWatchDog(uint8_t value) const;
|
||||
bool setWatchDogBitOn(uint8_t mask) const;
|
||||
bool setWatchDogBitOff(uint8_t mask) const;
|
||||
bool getWatchDogTimer(WatchDogTimer& out) const;
|
||||
bool setWatchDogTimer(WatchDogTimer in) const;
|
||||
|
||||
bool isUsbPowerConnected() const;
|
||||
|
||||
bool getOperationControl(uint8_t value) const;
|
||||
bool setOperationControlBitOn(uint8_t mask) const;
|
||||
|
||||
Reference in New Issue
Block a user