From 20c4e6d3abf64e363c10d3de184fb9963433faa1 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 12 Oct 2025 14:47:32 +0200 Subject: [PATCH] Create separate project for AXP192 driver --- Boards/M5stackCore2/CMakeLists.txt | 2 +- Boards/M5stackCore2/Source/M5stackCore2.cpp | 12 +- Boards/M5stackCore2/Source/devices/Power.cpp | 35 ++++ Boards/M5stackCore2/Source/devices/Power.h | 9 + Boards/M5stackStickCPlus/CMakeLists.txt | 7 + Boards/M5stackStickCPlus/README.md | 9 + .../Source/InitBoot.cpp | 0 .../Source/InitBoot.h | 0 .../M5stackStickCPlus/Source/M5stackCore2.cpp | 111 ++++++++++ .../M5stackStickCPlus/Source/M5stackCore2.h | 5 + .../Source/devices/Core2Power.cpp | 0 .../Source/devices/Core2Power.h | 0 .../Source/devices/Display.cpp | 36 ++++ .../Source/devices/Display.h | 14 ++ .../Source/devices/SdCard.cpp | 27 +++ .../M5stackStickCPlus/Source/devices/SdCard.h | 7 + Boards/M5stackStickCPlus2/CMakeLists.txt | 7 + Boards/M5stackStickCPlus2/README.md | 7 + Boards/M5stackStickCPlus2/Source/InitBoot.cpp | 153 ++++++++++++++ Boards/M5stackStickCPlus2/Source/InitBoot.h | 9 + .../Source/M5stackCoreS3.cpp | 193 ++++++++++++++++++ .../M5stackStickCPlus2/Source/M5stackCoreS3.h | 5 + .../Source/devices/Display.cpp | 51 +++++ .../Source/devices/Display.h | 14 ++ .../Source/devices/SdCard.cpp | 28 +++ .../Source/devices/SdCard.h | 7 + Drivers/AXP192/CMakeLists.txt | 8 + Drivers/AXP192/Include/Axp192.h | 57 ++++++ .../AXP192/Include}/axp192/axp192.h | 0 .../AXP192/Private}/axp192/LICENSE | 0 .../AXP192/Private}/axp192/README.md | 0 .../AXP192/Private}/axp192/axp192_config.h | 0 Drivers/AXP192/README.md | 5 + Drivers/AXP192/Source/Axp192.cpp | 117 +++++++++++ .../AXP192}/Source/axp192/axp192.c | 4 +- sdkconfig.board.m5stack-stickc-plus | 60 ++++++ sdkconfig.board.m5stack-stickc-plus2 | 59 ++++++ 37 files changed, 1052 insertions(+), 6 deletions(-) create mode 100644 Boards/M5stackCore2/Source/devices/Power.cpp create mode 100644 Boards/M5stackCore2/Source/devices/Power.h create mode 100644 Boards/M5stackStickCPlus/CMakeLists.txt create mode 100644 Boards/M5stackStickCPlus/README.md rename Boards/{M5stackCore2 => M5stackStickCPlus}/Source/InitBoot.cpp (100%) rename Boards/{M5stackCore2 => M5stackStickCPlus}/Source/InitBoot.h (100%) create mode 100644 Boards/M5stackStickCPlus/Source/M5stackCore2.cpp create mode 100644 Boards/M5stackStickCPlus/Source/M5stackCore2.h rename Boards/{M5stackCore2 => M5stackStickCPlus}/Source/devices/Core2Power.cpp (100%) rename Boards/{M5stackCore2 => M5stackStickCPlus}/Source/devices/Core2Power.h (100%) create mode 100644 Boards/M5stackStickCPlus/Source/devices/Display.cpp create mode 100644 Boards/M5stackStickCPlus/Source/devices/Display.h create mode 100644 Boards/M5stackStickCPlus/Source/devices/SdCard.cpp create mode 100644 Boards/M5stackStickCPlus/Source/devices/SdCard.h create mode 100644 Boards/M5stackStickCPlus2/CMakeLists.txt create mode 100644 Boards/M5stackStickCPlus2/README.md create mode 100644 Boards/M5stackStickCPlus2/Source/InitBoot.cpp create mode 100644 Boards/M5stackStickCPlus2/Source/InitBoot.h create mode 100644 Boards/M5stackStickCPlus2/Source/M5stackCoreS3.cpp create mode 100644 Boards/M5stackStickCPlus2/Source/M5stackCoreS3.h create mode 100644 Boards/M5stackStickCPlus2/Source/devices/Display.cpp create mode 100644 Boards/M5stackStickCPlus2/Source/devices/Display.h create mode 100644 Boards/M5stackStickCPlus2/Source/devices/SdCard.cpp create mode 100644 Boards/M5stackStickCPlus2/Source/devices/SdCard.h create mode 100644 Drivers/AXP192/CMakeLists.txt create mode 100644 Drivers/AXP192/Include/Axp192.h rename {Boards/M5stackCore2/Source => Drivers/AXP192/Include}/axp192/axp192.h (100%) rename {Boards/M5stackCore2/Source => Drivers/AXP192/Private}/axp192/LICENSE (100%) rename {Boards/M5stackCore2/Source => Drivers/AXP192/Private}/axp192/README.md (100%) rename {Boards/M5stackCore2/Source => Drivers/AXP192/Private}/axp192/axp192_config.h (100%) create mode 100644 Drivers/AXP192/README.md create mode 100644 Drivers/AXP192/Source/Axp192.cpp rename {Boards/M5stackCore2 => Drivers/AXP192}/Source/axp192/axp192.c (99%) create mode 100644 sdkconfig.board.m5stack-stickc-plus create mode 100644 sdkconfig.board.m5stack-stickc-plus2 diff --git a/Boards/M5stackCore2/CMakeLists.txt b/Boards/M5stackCore2/CMakeLists.txt index a332ac41..8d28c585 100644 --- a/Boards/M5stackCore2/CMakeLists.txt +++ b/Boards/M5stackCore2/CMakeLists.txt @@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} INCLUDE_DIRS "Source" - REQUIRES Tactility esp_lvgl_port esp_lcd ILI934x FT6x36 driver vfs fatfs + REQUIRES Tactility esp_lvgl_port esp_lcd AXP192 ILI934x FT6x36 driver vfs fatfs ) diff --git a/Boards/M5stackCore2/Source/M5stackCore2.cpp b/Boards/M5stackCore2/Source/M5stackCore2.cpp index 0f187e77..3628ee01 100644 --- a/Boards/M5stackCore2/Source/M5stackCore2.cpp +++ b/Boards/M5stackCore2/Source/M5stackCore2.cpp @@ -1,8 +1,7 @@ #include "M5stackCore2.h" -#include "InitBoot.h" #include "devices/Display.h" -#include "devices/Core2Power.h" #include "devices/SdCard.h" +#include "devices/Power.h" #include #include @@ -11,9 +10,16 @@ using namespace tt::hal; +constexpr auto* TAG = "Core2"; + +bool initBoot() { + TT_LOG_I(TAG, "initBoot"); + return initAxp(); +} + static DeviceVector createDevices() { return { - createPower(), + getAxp192(), createSdCard(), createDisplay() }; diff --git a/Boards/M5stackCore2/Source/devices/Power.cpp b/Boards/M5stackCore2/Source/devices/Power.cpp new file mode 100644 index 00000000..8140046f --- /dev/null +++ b/Boards/M5stackCore2/Source/devices/Power.cpp @@ -0,0 +1,35 @@ +#include + +static std::shared_ptr axp192 = nullptr; + +std::shared_ptr createAxp192() { + assert(axp192 == nullptr); + auto configuration = std::make_unique(I2C_NUM_0); + axp192 = std::make_shared(std::move(configuration)); + return axp192; +} + +std::shared_ptr 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; + }); + +} diff --git a/Boards/M5stackCore2/Source/devices/Power.h b/Boards/M5stackCore2/Source/devices/Power.h new file mode 100644 index 00000000..14a00889 --- /dev/null +++ b/Boards/M5stackCore2/Source/devices/Power.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +bool initAxp(); + +// Must call initAxp() first before this returns a non-nullptr response +std::shared_ptr getAxp192(); + diff --git a/Boards/M5stackStickCPlus/CMakeLists.txt b/Boards/M5stackStickCPlus/CMakeLists.txt new file mode 100644 index 00000000..a332ac41 --- /dev/null +++ b/Boards/M5stackStickCPlus/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE SOURCE_FILES Source/*.c*) + +idf_component_register( + SRCS ${SOURCE_FILES} + INCLUDE_DIRS "Source" + REQUIRES Tactility esp_lvgl_port esp_lcd ILI934x FT6x36 driver vfs fatfs +) diff --git a/Boards/M5stackStickCPlus/README.md b/Boards/M5stackStickCPlus/README.md new file mode 100644 index 00000000..6160285b --- /dev/null +++ b/Boards/M5stackStickCPlus/README.md @@ -0,0 +1,9 @@ +# M5Stack Core2 + +This board implementation concerns the original Core2 hardware and **not** the v1.1 variant. + +Reference implementations: +- [ESP-BSP](https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_2) + +Docs: +- [M5Stack.com](https://docs.m5stack.com/en/core/Core2) diff --git a/Boards/M5stackCore2/Source/InitBoot.cpp b/Boards/M5stackStickCPlus/Source/InitBoot.cpp similarity index 100% rename from Boards/M5stackCore2/Source/InitBoot.cpp rename to Boards/M5stackStickCPlus/Source/InitBoot.cpp diff --git a/Boards/M5stackCore2/Source/InitBoot.h b/Boards/M5stackStickCPlus/Source/InitBoot.h similarity index 100% rename from Boards/M5stackCore2/Source/InitBoot.h rename to Boards/M5stackStickCPlus/Source/InitBoot.h diff --git a/Boards/M5stackStickCPlus/Source/M5stackCore2.cpp b/Boards/M5stackStickCPlus/Source/M5stackCore2.cpp new file mode 100644 index 00000000..0f187e77 --- /dev/null +++ b/Boards/M5stackStickCPlus/Source/M5stackCore2.cpp @@ -0,0 +1,111 @@ +#include "M5stackCore2.h" +#include "InitBoot.h" +#include "devices/Display.h" +#include "devices/Core2Power.h" +#include "devices/SdCard.h" + +#include +#include + +#define CORE2_SPI_TRANSFER_SIZE_LIMIT (CORE2_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8) + +using namespace tt::hal; + +static DeviceVector createDevices() { + return { + createPower(), + createSdCard(), + createDisplay() + }; +} + +extern const Configuration m5stack_core2 = { + .initBoot = initBoot, + .createDevices = createDevices, + .i2c = { + i2c::Configuration { + .name = "Internal", + .port = I2C_NUM_0, + .initMode = i2c::InitMode::ByTactility, + .isMutable = false, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_21, + .scl_io_num = GPIO_NUM_22, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + }, + i2c::Configuration { + .name = "External", // (Grove) + .port = I2C_NUM_1, + .initMode = i2c::InitMode::ByTactility, + .isMutable = true, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_32, + .scl_io_num = GPIO_NUM_33, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + } + }, + .spi { + spi::Configuration { + .device = SPI2_HOST, + .dma = SPI_DMA_CH_AUTO, + .config = { + .mosi_io_num = GPIO_NUM_23, + .miso_io_num = GPIO_NUM_38, + .sclk_io_num = GPIO_NUM_18, + .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported + .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported + .data4_io_num = GPIO_NUM_NC, + .data5_io_num = GPIO_NUM_NC, + .data6_io_num = GPIO_NUM_NC, + .data7_io_num = GPIO_NUM_NC, + .data_io_default_level = false, + .max_transfer_sz = CORE2_SPI_TRANSFER_SIZE_LIMIT, + .flags = 0, + .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, + .intr_flags = 0 + }, + .initMode = spi::InitMode::ByTactility, + .isMutable = false, + .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display + } + }, + .uart { + uart::Configuration { + .name = "Grove", + .port = UART_NUM_1, + .rxPin = GPIO_NUM_32, + .txPin = GPIO_NUM_33, + .rtsPin = GPIO_NUM_NC, + .ctsPin = GPIO_NUM_NC, + .rxBufferSize = 1024, + .txBufferSize = 1024, + .config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0, + } + } + }, + } +}; diff --git a/Boards/M5stackStickCPlus/Source/M5stackCore2.h b/Boards/M5stackStickCPlus/Source/M5stackCore2.h new file mode 100644 index 00000000..45b8a82b --- /dev/null +++ b/Boards/M5stackStickCPlus/Source/M5stackCore2.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +extern const tt::hal::Configuration m5stack_core2; diff --git a/Boards/M5stackCore2/Source/devices/Core2Power.cpp b/Boards/M5stackStickCPlus/Source/devices/Core2Power.cpp similarity index 100% rename from Boards/M5stackCore2/Source/devices/Core2Power.cpp rename to Boards/M5stackStickCPlus/Source/devices/Core2Power.cpp diff --git a/Boards/M5stackCore2/Source/devices/Core2Power.h b/Boards/M5stackStickCPlus/Source/devices/Core2Power.h similarity index 100% rename from Boards/M5stackCore2/Source/devices/Core2Power.h rename to Boards/M5stackStickCPlus/Source/devices/Core2Power.h diff --git a/Boards/M5stackStickCPlus/Source/devices/Display.cpp b/Boards/M5stackStickCPlus/Source/devices/Display.cpp new file mode 100644 index 00000000..58152553 --- /dev/null +++ b/Boards/M5stackStickCPlus/Source/devices/Display.cpp @@ -0,0 +1,36 @@ +#include "Display.h" + +#include +#include + +std::shared_ptr createTouch() { + auto configuration = std::make_unique( + I2C_NUM_0, + GPIO_NUM_39, + CORE2_LCD_HORIZONTAL_RESOLUTION, + CORE2_LCD_VERTICAL_RESOLUTION + ); + + auto touch = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(touch); +} + +std::shared_ptr createDisplay() { + auto touch = createTouch(); + + auto configuration = std::make_unique( + CORE2_LCD_SPI_HOST, + CORE2_LCD_PIN_CS, + CORE2_LCD_PIN_DC, + CORE2_LCD_HORIZONTAL_RESOLUTION, + CORE2_LCD_VERTICAL_RESOLUTION, + touch, + false, + false, + false, + true + ); + + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); +} diff --git a/Boards/M5stackStickCPlus/Source/devices/Display.h b/Boards/M5stackStickCPlus/Source/devices/Display.h new file mode 100644 index 00000000..75c13107 --- /dev/null +++ b/Boards/M5stackStickCPlus/Source/devices/Display.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Tactility/hal/display/DisplayDevice.h" +#include + +#define CORE2_LCD_SPI_HOST SPI2_HOST +#define CORE2_LCD_PIN_CS GPIO_NUM_5 +#define CORE2_LCD_PIN_DC GPIO_NUM_15 +#define CORE2_LCD_HORIZONTAL_RESOLUTION 320 +#define CORE2_LCD_VERTICAL_RESOLUTION 240 +#define CORE2_LCD_DRAW_BUFFER_HEIGHT (CORE2_LCD_VERTICAL_RESOLUTION / 10) +#define CORE2_LCD_DRAW_BUFFER_SIZE (CORE2_LCD_HORIZONTAL_RESOLUTION * CORE2_LCD_DRAW_BUFFER_HEIGHT) + +std::shared_ptr createDisplay(); diff --git a/Boards/M5stackStickCPlus/Source/devices/SdCard.cpp b/Boards/M5stackStickCPlus/Source/devices/SdCard.cpp new file mode 100644 index 00000000..9d0f12b9 --- /dev/null +++ b/Boards/M5stackStickCPlus/Source/devices/SdCard.cpp @@ -0,0 +1,27 @@ +#include "SdCard.h" + +#include +#include + +constexpr auto CORE2_SDCARD_PIN_CS = GPIO_NUM_4; +constexpr auto CORE2_LCD_PIN_CS = GPIO_NUM_5; + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto configuration = std::make_unique( + CORE2_SDCARD_PIN_CS, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + tt::lvgl::getSyncLock(), + std::vector { + CORE2_LCD_PIN_CS + } + ); + + return std::make_shared( + std::move(configuration) + ); +} diff --git a/Boards/M5stackStickCPlus/Source/devices/SdCard.h b/Boards/M5stackStickCPlus/Source/devices/SdCard.h new file mode 100644 index 00000000..5cb65a73 --- /dev/null +++ b/Boards/M5stackStickCPlus/Source/devices/SdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include "Tactility/hal/sdcard/SdCardDevice.h" + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Boards/M5stackStickCPlus2/CMakeLists.txt b/Boards/M5stackStickCPlus2/CMakeLists.txt new file mode 100644 index 00000000..b2553f94 --- /dev/null +++ b/Boards/M5stackStickCPlus2/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE SOURCE_FILES Source/*.c*) + +idf_component_register( + SRCS ${SOURCE_FILES} + INCLUDE_DIRS "Source" + REQUIRES Tactility esp_lvgl_port ILI934x FT5x06 AXP2101 AW9523 driver vfs fatfs +) diff --git a/Boards/M5stackStickCPlus2/README.md b/Boards/M5stackStickCPlus2/README.md new file mode 100644 index 00000000..e1381612 --- /dev/null +++ b/Boards/M5stackStickCPlus2/README.md @@ -0,0 +1,7 @@ +# M5Stack CoreS3 + +Reference implementations: +- [ESP-BSP](https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_s3) + +Docs: +- [M5Stack.com](https://docs.m5stack.com/en/core/CoreS3) diff --git a/Boards/M5stackStickCPlus2/Source/InitBoot.cpp b/Boards/M5stackStickCPlus2/Source/InitBoot.cpp new file mode 100644 index 00000000..956ab56f --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/InitBoot.cpp @@ -0,0 +1,153 @@ +#include "InitBoot.h" + +#include +#include + +constexpr auto* TAG = "CoreS3"; + +std::shared_ptr axp2101; +std::shared_ptr aw9523; + +/** + * 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, "AW9523 init"); + + /** + * 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 + p0_state |= (1U); + // Bus out enable + p0_state |= (1U << 1U); + // I2S + p0_state |= (1U << 2U); + // SD card + p0_state |= (1U << 4U); + + // Enable LCD + p1_state |= (1U << 1U); + // Boost enable + p1_state |= (1U << 7U); + + /* AW9523 P0 is in push-pull mode */ + if (!aw9523->writeCTL(0x10)) { + TT_LOG_E(TAG, "AW9523: Failed to set CTL"); + return false; + } + + if (!aw9523->writeP0(p0_state)) { + TT_LOG_E(TAG, "AW9523: Failed to set P0"); + return false; + } + + if (!aw9523->writeP1(p1_state)) { + TT_LOG_E(TAG, "AW9523: Failed to set P1"); + return false; + } + + if (axp2101->isVBus()) { + float voltage = 0.0f; + axp2101->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 (AXP2101)"); + + // Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L61 + aw9523->bitOnP1(0b10000000); // SY7088 boost enable + + /** AXP2101 usage + Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/README.md?plain=1#L223 + | |M5Stack
CoreS3
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.275V,25mV/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) + }; + + if (axp2101->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; + } +} + +bool initBoot() { + TT_LOG_I(TAG, "initBoot()"); + + axp2101 = std::make_shared(I2C_NUM_0); + aw9523 = std::make_shared(I2C_NUM_0); + + return initPowerControl() && initGpioExpander(); +} \ No newline at end of file diff --git a/Boards/M5stackStickCPlus2/Source/InitBoot.h b/Boards/M5stackStickCPlus2/Source/InitBoot.h new file mode 100644 index 00000000..70156960 --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/InitBoot.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern std::shared_ptr axp2101; +extern std::shared_ptr aw9523; + +bool initBoot(); diff --git a/Boards/M5stackStickCPlus2/Source/M5stackCoreS3.cpp b/Boards/M5stackStickCPlus2/Source/M5stackCoreS3.cpp new file mode 100644 index 00000000..dc843a52 --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/M5stackCoreS3.cpp @@ -0,0 +1,193 @@ +#include "M5stackCoreS3.h" +#include "InitBoot.h" +#include "devices/Display.h" +#include "devices/SdCard.h" + +#include +#include +#include + +#define CORES3_TRANSACTION_SIZE (CORES3_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8) + +using namespace tt::hal; + +static DeviceVector createDevices() { + return { + axp2101, + aw9523, + std::make_shared(axp2101), + createSdCard(), + createDisplay() + }; +} + +const Configuration m5stack_cores3 = { + .initBoot = initBoot, + .createDevices = createDevices, + .i2c = { + i2c::Configuration { + .name = "Internal", + .port = I2C_NUM_0, + .initMode = i2c::InitMode::ByTactility, + .isMutable = false, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_12, + .scl_io_num = GPIO_NUM_11, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + }, + i2c::Configuration { + .name = "Port A", // Grove + .port = I2C_NUM_1, + .initMode = i2c::InitMode::Disabled, + .isMutable = true, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_2, + .scl_io_num = GPIO_NUM_1, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + }, + i2c::Configuration { + .name = "Port B", // Grove + .port = I2C_NUM_1, + .initMode = i2c::InitMode::Disabled, + .isMutable = true, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_9, + .scl_io_num = GPIO_NUM_8, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + }, + i2c::Configuration { + .name = "Port C", // Grove + .port = I2C_NUM_1, + .initMode = i2c::InitMode::Disabled, + .isMutable = true, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_18, + .scl_io_num = GPIO_NUM_17, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + } + }, + .spi { + spi::Configuration { + .device = SPI3_HOST, + .dma = SPI_DMA_CH_AUTO, + .config = { + .mosi_io_num = GPIO_NUM_37, + .miso_io_num = GPIO_NUM_35, + .sclk_io_num = GPIO_NUM_36, + .data2_io_num = GPIO_NUM_NC, + .data3_io_num = GPIO_NUM_NC, + .data4_io_num = GPIO_NUM_NC, + .data5_io_num = GPIO_NUM_NC, + .data6_io_num = GPIO_NUM_NC, + .data7_io_num = GPIO_NUM_NC, + .data_io_default_level = false, + .max_transfer_sz = CORES3_TRANSACTION_SIZE, + .flags = 0, + .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, + .intr_flags = 0 + }, + .initMode = spi::InitMode::ByTactility, + .isMutable = false, + .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display + } + }, + .uart { + uart::Configuration { + .name = "Port A", + .port = UART_NUM_1, + .rxPin = GPIO_NUM_2, + .txPin = GPIO_NUM_1, + .rtsPin = GPIO_NUM_NC, + .ctsPin = GPIO_NUM_NC, + .rxBufferSize = 1024, + .txBufferSize = 1024, + .config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0, + } + } + }, + uart::Configuration { + .name = "Port B", + .port = UART_NUM_1, + .rxPin = GPIO_NUM_9, + .txPin = GPIO_NUM_8, + .rtsPin = GPIO_NUM_NC, + .ctsPin = GPIO_NUM_NC, + .rxBufferSize = 1024, + .txBufferSize = 1024, + .config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0, + } + } + }, + uart::Configuration { + .name = "Port C", + .port = UART_NUM_1, + .rxPin = GPIO_NUM_18, + .txPin = GPIO_NUM_17, + .rtsPin = GPIO_NUM_NC, + .ctsPin = GPIO_NUM_NC, + .rxBufferSize = 1024, + .txBufferSize = 1024, + .config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0, + } + } + } + } +}; diff --git a/Boards/M5stackStickCPlus2/Source/M5stackCoreS3.h b/Boards/M5stackStickCPlus2/Source/M5stackCoreS3.h new file mode 100644 index 00000000..120c7697 --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/M5stackCoreS3.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +extern const tt::hal::Configuration m5stack_cores3; diff --git a/Boards/M5stackStickCPlus2/Source/devices/Display.cpp b/Boards/M5stackStickCPlus2/Source/devices/Display.cpp new file mode 100644 index 00000000..42105e71 --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/devices/Display.cpp @@ -0,0 +1,51 @@ +#include "Display.h" + +#include +#include +#include +#include +#include + +constexpr auto* TAG = "CoreS3Display"; + +static void setBacklightDuty(uint8_t backlightDuty) { + const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark + // TODO: Refactor to use Axp2102 driver subproject. Reference: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42 + 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"); + } +} + +static std::shared_ptr createTouch() { + // Note for future changes: Reset pin is 48 and interrupt pin is 47 + auto configuration = std::make_unique( + I2C_NUM_0, + 320, + 240 + ); + + auto touch = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(touch); +} + +std::shared_ptr createDisplay() { + auto touch = createTouch(); + + auto configuration = std::make_unique( + SPI3_HOST, + GPIO_NUM_3, + GPIO_NUM_35, + 320, + 240, + touch, + false, + false, + false, + true + ); + + configuration->backlightDutyFunction = ::setBacklightDuty; + + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); +} diff --git a/Boards/M5stackStickCPlus2/Source/devices/Display.h b/Boards/M5stackStickCPlus2/Source/devices/Display.h new file mode 100644 index 00000000..b180a5fb --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/devices/Display.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +// Display +#define CORES3_LCD_SPI_HOST SPI3_HOST +#define CORES3_LCD_PIN_CS GPIO_NUM_3 +#define CORES3_LCD_PIN_DC GPIO_NUM_35 +#define CORES3_LCD_HORIZONTAL_RESOLUTION 320 +#define CORES3_LCD_VERTICAL_RESOLUTION 240 +#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) + +std::shared_ptr createDisplay(); diff --git a/Boards/M5stackStickCPlus2/Source/devices/SdCard.cpp b/Boards/M5stackStickCPlus2/Source/devices/SdCard.cpp new file mode 100644 index 00000000..f314b5f5 --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/devices/SdCard.cpp @@ -0,0 +1,28 @@ +#include "SdCard.h" + +#include +#include + +constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4; +constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3; + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto configuration = std::make_unique( + CORES3_SDCARD_PIN_CS, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + tt::lvgl::getSyncLock(), + std::vector { + CORES3_LCD_PIN_CS + }, + SPI3_HOST + ); + + return std::make_shared( + std::move(configuration) + ); +} diff --git a/Boards/M5stackStickCPlus2/Source/devices/SdCard.h b/Boards/M5stackStickCPlus2/Source/devices/SdCard.h new file mode 100644 index 00000000..5cb65a73 --- /dev/null +++ b/Boards/M5stackStickCPlus2/Source/devices/SdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include "Tactility/hal/sdcard/SdCardDevice.h" + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Drivers/AXP192/CMakeLists.txt b/Drivers/AXP192/CMakeLists.txt new file mode 100644 index 00000000..afcd06ed --- /dev/null +++ b/Drivers/AXP192/CMakeLists.txt @@ -0,0 +1,8 @@ +file(GLOB_RECURSE SOURCE_FILES Source/*.c*) + +idf_component_register( + SRCS ${SOURCE_FILES} + INCLUDE_DIRS "Include" + PRIV_INCLUDE_DIRS "Private" + REQUIRES Tactility +) diff --git a/Drivers/AXP192/Include/Axp192.h b/Drivers/AXP192/Include/Axp192.h new file mode 100644 index 00000000..138a001f --- /dev/null +++ b/Drivers/AXP192/Include/Axp192.h @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include + +#include + +class Axp192 final : public tt::hal::power::PowerDevice { + + static int32_t i2cRead(void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size); + static int32_t i2cWrite(void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size); + +public: + + struct Configuration { + i2c_port_t port; + TickType_t readTimeout = 50 / portTICK_PERIOD_MS; + TickType_t writeTimeout = 50 / portTICK_PERIOD_MS; + }; + +private: + + std::unique_ptr configuration; + + axp192_t axpDevice = { + .read = i2cRead, + .write = i2cWrite, + .handle = this + }; + + bool isInitialized = false; + +public: + + explicit Axp192(std::unique_ptr configuration) : configuration(std::move(configuration)) {} + ~Axp192() override {} + + /** + * @warning Must call this function before device can operate! + * @param onInit + */ + bool init(const std::function& onInit) { + isInitialized = onInit(&axpDevice); + return isInitialized; + } + + std::string getName() const override { return "AXP192"; } + std::string getDescription() const override { return "AXP192 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; +}; diff --git a/Boards/M5stackCore2/Source/axp192/axp192.h b/Drivers/AXP192/Include/axp192/axp192.h similarity index 100% rename from Boards/M5stackCore2/Source/axp192/axp192.h rename to Drivers/AXP192/Include/axp192/axp192.h diff --git a/Boards/M5stackCore2/Source/axp192/LICENSE b/Drivers/AXP192/Private/axp192/LICENSE similarity index 100% rename from Boards/M5stackCore2/Source/axp192/LICENSE rename to Drivers/AXP192/Private/axp192/LICENSE diff --git a/Boards/M5stackCore2/Source/axp192/README.md b/Drivers/AXP192/Private/axp192/README.md similarity index 100% rename from Boards/M5stackCore2/Source/axp192/README.md rename to Drivers/AXP192/Private/axp192/README.md diff --git a/Boards/M5stackCore2/Source/axp192/axp192_config.h b/Drivers/AXP192/Private/axp192/axp192_config.h similarity index 100% rename from Boards/M5stackCore2/Source/axp192/axp192_config.h rename to Drivers/AXP192/Private/axp192/axp192_config.h diff --git a/Drivers/AXP192/README.md b/Drivers/AXP192/README.md new file mode 100644 index 00000000..91aca586 --- /dev/null +++ b/Drivers/AXP192/README.md @@ -0,0 +1,5 @@ +# AXP192 + +Power management with I2C interface. Used on M5Stack Core2 and StickCPlus. + +It includes driver code from https://github.com/tuupola/axp192, Copyright (c) 2019-2021 Mika Tuupola, MIT License diff --git a/Drivers/AXP192/Source/Axp192.cpp b/Drivers/AXP192/Source/Axp192.cpp new file mode 100644 index 00000000..aa3a60b6 --- /dev/null +++ b/Drivers/AXP192/Source/Axp192.cpp @@ -0,0 +1,117 @@ +#include "Axp192.h" + +constexpr auto TAG = "Axp192Power"; + +int32_t Axp192::i2cRead(void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) { + const auto* device = static_cast(handle); + if (tt::hal::i2c::masterReadRegister(device->configuration->port, address, reg, buffer, size, device->configuration->readTimeout)) { + return AXP192_OK; + } else { + return 1; + } +} + +int32_t Axp192::i2cWrite(void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) { + const auto* device = static_cast(handle); + if (tt::hal::i2c::masterWriteRegister(device->configuration->port, address, reg, buffer, size, device->configuration->writeTimeout)) { + return AXP192_OK; + } else { + return 1; + } +} + +bool Axp192::supportsMetric(MetricType type) const { + if (!isInitialized) { + return false; + } + + switch (type) { + using enum MetricType; + case BatteryVoltage: + case ChargeLevel: + case IsCharging: + return true; + default: + return false; + } +} + +bool Axp192::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 Axp192::isAllowedToCharge() const { + uint8_t buffer; + if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) { + return buffer & 0x80; + } else { + return false; + } +} + +void Axp192::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); + } +} diff --git a/Boards/M5stackCore2/Source/axp192/axp192.c b/Drivers/AXP192/Source/axp192/axp192.c similarity index 99% rename from Boards/M5stackCore2/Source/axp192/axp192.c rename to Drivers/AXP192/Source/axp192/axp192.c index 04a3f0d8..25790b54 100644 --- a/Boards/M5stackCore2/Source/axp192/axp192.c +++ b/Drivers/AXP192/Source/axp192/axp192.c @@ -35,8 +35,8 @@ Version: 0.6.0 #include #include -#include "axp192_config.h" -#include "axp192.h" +#include "axp192/axp192_config.h" +#include "axp192/axp192.h" static axp192_err_t read_coloumb_counter(const axp192_t *axp, float *buffer); static axp192_err_t read_battery_power(const axp192_t *axp, float *buffer); diff --git a/sdkconfig.board.m5stack-stickc-plus b/sdkconfig.board.m5stack-stickc-plus new file mode 100644 index 00000000..14930da0 --- /dev/null +++ b/sdkconfig.board.m5stack-stickc-plus @@ -0,0 +1,60 @@ +# Software defaults +# Increase stack size for WiFi (fixes crash after scan) +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=3072 +CONFIG_LV_FONT_MONTSERRAT_14=y +CONFIG_LV_FONT_MONTSERRAT_18=y +CONFIG_LV_USE_USER_DATA=y +CONFIG_LV_USE_FS_STDIO=y +CONFIG_LV_FS_STDIO_LETTER=65 +CONFIG_LV_FS_STDIO_PATH="" +CONFIG_LV_FS_STDIO_CACHE_SIZE=4096 +CONFIG_LV_USE_LODEPNG=y +CONFIG_LV_USE_BUILTIN_MALLOC=n +CONFIG_LV_USE_CLIB_MALLOC=y +CONFIG_LV_USE_MSGBOX=n +CONFIG_LV_USE_SPINNER=n +CONFIG_LV_USE_WIN=n +CONFIG_LV_USE_SNAPSHOT=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 +CONFIG_FREERTOS_SMP=n +CONFIG_FREERTOS_UNICORE=n +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=5120 +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FATFS_LFN_HEAP=y +CONFIG_FATFS_VOLUME_COUNT=3 +CONFIG_FATFS_SECTOR_512=y +CONFIG_WL_SECTOR_SIZE_512=y +CONFIG_WL_SECTOR_SIZE=512 +CONFIG_WL_SECTOR_MODE_SAFE=y +CONFIG_WL_SECTOR_MODE=1 + +# Hardware: Main +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16mb.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions-16mb.csv" +CONFIG_TT_BOARD_M5STACK_CORE2=y +CONFIG_TT_BOARD_NAME="M5Stack Core2" +CONFIG_TT_BOARD_ID="m5stack-core2" +CONFIG_IDF_EXPERIMENTAL_FEATURES=y +CONFIG_IDF_TARGET="esp32" +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_FLASHMODE_QIO=y +# Hardware: SPI RAM +CONFIG_ESP32_SPIRAM_SUPPORT=y +CONFIG_SPIRAM=y +CONFIG_SPIRAM_MODE_QUAD=y +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +# LVGL +CONFIG_LV_DISP_DEF_REFR_PERIOD=10 +CONFIG_LV_DPI_DEF=139 +CONFIG_LV_THEME_DEFAULT_DARK=y +# Fix for IRAM +CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y +CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y +CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y +CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y diff --git a/sdkconfig.board.m5stack-stickc-plus2 b/sdkconfig.board.m5stack-stickc-plus2 new file mode 100644 index 00000000..2b2f8341 --- /dev/null +++ b/sdkconfig.board.m5stack-stickc-plus2 @@ -0,0 +1,59 @@ +# Software defaults +# Increase stack size for WiFi (fixes crash after scan) +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=3072 +CONFIG_LV_FONT_MONTSERRAT_14=y +CONFIG_LV_FONT_MONTSERRAT_18=y +CONFIG_LV_USE_USER_DATA=y +CONFIG_LV_USE_FS_STDIO=y +CONFIG_LV_FS_STDIO_LETTER=65 +CONFIG_LV_FS_STDIO_PATH="" +CONFIG_LV_FS_STDIO_CACHE_SIZE=4096 +CONFIG_LV_USE_LODEPNG=y +CONFIG_LV_USE_BUILTIN_MALLOC=n +CONFIG_LV_USE_CLIB_MALLOC=y +CONFIG_LV_USE_MSGBOX=n +CONFIG_LV_USE_SPINNER=n +CONFIG_LV_USE_WIN=n +CONFIG_LV_USE_SNAPSHOT=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 +CONFIG_FREERTOS_SMP=n +CONFIG_FREERTOS_UNICORE=n +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=5120 +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FATFS_LFN_HEAP=y +CONFIG_FATFS_VOLUME_COUNT=3 +CONFIG_FATFS_SECTOR_512=y +CONFIG_WL_SECTOR_SIZE_512=y +CONFIG_WL_SECTOR_SIZE=512 +CONFIG_WL_SECTOR_MODE_SAFE=y +CONFIG_WL_SECTOR_MODE=1 + +# Hardware: Main +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16mb.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions-16mb.csv" +CONFIG_TT_BOARD_LILYGO_TDECK=y +CONFIG_TT_BOARD_NAME="LilyGo T-Deck" +CONFIG_TT_BOARD_ID="lilygo-tdeck" +CONFIG_IDF_EXPERIMENTAL_FEATURES=y +CONFIG_IDF_TARGET="esp32s3" +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y +CONFIG_FLASHMODE_QIO=y +# Hardware: SPI RAM +CONFIG_ESP32S3_SPIRAM_SUPPORT=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_SPEED_120M=y +CONFIG_SPIRAM_USE_MALLOC=y +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +# SPI Flash (can set back to 80MHz after ESP-IDF bug is resolved) +CONFIG_ESPTOOLPY_FLASHFREQ_120M=y +# LVGL +CONFIG_LV_DPI_DEF=139 +CONFIG_LV_DISP_DEF_REFR_PERIOD=10 +CONFIG_LV_THEME_DEFAULT_DARK=y +# USB +CONFIG_TINYUSB_MSC_ENABLED=y +CONFIG_TINYUSB_MSC_MOUNT_PATH="/sdcard" \ No newline at end of file