add some code
This commit is contained in:
@@ -0,0 +1 @@
|
||||
00ab2872c56a4037e6d1efda104ef0da00c5296865f8f938cc7cc2fc3e99f962
|
||||
@@ -0,0 +1 @@
|
||||
{"version": "1.0", "algorithm": "sha256", "created_at": "2025-05-21T15:56:53.722942+00:00", "files": [{"path": "CMakeLists.txt", "size": 456, "hash": "581b434233fe10f4ae03f48fe4ffcdc76e66027fbe744a663cb997910f492b4c"}, {"path": "idf_component.yml", "size": 419, "hash": "ad43d718c731c9544afc1212c7cdfa2a191b20ace26432a16834b0103d99023e"}, {"path": "esp_lcd_st7796_mipi.c", "size": 10806, "hash": "d072e86ab67b328e1377b5bfbb303273d4908c2fb3b6143ce10e5ed06eb01671"}, {"path": "esp_lcd_st7796.c", "size": 1238, "hash": "03c742b629f27d38a94cd3aa8a157195b9a9f8cc57618d30e96ecc3545b07b98"}, {"path": "README.md", "size": 6349, "hash": "bea9ce10526e7d6ad31f0ae522be18ecdd21275ff9935d3d5d86946f3da605da"}, {"path": "esp_lcd_st7796_general.c", "size": 13051, "hash": "d4b50de091a25cb3c001ed903d0178c6fc76d2705ea87daa11fe245a93592447"}, {"path": "license.txt", "size": 11358, "hash": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"}, {"path": "include/esp_lcd_st7796.h", "size": 9569, "hash": "25837296fe53c0a3a6dbb7e80dae24a97cbf266abbae762264a000f1b245a7e2"}, {"path": "test_apps/CMakeLists.txt", "size": 316, "hash": "bb5058dad04df955f82c042f32ea8b9a5434a54104caa0f01b2929741a24f0e5"}, {"path": "test_apps/sdkconfig.defaults", "size": 353, "hash": "296f4a3a607c38d36f5d9405c3fc968a1a495447f762753f007b212b0d21fbb7"}, {"path": "priv_include/esp_lcd_st7796_interface.h", "size": 1275, "hash": "3dcf1fc8902350f3d7e172cfb956431047121a011f0e35f86fd22437a675a66b"}, {"path": "test_apps/main/test_esp_lcd_st7796_general.c", "size": 5226, "hash": "b1027efe0ff375cfe33452525160d645fd4f83887235d3590dedc06eddf0f533"}, {"path": "test_apps/main/CMakeLists.txt", "size": 113, "hash": "5b20a48123d65be888744cb5c81ce67aab07572469268b9daf97e7d8177918f0"}, {"path": "test_apps/main/idf_component.yml", "size": 148, "hash": "2c9d76d9b5cf309b56ac449dfb787fadc3b3bd9debd7c941f2e75b413e7eae04"}, {"path": "test_apps/main/test_esp_lcd_st7796_mipi.c", "size": 7985, "hash": "b76a27bec8fd126f51a5a60729e62d7e703d2e644da721a35ca0637420c64e2c"}, {"path": "test_apps/main/test_app_main.c", "size": 1499, "hash": "c1525b7878c26e6700e6e992037a132a18b8d5ac6a9006d80c245d039815c7b0"}]}
|
||||
14
managed_components/espressif__esp_lcd_st7796/CMakeLists.txt
Normal file
14
managed_components/espressif__esp_lcd_st7796/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
set(srcs "esp_lcd_st7796.c"
|
||||
"esp_lcd_st7796_general.c")
|
||||
if(CONFIG_SOC_MIPI_DSI_SUPPORTED)
|
||||
list(APPEND srcs "esp_lcd_st7796_mipi.c")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES "esp_lcd"
|
||||
PRIV_REQUIRES "driver")
|
||||
|
||||
include(package_manager)
|
||||
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
|
||||
133
managed_components/espressif__esp_lcd_st7796/README.md
Normal file
133
managed_components/espressif__esp_lcd_st7796/README.md
Normal file
@@ -0,0 +1,133 @@
|
||||
# ESP LCD ST7796
|
||||
|
||||
[](https://components.espressif.com/components/espressif/esp_lcd_st7796)
|
||||
|
||||
Implementation of the ST7796 LCD controller with esp_lcd component.
|
||||
|
||||
| LCD controller | Communication interface | Component name | Link to datasheet |
|
||||
| :------------: | :---------------------: | :------------: | :---------------: |
|
||||
| ST7796 | SPI/I80/MIPI-DSI | esp_lcd_st7796 | [Specification](https://www.displayfuture.com/Display/datasheet/controller/ST7796s.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-dependency`, e.g.
|
||||
|
||||
```bash
|
||||
compote manifest add-dependency espressif/esp_lcd_st7796==1.0.0
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
### I80 interface
|
||||
|
||||
```c
|
||||
ESP_LOGI(TAG, "Initialize Intel 8080 bus");
|
||||
esp_lcd_i80_bus_handle_t i80_bus = NULL;
|
||||
esp_lcd_i80_bus_config_t bus_config = ST7796_PANEL_BUS_I80_CONFIG(
|
||||
EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES * EXAMPLE_LCD_BIT_PER_PIXEL / 8, EXAMPLE_LCD_DATA_WIDTH,
|
||||
EXAMPLE_PIN_NUM_LCD_DC, EXAMPLE_PIN_NUM_LCD_WR,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA0, EXAMPLE_PIN_NUM_LCD_DATA1, EXAMPLE_PIN_NUM_LCD_DATA2, EXAMPLE_PIN_NUM_LCD_DATA3,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA4, EXAMPLE_PIN_NUM_LCD_DATA5, EXAMPLE_PIN_NUM_LCD_DATA6, EXAMPLE_PIN_NUM_LCD_DATA7,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA8, EXAMPLE_PIN_NUM_LCD_DATA9, EXAMPLE_PIN_NUM_LCD_DATA10, EXAMPLE_PIN_NUM_LCD_DATA11,
|
||||
EXAMPLE_PIN_NUM_LCD_DATA12, EXAMPLE_PIN_NUM_LCD_DATA13, EXAMPLE_PIN_NUM_LCD_DATA14, EXAMPLE_PIN_NUM_LCD_DATA15);
|
||||
ESP_ERROR_CHECK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
esp_lcd_panel_io_i80_config_t io_config = ST7796_PANEL_IO_I80_CONFIG(EXAMPLE_PIN_NUM_LCD_CS, example_callback, &example_callback_ctx);
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
|
||||
|
||||
/**
|
||||
* Uncomment these lines if use custom initialization commands.
|
||||
* The array should be declared as "static const" and positioned outside the function.
|
||||
*/
|
||||
// static const st7796_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
// // {cmd, { data }, data_size, delay_ms}
|
||||
// {0xf0, (uint8_t []){0xc3}, 1, 0},
|
||||
// {0xf0, (uint8_t []){0x96}, 1, 0},
|
||||
// {0xb4, (uint8_t []){0x01}, 1, 0},
|
||||
// ...
|
||||
// };
|
||||
|
||||
ESP_LOGI(TAG, "Install ST7796 panel driver");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
// st7796_vendor_config_t vendor_config = { // Uncomment these lines if use custom initialization commands
|
||||
// .init_cmds = lcd_init_cmds,
|
||||
// .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(st7796_lcd_init_cmd_t),
|
||||
// };
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST, // Set to -1 if not use
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) // Implemented by LCD command `36h`
|
||||
.color_space = ESP_LCD_COLOR_SPACE_RGB,
|
||||
#else
|
||||
.rgb_endian = LCD_RGB_ENDIAN_RGB,
|
||||
#endif
|
||||
.bits_per_pixel = EXAMPLE_LCD_BIT_PER_PIXEL, // Implemented by LCD command `3Ah` (16/18/24)
|
||||
// .vendor_config = &vendor_config, // Uncomment this line if use custom initialization commands
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7796(io_handle, &panel_config, &panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_off(panel_handle, false));
|
||||
#else
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
#endif
|
||||
```
|
||||
|
||||
### MIPI Interface
|
||||
|
||||
```c
|
||||
/**
|
||||
* Uncomment these line if use custom initialization commands.
|
||||
* The array should be declared as static const and positioned outside the function.
|
||||
*/
|
||||
// static const st7796_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
// // cmd data data_size delay_ms
|
||||
// {0xFF, (uint8_t []){0x77, 0x01, 0x00, 0x00, 0x13}, 5, 0},
|
||||
// {0xEF, (uint8_t []){0x08}, 1, 0},
|
||||
// {0xFF, (uint8_t []){0x77, 0x01, 0x00, 0x00, 0x10}, 5, 0},
|
||||
// {0xC0, (uint8_t []){0x3B, 0x00}, 2, 0},
|
||||
// ...
|
||||
// };
|
||||
ESP_LOGI(TAG, "MIPI DSI PHY Powered on");
|
||||
esp_ldo_channel_config_t ldo_mipi_phy_config = {
|
||||
.chan_id = EXAMPLE_MIPI_DSI_PHY_PWR_LDO_CHAN,
|
||||
.voltage_mv = EXAMPLE_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy));
|
||||
|
||||
ESP_LOGI(TAG, "Initialize MIPI DSI bus");
|
||||
esp_lcd_dsi_bus_config_t bus_config = ST7796_PANEL_BUS_DSI_1CH_CONFIG();
|
||||
ESP_ERROR_CHECK(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_dbi_io_config_t dbi_config = ST7796_PANEL_IO_DBI_CONFIG();
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &mipi_dbi_io));
|
||||
|
||||
ESP_LOGI(TAG, "Install LCD driver of st7796");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
esp_lcd_dpi_panel_config_t dpi_config = ST7796_320_480_PANEL_60HZ_DPI_CONFIG(EXAMPLE_MIPI_DPI_PX_FORMAT);
|
||||
st7796_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(st7796_lcd_init_cmd_t),
|
||||
.flags.use_mipi_interface = 1,
|
||||
.mipi_config = {
|
||||
.dsi_bus = mipi_dsi_bus,
|
||||
.dpi_config = &dpi_config,
|
||||
},
|
||||
};
|
||||
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,
|
||||
.bits_per_pixel = EXAMPLE_LCD_BIT_PER_PIXEL,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7796(mipi_dbi_io, &panel_config, &panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_lcd_types.h"
|
||||
|
||||
#include "esp_lcd_st7796.h"
|
||||
#include "esp_lcd_st7796_interface.h"
|
||||
|
||||
static const char *TAG = "st7796";
|
||||
|
||||
esp_err_t esp_lcd_new_panel_st7796(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_LOGI(TAG, "version: %d.%d.%d", ESP_LCD_ST7796_VER_MAJOR, ESP_LCD_ST7796_VER_MINOR, ESP_LCD_ST7796_VER_PATCH);
|
||||
ESP_RETURN_ON_FALSE(panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, TAG, "Invalid arguments");
|
||||
st7796_vendor_config_t *vendor_config = (st7796_vendor_config_t *)panel_dev_config->vendor_config;
|
||||
|
||||
esp_err_t ret = ESP_ERR_NOT_SUPPORTED;
|
||||
|
||||
if (vendor_config && vendor_config->flags.use_mipi_interface) {
|
||||
#if SOC_MIPI_DSI_SUPPORTED
|
||||
ret = esp_lcd_new_panel_st7796_mipi(io, panel_dev_config, ret_panel);
|
||||
#else
|
||||
ESP_LOGE(TAG, "The chip does not support MIPI-DSI interface");
|
||||
#endif
|
||||
} else {
|
||||
ret = esp_lcd_new_panel_st7796_general(io, panel_dev_config, ret_panel);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 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"
|
||||
|
||||
#include "esp_lcd_st7796.h"
|
||||
#include "esp_lcd_st7796_interface.h"
|
||||
|
||||
static const char *TAG = "st7796_general";
|
||||
|
||||
static esp_err_t panel_st7796_del(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_st7796_reset(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_st7796_init(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_st7796_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_st7796_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
|
||||
static esp_err_t panel_st7796_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
static esp_err_t panel_st7796_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
|
||||
static esp_err_t panel_st7796_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
|
||||
static esp_err_t panel_st7796_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;
|
||||
uint8_t fb_bits_per_pixel;
|
||||
uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
|
||||
uint8_t colmod_val; // save current value of LCD_CMD_COLMOD register
|
||||
const st7796_lcd_init_cmd_t *init_cmds;
|
||||
uint16_t init_cmds_size;
|
||||
} st7796_panel_t;
|
||||
|
||||
esp_err_t esp_lcd_new_panel_st7796_general(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;
|
||||
st7796_panel_t *st7796 = NULL;
|
||||
gpio_config_t io_conf = { 0 };
|
||||
|
||||
ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||
st7796 = (st7796_panel_t *)calloc(1, sizeof(st7796_panel_t));
|
||||
ESP_GOTO_ON_FALSE(st7796, ESP_ERR_NO_MEM, err, TAG, "no mem for st7796 panel");
|
||||
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.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");
|
||||
}
|
||||
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
switch (panel_dev_config->color_space) {
|
||||
case ESP_LCD_COLOR_SPACE_RGB:
|
||||
st7796->madctl_val = 0;
|
||||
break;
|
||||
case ESP_LCD_COLOR_SPACE_BGR:
|
||||
st7796->madctl_val |= LCD_CMD_BGR_BIT;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color space");
|
||||
break;
|
||||
}
|
||||
#else
|
||||
switch (panel_dev_config->rgb_endian) {
|
||||
case LCD_RGB_ENDIAN_RGB:
|
||||
st7796->madctl_val = 0;
|
||||
break;
|
||||
case LCD_RGB_ENDIAN_BGR:
|
||||
st7796->madctl_val |= LCD_CMD_BGR_BIT;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported rgb endian");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (panel_dev_config->bits_per_pixel) {
|
||||
case 16: // RGB565
|
||||
st7796->colmod_val = 0x05;
|
||||
st7796->fb_bits_per_pixel = 16;
|
||||
break;
|
||||
case 18: // RGB666
|
||||
st7796->colmod_val = 0x06;
|
||||
// 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
|
||||
st7796->fb_bits_per_pixel = 24;
|
||||
break;
|
||||
case 24: // RGB888
|
||||
st7796->colmod_val = 0x07;
|
||||
st7796->fb_bits_per_pixel = 24;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
|
||||
break;
|
||||
}
|
||||
|
||||
st7796->io = io;
|
||||
st7796->reset_gpio_num = panel_dev_config->reset_gpio_num;
|
||||
st7796->reset_level = panel_dev_config->flags.reset_active_high;
|
||||
if (panel_dev_config->vendor_config) {
|
||||
st7796->init_cmds = ((st7796_vendor_config_t *)panel_dev_config->vendor_config)->init_cmds;
|
||||
st7796->init_cmds_size = ((st7796_vendor_config_t *)panel_dev_config->vendor_config)->init_cmds_size;
|
||||
}
|
||||
st7796->base.del = panel_st7796_del;
|
||||
st7796->base.reset = panel_st7796_reset;
|
||||
st7796->base.init = panel_st7796_init;
|
||||
st7796->base.draw_bitmap = panel_st7796_draw_bitmap;
|
||||
st7796->base.invert_color = panel_st7796_invert_color;
|
||||
st7796->base.set_gap = panel_st7796_set_gap;
|
||||
st7796->base.mirror = panel_st7796_mirror;
|
||||
st7796->base.swap_xy = panel_st7796_swap_xy;
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
st7796->base.disp_off = panel_st7796_disp_on_off;
|
||||
#else
|
||||
st7796->base.disp_on_off = panel_st7796_disp_on_off;
|
||||
#endif
|
||||
*ret_panel = &(st7796->base);
|
||||
ESP_LOGD(TAG, "new st7796 panel @%p", st7796);
|
||||
|
||||
ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_ST7796_VER_MAJOR, ESP_LCD_ST7796_VER_MINOR,
|
||||
ESP_LCD_ST7796_VER_PATCH);
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (st7796) {
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(panel_dev_config->reset_gpio_num);
|
||||
}
|
||||
free(st7796);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_del(esp_lcd_panel_t *panel)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
|
||||
if (st7796->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(st7796->reset_gpio_num);
|
||||
}
|
||||
ESP_LOGD(TAG, "del st7796 panel @%p", st7796);
|
||||
free(st7796);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_reset(esp_lcd_panel_t *panel)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
|
||||
// perform hardware reset
|
||||
if (st7796->reset_gpio_num >= 0) {
|
||||
gpio_set_level(st7796->reset_gpio_num, st7796->reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(st7796->reset_gpio_num, !st7796->reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
} else { // perform software reset
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(120)); // spec, wait at least 5ms before sending new command
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static const st7796_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
// {cmd, { data }, data_size, delay_ms}
|
||||
{0xf0, (uint8_t []){0xc3}, 1, 0},
|
||||
{0xf0, (uint8_t []){0x96}, 1, 0},
|
||||
{0xb4, (uint8_t []){0x01}, 1, 0},
|
||||
{0xb7, (uint8_t []){0xc6}, 1, 0},
|
||||
{0xe8, (uint8_t []){0x40, 0x8a, 0x00, 0x00, 0x29, 0x19, 0xa5, 0x33}, 8, 0},
|
||||
{0xc1, (uint8_t []){0x06}, 1, 0},
|
||||
{0xc2, (uint8_t []){0xa7}, 1, 0},
|
||||
{0xc5, (uint8_t []){0x18}, 1, 0},
|
||||
{0xe0, (uint8_t []){0xf0, 0x09, 0x0b, 0x06, 0x04, 0x15, 0x2f, 0x54, 0x42, 0x3c, 0x17, 0x14, 0x18, 0x1b}, 14, 0},
|
||||
{0xe1, (uint8_t []){0xf0, 0x09, 0x0b, 0x06, 0x04, 0x03, 0x2d, 0x43, 0x42, 0x3b, 0x16, 0x14, 0x17, 0x1b}, 14, 0},
|
||||
{0xf0, (uint8_t []){0x3c}, 1, 0},
|
||||
{0xf0, (uint8_t []){0x69}, 1, 0},
|
||||
};
|
||||
|
||||
static esp_err_t panel_st7796_init(esp_lcd_panel_t *panel)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
|
||||
// LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
st7796->madctl_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) {
|
||||
st7796->colmod_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
|
||||
const st7796_lcd_init_cmd_t *init_cmds = NULL;
|
||||
uint16_t init_cmds_size = 0;
|
||||
if (st7796->init_cmds) {
|
||||
init_cmds = st7796->init_cmds;
|
||||
init_cmds_size = st7796->init_cmds_size;
|
||||
} else {
|
||||
init_cmds = vendor_specific_init_default;
|
||||
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(st7796_lcd_init_cmd_t);
|
||||
}
|
||||
|
||||
bool is_cmd_overwritten = false;
|
||||
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;
|
||||
st7796->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
case LCD_CMD_COLMOD:
|
||||
is_cmd_overwritten = true;
|
||||
st7796->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(esp_lcd_panel_io_tx_param(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_st7796_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_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 = st7796->io;
|
||||
|
||||
x_start += st7796->x_gap;
|
||||
x_end += st7796->x_gap;
|
||||
y_start += st7796->y_gap;
|
||||
y_end += st7796->y_gap;
|
||||
|
||||
// define an area of frame memory where MCU can access
|
||||
ESP_RETURN_ON_ERROR(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), TAG, "send command failed");
|
||||
ESP_RETURN_ON_ERROR(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), TAG, "send command failed");
|
||||
// transfer frame buffer
|
||||
size_t len = (x_end - x_start) * (y_end - y_start) * st7796->fb_bits_per_pixel / 8;
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR, color_data, len), TAG, "send command failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
int command = 0;
|
||||
if (invert_color_data) {
|
||||
command = LCD_CMD_INVON;
|
||||
} else {
|
||||
command = LCD_CMD_INVOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
if (mirror_x) {
|
||||
st7796->madctl_val |= LCD_CMD_MX_BIT;
|
||||
} else {
|
||||
st7796->madctl_val &= ~LCD_CMD_MX_BIT;
|
||||
}
|
||||
if (mirror_y) {
|
||||
st7796->madctl_val |= LCD_CMD_MY_BIT;
|
||||
} else {
|
||||
st7796->madctl_val &= ~LCD_CMD_MY_BIT;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
st7796->madctl_val
|
||||
}, 1), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
if (swap_axes) {
|
||||
st7796->madctl_val |= LCD_CMD_MV_BIT;
|
||||
} else {
|
||||
st7796->madctl_val &= ~LCD_CMD_MV_BIT;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
st7796->madctl_val
|
||||
}, 1), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
st7796->x_gap = x_gap;
|
||||
st7796->y_gap = y_gap;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
|
||||
{
|
||||
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
int command = 0;
|
||||
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
on_off = !on_off;
|
||||
#endif
|
||||
|
||||
if (on_off) {
|
||||
command = LCD_CMD_DISPON;
|
||||
} else {
|
||||
command = LCD_CMD_DISPOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#if SOC_MIPI_DSI_SUPPORTED
|
||||
#include "esp_check.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_lcd_panel_commands.h"
|
||||
#include "esp_lcd_panel_interface.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#include "esp_lcd_st7796.h"
|
||||
#include "esp_lcd_st7796_interface.h"
|
||||
|
||||
typedef struct {
|
||||
esp_lcd_panel_io_handle_t io;
|
||||
int reset_gpio_num;
|
||||
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 st7796_lcd_init_cmd_t *init_cmds;
|
||||
uint16_t init_cmds_size;
|
||||
struct {
|
||||
unsigned int reset_level: 1;
|
||||
} flags;
|
||||
// To save the original functions of MIPI DPI panel
|
||||
esp_err_t (*del)(esp_lcd_panel_t *panel);
|
||||
esp_err_t (*init)(esp_lcd_panel_t *panel);
|
||||
} st7796_panel_t;
|
||||
|
||||
static const char *TAG = "st7796_mipi";
|
||||
|
||||
static esp_err_t panel_st7796_del(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_st7796_init(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_st7796_reset(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_st7796_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
|
||||
static esp_err_t panel_st7796_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool on_off);
|
||||
|
||||
esp_err_t esp_lcd_new_panel_st7796_mipi(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 arguments");
|
||||
st7796_vendor_config_t *vendor_config = (st7796_vendor_config_t *)panel_dev_config->vendor_config;
|
||||
ESP_RETURN_ON_FALSE(vendor_config && vendor_config->mipi_config.dpi_config && vendor_config->mipi_config.dsi_bus, ESP_ERR_INVALID_ARG, TAG,
|
||||
"invalid vendor config");
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)calloc(1, sizeof(st7796_panel_t));
|
||||
ESP_RETURN_ON_FALSE(st7796, ESP_ERR_NO_MEM, TAG, "no mem for st7796 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 LCD_RGB_ELEMENT_ORDER_RGB:
|
||||
st7796->madctl_val = 0;
|
||||
break;
|
||||
case LCD_RGB_ELEMENT_ORDER_BGR:
|
||||
st7796->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: // RGB565
|
||||
st7796->colmod_val = 0x55;
|
||||
break;
|
||||
case 18: // RGB666
|
||||
st7796->colmod_val = 0x66;
|
||||
break;
|
||||
case 24: // RGB888
|
||||
st7796->colmod_val = 0x77;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
|
||||
break;
|
||||
}
|
||||
|
||||
st7796->io = io;
|
||||
st7796->init_cmds = vendor_config->init_cmds;
|
||||
st7796->init_cmds_size = vendor_config->init_cmds_size;
|
||||
st7796->reset_gpio_num = panel_dev_config->reset_gpio_num;
|
||||
st7796->flags.reset_level = panel_dev_config->flags.reset_active_high;
|
||||
|
||||
// Create MIPI DPI panel
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_dpi(vendor_config->mipi_config.dsi_bus, vendor_config->mipi_config.dpi_config, &panel_handle), err, TAG,
|
||||
"create MIPI DPI panel failed");
|
||||
ESP_LOGD(TAG, "new MIPI DPI panel @%p", panel_handle);
|
||||
|
||||
// Save the original functions of MIPI DPI panel
|
||||
st7796->del = panel_handle->del;
|
||||
st7796->init = panel_handle->init;
|
||||
// Overwrite the functions of MIPI DPI panel
|
||||
panel_handle->del = panel_st7796_del;
|
||||
panel_handle->init = panel_st7796_init;
|
||||
panel_handle->reset = panel_st7796_reset;
|
||||
panel_handle->mirror = panel_st7796_mirror;
|
||||
panel_handle->invert_color = panel_st7796_invert_color;
|
||||
panel_handle->disp_on_off = panel_st7796_disp_on_off;
|
||||
panel_handle->user_data = st7796;
|
||||
*ret_panel = panel_handle;
|
||||
ESP_LOGD(TAG, "new st7796 panel @%p", st7796);
|
||||
|
||||
ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_ST7796_VER_MAJOR, ESP_LCD_ST7796_VER_MINOR,
|
||||
ESP_LCD_ST7796_VER_PATCH);
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (st7796) {
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(panel_dev_config->reset_gpio_num);
|
||||
}
|
||||
free(st7796);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const st7796_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
// {cmd, { data }, data_size, delay_ms}
|
||||
{0x11, (uint8_t []){0x00}, 0, 120},
|
||||
{0x36, (uint8_t []){0x48}, 1, 0},
|
||||
{0x3A, (uint8_t []){0x77}, 1, 0},
|
||||
{0xF0, (uint8_t []){0xC3}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x96}, 1, 0},
|
||||
{0xB4, (uint8_t []){0x02}, 1, 0},
|
||||
{0xB7, (uint8_t []){0xC6}, 1, 0},
|
||||
{0xB6, (uint8_t []){0x2F}, 1, 0},
|
||||
{0x11, (uint8_t []){0xC0, 0xF0, 0x35}, 3, 0},
|
||||
{0xC1, (uint8_t []){0x15}, 1, 0},
|
||||
{0xC2, (uint8_t []){0xAF}, 1, 0},
|
||||
{0xC3, (uint8_t []){0x09}, 1, 0},
|
||||
{0xC5, (uint8_t []){0x22}, 1, 0},
|
||||
{0xC6, (uint8_t []){0x00}, 1, 0},
|
||||
{0x11, (uint8_t []){0xE8, 0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33}, 9, 0},
|
||||
{0x11, (uint8_t []){0xE0, 0x70, 0x00, 0x05, 0x03, 0x02, 0x20, 0x29, 0x01, 0x45, 0x30, 0x09, 0x07, 0x22, 0x29}, 15, 0},
|
||||
{0x11, (uint8_t []){0xE1, 0x70, 0x0C, 0x10, 0x0F, 0x0E, 0x09, 0x35, 0x64, 0x48, 0x3A, 0x14, 0x13, 0x2E, 0x30}, 15, 0},
|
||||
{0x11, (uint8_t []){0xE0, 0x70, 0x04, 0x0A, 0x0B, 0x0A, 0x27, 0x31, 0x55, 0x47, 0x29, 0x13, 0x13, 0x29, 0x2D}, 15, 0},
|
||||
{0x11, (uint8_t []){0xE1, 0x70, 0x08, 0x0E, 0x09, 0x08, 0x04, 0x33, 0x32, 0x49, 0x36, 0x14, 0x14, 0x2A, 0x2F}, 15, 0},
|
||||
{0x21, (uint8_t []){0x00}, 0, 0},
|
||||
{0xF0, (uint8_t []){0xC3}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x96}, 1, 120},
|
||||
{0xF0, (uint8_t []){0xC3}, 1, 0},
|
||||
{0x29, (uint8_t []){0x00}, 0, 0},
|
||||
{0x2C, (uint8_t []){0x00}, 0, 0},
|
||||
//============ Gamma END===========
|
||||
};
|
||||
|
||||
static esp_err_t panel_st7796_del(esp_lcd_panel_t *panel)
|
||||
{
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)panel->user_data;
|
||||
|
||||
if (st7796->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(st7796->reset_gpio_num);
|
||||
}
|
||||
// Delete MIPI DPI panel
|
||||
st7796->del(panel);
|
||||
ESP_LOGD(TAG, "del st7796 panel @%p", st7796);
|
||||
free(st7796);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_init(esp_lcd_panel_t *panel)
|
||||
{
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
const st7796_lcd_init_cmd_t *init_cmds = NULL;
|
||||
uint16_t init_cmds_size = 0;
|
||||
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
st7796->madctl_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) {
|
||||
st7796->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 (st7796->init_cmds) {
|
||||
init_cmds = st7796->init_cmds;
|
||||
init_cmds_size = st7796->init_cmds_size;
|
||||
} else {
|
||||
init_cmds = vendor_specific_init_default;
|
||||
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(st7796_lcd_init_cmd_t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < init_cmds_size; i++) {
|
||||
// Send command
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(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");
|
||||
|
||||
ESP_RETURN_ON_ERROR(st7796->init(panel), TAG, "init MIPI DPI panel failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_reset(esp_lcd_panel_t *panel)
|
||||
{
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
|
||||
// Perform hardware reset
|
||||
if (st7796->reset_gpio_num >= 0) {
|
||||
gpio_set_level(st7796->reset_gpio_num, st7796->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(st7796->reset_gpio_num, !st7796->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
} else if (io) { // Perform software reset
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
|
||||
{
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
uint8_t command = 0;
|
||||
|
||||
ESP_RETURN_ON_FALSE(io, ESP_ERR_INVALID_STATE, TAG, "invalid panel IO");
|
||||
|
||||
if (invert_color_data) {
|
||||
command = LCD_CMD_INVON;
|
||||
} else {
|
||||
command = LCD_CMD_INVOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
|
||||
{
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
uint8_t madctl_val = st7796->madctl_val;
|
||||
|
||||
ESP_RETURN_ON_FALSE(io, ESP_ERR_INVALID_STATE, TAG, "invalid panel IO");
|
||||
|
||||
// Control mirror through LCD command
|
||||
if (mirror_x) {
|
||||
madctl_val |= LCD_CMD_MX_BIT;
|
||||
} else {
|
||||
madctl_val &= ~LCD_CMD_MX_BIT;
|
||||
}
|
||||
if (mirror_y) {
|
||||
madctl_val |= LCD_CMD_MY_BIT;
|
||||
} else {
|
||||
madctl_val &= ~LCD_CMD_MY_BIT;
|
||||
}
|
||||
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t []) {
|
||||
madctl_val
|
||||
}, 1), TAG, "send command failed");
|
||||
st7796->madctl_val = madctl_val;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
|
||||
{
|
||||
st7796_panel_t *st7796 = (st7796_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = st7796->io;
|
||||
int command = 0;
|
||||
|
||||
if (on_off) {
|
||||
command = LCD_CMD_DISPON;
|
||||
} else {
|
||||
command = LCD_CMD_DISPOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
dependencies:
|
||||
cmake_utilities: 0.*
|
||||
idf: '>=4.4'
|
||||
description: ESP LCD ST7796 driver (SPI && I80 && MIPI DSI)
|
||||
repository: git://github.com/espressif/esp-bsp.git
|
||||
repository_info:
|
||||
commit_sha: 7e5759a5dcae75624e0c7abb8d8aef6b95e33b1f
|
||||
path: components/lcd/esp_lcd_st7796
|
||||
targets:
|
||||
- esp32
|
||||
- esp32s2
|
||||
- esp32s3
|
||||
- esp32p4
|
||||
url: https://github.com/espressif/esp-bsp/tree/master/components/lcd/esp_lcd_st7796
|
||||
version: 1.3.2
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* @brief ESP LCD: ST7796
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/lcd_types.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_idf_version.h"
|
||||
#if SOC_MIPI_DSI_SUPPORTED
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
} st7796_lcd_init_cmd_t;
|
||||
|
||||
/**
|
||||
* @brief LCD panel vendor configuration.
|
||||
*
|
||||
* @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
const st7796_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
|
||||
* 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 */
|
||||
#if SOC_MIPI_DSI_SUPPORTED
|
||||
struct {
|
||||
esp_lcd_dsi_bus_handle_t dsi_bus; /*!< MIPI-DSI bus configuration */
|
||||
const esp_lcd_dpi_panel_config_t *dpi_config; /*!< MIPI-DPI panel configuration */
|
||||
} mipi_config;
|
||||
#endif
|
||||
struct {
|
||||
unsigned int use_mipi_interface: 1; /*<! Set to 1 if using MIPI interface, default is SPI/I80 interface */
|
||||
} flags;
|
||||
} st7796_vendor_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create LCD panel for model ST7796
|
||||
*
|
||||
* @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
|
||||
*
|
||||
* @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_st7796(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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////// Default Configuration Macros for I80 Interface /////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief LCD panel bus configuration structure
|
||||
*
|
||||
* @param[in] max_trans_bytes Maximum bytes of data to be transferred in one transaction. Normally set to the size of one frame bytes.
|
||||
* @param[in] data_width Data bus width
|
||||
* @param[in] dc I80 data/command pin number
|
||||
* @param[in] wr I80 write clock pin number
|
||||
* @param[in] d[0:15] I80 data pin number 0 ~ 15. Set to -1 if not used.
|
||||
*
|
||||
*/
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 1)
|
||||
#define ST7796_PANEL_BUS_I80_CONFIG(max_trans_bytes, data_width, dc, wr, d0, d1, d2, d3, d4, \
|
||||
d5, d6, d7, d8 , d9, d10, d11, d12, d13, d14, d15) \
|
||||
{ \
|
||||
.clk_src = LCD_CLK_SRC_PLL160M, \
|
||||
.dc_gpio_num = dc, \
|
||||
.wr_gpio_num = wr, \
|
||||
.data_gpio_nums = { \
|
||||
d0, d1, d2, d3, d4, d5, d6, d7, d8 , d9, d10, d11, d12, d13, d14, d15 \
|
||||
}, \
|
||||
.bus_width = data_width, \
|
||||
.max_transfer_bytes = max_trans_bytes, \
|
||||
}
|
||||
#else
|
||||
#define ST7796_PANEL_BUS_I80_CONFIG(max_trans_bytes, data_width, dc, wr, d0, d1, d2, d3, d4, \
|
||||
d5, d6, d7, d8 , d9, d10, d11, d12, d13, d14, d15) \
|
||||
{ \
|
||||
.clk_src = LCD_CLK_SRC_PLL160M, \
|
||||
.dc_gpio_num = dc, \
|
||||
.wr_gpio_num = wr, \
|
||||
.data_gpio_nums = { \
|
||||
d0, d1, d2, d3, d4, d5, d6, d7, d8 , d9, d10, d11, d12, d13, d14, d15 \
|
||||
}, \
|
||||
.bus_width = data_width, \
|
||||
.max_transfer_bytes = max_trans_bytes, \
|
||||
.psram_trans_align = 64, \
|
||||
.sram_trans_align = 4, \
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief LCD panel IO configuration structure
|
||||
*
|
||||
* @param[in] cs I80 chip select pin number
|
||||
* @param[in] cb Callback function when data transfer is done
|
||||
* @param[in] cb_ctx Callback function context
|
||||
*
|
||||
*/
|
||||
#define ST7796_PANEL_IO_I80_CONFIG(cs, cb, cb_ctx) \
|
||||
{ \
|
||||
.cs_gpio_num = cs, \
|
||||
.pclk_hz = 10 * 1000 * 1000, \
|
||||
.trans_queue_depth = 10, \
|
||||
.dc_levels = { \
|
||||
.dc_idle_level = 0, \
|
||||
.dc_cmd_level = 0, \
|
||||
.dc_dummy_level = 0, \
|
||||
.dc_data_level = 1, \
|
||||
}, \
|
||||
.flags = { \
|
||||
.swap_color_bytes = 1, \
|
||||
}, \
|
||||
.on_color_trans_done = cb, \
|
||||
.user_ctx = cb_ctx, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.lcd_param_bits = 8, \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////// Default Configuration Macros for MIPI-DSI Interface //////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief MIPI-DSI bus configuration structure
|
||||
*
|
||||
* @param[in] lane_num Number of data lanes
|
||||
* @param[in] lane_mbps Lane bit rate in Mbps
|
||||
*
|
||||
*/
|
||||
#define ST7796_PANEL_BUS_DSI_1CH_CONFIG() \
|
||||
{ \
|
||||
.bus_id = 0, \
|
||||
.num_data_lanes = 1, \
|
||||
.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT, \
|
||||
.lane_bit_rate_mbps = 480, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MIPI-DBI panel IO configuration structure
|
||||
*
|
||||
*/
|
||||
#define ST7796_PANEL_IO_DBI_CONFIG() \
|
||||
{ \
|
||||
.virtual_channel = 0, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.lcd_param_bits = 8, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MIPI DPI configuration structure
|
||||
*
|
||||
* @note refresh_rate = (dpi_clock_freq_mhz * 1000000) / (h_res + hsync_pulse_width + hsync_back_porch + hsync_front_porch)
|
||||
* / (v_res + vsync_pulse_width + vsync_back_porch + vsync_front_porch)
|
||||
*
|
||||
* @param[in] px_format Pixel format of the panel
|
||||
*
|
||||
*/
|
||||
#define ST7796_320_480_PANEL_60HZ_DPI_CONFIG(px_format) \
|
||||
{ \
|
||||
.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT, \
|
||||
.dpi_clock_freq_mhz = 10, \
|
||||
.virtual_channel = 0, \
|
||||
.pixel_format = px_format, \
|
||||
.num_fbs = 1, \
|
||||
.video_timing = { \
|
||||
.h_size = 320, \
|
||||
.v_size = 480, \
|
||||
.hsync_back_porch = 10, \
|
||||
.hsync_pulse_width = 10, \
|
||||
.hsync_front_porch = 20, \
|
||||
.vsync_back_porch = 10, \
|
||||
.vsync_pulse_width = 10, \
|
||||
.vsync_front_porch = 10, \
|
||||
}, \
|
||||
.flags.use_dma2d = true, \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
202
managed_components/espressif__esp_lcd_st7796/license.txt
Normal file
202
managed_components/espressif__esp_lcd_st7796/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,45 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_lcd_types.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/**
|
||||
* @brief Initialize ST7796 LCD panel with SPI/I80 interface
|
||||
*
|
||||
* @param[in] io LCD panel IO handle
|
||||
* @param[in] panel_dev_config LCD panel device configuration
|
||||
* @param[out] ret_panel LCD panel handle
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Otherwise: Fail
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_st7796_general(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);
|
||||
|
||||
#if SOC_MIPI_DSI_SUPPORTED
|
||||
/**
|
||||
* @brief Initialize ST7796 LCD panel with MIPI interface
|
||||
*
|
||||
* @param[in] io LCD panel IO handle
|
||||
* @param[in] panel_dev_config LCD panel device configuration
|
||||
* @param[out] ret_panel LCD panel handle
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - Otherwise: Fail
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_st7796_mipi(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);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -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_st7796)
|
||||
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
INCLUDE_DIRS "."
|
||||
WHOLE_ARCHIVE)
|
||||
@@ -0,0 +1,6 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
idf: ">=4.4"
|
||||
esp_lcd_st7796:
|
||||
version: "*"
|
||||
override_path: "../../../esp_lcd_st7796"
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include "unity_test_utils_memory.h"
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
// 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,135 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_LCD_I80_SUPPORTED
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
|
||||
#include "esp_lcd_st7796.h"
|
||||
|
||||
#define TEST_LCD_H_RES (320)
|
||||
#define TEST_LCD_V_RES (480)
|
||||
#define TEST_LCD_BIT_PER_PIXEL (16)
|
||||
#define TEST_LCD_DATA_WIDTH (8)
|
||||
|
||||
#define TEST_PIN_NUM_LCD_CS (GPIO_NUM_17)
|
||||
#define TEST_PIN_NUM_LCD_DC (GPIO_NUM_46)
|
||||
#define TEST_PIN_NUM_LCD_WR (GPIO_NUM_3)
|
||||
#define TEST_PIN_NUM_LCD_DATA0 (GPIO_NUM_9)
|
||||
#define TEST_PIN_NUM_LCD_DATA1 (GPIO_NUM_12)
|
||||
#define TEST_PIN_NUM_LCD_DATA2 (GPIO_NUM_11)
|
||||
#define TEST_PIN_NUM_LCD_DATA3 (GPIO_NUM_14)
|
||||
#define TEST_PIN_NUM_LCD_DATA4 (GPIO_NUM_13)
|
||||
#if CONFIG_IDF_TARGET_ESP32S2
|
||||
#define TEST_PIN_NUM_LCD_DATA5 (GPIO_NUM_8)
|
||||
#else
|
||||
#define TEST_PIN_NUM_LCD_DATA5 (GPIO_NUM_47)
|
||||
#endif
|
||||
#define TEST_PIN_NUM_LCD_DATA6 (GPIO_NUM_21)
|
||||
#define TEST_PIN_NUM_LCD_DATA7 (GPIO_NUM_45)
|
||||
#define TEST_PIN_NUM_LCD_DATA8 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA9 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA10 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA11 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA12 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA13 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA14 (-1)
|
||||
#define TEST_PIN_NUM_LCD_DATA15 (-1)
|
||||
#define TEST_PIN_NUM_LCD_RST (GPIO_NUM_NC)
|
||||
|
||||
#define TEST_DELAY_TIME_MS (3000)
|
||||
|
||||
static char *TAG = "st7796_test";
|
||||
static SemaphoreHandle_t refresh_finish = NULL;
|
||||
|
||||
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;
|
||||
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] = (BIT(j) >> (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);
|
||||
}
|
||||
|
||||
TEST_CASE("test st7796 to draw color bar with I80 interface", "[st7796][i80]")
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize Intel 8080 bus");
|
||||
esp_lcd_i80_bus_handle_t i80_bus = NULL;
|
||||
esp_lcd_i80_bus_config_t bus_config = ST7796_PANEL_BUS_I80_CONFIG(
|
||||
TEST_LCD_H_RES * TEST_LCD_V_RES * TEST_LCD_BIT_PER_PIXEL / 8, TEST_LCD_DATA_WIDTH,
|
||||
TEST_PIN_NUM_LCD_DC, TEST_PIN_NUM_LCD_WR,
|
||||
TEST_PIN_NUM_LCD_DATA0, TEST_PIN_NUM_LCD_DATA1, TEST_PIN_NUM_LCD_DATA2, TEST_PIN_NUM_LCD_DATA3,
|
||||
TEST_PIN_NUM_LCD_DATA4, TEST_PIN_NUM_LCD_DATA5, TEST_PIN_NUM_LCD_DATA6, TEST_PIN_NUM_LCD_DATA7,
|
||||
TEST_PIN_NUM_LCD_DATA8, TEST_PIN_NUM_LCD_DATA9, TEST_PIN_NUM_LCD_DATA10, TEST_PIN_NUM_LCD_DATA11,
|
||||
TEST_PIN_NUM_LCD_DATA12, TEST_PIN_NUM_LCD_DATA13, TEST_PIN_NUM_LCD_DATA14, TEST_PIN_NUM_LCD_DATA15);
|
||||
TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
esp_lcd_panel_io_i80_config_t io_config = ST7796_PANEL_IO_I80_CONFIG(TEST_PIN_NUM_LCD_CS, test_notify_refresh_ready, NULL);
|
||||
TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
|
||||
|
||||
ESP_LOGI(TAG, "Install ST7796 panel driver");
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = TEST_PIN_NUM_LCD_RST,
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
.color_space = ESP_LCD_COLOR_SPACE_BGR,
|
||||
#else
|
||||
.rgb_endian = LCD_RGB_ENDIAN_BGR,
|
||||
#endif
|
||||
.bits_per_pixel = TEST_LCD_BIT_PER_PIXEL,
|
||||
};
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
TEST_ESP_OK(esp_lcd_new_panel_st7796(io_handle, &panel_config, &panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_init(panel_handle));
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
TEST_ESP_OK(esp_lcd_panel_disp_off(panel_handle, false));
|
||||
#else
|
||||
TEST_ESP_OK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
#endif
|
||||
|
||||
test_draw_bitmap(panel_handle);
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_TIME_MS));
|
||||
|
||||
TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
|
||||
TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#if SOC_MIPI_DSI_SUPPORTED
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_ldo_regulator.h"
|
||||
#include "esp_dma_utils.h"
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include "unity_test_utils_memory.h"
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#include "esp_lcd_st7796.h"
|
||||
|
||||
#define TEST_LCD_H_RES (320)
|
||||
#define TEST_LCD_V_RES (480)
|
||||
#define TEST_LCD_BIT_PER_PIXEL (24)
|
||||
#define TEST_PIN_NUM_LCD_RST (-1)
|
||||
#define TEST_PIN_NUM_BK_LIGHT (-1) // set to -1 if not used
|
||||
#define TEST_LCD_BK_LIGHT_ON_LEVEL (1)
|
||||
#define TEST_LCD_BK_LIGHT_OFF_LEVEL !TEST_LCD_BK_LIGHT_ON_LEVEL
|
||||
|
||||
#if TEST_LCD_BIT_PER_PIXEL == 24
|
||||
#define TEST_MIPI_DPI_PX_FORMAT (LCD_COLOR_PIXEL_FORMAT_RGB888)
|
||||
#elif TEST_LCD_BIT_PER_PIXEL == 18
|
||||
#define TEST_MIPI_DPI_PX_FORMAT (LCD_COLOR_PIXEL_FORMAT_RGB666)
|
||||
#elif TEST_LCD_BIT_PER_PIXEL == 16
|
||||
#define TEST_MIPI_DPI_PX_FORMAT (LCD_COLOR_PIXEL_FORMAT_RGB565)
|
||||
#endif
|
||||
|
||||
#define TEST_DELAY_TIME_MS (3000)
|
||||
|
||||
#define TEST_MIPI_DSI_PHY_PWR_LDO_CHAN (3)
|
||||
#define TEST_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV (2500)
|
||||
|
||||
static char *TAG = "st7796_test";
|
||||
static esp_ldo_channel_handle_t ldo_mipi_phy = NULL;
|
||||
static esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
static esp_lcd_dsi_bus_handle_t mipi_dsi_bus = NULL;
|
||||
static esp_lcd_panel_io_handle_t mipi_dbi_io = NULL;
|
||||
static SemaphoreHandle_t refresh_finish = NULL;
|
||||
|
||||
IRAM_ATTR static bool test_notify_refresh_ready(esp_lcd_panel_handle_t panel, esp_lcd_dpi_panel_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
SemaphoreHandle_t refresh_finish = (SemaphoreHandle_t)user_ctx;
|
||||
BaseType_t need_yield = pdFALSE;
|
||||
|
||||
xSemaphoreGiveFromISR(refresh_finish, &need_yield);
|
||||
|
||||
return (need_yield == pdTRUE);
|
||||
}
|
||||
|
||||
static void test_init_lcd(void)
|
||||
{
|
||||
#if TEST_PIN_NUM_BK_LIGHT >= 0
|
||||
ESP_LOGI(TAG, "Turn on LCD backlight");
|
||||
gpio_config_t bk_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << TEST_PIN_NUM_BK_LIGHT
|
||||
};
|
||||
TEST_ESP_OK(gpio_config(&bk_gpio_config));
|
||||
TEST_ESP_OK(gpio_set_level(TEST_PIN_NUM_BK_LIGHT, TEST_LCD_BK_LIGHT_ON_LEVEL));
|
||||
#endif
|
||||
|
||||
// Turn on the power for MIPI DSI PHY, so it can go from "No Power" state to "Shutdown" state
|
||||
#ifdef TEST_MIPI_DSI_PHY_PWR_LDO_CHAN
|
||||
ESP_LOGI(TAG, "MIPI DSI PHY Powered on");
|
||||
esp_ldo_channel_config_t ldo_mipi_phy_config = {
|
||||
.chan_id = TEST_MIPI_DSI_PHY_PWR_LDO_CHAN,
|
||||
.voltage_mv = TEST_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV,
|
||||
};
|
||||
TEST_ESP_OK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy));
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Initialize MIPI DSI bus");
|
||||
esp_lcd_dsi_bus_config_t bus_config = ST7796_PANEL_BUS_DSI_1CH_CONFIG();
|
||||
TEST_ESP_OK(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_dbi_io_config_t dbi_config = ST7796_PANEL_IO_DBI_CONFIG();
|
||||
TEST_ESP_OK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &mipi_dbi_io));
|
||||
|
||||
ESP_LOGI(TAG, "Install LCD driver of st7796");
|
||||
esp_lcd_dpi_panel_config_t dpi_config = ST7796_320_480_PANEL_60HZ_DPI_CONFIG(TEST_MIPI_DPI_PX_FORMAT);
|
||||
st7796_vendor_config_t vendor_config = {
|
||||
.flags.use_mipi_interface = 1,
|
||||
.mipi_config.dsi_bus = mipi_dsi_bus,
|
||||
.mipi_config.dpi_config = &dpi_config,
|
||||
};
|
||||
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 = &vendor_config,
|
||||
};
|
||||
TEST_ESP_OK(esp_lcd_new_panel_st7796(mipi_dbi_io, &panel_config, &panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_init(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
|
||||
refresh_finish = xSemaphoreCreateBinary();
|
||||
TEST_ASSERT_NOT_NULL(refresh_finish);
|
||||
esp_lcd_dpi_panel_event_callbacks_t cbs = {
|
||||
.on_color_trans_done = test_notify_refresh_ready,
|
||||
};
|
||||
TEST_ESP_OK(esp_lcd_dpi_panel_register_event_callbacks(panel_handle, &cbs, refresh_finish));
|
||||
}
|
||||
|
||||
static void test_deinit_lcd(void)
|
||||
{
|
||||
TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
|
||||
TEST_ESP_OK(esp_lcd_panel_io_del(mipi_dbi_io));
|
||||
TEST_ESP_OK(esp_lcd_del_dsi_bus(mipi_dsi_bus));
|
||||
panel_handle = NULL;
|
||||
mipi_dbi_io = NULL;
|
||||
mipi_dsi_bus = NULL;
|
||||
|
||||
if (ldo_mipi_phy) {
|
||||
TEST_ESP_OK(esp_ldo_release_channel(ldo_mipi_phy));
|
||||
ldo_mipi_phy = NULL;
|
||||
}
|
||||
|
||||
vSemaphoreDelete(refresh_finish);
|
||||
refresh_finish = NULL;
|
||||
|
||||
#if TEST_PIN_NUM_BK_LIGHT >= 0
|
||||
TEST_ESP_OK(gpio_reset_pin(TEST_PIN_NUM_BK_LIGHT));
|
||||
TEST_ESP_OK(gpio_reset_pin(TEST_PIN_NUM_POWER));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_draw_color_bar(esp_lcd_panel_handle_t panel_handle, uint16_t h_res, uint16_t v_res)
|
||||
{
|
||||
uint8_t byte_per_pixel = (TEST_LCD_BIT_PER_PIXEL + 7) / 8;
|
||||
uint16_t row_line = v_res / byte_per_pixel / 8;
|
||||
uint8_t *color = (uint8_t *)heap_caps_calloc(1, row_line * h_res * byte_per_pixel, MALLOC_CAP_DMA);
|
||||
|
||||
for (int j = 0; j < byte_per_pixel * 8; j++) {
|
||||
for (int i = 0; i < row_line * h_res; i++) {
|
||||
for (int k = 0; k < byte_per_pixel; k++) {
|
||||
color[i * byte_per_pixel + k] = (BIT(j) >> (k * 8)) & 0xff;
|
||||
}
|
||||
}
|
||||
TEST_ESP_OK(esp_lcd_panel_draw_bitmap(panel_handle, 0, j * row_line, h_res, (j + 1) * row_line, color));
|
||||
xSemaphoreTake(refresh_finish, portMAX_DELAY);
|
||||
}
|
||||
|
||||
uint16_t color_line = row_line * byte_per_pixel * 8;
|
||||
uint16_t res_line = v_res - color_line;
|
||||
if (res_line) {
|
||||
for (int i = 0; i < res_line * h_res; i++) {
|
||||
for (int k = 0; k < byte_per_pixel; k++) {
|
||||
color[i * byte_per_pixel + k] = 0xff;
|
||||
}
|
||||
}
|
||||
TEST_ESP_OK(esp_lcd_panel_draw_bitmap(panel_handle, 0, color_line, h_res, v_res, color));
|
||||
xSemaphoreTake(refresh_finish, portMAX_DELAY);
|
||||
}
|
||||
|
||||
free(color);
|
||||
}
|
||||
|
||||
TEST_CASE("test st7796 to draw pattern with MIPI interface", "[st7796][draw_pattern]")
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize LCD device");
|
||||
test_init_lcd();
|
||||
|
||||
ESP_LOGI(TAG, "Show color bar pattern drawn by hardware");
|
||||
TEST_ESP_OK(esp_lcd_dpi_panel_set_pattern(panel_handle, MIPI_DSI_PATTERN_BAR_VERTICAL));
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_TIME_MS));
|
||||
TEST_ESP_OK(esp_lcd_dpi_panel_set_pattern(panel_handle, MIPI_DSI_PATTERN_BAR_HORIZONTAL));
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_TIME_MS));
|
||||
TEST_ESP_OK(esp_lcd_dpi_panel_set_pattern(panel_handle, MIPI_DSI_PATTERN_NONE));
|
||||
|
||||
ESP_LOGI(TAG, "Deinitialize LCD device");
|
||||
test_deinit_lcd();
|
||||
}
|
||||
|
||||
TEST_CASE("test st7796 to draw color bar with MIPI interface", "[st7796][draw_color_bar]")
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize LCD device");
|
||||
test_init_lcd();
|
||||
|
||||
ESP_LOGI(TAG, "Show color bar drawn by software");
|
||||
test_draw_color_bar(panel_handle, TEST_LCD_H_RES, TEST_LCD_V_RES);
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_TIME_MS));
|
||||
|
||||
ESP_LOGI(TAG, "Deinitialize LCD device");
|
||||
test_deinit_lcd();
|
||||
}
|
||||
|
||||
TEST_CASE("test st7796 to rotate with MIPI interface", "[st7796][rotate]")
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize LCD device");
|
||||
test_init_lcd();
|
||||
|
||||
ESP_LOGI(TAG, "Mirror the screen");
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
TEST_ASSERT_NOT_EQUAL(esp_lcd_panel_mirror(panel_handle, i & 2, i & 1), ESP_FAIL);
|
||||
|
||||
ESP_LOGI(TAG, "Mirror: %d", i);
|
||||
test_draw_color_bar(panel_handle, TEST_LCD_H_RES, TEST_LCD_V_RES);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Deinitialize LCD device");
|
||||
test_deinit_lcd();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
CONFIG_IDF_TARGET="esp32s3"
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_PERF=y
|
||||
CONFIG_SPIRAM=y
|
||||
CONFIG_SPIRAM_MODE_OCT=y
|
||||
CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y
|
||||
CONFIG_SPIRAM_RODATA=y
|
||||
CONFIG_SPIRAM_SPEED_80M=y
|
||||
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
|
||||
Reference in New Issue
Block a user