Add LVGL QSPI LCD with RAM example and SH8601 driver
Introduced the 05_LVGL_WITH_RAM example project for ESP32 targets, including support for QSPI LCD panels (SPD1020, GC9B71, SH8601) and touch controllers. Added SH8601 LCD driver component, related documentation, initialization code, and test applications. Updated .gitignore to allow tracking of the new example directory.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
9597cce74af4bae0ec423ee819a2916b995ff3e5bb8d590bdb0a27fa9e715dab
|
||||
24
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/CHANGELOG.md
Normal file
24
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/CHANGELOG.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# ChangeLog
|
||||
|
||||
## v0.0.1 - 2023-08-22
|
||||
|
||||
### Enhancements:
|
||||
|
||||
* Implement the driver for the SH8601 LCD controller
|
||||
* Support SPI and QSPI interface
|
||||
|
||||
## v0.0.2 - 2023-10-07
|
||||
|
||||
### Enhancements:
|
||||
|
||||
* Support to use ESP-IDF release/v5.0
|
||||
|
||||
## v1.0.0 - 2023-11-03
|
||||
|
||||
### bugfix
|
||||
|
||||
* Fix the incompatible dependent version of ESP-IDF
|
||||
* Remove LCD command `29h` from the initialization sequence
|
||||
* Increase `pclk_hz` to 40MHz in default panel IO configuration
|
||||
* Add parameter `max_trans_sz` in default bus configuration macro
|
||||
* Add check for conflicting commands between initialization sequence and driver
|
||||
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "esp_lcd_sh8601.c" INCLUDE_DIRS "include" PRIV_REQUIRES "driver" REQUIRES "esp_lcd")
|
||||
|
||||
include(package_manager)
|
||||
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
|
||||
147
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/README.md
Normal file
147
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/README.md
Normal file
@@ -0,0 +1,147 @@
|
||||
# ESP LCD SH8601
|
||||
|
||||
[](https://components.espressif.com/components/espressif/esp_lcd_sh8601)
|
||||
|
||||
Implementation of the SH8601 LCD controller with [esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/lcd.html) component.
|
||||
|
||||
| LCD controller | Communication interface | Component name | Link to datasheet |
|
||||
| :------------: | :---------------------: | :------------: | :---------------------------------------------------------------------------: |
|
||||
| SH8601 | SPI/QSPI | esp_lcd_sh8601 | [PDF](https://dl.espressif.com/AE/esp-iot-solution/SH8601A0_DataSheet_Preliminary_V0.0_UCS__191107_1_.pdf) |
|
||||
|
||||
## Add to project
|
||||
|
||||
Packages from this repository are uploaded to [Espressif's component service](https://components.espressif.com/).
|
||||
You can add them to your project via `idf.py add-dependancy`, e.g.
|
||||
```
|
||||
idf.py add-dependency "espressif/esp_lcd_sh8601"
|
||||
```
|
||||
|
||||
Alternatively, you can create `idf_component.yml`. More is in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html).
|
||||
|
||||
## Initialization Code
|
||||
|
||||
### SPI Interface
|
||||
|
||||
```c
|
||||
ESP_LOGI(TAG, "Initialize SPI bus");
|
||||
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_BUS_QSPI_CONFIG(EXAMPLE_PIN_NUM_LCD_PCLK,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA0,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA1,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA2,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA3,
|
||||
EXAMPLE_LCD_H_RES * 80 * sizeof(uint16_t));
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(EXAMPLE_LCD_HOST, &bus_config, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_SPI_CONFIG(EXAMPLE_PIN_NUM_LCD_CS, EXAMPLE_PIN_NUM_LCD_DC,
|
||||
callback, &callback_data);
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)EXAMPLE_LCD_HOST, &io_config, &io_handle));
|
||||
|
||||
/**
|
||||
* Uncomment these line if use custom initialization commands.
|
||||
* The array should be declared as static const and positioned outside the function.
|
||||
*/
|
||||
// static const sh8601_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
// // {cmd, { data }, data_size, delay_ms}
|
||||
// {0x44, (uint8_t []){0x00, 0xc8}, 2, 0},
|
||||
// {0x35, (uint8_t []){0x00}, 0, 0},
|
||||
// {0x53, (uint8_t []){0x20}, 1, 25},
|
||||
// {0x29, (uint8_t []){0x00}, 0, 120},
|
||||
// ...
|
||||
// };
|
||||
|
||||
ESP_LOGI(TAG, "Install SH8601 panel driver");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
const sh8601_vendor_config_t vendor_config = {
|
||||
// .init_cmds = lcd_init_cmds, // Uncomment these line if use custom initialization commands
|
||||
// .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(sh8601_lcd_init_cmd_t),
|
||||
.flags = {
|
||||
.use_qspi_interface = 0,
|
||||
},
|
||||
};
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h`
|
||||
.bits_per_pixel = 16, // Implemented by LCD command `3Ah` (16/18/24)
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle));
|
||||
esp_lcd_panel_reset(panel_handle);
|
||||
esp_lcd_panel_init(panel_handle);
|
||||
esp_lcd_panel_disp_on_off(panel_handle, true);
|
||||
```
|
||||
|
||||
### QSPI Interface
|
||||
|
||||
```c
|
||||
ESP_LOGI(TAG, "Initialize QSPI bus");
|
||||
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_BUS_QSPI_CONFIG(EXAMPLE_PIN_NUM_LCD_PCLK,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA0,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA1,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA2,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA3,
|
||||
EXAMPLE_LCD_H_RES * 80 * sizeof(uint16_t));
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(EXAMPLE_LCD_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_QSPI_CONFIG(EXAMPLE_PIN_NUM_LCD_CS, callback, &callback_data);
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)EXAMPLE_LCD_HOST, &io_config, &io_handle));
|
||||
|
||||
/**
|
||||
* Uncomment these line if use custom initialization commands.
|
||||
* The array should be declared as static const and positioned outside the function.
|
||||
*/
|
||||
// static const sh8601_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
// // {cmd, { data }, data_size, delay_ms}
|
||||
// {0x44, (uint8_t []){0x00, 0xc8}, 2, 0},
|
||||
// {0x35, (uint8_t []){0x00}, 0, 0},
|
||||
// {0x53, (uint8_t []){0x20}, 1, 25},
|
||||
// {0x29, (uint8_t []){0x00}, 0, 120},
|
||||
// ...
|
||||
// };
|
||||
|
||||
ESP_LOGI(TAG, "Install SH8601 panel driver");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
const sh8601_vendor_config_t vendor_config = {
|
||||
// .init_cmds = lcd_init_cmds, // Uncomment these line if use custom initialization commands
|
||||
// .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(sh8601_lcd_init_cmd_t),
|
||||
.flags = {
|
||||
.use_qspi_interface = 1,
|
||||
},
|
||||
};
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h`
|
||||
.bits_per_pixel = 16, // Implemented by LCD command `3Ah`
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle));
|
||||
|
||||
esp_lcd_panel_reset(panel_handle);
|
||||
esp_lcd_panel_init(panel_handle);
|
||||
esp_lcd_panel_disp_on_off(panel_handle, true);
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
* When utilizing `esp_panel_lcd_draw_bitmap()` to refresh the screen, ensure that `x_start`, `y_start`, `x_end` and `y_end` are divisible by `2`. This is a requirement of SH8610. For LVGL, register the following function into `rounder_cb` of `lv_disp_drv_t` to round the coordinates.
|
||||
|
||||
```c
|
||||
void lvgl_port_rounder_callback(struct _lv_disp_drv_t * disp_drv, lv_area_t * area)
|
||||
{
|
||||
uint16_t x1 = area->x1;
|
||||
uint16_t x2 = area->x2;
|
||||
uint16_t y1 = area->y1;
|
||||
uint16_t y2 = area->y2;
|
||||
|
||||
// round the start of area down to the nearest even number
|
||||
area->x1 = (x1 >> 1) << 1;
|
||||
area->y1 = (y1 >> 1) << 1;
|
||||
|
||||
// round the end of area up to the nearest odd number
|
||||
area->x2 = ((x2 >> 1) << 1) + 1;
|
||||
area->y2 = ((y2 >> 1) << 1) + 1;
|
||||
}
|
||||
```
|
||||
347
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/esp_lcd_sh8601.c
Normal file
347
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/esp_lcd_sh8601.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 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 "driver/gpio.h"
|
||||
#include "esp_check.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 "esp_log.h"
|
||||
|
||||
#include "esp_lcd_sh8601.h"
|
||||
|
||||
#define LCD_OPCODE_WRITE_CMD (0x02ULL)
|
||||
#define LCD_OPCODE_READ_CMD (0x03ULL)
|
||||
#define LCD_OPCODE_WRITE_COLOR (0x32ULL)
|
||||
|
||||
static const char *TAG = "sh8601";
|
||||
|
||||
static esp_err_t panel_sh8601_del(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_sh8601_reset(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_sh8601_init(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_sh8601_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_sh8601_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
|
||||
static esp_err_t panel_sh8601_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
static esp_err_t panel_sh8601_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
|
||||
static esp_err_t panel_sh8601_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
|
||||
static esp_err_t panel_sh8601_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;
|
||||
int x_gap;
|
||||
int y_gap;
|
||||
uint8_t fb_bits_per_pixel;
|
||||
uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
|
||||
uint8_t colmod_val; // save surrent value of LCD_CMD_COLMOD register
|
||||
const sh8601_lcd_init_cmd_t *init_cmds;
|
||||
uint16_t init_cmds_size;
|
||||
struct {
|
||||
unsigned int use_qspi_interface: 1;
|
||||
unsigned int reset_level: 1;
|
||||
} flags;
|
||||
} sh8601_panel_t;
|
||||
|
||||
esp_err_t esp_lcd_new_panel_sh8601(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_RETURN_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
sh8601_panel_t *sh8601 = NULL;
|
||||
sh8601 = calloc(1, sizeof(sh8601_panel_t));
|
||||
ESP_GOTO_ON_FALSE(sh8601, ESP_ERR_NO_MEM, err, TAG, "no mem for sh8601 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->rgb_ele_order) {
|
||||
case LCD_RGB_ELEMENT_ORDER_RGB:
|
||||
sh8601->madctl_val = 0;
|
||||
break;
|
||||
case LCD_RGB_ELEMENT_ORDER_BGR:
|
||||
sh8601->madctl_val |= LCD_CMD_BGR_BIT;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color element order");
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t fb_bits_per_pixel = 0;
|
||||
switch (panel_dev_config->bits_per_pixel) {
|
||||
case 16: // RGB565
|
||||
sh8601->colmod_val = 0x55;
|
||||
fb_bits_per_pixel = 16;
|
||||
break;
|
||||
case 18: // RGB666
|
||||
sh8601->colmod_val = 0x66;
|
||||
// each color component (R/G/B) should occupy the 6 high bits of a byte, which means 3 full bytes are required for a pixel
|
||||
fb_bits_per_pixel = 24;
|
||||
break;
|
||||
case 24: // RGB888
|
||||
sh8601->colmod_val = 0x77;
|
||||
fb_bits_per_pixel = 24;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
|
||||
break;
|
||||
}
|
||||
|
||||
sh8601->io = io;
|
||||
sh8601->reset_gpio_num = panel_dev_config->reset_gpio_num;
|
||||
sh8601->fb_bits_per_pixel = fb_bits_per_pixel;
|
||||
sh8601_vendor_config_t *vendor_config = (sh8601_vendor_config_t *)panel_dev_config->vendor_config;
|
||||
if (vendor_config) {
|
||||
sh8601->init_cmds = vendor_config->init_cmds;
|
||||
sh8601->init_cmds_size = vendor_config->init_cmds_size;
|
||||
sh8601->flags.use_qspi_interface = vendor_config->flags.use_qspi_interface;
|
||||
}
|
||||
sh8601->flags.reset_level = panel_dev_config->flags.reset_active_high;
|
||||
sh8601->base.del = panel_sh8601_del;
|
||||
sh8601->base.reset = panel_sh8601_reset;
|
||||
sh8601->base.init = panel_sh8601_init;
|
||||
sh8601->base.draw_bitmap = panel_sh8601_draw_bitmap;
|
||||
sh8601->base.invert_color = panel_sh8601_invert_color;
|
||||
sh8601->base.set_gap = panel_sh8601_set_gap;
|
||||
sh8601->base.mirror = panel_sh8601_mirror;
|
||||
sh8601->base.swap_xy = panel_sh8601_swap_xy;
|
||||
sh8601->base.disp_on_off = panel_sh8601_disp_on_off;
|
||||
*ret_panel = &(sh8601->base);
|
||||
ESP_LOGD(TAG, "new sh8601 panel @%p", sh8601);
|
||||
|
||||
ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_SH8601_VER_MAJOR, ESP_LCD_SH8601_VER_MINOR,
|
||||
ESP_LCD_SH8601_VER_PATCH);
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (sh8601) {
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(panel_dev_config->reset_gpio_num);
|
||||
}
|
||||
free(sh8601);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t tx_param(sh8601_panel_t *sh8601, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
|
||||
{
|
||||
if (sh8601->flags.use_qspi_interface) {
|
||||
lcd_cmd &= 0xff;
|
||||
lcd_cmd <<= 8;
|
||||
lcd_cmd |= LCD_OPCODE_WRITE_CMD << 24;
|
||||
}
|
||||
return esp_lcd_panel_io_tx_param(io, lcd_cmd, param, param_size);
|
||||
}
|
||||
|
||||
static esp_err_t tx_color(sh8601_panel_t *sh8601, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
|
||||
{
|
||||
if (sh8601->flags.use_qspi_interface) {
|
||||
lcd_cmd &= 0xff;
|
||||
lcd_cmd <<= 8;
|
||||
lcd_cmd |= LCD_OPCODE_WRITE_COLOR << 24;
|
||||
}
|
||||
return esp_lcd_panel_io_tx_color(io, lcd_cmd, param, param_size);
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_del(esp_lcd_panel_t *panel)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
|
||||
if (sh8601->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(sh8601->reset_gpio_num);
|
||||
}
|
||||
ESP_LOGD(TAG, "del sh8601 panel @%p", sh8601);
|
||||
free(sh8601);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_reset(esp_lcd_panel_t *panel)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = sh8601->io;
|
||||
|
||||
// Perform hardware reset
|
||||
if (sh8601->reset_gpio_num >= 0) {
|
||||
gpio_set_level(sh8601->reset_gpio_num, sh8601->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(sh8601->reset_gpio_num, !sh8601->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(150));
|
||||
} else { // Perform software reset
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(80));
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static const sh8601_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
// {cmd, { data }, data_size, delay_ms}
|
||||
{0x44, (uint8_t []){0x01, 0xD1}, 2, 0},
|
||||
{0x35, (uint8_t []){0x00}, 0, 0},
|
||||
{0x53, (uint8_t []){0x20}, 1, 25},
|
||||
};
|
||||
|
||||
static esp_err_t panel_sh8601_init(esp_lcd_panel_t *panel)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = sh8601->io;
|
||||
const sh8601_lcd_init_cmd_t *init_cmds = NULL;
|
||||
uint16_t init_cmds_size = 0;
|
||||
bool is_cmd_overwritten = false;
|
||||
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
sh8601->madctl_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, LCD_CMD_COLMOD, (uint8_t[]) {
|
||||
sh8601->colmod_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
|
||||
// vendor specific initialization, it can be different between manufacturers
|
||||
// should consult the LCD supplier for initialization sequence code
|
||||
if (sh8601->init_cmds) {
|
||||
init_cmds = sh8601->init_cmds;
|
||||
init_cmds_size = sh8601->init_cmds_size;
|
||||
} else {
|
||||
init_cmds = vendor_specific_init_default;
|
||||
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(sh8601_lcd_init_cmd_t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < init_cmds_size; i++) {
|
||||
// Check if the command has been used or conflicts with the internal
|
||||
switch (init_cmds[i].cmd) {
|
||||
case LCD_CMD_MADCTL:
|
||||
is_cmd_overwritten = true;
|
||||
sh8601->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
case LCD_CMD_COLMOD:
|
||||
is_cmd_overwritten = true;
|
||||
sh8601->colmod_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
default:
|
||||
is_cmd_overwritten = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_cmd_overwritten) {
|
||||
ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence", init_cmds[i].cmd);
|
||||
}
|
||||
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, init_cmds[i].cmd, init_cmds[i].data, init_cmds[i].data_bytes), TAG,
|
||||
"send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(init_cmds[i].delay_ms));
|
||||
}
|
||||
ESP_LOGD(TAG, "send init commands success");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_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 = sh8601->io;
|
||||
|
||||
x_start += sh8601->x_gap;
|
||||
x_end += sh8601->x_gap;
|
||||
y_start += sh8601->y_gap;
|
||||
y_end += sh8601->y_gap;
|
||||
|
||||
// define an area of frame memory where MCU can access
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, LCD_CMD_CASET, (uint8_t[]) {
|
||||
(x_start >> 8) & 0xFF,
|
||||
x_start & 0xFF,
|
||||
((x_end - 1) >> 8) & 0xFF,
|
||||
(x_end - 1) & 0xFF,
|
||||
}, 4), TAG, "send command failed");
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, LCD_CMD_RASET, (uint8_t[]) {
|
||||
(y_start >> 8) & 0xFF,
|
||||
y_start & 0xFF,
|
||||
((y_end - 1) >> 8) & 0xFF,
|
||||
(y_end - 1) & 0xFF,
|
||||
}, 4), TAG, "send command failed");
|
||||
// transfer frame buffer
|
||||
size_t len = (x_end - x_start) * (y_end - y_start) * sh8601->fb_bits_per_pixel / 8;
|
||||
tx_color(sh8601, io, LCD_CMD_RAMWR, color_data, len);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = sh8601->io;
|
||||
int command = 0;
|
||||
if (invert_color_data) {
|
||||
command = LCD_CMD_INVON;
|
||||
} else {
|
||||
command = LCD_CMD_INVOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, command, NULL, 0), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = sh8601->io;
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if (mirror_x) {
|
||||
sh8601->madctl_val |= BIT(6);
|
||||
} else {
|
||||
sh8601->madctl_val &= ~BIT(6);
|
||||
}
|
||||
if (mirror_y) {
|
||||
ESP_LOGE(TAG, "mirror_y is not supported by this panel");
|
||||
ret = ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
sh8601->madctl_val
|
||||
}, 1), TAG, "send command failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
|
||||
{
|
||||
ESP_LOGE(TAG, "swap_xy is not supported by this panel");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
sh8601->x_gap = x_gap;
|
||||
sh8601->y_gap = y_gap;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_sh8601_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
|
||||
{
|
||||
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = sh8601->io;
|
||||
int command = 0;
|
||||
|
||||
if (on_off) {
|
||||
command = LCD_CMD_DISPON;
|
||||
} else {
|
||||
command = LCD_CMD_DISPOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, command, NULL, 0), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
10
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/idf_component.yml
Normal file
10
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/idf_component.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
dependencies:
|
||||
cmake_utilities:
|
||||
version: 0.*
|
||||
idf:
|
||||
version: '>5.0.4,!=5.1.1'
|
||||
description: ESP LCD SH8601
|
||||
issues: https://github.com/espressif/esp-iot-solution/issues
|
||||
repository: https://github.com/espressif/esp-iot-solution.git
|
||||
url: https://github.com/espressif/esp-iot-solution/tree/master/components/display/lcd/esp_lcd_sh8601
|
||||
version: 1.0.0
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief LCD panel initialization commands.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int cmd; /*<! The specific LCD command */
|
||||
const void *data; /*<! Buffer that holds the command specific data */
|
||||
size_t data_bytes; /*<! Size of `data` in memory, in bytes */
|
||||
unsigned int delay_ms; /*<! Delay in milliseconds after this command */
|
||||
} sh8601_lcd_init_cmd_t;
|
||||
|
||||
/**
|
||||
* @brief LCD panel vendor configuration.
|
||||
*
|
||||
* @note This structure can be used to select interface type and override default initialization commands.
|
||||
* @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
const sh8601_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array.
|
||||
* The array should be declared as `static const` and positioned outside the function.
|
||||
* Please refer to `vendor_specific_init_default` in source file
|
||||
*/
|
||||
uint16_t init_cmds_size; /*<! Number of commands in above array */
|
||||
struct {
|
||||
unsigned int use_qspi_interface: 1; /*<! Set to 1 if use QSPI interface, default is SPI interface */
|
||||
} flags;
|
||||
} sh8601_vendor_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create LCD panel for model SH8601
|
||||
*
|
||||
* @param[in] io LCD panel IO handle
|
||||
* @param[in] panel_dev_config General panel device configuration (Use `vendor_config` to select QSPI interface or override default initialization commands)
|
||||
* @param[out] ret_panel Returned LCD panel handle
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Otherwise: Fail
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_sh8601(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);
|
||||
|
||||
/**
|
||||
* @brief LCD panel bus configuration structure
|
||||
*
|
||||
*/
|
||||
#define SH8601_PANEL_BUS_SPI_CONFIG(sclk, mosi, max_trans_sz) \
|
||||
{ \
|
||||
.sclk_io_num = sclk, \
|
||||
.mosi_io_num = mosi, \
|
||||
.miso_io_num = -1, \
|
||||
.quadhd_io_num = -1, \
|
||||
.quadwp_io_num = -1, \
|
||||
.max_transfer_sz = max_trans_sz, \
|
||||
}
|
||||
#define SH8601_PANEL_BUS_QSPI_CONFIG(sclk, d0, d1, d2, d3, max_trans_sz) \
|
||||
{ \
|
||||
.sclk_io_num = sclk, \
|
||||
.data0_io_num = d0, \
|
||||
.data1_io_num = d1, \
|
||||
.data2_io_num = d2, \
|
||||
.data3_io_num = d3, \
|
||||
.max_transfer_sz = max_trans_sz, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD panel IO configuration structure
|
||||
*
|
||||
*/
|
||||
#define SH8601_PANEL_IO_SPI_CONFIG(cs, dc, cb, cb_ctx) \
|
||||
{ \
|
||||
.cs_gpio_num = cs, \
|
||||
.dc_gpio_num = dc, \
|
||||
.spi_mode = 0, \
|
||||
.pclk_hz = 40 * 1000 * 1000, \
|
||||
.trans_queue_depth = 10, \
|
||||
.on_color_trans_done = cb, \
|
||||
.user_ctx = cb_ctx, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.lcd_param_bits = 8, \
|
||||
}
|
||||
#define SH8601_PANEL_IO_QSPI_CONFIG(cs, cb, cb_ctx) \
|
||||
{ \
|
||||
.cs_gpio_num = cs, \
|
||||
.dc_gpio_num = -1, \
|
||||
.spi_mode = 0, \
|
||||
.pclk_hz = 40 * 1000 * 1000, \
|
||||
.trans_queue_depth = 10, \
|
||||
.on_color_trans_done = cb, \
|
||||
.user_ctx = cb_ctx, \
|
||||
.lcd_cmd_bits = 32, \
|
||||
.lcd_param_bits = 8, \
|
||||
.flags = { \
|
||||
.quad_mode = true, \
|
||||
}, \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
202
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/license.txt
Normal file
202
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/license.txt
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(test_esp_lcd_gc9b71)
|
||||
@@ -0,0 +1 @@
|
||||
idf_component_register(SRCS "test_esp_lcd_sh8601.c")
|
||||
@@ -0,0 +1,6 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
idf: ">=5.0.4"
|
||||
esp_lcd_sh8601:
|
||||
version: "*"
|
||||
override_path: "../../../esp_lcd_sh8601"
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_lcd_panel_io_interface.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include "unity_test_utils_memory.h"
|
||||
|
||||
#include "esp_lcd_sh8601.h"
|
||||
|
||||
#define TEST_LCD_HOST SPI2_HOST
|
||||
#define TEST_LCD_H_RES (368)
|
||||
#define TEST_LCD_V_RES (448)
|
||||
#define TEST_LCD_BIT_PER_PIXEL (16)
|
||||
|
||||
#define TEST_PIN_NUM_LCD_CS (GPIO_NUM_9)
|
||||
#define TEST_PIN_NUM_LCD_PCLK (GPIO_NUM_10)
|
||||
#define TEST_PIN_NUM_LCD_DATA0 (GPIO_NUM_11)
|
||||
#define TEST_PIN_NUM_LCD_DATA1 (GPIO_NUM_12)
|
||||
#define TEST_PIN_NUM_LCD_DATA2 (GPIO_NUM_13)
|
||||
#define TEST_PIN_NUM_LCD_DATA3 (GPIO_NUM_14)
|
||||
#define TEST_PIN_NUM_LCD_RST (GPIO_NUM_21)
|
||||
#define TEST_PIN_NUM_LCD_DC (GPIO_NUM_8)
|
||||
|
||||
#define TEST_DELAY_TIME_MS (3000)
|
||||
|
||||
static char *TAG = "sh8601_test";
|
||||
static SemaphoreHandle_t refresh_finish = NULL;
|
||||
|
||||
static const sh8601_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
{0x11, (uint8_t []){0x00}, 0, 120},
|
||||
{0x44, (uint8_t []){0x01, 0xD1}, 2, 0},
|
||||
{0x35, (uint8_t []){0x00}, 1, 0},
|
||||
{0x53, (uint8_t []){0x20}, 1, 10},
|
||||
{0x51, (uint8_t []){0x00}, 1, 10},
|
||||
{0x29, (uint8_t []){0x00}, 0, 10},
|
||||
{0x51, (uint8_t []){0xFF}, 1, 0},
|
||||
};
|
||||
|
||||
IRAM_ATTR static bool test_notify_refresh_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
BaseType_t need_yield = pdFALSE;
|
||||
|
||||
xSemaphoreGiveFromISR(refresh_finish, &need_yield);
|
||||
return (need_yield == pdTRUE);
|
||||
}
|
||||
|
||||
static void test_draw_bitmap(esp_lcd_panel_handle_t panel_handle)
|
||||
{
|
||||
refresh_finish = xSemaphoreCreateBinary();
|
||||
TEST_ASSERT_NOT_NULL(refresh_finish);
|
||||
|
||||
uint16_t row_line = ((TEST_LCD_V_RES / TEST_LCD_BIT_PER_PIXEL) << 1) >> 1;
|
||||
uint8_t byte_per_pixel = TEST_LCD_BIT_PER_PIXEL / 8;
|
||||
uint8_t *color = (uint8_t *)heap_caps_calloc(1, row_line * TEST_LCD_H_RES * byte_per_pixel, MALLOC_CAP_DMA);
|
||||
TEST_ASSERT_NOT_NULL(color);
|
||||
|
||||
for (int j = 0; j < TEST_LCD_BIT_PER_PIXEL; j++) {
|
||||
for (int i = 0; i < row_line * TEST_LCD_H_RES; i++) {
|
||||
for (int k = 0; k < byte_per_pixel; k++) {
|
||||
color[i * byte_per_pixel + k] = (SPI_SWAP_DATA_TX(BIT(j), TEST_LCD_BIT_PER_PIXEL) >> (k * 8)) & 0xff;
|
||||
}
|
||||
}
|
||||
TEST_ESP_OK(esp_lcd_panel_draw_bitmap(panel_handle, 0, j * row_line, TEST_LCD_H_RES, (j + 1) * row_line, color));
|
||||
xSemaphoreTake(refresh_finish, portMAX_DELAY);
|
||||
}
|
||||
free(color);
|
||||
vSemaphoreDelete(refresh_finish);
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_CASE("test sh8601 to draw color bar with SPI interface", "[sh8601][spi]")
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = SH8601_PANEL_BUS_SPI_CONFIG(TEST_PIN_NUM_LCD_PCLK,
|
||||
TEST_PIN_NUM_LCD_DATA0,
|
||||
TEST_LCD_H_RES * TEST_LCD_V_RES * TEST_LCD_BIT_PER_PIXEL / 8);
|
||||
TEST_ESP_OK(spi_bus_initialize(TEST_LCD_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_SPI_CONFIG(TEST_PIN_NUM_LCD_CS, TEST_PIN_NUM_LCD_DC,
|
||||
test_notify_refresh_ready, NULL);
|
||||
// Attach the LCD to the SPI bus
|
||||
TEST_ESP_OK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)TEST_LCD_HOST, &io_config, &io_handle));
|
||||
|
||||
ESP_LOGI(TAG, "Install LCD driver of sh8601");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = TEST_PIN_NUM_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.bits_per_pixel = TEST_LCD_BIT_PER_PIXEL,
|
||||
};
|
||||
TEST_ESP_OK(esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle));
|
||||
esp_lcd_panel_reset(panel_handle);
|
||||
esp_lcd_panel_init(panel_handle);
|
||||
esp_lcd_panel_disp_on_off(panel_handle, true);
|
||||
|
||||
test_draw_bitmap(panel_handle);
|
||||
|
||||
TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
|
||||
TEST_ESP_OK(spi_bus_free(TEST_LCD_HOST));
|
||||
}
|
||||
|
||||
TEST_CASE("test sh8601 to draw color bar with QSPI interface", "[sh8601][qspi]")
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = SH8601_PANEL_BUS_QSPI_CONFIG(TEST_PIN_NUM_LCD_PCLK,
|
||||
TEST_PIN_NUM_LCD_DATA0,
|
||||
TEST_PIN_NUM_LCD_DATA1,
|
||||
TEST_PIN_NUM_LCD_DATA2,
|
||||
TEST_PIN_NUM_LCD_DATA3,
|
||||
TEST_LCD_H_RES * TEST_LCD_V_RES * TEST_LCD_BIT_PER_PIXEL / 8);
|
||||
TEST_ESP_OK(spi_bus_initialize(TEST_LCD_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_QSPI_CONFIG(TEST_PIN_NUM_LCD_CS, test_notify_refresh_ready, NULL);
|
||||
// Attach the LCD to the SPI bus
|
||||
TEST_ESP_OK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)TEST_LCD_HOST, &io_config, &io_handle));
|
||||
|
||||
ESP_LOGI(TAG, "Install LCD driver of sh8601");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
const sh8601_vendor_config_t vendor_config = {
|
||||
.init_cmds = lcd_init_cmds,
|
||||
.init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]),
|
||||
.flags = {
|
||||
.use_qspi_interface = 1,
|
||||
},
|
||||
};
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = TEST_PIN_NUM_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.bits_per_pixel = TEST_LCD_BIT_PER_PIXEL,
|
||||
.vendor_config = (void *)&vendor_config,
|
||||
};
|
||||
TEST_ESP_OK(esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle));
|
||||
esp_lcd_panel_reset(panel_handle);
|
||||
esp_lcd_panel_init(panel_handle);
|
||||
esp_lcd_panel_disp_on_off(panel_handle, true);
|
||||
|
||||
test_draw_bitmap(panel_handle);
|
||||
|
||||
TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
|
||||
TEST_ESP_OK(spi_bus_free(TEST_LCD_HOST));
|
||||
}
|
||||
|
||||
// Some resources are lazy allocated in the LCD driver, the threadhold is left for that case
|
||||
#define TEST_MEMORY_LEAK_THRESHOLD (300)
|
||||
|
||||
static size_t before_free_8bit;
|
||||
static size_t before_free_32bit;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD);
|
||||
unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
/**
|
||||
* __ ___ __ ___ _
|
||||
* / _\ /\ /( _ ) / /_ / _ \/ |
|
||||
* \ \ / /_/ / _ \| '_ \| | | | |
|
||||
* _\ \/ __ / (_) | (_) | |_| | |
|
||||
* \__/\/ /_/ \___/ \___/ \___/|_|
|
||||
*/
|
||||
printf(" __ ___ __ ___ _\r\n");
|
||||
printf("/ _\\ /\\ /( _ ) / /_ / _ \\/ |\r\n");
|
||||
printf("\\ \\ / /_/ / _ \\| '_ \\| | | | |\r\n");
|
||||
printf("_\\ \\/ __ / (_) | (_) | |_| | |\r\n");
|
||||
printf("\\__/\\/ /_/ \\___/ \\___/ \\___/|_|\r\n");
|
||||
unity_run_menu();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
@pytest.mark.target('esp32s3')
|
||||
@pytest.mark.env('esp32_s3_lcd_ev_board')
|
||||
def test_usb_stream(dut: Dut)-> None:
|
||||
dut.run_all_single_board_cases()
|
||||
|
||||
2061
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/test_apps/sdkconfig
Normal file
2061
05_LVGL_WITH_RAM/components/esp_lcd_sh8601/test_apps/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
# For IDF 5.0
|
||||
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
|
||||
|
||||
# For IDF4.4
|
||||
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP_TASK_WDT=n
|
||||
Reference in New Issue
Block a user