Board update and created Axp2101Power class

This commit is contained in:
Ken Van Hoeylandt 2025-09-02 22:32:48 +02:00
parent b0408e40ec
commit e971f01eeb
13 changed files with 45 additions and 53 deletions

View File

@ -1,5 +1,7 @@
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register( idf_component_register(
SRC_DIRS "Source" "Source/hal" SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source" INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port ILI934x FT5x06 AXP2101 AW9523 driver vfs fatfs REQUIRES Tactility esp_lvgl_port ILI934x FT5x06 AXP2101 AW9523 driver vfs fatfs
) )

View File

@ -1,4 +0,0 @@
#pragma once
#define AXP2101_ADDRESS 0x34
#define AW9523_ADDRESS 0x58

View File

@ -1,10 +1,9 @@
#include <Axp2101.h> #include "InitBoot.h"
#include <Aw9523.h>
#include <Tactility/Log.h> #include <Tactility/Log.h>
#include <Tactility/kernel/Kernel.h> #include <Tactility/kernel/Kernel.h>
#define TAG "cores3" constexpr auto* TAG = "CoreS3";
std::shared_ptr<Axp2101> axp2101; std::shared_ptr<Axp2101> axp2101;
std::shared_ptr<Aw9523> aw9523; std::shared_ptr<Aw9523> aw9523;
@ -148,9 +147,7 @@ bool initBoot() {
TT_LOG_I(TAG, "initBoot()"); TT_LOG_I(TAG, "initBoot()");
axp2101 = std::make_shared<Axp2101>(I2C_NUM_0); axp2101 = std::make_shared<Axp2101>(I2C_NUM_0);
tt::hal::registerDevice(axp2101);
aw9523 = std::make_shared<Aw9523>(I2C_NUM_0); aw9523 = std::make_shared<Aw9523>(I2C_NUM_0);
tt::hal::registerDevice(aw9523);
return initPowerControl() && initGpioExpander(); return initPowerControl() && initGpioExpander();
} }

View File

@ -1,3 +1,9 @@
#pragma once #pragma once
#include <Axp2101.h>
#include <Aw9523.h>
extern std::shared_ptr<Axp2101> axp2101;
extern std::shared_ptr<Aw9523> aw9523;
bool initBoot(); bool initBoot();

View File

@ -1,10 +1,9 @@
#include "M5stackCoreS3.h" #include "M5stackCoreS3.h"
#include "InitBoot.h" #include "InitBoot.h"
#include "hal/CoreS3Display.h" #include "devices/Display.h"
#include "hal/CoreS3DisplayConstants.h" #include "devices/SdCard.h"
#include "hal/CoreS3Power.h"
#include "hal/CoreS3SdCard.h"
#include <Axp2101Power.h>
#include <Tactility/lvgl/LvglSync.h> #include <Tactility/lvgl/LvglSync.h>
#include <Tactility/hal/uart/Uart.h> #include <Tactility/hal/uart/Uart.h>
@ -12,11 +11,19 @@
using namespace tt::hal; using namespace tt::hal;
static DeviceVector createDevices() {
return {
axp2101,
aw9523,
std::make_shared<Axp2101Power>(axp2101),
createSdCard(),
createDisplay()
};
}
const Configuration m5stack_cores3 = { const Configuration m5stack_cores3 = {
.initBoot = initBoot, .initBoot = initBoot,
.createDisplay = createDisplay, .createDevices = createDevices,
.sdcard = createSdCard(),
.power = createPower,
.i2c = { .i2c = {
i2c::Configuration { i2c::Configuration {
.name = "Internal", .name = "Internal",

View File

@ -1,12 +1,12 @@
#include "CoreS3Display.h" #include "Display.h"
#include "CoreS3Constants.h"
#include <Axp2101.h>
#include <Ft5x06Touch.h> #include <Ft5x06Touch.h>
#include <Ili934xDisplay.h> #include <Ili934xDisplay.h>
#include <Tactility/Log.h> #include <Tactility/Log.h>
#include <Tactility/hal/i2c/I2c.h> #include <Tactility/hal/i2c/I2c.h>
constexpr auto TAG = "CoreS3Display"; constexpr auto* TAG = "CoreS3Display";
static void setBacklightDuty(uint8_t backlightDuty) { static void setBacklightDuty(uint8_t backlightDuty) {
const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <Tactility/hal/display/DisplayDevice.h>
// Display // Display
#define CORES3_LCD_SPI_HOST SPI3_HOST #define CORES3_LCD_SPI_HOST SPI3_HOST
#define CORES3_LCD_PIN_CS GPIO_NUM_3 #define CORES3_LCD_PIN_CS GPIO_NUM_3
@ -8,3 +10,5 @@
#define CORES3_LCD_VERTICAL_RESOLUTION 240 #define CORES3_LCD_VERTICAL_RESOLUTION 240
#define CORES3_LCD_DRAW_BUFFER_HEIGHT (CORES3_LCD_VERTICAL_RESOLUTION / 10) #define CORES3_LCD_DRAW_BUFFER_HEIGHT (CORES3_LCD_VERTICAL_RESOLUTION / 10)
#define CORES3_LCD_DRAW_BUFFER_SIZE (CORES3_LCD_HORIZONTAL_RESOLUTION * CORES3_LCD_DRAW_BUFFER_HEIGHT) #define CORES3_LCD_DRAW_BUFFER_SIZE (CORES3_LCD_HORIZONTAL_RESOLUTION * CORES3_LCD_DRAW_BUFFER_HEIGHT)
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -1,10 +1,8 @@
#include "CoreS3SdCard.h" #include "SdCard.h"
#include <Tactility/lvgl/LvglSync.h> #include <Tactility/lvgl/LvglSync.h>
#include <Tactility/hal/sdcard/SpiSdCardDevice.h> #include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <esp_vfs_fat.h>
constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4; constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4;
constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3; constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3;

View File

@ -1,5 +0,0 @@
#pragma once
#include <Tactility/hal/display/DisplayDevice.h>
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -21,8 +21,8 @@ public:
explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {} explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {}
std::string getName() const final { return "AXP2101"; } std::string getName() const override { return "AXP2101"; }
std::string getDescription() const final { return "Power management with I2C interface."; } std::string getDescription() const override { return "Power management with I2C interface."; }
bool setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const; bool setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const;

View File

@ -1,6 +1,6 @@
#include "CoreS3Power.h" #include "Axp2101Power.h"
bool CoreS3Power::supportsMetric(MetricType type) const { bool Axp2101Power::supportsMetric(MetricType type) const {
switch (type) { switch (type) {
using enum MetricType; using enum MetricType;
case BatteryVoltage: case BatteryVoltage:
@ -14,7 +14,7 @@ bool CoreS3Power::supportsMetric(MetricType type) const {
return false; // Safety guard for when new enum values are introduced return false; // Safety guard for when new enum values are introduced
} }
bool CoreS3Power::getMetric(MetricType type, MetricData& data) { bool Axp2101Power::getMetric(MetricType type, MetricData& data) {
switch (type) { switch (type) {
using enum MetricType; using enum MetricType;
case BatteryVoltage: { case BatteryVoltage: {
@ -57,7 +57,7 @@ bool CoreS3Power::getMetric(MetricType type, MetricData& data) {
} }
} }
bool CoreS3Power::isAllowedToCharge() const { bool Axp2101Power::isAllowedToCharge() const {
bool enabled; bool enabled;
if (axpDevice->isChargingEnabled(enabled)) { if (axpDevice->isChargingEnabled(enabled)) {
return enabled; return enabled;
@ -66,17 +66,6 @@ bool CoreS3Power::isAllowedToCharge() const {
} }
} }
void CoreS3Power::setAllowedToCharge(bool canCharge) { void Axp2101Power::setAllowedToCharge(bool canCharge) {
axpDevice->setChargingEnabled(canCharge); axpDevice->setChargingEnabled(canCharge);
} }
static std::shared_ptr<PowerDevice> power;
extern std::shared_ptr<Axp2101> axp2101;
std::shared_ptr<PowerDevice> createPower() {
if (power == nullptr) {
power = std::make_shared<CoreS3Power>(axp2101);
}
return power;
}

View File

@ -7,17 +7,17 @@
using tt::hal::power::PowerDevice; using tt::hal::power::PowerDevice;
class CoreS3Power final : public PowerDevice { class Axp2101Power final : public PowerDevice {
std::shared_ptr<Axp2101> axpDevice; std::shared_ptr<Axp2101> axpDevice;
public: public:
explicit CoreS3Power(std::shared_ptr<Axp2101> axp) : axpDevice(std::move(axp)) {} explicit Axp2101Power(std::shared_ptr<Axp2101> axp) : axpDevice(std::move(axp)) {}
~CoreS3Power() override = default; ~Axp2101Power() override = default;
std::string getName() const final { return "AXP2101 Power"; } std::string getName() const override { return "AXP2101 Power"; }
std::string getDescription() const final { return "Power management via I2C"; } std::string getDescription() const override { return "Power management via AXP2101 over I2C"; }
bool supportsMetric(MetricType type) const override; bool supportsMetric(MetricType type) const override;
bool getMetric(MetricType type, MetricData& data) override; bool getMetric(MetricType type, MetricData& data) override;
@ -26,5 +26,3 @@ public:
bool isAllowedToCharge() const override; bool isAllowedToCharge() const override;
void setAllowedToCharge(bool canCharge) override; void setAllowedToCharge(bool canCharge) override;
}; };
std::shared_ptr<PowerDevice> createPower();