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)
This commit is contained in:
committed by
GitHub
parent
3ca0f8cf97
commit
3ea02d912f
@@ -1,44 +1,6 @@
|
||||
#include "Axp2101.h"
|
||||
#include "Log.h"
|
||||
|
||||
bool Axp2101::readRegister12(uint8_t reg, float& out) const {
|
||||
std::uint8_t data[2] = {0};
|
||||
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
|
||||
out = (data[0] & 0x0F) << 8 | data[1];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::readRegister14(uint8_t reg, float& out) const {
|
||||
std::uint8_t data[2] = {0};
|
||||
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
|
||||
out = (data[0] & 0x3F) << 8 | data[1];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::readRegister16(uint8_t reg, uint16_t& out) const {
|
||||
std::uint8_t data[2] = {0};
|
||||
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
|
||||
out = data[0] << 8 | data[1];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::readRegister8(uint8_t reg, uint8_t& result) const {
|
||||
return tt::hal::i2c::masterWriteRead(port, DEFAULT_ADDRESS, ®, 1, &result, 1, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
bool Axp2101::writeRegister8(uint8_t reg, uint8_t value) const {
|
||||
return tt::hal::i2c::masterWrite(port, DEFAULT_ADDRESS, reg, &value, 1, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
bool Axp2101::getBatteryVoltage(float& vbatMillis) const {
|
||||
return readRegister14(0x34, vbatMillis);
|
||||
}
|
||||
@@ -72,3 +34,26 @@ bool Axp2101::setChargingEnabled(bool enabled) const {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/i2c/I2c.h"
|
||||
#include "I2cDevice/I2cDevice.h"
|
||||
|
||||
#define AXP2101_ADDRESS 0x34
|
||||
|
||||
/**
|
||||
* 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;
|
||||
class Axp2101 : I2cDevice {
|
||||
|
||||
public:
|
||||
|
||||
@@ -28,10 +20,15 @@ public:
|
||||
CHARGE_STATUS_STANDBY = 0b00
|
||||
};
|
||||
|
||||
Axp2101(i2c_port_t port) : port(port) {}
|
||||
explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {}
|
||||
|
||||
bool setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const;
|
||||
|
||||
bool getBatteryVoltage(float& vbatMillis) const;
|
||||
bool getChargeStatus(ChargeStatus& status) const;
|
||||
bool isChargingEnabled(bool& enabled) const;
|
||||
bool setChargingEnabled(bool enabled) const;
|
||||
|
||||
bool isVBus() const;
|
||||
bool getVBusVoltage(float& out) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user