Merge develop into main (#368)
New boards: - LilyGO T-Dongle S3 - M5Stack StickC Plus - M5Stack StickC Plus2 New drivers: - AXP192: power control via I2C - ButtonControl: GPIO button input as LVGL device Other changes: - Updated implementation of AXP192 driver for Core2 board - Fix launcher UX for vertical layout - Fix error when properties file had an empty line - Add `__floatsidf` to `tt_init.cpp`
This commit is contained in:
committed by
GitHub
parent
3a59540365
commit
d8346998ce
@@ -1,108 +0,0 @@
|
||||
#include "Core2Power.h"
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include "axp192/axp192.h"
|
||||
|
||||
constexpr auto TAG = "Core2Power";
|
||||
|
||||
extern axp192_t axpDevice;
|
||||
|
||||
bool Core2Power::supportsMetric(MetricType type) const {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case BatteryVoltage:
|
||||
case ChargeLevel:
|
||||
case IsCharging:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Core2Power::getMetric(MetricType type, MetricData& data) {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case BatteryVoltage: {
|
||||
float voltage;
|
||||
if (axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &voltage) == ESP_OK) {
|
||||
data.valueAsUint32 = (uint32_t)std::max((voltage * 1000.f), 0.0f);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case ChargeLevel: {
|
||||
float vbat, charge_current;
|
||||
if (
|
||||
axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &vbat) == ESP_OK &&
|
||||
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK
|
||||
) {
|
||||
float max_voltage = 4.20f;
|
||||
float min_voltage = 2.69f; // From M5Unified
|
||||
float voltage_correction = (charge_current > 0.01f) ? -0.1f : 0.f; // Roughly 0.1V drop when ccharging
|
||||
float corrected_voltage = vbat + voltage_correction;
|
||||
if (corrected_voltage > 2.69f) {
|
||||
float charge_factor = (corrected_voltage - min_voltage) / (max_voltage - min_voltage);
|
||||
data.valueAsUint8 = (uint8_t)(charge_factor * 100.f);
|
||||
} else {
|
||||
data.valueAsUint8 = 0;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case IsCharging: {
|
||||
float charge_current;
|
||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK) {
|
||||
data.valueAsBool = charge_current > 0.001f;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case Current: {
|
||||
float charge_current, discharge_current;
|
||||
if (
|
||||
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK &&
|
||||
axp192_read(&axpDevice, AXP192_DISCHARGE_CURRENT, &discharge_current) == ESP_OK
|
||||
) {
|
||||
if (charge_current > 0.0f) {
|
||||
data.valueAsInt32 = (int32_t) (charge_current * 1000.0f);
|
||||
} else {
|
||||
data.valueAsInt32 = -(int32_t) (discharge_current * 1000.0f);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Core2Power::isAllowedToCharge() const {
|
||||
uint8_t buffer;
|
||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) {
|
||||
return buffer & 0x80;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Core2Power::setAllowedToCharge(bool canCharge) {
|
||||
uint8_t buffer;
|
||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) {
|
||||
buffer = (buffer & 0x7F) + (canCharge ? 0x80 : 0x00);
|
||||
axp192_write(&axpDevice, AXP192_CHARGE_CONTROL_1, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<PowerDevice> power;
|
||||
|
||||
std::shared_ptr<PowerDevice> createPower() {
|
||||
if (power == nullptr) {
|
||||
power = std::make_shared<Core2Power>();
|
||||
}
|
||||
return power;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/power/PowerDevice.h"
|
||||
#include <memory>
|
||||
|
||||
using tt::hal::power::PowerDevice;
|
||||
|
||||
class Core2Power : public PowerDevice {
|
||||
|
||||
public:
|
||||
|
||||
Core2Power() = default;
|
||||
~Core2Power() override = default;
|
||||
|
||||
std::string getName() const final { return "AXP192 Power"; }
|
||||
std::string getDescription() const final { return "Power management via I2C"; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
bool supportsChargeControl() const override { return true; }
|
||||
bool isAllowedToCharge() const override;
|
||||
void setAllowedToCharge(bool canCharge) override;
|
||||
};
|
||||
|
||||
std::shared_ptr<PowerDevice> createPower();
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <Axp192.h>
|
||||
|
||||
static std::shared_ptr<Axp192> axp192 = nullptr;
|
||||
|
||||
std::shared_ptr<Axp192> createAxp192() {
|
||||
assert(axp192 == nullptr);
|
||||
auto configuration = std::make_unique<Axp192::Configuration>(I2C_NUM_0);
|
||||
axp192 = std::make_shared<Axp192>(std::move(configuration));
|
||||
return axp192;
|
||||
}
|
||||
|
||||
std::shared_ptr<Axp192> getAxp192() {
|
||||
assert(axp192 != nullptr);
|
||||
return axp192;
|
||||
}
|
||||
|
||||
bool initAxp() {
|
||||
const auto axp = createAxp192();
|
||||
return axp->init([](auto* driver) {
|
||||
axp192_ioctl(driver, AXP192_LDO2_SET_VOLTAGE, 3300); // LCD + SD
|
||||
axp192_ioctl(driver, AXP192_LDO3_SET_VOLTAGE, 0); // VIB_MOTOR STOP
|
||||
axp192_ioctl(driver, AXP192_DCDC3_SET_VOLTAGE, 3300);
|
||||
|
||||
axp192_ioctl(driver, AXP192_LDO2_ENABLE);
|
||||
axp192_ioctl(driver, AXP192_LDO3_DISABLE);
|
||||
axp192_ioctl(driver, AXP192_DCDC3_ENABLE);
|
||||
|
||||
axp192_write(driver, AXP192_PWM1_DUTY_CYCLE_2, 255); // PWM 255 (LED OFF)
|
||||
axp192_write(driver, AXP192_GPIO1_CONTROL, 0x02); // GPIO1 PWM
|
||||
|
||||
// TODO: We could charge at 390mA according to the M5Unified code, but the AXP driver in M5Unified limits to 132mA, so it's unclear what the AXP supports.
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Axp192.h>
|
||||
|
||||
bool initAxp();
|
||||
|
||||
// Must call initAxp() first before this returns a non-nullptr response
|
||||
std::shared_ptr<Axp192> getAxp192();
|
||||
|
||||
Reference in New Issue
Block a user