lvgl canvas 图形被截断
Posted: Mon Dec 06, 2021 4:19 am
我用的中景园st7789 240x240的屏幕,canvas总是截掉80个像素的图片,我画一个图形放在0,0只显示一部分,然后canvas坐标慢慢往下(默认坐标系下y增加)就显示得越来越多。我并没有用任何变换。
void init_display(QueueHandle_t *msg_queue) {
queue = msg_queue;
esp_err_t ret = ESP_OK;
spi_config_t bus_conf = { .miso_io_num = SPI2_MISO,
.mosi_io_num = SPI2_MOSI, .sclk_io_num = SPI2_SCK,
.max_transfer_sz = 2 * 240 * 240 + 10, };
spi_bus_handle_t s_spi2_bus_handle = spi_bus_create(SPI2_HOST, &bus_conf);
scr_interface_spi_config_t spi_lcd_cfg = { .spi_bus = s_spi2_bus_handle,
.pin_num_cs = LCD_SPI_CS_PIN, .pin_num_dc = LCD_SPI_DC_PIN,
.clk_freq = LCD_SPI_CLOCK_FREQ, .swap_data = true, };
scr_interface_driver_t *iface_drv;
scr_interface_create(SCREEN_IFACE_SPI, &spi_lcd_cfg, &iface_drv);
ret = scr_find_driver(SCREEN_CONTROLLER_ST7789, &g_lcd);
if (ESP_OK != ret) {
ESP_LOGE(TAG, "screen find failed");
return;
}
scr_controller_config_t lcd_cfg =
{ .interface_drv = iface_drv, .pin_num_rst = LCD_SPI_RESET_PIN,
.pin_num_bckl = LCD_SPI_BL_PIN, .rst_active_level = 0,
.bckl_active_level = 1, .offset_hor = 0, .offset_ver = 0,
.width = 240, .height = 240, .rotate = SCR_DIR_LRTB, };
ret = g_lcd.init(&lcd_cfg);
if (ESP_OK != ret) {
ESP_LOGE(TAG, "screen initialize failed");
return;
}
g_lcd.get_info(&g_lcd_info);
ESP_LOGI(TAG, "Screen name:%s | width:%d | height:%d", g_lcd_info.name,
g_lcd_info.width, g_lcd_info.height);
lvgl_init(&g_lcd, NULL);
lv_style_t bg_style;
lv_style_init(&bg_style);
lv_style_set_bg_color(&bg_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_add_style(lv_scr_act(), LV_OBJ_PART_MAIN, &bg_style);
create_canvas();
// main_page();
}
void create_canvas() {
canvas = lv_canvas_create(lv_scr_act(), NULL);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT,
LV_IMG_CF_TRUE_COLOR);
lv_obj_align(canvas, NULL, LV_ALIGN_IN_TOP_LEFT,0, 40);
lv_canvas_fill_bg(canvas, LV_COLOR_BLACK, LV_OPA_COVER);
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.radius = 40;
rect_dsc.bg_opa = LV_OPA_TRANSP;
rect_dsc.border_width = 2;
rect_dsc.border_opa = LV_OPA_90;
rect_dsc.border_color = LV_COLOR_MAKE(0x00, 0xFF, 0x00);
lv_canvas_draw_rect(canvas, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, &rect_dsc);
}
第一次用lvgl 小白一个
请问这会是我代码的问题吗?void init_display(QueueHandle_t *msg_queue) {
queue = msg_queue;
esp_err_t ret = ESP_OK;
spi_config_t bus_conf = { .miso_io_num = SPI2_MISO,
.mosi_io_num = SPI2_MOSI, .sclk_io_num = SPI2_SCK,
.max_transfer_sz = 2 * 240 * 240 + 10, };
spi_bus_handle_t s_spi2_bus_handle = spi_bus_create(SPI2_HOST, &bus_conf);
scr_interface_spi_config_t spi_lcd_cfg = { .spi_bus = s_spi2_bus_handle,
.pin_num_cs = LCD_SPI_CS_PIN, .pin_num_dc = LCD_SPI_DC_PIN,
.clk_freq = LCD_SPI_CLOCK_FREQ, .swap_data = true, };
scr_interface_driver_t *iface_drv;
scr_interface_create(SCREEN_IFACE_SPI, &spi_lcd_cfg, &iface_drv);
ret = scr_find_driver(SCREEN_CONTROLLER_ST7789, &g_lcd);
if (ESP_OK != ret) {
ESP_LOGE(TAG, "screen find failed");
return;
}
scr_controller_config_t lcd_cfg =
{ .interface_drv = iface_drv, .pin_num_rst = LCD_SPI_RESET_PIN,
.pin_num_bckl = LCD_SPI_BL_PIN, .rst_active_level = 0,
.bckl_active_level = 1, .offset_hor = 0, .offset_ver = 0,
.width = 240, .height = 240, .rotate = SCR_DIR_LRTB, };
ret = g_lcd.init(&lcd_cfg);
if (ESP_OK != ret) {
ESP_LOGE(TAG, "screen initialize failed");
return;
}
g_lcd.get_info(&g_lcd_info);
ESP_LOGI(TAG, "Screen name:%s | width:%d | height:%d", g_lcd_info.name,
g_lcd_info.width, g_lcd_info.height);
lvgl_init(&g_lcd, NULL);
lv_style_t bg_style;
lv_style_init(&bg_style);
lv_style_set_bg_color(&bg_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_add_style(lv_scr_act(), LV_OBJ_PART_MAIN, &bg_style);
create_canvas();
// main_page();
}
void create_canvas() {
canvas = lv_canvas_create(lv_scr_act(), NULL);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT,
LV_IMG_CF_TRUE_COLOR);
lv_obj_align(canvas, NULL, LV_ALIGN_IN_TOP_LEFT,0, 40);
lv_canvas_fill_bg(canvas, LV_COLOR_BLACK, LV_OPA_COVER);
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.radius = 40;
rect_dsc.bg_opa = LV_OPA_TRANSP;
rect_dsc.border_width = 2;
rect_dsc.border_opa = LV_OPA_90;
rect_dsc.border_color = LV_COLOR_MAKE(0x00, 0xFF, 0x00);
lv_canvas_draw_rect(canvas, 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, &rect_dsc);
}
第一次用lvgl 小白一个