forked from xiaozhi/xiaozhi-esp32
1.4.3: Low power popup & replace OledDisplay with Ssd1306Display
This commit is contained in:
37
main/boards/common/axp2101.cc
Normal file
37
main/boards/common/axp2101.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "axp2101.h"
|
||||
#include "board.h"
|
||||
#include "display.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#define TAG "Axp2101"
|
||||
|
||||
Axp2101::Axp2101(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
|
||||
}
|
||||
|
||||
int Axp2101::GetBatteryCurrentDirection() {
|
||||
return (ReadReg(0x01) & 0b01100000) >> 5;
|
||||
}
|
||||
|
||||
bool Axp2101::IsCharging() {
|
||||
return GetBatteryCurrentDirection() == 1;
|
||||
}
|
||||
|
||||
bool Axp2101::IsDischarging() {
|
||||
return GetBatteryCurrentDirection() == 2;
|
||||
}
|
||||
|
||||
bool Axp2101::IsChargingDone() {
|
||||
uint8_t value = ReadReg(0x01);
|
||||
return (value & 0b00000111) == 0b00000100;
|
||||
}
|
||||
|
||||
int Axp2101::GetBatteryLevel() {
|
||||
return ReadReg(0xA4);
|
||||
}
|
||||
|
||||
void Axp2101::PowerOff() {
|
||||
uint8_t value = ReadReg(0x10);
|
||||
value = value | 0x01;
|
||||
WriteReg(0x10, value);
|
||||
}
|
||||
Reference in New Issue
Block a user