Ken Van Hoeylandt 3ea02d912f
Merge develop into main (#167)
- WiFi Connect app is now hidden by default, but accessible at the bottom of the WiFi Manage app when WiFi is turned on.
- WiFi service now turns on WiFi when calling connect() and WiFi is not on.
- Removed `blocking` option for `service::loader::startApp()`. This feature was unused and complex.
- Various apps: Moved private headers into Private/ folder.
- Various apps: created start() function for easy starting.
- Added documentation to all TactilityC APIs
- Refactored various `enum` into `class enum`
- Refactor M5Stack `initBoot()` (but VBus is still 0V for some reason)
2025-01-17 19:37:42 +01:00

60 lines
1.5 KiB
C++

#include "Axp2101.h"
#include "Log.h"
bool Axp2101::getBatteryVoltage(float& vbatMillis) const {
return readRegister14(0x34, vbatMillis);
}
bool Axp2101::getChargeStatus(ChargeStatus& status) const {
uint8_t value;
if (readRegister8(0x01, value)) {
value = (value >> 5) & 0b11;
status = (value == 1) ? CHARGE_STATUS_CHARGING : ((value == 2) ? CHARGE_STATUS_DISCHARGING : CHARGE_STATUS_STANDBY);
return true;
} else {
return false;
}
}
bool Axp2101::isChargingEnabled(bool& enabled) const {
uint8_t value;
if (readRegister8(0x18, value)) {
enabled = value & 0b10;
return true;
} else {
return false;
}
}
bool Axp2101::setChargingEnabled(bool enabled) const {
uint8_t value;
if (readRegister8(0x18, value)) {
return writeRegister8(0x18, (value & 0xFD) | (enabled << 1));
} else {
return false;
}
}
bool Axp2101::isVBus() const {
uint8_t value;
return readRegister8(0x00, value) && (value & 0x20);
}
bool Axp2101::getVBusVoltage(float& out) const {
if (!isVBus()) {
return false;
} else {
float vbus;
if (readRegister14(0x38, vbus) && vbus < 16375) {
out = vbus / 1000.0f;
return true;
} else {
return false;
}
}
}
bool Axp2101::setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const {
return tt::hal::i2c::masterWriteRegisterArray(port, address, bytePairs, bytePairsSize, DEFAULT_TIMEOUT);
}