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

66 lines
1.7 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>
2025-02-15 17:12:06 -05:00
#include <driver/i2c_types.h>
#include <esp_lcd_panel_io.h>
#include <esp_log.h>
2025-02-15 10:11:49 -05:00
#include "display/lv_display.h"
#define LVGL_PALETTE_SIZE 8
2025-02-15 17:12:06 -05:00
static const char *TAG = "lcd-panel";
2025-02-15 10:11:49 -05:00
2025-02-15 17:12:06 -05:00
class IPanelDevice {
public:
explicit IPanelDevice(i2c_master_bus_handle_t i2c,
int reset_gpio_num,
esp_lcd_panel_io_i2c_config_t io_config) :
reset_gpio_num_(reset_gpio_num),
i2c_bus_(i2c),
io_config_(io_config) { }
2025-02-15 10:11:49 -05:00
2025-02-15 17:12:06 -05:00
virtual ~IPanelDevice() = default;
2025-02-15 10:11:49 -05:00
2025-02-15 17:12:06 -05:00
[[nodiscard]] lv_display_t *create_display() const
2025-02-15 10:11:49 -05:00
{
2025-02-15 17:12:06 -05:00
auto display = lv_display_create(width_, height_);
assert(display);
return display;
2025-02-15 10:11:49 -05:00
}
2025-02-15 17:12:06 -05:00
void 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
{
2025-02-15 17:12:06 -05:00
// If the passed handle is already allocated, delete it.
if (panel != nullptr) {
ESP_LOGI(TAG, "Removing unused panel");
esp_lcd_panel_del(panel);
}
ESP_LOGI(TAG, "Install SSD1306 panel driver");
init_panel(config, io, panel);
2025-02-15 10:11:49 -05:00
}
2025-02-15 17:12:06 -05:00
int32_t width_;
int32_t height_;
int reset_gpio_num_;
2025-02-15 10:11:49 -05:00
2025-02-15 17:12:06 -05:00
// LVGL reserves 2x4 bytes in the buffer to be used as a palette.
size_t lv_buf_size_;
// TODO: Can we use a static accessor in I2C instead?
i2c_master_bus_handle_t i2c_bus_;
2025-02-15 10:11:49 -05:00
2025-02-15 17:12:06 -05:00
esp_lcd_panel_io_i2c_config_t io_config_;
2025-02-15 10:11:49 -05:00
2025-02-15 17:12:06 -05:00
private:
virtual void init_panel(esp_lcd_panel_dev_config_t &config,
esp_lcd_panel_io_handle_t io,
esp_lcd_panel_handle_t &panel) = 0;
2025-02-15 10:11:49 -05:00
};
#endif // PANEL_DEVICE_H