Ken Van Hoeylandt 737c0f7447
CoreS3 refactored & remove M5 libraries (#143)
Remove dependencies M5Unified and M5GFX because:
- Sometimes the release doesn't even compile
- The amount of functions is too close to the limit (I recently had to remove some code/dependency to be able to make a build at all)
- Graphics performance issue since last update
- Touch screen performance issues (not perfect yet, but better)
- Compatibility issues with Tactility SPI/I2C versus M5Unified/M5GFX variants.
2025-01-02 00:19:24 +01:00

38 lines
1.1 KiB
C++

#pragma once
#include "hal/i2c/I2c.h"
/**
* References:
* - https://github.com/m5stack/M5Unified/blob/master/src/utility/AXP2101_Class.cpp
* - http://file.whycan.com/files/members/6736/AXP2101_Datasheet_V1.0_en_3832.pdf
*/
class Axp2101 {
i2c_port_t port;
static constexpr uint8_t DEFAULT_ADDRESS = 0x34;
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
bool readRegister8(uint8_t reg, uint8_t& result) const;
bool writeRegister8(uint8_t reg, uint8_t value) const;
bool readRegister12(uint8_t reg, float& out) const;
bool readRegister14(uint8_t reg, float& out) const;
bool readRegister16(uint8_t reg, uint16_t& out) const;
public:
enum ChargeStatus {
CHARGE_STATUS_CHARGING = 0b01,
CHARGE_STATUS_DISCHARGING = 0b10,
CHARGE_STATUS_STANDBY = 0b00
};
Axp2101(i2c_port_t port) : port(port) {}
bool getBatteryVoltage(float& vbatMillis) const;
bool getChargeStatus(ChargeStatus& status) const;
bool isChargingEnabled(bool& enabled) const;
bool setChargingEnabled(bool enabled) const;
};