From 1627b9fa853e5dd5ef67d3f2e39d97fc7d222c6b Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Wed, 3 Sep 2025 22:05:28 +0200 Subject: [PATCH] Merge develop into main (#316) - Updated all boards to use `hal::Configuration.createDevices` - Updated all boards to use new directory structure and file naming convention - Refactored `Xpt2046SoftSpi` driver. - Created `Axp2101Power` device in `Drivers/AXP2101` - Removed global static instances from some drivers (instances that kept a reference to the Device*) - Improved `SystemInfoApp` UI: better memory labels, hide external memory bar when there's no PSRAM - Fix for HAL: register touch devices after displays are registered - Fix for Boot splash hanging on WiFi init: unlock file lock after using it --- Boards/CYD-2432S024C/Source/CYD2432S024C.cpp | 18 +- .../YellowDisplay.cpp => devices/Display.cpp} | 3 +- .../Display.h} | 4 + .../YellowSdCard.cpp => devices/SdCard.cpp} | 4 +- .../Source/devices/SdCard.h} | 0 .../CYD-2432S024C/Source/hal/YellowDisplay.h | 6 - .../CYD-2432S024C/Source/hal/YellowSdCard.h | 8 - .../Source/hal/YellowTouchConstants.h | 5 - Boards/CYD-2432S028R/Source/CYD2432S028R.cpp | 29 ++-- .../YellowDisplay.cpp => devices/Display.cpp} | 16 +- .../YellowConstants.h => devices/Display.h} | 15 +- .../CYD-2432S028R/Source/devices/SdCard.cpp | 21 +++ .../Source/devices/SdCard.h} | 0 .../CYD-2432S028R/Source/hal/YellowDisplay.h | 6 - .../CYD-2432S028R/Source/hal/YellowSdCard.cpp | 26 --- .../CYD-2432S028R/Source/hal/YellowSdCard.h | 8 - Boards/CYD-2432S032C/Source/CYD2432S032C.cpp | 15 +- .../CydDisplay.cpp => devices/Display.cpp} | 2 +- .../Source/devices/Display.h} | 1 + .../Source/devices/SdCard.cpp} | 6 +- Boards/CYD-2432S032C/Source/devices/SdCard.h | 8 + Boards/CYD-2432S032C/Source/hal/CydDisplay.h | 6 - Boards/CYD-4848S040C/Source/CYD4848S040C.cpp | 17 +- .../{hal/CydSdCard.cpp => devices/SdCard.cpp} | 2 +- .../Source/devices/SdCard.h} | 1 + .../St7701Display.cpp} | 21 +-- .../CydDisplay.h => devices/St7701Display.h} | 6 +- Boards/CYD-8048S043C/Source/CYD8048S043C.cpp | 26 +-- .../CydDisplay.cpp => devices/Display.cpp} | 2 +- .../{hal/CydDisplay.h => devices/Display.h} | 0 .../{hal/CydSdCard.cpp => devices/SdCard.cpp} | 2 +- .../{hal/CydSdCard.h => devices/SdCard.h} | 0 Boards/CYD-JC2432W328C/Source/JC2432W328C.cpp | 21 ++- .../YellowDisplay.cpp => devices/Display.cpp} | 7 +- .../Display.h} | 4 + .../Source/devices/SdCard.cpp} | 6 +- .../Source/devices/SdCard.h} | 1 + .../Source/hal/YellowDisplay.h | 6 - .../CYD-JC2432W328C/Source/hal/YellowSdCard.h | 8 - Boards/CYD-JC8048W550C/Source/JC8048W550C.cpp | 17 +- .../CydDisplay.cpp => devices/Display.cpp} | 7 +- .../Source/devices/Display.h} | 0 .../{hal/CydSdCard.cpp => devices/SdCard.cpp} | 2 +- .../CYD-JC8048W550C/Source/devices/SdCard.h | 7 + .../Source/CrowPanelAdvance28.cpp | 17 +- .../Display.cpp} | 13 +- .../Display.h} | 4 + .../SdCard.cpp} | 4 +- .../Source/devices/SdCard.h} | 0 .../Source/CrowPanelAdvance35.cpp | 17 +- .../Display.cpp} | 5 +- .../Display.h} | 4 + .../SdCard.cpp} | 4 +- .../Source/devices/SdCard.h} | 0 .../Source/CrowPanelAdvance50.cpp | 16 +- .../Display.cpp} | 2 +- .../Source/devices/Display.h} | 0 .../SdCard.cpp} | 4 +- .../Source/devices/SdCard.h | 7 + .../Source/CrowPanelBasic28.cpp | 21 ++- .../Display.cpp} | 3 +- .../Display.h} | 4 + .../Source/devices/SdCard.cpp} | 2 +- .../Source/devices/SdCard.h} | 0 .../Source/hal/CrowPanelDisplay.h | 5 - .../Source/CrowPanelBasic35.cpp | 21 ++- .../Display.cpp} | 19 +-- .../Display.h} | 4 + .../Source/devices/SdCard.cpp} | 4 +- .../Source/devices/SdCard.h} | 0 .../Source/CrowPanelBasic50.cpp | 17 +- .../Display.cpp} | 2 +- .../Source/devices/Display.h} | 0 .../Source/devices/SdCard.cpp} | 2 +- .../Source/devices/SdCard.h | 7 + .../Source/LilygoTloraPager.cpp | 15 +- .../TpagerDisplay.cpp => devices/Display.cpp} | 10 +- .../Source/devices/Display.h} | 0 .../TpagerSdCard.cpp => devices/SdCard.cpp} | 2 +- .../{hal/TpagerSdCard.h => devices/SdCard.h} | 0 .../Source/{hal => devices}/TpagerEncoder.cpp | 2 +- .../Source/{hal => devices}/TpagerEncoder.h | 4 +- .../{hal => devices}/TpagerKeyboard.cpp | 0 .../Source/{hal => devices}/TpagerKeyboard.h | 0 .../Source/{hal => devices}/TpagerPower.cpp | 0 .../Source/{hal => devices}/TpagerPower.h | 0 .../Source/hal/TpagerDisplay.h | 5 - .../Source/hal/TpagerDisplayConstants.h | 8 - Boards/M5stackCore2/Source/InitBoot.cpp | 2 +- Boards/M5stackCore2/Source/M5stackCore2.cpp | 32 ++-- .../Source/{hal => devices}/Core2Power.cpp | 2 - .../Source/{hal => devices}/Core2Power.h | 0 .../Core2Display.cpp => devices/Display.cpp} | 2 +- .../{hal/Core2Display.h => devices/Display.h} | 0 .../Core2SdCard.cpp => devices/SdCard.cpp} | 8 +- .../Source/devices/SdCard.h} | 0 Boards/M5stackCoreS3/CMakeLists.txt | 4 +- Boards/M5stackCoreS3/Source/CoreS3Constants.h | 4 - Boards/M5stackCoreS3/Source/InitBoot.cpp | 7 +- Boards/M5stackCoreS3/Source/InitBoot.h | 6 + Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp | 21 ++- .../CoreS3Display.cpp => devices/Display.cpp} | 6 +- .../Display.h} | 4 + .../CoreS3SdCard.cpp => devices/SdCard.cpp} | 4 +- .../Source/devices/SdCard.h} | 0 .../M5stackCoreS3/Source/hal/CoreS3Display.h | 5 - .../Source/{PowerOn.cpp => InitBoot.cpp} | 7 +- Boards/UnPhone/Source/UnPhone.cpp | 21 ++- .../Hx8357Display.cpp} | 24 ++- .../Hx8357Display.h} | 18 +- .../UnPhoneSdCard.cpp => devices/SdCard.cpp} | 6 +- .../Source/devices/SdCard.h} | 0 .../UnPhoneTouch.cpp => devices/Touch.cpp} | 5 +- .../{hal/UnPhoneTouch.h => devices/Touch.h} | 0 .../Source/hal/UnPhoneDisplayConstants.h | 11 -- Boards/UnPhone/Source/hal/UnPhoneSdCard.h | 7 - .../Source/WaveshareS3Touch43.cpp | 14 +- .../Display.cpp} | 2 +- .../Source/devices/Display.h} | 0 .../Source/devices/SdCard.cpp} | 5 +- .../Source/devices/SdCard.h} | 0 .../Source/hal/WaveshareDisplay.h | 5 - Documentation/ideas.md | 7 +- Drivers/AXP2101/Source/Axp2101.h | 4 +- .../AXP2101/Source/Axp2101Power.cpp | 21 +-- .../AXP2101/Source/Axp2101Power.h | 12 +- Drivers/XPT2046/Source/Xpt2046Power.cpp | 10 -- Drivers/XPT2046/Source/Xpt2046Power.h | 5 +- Drivers/XPT2046/Source/Xpt2046Touch.cpp | 3 - Drivers/XPT2046/Source/Xpt2046Touch.h | 2 - .../XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp | 155 ++++++++---------- .../XPT2046SoftSPI/Source/Xpt2046SoftSpi.h | 20 +-- .../Source/app/systeminfo/SystemInfo.cpp | 6 +- Tactility/Source/hal/Hal.cpp | 12 ++ .../service/wifi/WifiBootSplashInit.cpp | 7 +- 135 files changed, 543 insertions(+), 577 deletions(-) rename Boards/CYD-2432S024C/Source/{hal/YellowDisplay.cpp => devices/Display.cpp} (94%) rename Boards/CYD-2432S024C/Source/{hal/YellowDisplayConstants.h => devices/Display.h} (78%) rename Boards/CYD-2432S024C/Source/{hal/YellowSdCard.cpp => devices/SdCard.cpp} (88%) rename Boards/{CYD-2432S032C/Source/hal/CydSdCard.h => CYD-2432S024C/Source/devices/SdCard.h} (100%) delete mode 100644 Boards/CYD-2432S024C/Source/hal/YellowDisplay.h delete mode 100644 Boards/CYD-2432S024C/Source/hal/YellowSdCard.h delete mode 100644 Boards/CYD-2432S024C/Source/hal/YellowTouchConstants.h rename Boards/CYD-2432S028R/Source/{hal/YellowDisplay.cpp => devices/Display.cpp} (76%) rename Boards/CYD-2432S028R/Source/{hal/YellowConstants.h => devices/Display.h} (63%) create mode 100644 Boards/CYD-2432S028R/Source/devices/SdCard.cpp rename Boards/{CYD-4848S040C/Source/hal/CydSdCard.h => CYD-2432S028R/Source/devices/SdCard.h} (100%) delete mode 100644 Boards/CYD-2432S028R/Source/hal/YellowDisplay.h delete mode 100644 Boards/CYD-2432S028R/Source/hal/YellowSdCard.cpp delete mode 100644 Boards/CYD-2432S028R/Source/hal/YellowSdCard.h rename Boards/CYD-2432S032C/Source/{hal/CydDisplay.cpp => devices/Display.cpp} (97%) rename Boards/{ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h => CYD-2432S032C/Source/devices/Display.h} (87%) rename Boards/{CYD-JC2432W328C/Source/hal/YellowSdCard.cpp => CYD-2432S032C/Source/devices/SdCard.cpp} (84%) create mode 100644 Boards/CYD-2432S032C/Source/devices/SdCard.h delete mode 100644 Boards/CYD-2432S032C/Source/hal/CydDisplay.h rename Boards/CYD-4848S040C/Source/{hal/CydSdCard.cpp => devices/SdCard.cpp} (95%) rename Boards/{WaveshareS3Touch43/Source/hal/WaveshareSdCard.h => CYD-4848S040C/Source/devices/SdCard.h} (99%) rename Boards/CYD-4848S040C/Source/{hal/CydDisplay.cpp => devices/St7701Display.cpp} (89%) rename Boards/CYD-4848S040C/Source/{hal/CydDisplay.h => devices/St7701Display.h} (83%) rename Boards/CYD-8048S043C/Source/{hal/CydDisplay.cpp => devices/Display.cpp} (99%) rename Boards/CYD-8048S043C/Source/{hal/CydDisplay.h => devices/Display.h} (100%) rename Boards/CYD-8048S043C/Source/{hal/CydSdCard.cpp => devices/SdCard.cpp} (95%) rename Boards/CYD-8048S043C/Source/{hal/CydSdCard.h => devices/SdCard.h} (100%) rename Boards/CYD-JC2432W328C/Source/{hal/YellowDisplay.cpp => devices/Display.cpp} (92%) rename Boards/CYD-JC2432W328C/Source/{hal/YellowDisplayConstants.h => devices/Display.h} (79%) rename Boards/{CYD-2432S032C/Source/hal/CydSdCard.cpp => CYD-JC2432W328C/Source/devices/SdCard.cpp} (84%) rename Boards/{M5stackCoreS3/Source/hal/CoreS3SdCard.h => CYD-JC2432W328C/Source/devices/SdCard.h} (99%) delete mode 100644 Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.h delete mode 100644 Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.h rename Boards/CYD-JC8048W550C/Source/{hal/CydDisplay.cpp => devices/Display.cpp} (98%) rename Boards/{ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplay.h => CYD-JC8048W550C/Source/devices/Display.h} (100%) rename Boards/CYD-JC8048W550C/Source/{hal/CydSdCard.cpp => devices/SdCard.cpp} (96%) create mode 100644 Boards/CYD-JC8048W550C/Source/devices/SdCard.h rename Boards/ElecrowCrowpanelAdvance28/Source/{hal/CrowPanelDisplay.cpp => devices/Display.cpp} (89%) rename Boards/ElecrowCrowpanelAdvance28/Source/{hal/CrowPanelDisplayConstants.h => devices/Display.h} (73%) rename Boards/ElecrowCrowpanelAdvance28/Source/{hal/CrowPanelSdCard.cpp => devices/SdCard.cpp} (91%) rename Boards/{CYD-JC8048W550C/Source/hal/CydSdCard.h => ElecrowCrowpanelAdvance28/Source/devices/SdCard.h} (100%) rename Boards/ElecrowCrowpanelAdvance35/Source/{hal/CrowPanelDisplay.cpp => devices/Display.cpp} (91%) rename Boards/ElecrowCrowpanelAdvance35/Source/{hal/CrowPanelDisplayConstants.h => devices/Display.h} (73%) rename Boards/ElecrowCrowpanelAdvance35/Source/{hal/CrowPanelSdCard.cpp => devices/SdCard.cpp} (91%) rename Boards/{ElecrowCrowpanelAdvance28/Source/hal/CrowPanelSdCard.h => ElecrowCrowpanelAdvance35/Source/devices/SdCard.h} (100%) rename Boards/ElecrowCrowpanelAdvance50/Source/{hal/CrowPanelDisplay.cpp => devices/Display.cpp} (99%) rename Boards/{ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplay.h => ElecrowCrowpanelAdvance50/Source/devices/Display.h} (100%) rename Boards/ElecrowCrowpanelAdvance50/Source/{hal/CrowPanelSdCard.cpp => devices/SdCard.cpp} (92%) create mode 100644 Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.h rename Boards/ElecrowCrowpanelBasic28/Source/{hal/CrowPanelDisplay.cpp => devices/Display.cpp} (93%) rename Boards/ElecrowCrowpanelBasic28/Source/{hal/CrowPanelDisplayConstants.h => devices/Display.h} (75%) rename Boards/{ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp => ElecrowCrowpanelBasic28/Source/devices/SdCard.cpp} (95%) rename Boards/{ElecrowCrowpanelAdvance35/Source/hal/CrowPanelSdCard.h => ElecrowCrowpanelBasic28/Source/devices/SdCard.h} (100%) delete mode 100644 Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.h rename Boards/ElecrowCrowpanelBasic35/Source/{hal/CrowPanelDisplay.cpp => devices/Display.cpp} (74%) rename Boards/ElecrowCrowpanelBasic35/Source/{hal/CrowPanelDisplayConstants.h => devices/Display.h} (75%) rename Boards/{ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.cpp => ElecrowCrowpanelBasic35/Source/devices/SdCard.cpp} (90%) rename Boards/{ElecrowCrowpanelAdvance50/Source/hal/CrowPanelSdCard.h => ElecrowCrowpanelBasic35/Source/devices/SdCard.h} (100%) rename Boards/ElecrowCrowpanelBasic50/Source/{hal/CrowPanelDisplay.cpp => devices/Display.cpp} (99%) rename Boards/{ElecrowCrowpanelAdvance50/Source/hal/CrowPanelDisplay.h => ElecrowCrowpanelBasic50/Source/devices/Display.h} (100%) rename Boards/{WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp => ElecrowCrowpanelBasic50/Source/devices/SdCard.cpp} (93%) create mode 100644 Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.h rename Boards/LilygoTLoraPager/Source/{hal/TpagerDisplay.cpp => devices/Display.cpp} (70%) rename Boards/{ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h => LilygoTLoraPager/Source/devices/Display.h} (100%) rename Boards/LilygoTLoraPager/Source/{hal/TpagerSdCard.cpp => devices/SdCard.cpp} (96%) rename Boards/LilygoTLoraPager/Source/{hal/TpagerSdCard.h => devices/SdCard.h} (100%) rename Boards/LilygoTLoraPager/Source/{hal => devices}/TpagerEncoder.cpp (98%) rename Boards/LilygoTLoraPager/Source/{hal => devices}/TpagerEncoder.h (91%) rename Boards/LilygoTLoraPager/Source/{hal => devices}/TpagerKeyboard.cpp (100%) rename Boards/LilygoTLoraPager/Source/{hal => devices}/TpagerKeyboard.h (100%) rename Boards/LilygoTLoraPager/Source/{hal => devices}/TpagerPower.cpp (100%) rename Boards/LilygoTLoraPager/Source/{hal => devices}/TpagerPower.h (100%) delete mode 100644 Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h delete mode 100644 Boards/LilygoTLoraPager/Source/hal/TpagerDisplayConstants.h rename Boards/M5stackCore2/Source/{hal => devices}/Core2Power.cpp (97%) rename Boards/M5stackCore2/Source/{hal => devices}/Core2Power.h (100%) rename Boards/M5stackCore2/Source/{hal/Core2Display.cpp => devices/Display.cpp} (97%) rename Boards/M5stackCore2/Source/{hal/Core2Display.h => devices/Display.h} (100%) rename Boards/M5stackCore2/Source/{hal/Core2SdCard.cpp => devices/SdCard.cpp} (82%) rename Boards/{ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.h => M5stackCore2/Source/devices/SdCard.h} (100%) delete mode 100644 Boards/M5stackCoreS3/Source/CoreS3Constants.h rename Boards/M5stackCoreS3/Source/{hal/CoreS3Display.cpp => devices/Display.cpp} (94%) rename Boards/M5stackCoreS3/Source/{hal/CoreS3DisplayConstants.h => devices/Display.h} (77%) rename Boards/M5stackCoreS3/Source/{hal/CoreS3SdCard.cpp => devices/SdCard.cpp} (93%) rename Boards/{ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.h => M5stackCoreS3/Source/devices/SdCard.h} (100%) delete mode 100644 Boards/M5stackCoreS3/Source/hal/CoreS3Display.h rename Boards/UnPhone/Source/{PowerOn.cpp => InitBoot.cpp} (98%) rename Boards/UnPhone/Source/{hal/UnPhoneDisplay.cpp => devices/Hx8357Display.cpp} (82%) rename Boards/UnPhone/Source/{hal/UnPhoneDisplay.h => devices/Hx8357Display.h} (75%) rename Boards/UnPhone/Source/{hal/UnPhoneSdCard.cpp => devices/SdCard.cpp} (87%) rename Boards/{ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.h => UnPhone/Source/devices/SdCard.h} (100%) rename Boards/UnPhone/Source/{hal/UnPhoneTouch.cpp => devices/Touch.cpp} (74%) rename Boards/UnPhone/Source/{hal/UnPhoneTouch.h => devices/Touch.h} (100%) delete mode 100644 Boards/UnPhone/Source/hal/UnPhoneDisplayConstants.h delete mode 100644 Boards/UnPhone/Source/hal/UnPhoneSdCard.h rename Boards/WaveshareS3Touch43/Source/{hal/WaveshareDisplay.cpp => devices/Display.cpp} (98%) rename Boards/{CYD-JC8048W550C/Source/hal/CydDisplay.h => WaveshareS3Touch43/Source/devices/Display.h} (100%) rename Boards/{ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.cpp => WaveshareS3Touch43/Source/devices/SdCard.cpp} (82%) rename Boards/{M5stackCore2/Source/hal/Core2SdCard.h => WaveshareS3Touch43/Source/devices/SdCard.h} (100%) delete mode 100644 Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h rename Boards/M5stackCoreS3/Source/hal/CoreS3Power.cpp => Drivers/AXP2101/Source/Axp2101Power.cpp (78%) rename Boards/M5stackCoreS3/Source/hal/CoreS3Power.h => Drivers/AXP2101/Source/Axp2101Power.h (57%) diff --git a/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp b/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp index 56f6650a..d4daa65b 100644 --- a/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp +++ b/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp @@ -1,22 +1,26 @@ #include "CYD2432S024C.h" -#include "hal/YellowDisplay.h" -#include "hal/YellowDisplayConstants.h" -#include "hal/YellowSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include #include #define CYD_SPI_TRANSFER_SIZE_LIMIT (TWODOTFOUR_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8) -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(TWODOTFOUR_LCD_PIN_BACKLIGHT); } +static tt::hal::DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const tt::hal::Configuration cyd_2432s024c_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createYellowSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = { tt::hal::i2c::Configuration { .name = "First", diff --git a/Boards/CYD-2432S024C/Source/hal/YellowDisplay.cpp b/Boards/CYD-2432S024C/Source/devices/Display.cpp similarity index 94% rename from Boards/CYD-2432S024C/Source/hal/YellowDisplay.cpp rename to Boards/CYD-2432S024C/Source/devices/Display.cpp index b30d7d75..2713e343 100644 --- a/Boards/CYD-2432S024C/Source/hal/YellowDisplay.cpp +++ b/Boards/CYD-2432S024C/Source/devices/Display.cpp @@ -1,6 +1,5 @@ -#include "YellowDisplay.h" +#include "Display.h" #include "Cst816Touch.h" -#include "YellowDisplayConstants.h" #include #include diff --git a/Boards/CYD-2432S024C/Source/hal/YellowDisplayConstants.h b/Boards/CYD-2432S024C/Source/devices/Display.h similarity index 78% rename from Boards/CYD-2432S024C/Source/hal/YellowDisplayConstants.h rename to Boards/CYD-2432S024C/Source/devices/Display.h index 1838914a..7be4a3d3 100644 --- a/Boards/CYD-2432S024C/Source/hal/YellowDisplayConstants.h +++ b/Boards/CYD-2432S024C/Source/devices/Display.h @@ -1,5 +1,8 @@ #pragma once +#include "Tactility/hal/display/DisplayDevice.h" +#include + #define TWODOTFOUR_LCD_PIN_BACKLIGHT GPIO_NUM_27 // Display @@ -11,3 +14,4 @@ #define TWODOTFOUR_LCD_PIN_CS GPIO_NUM_15 #define TWODOTFOUR_LCD_PIN_DC GPIO_NUM_2 +std::shared_ptr createDisplay(); diff --git a/Boards/CYD-2432S024C/Source/hal/YellowSdCard.cpp b/Boards/CYD-2432S024C/Source/devices/SdCard.cpp similarity index 88% rename from Boards/CYD-2432S024C/Source/hal/YellowSdCard.cpp rename to Boards/CYD-2432S024C/Source/devices/SdCard.cpp index ceb4c53e..da3090cc 100644 --- a/Boards/CYD-2432S024C/Source/hal/YellowSdCard.cpp +++ b/Boards/CYD-2432S024C/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "YellowSdCard.h" +#include "SdCard.h" #define TAG "twodotfour_sdcard" @@ -9,7 +9,7 @@ constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; using tt::hal::sdcard::SpiSdCardDevice; -std::shared_ptr createYellowSdCard() { +std::shared_ptr createSdCard() { auto configuration = std::make_unique( SDCARD_PIN_CS, GPIO_NUM_NC, diff --git a/Boards/CYD-2432S032C/Source/hal/CydSdCard.h b/Boards/CYD-2432S024C/Source/devices/SdCard.h similarity index 100% rename from Boards/CYD-2432S032C/Source/hal/CydSdCard.h rename to Boards/CYD-2432S024C/Source/devices/SdCard.h diff --git a/Boards/CYD-2432S024C/Source/hal/YellowDisplay.h b/Boards/CYD-2432S024C/Source/hal/YellowDisplay.h deleted file mode 100644 index 036603c9..00000000 --- a/Boards/CYD-2432S024C/Source/hal/YellowDisplay.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-2432S024C/Source/hal/YellowSdCard.h b/Boards/CYD-2432S024C/Source/hal/YellowSdCard.h deleted file mode 100644 index 772f7119..00000000 --- a/Boards/CYD-2432S024C/Source/hal/YellowSdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createYellowSdCard(); - diff --git a/Boards/CYD-2432S024C/Source/hal/YellowTouchConstants.h b/Boards/CYD-2432S024C/Source/hal/YellowTouchConstants.h deleted file mode 100644 index c2d9c540..00000000 --- a/Boards/CYD-2432S024C/Source/hal/YellowTouchConstants.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -// Touch -#define TWODOTFOUR_TOUCH_I2C_PORT I2C_NUM_0 - diff --git a/Boards/CYD-2432S028R/Source/CYD2432S028R.cpp b/Boards/CYD-2432S028R/Source/CYD2432S028R.cpp index e1a461b1..974af813 100644 --- a/Boards/CYD-2432S028R/Source/CYD2432S028R.cpp +++ b/Boards/CYD-2432S028R/Source/CYD2432S028R.cpp @@ -1,14 +1,18 @@ #include "CYD2432S028R.h" -#include "hal/YellowDisplay.h" -#include "hal/YellowConstants.h" -#include "hal/YellowSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include #include #include +// SPI Transfer +#define CYD_SPI_TRANSFER_SIZE_LIMIT (CYD2432S028R_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8) +// Display backlight (PWM) +#define CYD2432S028R_LCD_PIN_BACKLIGHT GPIO_NUM_21 + using namespace tt::hal; -bool initBoot() { +static bool initBoot() { //Set the RGB Led Pins to output and turn them off ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green @@ -22,16 +26,21 @@ bool initBoot() { return driver::pwmbacklight::init(CYD2432S028R_LCD_PIN_BACKLIGHT); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const Configuration cyd_2432s028r_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createYellowSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = {}, .spi { //Display spi::Configuration { - .device = CYD2432S028R_LCD_SPI_HOST, + .device = SPI2_HOST, .dma = SPI_DMA_CH_AUTO, .config = { .mosi_io_num = GPIO_NUM_13, @@ -56,7 +65,7 @@ const Configuration cyd_2432s028r_config = { // SDCard spi::Configuration { - .device = CYD2432S028R_SDCARD_SPI_HOST, + .device = SPI3_HOST, .dma = SPI_DMA_CH_AUTO, .config = { .mosi_io_num = GPIO_NUM_23, @@ -74,7 +83,7 @@ const Configuration cyd_2432s028r_config = { .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, .intr_flags = 0 }, - .initMode = tt::hal::spi::InitMode::ByTactility, + .initMode = spi::InitMode::ByTactility, .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, diff --git a/Boards/CYD-2432S028R/Source/hal/YellowDisplay.cpp b/Boards/CYD-2432S028R/Source/devices/Display.cpp similarity index 76% rename from Boards/CYD-2432S028R/Source/hal/YellowDisplay.cpp rename to Boards/CYD-2432S028R/Source/devices/Display.cpp index 82534fa5..dea602b6 100644 --- a/Boards/CYD-2432S028R/Source/hal/YellowDisplay.cpp +++ b/Boards/CYD-2432S028R/Source/devices/Display.cpp @@ -1,13 +1,9 @@ -#include "YellowDisplay.h" +#include "Display.h" #include "Xpt2046SoftSpi.h" -#include "YellowConstants.h" #include #include -static const char* TAG = "YellowDisplay"; - -// Global to hold reference (only needed if calling stop() later) -static std::unique_ptr touch; +constexpr auto* TAG = "CYD"; static std::shared_ptr createTouch() { auto configuration = std::make_unique( @@ -23,17 +19,15 @@ static std::shared_ptr createTouch() { ); // Allocate the driver - touch = std::make_unique(std::move(configuration)); + auto touch = std::make_shared(std::move(configuration)); // Start the driver if (!touch->start()) { ESP_LOGE(TAG, "Touch driver start failed"); return nullptr; } - - return std::shared_ptr(touch.get(), [](tt::hal::touch::TouchDevice*) { - // No delete needed; `touch` is managed above - }); + + return touch; } std::shared_ptr createDisplay() { diff --git a/Boards/CYD-2432S028R/Source/hal/YellowConstants.h b/Boards/CYD-2432S028R/Source/devices/Display.h similarity index 63% rename from Boards/CYD-2432S028R/Source/hal/YellowConstants.h rename to Boards/CYD-2432S028R/Source/devices/Display.h index 96aa39d1..1fbc536a 100644 --- a/Boards/CYD-2432S028R/Source/hal/YellowConstants.h +++ b/Boards/CYD-2432S028R/Source/devices/Display.h @@ -1,7 +1,7 @@ #pragma once -// Display backlight (PWM) -#define CYD2432S028R_LCD_PIN_BACKLIGHT GPIO_NUM_21 +#include "Tactility/hal/display/DisplayDevice.h" +#include // Display #define CYD2432S028R_LCD_SPI_HOST SPI2_HOST @@ -12,10 +12,6 @@ #define CYD2432S028R_LCD_PIN_CS GPIO_NUM_15 #define CYD2432S028R_LCD_PIN_DC GPIO_NUM_2 -// Touch -#define CYD2432S028R_TOUCH_SPI_HOST SPI3_HOST -#define CYD2432S028R_TOUCH_PIN_CS GPIO_NUM_33 - // Touch (Software SPI) #define CYD_TOUCH_MISO_PIN GPIO_NUM_39 #define CYD_TOUCH_MOSI_PIN GPIO_NUM_32 @@ -23,9 +19,4 @@ #define CYD_TOUCH_CS_PIN GPIO_NUM_33 #define CYD_TOUCH_IRQ_PIN GPIO_NUM_36 -// SDCard -#define CYD2432S028R_SDCARD_SPI_HOST SPI3_HOST -#define CYD2432S028R_SDCARD_PIN_CS GPIO_NUM_5 - -// SPI Transfer -#define CYD_SPI_TRANSFER_SIZE_LIMIT (CYD2432S028R_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8) +std::shared_ptr createDisplay(); diff --git a/Boards/CYD-2432S028R/Source/devices/SdCard.cpp b/Boards/CYD-2432S028R/Source/devices/SdCard.cpp new file mode 100644 index 00000000..0a4cdba0 --- /dev/null +++ b/Boards/CYD-2432S028R/Source/devices/SdCard.cpp @@ -0,0 +1,21 @@ +#include "SdCard.h" +#include +#include + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto config = std::make_unique( + GPIO_NUM_5, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + std::make_shared(), + std::vector(), + SPI3_HOST + ); + + return std::make_shared(std::move(config)); +} + diff --git a/Boards/CYD-4848S040C/Source/hal/CydSdCard.h b/Boards/CYD-2432S028R/Source/devices/SdCard.h similarity index 100% rename from Boards/CYD-4848S040C/Source/hal/CydSdCard.h rename to Boards/CYD-2432S028R/Source/devices/SdCard.h diff --git a/Boards/CYD-2432S028R/Source/hal/YellowDisplay.h b/Boards/CYD-2432S028R/Source/hal/YellowDisplay.h deleted file mode 100644 index 036603c9..00000000 --- a/Boards/CYD-2432S028R/Source/hal/YellowDisplay.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-2432S028R/Source/hal/YellowSdCard.cpp b/Boards/CYD-2432S028R/Source/hal/YellowSdCard.cpp deleted file mode 100644 index 49c81c3a..00000000 --- a/Boards/CYD-2432S028R/Source/hal/YellowSdCard.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "YellowSdCard.h" -#include "YellowConstants.h" -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createYellowSdCard() { - auto* configuration = new SpiSdCardDevice::Config( - CYD2432S028R_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), - std::vector(), - CYD2432S028R_SDCARD_SPI_HOST - ); - - auto* sdcard = (SdCardDevice*) new SpiSdCardDevice( - std::unique_ptr(configuration) - ); - - return std::shared_ptr(sdcard); -} - diff --git a/Boards/CYD-2432S028R/Source/hal/YellowSdCard.h b/Boards/CYD-2432S028R/Source/hal/YellowSdCard.h deleted file mode 100644 index 772f7119..00000000 --- a/Boards/CYD-2432S028R/Source/hal/YellowSdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createYellowSdCard(); - diff --git a/Boards/CYD-2432S032C/Source/CYD2432S032C.cpp b/Boards/CYD-2432S032C/Source/CYD2432S032C.cpp index f313b2e8..69ffebf1 100644 --- a/Boards/CYD-2432S032C/Source/CYD2432S032C.cpp +++ b/Boards/CYD-2432S032C/Source/CYD2432S032C.cpp @@ -1,7 +1,7 @@ #include "CYD2432S032C.h" #include "Tactility/lvgl/LvglSync.h" -#include "hal/CydDisplay.h" -#include "hal/CydSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include @@ -25,11 +25,16 @@ bool initBoot() { return true; } +static tt::hal::DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const tt::hal::Configuration cyd_2432S032c_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = { tt::hal::i2c::Configuration { .name = "Internal", diff --git a/Boards/CYD-2432S032C/Source/hal/CydDisplay.cpp b/Boards/CYD-2432S032C/Source/devices/Display.cpp similarity index 97% rename from Boards/CYD-2432S032C/Source/hal/CydDisplay.cpp rename to Boards/CYD-2432S032C/Source/devices/Display.cpp index ed6b00a0..33e67cd5 100644 --- a/Boards/CYD-2432S032C/Source/hal/CydDisplay.cpp +++ b/Boards/CYD-2432S032C/Source/devices/Display.cpp @@ -1,4 +1,4 @@ -#include "CydDisplay.h" +#include "Display.h" #include #include diff --git a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h b/Boards/CYD-2432S032C/Source/devices/Display.h similarity index 87% rename from Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h rename to Boards/CYD-2432S032C/Source/devices/Display.h index 7a9b967d..344191d6 100644 --- a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h +++ b/Boards/CYD-2432S032C/Source/devices/Display.h @@ -1,5 +1,6 @@ #pragma once #include +#include std::shared_ptr createDisplay(); diff --git a/Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.cpp b/Boards/CYD-2432S032C/Source/devices/SdCard.cpp similarity index 84% rename from Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.cpp rename to Boards/CYD-2432S032C/Source/devices/SdCard.cpp index db09d6a7..0caa946a 100644 --- a/Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.cpp +++ b/Boards/CYD-2432S032C/Source/devices/SdCard.cpp @@ -1,6 +1,4 @@ -#include "YellowSdCard.h" - -#define TAG "jc2432w328c_sdcard" +#include "SdCard.h" #include #include @@ -10,7 +8,7 @@ constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; using tt::hal::sdcard::SpiSdCardDevice; -std::shared_ptr createYellowSdCard() { +std::shared_ptr createSdCard() { auto configuration = std::make_unique( SDCARD_PIN_CS, GPIO_NUM_NC, diff --git a/Boards/CYD-2432S032C/Source/devices/SdCard.h b/Boards/CYD-2432S032C/Source/devices/SdCard.h new file mode 100644 index 00000000..fea58cef --- /dev/null +++ b/Boards/CYD-2432S032C/Source/devices/SdCard.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); + diff --git a/Boards/CYD-2432S032C/Source/hal/CydDisplay.h b/Boards/CYD-2432S032C/Source/hal/CydDisplay.h deleted file mode 100644 index 036603c9..00000000 --- a/Boards/CYD-2432S032C/Source/hal/CydDisplay.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-4848S040C/Source/CYD4848S040C.cpp b/Boards/CYD-4848S040C/Source/CYD4848S040C.cpp index 860a085d..1252f528 100644 --- a/Boards/CYD-4848S040C/Source/CYD4848S040C.cpp +++ b/Boards/CYD-4848S040C/Source/CYD4848S040C.cpp @@ -1,20 +1,25 @@ #include "CYD4848S040C.h" -#include "hal/CydDisplay.h" -#include "hal/CydSdCard.h" +#include "devices/St7701Display.h" +#include "devices/SdCard.h" #include using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(GPIO_NUM_38, 1000); } +static DeviceVector createDevices() { + return { + std::reinterpret_pointer_cast(std::make_shared()), + createSdCard() + }; +} + const Configuration cyd_4848s040c_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = { //Touch i2c::Configuration { diff --git a/Boards/CYD-4848S040C/Source/hal/CydSdCard.cpp b/Boards/CYD-4848S040C/Source/devices/SdCard.cpp similarity index 95% rename from Boards/CYD-4848S040C/Source/hal/CydSdCard.cpp rename to Boards/CYD-4848S040C/Source/devices/SdCard.cpp index 9c2491e6..53b1710c 100644 --- a/Boards/CYD-4848S040C/Source/hal/CydSdCard.cpp +++ b/Boards/CYD-4848S040C/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "CydSdCard.h" +#include "SdCard.h" #include #include diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.h b/Boards/CYD-4848S040C/Source/devices/SdCard.h similarity index 99% rename from Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.h rename to Boards/CYD-4848S040C/Source/devices/SdCard.h index 5cb65a73..4da9f5b9 100644 --- a/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.h +++ b/Boards/CYD-4848S040C/Source/devices/SdCard.h @@ -5,3 +5,4 @@ using tt::hal::sdcard::SdCardDevice; std::shared_ptr createSdCard(); + diff --git a/Boards/CYD-4848S040C/Source/hal/CydDisplay.cpp b/Boards/CYD-4848S040C/Source/devices/St7701Display.cpp similarity index 89% rename from Boards/CYD-4848S040C/Source/hal/CydDisplay.cpp rename to Boards/CYD-4848S040C/Source/devices/St7701Display.cpp index 2ad2ceb9..4ac8fb99 100644 --- a/Boards/CYD-4848S040C/Source/hal/CydDisplay.cpp +++ b/Boards/CYD-4848S040C/Source/devices/St7701Display.cpp @@ -1,4 +1,4 @@ -#include "CydDisplay.h" +#include "St7701Display.h" #include #include @@ -11,7 +11,7 @@ #include #include -constexpr auto TAG = "ST7701"; +constexpr auto TAG = "St7701Display"; static const st7701_lcd_init_cmd_t st7701_lcd_init_cmds[] = { // {cmd, { data }, data_size, delay_ms} @@ -56,7 +56,7 @@ static const st7701_lcd_init_cmd_t st7701_lcd_init_cmds[] = { {0x29, (uint8_t[]) {0x00}, 0, 0}, //Display On }; -bool CydDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { +bool St7701Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { spi_line_config_t line_config = { .cs_io_type = IO_TYPE_GPIO, .cs_gpio_num = GPIO_NUM_39, @@ -70,7 +70,7 @@ bool CydDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { return esp_lcd_new_panel_io_3wire_spi(&panel_io_config, &outHandle) == ESP_OK; } -bool CydDisplay::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) { +bool St7701Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) { const esp_lcd_rgb_panel_config_t rgb_config = { .clk_src = LCD_CLK_SRC_DEFAULT, .timings = { @@ -180,7 +180,7 @@ bool CydDisplay::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_p return true; } -lvgl_port_display_cfg_t CydDisplay::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { +lvgl_port_display_cfg_t St7701Display::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { return { .io_handle = ioHandle, .panel_handle = panelHandle, @@ -208,7 +208,7 @@ lvgl_port_display_cfg_t CydDisplay::getLvglPortDisplayConfig(esp_lcd_panel_io_ha }; } -lvgl_port_display_rgb_cfg_t CydDisplay::getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { +lvgl_port_display_rgb_cfg_t St7701Display::getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { return { .flags = { .bb_mode = true, @@ -217,7 +217,7 @@ lvgl_port_display_rgb_cfg_t CydDisplay::getLvglPortDisplayRgbConfig(esp_lcd_pane }; } -std::shared_ptr _Nullable CydDisplay::getTouchDevice() { +std::shared_ptr _Nullable St7701Display::getTouchDevice() { if (touchDevice == nullptr) { auto configuration = std::make_unique( I2C_NUM_0, @@ -231,11 +231,6 @@ std::shared_ptr _Nullable CydDisplay::getTouchDevic return touchDevice; } -void CydDisplay::setBacklightDuty(uint8_t backlightDuty) { +void St7701Display::setBacklightDuty(uint8_t backlightDuty) { driver::pwmbacklight::setBacklightDuty(backlightDuty); } - -std::shared_ptr createDisplay() { - auto display = std::make_shared(); - return std::reinterpret_pointer_cast(display); -} diff --git a/Boards/CYD-4848S040C/Source/hal/CydDisplay.h b/Boards/CYD-4848S040C/Source/devices/St7701Display.h similarity index 83% rename from Boards/CYD-4848S040C/Source/hal/CydDisplay.h rename to Boards/CYD-4848S040C/Source/devices/St7701Display.h index 960d00fd..58a75c90 100644 --- a/Boards/CYD-4848S040C/Source/hal/CydDisplay.h +++ b/Boards/CYD-4848S040C/Source/devices/St7701Display.h @@ -5,7 +5,7 @@ #include #include -class CydDisplay final : public EspLcdDisplay { +class St7701Display final : public EspLcdDisplay { std::shared_ptr _Nullable touchDevice; @@ -21,7 +21,7 @@ class CydDisplay final : public EspLcdDisplay { public: - CydDisplay() : EspLcdDisplay(std::make_shared(tt::Mutex::Type::Recursive)) {} + St7701Display() : EspLcdDisplay(std::make_shared(tt::Mutex::Type::Recursive)) {} std::string getName() const override { return "ST7701S"; } @@ -33,5 +33,3 @@ public: bool supportsBacklightDuty() const override { return true; } }; - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp b/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp index ba5e49c7..7e26ee29 100644 --- a/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp +++ b/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp @@ -1,21 +1,27 @@ #include "CYD8048S043C.h" // Don't remove, or we get a linker error ("undefined reference to `cyd_8048s043c_config'" - GCC bug?) #include "PwmBacklight.h" -#include "hal/CydDisplay.h" -#include "hal/CydSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" using namespace tt::hal; -bool initBoot() { +static bool initBoot() { + // Display backlight return driver::pwmbacklight::init(GPIO_NUM_2, 200); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const Configuration cyd_8048s043c_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = { - //Touch + // Touch i2c::Configuration { .name = "Internal", .port = I2C_NUM_0, @@ -33,7 +39,7 @@ const Configuration cyd_8048s043c_config = { .clk_flags = 0 } }, - //P4 header, JST SH 1.0, GND / 3.3V / IO17 / IO18 + // P4 header, JST SH 1.0, GND / 3.3V / IO17 / IO18 i2c::Configuration { .name = "External", .port = I2C_NUM_1, @@ -53,7 +59,7 @@ const Configuration cyd_8048s043c_config = { } }, .spi { - //SD Card + // SD Card spi::Configuration { .device = SPI2_HOST, .dma = SPI_DMA_CH_AUTO, @@ -79,7 +85,7 @@ const Configuration cyd_8048s043c_config = { } }, .uart { - //P4 header, JST SH 1.0, GND / 3.3V / IO17 / IO18 + // P4 header, JST SH 1.0, GND / 3.3V / IO17 / IO18 uart::Configuration { .name = "UART1", .port = UART_NUM_1, diff --git a/Boards/CYD-8048S043C/Source/hal/CydDisplay.cpp b/Boards/CYD-8048S043C/Source/devices/Display.cpp similarity index 99% rename from Boards/CYD-8048S043C/Source/hal/CydDisplay.cpp rename to Boards/CYD-8048S043C/Source/devices/Display.cpp index 02946968..6ce9afe4 100644 --- a/Boards/CYD-8048S043C/Source/hal/CydDisplay.cpp +++ b/Boards/CYD-8048S043C/Source/devices/Display.cpp @@ -1,4 +1,4 @@ -#include "CydDisplay.h" +#include "Display.h" #include #include diff --git a/Boards/CYD-8048S043C/Source/hal/CydDisplay.h b/Boards/CYD-8048S043C/Source/devices/Display.h similarity index 100% rename from Boards/CYD-8048S043C/Source/hal/CydDisplay.h rename to Boards/CYD-8048S043C/Source/devices/Display.h diff --git a/Boards/CYD-8048S043C/Source/hal/CydSdCard.cpp b/Boards/CYD-8048S043C/Source/devices/SdCard.cpp similarity index 95% rename from Boards/CYD-8048S043C/Source/hal/CydSdCard.cpp rename to Boards/CYD-8048S043C/Source/devices/SdCard.cpp index 0974f949..3a116b92 100644 --- a/Boards/CYD-8048S043C/Source/hal/CydSdCard.cpp +++ b/Boards/CYD-8048S043C/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "CydSdCard.h" +#include "SdCard.h" #include #include diff --git a/Boards/CYD-8048S043C/Source/hal/CydSdCard.h b/Boards/CYD-8048S043C/Source/devices/SdCard.h similarity index 100% rename from Boards/CYD-8048S043C/Source/hal/CydSdCard.h rename to Boards/CYD-8048S043C/Source/devices/SdCard.h diff --git a/Boards/CYD-JC2432W328C/Source/JC2432W328C.cpp b/Boards/CYD-JC2432W328C/Source/JC2432W328C.cpp index 6237185a..60034d6e 100644 --- a/Boards/CYD-JC2432W328C/Source/JC2432W328C.cpp +++ b/Boards/CYD-JC2432W328C/Source/JC2432W328C.cpp @@ -1,18 +1,16 @@ #include "JC2432W328C.h" -#include "hal/YellowDisplay.h" -#include "hal/YellowDisplayConstants.h" -#include "hal/YellowSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" -#include #include - #include +#include using namespace tt::hal; #define CYD_SPI_TRANSFER_SIZE_LIMIT (JC2432W328C_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8) -bool initBoot() { +static bool initBoot() { //Set the RGB Led Pins to output and turn them off ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green @@ -26,11 +24,16 @@ bool initBoot() { return driver::pwmbacklight::init(JC2432W328C_LCD_PIN_BACKLIGHT); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const Configuration cyd_jc2432w328c_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createYellowSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = { //Touch i2c::Configuration { diff --git a/Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.cpp b/Boards/CYD-JC2432W328C/Source/devices/Display.cpp similarity index 92% rename from Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.cpp rename to Boards/CYD-JC2432W328C/Source/devices/Display.cpp index ed680d05..1d999461 100644 --- a/Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.cpp +++ b/Boards/CYD-JC2432W328C/Source/devices/Display.cpp @@ -1,9 +1,8 @@ -#include "YellowDisplay.h" -#include "Cst816Touch.h" -#include "YellowDisplayConstants.h" +#include "Display.h" -#include +#include #include +#include static std::shared_ptr createTouch() { auto configuration = std::make_unique( diff --git a/Boards/CYD-JC2432W328C/Source/hal/YellowDisplayConstants.h b/Boards/CYD-JC2432W328C/Source/devices/Display.h similarity index 79% rename from Boards/CYD-JC2432W328C/Source/hal/YellowDisplayConstants.h rename to Boards/CYD-JC2432W328C/Source/devices/Display.h index 6aa0c735..b3cd143d 100644 --- a/Boards/CYD-JC2432W328C/Source/hal/YellowDisplayConstants.h +++ b/Boards/CYD-JC2432W328C/Source/devices/Display.h @@ -1,5 +1,8 @@ #pragma once +#include "Tactility/hal/display/DisplayDevice.h" +#include + // Display backlight (PWM) #define JC2432W328C_LCD_PIN_BACKLIGHT GPIO_NUM_27 @@ -12,3 +15,4 @@ #define JC2432W328C_LCD_PIN_CS GPIO_NUM_15 #define JC2432W328C_LCD_PIN_DC GPIO_NUM_2 +std::shared_ptr createDisplay(); diff --git a/Boards/CYD-2432S032C/Source/hal/CydSdCard.cpp b/Boards/CYD-JC2432W328C/Source/devices/SdCard.cpp similarity index 84% rename from Boards/CYD-2432S032C/Source/hal/CydSdCard.cpp rename to Boards/CYD-JC2432W328C/Source/devices/SdCard.cpp index 3ee10478..0caa946a 100644 --- a/Boards/CYD-2432S032C/Source/hal/CydSdCard.cpp +++ b/Boards/CYD-JC2432W328C/Source/devices/SdCard.cpp @@ -1,10 +1,10 @@ -#include "CydSdCard.h" +#include "SdCard.h" #include #include -#define SDCARD_SPI_HOST SPI3_HOST -#define SDCARD_PIN_CS GPIO_NUM_5 +constexpr auto SDCARD_SPI_HOST = SPI3_HOST; +constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; using tt::hal::sdcard::SpiSdCardDevice; diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3SdCard.h b/Boards/CYD-JC2432W328C/Source/devices/SdCard.h similarity index 99% rename from Boards/M5stackCoreS3/Source/hal/CoreS3SdCard.h rename to Boards/CYD-JC2432W328C/Source/devices/SdCard.h index 5cb65a73..4da9f5b9 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3SdCard.h +++ b/Boards/CYD-JC2432W328C/Source/devices/SdCard.h @@ -5,3 +5,4 @@ using tt::hal::sdcard::SdCardDevice; std::shared_ptr createSdCard(); + diff --git a/Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.h b/Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.h deleted file mode 100644 index 036603c9..00000000 --- a/Boards/CYD-JC2432W328C/Source/hal/YellowDisplay.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.h b/Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.h deleted file mode 100644 index 772f7119..00000000 --- a/Boards/CYD-JC2432W328C/Source/hal/YellowSdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createYellowSdCard(); - diff --git a/Boards/CYD-JC8048W550C/Source/JC8048W550C.cpp b/Boards/CYD-JC8048W550C/Source/JC8048W550C.cpp index 1f69379a..1339f199 100644 --- a/Boards/CYD-JC8048W550C/Source/JC8048W550C.cpp +++ b/Boards/CYD-JC8048W550C/Source/JC8048W550C.cpp @@ -1,19 +1,24 @@ #include "JC8048W550C.h" // Don't remove, or we get a linker error ("undefined reference to `cyd_jc8048w550c_config'" - GCC bug?) #include "PwmBacklight.h" -#include "hal/CydDisplay.h" -#include "hal/CydSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(GPIO_NUM_2); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const Configuration cyd_jc8048w550c_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = { //Touch i2c::Configuration { diff --git a/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp b/Boards/CYD-JC8048W550C/Source/devices/Display.cpp similarity index 98% rename from Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp rename to Boards/CYD-JC8048W550C/Source/devices/Display.cpp index b85e76ed..6ce9afe4 100644 --- a/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp +++ b/Boards/CYD-JC8048W550C/Source/devices/Display.cpp @@ -1,9 +1,8 @@ -#include "RgbDisplay.h" +#include "Display.h" -#include "CydDisplay.h" - -#include #include +#include +#include #include std::shared_ptr _Nullable createTouch() { diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplay.h b/Boards/CYD-JC8048W550C/Source/devices/Display.h similarity index 100% rename from Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplay.h rename to Boards/CYD-JC8048W550C/Source/devices/Display.h diff --git a/Boards/CYD-JC8048W550C/Source/hal/CydSdCard.cpp b/Boards/CYD-JC8048W550C/Source/devices/SdCard.cpp similarity index 96% rename from Boards/CYD-JC8048W550C/Source/hal/CydSdCard.cpp rename to Boards/CYD-JC8048W550C/Source/devices/SdCard.cpp index 0bb3c2bc..97d064eb 100644 --- a/Boards/CYD-JC8048W550C/Source/hal/CydSdCard.cpp +++ b/Boards/CYD-JC8048W550C/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "CydSdCard.h" +#include "SdCard.h" #include #include diff --git a/Boards/CYD-JC8048W550C/Source/devices/SdCard.h b/Boards/CYD-JC8048W550C/Source/devices/SdCard.h new file mode 100644 index 00000000..6f5443c7 --- /dev/null +++ b/Boards/CYD-JC8048W550C/Source/devices/SdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp b/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp index 0aaeaab2..b9b9d583 100644 --- a/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp +++ b/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp @@ -1,8 +1,7 @@ #include "PwmBacklight.h" #include "Tactility/lvgl/LvglSync.h" -#include "hal/CrowPanelDisplay.h" -#include "hal/CrowPanelDisplayConstants.h" -#include "hal/CrowPanelSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include @@ -10,14 +9,20 @@ using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(GPIO_NUM_38); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + extern const Configuration crowpanel_advance_28 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelAdvance28/Source/devices/Display.cpp similarity index 89% rename from Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplay.cpp rename to Boards/ElecrowCrowpanelAdvance28/Source/devices/Display.cpp index 857436cc..0627b99a 100644 --- a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelAdvance28/Source/devices/Display.cpp @@ -1,5 +1,4 @@ -#include "CrowPanelDisplay.h" -#include "CrowPanelDisplayConstants.h" +#include "Display.h" #include #include @@ -11,8 +10,8 @@ static std::shared_ptr createTouch() { I2C_NUM_0, 240, 320, - true, - true, + false, + false, false ); @@ -26,11 +25,11 @@ std::shared_ptr createDisplay() { CROWPANEL_LCD_SPI_HOST, CROWPANEL_LCD_PIN_CS, CROWPANEL_LCD_PIN_DC, - 320, 240, + 320, touch, - true, - true, + false, + false, false, true ); diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplayConstants.h b/Boards/ElecrowCrowpanelAdvance28/Source/devices/Display.h similarity index 73% rename from Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplayConstants.h rename to Boards/ElecrowCrowpanelAdvance28/Source/devices/Display.h index babc05d7..e1a299f3 100644 --- a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelDisplayConstants.h +++ b/Boards/ElecrowCrowpanelAdvance28/Source/devices/Display.h @@ -1,8 +1,12 @@ #pragma once +#include + #define CROWPANEL_LCD_SPI_HOST SPI2_HOST #define CROWPANEL_LCD_PIN_CS GPIO_NUM_40 #define CROWPANEL_LCD_PIN_DC GPIO_NUM_41 // RS #define CROWPANEL_LCD_HORIZONTAL_RESOLUTION 320 #define CROWPANEL_LCD_VERTICAL_RESOLUTION 240 #define CROWPANEL_LCD_SPI_TRANSFER_HEIGHT (CROWPANEL_LCD_VERTICAL_RESOLUTION / 10) + +std::shared_ptr createDisplay(); diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelSdCard.cpp b/Boards/ElecrowCrowpanelAdvance28/Source/devices/SdCard.cpp similarity index 91% rename from Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelSdCard.cpp rename to Boards/ElecrowCrowpanelAdvance28/Source/devices/SdCard.cpp index caefc81c..1c011c3c 100644 --- a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/ElecrowCrowpanelAdvance28/Source/devices/SdCard.cpp @@ -1,10 +1,8 @@ -#include "CrowPanelSdCard.h" +#include "SdCard.h" #include #include -#include - using tt::hal::sdcard::SpiSdCardDevice; constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7; diff --git a/Boards/CYD-JC8048W550C/Source/hal/CydSdCard.h b/Boards/ElecrowCrowpanelAdvance28/Source/devices/SdCard.h similarity index 100% rename from Boards/CYD-JC8048W550C/Source/hal/CydSdCard.h rename to Boards/ElecrowCrowpanelAdvance28/Source/devices/SdCard.h diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp b/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp index 4598a286..0ba41c17 100644 --- a/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp +++ b/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp @@ -1,8 +1,7 @@ #include "PwmBacklight.h" #include "Tactility/lvgl/LvglSync.h" -#include "hal/CrowPanelDisplay.h" -#include "hal/CrowPanelDisplayConstants.h" -#include "hal/CrowPanelSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include @@ -10,14 +9,20 @@ using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(GPIO_NUM_38); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + extern const Configuration crowpanel_advance_35 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelAdvance35/Source/devices/Display.cpp similarity index 91% rename from Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplay.cpp rename to Boards/ElecrowCrowpanelAdvance35/Source/devices/Display.cpp index 0c7ef6cb..6b5919f6 100644 --- a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelAdvance35/Source/devices/Display.cpp @@ -1,12 +1,9 @@ -#include "CrowPanelDisplay.h" -#include "CrowPanelDisplayConstants.h" +#include "Display.h" #include #include #include -#define TAG "crowpanel_display" - static std::shared_ptr createTouch() { // Note for future changes: Reset pin is 48 and interrupt pin is 47 auto configuration = std::make_unique( diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplayConstants.h b/Boards/ElecrowCrowpanelAdvance35/Source/devices/Display.h similarity index 73% rename from Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplayConstants.h rename to Boards/ElecrowCrowpanelAdvance35/Source/devices/Display.h index 7751949e..6a4f0d3b 100644 --- a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplayConstants.h +++ b/Boards/ElecrowCrowpanelAdvance35/Source/devices/Display.h @@ -1,8 +1,12 @@ #pragma once +#include + #define CROWPANEL_LCD_SPI_HOST SPI2_HOST #define CROWPANEL_LCD_PIN_CS GPIO_NUM_40 #define CROWPANEL_LCD_PIN_DC GPIO_NUM_41 // RS #define CROWPANEL_LCD_HORIZONTAL_RESOLUTION 320 #define CROWPANEL_LCD_VERTICAL_RESOLUTION 480 #define CROWPANEL_LCD_SPI_TRANSFER_HEIGHT (CROWPANEL_LCD_VERTICAL_RESOLUTION / 10) + +std::shared_ptr createDisplay(); diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelSdCard.cpp b/Boards/ElecrowCrowpanelAdvance35/Source/devices/SdCard.cpp similarity index 91% rename from Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelSdCard.cpp rename to Boards/ElecrowCrowpanelAdvance35/Source/devices/SdCard.cpp index caefc81c..1c011c3c 100644 --- a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/ElecrowCrowpanelAdvance35/Source/devices/SdCard.cpp @@ -1,10 +1,8 @@ -#include "CrowPanelSdCard.h" +#include "SdCard.h" #include #include -#include - using tt::hal::sdcard::SpiSdCardDevice; constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7; diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelSdCard.h b/Boards/ElecrowCrowpanelAdvance35/Source/devices/SdCard.h similarity index 100% rename from Boards/ElecrowCrowpanelAdvance28/Source/hal/CrowPanelSdCard.h rename to Boards/ElecrowCrowpanelAdvance35/Source/devices/SdCard.h diff --git a/Boards/ElecrowCrowpanelAdvance50/Source/CrowPanelAdvance50.cpp b/Boards/ElecrowCrowpanelAdvance50/Source/CrowPanelAdvance50.cpp index ce58402a..0cb7702e 100644 --- a/Boards/ElecrowCrowpanelAdvance50/Source/CrowPanelAdvance50.cpp +++ b/Boards/ElecrowCrowpanelAdvance50/Source/CrowPanelAdvance50.cpp @@ -1,12 +1,12 @@ -#include "hal/CrowPanelDisplay.h" -#include "hal/CrowPanelSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include #include using namespace tt::hal; -bool initBoot() { +static bool initBoot() { TCA9534_IO_EXP io_expander = { .I2C_ADDR = 0x18, .i2c_master_port = I2C_NUM_0, @@ -21,10 +21,16 @@ bool initBoot() { return true; } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + extern const Configuration crowpanel_advance_50 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelAdvance50/Source/devices/Display.cpp similarity index 99% rename from Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelDisplay.cpp rename to Boards/ElecrowCrowpanelAdvance50/Source/devices/Display.cpp index 7f79525d..57197196 100644 --- a/Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelAdvance50/Source/devices/Display.cpp @@ -1,4 +1,4 @@ -#include "CrowPanelDisplay.h" +#include "Display.h" #include #include diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplay.h b/Boards/ElecrowCrowpanelAdvance50/Source/devices/Display.h similarity index 100% rename from Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelDisplay.h rename to Boards/ElecrowCrowpanelAdvance50/Source/devices/Display.h diff --git a/Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelSdCard.cpp b/Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.cpp similarity index 92% rename from Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelSdCard.cpp rename to Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.cpp index 124e9efc..3087262a 100644 --- a/Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.cpp @@ -1,10 +1,8 @@ -#include "CrowPanelSdCard.h" +#include "SdCard.h" #include #include -#include - using tt::hal::sdcard::SpiSdCardDevice; std::shared_ptr createSdCard() { diff --git a/Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.h b/Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.h new file mode 100644 index 00000000..6f5443c7 --- /dev/null +++ b/Boards/ElecrowCrowpanelAdvance50/Source/devices/SdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp b/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp index b1902554..ba632dbd 100644 --- a/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp +++ b/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp @@ -1,25 +1,30 @@ #include "PwmBacklight.h" -#include "Tactility/lvgl/LvglSync.h" -#include "hal/CrowPanelDisplay.h" -#include "hal/CrowPanelDisplayConstants.h" -#include "hal/CrowPanelSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include #include +#include #define CROWPANEL_SPI_TRANSFER_SIZE_LIMIT (CROWPANEL_LCD_HORIZONTAL_RESOLUTION * CROWPANEL_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8)) using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(GPIO_NUM_27); } +static DeviceVector createDevices() { + return { + std::make_shared(), + createDisplay(), + createSdCard(), + }; +} + extern const Configuration crowpanel_basic_28 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = getOrCreatePower, + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelBasic28/Source/devices/Display.cpp similarity index 93% rename from Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.cpp rename to Boards/ElecrowCrowpanelBasic28/Source/devices/Display.cpp index 427d4f7f..37648ee7 100644 --- a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelBasic28/Source/devices/Display.cpp @@ -1,5 +1,4 @@ -#include "CrowPanelDisplay.h" -#include "CrowPanelDisplayConstants.h" +#include "Display.h" #include #include diff --git a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplayConstants.h b/Boards/ElecrowCrowpanelBasic28/Source/devices/Display.h similarity index 75% rename from Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplayConstants.h rename to Boards/ElecrowCrowpanelBasic28/Source/devices/Display.h index c35eb30d..2c586145 100644 --- a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplayConstants.h +++ b/Boards/ElecrowCrowpanelBasic28/Source/devices/Display.h @@ -1,5 +1,7 @@ #pragma once +#include + #define CROWPANEL_LCD_SPI_HOST SPI2_HOST #define CROWPANEL_LCD_PIN_CS GPIO_NUM_15 #define CROWPANEL_TOUCH_PIN_CS GPIO_NUM_33 @@ -7,3 +9,5 @@ #define CROWPANEL_LCD_HORIZONTAL_RESOLUTION 320 #define CROWPANEL_LCD_VERTICAL_RESOLUTION 240 #define CROWPANEL_LCD_SPI_TRANSFER_HEIGHT (CROWPANEL_LCD_VERTICAL_RESOLUTION / 10) + +std::shared_ptr createDisplay(); diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp b/Boards/ElecrowCrowpanelBasic28/Source/devices/SdCard.cpp similarity index 95% rename from Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp rename to Boards/ElecrowCrowpanelBasic28/Source/devices/SdCard.cpp index 2696e05c..3103ad3d 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/ElecrowCrowpanelBasic28/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "CrowPanelSdCard.h" +#include "SdCard.h" #include #include diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelSdCard.h b/Boards/ElecrowCrowpanelBasic28/Source/devices/SdCard.h similarity index 100% rename from Boards/ElecrowCrowpanelAdvance35/Source/hal/CrowPanelSdCard.h rename to Boards/ElecrowCrowpanelBasic28/Source/devices/SdCard.h diff --git a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.h b/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.h deleted file mode 100644 index 5a0d81b3..00000000 --- a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelDisplay.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" - -std::shared_ptr createDisplay(); diff --git a/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp b/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp index 556e8e14..6ed02667 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp +++ b/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp @@ -1,25 +1,30 @@ #include "PwmBacklight.h" #include "Tactility/lvgl/LvglSync.h" -#include "hal/CrowPanelDisplay.h" -#include "hal/CrowPanelDisplayConstants.h" -#include "hal/CrowPanelSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include #include -#define CROWPANEL_SPI_TRANSFER_SIZE_LIMIT (CROWPANEL_LCD_HORIZONTAL_RESOLUTION * CROWPANEL_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8)) +constexpr auto CROWPANEL_SPI_TRANSFER_SIZE_LIMIT = (CROWPANEL_LCD_HORIZONTAL_RESOLUTION * CROWPANEL_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8)); using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(GPIO_NUM_27); } +static DeviceVector createDevices() { + return { + std::make_shared(), + createDisplay(), + createSdCard(), + }; +} + extern const Configuration crowpanel_basic_35 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = getOrCreatePower, + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelBasic35/Source/devices/Display.cpp similarity index 74% rename from Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp rename to Boards/ElecrowCrowpanelBasic35/Source/devices/Display.cpp index 4f50d62c..bef72235 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelBasic35/Source/devices/Display.cpp @@ -1,10 +1,8 @@ -#include "CrowPanelDisplay.h" -#include "CrowPanelDisplayConstants.h" +#include "Display.h" #include -#include - #include +#include std::shared_ptr createTouch() { auto configuration = std::make_unique( @@ -12,8 +10,8 @@ std::shared_ptr createTouch() { CROWPANEL_TOUCH_PIN_CS, 320, 480, - true, - true, + false, + false, true ); @@ -23,23 +21,18 @@ std::shared_ptr createTouch() { std::shared_ptr createDisplay() { auto touch = createTouch(); - /** - * This display is mirrored on X, but that doesn't seem to work with the driver. - * Instead, we swap XY, which does work. That results in a landscape image. - */ auto configuration = std::make_unique( CROWPANEL_LCD_SPI_HOST, CROWPANEL_LCD_PIN_CS, CROWPANEL_LCD_PIN_DC, - 480, 320, + 480, touch, - true, + false, false, false ); - configuration->mirrorX = true; configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; auto display = std::make_shared(std::move(configuration)); diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplayConstants.h b/Boards/ElecrowCrowpanelBasic35/Source/devices/Display.h similarity index 75% rename from Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplayConstants.h rename to Boards/ElecrowCrowpanelBasic35/Source/devices/Display.h index 09e8d858..5080412f 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplayConstants.h +++ b/Boards/ElecrowCrowpanelBasic35/Source/devices/Display.h @@ -1,5 +1,7 @@ #pragma once +#include + #define CROWPANEL_LCD_SPI_HOST SPI2_HOST #define CROWPANEL_LCD_PIN_CS GPIO_NUM_15 #define CROWPANEL_TOUCH_PIN_CS GPIO_NUM_12 @@ -7,3 +9,5 @@ #define CROWPANEL_LCD_HORIZONTAL_RESOLUTION 320 #define CROWPANEL_LCD_VERTICAL_RESOLUTION 240 #define CROWPANEL_LCD_SPI_TRANSFER_HEIGHT (CROWPANEL_LCD_VERTICAL_RESOLUTION / 10) + +std::shared_ptr createDisplay(); diff --git a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.cpp b/Boards/ElecrowCrowpanelBasic35/Source/devices/SdCard.cpp similarity index 90% rename from Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.cpp rename to Boards/ElecrowCrowpanelBasic35/Source/devices/SdCard.cpp index 826ac9bf..3103ad3d 100644 --- a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/ElecrowCrowpanelBasic35/Source/devices/SdCard.cpp @@ -1,10 +1,8 @@ -#include "CrowPanelSdCard.h" +#include "SdCard.h" #include #include -#include - using tt::hal::sdcard::SpiSdCardDevice; std::shared_ptr createSdCard() { diff --git a/Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelSdCard.h b/Boards/ElecrowCrowpanelBasic35/Source/devices/SdCard.h similarity index 100% rename from Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelSdCard.h rename to Boards/ElecrowCrowpanelBasic35/Source/devices/SdCard.h diff --git a/Boards/ElecrowCrowpanelBasic50/Source/CrowPanelBasic50.cpp b/Boards/ElecrowCrowpanelBasic50/Source/CrowPanelBasic50.cpp index 6447c34a..a556fd23 100644 --- a/Boards/ElecrowCrowpanelBasic50/Source/CrowPanelBasic50.cpp +++ b/Boards/ElecrowCrowpanelBasic50/Source/CrowPanelBasic50.cpp @@ -1,19 +1,26 @@ -#include "hal/CrowPanelDisplay.h" -#include "hal/CrowPanelSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include #include using namespace tt::hal; -bool initBoot() { +static bool initBoot() { + // Note: I tried 100 Hz to 100 kHz and couldn't get the flickering to stop return driver::pwmbacklight::init(GPIO_NUM_2); } +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard(), + }; +} + extern const Configuration crowpanel_basic_50 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelBasic50/Source/devices/Display.cpp similarity index 99% rename from Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp rename to Boards/ElecrowCrowpanelBasic50/Source/devices/Display.cpp index 6533da9a..94689d66 100644 --- a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelBasic50/Source/devices/Display.cpp @@ -1,4 +1,4 @@ -#include "CrowPanelDisplay.h" +#include "Display.h" #include #include diff --git a/Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelDisplay.h b/Boards/ElecrowCrowpanelBasic50/Source/devices/Display.h similarity index 100% rename from Boards/ElecrowCrowpanelAdvance50/Source/hal/CrowPanelDisplay.h rename to Boards/ElecrowCrowpanelBasic50/Source/devices/Display.h diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp b/Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.cpp similarity index 93% rename from Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp rename to Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.cpp index 885ba208..a27db36c 100644 --- a/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp +++ b/Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "WaveshareSdCard.h" +#include "SdCard.h" #include diff --git a/Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.h b/Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.h new file mode 100644 index 00000000..6f5443c7 --- /dev/null +++ b/Boards/ElecrowCrowpanelBasic50/Source/devices/SdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp b/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp index 3394eb0b..a2e6f48a 100644 --- a/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp +++ b/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp @@ -1,22 +1,21 @@ #include "Tactility/lvgl/LvglSync.h" -#include "hal/TpagerDisplay.h" -#include "hal/TpagerEncoder.h" -#include "hal/TpagerDisplayConstants.h" -#include "hal/TpagerKeyboard.h" -#include "hal/TpagerPower.h" -#include "hal/TpagerSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" +#include "devices/TpagerEncoder.h" +#include "devices/TpagerKeyboard.h" +#include "devices/TpagerPower.h" #include #include #include -#define TPAGER_SPI_TRANSFER_SIZE_LIMIT (TPAGER_LCD_HORIZONTAL_RESOLUTION * TPAGER_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8)) +#define TPAGER_SPI_TRANSFER_SIZE_LIMIT (480 * 222 * (LV_COLOR_DEPTH / 8)) bool tpagerInit(); using namespace tt::hal; -DeviceVector createDevices() { +static DeviceVector createDevices() { auto bq27220 = std::make_shared(I2C_NUM_0); auto power = std::make_shared(bq27220); diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp b/Boards/LilygoTLoraPager/Source/devices/Display.cpp similarity index 70% rename from Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp rename to Boards/LilygoTLoraPager/Source/devices/Display.cpp index 5f4c6755..84a42d18 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp +++ b/Boards/LilygoTLoraPager/Source/devices/Display.cpp @@ -1,10 +1,14 @@ -#include "TpagerDisplay.h" -#include "TpagerDisplayConstants.h" +#include "Display.h" #include #include -#include +#define TPAGER_LCD_SPI_HOST SPI2_HOST +#define TPAGER_LCD_PIN_CS GPIO_NUM_38 +#define TPAGER_LCD_PIN_DC GPIO_NUM_37 // RS +#define TPAGER_LCD_HORIZONTAL_RESOLUTION 222 +#define TPAGER_LCD_VERTICAL_RESOLUTION 480 +#define TPAGER_LCD_SPI_TRANSFER_HEIGHT (TPAGER_LCD_VERTICAL_RESOLUTION / 10) std::shared_ptr createDisplay() { auto configuration = std::make_unique( diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h b/Boards/LilygoTLoraPager/Source/devices/Display.h similarity index 100% rename from Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h rename to Boards/LilygoTLoraPager/Source/devices/Display.h diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerSdCard.cpp b/Boards/LilygoTLoraPager/Source/devices/SdCard.cpp similarity index 96% rename from Boards/LilygoTLoraPager/Source/hal/TpagerSdCard.cpp rename to Boards/LilygoTLoraPager/Source/devices/SdCard.cpp index 29a21630..940dc7d4 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerSdCard.cpp +++ b/Boards/LilygoTLoraPager/Source/devices/SdCard.cpp @@ -1,4 +1,4 @@ -#include "TpagerSdCard.h" +#include "SdCard.h" #include #include diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerSdCard.h b/Boards/LilygoTLoraPager/Source/devices/SdCard.h similarity index 100% rename from Boards/LilygoTLoraPager/Source/hal/TpagerSdCard.h rename to Boards/LilygoTLoraPager/Source/devices/SdCard.h diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerEncoder.cpp b/Boards/LilygoTLoraPager/Source/devices/TpagerEncoder.cpp similarity index 98% rename from Boards/LilygoTLoraPager/Source/hal/TpagerEncoder.cpp rename to Boards/LilygoTLoraPager/Source/devices/TpagerEncoder.cpp index 25514564..b4ff408d 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerEncoder.cpp +++ b/Boards/LilygoTLoraPager/Source/devices/TpagerEncoder.cpp @@ -111,7 +111,7 @@ void TpagerEncoder::initEncoder() { } } -int TpagerEncoder::getEncoderPulses() { +int TpagerEncoder::getEncoderPulses() const { int pulses = 0; pcnt_unit_get_count(encPcntUnit, &pulses); return pulses; diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerEncoder.h b/Boards/LilygoTLoraPager/Source/devices/TpagerEncoder.h similarity index 91% rename from Boards/LilygoTLoraPager/Source/hal/TpagerEncoder.h rename to Boards/LilygoTLoraPager/Source/devices/TpagerEncoder.h index 52699e42..3081af03 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerEncoder.h +++ b/Boards/LilygoTLoraPager/Source/devices/TpagerEncoder.h @@ -15,7 +15,7 @@ class TpagerEncoder final : public tt::hal::encoder::EncoderDevice { public: TpagerEncoder() {} - ~TpagerEncoder() {} + ~TpagerEncoder() override {} std::string getName() const override { return "T-Lora Pager Encoder"; } std::string getDescription() const override { return "The encoder wheel next to the display"; } @@ -23,7 +23,7 @@ public: bool startLvgl(lv_display_t* display) override; bool stopLvgl() override; - int getEncoderPulses(); + int getEncoderPulses() const; lv_indev_t* _Nullable getLvglIndev() override { return encHandle; } }; diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.cpp b/Boards/LilygoTLoraPager/Source/devices/TpagerKeyboard.cpp similarity index 100% rename from Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.cpp rename to Boards/LilygoTLoraPager/Source/devices/TpagerKeyboard.cpp diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.h b/Boards/LilygoTLoraPager/Source/devices/TpagerKeyboard.h similarity index 100% rename from Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.h rename to Boards/LilygoTLoraPager/Source/devices/TpagerKeyboard.h diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerPower.cpp b/Boards/LilygoTLoraPager/Source/devices/TpagerPower.cpp similarity index 100% rename from Boards/LilygoTLoraPager/Source/hal/TpagerPower.cpp rename to Boards/LilygoTLoraPager/Source/devices/TpagerPower.cpp diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerPower.h b/Boards/LilygoTLoraPager/Source/devices/TpagerPower.h similarity index 100% rename from Boards/LilygoTLoraPager/Source/hal/TpagerPower.h rename to Boards/LilygoTLoraPager/Source/devices/TpagerPower.h diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h b/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h deleted file mode 100644 index 7a9b967d..00000000 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplayConstants.h b/Boards/LilygoTLoraPager/Source/hal/TpagerDisplayConstants.h deleted file mode 100644 index 98847e46..00000000 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplayConstants.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#define TPAGER_LCD_SPI_HOST SPI2_HOST -#define TPAGER_LCD_PIN_CS GPIO_NUM_38 -#define TPAGER_LCD_PIN_DC GPIO_NUM_37 // RS -#define TPAGER_LCD_HORIZONTAL_RESOLUTION 222 -#define TPAGER_LCD_VERTICAL_RESOLUTION 480 -#define TPAGER_LCD_SPI_TRANSFER_HEIGHT (TPAGER_LCD_VERTICAL_RESOLUTION / 10) diff --git a/Boards/M5stackCore2/Source/InitBoot.cpp b/Boards/M5stackCore2/Source/InitBoot.cpp index 19a67736..a4e7871c 100644 --- a/Boards/M5stackCore2/Source/InitBoot.cpp +++ b/Boards/M5stackCore2/Source/InitBoot.cpp @@ -7,7 +7,7 @@ #include #include -#define TAG "core2" +constexpr auto* TAG = "Core2"; axp192_t axpDevice; diff --git a/Boards/M5stackCore2/Source/M5stackCore2.cpp b/Boards/M5stackCore2/Source/M5stackCore2.cpp index e08665c3..0f187e77 100644 --- a/Boards/M5stackCore2/Source/M5stackCore2.cpp +++ b/Boards/M5stackCore2/Source/M5stackCore2.cpp @@ -1,8 +1,8 @@ #include "M5stackCore2.h" #include "InitBoot.h" -#include "hal/Core2Display.h" -#include "hal/Core2Power.h" -#include "hal/Core2SdCard.h" +#include "devices/Display.h" +#include "devices/Core2Power.h" +#include "devices/SdCard.h" #include #include @@ -11,16 +11,22 @@ using namespace tt::hal; -extern const tt::hal::Configuration m5stack_core2 = { +static DeviceVector createDevices() { + return { + createPower(), + createSdCard(), + createDisplay() + }; +} + +extern const Configuration m5stack_core2 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = createPower, + .createDevices = createDevices, .i2c = { - tt::hal::i2c::Configuration { + i2c::Configuration { .name = "Internal", .port = I2C_NUM_0, - .initMode = tt::hal::i2c::InitMode::ByTactility, + .initMode = i2c::InitMode::ByTactility, .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, @@ -34,10 +40,10 @@ extern const tt::hal::Configuration m5stack_core2 = { .clk_flags = 0 } }, - tt::hal::i2c::Configuration { + i2c::Configuration { .name = "External", // (Grove) .port = I2C_NUM_1, - .initMode = tt::hal::i2c::InitMode::ByTactility, + .initMode = i2c::InitMode::ByTactility, .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, @@ -53,7 +59,7 @@ extern const tt::hal::Configuration m5stack_core2 = { } }, .spi { - tt::hal::spi::Configuration { + spi::Configuration { .device = SPI2_HOST, .dma = SPI_DMA_CH_AUTO, .config = { @@ -72,7 +78,7 @@ extern const tt::hal::Configuration m5stack_core2 = { .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, .intr_flags = 0 }, - .initMode = tt::hal::spi::InitMode::ByTactility, + .initMode = spi::InitMode::ByTactility, .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } diff --git a/Boards/M5stackCore2/Source/hal/Core2Power.cpp b/Boards/M5stackCore2/Source/devices/Core2Power.cpp similarity index 97% rename from Boards/M5stackCore2/Source/hal/Core2Power.cpp rename to Boards/M5stackCore2/Source/devices/Core2Power.cpp index 6256186d..3d5a5c3d 100644 --- a/Boards/M5stackCore2/Source/hal/Core2Power.cpp +++ b/Boards/M5stackCore2/Source/devices/Core2Power.cpp @@ -16,8 +16,6 @@ bool Core2Power::supportsMetric(MetricType type) const { default: return false; } - - return false; // Safety guard for when new enum values are introduced } bool Core2Power::getMetric(MetricType type, MetricData& data) { diff --git a/Boards/M5stackCore2/Source/hal/Core2Power.h b/Boards/M5stackCore2/Source/devices/Core2Power.h similarity index 100% rename from Boards/M5stackCore2/Source/hal/Core2Power.h rename to Boards/M5stackCore2/Source/devices/Core2Power.h diff --git a/Boards/M5stackCore2/Source/hal/Core2Display.cpp b/Boards/M5stackCore2/Source/devices/Display.cpp similarity index 97% rename from Boards/M5stackCore2/Source/hal/Core2Display.cpp rename to Boards/M5stackCore2/Source/devices/Display.cpp index 25f7f7e5..58152553 100644 --- a/Boards/M5stackCore2/Source/hal/Core2Display.cpp +++ b/Boards/M5stackCore2/Source/devices/Display.cpp @@ -1,4 +1,4 @@ -#include "Core2Display.h" +#include "Display.h" #include #include diff --git a/Boards/M5stackCore2/Source/hal/Core2Display.h b/Boards/M5stackCore2/Source/devices/Display.h similarity index 100% rename from Boards/M5stackCore2/Source/hal/Core2Display.h rename to Boards/M5stackCore2/Source/devices/Display.h diff --git a/Boards/M5stackCore2/Source/hal/Core2SdCard.cpp b/Boards/M5stackCore2/Source/devices/SdCard.cpp similarity index 82% rename from Boards/M5stackCore2/Source/hal/Core2SdCard.cpp rename to Boards/M5stackCore2/Source/devices/SdCard.cpp index e39f59fb..9d0f12b9 100644 --- a/Boards/M5stackCore2/Source/hal/Core2SdCard.cpp +++ b/Boards/M5stackCore2/Source/devices/SdCard.cpp @@ -1,12 +1,10 @@ -#include "Core2SdCard.h" +#include "SdCard.h" #include #include -#include - -#define CORE2_SDCARD_PIN_CS GPIO_NUM_4 -#define CORE2_LCD_PIN_CS GPIO_NUM_5 +constexpr auto CORE2_SDCARD_PIN_CS = GPIO_NUM_4; +constexpr auto CORE2_LCD_PIN_CS = GPIO_NUM_5; using tt::hal::sdcard::SpiSdCardDevice; diff --git a/Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.h b/Boards/M5stackCore2/Source/devices/SdCard.h similarity index 100% rename from Boards/ElecrowCrowpanelBasic28/Source/hal/CrowPanelSdCard.h rename to Boards/M5stackCore2/Source/devices/SdCard.h diff --git a/Boards/M5stackCoreS3/CMakeLists.txt b/Boards/M5stackCoreS3/CMakeLists.txt index d393c180..b2553f94 100644 --- a/Boards/M5stackCoreS3/CMakeLists.txt +++ b/Boards/M5stackCoreS3/CMakeLists.txt @@ -1,5 +1,7 @@ +file(GLOB_RECURSE SOURCE_FILES Source/*.c*) + idf_component_register( - SRC_DIRS "Source" "Source/hal" + SRCS ${SOURCE_FILES} INCLUDE_DIRS "Source" REQUIRES Tactility esp_lvgl_port ILI934x FT5x06 AXP2101 AW9523 driver vfs fatfs ) diff --git a/Boards/M5stackCoreS3/Source/CoreS3Constants.h b/Boards/M5stackCoreS3/Source/CoreS3Constants.h deleted file mode 100644 index 766c1d87..00000000 --- a/Boards/M5stackCoreS3/Source/CoreS3Constants.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define AXP2101_ADDRESS 0x34 -#define AW9523_ADDRESS 0x58 diff --git a/Boards/M5stackCoreS3/Source/InitBoot.cpp b/Boards/M5stackCoreS3/Source/InitBoot.cpp index 4a863104..956ab56f 100644 --- a/Boards/M5stackCoreS3/Source/InitBoot.cpp +++ b/Boards/M5stackCoreS3/Source/InitBoot.cpp @@ -1,10 +1,9 @@ -#include -#include +#include "InitBoot.h" #include #include -#define TAG "cores3" +constexpr auto* TAG = "CoreS3"; std::shared_ptr axp2101; std::shared_ptr aw9523; @@ -148,9 +147,7 @@ bool initBoot() { TT_LOG_I(TAG, "initBoot()"); axp2101 = std::make_shared(I2C_NUM_0); - tt::hal::registerDevice(axp2101); aw9523 = std::make_shared(I2C_NUM_0); - tt::hal::registerDevice(aw9523); return initPowerControl() && initGpioExpander(); } \ No newline at end of file diff --git a/Boards/M5stackCoreS3/Source/InitBoot.h b/Boards/M5stackCoreS3/Source/InitBoot.h index f3e5bf89..70156960 100644 --- a/Boards/M5stackCoreS3/Source/InitBoot.h +++ b/Boards/M5stackCoreS3/Source/InitBoot.h @@ -1,3 +1,9 @@ #pragma once +#include +#include + +extern std::shared_ptr axp2101; +extern std::shared_ptr aw9523; + bool initBoot(); diff --git a/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp b/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp index 1e0c120d..dc843a52 100644 --- a/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp +++ b/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp @@ -1,10 +1,9 @@ #include "M5stackCoreS3.h" #include "InitBoot.h" -#include "hal/CoreS3Display.h" -#include "hal/CoreS3DisplayConstants.h" -#include "hal/CoreS3Power.h" -#include "hal/CoreS3SdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" +#include #include #include @@ -12,11 +11,19 @@ using namespace tt::hal; +static DeviceVector createDevices() { + return { + axp2101, + aw9523, + std::make_shared(axp2101), + createSdCard(), + createDisplay() + }; +} + const Configuration m5stack_cores3 = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createSdCard(), - .power = createPower, + .createDevices = createDevices, .i2c = { i2c::Configuration { .name = "Internal", diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp b/Boards/M5stackCoreS3/Source/devices/Display.cpp similarity index 94% rename from Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp rename to Boards/M5stackCoreS3/Source/devices/Display.cpp index 250e1cc9..42105e71 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3Display.cpp +++ b/Boards/M5stackCoreS3/Source/devices/Display.cpp @@ -1,12 +1,12 @@ -#include "CoreS3Display.h" -#include "CoreS3Constants.h" +#include "Display.h" +#include #include #include #include #include -constexpr auto TAG = "CoreS3Display"; +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 diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3DisplayConstants.h b/Boards/M5stackCoreS3/Source/devices/Display.h similarity index 77% rename from Boards/M5stackCoreS3/Source/hal/CoreS3DisplayConstants.h rename to Boards/M5stackCoreS3/Source/devices/Display.h index afac7a06..b180a5fb 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3DisplayConstants.h +++ b/Boards/M5stackCoreS3/Source/devices/Display.h @@ -1,5 +1,7 @@ #pragma once +#include + // Display #define CORES3_LCD_SPI_HOST SPI3_HOST #define CORES3_LCD_PIN_CS GPIO_NUM_3 @@ -8,3 +10,5 @@ #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/M5stackCoreS3/Source/hal/CoreS3SdCard.cpp b/Boards/M5stackCoreS3/Source/devices/SdCard.cpp similarity index 93% rename from Boards/M5stackCoreS3/Source/hal/CoreS3SdCard.cpp rename to Boards/M5stackCoreS3/Source/devices/SdCard.cpp index a815b5fa..f314b5f5 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3SdCard.cpp +++ b/Boards/M5stackCoreS3/Source/devices/SdCard.cpp @@ -1,10 +1,8 @@ -#include "CoreS3SdCard.h" +#include "SdCard.h" #include #include -#include - constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4; constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3; diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.h b/Boards/M5stackCoreS3/Source/devices/SdCard.h similarity index 100% rename from Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.h rename to Boards/M5stackCoreS3/Source/devices/SdCard.h diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3Display.h b/Boards/M5stackCoreS3/Source/hal/CoreS3Display.h deleted file mode 100644 index 7a9b967d..00000000 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3Display.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/UnPhone/Source/PowerOn.cpp b/Boards/UnPhone/Source/InitBoot.cpp similarity index 98% rename from Boards/UnPhone/Source/PowerOn.cpp rename to Boards/UnPhone/Source/InitBoot.cpp index 40690122..3f60a4e6 100644 --- a/Boards/UnPhone/Source/PowerOn.cpp +++ b/Boards/UnPhone/Source/InitBoot.cpp @@ -3,7 +3,7 @@ #include #include -#define TAG "unphone" +constexpr auto* TAG = "unPhone"; std::shared_ptr unPhoneFeatures; static std::unique_ptr powerThread; @@ -14,8 +14,6 @@ static const char* powerSleepKey = "power_sleep_key"; class DeviceStats { -private: - tt::Preferences preferences = tt::Preferences("unphone"); int32_t getValue(const char* key) { @@ -161,7 +159,6 @@ static bool unPhonePowerOn() { bootStats.notifyBootStart(); bq24295 = std::make_shared(I2C_NUM_0); - tt::hal::registerDevice(bq24295); unPhoneFeatures = std::make_shared(bq24295); @@ -185,7 +182,7 @@ static bool unPhonePowerOn() { return true; } -bool unPhoneInitPower() { +bool initBoot() { ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START); if (!unPhonePowerOn()) { diff --git a/Boards/UnPhone/Source/UnPhone.cpp b/Boards/UnPhone/Source/UnPhone.cpp index 3d7f335d..895e5f2a 100644 --- a/Boards/UnPhone/Source/UnPhone.cpp +++ b/Boards/UnPhone/Source/UnPhone.cpp @@ -1,20 +1,25 @@ #include "Tactility/lvgl/LvglSync.h" #include "UnPhoneFeatures.h" #include "Xpt2046Power.h" -#include "hal/UnPhoneDisplay.h" -#include "hal/UnPhoneDisplayConstants.h" -#include "hal/UnPhoneSdCard.h" +#include "devices/Hx8357Display.h" +#include "devices/SdCard.h" #include #define UNPHONE_SPI_TRANSFER_SIZE_LIMIT (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_SPI_TRANSFER_HEIGHT * LV_COLOR_DEPTH / 8) -bool unPhoneInitPower(); +bool initBoot(); + +static tt::hal::DeviceVector createDevices() { + return { + std::make_shared(), + createDisplay(), + createSdCard() + }; +} extern const tt::hal::Configuration unPhone = { - .initBoot = unPhoneInitPower, - .createDisplay = createDisplay, - .sdcard = createUnPhoneSdCard(), - .power = getOrCreatePower, + .initBoot = initBoot, + .createDevices = createDevices, .i2c = { tt::hal::i2c::Configuration { .name = "Internal", diff --git a/Boards/UnPhone/Source/hal/UnPhoneDisplay.cpp b/Boards/UnPhone/Source/devices/Hx8357Display.cpp similarity index 82% rename from Boards/UnPhone/Source/hal/UnPhoneDisplay.cpp rename to Boards/UnPhone/Source/devices/Hx8357Display.cpp index a00e12e7..323f37ae 100644 --- a/Boards/UnPhone/Source/hal/UnPhoneDisplay.cpp +++ b/Boards/UnPhone/Source/devices/Hx8357Display.cpp @@ -1,20 +1,18 @@ -#include "UnPhoneDisplay.h" -#include "UnPhoneDisplayConstants.h" -#include "UnPhoneTouch.h" -#include "UnPhoneFeatures.h" +#include "Hx8357Display.h" +#include "Touch.h" +#include #include -#include #include #include -constexpr auto TAG = "UnPhoneDisplay"; +constexpr auto TAG = "Hx8357Display"; constexpr auto BUFFER_SIZE = (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_DRAW_BUFFER_HEIGHT * LV_COLOR_DEPTH / 8); extern std::shared_ptr unPhoneFeatures; -bool UnPhoneDisplay::start() { +bool Hx8357Display::start() { TT_LOG_I(TAG, "start"); disp_spi_add_device(SPI2_HOST); @@ -27,13 +25,13 @@ bool UnPhoneDisplay::start() { return true; } -bool UnPhoneDisplay::stop() { +bool Hx8357Display::stop() { TT_LOG_I(TAG, "stop"); disp_spi_remove_device(); return true; } -bool UnPhoneDisplay::startLvgl() { +bool Hx8357Display::startLvgl() { TT_LOG_I(TAG, "startLvgl"); if (lvglDisplay != nullptr) { @@ -74,7 +72,7 @@ bool UnPhoneDisplay::startLvgl() { return true; } -bool UnPhoneDisplay::stopLvgl() { +bool Hx8357Display::stopLvgl() { TT_LOG_I(TAG, "stopLvgl"); if (lvglDisplay == nullptr) { @@ -100,7 +98,7 @@ bool UnPhoneDisplay::stopLvgl() { return true; } -std::shared_ptr _Nullable UnPhoneDisplay::getTouchDevice() { +std::shared_ptr _Nullable Hx8357Display::getTouchDevice() { if (touchDevice == nullptr) { touchDevice = std::reinterpret_pointer_cast(createTouch()); TT_LOG_I(TAG, "Created touch device"); @@ -110,10 +108,10 @@ std::shared_ptr _Nullable UnPhoneDisplay::getTouchD } std::shared_ptr createDisplay() { - return std::make_shared(); + return std::make_shared(); } -bool UnPhoneDisplay::UnPhoneDisplayDriver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) { +bool Hx8357Display::Hx8357Driver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) { lv_area_t area = { xStart, yStart, xEnd, yEnd }; hx8357_flush(nullptr, &area, (uint8_t*)pixelData); return true; diff --git a/Boards/UnPhone/Source/hal/UnPhoneDisplay.h b/Boards/UnPhone/Source/devices/Hx8357Display.h similarity index 75% rename from Boards/UnPhone/Source/hal/UnPhoneDisplay.h rename to Boards/UnPhone/Source/devices/Hx8357Display.h index 3d489783..e081a452 100644 --- a/Boards/UnPhone/Source/hal/UnPhoneDisplay.h +++ b/Boards/UnPhone/Source/devices/Hx8357Display.h @@ -7,18 +7,26 @@ #include #include -#include "UnPhoneDisplayConstants.h" - #include -class UnPhoneDisplay : public tt::hal::display::DisplayDevice { +#define UNPHONE_LCD_SPI_HOST SPI2_HOST +#define UNPHONE_LCD_PIN_CS GPIO_NUM_48 +#define UNPHONE_LCD_PIN_DC GPIO_NUM_47 +#define UNPHONE_LCD_PIN_RESET GPIO_NUM_46 +#define UNPHONE_LCD_SPI_FREQUENCY 27000000 +#define UNPHONE_LCD_HORIZONTAL_RESOLUTION 320 +#define UNPHONE_LCD_VERTICAL_RESOLUTION 480 +#define UNPHONE_LCD_DRAW_BUFFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15) +#define UNPHONE_LCD_SPI_TRANSFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15) + +class Hx8357Display : public tt::hal::display::DisplayDevice { uint8_t* _Nullable buffer = nullptr; lv_display_t* _Nullable lvglDisplay = nullptr; std::shared_ptr _Nullable touchDevice; std::shared_ptr _Nullable nativeDisplay; - class UnPhoneDisplayDriver : public tt::hal::display::DisplayDriver { + class Hx8357Driver : public tt::hal::display::DisplayDriver { std::shared_ptr lock = tt::hal::spi::getLock(SPI2_HOST); public: tt::hal::display::ColorFormat getColorFormat() const override { return tt::hal::display::ColorFormat::RGB888; } @@ -52,7 +60,7 @@ public: std::shared_ptr _Nullable getDisplayDriver() override { if (nativeDisplay == nullptr) { - nativeDisplay = std::make_shared(); + nativeDisplay = std::make_shared(); } assert(nativeDisplay != nullptr); return nativeDisplay; diff --git a/Boards/UnPhone/Source/hal/UnPhoneSdCard.cpp b/Boards/UnPhone/Source/devices/SdCard.cpp similarity index 87% rename from Boards/UnPhone/Source/hal/UnPhoneSdCard.cpp rename to Boards/UnPhone/Source/devices/SdCard.cpp index bee87647..749470ee 100644 --- a/Boards/UnPhone/Source/hal/UnPhoneSdCard.cpp +++ b/Boards/UnPhone/Source/devices/SdCard.cpp @@ -1,10 +1,8 @@ -#include "UnPhoneSdCard.h" +#include "SdCard.h" #include #include -#include - #define UNPHONE_SDCARD_PIN_CS GPIO_NUM_43 #define UNPHONE_LCD_PIN_CS GPIO_NUM_48 #define UNPHONE_LORA_PIN_CS GPIO_NUM_44 @@ -12,7 +10,7 @@ using tt::hal::sdcard::SpiSdCardDevice; -std::shared_ptr createUnPhoneSdCard() { +std::shared_ptr createSdCard() { auto configuration = std::make_unique( UNPHONE_SDCARD_PIN_CS, GPIO_NUM_NC, diff --git a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.h b/Boards/UnPhone/Source/devices/SdCard.h similarity index 100% rename from Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.h rename to Boards/UnPhone/Source/devices/SdCard.h diff --git a/Boards/UnPhone/Source/hal/UnPhoneTouch.cpp b/Boards/UnPhone/Source/devices/Touch.cpp similarity index 74% rename from Boards/UnPhone/Source/hal/UnPhoneTouch.cpp rename to Boards/UnPhone/Source/devices/Touch.cpp index b455afd3..6e189068 100644 --- a/Boards/UnPhone/Source/hal/UnPhoneTouch.cpp +++ b/Boards/UnPhone/Source/devices/Touch.cpp @@ -1,11 +1,10 @@ -#include "UnPhoneTouch.h" -#include "UnPhoneDisplayConstants.h" +#include "Touch.h" #include std::shared_ptr createTouch() { auto configuration = std::make_unique( - UNPHONE_LCD_SPI_HOST, + SPI2_HOST, GPIO_NUM_38, 320, 480 diff --git a/Boards/UnPhone/Source/hal/UnPhoneTouch.h b/Boards/UnPhone/Source/devices/Touch.h similarity index 100% rename from Boards/UnPhone/Source/hal/UnPhoneTouch.h rename to Boards/UnPhone/Source/devices/Touch.h diff --git a/Boards/UnPhone/Source/hal/UnPhoneDisplayConstants.h b/Boards/UnPhone/Source/hal/UnPhoneDisplayConstants.h deleted file mode 100644 index 3c3b34b7..00000000 --- a/Boards/UnPhone/Source/hal/UnPhoneDisplayConstants.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#define UNPHONE_LCD_SPI_HOST SPI2_HOST -#define UNPHONE_LCD_PIN_CS GPIO_NUM_48 -#define UNPHONE_LCD_PIN_DC GPIO_NUM_47 -#define UNPHONE_LCD_PIN_RESET GPIO_NUM_46 -#define UNPHONE_LCD_SPI_FREQUENCY 27000000 -#define UNPHONE_LCD_HORIZONTAL_RESOLUTION 320 -#define UNPHONE_LCD_VERTICAL_RESOLUTION 480 -#define UNPHONE_LCD_DRAW_BUFFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15) -#define UNPHONE_LCD_SPI_TRANSFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15) diff --git a/Boards/UnPhone/Source/hal/UnPhoneSdCard.h b/Boards/UnPhone/Source/hal/UnPhoneSdCard.h deleted file mode 100644 index 2ac34751..00000000 --- a/Boards/UnPhone/Source/hal/UnPhoneSdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createUnPhoneSdCard(); diff --git a/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp b/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp index 568ba8e4..a0ba71ef 100644 --- a/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp +++ b/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp @@ -1,13 +1,19 @@ -#include "hal/WaveshareDisplay.h" -#include "hal/WaveshareSdCard.h" +#include "devices/Display.h" +#include "devices/SdCard.h" #include using namespace tt::hal; +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + extern const Configuration waveshare_s3_touch_43 = { - .createDisplay = createDisplay, - .sdcard = createSdCard(), + .createDevices = createDevices, .i2c = { // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) // Note: You could repurpose 1 or more UART interfaces as I2C interfaces diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.cpp b/Boards/WaveshareS3Touch43/Source/devices/Display.cpp similarity index 98% rename from Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.cpp rename to Boards/WaveshareS3Touch43/Source/devices/Display.cpp index 3f86473f..85ff2ede 100644 --- a/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.cpp +++ b/Boards/WaveshareS3Touch43/Source/devices/Display.cpp @@ -1,4 +1,4 @@ -#include "WaveshareDisplay.h" +#include "Display.h" #include #include diff --git a/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.h b/Boards/WaveshareS3Touch43/Source/devices/Display.h similarity index 100% rename from Boards/CYD-JC8048W550C/Source/hal/CydDisplay.h rename to Boards/WaveshareS3Touch43/Source/devices/Display.h diff --git a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.cpp b/Boards/WaveshareS3Touch43/Source/devices/SdCard.cpp similarity index 82% rename from Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.cpp rename to Boards/WaveshareS3Touch43/Source/devices/SdCard.cpp index cca2eebe..a27db36c 100644 --- a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/WaveshareS3Touch43/Source/devices/SdCard.cpp @@ -1,9 +1,6 @@ -#include "CrowPanelSdCard.h" +#include "SdCard.h" #include -#include - -#include using tt::hal::sdcard::SpiSdCardDevice; diff --git a/Boards/M5stackCore2/Source/hal/Core2SdCard.h b/Boards/WaveshareS3Touch43/Source/devices/SdCard.h similarity index 100% rename from Boards/M5stackCore2/Source/hal/Core2SdCard.h rename to Boards/WaveshareS3Touch43/Source/devices/SdCard.h diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h b/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h deleted file mode 100644 index 5a0d81b3..00000000 --- a/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" - -std::shared_ptr createDisplay(); diff --git a/Documentation/ideas.md b/Documentation/ideas.md index e905405c..1a7a270f 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -2,17 +2,21 @@ ## Higher Priority -- External app loading: Check the version of Tactility and check ESP target hardware to check for compatibility. - Fix Development service: when no SD card is present, the app fails to install. Consider installing to `/data` Note: Change app install to "transfer file" functionality. We can have a proper install when we have app packaging. + Note: Consider installation path option in interface +- Update ILI934x to v2.0.1 +- External app loading: Check the version of Tactility and check ESP target hardware to check for compatibility. - Make a URL handler. Use it for handling local files. Match file types with apps. Create some kind of "intent" handler like on Android. The intent can have an action (e.g. view), a URL and an optional bundle. The manifest can provide the intent handler - App packaging +- Bug: GraphicsDemo should check if display supports the DisplayDriver interface (and same for touch) and show an AlertDialog error if there's a problem ## Lower Priority +- Try out ILI9342 https://github.com/jbrilha/esp_lcd_ili9342 - Localize all apps - Support hot-plugging SD card (note: this is not possible if they require the CS pin hack) - Create more unit tests for `tactility` @@ -36,6 +40,7 @@ - Show a warning screen when a user plugs in the SD card on a device that only supports mounting at boot. - Scanning SD card for external apps and auto-register them (in a temporary register?) - Remove flex_flow from app_container in Gui.cpp +- Bug: Turn on WiFi (when testing it wasn't connected/connecting - just active). Open chat. Observe crash. # Nice-to-haves diff --git a/Drivers/AXP2101/Source/Axp2101.h b/Drivers/AXP2101/Source/Axp2101.h index 71b789e3..19515e91 100644 --- a/Drivers/AXP2101/Source/Axp2101.h +++ b/Drivers/AXP2101/Source/Axp2101.h @@ -21,8 +21,8 @@ public: explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {} - std::string getName() const final { return "AXP2101"; } - std::string getDescription() const final { return "Power management with I2C interface."; } + std::string getName() const override { return "AXP2101"; } + std::string getDescription() const override { return "Power management with I2C interface."; } bool setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const; diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3Power.cpp b/Drivers/AXP2101/Source/Axp2101Power.cpp similarity index 78% rename from Boards/M5stackCoreS3/Source/hal/CoreS3Power.cpp rename to Drivers/AXP2101/Source/Axp2101Power.cpp index 6b998aed..48dc5298 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3Power.cpp +++ b/Drivers/AXP2101/Source/Axp2101Power.cpp @@ -1,6 +1,6 @@ -#include "CoreS3Power.h" +#include "Axp2101Power.h" -bool CoreS3Power::supportsMetric(MetricType type) const { +bool Axp2101Power::supportsMetric(MetricType type) const { switch (type) { using enum MetricType; case BatteryVoltage: @@ -14,7 +14,7 @@ bool CoreS3Power::supportsMetric(MetricType type) const { 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) { using enum MetricType; case BatteryVoltage: { @@ -57,7 +57,7 @@ bool CoreS3Power::getMetric(MetricType type, MetricData& data) { } } -bool CoreS3Power::isAllowedToCharge() const { +bool Axp2101Power::isAllowedToCharge() const { bool enabled; if (axpDevice->isChargingEnabled(enabled)) { return enabled; @@ -66,17 +66,6 @@ bool CoreS3Power::isAllowedToCharge() const { } } -void CoreS3Power::setAllowedToCharge(bool canCharge) { +void Axp2101Power::setAllowedToCharge(bool canCharge) { axpDevice->setChargingEnabled(canCharge); } - -static std::shared_ptr power; -extern std::shared_ptr axp2101; - -std::shared_ptr createPower() { - if (power == nullptr) { - power = std::make_shared(axp2101); - } - - return power; -} diff --git a/Boards/M5stackCoreS3/Source/hal/CoreS3Power.h b/Drivers/AXP2101/Source/Axp2101Power.h similarity index 57% rename from Boards/M5stackCoreS3/Source/hal/CoreS3Power.h rename to Drivers/AXP2101/Source/Axp2101Power.h index 4b889ac8..56303a8a 100644 --- a/Boards/M5stackCoreS3/Source/hal/CoreS3Power.h +++ b/Drivers/AXP2101/Source/Axp2101Power.h @@ -7,17 +7,17 @@ using tt::hal::power::PowerDevice; -class CoreS3Power final : public PowerDevice { +class Axp2101Power final : public PowerDevice { std::shared_ptr axpDevice; public: - explicit CoreS3Power(std::shared_ptr axp) : axpDevice(std::move(axp)) {} - ~CoreS3Power() override = default; + explicit Axp2101Power(std::shared_ptr axp) : axpDevice(std::move(axp)) {} + ~Axp2101Power() override = default; - std::string getName() const final { return "AXP2101 Power"; } - std::string getDescription() const final { return "Power management via I2C"; } + std::string getName() const override { return "AXP2101 Power"; } + std::string getDescription() const override { return "Power management via AXP2101 over I2C"; } bool supportsMetric(MetricType type) const override; bool getMetric(MetricType type, MetricData& data) override; @@ -26,5 +26,3 @@ public: bool isAllowedToCharge() const override; void setAllowedToCharge(bool canCharge) override; }; - -std::shared_ptr createPower(); diff --git a/Drivers/XPT2046/Source/Xpt2046Power.cpp b/Drivers/XPT2046/Source/Xpt2046Power.cpp index 45780d15..a2e0126d 100644 --- a/Drivers/XPT2046/Source/Xpt2046Power.cpp +++ b/Drivers/XPT2046/Source/Xpt2046Power.cpp @@ -102,13 +102,3 @@ bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) { return false; } } - -static std::shared_ptr power; - -std::shared_ptr getOrCreatePower() { - if (power == nullptr) { - power = std::make_shared(); - } - return power; -} - diff --git a/Drivers/XPT2046/Source/Xpt2046Power.h b/Drivers/XPT2046/Source/Xpt2046Power.h index 68b1e93e..f14036ee 100644 --- a/Drivers/XPT2046/Source/Xpt2046Power.h +++ b/Drivers/XPT2046/Source/Xpt2046Power.h @@ -18,14 +18,11 @@ class Xpt2046Power : public PowerDevice { public: - ~Xpt2046Power() = default; + ~Xpt2046Power() override = default; std::string getName() const final { return "XPT2046 Power Measurement"; } std::string getDescription() const final { return "Power interface via XPT2046 voltage measurement"; } bool supportsMetric(MetricType type) const override; bool getMetric(MetricType type, MetricData& data) override; - }; - -std::shared_ptr getOrCreatePower(); diff --git a/Drivers/XPT2046/Source/Xpt2046Touch.cpp b/Drivers/XPT2046/Source/Xpt2046Touch.cpp index f8442094..16980d5d 100644 --- a/Drivers/XPT2046/Source/Xpt2046Touch.cpp +++ b/Drivers/XPT2046/Source/Xpt2046Touch.cpp @@ -5,9 +5,6 @@ #include #include -#include - -Xpt2046Touch* Xpt2046Touch::instance = nullptr; bool Xpt2046Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { const esp_lcd_panel_io_spi_config_t io_config = ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG(configuration->spiPinCs); diff --git a/Drivers/XPT2046/Source/Xpt2046Touch.h b/Drivers/XPT2046/Source/Xpt2046Touch.h index e70ba94f..fb813b24 100644 --- a/Drivers/XPT2046/Source/Xpt2046Touch.h +++ b/Drivers/XPT2046/Source/Xpt2046Touch.h @@ -39,8 +39,6 @@ public: private: - static Xpt2046Touch* instance; - std::unique_ptr configuration; bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle) override; diff --git a/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp b/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp index 1ff5cc96..785937d6 100644 --- a/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp +++ b/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp @@ -13,11 +13,11 @@ #include #include -#define TAG "Xpt2046SoftSpi" +constexpr auto* TAG = "Xpt2046SoftSpi"; -#define RERUN_CALIBRATE false -#define CMD_READ_Y 0x90 // Try different commands if these don't work -#define CMD_READ_X 0xD0 // Alternative: 0x98 for Y, 0xD8 for X +constexpr auto RERUN_CALIBRATE = false; +constexpr auto CMD_READ_Y = 0x90; // Try different commands if these don't work +constexpr auto CMD_READ_X = 0xD0; // Alternative: 0x98 for Y, 0xD8 for X struct Calibration { int xMin; @@ -33,8 +33,6 @@ Calibration cal = { .yMax = 1900 }; -Xpt2046SoftSpi* Xpt2046SoftSpi::instance = nullptr; - Xpt2046SoftSpi::Xpt2046SoftSpi(std::unique_ptr inConfiguration) : configuration(std::move(inConfiguration)) { assert(configuration != nullptr); @@ -54,62 +52,7 @@ static void ensureNvsInitialized() { initialized = (result == ESP_OK); } -bool Xpt2046SoftSpi::start(lv_display_t* display) { - ensureNvsInitialized(); - - TT_LOG_I(TAG, "Starting Xpt2046SoftSpi touch driver"); - - // Configure GPIO pins - gpio_config_t io_conf = {}; - - // Configure MOSI, CLK, CS as outputs - io_conf.intr_type = GPIO_INTR_DISABLE; - io_conf.mode = GPIO_MODE_OUTPUT; - io_conf.pin_bit_mask = (1ULL << configuration->mosiPin) | - (1ULL << configuration->clkPin) | - (1ULL << configuration->csPin); - io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; - io_conf.pull_up_en = GPIO_PULLUP_DISABLE; - - if (gpio_config(&io_conf) != ESP_OK) { - TT_LOG_E(TAG, "Failed to configure output pins"); - return false; - } - - // Configure MISO as input - io_conf.mode = GPIO_MODE_INPUT; - io_conf.pin_bit_mask = (1ULL << configuration->misoPin); - io_conf.pull_up_en = GPIO_PULLUP_ENABLE; - - if (gpio_config(&io_conf) != ESP_OK) { - TT_LOG_E(TAG, "Failed to configure input pin"); - return false; - } - - // Initialize pin states - gpio_set_level(configuration->csPin, 1); // CS high - gpio_set_level(configuration->clkPin, 0); // CLK low - gpio_set_level(configuration->mosiPin, 0); // MOSI low - - TT_LOG_I(TAG, "GPIO configured: MOSI=%d, MISO=%d, CLK=%d, CS=%d", configuration->mosiPin, configuration->misoPin, configuration->clkPin, configuration->csPin); - - // Load or perform calibration - bool calibrationValid = true; //loadCalibration() && !RERUN_CALIBRATE; - if (calibrationValid) { - // Check if calibration values are valid (xMin != xMax, yMin != yMax) - if (cal.xMin == cal.xMax || cal.yMin == cal.yMax) { - TT_LOG_W(TAG, "Invalid calibration detected: xMin=%d, xMax=%d, yMin=%d, yMax=%d", cal.xMin, cal.xMax, cal.yMin, cal.yMax); - calibrationValid = false; - } - } - - if (!calibrationValid) { - TT_LOG_W(TAG, "Calibration data not found, invalid, or forced recalibration"); - calibrate(); - saveCalibration(); - } else { - TT_LOG_I(TAG, "Loaded calibration: xMin=%d, yMin=%d, xMax=%d, yMax=%d", cal.xMin, cal.yMin, cal.xMax, cal.yMax); - } +bool Xpt2046SoftSpi::startLvgl(lv_display_t* display) { // Create LVGL input device deviceHandle = lv_indev_create(); @@ -117,27 +60,24 @@ bool Xpt2046SoftSpi::start(lv_display_t* display) { TT_LOG_E(TAG, "Failed to create LVGL input device"); return false; } + lv_indev_set_type(deviceHandle, LV_INDEV_TYPE_POINTER); lv_indev_set_read_cb(deviceHandle, touchReadCallback); lv_indev_set_user_data(deviceHandle, this); - instance = this; TT_LOG_I(TAG, "Xpt2046SoftSpi touch driver started successfully"); return true; } bool Xpt2046SoftSpi::stop() { TT_LOG_I(TAG, "Stopping Xpt2046SoftSpi touch driver"); - instance = nullptr; - cleanup(); - return true; -} -void Xpt2046SoftSpi::cleanup() { + // Stop LVLG if needed if (deviceHandle != nullptr) { - lv_indev_delete(deviceHandle); - deviceHandle = nullptr; + stopLvgl(); } + + return true; } int Xpt2046SoftSpi::readSPI(uint8_t command) { @@ -338,10 +278,64 @@ void Xpt2046SoftSpi::touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) } } -// Zero-argument start bool Xpt2046SoftSpi::start() { - // Default to LVGL-less startup if needed - return startLvgl(nullptr); + ensureNvsInitialized();; + + TT_LOG_I(TAG, "Starting Xpt2046SoftSpi touch driver"); + + // Configure GPIO pins + gpio_config_t io_conf = {}; + + // Configure MOSI, CLK, CS as outputs + io_conf.intr_type = GPIO_INTR_DISABLE; + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = (1ULL << configuration->mosiPin) | + (1ULL << configuration->clkPin) | + (1ULL << configuration->csPin); + io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; + io_conf.pull_up_en = GPIO_PULLUP_DISABLE; + + if (gpio_config(&io_conf) != ESP_OK) { + TT_LOG_E(TAG, "Failed to configure output pins"); + return false; + } + + // Configure MISO as input + io_conf.mode = GPIO_MODE_INPUT; + io_conf.pin_bit_mask = (1ULL << configuration->misoPin); + io_conf.pull_up_en = GPIO_PULLUP_ENABLE; + + if (gpio_config(&io_conf) != ESP_OK) { + TT_LOG_E(TAG, "Failed to configure input pin"); + return false; + } + + // Initialize pin states + gpio_set_level(configuration->csPin, 1); // CS high + gpio_set_level(configuration->clkPin, 0); // CLK low + gpio_set_level(configuration->mosiPin, 0); // MOSI low + + TT_LOG_I(TAG, "GPIO configured: MOSI=%d, MISO=%d, CLK=%d, CS=%d", configuration->mosiPin, configuration->misoPin, configuration->clkPin, configuration->csPin); + + // Load or perform calibration + bool calibrationValid = true; //loadCalibration() && !RERUN_CALIBRATE; + if (calibrationValid) { + // Check if calibration values are valid (xMin != xMax, yMin != yMax) + if (cal.xMin == cal.xMax || cal.yMin == cal.yMax) { + TT_LOG_W(TAG, "Invalid calibration detected: xMin=%d, xMax=%d, yMin=%d, yMax=%d", cal.xMin, cal.xMax, cal.yMin, cal.yMax); + calibrationValid = false; + } + } + + if (!calibrationValid) { + TT_LOG_W(TAG, "Calibration data not found, invalid, or forced recalibration"); + calibrate(); + saveCalibration(); + } else { + TT_LOG_I(TAG, "Loaded calibration: xMin=%d, yMin=%d, xMax=%d, yMax=%d", cal.xMin, cal.yMin, cal.xMax, cal.yMax); + } + + return true; } // Whether this device supports LVGL @@ -349,19 +343,12 @@ bool Xpt2046SoftSpi::supportsLvgl() const { return true; } -// Start with LVGL display -bool Xpt2046SoftSpi::startLvgl(lv_display_t* display) { - return start(display); -} - // Stop LVGL bool Xpt2046SoftSpi::stopLvgl() { - cleanup(); - return true; -} - -// Supports a separate touch driver? Yes/No -bool Xpt2046SoftSpi::supportsTouchDriver() { + if (deviceHandle != nullptr) { + lv_indev_delete(deviceHandle); + deviceHandle = nullptr; + } return true; } diff --git a/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.h b/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.h index 3c820b3a..ae571354 100644 --- a/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.h +++ b/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.h @@ -2,12 +2,8 @@ #include "Tactility/hal/touch/TouchDevice.h" #include "Tactility/hal/touch/TouchDriver.h" -#include #include "lvgl.h" #include -#include -#include -#include #include #include @@ -61,12 +57,10 @@ public: }; private: - static Xpt2046SoftSpi* instance; std::unique_ptr configuration; lv_indev_t* deviceHandle = nullptr; int readSPI(uint8_t command); - void cleanup(); bool loadCalibration(); void saveCalibration(); static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data); @@ -78,24 +72,20 @@ public: std::string getName() const final { return "Xpt2046SoftSpi"; } std::string getDescription() const final { return "Xpt2046 Soft SPI touch driver"; } - bool start() override; // zero-arg start + bool start() override; + bool stop() override; + bool supportsLvgl() const override; bool startLvgl(lv_display_t* display) override; bool stopLvgl() override; - bool stop() override; - bool supportsTouchDriver() override; + + bool supportsTouchDriver() override { return true; } std::shared_ptr getTouchDriver() override; lv_indev_t* getLvglIndev() override { return deviceHandle; } - // Original LVGL-specific start - bool start(lv_display_t* display); - // XPT2046-specific methods Point getTouch(); void calibrate(); void setCalibration(int xMin, int yMin, int xMax, int yMax); bool isTouched(); - - // Static instance access - static Xpt2046SoftSpi* getInstance() { return instance; } }; diff --git a/Tactility/Source/app/systeminfo/SystemInfo.cpp b/Tactility/Source/app/systeminfo/SystemInfo.cpp index f95b0916..cde202a8 100644 --- a/Tactility/Source/app/systeminfo/SystemInfo.cpp +++ b/Tactility/Source/app/systeminfo/SystemInfo.cpp @@ -142,8 +142,10 @@ class SystemInfoApp : public App { lv_obj_set_flex_flow(memory_wrapper, LV_FLEX_FLOW_COLUMN); lv_obj_set_size(memory_wrapper, LV_PCT(100), LV_SIZE_CONTENT); - addMemoryBar(memory_wrapper, "Heap", getHeapTotal() - getHeapFree(), getHeapTotal()); - addMemoryBar(memory_wrapper, "SPI", getSpiTotal() - getSpiFree(), getSpiTotal()); + addMemoryBar(memory_wrapper, "Internal", getHeapTotal() - getHeapFree(), getHeapTotal()); + if (getSpiTotal() > 0) { + addMemoryBar(memory_wrapper, "External", getSpiTotal() - getSpiFree(), getSpiTotal()); + } #if configUSE_TRACE_FACILITY auto* tasks_label = lv_label_create(wrapper); diff --git a/Tactility/Source/hal/Hal.cpp b/Tactility/Source/hal/Hal.cpp index e1d9355b..eb20185f 100644 --- a/Tactility/Source/hal/Hal.cpp +++ b/Tactility/Source/hal/Hal.cpp @@ -7,6 +7,8 @@ #include "Tactility/hal/spi/SpiInit.h" #include "Tactility/hal/uart/UartInit.h" +#include +#include #include namespace tt::hal { @@ -35,6 +37,16 @@ void registerDevices(const Configuration& configuration) { auto devices = configuration.createDevices(); for (auto& device : devices) { registerDevice(device); + + // Register attached devices + if (device->getType() == Device::Type::Display) { + const auto display = std::static_pointer_cast(device); + assert(display != nullptr); + const std::shared_ptr touch = display->getTouchDevice(); + if (touch != nullptr) { + registerDevice(touch); + } + } } } diff --git a/Tactility/Source/service/wifi/WifiBootSplashInit.cpp b/Tactility/Source/service/wifi/WifiBootSplashInit.cpp index 3d92da5a..eaea7999 100644 --- a/Tactility/Source/service/wifi/WifiBootSplashInit.cpp +++ b/Tactility/Source/service/wifi/WifiBootSplashInit.cpp @@ -33,6 +33,7 @@ struct ApProperties { static void importWifiAp(const std::string& filePath) { std::map map; if (!file::loadPropertiesFile(filePath, map)) { + TT_LOG_E(TAG, "Failed to load AP properties at %s", filePath.c_str()); return; } @@ -44,6 +45,7 @@ static void importWifiAp(const std::string& filePath) { const auto ssid = ssid_iterator->second; if (!settings::contains(ssid)) { + const auto password_iterator = map.find(AP_PROPERTIES_KEY_PASSWORD); const auto password = password_iterator == map.end() ? "" : password_iterator->second; @@ -78,10 +80,10 @@ static void importWifiAp(const std::string& filePath) { } static void importWifiApSettings(std::shared_ptr sdcard) { - auto lock = sdcard->getLock()->asScopedLock(); - lock.lock(); auto path = file::getChildPath(sdcard->getMountPath(), "settings"); + auto lock = sdcard->getLock()->asScopedLock(); + lock.lock(); std::vector dirent_list; if (file::scandir(path, dirent_list, [](const dirent* entry) { switch (entry->d_type) { @@ -102,6 +104,7 @@ static void importWifiApSettings(std::shared_ptr sdca }, nullptr) == 0) { return; } + lock.unlock(); if (dirent_list.empty()) { TT_LOG_W(TAG, "No AP files found at %s", sdcard->getMountPath().c_str());