#include "YellowDisplay.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; static std::shared_ptr createTouch() { auto configuration = std::make_unique( CYD_TOUCH_MOSI_PIN, CYD_TOUCH_MISO_PIN, CYD_TOUCH_SCK_PIN, CYD_TOUCH_CS_PIN, CYD2432S028R_LCD_HORIZONTAL_RESOLUTION, // 240 CYD2432S028R_LCD_VERTICAL_RESOLUTION, // 320 false, // swapXY true, // mirrorX false // mirrorY ); // Allocate the driver touch = std::make_unique(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 }); } std::shared_ptr createDisplay() { auto touch = createTouch(); auto configuration = std::make_unique( CYD2432S028R_LCD_SPI_HOST, CYD2432S028R_LCD_PIN_CS, CYD2432S028R_LCD_PIN_DC, CYD2432S028R_LCD_HORIZONTAL_RESOLUTION, CYD2432S028R_LCD_VERTICAL_RESOLUTION, touch, false, // swapXY true, // mirrorX false, // mirrorY false, CYD2432S028R_LCD_DRAW_BUFFER_SIZE ); configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; auto display = std::make_shared(std::move(configuration)); return std::reinterpret_pointer_cast(display); }