hello, sirs,
I’m trying to show images on a LCD 1.28 display。It’s ok to show text with label,but it does not work with images。
the code goes like this:
extern const char close_start asm(“_binary_close_bmp_start”);
extern const char close_end asm(“_binary_close_bmp_end”);
spi_bus_config_t bus_config = {};
bus_config.sclk_io_num = DISPLAY_SCLK_PIN;
bus_config.mosi_io_num = DISPLAY_MOSI_PIN;
bus_config.miso_io_num = -1;
bus_config.quadhd_io_num = -1;
bus_config.quadwp_io_num = -1;
bus_config.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &bus_config, SPI_DMA_CH_AUTO)); // Enable the DMA feature
const esp_lcd_panel_io_spi_config_t io_config = {
.cs_gpio_num = DISPLAY_LCD_CS_PIN,
.dc_gpio_num = DISPLAY_LCD_DC_PIN,
.spi_mode = 0,
.pclk_hz = 80 * 1000 * 1000,
.trans_queue_depth = 10,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &io_config, &panel_io_));
ESP_LOGI(TAG, "Initialize LVGL");
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
//port_cfg.task_stack = 1024 * 30;
//port_cfg.task_affinity = 1;
lvgl_port_init(&port_cfg);
ESP_LOGI(TAG, "Install GC9A01 panel driver");
esp_lcd_panel_dev_config_t panel_config = {};
panel_config.reset_gpio_num = GPIO_NUM_42; // TODO: move to config
panel_config.bits_per_pixel = 16;
//panel_config.color_space = ESP_LCD_COLOR_SPACE_RGB;
panel_config.rgb_endian = LCD_RGB_ENDIAN_RGB;
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01((esp_lcd_panel_io_handle_t)panel_io, &panel_config, &panel_));
ESP_LOGI(TAG, "gc9a01 driver installed");
// Reset the display
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_));
if (esp_lcd_panel_init(panel_) != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize display");
return;
}
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_, true));
// Set the display to on
ESP_LOGI(TAG, "Turning display on");
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true));
ESP_LOGI(TAG, "Adding LCD screen");
const lvgl_port_display_cfg_t display_cfg = {
.io_handle = panel_io_,
.panel_handle = panel_,
.control_handle = nullptr,
.buffer_size = static_cast<uint32_t>(width_ * height_),
.double_buffer = false,
.trans_size = static_cast<uint32_t>(width_ * 10),
.hres = static_cast<uint32_t>(width_),
.vres = static_cast<uint32_t>(height_),
.monochrome = false,
.rotation = {
.swap_xy = false,
.mirror_x = mirror_x_,
.mirror_y = mirror_y_,
},
.color_format = LV_COLOR_FORMAT_RGB565,
.flags = {
.buff_dma = 0,
.buff_spiram = 1, // TODO: figure out why dma doesn't work
.sw_rotate = 0,
.swap_bytes = 1,
.full_refresh = 0,
.direct_mode = 0,
},
};
disp_ = lvgl_port_add_disp(&display_cfg);
static lv_img_dsc_t image_open_src;
image_open_src.data_size = close_end - close_start;
image_open_src.data = reinterpret_cast<const uint8_t*>(close_start);
lv_obj_t* image_open = lv_img_create(screen);
lv_img_set_src(image_open, &image_open_src);
lv_obj_set_align(image_open, LV_ALIGN_CENTER);
lv_obj_set_size(image_open, width_, height_);
I’m stucked here with no clue.