add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1 @@
5fa0f8b1274576d4484e2b8d9358e2a5d09c721511bef0dce6a55b4206b5f0e9

View File

@@ -0,0 +1,26 @@
# ChangeLog
## v1.0.1 - 2025-01-13
### bugfix:
* Fix issues of QSPI interface
## v1.0.0 - 2024-08-12
### Enhancements:
* Component version maintenance, code improvement, and documentation enhancement
## v0.0.1 - 2023-12-01
### Enhancements:
* Implement the driver for the ST77916 LCD controller
* Support SPI and QSPI interface
## v0.0.2 - 2023-12-15
### Enhancements:
* Fix issues of QSPI interface

View File

@@ -0,0 +1 @@
{"version": "1.0", "algorithm": "sha256", "created_at": "2025-05-21T16:22:44.538744+00:00", "files": [{"path": "CMakeLists.txt", "size": 189, "hash": "d9e6afb7ee86418f0e7b00bc2130d0004cb2a19ffb33f33dd73fa2e95c307d25"}, {"path": "CHANGELOG.md", "size": 412, "hash": "3a0ee035cb4e3784eaba660eca2e713deeff7d145531fb0f7ffd8ce6e8938682"}, {"path": "idf_component.yml", "size": 459, "hash": "18cc04f5fc379b6279678983b0ea054e335f1636292ff856c9aa896b4b4037e0"}, {"path": "README.md", "size": 6085, "hash": "ff1ea508952e6d3ce099dad268a15d6c6ad25cc62de6d9e1776551b22d59b07a"}, {"path": "esp_lcd_st77916.c", "size": 21442, "hash": "a9124ac8a582d32fee40f60e6e5be747253ace5bc458d0e21972a84a416570ff"}, {"path": "license.txt", "size": 11358, "hash": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"}, {"path": "include/esp_lcd_st77916.h", "size": 4954, "hash": "21f444cdc25ed1ceec379fe91fb5fd09d31ef179a946c9a7bd6f67d2e3599bfa"}, {"path": "test_apps/CMakeLists.txt", "size": 317, "hash": "cae0178540c6a4a24b56f590eb1f6bf4a85707bd521d9908b3abfc4aed8364b0"}, {"path": "test_apps/pytest_esp_lcd_st77916.py", "size": 300, "hash": "6513b1e4ab20df1aca721edef3485c23da4c0bc34920537ede6c1203ddd4f16a"}, {"path": "test_apps/sdkconfig.defaults", "size": 257, "hash": "b3f9660085595b907f7411e205468220c2dfb867de4de5d7fb3cbb406651dcab"}, {"path": "test_apps/main/CMakeLists.txt", "size": 54, "hash": "263db0b3aae2eae64e526904e06d12a8a5afc3ffe424bcb5992ac015c523c2b2"}, {"path": "test_apps/main/idf_component.yml", "size": 159, "hash": "fb0f2c2300bb6f5f80412b27393d83281fc13ed1a6fa8577e6b9f0f8af0d39f7"}, {"path": "test_apps/main/test_esp_lcd_st77916.c", "size": 7408, "hash": "220671da6d27e35fdf2e864ce0d26648e7974b32cff9afdd8f4c6715d24f9086"}]}

View File

@@ -0,0 +1,4 @@
idf_component_register(SRCS "esp_lcd_st77916.c" INCLUDE_DIRS "include" PRIV_REQUIRES "driver" REQUIRES "esp_lcd")
include(package_manager)
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})

View File

@@ -0,0 +1,122 @@
# ESP LCD ST77916
[![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_st77916/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_st77916)
Implementation of the ST77916 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 |
| :------------: | :---------------------: | :------------: | :---------------------------------------------------------------------------: |
| ST77916 | SPI/QSPI | esp_lcd_st77916 | [PDF](https://dl.espressif.com/AE/esp-iot-solution/ST77916_SPEC_V1.0.pdf) |
For more information on LCD, please refer to the [LCD documentation](https://docs.espressif.com/projects/esp-iot-solution/en/latest/display/lcd/index.html).
## 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_st77916"
```
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 spi_bus_config_t buscfg = ST77916_PANEL_BUS_SPI_CONFIG(EXAMPLE_PIN_NUM_LCD_PCLK, EXAMPLE_PIN_NUM_LCD_DATA0, 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 = ST77916_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 st77916_lcd_init_cmd_t lcd_init_cmds[] = {
// // {cmd, { data }, data_size, delay_ms}
// {0xF0, (uint8_t []){0x08}, 1, 0},
// {0xF2, (uint8_t []){0x08}, 1, 0},
// {0x9B, (uint8_t []){0x51}, 1, 0},
// {0x86, (uint8_t []){0x53}, 1, 0},
// ...
// };
ESP_LOGI(TAG, "Install ST77916 panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
const st77916_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(st77916_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 = EXAMPLE_LCD_BIT_PER_PIXEL, // Implemented by LCD command `3Ah` (16/18)
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_st77916(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 spi_bus_config_t buscfg = ST77916_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 = ST77916_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 st77916_lcd_init_cmd_t lcd_init_cmds[] = {
// // {cmd, { data }, data_size, delay_ms}
// {0xF0, (uint8_t []){0x08}, 1, 0},
// {0xF2, (uint8_t []){0x08}, 1, 0},
// {0x9B, (uint8_t []){0x51}, 1, 0},
// {0x86, (uint8_t []){0x53}, 1, 0},
// ...
// };
ESP_LOGI(TAG, "Install ST77916 panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
const st77916_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(st77916_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 = EXAMPLE_LCD_BIT_PER_PIXEL, // Implemented by LCD command `3Ah` (16/18)
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_st77916(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);
```

View File

@@ -0,0 +1,575 @@
/*
* 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_st77916.h"
#define LCD_OPCODE_WRITE_CMD (0x02ULL)
#define LCD_OPCODE_READ_CMD (0x0BULL)
#define LCD_OPCODE_WRITE_COLOR (0x32ULL)
#define ST77916_CMD_SET (0xF0)
#define ST77916_PARAM_SET (0x00)
static const char *TAG = "st77916";
static esp_err_t panel_st77916_del(esp_lcd_panel_t *panel);
static esp_err_t panel_st77916_reset(esp_lcd_panel_t *panel);
static esp_err_t panel_st77916_init(esp_lcd_panel_t *panel);
static esp_err_t panel_st77916_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_st77916_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
static esp_err_t panel_st77916_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_st77916_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_st77916_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_st77916_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 st77916_lcd_init_cmd_t *init_cmds;
uint16_t init_cmds_size;
struct {
unsigned int use_qspi_interface: 1;
unsigned int reset_level: 1;
} flags;
} st77916_panel_t;
esp_err_t esp_lcd_new_panel_st77916(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;
st77916_panel_t *st77916 = NULL;
st77916 = calloc(1, sizeof(st77916_panel_t));
ESP_GOTO_ON_FALSE(st77916, ESP_ERR_NO_MEM, err, TAG, "no mem for st77916 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:
st77916->madctl_val = 0;
break;
case LCD_RGB_ELEMENT_ORDER_BGR:
st77916->madctl_val |= LCD_CMD_BGR_BIT;
break;
default:
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color element order");
break;
}
switch (panel_dev_config->bits_per_pixel) {
case 16: // RGB565
st77916->colmod_val = 0x55;
st77916->fb_bits_per_pixel = 16;
break;
case 18: // RGB666
st77916->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
st77916->fb_bits_per_pixel = 24;
break;
default:
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
break;
}
st77916->io = io;
st77916->reset_gpio_num = panel_dev_config->reset_gpio_num;
st77916->flags.reset_level = panel_dev_config->flags.reset_active_high;
st77916_vendor_config_t *vendor_config = (st77916_vendor_config_t *)panel_dev_config->vendor_config;
if (vendor_config) {
st77916->init_cmds = vendor_config->init_cmds;
st77916->init_cmds_size = vendor_config->init_cmds_size;
st77916->flags.use_qspi_interface = vendor_config->flags.use_qspi_interface;
}
st77916->base.del = panel_st77916_del;
st77916->base.reset = panel_st77916_reset;
st77916->base.init = panel_st77916_init;
st77916->base.draw_bitmap = panel_st77916_draw_bitmap;
st77916->base.invert_color = panel_st77916_invert_color;
st77916->base.set_gap = panel_st77916_set_gap;
st77916->base.mirror = panel_st77916_mirror;
st77916->base.swap_xy = panel_st77916_swap_xy;
st77916->base.disp_on_off = panel_st77916_disp_on_off;
*ret_panel = &(st77916->base);
ESP_LOGD(TAG, "new st77916 panel @%p", st77916);
ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_ST77916_VER_MAJOR, ESP_LCD_ST77916_VER_MINOR,
ESP_LCD_ST77916_VER_PATCH);
return ESP_OK;
err:
if (st77916) {
if (panel_dev_config->reset_gpio_num >= 0) {
gpio_reset_pin(panel_dev_config->reset_gpio_num);
}
free(st77916);
}
return ret;
}
static esp_err_t tx_param(st77916_panel_t *st77916, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
{
if (st77916->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(st77916_panel_t *st77916, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
{
if (st77916->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_st77916_del(esp_lcd_panel_t *panel)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
if (st77916->reset_gpio_num >= 0) {
gpio_reset_pin(st77916->reset_gpio_num);
}
ESP_LOGD(TAG, "del st77916 panel @%p", st77916);
free(st77916);
return ESP_OK;
}
static esp_err_t panel_st77916_reset(esp_lcd_panel_t *panel)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
esp_lcd_panel_io_handle_t io = st77916->io;
// Perform hardware reset
if (st77916->reset_gpio_num >= 0) {
gpio_set_level(st77916->reset_gpio_num, st77916->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(10));
gpio_set_level(st77916->reset_gpio_num, !st77916->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(120));
} else { // Perform software reset
ESP_RETURN_ON_ERROR(tx_param(st77916, io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed");
vTaskDelay(pdMS_TO_TICKS(120));
}
return ESP_OK;
}
static const st77916_lcd_init_cmd_t vendor_specific_init_default[] = {
{0xF0, (uint8_t []){0x08}, 1, 0},
{0xF2, (uint8_t []){0x08}, 1, 0},
{0x9B, (uint8_t []){0x51}, 1, 0},
{0x86, (uint8_t []){0x53}, 1, 0},
{0xF2, (uint8_t []){0x80}, 1, 0},
{0xF0, (uint8_t []){0x00}, 1, 0},
{0xF0, (uint8_t []){0x01}, 1, 0},
{0xF1, (uint8_t []){0x01}, 1, 0},
{0xB0, (uint8_t []){0x54}, 1, 0},
{0xB1, (uint8_t []){0x3F}, 1, 0},
{0xB2, (uint8_t []){0x2A}, 1, 0},
{0xB4, (uint8_t []){0x46}, 1, 0},
{0xB5, (uint8_t []){0x34}, 1, 0},
{0xB6, (uint8_t []){0xD5}, 1, 0},
{0xB7, (uint8_t []){0x30}, 1, 0},
{0xB8, (uint8_t []){0x04}, 1, 0},
{0xBA, (uint8_t []){0x00}, 1, 0},
{0xBB, (uint8_t []){0x08}, 1, 0},
{0xBC, (uint8_t []){0x08}, 1, 0},
{0xBD, (uint8_t []){0x00}, 1, 0},
{0xC0, (uint8_t []){0x80}, 1, 0},
{0xC1, (uint8_t []){0x10}, 1, 0},
{0xC2, (uint8_t []){0x37}, 1, 0},
{0xC3, (uint8_t []){0x80}, 1, 0},
{0xC4, (uint8_t []){0x10}, 1, 0},
{0xC5, (uint8_t []){0x37}, 1, 0},
{0xC6, (uint8_t []){0xA9}, 1, 0},
{0xC7, (uint8_t []){0x41}, 1, 0},
{0xC8, (uint8_t []){0x51}, 1, 0},
{0xC9, (uint8_t []){0xA9}, 1, 0},
{0xCA, (uint8_t []){0x41}, 1, 0},
{0xCB, (uint8_t []){0x51}, 1, 0},
{0xD0, (uint8_t []){0x91}, 1, 0},
{0xD1, (uint8_t []){0x68}, 1, 0},
{0xD2, (uint8_t []){0x69}, 1, 0},
{0xF5, (uint8_t []){0x00, 0xA5}, 2, 0},
{0xDD, (uint8_t []){0x35}, 1, 0},
{0xDE, (uint8_t []){0x35}, 1, 0},
{0xF1, (uint8_t []){0x10}, 1, 0},
{0xF0, (uint8_t []){0x00}, 1, 0},
{0xF0, (uint8_t []){0x02}, 1, 0},
{0xE0, (uint8_t []){0x70, 0x09, 0x12, 0x0C, 0x0B, 0x27, 0x38, 0x54, 0x4E, 0x19, 0x15, 0x15, 0x2C, 0x2F}, 14, 0},
{0xE1, (uint8_t []){0x70, 0x08, 0x11, 0x0C, 0x0B, 0x27, 0x38, 0x43, 0x4C, 0x18, 0x14, 0x14, 0x2B, 0x2D}, 14, 0},
{0xF0, (uint8_t []){0x10}, 1, 0},
{0xF3, (uint8_t []){0x10}, 1, 0},
{0xE0, (uint8_t []){0x0A}, 1, 0},
{0xE1, (uint8_t []){0x00}, 1, 0},
{0xE2, (uint8_t []){0x0B}, 1, 0},
{0xE3, (uint8_t []){0x00}, 1, 0},
{0xE4, (uint8_t []){0xE0}, 1, 0},
{0xE5, (uint8_t []){0x06}, 1, 0},
{0xE6, (uint8_t []){0x21}, 1, 0},
{0xE7, (uint8_t []){0x00}, 1, 0},
{0xE8, (uint8_t []){0x05}, 1, 0},
{0xE9, (uint8_t []){0x82}, 1, 0},
{0xEA, (uint8_t []){0xDF}, 1, 0},
{0xEB, (uint8_t []){0x89}, 1, 0},
{0xEC, (uint8_t []){0x20}, 1, 0},
{0xED, (uint8_t []){0x14}, 1, 0},
{0xEE, (uint8_t []){0xFF}, 1, 0},
{0xEF, (uint8_t []){0x00}, 1, 0},
{0xF8, (uint8_t []){0xFF}, 1, 0},
{0xF9, (uint8_t []){0x00}, 1, 0},
{0xFA, (uint8_t []){0x00}, 1, 0},
{0xFB, (uint8_t []){0x30}, 1, 0},
{0xFC, (uint8_t []){0x00}, 1, 0},
{0xFD, (uint8_t []){0x00}, 1, 0},
{0xFE, (uint8_t []){0x00}, 1, 0},
{0xFF, (uint8_t []){0x00}, 1, 0},
{0x60, (uint8_t []){0x42}, 1, 0},
{0x61, (uint8_t []){0xE0}, 1, 0},
{0x62, (uint8_t []){0x40}, 1, 0},
{0x63, (uint8_t []){0x40}, 1, 0},
{0x64, (uint8_t []){0x02}, 1, 0},
{0x65, (uint8_t []){0x00}, 1, 0},
{0x66, (uint8_t []){0x40}, 1, 0},
{0x67, (uint8_t []){0x03}, 1, 0},
{0x68, (uint8_t []){0x00}, 1, 0},
{0x69, (uint8_t []){0x00}, 1, 0},
{0x6A, (uint8_t []){0x00}, 1, 0},
{0x6B, (uint8_t []){0x00}, 1, 0},
{0x70, (uint8_t []){0x42}, 1, 0},
{0x71, (uint8_t []){0xE0}, 1, 0},
{0x72, (uint8_t []){0x40}, 1, 0},
{0x73, (uint8_t []){0x40}, 1, 0},
{0x74, (uint8_t []){0x02}, 1, 0},
{0x75, (uint8_t []){0x00}, 1, 0},
{0x76, (uint8_t []){0x40}, 1, 0},
{0x77, (uint8_t []){0x03}, 1, 0},
{0x78, (uint8_t []){0x00}, 1, 0},
{0x79, (uint8_t []){0x00}, 1, 0},
{0x7A, (uint8_t []){0x00}, 1, 0},
{0x7B, (uint8_t []){0x00}, 1, 0},
{0x80, (uint8_t []){0x38}, 1, 0},
{0x81, (uint8_t []){0x00}, 1, 0},
{0x82, (uint8_t []){0x04}, 1, 0},
{0x83, (uint8_t []){0x02}, 1, 0},
{0x84, (uint8_t []){0xDC}, 1, 0},
{0x85, (uint8_t []){0x00}, 1, 0},
{0x86, (uint8_t []){0x00}, 1, 0},
{0x87, (uint8_t []){0x00}, 1, 0},
{0x88, (uint8_t []){0x38}, 1, 0},
{0x89, (uint8_t []){0x00}, 1, 0},
{0x8A, (uint8_t []){0x06}, 1, 0},
{0x8B, (uint8_t []){0x02}, 1, 0},
{0x8C, (uint8_t []){0xDE}, 1, 0},
{0x8D, (uint8_t []){0x00}, 1, 0},
{0x8E, (uint8_t []){0x00}, 1, 0},
{0x8F, (uint8_t []){0x00}, 1, 0},
{0x90, (uint8_t []){0x38}, 1, 0},
{0x91, (uint8_t []){0x00}, 1, 0},
{0x92, (uint8_t []){0x08}, 1, 0},
{0x93, (uint8_t []){0x02}, 1, 0},
{0x94, (uint8_t []){0xE0}, 1, 0},
{0x95, (uint8_t []){0x00}, 1, 0},
{0x96, (uint8_t []){0x00}, 1, 0},
{0x97, (uint8_t []){0x00}, 1, 0},
{0x98, (uint8_t []){0x38}, 1, 0},
{0x99, (uint8_t []){0x00}, 1, 0},
{0x9A, (uint8_t []){0x0A}, 1, 0},
{0x9B, (uint8_t []){0x02}, 1, 0},
{0x9C, (uint8_t []){0xE2}, 1, 0},
{0x9D, (uint8_t []){0x00}, 1, 0},
{0x9E, (uint8_t []){0x00}, 1, 0},
{0x9F, (uint8_t []){0x00}, 1, 0},
{0xA0, (uint8_t []){0x38}, 1, 0},
{0xA1, (uint8_t []){0x00}, 1, 0},
{0xA2, (uint8_t []){0x03}, 1, 0},
{0xA3, (uint8_t []){0x02}, 1, 0},
{0xA4, (uint8_t []){0xDB}, 1, 0},
{0xA5, (uint8_t []){0x00}, 1, 0},
{0xA6, (uint8_t []){0x00}, 1, 0},
{0xA7, (uint8_t []){0x00}, 1, 0},
{0xA8, (uint8_t []){0x38}, 1, 0},
{0xA9, (uint8_t []){0x00}, 1, 0},
{0xAA, (uint8_t []){0x05}, 1, 0},
{0xAB, (uint8_t []){0x02}, 1, 0},
{0xAC, (uint8_t []){0xDD}, 1, 0},
{0xAD, (uint8_t []){0x00}, 1, 0},
{0xAE, (uint8_t []){0x00}, 1, 0},
{0xAF, (uint8_t []){0x00}, 1, 0},
{0xB0, (uint8_t []){0x38}, 1, 0},
{0xB1, (uint8_t []){0x00}, 1, 0},
{0xB2, (uint8_t []){0x07}, 1, 0},
{0xB3, (uint8_t []){0x02}, 1, 0},
{0xB4, (uint8_t []){0xDF}, 1, 0},
{0xB5, (uint8_t []){0x00}, 1, 0},
{0xB6, (uint8_t []){0x00}, 1, 0},
{0xB7, (uint8_t []){0x00}, 1, 0},
{0xB8, (uint8_t []){0x38}, 1, 0},
{0xB9, (uint8_t []){0x00}, 1, 0},
{0xBA, (uint8_t []){0x09}, 1, 0},
{0xBB, (uint8_t []){0x02}, 1, 0},
{0xBC, (uint8_t []){0xE1}, 1, 0},
{0xBD, (uint8_t []){0x00}, 1, 0},
{0xBE, (uint8_t []){0x00}, 1, 0},
{0xBF, (uint8_t []){0x00}, 1, 0},
{0xC0, (uint8_t []){0x22}, 1, 0},
{0xC1, (uint8_t []){0xAA}, 1, 0},
{0xC2, (uint8_t []){0x65}, 1, 0},
{0xC3, (uint8_t []){0x74}, 1, 0},
{0xC4, (uint8_t []){0x47}, 1, 0},
{0xC5, (uint8_t []){0x56}, 1, 0},
{0xC6, (uint8_t []){0x00}, 1, 0},
{0xC7, (uint8_t []){0x88}, 1, 0},
{0xC8, (uint8_t []){0x99}, 1, 0},
{0xC9, (uint8_t []){0x33}, 1, 0},
{0xD0, (uint8_t []){0x11}, 1, 0},
{0xD1, (uint8_t []){0xAA}, 1, 0},
{0xD2, (uint8_t []){0x65}, 1, 0},
{0xD3, (uint8_t []){0x74}, 1, 0},
{0xD4, (uint8_t []){0x47}, 1, 0},
{0xD5, (uint8_t []){0x56}, 1, 0},
{0xD6, (uint8_t []){0x00}, 1, 0},
{0xD7, (uint8_t []){0x88}, 1, 0},
{0xD8, (uint8_t []){0x99}, 1, 0},
{0xD9, (uint8_t []){0x33}, 1, 0},
{0xF3, (uint8_t []){0x01}, 1, 0},
{0xF0, (uint8_t []){0x00}, 1, 0},
{0xF0, (uint8_t []){0x01}, 1, 0},
{0xF1, (uint8_t []){0x01}, 1, 0},
{0xA0, (uint8_t []){0x0B}, 1, 0},
{0xA3, (uint8_t []){0x2A}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x2B}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x2C}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x2D}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x2E}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x2F}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x30}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x31}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x32}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA3, (uint8_t []){0x33}, 1, 0},
{0xA5, (uint8_t []){0xC3}, 1, 1},
{0xA0, (uint8_t []){0x09}, 1, 0},
{0xF1, (uint8_t []){0x10}, 1, 0},
{0xF0, (uint8_t []){0x00}, 1, 0},
{0x2A, (uint8_t []){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x2B, (uint8_t []){0x01, 0x68, 0x01, 0x68}, 4, 0},
{0x4D, (uint8_t []){0x00}, 1, 0},
{0x4E, (uint8_t []){0x00}, 1, 0},
{0x4F, (uint8_t []){0x00}, 1, 0},
{0x4C, (uint8_t []){0x01}, 1, 10},
{0x4C, (uint8_t []){0x00}, 1, 0},
{0x2A, (uint8_t []){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x2B, (uint8_t []){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x21, (uint8_t []){0x00}, 1, 0},
{0x11, (uint8_t []){0x00}, 1, 120},
};
static esp_err_t panel_st77916_init(esp_lcd_panel_t *panel)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
esp_lcd_panel_io_handle_t io = st77916->io;
const st77916_lcd_init_cmd_t *init_cmds = NULL;
uint16_t init_cmds_size = 0;
bool is_user_set = true;
bool is_cmd_overwritten = false;
ESP_RETURN_ON_ERROR(tx_param(st77916, io, LCD_CMD_MADCTL, (uint8_t[]) {
st77916->madctl_val,
}, 1), TAG, "send command failed");
ESP_RETURN_ON_ERROR(tx_param(st77916, io, LCD_CMD_COLMOD, (uint8_t[]) {
st77916->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 (st77916->init_cmds) {
init_cmds = st77916->init_cmds;
init_cmds_size = st77916->init_cmds_size;
} else {
init_cmds = vendor_specific_init_default;
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(st77916_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
if (is_user_set && (init_cmds[i].data_bytes > 0)) {
switch (init_cmds[i].cmd) {
case LCD_CMD_MADCTL:
is_cmd_overwritten = true;
st77916->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
break;
case LCD_CMD_COLMOD:
is_cmd_overwritten = true;
st77916->colmod_val = ((uint8_t *)init_cmds[i].data)[0];
break;
default:
is_cmd_overwritten = false;
break;
}
if (is_cmd_overwritten) {
is_cmd_overwritten = false;
ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence", init_cmds[i].cmd);
}
}
// Send command
ESP_RETURN_ON_ERROR(tx_param(st77916, 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));
// Check if the current cmd is the "command set" cmd
if ((init_cmds[i].cmd == ST77916_CMD_SET)) {
is_user_set = ((uint8_t *)init_cmds[i].data)[0] == ST77916_PARAM_SET ? true : false;
}
}
ESP_LOGD(TAG, "send init commands success");
return ESP_OK;
}
static esp_err_t panel_st77916_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_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 = st77916->io;
x_start += st77916->x_gap;
x_end += st77916->x_gap;
y_start += st77916->y_gap;
y_end += st77916->y_gap;
// define an area of frame memory where MCU can access
ESP_RETURN_ON_ERROR(tx_param(st77916, 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(st77916, 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) * st77916->fb_bits_per_pixel / 8;
tx_color(st77916, io, LCD_CMD_RAMWR, color_data, len);
return ESP_OK;
}
static esp_err_t panel_st77916_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
esp_lcd_panel_io_handle_t io = st77916->io;
int command = 0;
if (invert_color_data) {
command = LCD_CMD_INVON;
} else {
command = LCD_CMD_INVOFF;
}
ESP_RETURN_ON_ERROR(tx_param(st77916, io, command, NULL, 0), TAG, "send command failed");
return ESP_OK;
}
static esp_err_t panel_st77916_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
esp_lcd_panel_io_handle_t io = st77916->io;
esp_err_t ret = ESP_OK;
if (mirror_x) {
st77916->madctl_val |= BIT(6);
} else {
st77916->madctl_val &= ~BIT(6);
}
if (mirror_y) {
st77916->madctl_val |= BIT(7);
} else {
st77916->madctl_val &= ~BIT(7);
}
ESP_RETURN_ON_ERROR(tx_param(st77916, io, LCD_CMD_MADCTL, (uint8_t[]) {
st77916->madctl_val
}, 1), TAG, "send command failed");
return ret;
}
static esp_err_t panel_st77916_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
esp_lcd_panel_io_handle_t io = st77916->io;
if (swap_axes) {
st77916->madctl_val |= LCD_CMD_MV_BIT;
} else {
st77916->madctl_val &= ~LCD_CMD_MV_BIT;
}
ESP_RETURN_ON_ERROR(tx_param(st77916, io, LCD_CMD_MADCTL, (uint8_t[]) {
st77916->madctl_val
}, 1), TAG, "send command failed");
return ESP_OK;
}
static esp_err_t panel_st77916_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
st77916->x_gap = x_gap;
st77916->y_gap = y_gap;
return ESP_OK;
}
static esp_err_t panel_st77916_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
st77916_panel_t *st77916 = __containerof(panel, st77916_panel_t, base);
esp_lcd_panel_io_handle_t io = st77916->io;
int command = 0;
if (on_off) {
command = LCD_CMD_DISPON;
} else {
command = LCD_CMD_DISPOFF;
}
ESP_RETURN_ON_ERROR(tx_param(st77916, io, command, NULL, 0), TAG, "send command failed");
return ESP_OK;
}

View File

@@ -0,0 +1,11 @@
dependencies:
cmake_utilities: 0.*
idf: '>5.0.4,!=5.1.1'
description: ESP LCD ST77916(SPI & QSPI)
issues: https://github.com/espressif/esp-iot-solution/issues
repository: git://github.com/espressif/esp-iot-solution.git
repository_info:
commit_sha: 6a112f4ddfeaf30ec360567ea9260a39e195c385
path: components/display/lcd/esp_lcd_st77916
url: https://github.com/espressif/esp-iot-solution/tree/master/components/display/lcd/esp_lcd_st77916
version: 1.0.1

View File

@@ -0,0 +1,114 @@
/*
* 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 */
} st77916_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 st77916_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;
} st77916_vendor_config_t;
/**
* @brief Create LCD panel for model ST77916
*
* @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_st77916(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 ST77916_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 ST77916_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 ST77916_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 ST77916_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

View 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.

View File

@@ -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_st77916)

View File

@@ -0,0 +1 @@
idf_component_register(SRCS "test_esp_lcd_st77916.c")

View File

@@ -0,0 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">5.0.4,!=5.1.1"
esp_lcd_st77916:
version: "*"
override_path: "../../../esp_lcd_st77916"

View File

@@ -0,0 +1,187 @@
/*
* 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.h"
#include "esp_lcd_panel_ops.h"
#include "unity.h"
#include "unity_test_runner.h"
#include "esp_lcd_st77916.h"
#define TEST_LCD_HOST SPI2_HOST
#define TEST_LCD_H_RES (360)
#define TEST_LCD_V_RES (360)
#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_17)
#define TEST_PIN_NUM_LCD_DC (GPIO_NUM_8)
#define TEST_DELAY_TIME_MS (3000)
static char *TAG = "st77916_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) << 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 st77916 to draw color bar with SPI interface", "[st77916][spi]")
{
ESP_LOGI(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = ST77916_PANEL_BUS_SPI_CONFIG(TEST_PIN_NUM_LCD_PCLK, TEST_PIN_NUM_LCD_DATA0, TEST_LCD_H_RES * 80 * 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 = ST77916_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 st77916");
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_st77916(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 st77916 to draw color bar with QSPI interface", "[st77916][qspi]")
{
ESP_LOGI(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = ST77916_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 * 80 * 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 = ST77916_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 st77916");
esp_lcd_panel_handle_t panel_handle = NULL;
const st77916_vendor_config_t vendor_config = {
.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_st77916(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;
static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}
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);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
}
void app_main(void)
{
/**
* __ _____ _____ _____ ___ _ __
* / _\/__ \___ |___ / _ \/ |/ /_
* \ \ / /\/ / / / / (_) | | '_ \
* _\ \ / / / / / / \__, | | (_) |
* \__/ \/ /_/ /_/ /_/|_|\___/
*/
printf(" __ _____ _____ _____ ___ _ __\r\n");
printf(" / _\\/__ \\___ |___ / _ \\/ |/ /\r\n");
printf(" \\ \\ / /\\/ / / / / (_) | | '_ \r\n");
printf(" _\\ \\ / / / / / / \\__, | | (_) |\r\n");
printf(" \\__/ \\/ /_/ /_/ /_/|_|\\___/\r\n");
unity_run_menu();
}

View File

@@ -0,0 +1,9 @@
# 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()

View File

@@ -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