forked from xiaozhi/xiaozhi-esp32
增加LCD屏幕类型\RGB屏参考\增加鱼鹰3.13寸LCD开发板 (#191)
* 增加LCD屏幕类型\RGB屏参考\增加鱼鹰3.13寸LCD开发板 1、增加LCD屏幕类型判断,lvgl port对不同屏幕初始化不一样 2、增加RGB屏使用参考 3、增加鱼鹰3.13寸LCD开发板 * Update lcd_display.h * 修改xingzhi两个board为SpiLcdDisplay
This commit is contained in:
@@ -16,12 +16,11 @@
|
||||
|
||||
LV_FONT_DECLARE(font_awesome_30_4);
|
||||
|
||||
LcdDisplay::LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
SpiLcdDisplay::SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts)
|
||||
: panel_io_(panel_io), panel_(panel), backlight_pin_(backlight_pin), backlight_output_invert_(backlight_output_invert),
|
||||
fonts_(fonts) {
|
||||
: LcdDisplay(panel_io, panel, backlight_pin, backlight_output_invert, fonts) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
@@ -98,6 +97,86 @@ LcdDisplay::LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_
|
||||
SetBacklight(brightness_);
|
||||
}
|
||||
|
||||
// RGB LCD实现
|
||||
RgbLcdDisplay::RgbLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts)
|
||||
: LcdDisplay(panel_io, panel, backlight_pin, backlight_output_invert, fonts) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
// 创建背光渐变定时器
|
||||
const esp_timer_create_args_t timer_args = {
|
||||
.callback = [](void* arg) {
|
||||
LcdDisplay* display = static_cast<LcdDisplay*>(arg);
|
||||
display->OnBacklightTimer();
|
||||
},
|
||||
.arg = this,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
.name = "backlight_timer",
|
||||
.skip_unhandled_events = true,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_timer_create(&timer_args, &backlight_timer_));
|
||||
InitializeBacklight(backlight_pin);
|
||||
|
||||
// draw white
|
||||
std::vector<uint16_t> buffer(width_, 0xFFFF);
|
||||
for (int y = 0; y < height_; y++) {
|
||||
esp_lcd_panel_draw_bitmap(panel_, 0, y, width_, y + 1, buffer.data());
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Initialize LVGL library");
|
||||
lv_init();
|
||||
|
||||
ESP_LOGI(TAG, "Initialize LVGL port");
|
||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||
lvgl_port_init(&port_cfg);
|
||||
|
||||
ESP_LOGI(TAG, "Adding LCD screen");
|
||||
const lvgl_port_display_cfg_t display_cfg = {
|
||||
.io_handle = panel_io_,
|
||||
.panel_handle = panel_,
|
||||
.buffer_size = static_cast<uint32_t>(width_ * 10),
|
||||
.double_buffer = true,
|
||||
.hres = static_cast<uint32_t>(width_),
|
||||
.vres = static_cast<uint32_t>(height_),
|
||||
.rotation = {
|
||||
.swap_xy = swap_xy,
|
||||
.mirror_x = mirror_x,
|
||||
.mirror_y = mirror_y,
|
||||
},
|
||||
.flags = {
|
||||
.buff_dma = 1,
|
||||
.swap_bytes = 0,
|
||||
.full_refresh = 1,
|
||||
.direct_mode = 1,
|
||||
},
|
||||
};
|
||||
|
||||
const lvgl_port_display_rgb_cfg_t rgb_cfg = {
|
||||
.flags = {
|
||||
.bb_mode = true,
|
||||
.avoid_tearing = true,
|
||||
}
|
||||
};
|
||||
|
||||
display_ = lvgl_port_add_disp_rgb(&display_cfg, &rgb_cfg);
|
||||
if (display_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to add RGB display");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset_x != 0 || offset_y != 0) {
|
||||
lv_display_set_offset(display_, offset_x, offset_y);
|
||||
}
|
||||
|
||||
SetupUI();
|
||||
|
||||
SetBacklight(brightness_);
|
||||
}
|
||||
|
||||
LcdDisplay::~LcdDisplay() {
|
||||
if (backlight_timer_ != nullptr) {
|
||||
esp_timer_stop(backlight_timer_);
|
||||
|
||||
@@ -31,23 +31,76 @@ protected:
|
||||
|
||||
esp_timer_handle_t backlight_timer_ = nullptr;
|
||||
uint8_t current_brightness_ = 0;
|
||||
void OnBacklightTimer();
|
||||
void InitializeBacklight(gpio_num_t backlight_pin);
|
||||
|
||||
virtual void SetupUI();
|
||||
virtual bool Lock(int timeout_ms = 0) override;
|
||||
virtual void Unlock() override;
|
||||
|
||||
public:
|
||||
protected:
|
||||
// 添加protected构造函数
|
||||
LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts);
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
DisplayFonts fonts)
|
||||
: panel_io_(panel_io), panel_(panel),
|
||||
backlight_pin_(backlight_pin), backlight_output_invert_(backlight_output_invert),
|
||||
fonts_(fonts) {}
|
||||
|
||||
public:
|
||||
~LcdDisplay();
|
||||
|
||||
virtual void OnBacklightTimer();
|
||||
virtual void SetEmotion(const char* emotion) override;
|
||||
virtual void SetIcon(const char* icon) override;
|
||||
virtual void SetBacklight(uint8_t brightness) override;
|
||||
};
|
||||
|
||||
// RGB LCD显示器
|
||||
class RgbLcdDisplay : public LcdDisplay {
|
||||
public:
|
||||
RgbLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts);
|
||||
};
|
||||
|
||||
// MIPI LCD显示器
|
||||
class MipiLcdDisplay : public LcdDisplay {
|
||||
public:
|
||||
MipiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts);
|
||||
};
|
||||
|
||||
// // SPI LCD显示器
|
||||
class SpiLcdDisplay : public LcdDisplay {
|
||||
public:
|
||||
SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts);
|
||||
};
|
||||
|
||||
// QSPI LCD显示器
|
||||
class QspiLcdDisplay : public LcdDisplay {
|
||||
public:
|
||||
QspiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts);
|
||||
};
|
||||
|
||||
// MCU8080 LCD显示器
|
||||
class Mcu8080LcdDisplay : public LcdDisplay {
|
||||
public:
|
||||
Mcu8080LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy,
|
||||
DisplayFonts fonts);
|
||||
};
|
||||
#endif // LCD_DISPLAY_H
|
||||
|
||||
Reference in New Issue
Block a user