mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'example/lcd_spi_1' into 'master'
Change LCD example gc9a01 to universal SPI LCD example with SPI touch Closes IDF-5399 See merge request espressif/esp-idf!19221
This commit is contained in:
commit
7d5eb1fc01
@ -1,2 +0,0 @@
|
||||
idf_component_register(SRCS "esp_lcd_panel_gc9a01.c" "gc9a01_example_main.c" "lvgl_demo_ui.c"
|
||||
INCLUDE_DIRS ".")
|
@ -1,323 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_lcd_panel_interface.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_commands.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
static const char *TAG = "gc9a01";
|
||||
|
||||
static esp_err_t panel_gc9a01_del(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_gc9a01_reset(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_gc9a01_init(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_gc9a01_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data);
|
||||
static esp_err_t panel_gc9a01_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
|
||||
static esp_err_t panel_gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
static esp_err_t panel_gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
|
||||
static esp_err_t panel_gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
|
||||
static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool off);
|
||||
|
||||
typedef struct {
|
||||
esp_lcd_panel_t base;
|
||||
esp_lcd_panel_io_handle_t io;
|
||||
int reset_gpio_num;
|
||||
bool reset_level;
|
||||
int x_gap;
|
||||
int y_gap;
|
||||
unsigned int bits_per_pixel;
|
||||
uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
|
||||
uint8_t colmod_cal; // save surrent value of LCD_CMD_COLMOD register
|
||||
} gc9a01_panel_t;
|
||||
|
||||
esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
gc9a01_panel_t *gc9a01 = NULL;
|
||||
ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||
gc9a01 = calloc(1, sizeof(gc9a01_panel_t));
|
||||
ESP_GOTO_ON_FALSE(gc9a01, ESP_ERR_NO_MEM, err, TAG, "no mem for gc9a01 panel");
|
||||
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_config_t io_conf = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed");
|
||||
}
|
||||
|
||||
switch (panel_dev_config->color_space) {
|
||||
case ESP_LCD_COLOR_SPACE_RGB:
|
||||
gc9a01->madctl_val = 0;
|
||||
break;
|
||||
case ESP_LCD_COLOR_SPACE_BGR:
|
||||
gc9a01->madctl_val |= LCD_CMD_BGR_BIT;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color space");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (panel_dev_config->bits_per_pixel) {
|
||||
case 16:
|
||||
gc9a01->colmod_cal = 0x55;
|
||||
break;
|
||||
case 18:
|
||||
gc9a01->colmod_cal = 0x66;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
|
||||
break;
|
||||
}
|
||||
|
||||
gc9a01->io = io;
|
||||
gc9a01->bits_per_pixel = panel_dev_config->bits_per_pixel;
|
||||
gc9a01->reset_gpio_num = panel_dev_config->reset_gpio_num;
|
||||
gc9a01->reset_level = panel_dev_config->flags.reset_active_high;
|
||||
gc9a01->base.del = panel_gc9a01_del;
|
||||
gc9a01->base.reset = panel_gc9a01_reset;
|
||||
gc9a01->base.init = panel_gc9a01_init;
|
||||
gc9a01->base.draw_bitmap = panel_gc9a01_draw_bitmap;
|
||||
gc9a01->base.invert_color = panel_gc9a01_invert_color;
|
||||
gc9a01->base.set_gap = panel_gc9a01_set_gap;
|
||||
gc9a01->base.mirror = panel_gc9a01_mirror;
|
||||
gc9a01->base.swap_xy = panel_gc9a01_swap_xy;
|
||||
gc9a01->base.disp_on_off = panel_gc9a01_disp_on_off;
|
||||
*ret_panel = &(gc9a01->base);
|
||||
ESP_LOGD(TAG, "new gc9a01 panel @%p", gc9a01);
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (gc9a01) {
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(panel_dev_config->reset_gpio_num);
|
||||
}
|
||||
free(gc9a01);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_del(esp_lcd_panel_t *panel)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
|
||||
if (gc9a01->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(gc9a01->reset_gpio_num);
|
||||
}
|
||||
ESP_LOGD(TAG, "del gc9a01 panel @%p", gc9a01);
|
||||
free(gc9a01);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_reset(esp_lcd_panel_t *panel)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
|
||||
// perform hardware reset
|
||||
if (gc9a01->reset_gpio_num >= 0) {
|
||||
gpio_set_level(gc9a01->reset_gpio_num, gc9a01->reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(gc9a01->reset_gpio_num, !gc9a01->reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
} else { // perform software reset
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0);
|
||||
vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5ms before sending new command
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t cmd;
|
||||
uint8_t data[16];
|
||||
uint8_t data_bytes; // Length of data in above data array; 0xFF = end of cmds.
|
||||
} lcd_init_cmd_t;
|
||||
|
||||
static const lcd_init_cmd_t vendor_specific_init[] = {
|
||||
// Enable Inter Register
|
||||
{0xfe, {0}, 0},
|
||||
{0xef, {0}, 0},
|
||||
{0xeb, {0x14}, 1},
|
||||
{0x84, {0x60}, 1},
|
||||
{0x85, {0xff}, 1},
|
||||
{0x86, {0xff}, 1},
|
||||
{0x87, {0xff}, 1},
|
||||
{0x8e, {0xff}, 1},
|
||||
{0x8f, {0xff}, 1},
|
||||
{0x88, {0x0a}, 1},
|
||||
{0x89, {0x23}, 1},
|
||||
{0x8a, {0x00}, 1},
|
||||
{0x8b, {0x80}, 1},
|
||||
{0x8c, {0x01}, 1},
|
||||
{0x8d, {0x03}, 1},
|
||||
{0x90, {0x08, 0x08, 0x08, 0x08}, 4},
|
||||
{0xff, {0x60, 0x01, 0x04}, 3},
|
||||
{0xC3, {0x13}, 1},
|
||||
{0xC4, {0x13}, 1},
|
||||
{0xC9, {0x30}, 1},
|
||||
{0xbe, {0x11}, 1},
|
||||
{0xe1, {0x10, 0x0e}, 2},
|
||||
{0xdf, {0x21, 0x0c, 0x02}, 3},
|
||||
// Set gamma
|
||||
{0xF0, {0x45, 0x09, 0x08, 0x08, 0x26, 0x2a}, 6},
|
||||
{0xF1, {0x43, 0x70, 0x72, 0x36, 0x37, 0x6f}, 6},
|
||||
{0xF2, {0x45, 0x09, 0x08, 0x08, 0x26, 0x2a}, 6},
|
||||
{0xF3, {0x43, 0x70, 0x72, 0x36, 0x37, 0x6f}, 6},
|
||||
{0xed, {0x1b, 0x0b}, 2},
|
||||
{0xae, {0x77}, 1},
|
||||
{0xcd, {0x63}, 1},
|
||||
{0x70, {0x07, 0x07, 0x04, 0x0e, 0x0f, 0x09, 0x07, 0x08, 0x03}, 9},
|
||||
{0xE8, {0x34}, 1}, // 4 dot inversion
|
||||
{0x60, {0x38, 0x0b, 0x6D, 0x6D, 0x39, 0xf0, 0x6D, 0x6D}, 8},
|
||||
{0x61, {0x38, 0xf4, 0x6D, 0x6D, 0x38, 0xf7, 0x6D, 0x6D}, 8},
|
||||
{0x62, {0x38, 0x0D, 0x71, 0xED, 0x70, 0x70, 0x38, 0x0F, 0x71, 0xEF, 0x70, 0x70}, 12},
|
||||
{0x63, {0x38, 0x11, 0x71, 0xF1, 0x70, 0x70, 0x38, 0x13, 0x71, 0xF3, 0x70, 0x70}, 12},
|
||||
{0x64, {0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07}, 7},
|
||||
{0x66, {0x3C, 0x00, 0xCD, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00}, 10},
|
||||
{0x67, {0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98}, 10},
|
||||
{0x74, {0x10, 0x45, 0x80, 0x00, 0x00, 0x4E, 0x00}, 7},
|
||||
{0x98, {0x3e, 0x07}, 2},
|
||||
{0x99, {0x3e, 0x07}, 2},
|
||||
{0, {0}, 0xff},
|
||||
};
|
||||
|
||||
static esp_err_t panel_gc9a01_init(esp_lcd_panel_t *panel)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
|
||||
// LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
gc9a01->madctl_val,
|
||||
}, 1);
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) {
|
||||
gc9a01->colmod_cal,
|
||||
}, 1);
|
||||
|
||||
// vendor specific initialization, it can be different between manufacturers
|
||||
// should consult the LCD supplier for initialization sequence code
|
||||
int cmd = 0;
|
||||
while (vendor_specific_init[cmd].data_bytes != 0xff) {
|
||||
esp_lcd_panel_io_tx_param(io, vendor_specific_init[cmd].cmd, vendor_specific_init[cmd].data, vendor_specific_init[cmd].data_bytes & 0x1F);
|
||||
cmd++;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position");
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
|
||||
x_start += gc9a01->x_gap;
|
||||
x_end += gc9a01->x_gap;
|
||||
y_start += gc9a01->y_gap;
|
||||
y_end += gc9a01->y_gap;
|
||||
|
||||
// define an area of frame memory where MCU can access
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_CASET, (uint8_t[]) {
|
||||
(x_start >> 8) & 0xFF,
|
||||
x_start & 0xFF,
|
||||
((x_end - 1) >> 8) & 0xFF,
|
||||
(x_end - 1) & 0xFF,
|
||||
}, 4);
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_RASET, (uint8_t[]) {
|
||||
(y_start >> 8) & 0xFF,
|
||||
y_start & 0xFF,
|
||||
((y_end - 1) >> 8) & 0xFF,
|
||||
(y_end - 1) & 0xFF,
|
||||
}, 4);
|
||||
// transfer frame buffer
|
||||
size_t len = (x_end - x_start) * (y_end - y_start) * gc9a01->bits_per_pixel / 8;
|
||||
esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR, color_data, len);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
int command = 0;
|
||||
if (invert_color_data) {
|
||||
command = LCD_CMD_INVON;
|
||||
} else {
|
||||
command = LCD_CMD_INVOFF;
|
||||
}
|
||||
esp_lcd_panel_io_tx_param(io, command, NULL, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
if (mirror_x) {
|
||||
gc9a01->madctl_val |= LCD_CMD_MX_BIT;
|
||||
} else {
|
||||
gc9a01->madctl_val &= ~LCD_CMD_MX_BIT;
|
||||
}
|
||||
if (mirror_y) {
|
||||
gc9a01->madctl_val |= LCD_CMD_MY_BIT;
|
||||
} else {
|
||||
gc9a01->madctl_val &= ~LCD_CMD_MY_BIT;
|
||||
}
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
gc9a01->madctl_val
|
||||
}, 1);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
if (swap_axes) {
|
||||
gc9a01->madctl_val |= LCD_CMD_MV_BIT;
|
||||
} else {
|
||||
gc9a01->madctl_val &= ~LCD_CMD_MV_BIT;
|
||||
}
|
||||
esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
gc9a01->madctl_val
|
||||
}, 1);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
gc9a01->x_gap = x_gap;
|
||||
gc9a01->y_gap = y_gap;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
|
||||
{
|
||||
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = gc9a01->io;
|
||||
int command = 0;
|
||||
if (on_off) {
|
||||
command = LCD_CMD_DISPON;
|
||||
} else {
|
||||
command = LCD_CMD_DISPOFF;
|
||||
}
|
||||
esp_lcd_panel_io_tx_param(io, command, NULL, 0);
|
||||
return ESP_OK;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Create LCD panel for model GC9A01
|
||||
*
|
||||
* @param[in] io LCD panel IO handle
|
||||
* @param[in] panel_dev_config general panel device configuration
|
||||
* @param[out] ret_panel Returned LCD panel handle
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
* - ESP_ERR_NO_MEM if out of memory
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
idf: ">=4.4"
|
||||
lvgl/lvgl: "~8.2.0"
|
@ -38,7 +38,7 @@ static const char *TAG = "example";
|
||||
|
||||
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
|
||||
|
||||
extern void example_lvgl_demo_ui(lv_obj_t *scr);
|
||||
extern void example_lvgl_demo_ui(lv_disp_t *disp);
|
||||
|
||||
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
@ -159,8 +159,7 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000));
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL Scroll Text");
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
example_lvgl_demo_ui(scr);
|
||||
example_lvgl_demo_ui(disp);
|
||||
|
||||
while (1) {
|
||||
// raise the task priority of LVGL and/or reduce the handler period can improve the performance
|
||||
|
@ -6,8 +6,9 @@
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
void example_lvgl_demo_ui(lv_obj_t *scr)
|
||||
void example_lvgl_demo_ui(lv_disp_t *disp)
|
||||
{
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
lv_obj_t *label = lv_label_create(scr);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); /* Circular scroll */
|
||||
lv_label_set_text(label, "Hello Espressif, Hello LVGL.");
|
||||
|
@ -74,7 +74,7 @@ static const char *TAG = "example";
|
||||
// Supported alignment: 16, 32, 64. A higher alignment can enables higher burst transfer size, thus a higher i80 bus throughput.
|
||||
#define EXAMPLE_PSRAM_DATA_ALIGNMENT 64
|
||||
|
||||
extern void example_lvgl_demo_ui(lv_obj_t *scr);
|
||||
extern void example_lvgl_demo_ui(lv_disp_t *disp);
|
||||
|
||||
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
@ -268,8 +268,7 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000));
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL animation");
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
example_lvgl_demo_ui(scr);
|
||||
example_lvgl_demo_ui(disp);
|
||||
|
||||
while (1) {
|
||||
// raise the task priority of LVGL and/or reduce the handler period can improve the performance
|
||||
|
@ -74,8 +74,10 @@ static void anim_timer_cb(lv_timer_t *timer)
|
||||
}
|
||||
}
|
||||
|
||||
void example_lvgl_demo_ui(lv_obj_t *scr)
|
||||
void example_lvgl_demo_ui(lv_disp_t *disp)
|
||||
{
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
|
||||
// Create image
|
||||
img_logo = lv_img_create(scr);
|
||||
lv_img_set_src(img_logo, &esp_logo);
|
||||
|
@ -39,8 +39,9 @@ static void add_data(lv_timer_t *timer)
|
||||
lv_chart_set_next_value2(chart, lv_chart_get_series_next(chart, NULL), lv_rand(0, 200), lv_rand(0, 1000));
|
||||
}
|
||||
|
||||
void example_lvgl_demo_ui(lv_obj_t *scr)
|
||||
void example_lvgl_demo_ui(lv_disp_t *disp)
|
||||
{
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
lv_obj_t *chart = lv_chart_create(scr);
|
||||
lv_obj_set_size(chart, 200, 150);
|
||||
lv_obj_align(chart, LV_ALIGN_CENTER, 0, 0);
|
||||
|
@ -60,7 +60,7 @@ SemaphoreHandle_t sem_vsync_end;
|
||||
SemaphoreHandle_t sem_gui_ready;
|
||||
#endif
|
||||
|
||||
extern void example_lvgl_demo_ui(lv_obj_t *scr);
|
||||
extern void example_lvgl_demo_ui(lv_disp_t *disp);
|
||||
|
||||
static bool example_on_vsync_event(esp_lcd_panel_handle_t panel, const esp_lcd_rgb_panel_event_data_t *event_data, void *user_data)
|
||||
{
|
||||
@ -226,8 +226,7 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000));
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL Scatter Chart");
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
example_lvgl_demo_ui(scr);
|
||||
example_lvgl_demo_ui(disp);
|
||||
|
||||
while (1) {
|
||||
// raise the task priority of LVGL and/or reduce the handler period can improve the performance
|
||||
|
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(lcd_gc9a01)
|
||||
project(spi_lcd_touch)
|
@ -1,20 +1,24 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- |
|
||||
|
||||
# GC9A01 porting example
|
||||
# SPI LCD and Touch Panel Example
|
||||
|
||||
[esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) provides several panel drivers out-of box, e.g. ST7789, SSD1306, NT35510. However, there're a lot of other panels on the market, it's beyond `esp_lcd` component's responsibility to include them all.
|
||||
|
||||
`esp_lcd` allows user to add their own panel drivers in the project scope (i.e. panel driver can live outside of esp-idf), so that the upper layer code like LVGL porting code can be reused without any modifications, as long as user-implemented panel driver follows the interface defined in the `esp_lcd` component.
|
||||
|
||||
This example shows how to add the GC9A01 driver in the project folder but still use the API provided by `esp_lcd` component. As GC9A01 is famous in the form of a circular screen, this example will draw a fancy dash board with the LVGL library. For more information about porting the LVGL library, you can also refer to [another lvgl porting example](../i80_controller/README.md).
|
||||
This example shows how to use GC9A01 or ILI9341 display driver from Component manager in esp-idf project. These components are using API provided by `esp_lcd` component. This example will draw a fancy dash board with the LVGL library. For more information about porting the LVGL library, you can also refer to [another lvgl porting example](../i80_controller/README.md).
|
||||
|
||||
## Touch controller STMPE610
|
||||
|
||||
In this example you can enable touch controller STMPE610 connected via SPI. The SPI connection is shared with LCD screen.
|
||||
|
||||
## How to use the example
|
||||
|
||||
### Hardware Required
|
||||
|
||||
* An ESP development board
|
||||
* An GC9A01 LCD panel, with SPI interface
|
||||
* An GC9A01 or ILI9341 LCD panel, with SPI interface (with/without STMPE610 SPI touch)
|
||||
* An USB cable for power supply and programming
|
||||
|
||||
### Hardware Connection
|
||||
@ -22,7 +26,7 @@ This example shows how to add the GC9A01 driver in the project folder but still
|
||||
The connection between ESP Board and the LCD is as follows:
|
||||
|
||||
```
|
||||
ESP Board GC9A01 Panel
|
||||
ESP Board GC9A01/ILI9341 Panel + TOUCH
|
||||
┌──────────────────────┐ ┌────────────────────┐
|
||||
│ GND ├─────────────►│ GND │
|
||||
│ │ │ │
|
||||
@ -30,20 +34,24 @@ The connection between ESP Board and the LCD is as follows:
|
||||
│ │ │ │
|
||||
│ PCLK ├─────────────►│ SCL │
|
||||
│ │ │ │
|
||||
│ DATA0 ├─────────────►│ SDA │
|
||||
│ MOSI ├─────────────►│ MOSI │
|
||||
│ │ │ │
|
||||
│ MISO |◄─────────────┤ MISO │
|
||||
│ │ │ │
|
||||
│ RST ├─────────────►│ RES │
|
||||
│ │ │ │
|
||||
│ DC ├─────────────►│ DC │
|
||||
│ │ │ │
|
||||
│ CS ├─────────────►│ CS │
|
||||
│ LCD CS ├─────────────►│ LCD CS │
|
||||
│ │ │ │
|
||||
│ TOUCH CS ├─────────────►│ TOUCH CS │
|
||||
│ │ │ │
|
||||
│ BK_LIGHT ├─────────────►│ BLK │
|
||||
└──────────────────────┘ └────────────────────┘
|
||||
```
|
||||
|
||||
The GPIO number used by this example can be changed in [lvgl_example_main.c](main/gc9a01_example_main.c).
|
||||
Especially, please pay attention to the level used to turn on the LCD backlight, some LCD module needs a low level to turn it on, while others take a high level. You can change the backlight level macro `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL` in [lvgl_example_main.c](main/gc9a01_example_main.c).
|
||||
The GPIO number used by this example can be changed in [lvgl_example_main.c](main/spi_lcd_touch_example_main.c).
|
||||
Especially, please pay attention to the level used to turn on the LCD backlight, some LCD module needs a low level to turn it on, while others take a high level. You can change the backlight level macro `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL` in [lvgl_example_main.c](main/spi_lcd_touch_example_main.c).
|
||||
|
||||
### Build and Flash
|
||||
|
||||
@ -59,19 +67,23 @@ See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/l
|
||||
|
||||
```bash
|
||||
...
|
||||
I (304) cpu_start: Starting scheduler.
|
||||
I (308) example: Turn off LCD backlight
|
||||
I (308) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (318) example: Initialize SPI bus
|
||||
I (318) example: Install panel IO
|
||||
I (328) gpio: GPIO[5]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (338) example: Install GC9A01 panel driver
|
||||
I (338) gpio: GPIO[3]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (468) example: Turn on LCD backlight
|
||||
I (468) example: Initialize LVGL library
|
||||
I (468) example: Register display driver to LVGL
|
||||
I (468) example: Install LVGL tick timer
|
||||
I (468) example: Display LVGL Meter Widget
|
||||
I (409) cpu_start: Starting scheduler on APP CPU.
|
||||
I (419) example: Turn off LCD backlight
|
||||
I (419) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (429) example: Initialize SPI bus
|
||||
I (439) example: Install panel IO
|
||||
I (439) gpio: GPIO[5]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (449) example: Install GC9A01 panel driver
|
||||
I (459) gpio: GPIO[3]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (589) gpio: GPIO[0]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
|
||||
I (589) example: Initialize touch controller STMPE610
|
||||
I (589) STMPE610: TouchPad ID: 0x0811
|
||||
I (589) STMPE610: TouchPad Ver: 0x03
|
||||
I (599) example: Turn on LCD backlight
|
||||
I (599) example: Initialize LVGL library
|
||||
I (609) example: Register display driver to LVGL
|
||||
I (619) example: Install LVGL tick timer
|
||||
I (619) example: Display LVGL Meter Widget
|
||||
...
|
||||
```
|
||||
|
||||
@ -80,7 +92,5 @@ I (468) example: Display LVGL Meter Widget
|
||||
|
||||
* Why the LCD doesn't light up?
|
||||
* Check the backlight's turn-on level, and update it in `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL`
|
||||
* Weird color display?
|
||||
* Each LCD panel has it's own initialize code, see the `vendor_specific_init` array defined in [GC9A01 driver](main/esp_lcd_panel_gc9a01.c), where contains the Gama setting. You should consult your the LCD supplier.
|
||||
|
||||
For any technical queries, please open an [issue] (https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
||||
For any technical queries, please open an [issue] (https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "spi_lcd_touch_example_main.c" "lvgl_demo_ui.c"
|
||||
INCLUDE_DIRS ".")
|
@ -0,0 +1,35 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
choice EXAMPLE_LCD_CONTROLLER
|
||||
prompt "LCD controller model"
|
||||
default EXAMPLE_LCD_CONTROLLER_ILI9341
|
||||
help
|
||||
Select LCD controller model
|
||||
|
||||
config EXAMPLE_LCD_CONTROLLER_ILI9341
|
||||
bool "ILI9341"
|
||||
|
||||
config EXAMPLE_LCD_CONTROLLER_GC9A01
|
||||
bool "GC9A01"
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_LCD_TOUCH_ENABLED
|
||||
bool "Enable LCD touch"
|
||||
default n
|
||||
help
|
||||
Enable this option if you wish to use display touch. You can select from touch controllers.
|
||||
|
||||
choice EXAMPLE_LCD_TOUCH_CONTROLLER
|
||||
prompt "LCD touch controller model"
|
||||
depends on EXAMPLE_LCD_TOUCH_ENABLED
|
||||
default EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
|
||||
help
|
||||
Select LCD touch controller model
|
||||
|
||||
config EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
|
||||
bool "STMPE610"
|
||||
help
|
||||
Touch controller STMPE610 connected via SPI.
|
||||
endchoice
|
||||
|
||||
endmenu
|
@ -0,0 +1,6 @@
|
||||
dependencies:
|
||||
idf: ">=4.4"
|
||||
lvgl/lvgl: "~8.3.0"
|
||||
esp_lcd_ili9341: "^1.0"
|
||||
esp_lcd_gc9a01: "^1.0"
|
||||
esp_lcd_touch_stmpe610: "^1.0"
|
@ -9,14 +9,27 @@
|
||||
#include "lvgl.h"
|
||||
|
||||
static lv_obj_t *meter;
|
||||
static lv_obj_t * btn;
|
||||
static lv_disp_rot_t rotation = LV_DISP_ROT_NONE;
|
||||
|
||||
static void set_value(void *indic, int32_t v)
|
||||
{
|
||||
lv_meter_set_indicator_end_value(meter, indic, v);
|
||||
}
|
||||
|
||||
void example_lvgl_demo_ui(lv_obj_t *scr)
|
||||
static void btn_cb(lv_event_t * e)
|
||||
{
|
||||
lv_disp_t *disp = lv_event_get_user_data(e);
|
||||
rotation++;
|
||||
if (rotation > LV_DISP_ROT_270) {
|
||||
rotation = LV_DISP_ROT_NONE;
|
||||
}
|
||||
lv_disp_set_rotation(disp, rotation);
|
||||
}
|
||||
|
||||
void example_lvgl_demo_ui(lv_disp_t *disp)
|
||||
{
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
meter = lv_meter_create(scr);
|
||||
lv_obj_center(meter);
|
||||
lv_obj_set_size(meter, 200, 200);
|
||||
@ -51,6 +64,13 @@ void example_lvgl_demo_ui(lv_obj_t *scr)
|
||||
/*Add a needle line indicator*/
|
||||
indic = lv_meter_add_needle_line(meter, scale, 4, lv_palette_main(LV_PALETTE_GREY), -10);
|
||||
|
||||
btn = lv_btn_create(scr);
|
||||
lv_obj_t * lbl = lv_label_create(btn);
|
||||
lv_label_set_text_static(lbl, LV_SYMBOL_REFRESH" ROTATE");
|
||||
lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 30, -30);
|
||||
/*Button event*/
|
||||
lv_obj_add_event_cb(btn, btn_cb, LV_EVENT_CLICKED, disp);
|
||||
|
||||
/*Create an animation to set the value*/
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
@ -16,7 +16,16 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "lvgl.h"
|
||||
#include "esp_lcd_panel_gc9a01.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_CONTROLLER_ILI9341
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#elif CONFIG_EXAMPLE_LCD_CONTROLLER_GC9A01
|
||||
#include "esp_lcd_gc9a01.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
|
||||
#include "esp_lcd_touch_stmpe610.h"
|
||||
#endif
|
||||
|
||||
static const char *TAG = "example";
|
||||
|
||||
@ -29,23 +38,35 @@ static const char *TAG = "example";
|
||||
#define EXAMPLE_LCD_PIXEL_CLOCK_HZ (20 * 1000 * 1000)
|
||||
#define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL 1
|
||||
#define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL
|
||||
#define EXAMPLE_PIN_NUM_DATA0 19
|
||||
#define EXAMPLE_PIN_NUM_PCLK 18
|
||||
#define EXAMPLE_PIN_NUM_CS 4
|
||||
#define EXAMPLE_PIN_NUM_DC 5
|
||||
#define EXAMPLE_PIN_NUM_RST 3
|
||||
#define EXAMPLE_PIN_NUM_SCLK 18
|
||||
#define EXAMPLE_PIN_NUM_MOSI 19
|
||||
#define EXAMPLE_PIN_NUM_MISO 21
|
||||
#define EXAMPLE_PIN_NUM_LCD_DC 5
|
||||
#define EXAMPLE_PIN_NUM_LCD_RST 3
|
||||
#define EXAMPLE_PIN_NUM_LCD_CS 4
|
||||
#define EXAMPLE_PIN_NUM_BK_LIGHT 2
|
||||
#define EXAMPLE_PIN_NUM_TOUCH_CS 15
|
||||
|
||||
// The pixel number in horizontal and vertical
|
||||
#if CONFIG_EXAMPLE_LCD_CONTROLLER_ILI9341
|
||||
#define EXAMPLE_LCD_H_RES 240
|
||||
#define EXAMPLE_LCD_V_RES 320
|
||||
#elif CONFIG_EXAMPLE_LCD_CONTROLLER_GC9A01
|
||||
#define EXAMPLE_LCD_H_RES 240
|
||||
#define EXAMPLE_LCD_V_RES 240
|
||||
#endif
|
||||
// Bit number used to represent command and parameter
|
||||
#define EXAMPLE_LCD_CMD_BITS 8
|
||||
#define EXAMPLE_LCD_PARAM_BITS 8
|
||||
|
||||
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
|
||||
|
||||
extern void example_lvgl_demo_ui(lv_obj_t *scr);
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
esp_lcd_touch_handle_t tp = NULL;
|
||||
#endif
|
||||
|
||||
extern void example_lvgl_demo_ui(lv_disp_t *disp);
|
||||
|
||||
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
@ -65,6 +86,78 @@ static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_
|
||||
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
|
||||
}
|
||||
|
||||
/* Rotate display and touch, when rotated screen in LVGL. Called when driver parameters are updated. */
|
||||
static void example_lvgl_port_update_callback(lv_disp_drv_t *drv)
|
||||
{
|
||||
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data;
|
||||
|
||||
switch (drv->rotated) {
|
||||
case LV_DISP_ROT_NONE:
|
||||
// Rotate LCD display
|
||||
esp_lcd_panel_swap_xy(panel_handle, false);
|
||||
esp_lcd_panel_mirror(panel_handle, true, false);
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
// Rotate LCD touch
|
||||
esp_lcd_touch_set_mirror_y(tp, false);
|
||||
esp_lcd_touch_set_mirror_x(tp, false);
|
||||
#endif
|
||||
break;
|
||||
case LV_DISP_ROT_90:
|
||||
// Rotate LCD display
|
||||
esp_lcd_panel_swap_xy(panel_handle, true);
|
||||
esp_lcd_panel_mirror(panel_handle, true, true);
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
// Rotate LCD touch
|
||||
esp_lcd_touch_set_mirror_y(tp, false);
|
||||
esp_lcd_touch_set_mirror_x(tp, false);
|
||||
#endif
|
||||
break;
|
||||
case LV_DISP_ROT_180:
|
||||
// Rotate LCD display
|
||||
esp_lcd_panel_swap_xy(panel_handle, false);
|
||||
esp_lcd_panel_mirror(panel_handle, false, true);
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
// Rotate LCD touch
|
||||
esp_lcd_touch_set_mirror_y(tp, false);
|
||||
esp_lcd_touch_set_mirror_x(tp, false);
|
||||
#endif
|
||||
break;
|
||||
case LV_DISP_ROT_270:
|
||||
// Rotate LCD display
|
||||
esp_lcd_panel_swap_xy(panel_handle, true);
|
||||
esp_lcd_panel_mirror(panel_handle, false, false);
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
// Rotate LCD touch
|
||||
esp_lcd_touch_set_mirror_y(tp, false);
|
||||
esp_lcd_touch_set_mirror_x(tp, false);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
static void example_lvgl_touch_cb(lv_indev_drv_t * drv, lv_indev_data_t * data)
|
||||
{
|
||||
uint16_t touchpad_x[1] = {0};
|
||||
uint16_t touchpad_y[1] = {0};
|
||||
uint8_t touchpad_cnt = 0;
|
||||
|
||||
/* Read touch controller data */
|
||||
esp_lcd_touch_read_data(drv->user_data);
|
||||
|
||||
/* Get coordinates */
|
||||
bool touchpad_pressed = esp_lcd_touch_get_coordinates(drv->user_data, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
|
||||
|
||||
if (touchpad_pressed && touchpad_cnt > 0) {
|
||||
data->point.x = touchpad_x[0];
|
||||
data->point.y = touchpad_y[0];
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void example_increase_lvgl_tick(void *arg)
|
||||
{
|
||||
/* Tell LVGL how many milliseconds has elapsed */
|
||||
@ -85,9 +178,9 @@ void app_main(void)
|
||||
|
||||
ESP_LOGI(TAG, "Initialize SPI bus");
|
||||
spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = EXAMPLE_PIN_NUM_PCLK,
|
||||
.mosi_io_num = EXAMPLE_PIN_NUM_DATA0,
|
||||
.miso_io_num = -1,
|
||||
.sclk_io_num = EXAMPLE_PIN_NUM_SCLK,
|
||||
.mosi_io_num = EXAMPLE_PIN_NUM_MOSI,
|
||||
.miso_io_num = EXAMPLE_PIN_NUM_MISO,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
.max_transfer_sz = EXAMPLE_LCD_H_RES * 80 * sizeof(uint16_t),
|
||||
@ -97,8 +190,8 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.dc_gpio_num = EXAMPLE_PIN_NUM_DC,
|
||||
.cs_gpio_num = EXAMPLE_PIN_NUM_CS,
|
||||
.dc_gpio_num = EXAMPLE_PIN_NUM_LCD_DC,
|
||||
.cs_gpio_num = EXAMPLE_PIN_NUM_LCD_CS,
|
||||
.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
|
||||
.lcd_cmd_bits = EXAMPLE_LCD_CMD_BITS,
|
||||
.lcd_param_bits = EXAMPLE_LCD_PARAM_BITS,
|
||||
@ -113,20 +206,54 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "Install GC9A01 panel driver");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = EXAMPLE_PIN_NUM_RST,
|
||||
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
|
||||
#if CONFIG_EXAMPLE_LCD_CONTROLLER_ILI9341
|
||||
.color_space = ESP_LCD_COLOR_SPACE_RGB,
|
||||
#elif CONFIG_EXAMPLE_LCD_CONTROLLER_GC9A01
|
||||
.color_space = ESP_LCD_COLOR_SPACE_BGR,
|
||||
#endif
|
||||
.bits_per_pixel = 16,
|
||||
};
|
||||
#if CONFIG_EXAMPLE_LCD_CONTROLLER_ILI9341
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(io_handle, &panel_config, &panel_handle));
|
||||
#elif CONFIG_EXAMPLE_LCD_CONTROLLER_GC9A01
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(io_handle, &panel_config, &panel_handle));
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
|
||||
#if CONFIG_EXAMPLE_LCD_CONTROLLER_GC9A01
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_handle, true));
|
||||
#endif
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, true, false));
|
||||
|
||||
// user can flush pre-defined pattern to the screen before we turn on the screen or backlight
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
|
||||
esp_lcd_panel_io_spi_config_t tp_io_config = ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG(EXAMPLE_PIN_NUM_TOUCH_CS);
|
||||
// Attach the TOUCH to the SPI bus
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &tp_io_config, &tp_io_handle));
|
||||
|
||||
esp_lcd_touch_config_t tp_cfg = {
|
||||
.x_max = EXAMPLE_LCD_H_RES,
|
||||
.y_max = EXAMPLE_LCD_V_RES,
|
||||
.rst_gpio_num = -1,
|
||||
.int_gpio_num = -1,
|
||||
.flags = {
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 0,
|
||||
},
|
||||
};
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
|
||||
ESP_LOGI(TAG, "Initialize touch controller STMPE610");
|
||||
ESP_ERROR_CHECK(esp_lcd_touch_new_spi_stmpe610(tp_io_handle, &tp_cfg, &tp));
|
||||
#endif // CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
|
||||
#endif // CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
|
||||
ESP_LOGI(TAG, "Turn on LCD backlight");
|
||||
gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL);
|
||||
|
||||
@ -146,6 +273,7 @@ void app_main(void)
|
||||
disp_drv.hor_res = EXAMPLE_LCD_H_RES;
|
||||
disp_drv.ver_res = EXAMPLE_LCD_V_RES;
|
||||
disp_drv.flush_cb = example_lvgl_flush_cb;
|
||||
disp_drv.drv_update_cb = example_lvgl_port_update_callback;
|
||||
disp_drv.draw_buf = &disp_buf;
|
||||
disp_drv.user_data = panel_handle;
|
||||
lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
|
||||
@ -160,9 +288,19 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
|
||||
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000));
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
|
||||
static lv_indev_drv_t indev_drv; // Input device driver (Touch)
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.disp = disp;
|
||||
indev_drv.read_cb = example_lvgl_touch_cb;
|
||||
indev_drv.user_data = tp;
|
||||
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL Meter Widget");
|
||||
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||||
example_lvgl_demo_ui(scr);
|
||||
example_lvgl_demo_ui(disp);
|
||||
|
||||
while (1) {
|
||||
// raise the task priority of LVGL and/or reduce the handler period can improve the performance
|
Loading…
x
Reference in New Issue
Block a user