klips/esp/cpp/07_lcd-panel/main/panel_device.h

66 lines
1.8 KiB
C
Raw Normal View History

2025-02-15 10:11:49 -05:00
#ifndef PANEL_DEVICE_H
#define PANEL_DEVICE_H
#include <esp_lcd_panel_dev.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lcd_panel_ssd1306.h>
#include "display/lv_display.h"
#define LVGL_PALETTE_SIZE 8
template<typename T>
2025-02-15 14:04:08 -05:00
class PanelDeviceInterface {
2025-02-15 10:11:49 -05:00
public:
2025-02-15 14:04:08 -05:00
PanelDeviceInterface(size_t width, size_t height) : width_(width), height_(height) { }
2025-02-15 10:11:49 -05:00
2025-02-15 14:04:08 -05:00
~PanelDeviceInterface() = default;
2025-02-15 10:11:49 -05:00
[[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<typename T>
2025-02-15 14:04:08 -05:00
void PanelDeviceInterface<T>::create_panel(esp_lcd_panel_dev_config_t &config,
esp_lcd_panel_io_handle_t io,
esp_lcd_panel_handle_t &panel)
2025-02-15 10:11:49 -05:00
{
// 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