#ifndef PANEL_DEVICE_H #define PANEL_DEVICE_H #include #include #include #include "display/lv_display.h" #define LVGL_PALETTE_SIZE 8 template class PanelDeviceInterface { public: PanelDeviceInterface(size_t width, size_t height) : width_(width), height_(height) { } ~PanelDeviceInterface() = default; [[nodiscard]] size_t get_width() const { return width_; } [[nodiscard]] size_t get_height() const { return height_; } [[nodiscard]] size_t get_area() const { return width_ * height_; } [[nodiscard]] size_t get_draw_buffer_size() const { // LVGL reserves 2x4 bytes in the buffer to be used as a palette. return width_ * height_ / 8 + LVGL_PALETTE_SIZE; } [[nodiscard]] lv_display_t *create_display() const { return lv_display_create(width_, height_); } [[nodiscard]] T &get_vendor_config() const { return vendor_config_; } void create_panel(esp_lcd_panel_dev_config_t &panel_config, esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t &panel_handle); private: size_t width_; size_t height_; protected: T vendor_config_; }; template void PanelDeviceInterface::create_panel(esp_lcd_panel_dev_config_t &config, esp_lcd_panel_io_handle_t io, esp_lcd_panel_handle_t &panel) { // If the passed handle is already allocated, delete it. if (panel != nullptr) { esp_lcd_panel_del(panel); } // Set the vendor config and allocate a new panel handle. config.vendor_config = &vendor_config_; // TODO: This needs moved to SSD1306 ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io, &config, &panel)); } #endif // PANEL_DEVICE_H