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:
Ken Van Hoeylandt
2025-01-17 19:37:42 +01:00
committed by GitHub
parent 3ca0f8cf97
commit 3ea02d912f
147 changed files with 1538 additions and 739 deletions
+2 -2
View File
@@ -20,7 +20,7 @@ extern const tt::hal::Configuration lilygo_tdeck = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@@ -38,7 +38,7 @@ extern const tt::hal::Configuration lilygo_tdeck = {
tt::hal::i2c::Configuration {
.name = "External",
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
+8 -8
View File
@@ -56,11 +56,11 @@ TdeckPower::~TdeckPower() {
bool TdeckPower::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case CHARGE_LEVEL:
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
return true;
case IS_CHARGING:
case CURRENT:
case MetricType::IsCharging:
case MetricType::Current:
return false;
}
@@ -69,17 +69,17 @@ bool TdeckPower::supportsMetric(MetricType type) const {
bool TdeckPower::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE:
case MetricType::BatteryVoltage:
return readBatteryVoltageSampled(data.valueAsUint32);
case CHARGE_LEVEL:
case MetricType::ChargeLevel:
if (readBatteryVoltageSampled(data.valueAsUint32)) {
data.valueAsUint32 = estimateChargeLevelFromVoltage(data.valueAsUint32);
return true;
} else {
return false;
}
case IS_CHARGING:
case CURRENT:
case MetricType::IsCharging:
case MetricType::Current:
return false;
}
@@ -18,7 +18,7 @@ std::shared_ptr<SdCard> createTdeckSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
tt::lvgl::getLvglSyncLockable(),
{
TDECK_RADIO_PIN_CS,
+2 -2
View File
@@ -16,11 +16,11 @@
axp192_t axpDevice;
static int32_t axpI2cRead(TT_UNUSED void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) {
return tt::hal::i2c::masterRead(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
return tt::hal::i2c::masterReadRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
}
static int32_t axpI2cWrite(TT_UNUSED void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) {
return tt::hal::i2c::masterWrite(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
return tt::hal::i2c::masterWriteRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
}
static bool initSpi2() {
+2 -2
View File
@@ -15,7 +15,7 @@ extern const tt::hal::Configuration m5stack_core2 = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false, // Might be set to try after trying out what it does AXP and screen
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@@ -33,7 +33,7 @@ extern const tt::hal::Configuration m5stack_core2 = {
tt::hal::i2c::Configuration {
.name = "External", // (Grove)
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@@ -8,11 +8,11 @@ extern axp192_t axpDevice;
bool Core2Power::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case CHARGE_LEVEL:
case IS_CHARGING:
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
case MetricType::IsCharging:
return true;
case CURRENT:
case MetricType::Current:
return false;
}
@@ -21,7 +21,7 @@ bool Core2Power::supportsMetric(MetricType type) const {
bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE: {
case MetricType::BatteryVoltage: {
float voltage;
if (axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &voltage) == ESP_OK) {
data.valueAsUint32 = (uint32_t)TT_MAX((voltage * 1000.f), 0.0f);
@@ -30,7 +30,7 @@ bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CHARGE_LEVEL: {
case MetricType::ChargeLevel: {
float vbat, charge_current;
if (
axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &vbat) == ESP_OK &&
@@ -51,7 +51,7 @@ bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case IS_CHARGING: {
case MetricType::IsCharging: {
float charge_current;
if (axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK) {
data.valueAsBool = charge_current > 0.001f;
@@ -60,7 +60,7 @@ bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CURRENT: {
case MetricType::Current: {
float charge_current, discharge_current;
if (
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK &&
@@ -16,7 +16,7 @@ std::shared_ptr<SdCard> createSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
tt::lvgl::getLvglSyncLockable(),
{
CORE2_LCD_PIN_CS
+1 -1
View File
@@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source" "Source/hal" "Source/Axp2101"
SRC_DIRS "Source" "Source/hal" "Source/Axp2101" "Source/Aw9523" "Source/I2cDevice"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 esp_lcd_touch_ft5x06 driver vfs fatfs
)
@@ -0,0 +1,24 @@
#include "Aw9523.h"
#define AW9523_REGISTER_P0 0x02
#define AW9523_REGISTER_P1 0x03
bool Aw9523::readP0(uint8_t& output) const {
return readRegister8(AW9523_REGISTER_P0, output);
}
bool Aw9523::readP1(uint8_t& output) const {
return readRegister8(AW9523_REGISTER_P1, output);
}
bool Aw9523::writeP0(uint8_t value) const {
return writeRegister8(AW9523_REGISTER_P0, value);
}
bool Aw9523::writeP1(uint8_t value) const {
return writeRegister8(AW9523_REGISTER_P1, value);
}
bool Aw9523::bitOnP1(uint8_t bitmask) const {
return bitOn(AW9523_REGISTER_P1, bitmask);
}
@@ -0,0 +1,20 @@
#pragma once
#include "I2cDevice/I2cDevice.h"
#define AW9523_ADDRESS 0x58
class Aw9523 : I2cDevice {
public:
explicit Aw9523(i2c_port_t port) : I2cDevice(port, AW9523_ADDRESS) {}
bool readP0(uint8_t& output) const;
bool readP1(uint8_t& output) const;
bool writeP0(uint8_t value) const;
bool writeP1(uint8_t value) const;
bool bitOnP1(uint8_t bitmask) const;
};
+23 -38
View File
@@ -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, &reg, 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);
}
+10 -13
View File
@@ -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;
};
@@ -0,0 +1,59 @@
#include "I2cDevice.h"
bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x0F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool I2cDevice::readRegister14(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x3F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool I2cDevice::readRegister16(uint8_t reg, uint16_t& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = data[0] << 8 | data[1];
return true;
} else {
return false;
}
}
bool I2cDevice::readRegister8(uint8_t reg, uint8_t& result) const {
return tt::hal::i2c::masterWriteRead(port, address, &reg, 1, &result, 1, DEFAULT_TIMEOUT);
}
bool I2cDevice::writeRegister8(uint8_t reg, uint8_t value) const {
return tt::hal::i2c::masterWriteRegister(port, address, reg, &value, 1, DEFAULT_TIMEOUT);
}
bool I2cDevice::bitOn(uint8_t reg, uint8_t bitmask) const {
uint8_t state;
if (readRegister8(reg, state)) {
state |= bitmask;
return writeRegister8(reg, state);
} else {
return false;
}
}
bool I2cDevice::bitOff(uint8_t reg, uint8_t bitmask) const {
uint8_t state;
if (readRegister8(reg, state)) {
state &= ~bitmask;
return writeRegister8(reg, state);
} else {
return false;
}
}
@@ -0,0 +1,25 @@
#pragma once
#include "hal/i2c/I2c.h"
class I2cDevice {
protected:
i2c_port_t port;
uint8_t address;
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;
bool bitOn(uint8_t reg, uint8_t bitmask) const;
bool bitOff(uint8_t reg, uint8_t bitmask) const;
public:
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {}
};
+117 -37
View File
@@ -3,8 +3,9 @@
#include <intr_types.h>
#include "Log.h"
#include "hal/CoreS3DisplayConstants.h"
#include "hal/i2c/I2c.h"
#include "CoreS3Constants.h"
#include "kernel/Kernel.h"
#include "Axp2101/Axp2101.h"
#include "Aw9523/Aw9523.h"
#define TAG "core2"
@@ -43,62 +44,141 @@ static bool initSpi3() {
/**
* For details see https://github.com/espressif/esp-bsp/blob/master/bsp/m5stack_core_s3/m5stack_core_s3.c
* and schematic: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/core/K128%20CoreS3/Sch_M5_CoreS3_v1.0.pdf
*/
bool initGpioExpander() {
TT_LOG_I(TAG, "Init AW9523 GPIO expander");
uint8_t aw9523_P0 = 0b10;
uint8_t aw9523_P1 = 0b10100000;
TT_LOG_I(TAG, "AW9523 init");
// Enable LCD
aw9523_P1 |= (1 << 1);
/**
* P0 pins:
* 0: Touch reset
* 1: Bus out enable
* 2: AW88298 reset (I2S)
* 3: ES7210 interrupt (Audio ADC)
* 4: SD Card SW(itch on?)
* 5: USB OTG enable
* 6: /
* 7: /
*/
/**
* P1 pins:
* 0: Cam reset
* 1: LCD reset
* 2: Touch interrupt
* 3: AW88298 interrupt (I2S)
* 4: /
* 5: /
* 6: /
* 7: Boost enable
*/
uint8_t p0_state = 0U;
uint8_t p1_state = 0U;
// Enable touch
aw9523_P0 |= (1);
p0_state |= (1U);
// Bus out enable
p0_state |= (1U << 1U);
// I2S
p0_state |= (1U << 2U);
// SD card
aw9523_P0 |= (1 << 4);
p0_state |= (1U << 4U);
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x02, &aw9523_P0, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable LCD");
// Enable LCD
p1_state |= (1U << 1U);
// Boost enable
p1_state |= (1U << 7U);
Aw9523 aw(I2C_NUM_0);
if (!aw.writeP0(p0_state)) {
TT_LOG_E(TAG, "AW9523: Failed to set P0");
return false;
}
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x03, &aw9523_P1, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable touch");
if (!aw.writeP1(p1_state)) {
TT_LOG_E(TAG, "AW9523: Failed to set P1");
return false;
}
Axp2101 axp(I2C_NUM_0);
if (axp.isVBus()) {
float voltage = 0.0f;
axp.getVBusVoltage(voltage);
TT_LOG_I(TAG, "AXP2101: VBus at %.2f", voltage);
} else {
TT_LOG_W(TAG, "AXP2101: VBus disabled");
}
return true;
}
bool initPowerControl() {
TT_LOG_I(TAG, "Init power control");
TT_LOG_I(TAG, "Init power control (AXP2101)");
uint8_t sdcard_3v3 = 0b00011100;
// TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x95, &sdcard_3v3, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable SD card");
Aw9523 aw(I2C_NUM_0);
// Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L61
aw.bitOnP1(0b10000000); // SY7088 boost enable
/** AXP2101 usage
Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/README.md?plain=1#L223
| |M5Stack<BR>CoreS3<BR>CoreS3SE| |
|:---------:|:-----------------:|:---------:|
| ALDO1 |VDD 1v8 | ALDO1 |
| ALDO2 |VDDA 3v3 | ALDO2 |
| ALDO3 |CAM 3v3 | ALDO3 |
| ALDO4 |TF 3v3 | ALDO4 |
| BLDO1 |AVDD | BLDO1 |
| BLDO2 |DVDD | BLDO2 |
| DLDO1/DC1 |LCD BL | DLDO1/DC1 |
| DLDO2/DC2 | --- | DLDO2/DC2 |
| BACKUP |RTC BAT | BACKUP |
*/
/**
* 0x92 = ALD01
* 0x93 = ALD02
* 0x94 = ALD03
* 0x95 = ALD04
* 0x96 = BLD01
* 0x97 = BLD02
*
* DCDC1 : 0.7-3.5V 25mV/step 1200mA
* DCDC2 : 0.7-2.275V25mV/step 1600mA
* DCDC3 : 0.7-3.5V 25mV/step 700mA
* LDOio0: 1.8-3.3V, 100mV/step 50mA
* LDO1 : 30mA always on
* LDO2 : 1.8-3.3V 100mV/step 200mA
* LDO3 : 1.8-3.3V 100mV/step 200mA
*/
// Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L64
static constexpr uint8_t reg_data_array[] = {
0x90U, 0xBFU, // LDOS ON/OFF control 0 (backlight)
0x92U, 18U -5U, // ALDO1 set to 1.8v // for AW88298
0x93U, 33U -5U, // ALDO2 set to 3.3v // for ES7210
0x94U, 33U -5U, // ALDO3 set to 3.3v // for camera
0x95U, 33U -5U, // ALDO3 set to 3.3v // for TF card slot
0x27, 0x00, // PowerKey Hold=1sec / PowerOff=4sec
0x69, 0x11, // CHGLED setting
0x10, 0x30, // PMU common config
0x30, 0x0F // ADC enabled (for voltage measurement)
};
Axp2101 axp(I2C_NUM_0);
if (axp.setRegisters((uint8_t*)reg_data_array, sizeof(reg_data_array))) {
TT_LOG_I(TAG, "AXP2101 initialized with %d registers", sizeof(reg_data_array) / 2);
return true;
} else {
TT_LOG_E(TAG, "AXP2101: Failed to set registers");
return false;
}
// TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
uint8_t axp_dld01_enable = 0xBF; // For backlight
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x90, &axp_dld01_enable, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable display backlight");
return false;
}
// TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62
uint8_t axp_dld01_voltage = 0b00011000; // For backlight
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &axp_dld01_voltage, 1, 1000)) {
TT_LOG_E(TAG, "Failed to set display backlight voltage");
return false;
}
return true;
}
bool initBoot() {
TT_LOG_I(TAG, "initBoot");
return initPowerControl() && initGpioExpander() && initSpi3();
TT_LOG_I(TAG, "initBoot()");
return initPowerControl() &&
initGpioExpander() &&
initSpi3();
}
@@ -15,7 +15,7 @@ const tt::hal::Configuration m5stack_cores3 = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@@ -33,7 +33,7 @@ const tt::hal::Configuration m5stack_cores3 = {
tt::hal::i2c::Configuration {
.name = "External", // Grove
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@@ -175,7 +175,7 @@ void CoreS3Display::setGammaCurve(uint8_t index) {
void CoreS3Display::setBacklightDuty(uint8_t backlightDuty) {
const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark
// TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) {
if (!tt::hal::i2c::masterWriteRegister(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) { // Sets DLD01
TT_LOG_E(TAG, "Failed to set display backlight voltage");
}
}
@@ -5,11 +5,11 @@
bool CoreS3Power::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case IS_CHARGING:
case CHARGE_LEVEL:
case MetricType::BatteryVoltage:
case MetricType::IsCharging:
case MetricType::ChargeLevel:
return true;
case CURRENT:
case MetricType::Current:
return false;
}
@@ -18,7 +18,7 @@ bool CoreS3Power::supportsMetric(MetricType type) const {
bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE: {
case MetricType::BatteryVoltage: {
float milliVolt;
if (axpDevice.getBatteryVoltage(milliVolt)) {
data.valueAsUint32 = (uint32_t)milliVolt;
@@ -27,7 +27,7 @@ bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CHARGE_LEVEL: {
case MetricType::ChargeLevel: {
float vbatMillis;
if (axpDevice.getBatteryVoltage(vbatMillis)) {
float vbat = vbatMillis / 1000.f;
@@ -44,7 +44,7 @@ bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case IS_CHARGING: {
case MetricType::IsCharging: {
Axp2101::ChargeStatus status;
if (axpDevice.getChargeStatus(status)) {
data.valueAsBool = (status == Axp2101::CHARGE_STATUS_CHARGING);
@@ -53,7 +53,7 @@ bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CURRENT:
case MetricType::Current:
return false;
}
@@ -16,7 +16,7 @@ std::shared_ptr<SdCard> createSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
tt::lvgl::getLvglSyncLockable(),
{
CORES3_LCD_PIN_CS
+2 -2
View File
@@ -10,8 +10,8 @@
#define TAG "lvgl_task"
// Mutex for LVGL drawing
static tt::Mutex lvgl_mutex(tt::Mutex::TypeRecursive);
static tt::Mutex task_mutex(tt::Mutex::TypeRecursive);
static tt::Mutex lvgl_mutex(tt::Mutex::Type::Recursive);
static tt::Mutex task_mutex(tt::Mutex::Type::Recursive);
static uint32_t task_max_sleep_ms = 10;
// Mutex for LVGL task state (to modify task_running state)
@@ -36,7 +36,7 @@ extern const tt::hal::Configuration hardware = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@@ -54,7 +54,7 @@ extern const tt::hal::Configuration hardware = {
tt::hal::i2c::Configuration {
.name = "External",
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@@ -4,10 +4,10 @@
bool SimulatorPower::supportsMetric(MetricType type) const {
switch (type) {
case IS_CHARGING:
case CURRENT:
case BATTERY_VOLTAGE:
case CHARGE_LEVEL:
case MetricType::IsCharging:
case MetricType::Current:
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
return true;
}
@@ -16,16 +16,16 @@ bool SimulatorPower::supportsMetric(MetricType type) const {
bool SimulatorPower::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case IS_CHARGING:
case MetricType::IsCharging:
data.valueAsBool = true;
return true;
case CURRENT:
case MetricType::Current:
data.valueAsInt32 = 42;
return true;
case BATTERY_VOLTAGE:
case MetricType::BatteryVoltage:
data.valueAsUint32 = 4032;
return true;
case CHARGE_LEVEL:
case MetricType::ChargeLevel:
data.valueAsUint8 = 100;
return true;
}
@@ -8,14 +8,14 @@ class SimulatorSdCard : public SdCard {
private:
State state;
public:
SimulatorSdCard() : SdCard(MountBehaviourAtBoot), state(StateUnmounted) {}
SimulatorSdCard() : SdCard(MountBehaviour::AtBoot), state(State::Unmounted) {}
bool mount(const char* mountPath) override {
state = StateMounted;
state = State::Mounted;
return true;
}
bool unmount() override {
state = StateUnmounted;
state = State::Unmounted;
return true;
}
+2 -2
View File
@@ -15,7 +15,7 @@ const tt::hal::Configuration yellow_board_24inch_cap = {
tt::hal::i2c::Configuration {
.name = "First",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitDisabled,
.initMode = tt::hal::i2c::InitMode::Disabled,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@@ -33,7 +33,7 @@ const tt::hal::Configuration yellow_board_24inch_cap = {
tt::hal::i2c::Configuration {
.name = "Second",
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitDisabled,
.initMode = tt::hal::i2c::InitMode::Disabled,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@@ -16,7 +16,7 @@ std::shared_ptr<SdCard> createYellowSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
nullptr,
std::vector<gpio_num_t>(),
SDCARD_SPI_HOST