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

View File

@@ -0,0 +1,13 @@
# ChangeLog
## v1.0.1 - 2025-03-09
### bugfix:
- Fixed an issue where using i2c_master could not set scl_speed_hz resulting in an invalid scl frequency error
## v1.0.0 - 2024-02-29
### Enhancements:
- Implement the driver for the AXS15231B LCD controller

View File

@@ -0,0 +1 @@
{"version": "1.0", "algorithm": "sha256", "created_at": "2025-05-21T17:09:11.422210+00:00", "files": [{"path": "CMakeLists.txt", "size": 223, "hash": "bbb95b7a7f8929bbdd342ed124c8abb72f0a38432384f26207c9b5b182e43c33"}, {"path": "CHANGELOG.md", "size": 261, "hash": "d339d153df3b46a0a55cc088dc85556feba6ed1aa22cf44fb59136272098781f"}, {"path": "idf_component.yml", "size": 494, "hash": "cebb659fecc3bd4b64d4f6577572284abbccd9d7689762c5f48999c90a97f360"}, {"path": "README.md", "size": 9132, "hash": "469dea455a0353162e419867fdc23768400cbc6bd63cc6a70bcd7d27f9fc89b9"}, {"path": "esp_lcd_axs15231b.c", "size": 23671, "hash": "51dd1dd9239b95852874f681ed1c7932baa545e2e7d93855e2fcfecf07d4be14"}, {"path": "license.txt", "size": 11358, "hash": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"}, {"path": "include/esp_lcd_axs15231b.h", "size": 9347, "hash": "fcc25efb76ef503f5de2ea992a2bb98eb71257bc086be01f7f4251eef4237551"}, {"path": "test_apps/pytest_esp_lcd_axs15231b.py", "size": 929, "hash": "b37415283fe0d501b2dd653fb54a1719dab03d1cfba4c4b7a91e3f5549232a97"}, {"path": "test_apps/CMakeLists.txt", "size": 319, "hash": "71666416231801c348bb71ab2e79548b8dbe62fec0f5eb8dd32efa4984cb858e"}, {"path": "test_apps/sdkconfig.defaults", "size": 313, "hash": "9918b62ed2078e0e999d94b5e9c6689bffeca3c23508066f1c9b52c16e429c50"}, {"path": "test_apps/main/test_esp_lcd_axs15231b.c", "size": 21027, "hash": "d3345b0c522659acb35e8c9d190748735481e19132bdae2aef83707330094b75"}, {"path": "test_apps/main/CMakeLists.txt", "size": 56, "hash": "bd598b57eb6b6295291d10c75e44d904efcfe13a6df3f9508c39aaf9f0c23921"}, {"path": "test_apps/main/idf_component.yml", "size": 139, "hash": "1797262d57a62083ccef547be3e1244572677153f9fd6c5ae4b6f6dcc39e3db9"}]}

View File

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

View File

@@ -0,0 +1,206 @@
# ESP LCD & Touch AXS15231B
[![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_axs15231b/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_axs15231b)
Implementation of the AXS15231B LCD & Touch controller with esp_lcd component.
| LCD controller | Communication interface | Component name | Link to datasheet |
| :------------: | :---------------------: | :------------: | :---------------: |
| AXS15231B | I80/SPI/QSPI | esp_lcd_axs15231b | [Specification](https://dl.espressif.com/AE/esp_iot_solution/AXS15231B_Datasheet_V0.5_20230306.pdf) |
## Add to project
Packages from this repository are uploaded to [Espressif's component service](https://components.espressif.com/).
You can add them to your project via `idf.py add-dependancy`, e.g.
```
idf.py add-dependency esp_lcd_axs15231b==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 of the LCD component.
### SPI Interface
```c
ESP_LOGI(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = AXS15231B_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 = AXS15231B_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 axs15231b_lcd_init_cmd_t lcd_init_cmds[] = {
// // {cmd, { data }, data_size, delay_ms}
// {0xFF, (uint8_t []){0x20, 0x10, 0x10}, 3, 0},
// {0x0C, (uint8_t []){0x11}, 1, 0},
// {0x10, (uint8_t []){0x02}, 1, 0},
// {0x11, (uint8_t []){0x11}, 1, 0},
// ...
// };
ESP_LOGI(TAG, "Install AXS15231B panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
const axs15231b_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(axs15231b_lcd_init_cmd_t),
.flags = {
.use_qspi_interface = 0,
},
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h`
.bits_per_pixel = 16, // Implemented by LCD command `3Ah` (16/18)
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_axs15231b(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 = AXS15231B_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 = AXS15231B_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 axs15231b_lcd_init_cmd_t lcd_init_cmds[] = {
// // {cmd, { data }, data_size, delay_ms}
// {0xFF, (uint8_t []){0x20, 0x10, 0x10}, 3, 0},
// {0x0C, (uint8_t []){0x11}, 1, 0},
// {0x10, (uint8_t []){0x02}, 1, 0},
// {0x11, (uint8_t []){0x11}, 1, 0},
// ...
// };
ESP_LOGI(TAG, "Install AXS15231B panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
const axs15231b_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(axs15231b_lcd_init_cmd_t),
.flags = {
.use_qspi_interface = 1,
},
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h`
.bits_per_pixel = 16, // Implemented by LCD command `3Ah` (16/18)
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_axs15231b(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);
```
### I80 Interface
```c
ESP_LOGI(TAG, "Initialize Intel 8080 bus");
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;
const esp_lcd_panel_io_spi_config_t io_config = ILI9341_PANEL_IO_SPI_CONFIG(EXAMPLE_PIN_NUM_LCD_CS, EXAMPLE_PIN_NUM_LCD_DC,
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 axs15231b_lcd_init_cmd_t lcd_init_cmds[] = {
// // {cmd, { data }, data_size, delay_ms}
// {0xCF, (uint8_t []){0x00, 0xAA, 0XE0}, 3, 0},
// {0xED, (uint8_t []){0x67, 0x03, 0X12, 0X81}, 4, 0},
// {0xE8, (uint8_t []){0x8A, 0x01, 0x78}, 3, 0},
// ...
// };
ESP_LOGI(TAG, "Install AXS15231B panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
// const axs15231b_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(axs15231b_lcd_init_cmd_t),
// };
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h`
.bits_per_pixel = 16, // Implemented by LCD command `3Ah` (16/18)
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_axs15231b(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);
```
## Initialization of the touch component.
```
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG();
esp_lcd_touch_config_t tp_cfg = {
.x_max = CONFIG_LCD_HRES,
.y_max = CONFIG_LCD_VRES,
.rst_gpio_num = -1,
.int_gpio_num = -1,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
esp_lcd_touch_handle_t tp;
esp_lcd_touch_new_i2c_axs15231b(io_config, &tp_cfg, &tp);
```
Read data from the touch controller and store it in RAM memory. It should be called regularly in poll.
```
esp_lcd_touch_read_data(tp);
```
Get one X and Y coordinates with strength of touch.
```
uint16_t touch_x[1];
uint16_t touch_y[1];
uint16_t touch_strength[1];
uint8_t touch_cnt = 0;
bool touchpad_pressed = esp_lcd_touch_get_coordinates(tp, touch_x, touch_y, touch_strength, &touch_cnt, 1);
```
There is an example in ESP-IDF with this LCD controller. Please follow this [link](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/lcd/spi_lcd_touch).

View File

@@ -0,0 +1,550 @@
/*
* SPDX-FileCopyrightText: 2021-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_touch.h"
#include "esp_lcd_axs15231b.h"
/*max point num*/
#define AXS_MAX_TOUCH_NUMBER (1)
#define LCD_OPCODE_WRITE_CMD (0x02ULL)
#define LCD_OPCODE_READ_CMD (0x0BULL)
#define LCD_OPCODE_WRITE_COLOR (0x32ULL)
static const char *TAG = "lcd_panel.axs15231b";
static esp_err_t panel_axs15231b_del(esp_lcd_panel_t *panel);
static esp_err_t panel_axs15231b_reset(esp_lcd_panel_t *panel);
static esp_err_t panel_axs15231b_init(esp_lcd_panel_t *panel);
static esp_err_t panel_axs15231b_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_axs15231b_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
static esp_err_t panel_axs15231b_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_axs15231b_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_axs15231b_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_axs15231b_disp_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t touch_axs15231b_read_data(esp_lcd_touch_handle_t tp);
static bool touch_axs15231b_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
static esp_err_t touch_axs15231b_del(esp_lcd_touch_handle_t tp);
static esp_err_t touch_axs15231b_reset(esp_lcd_touch_handle_t tp);
static esp_err_t i2c_read_bytes(esp_lcd_touch_handle_t tp, int reg, uint8_t *data, uint8_t len);
static esp_err_t i2c_write_bytes(esp_lcd_touch_handle_t tp, int reg, const uint8_t *data, uint8_t len);
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 axs15231b_lcd_init_cmd_t *init_cmds;
uint16_t init_cmds_size;
struct {
unsigned int use_qspi_interface: 1;
unsigned int reset_level: 1;
} flags;
} axs15231b_panel_t;
esp_err_t esp_lcd_new_panel_axs15231b(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;
axs15231b_panel_t *axs15231b = NULL;
ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
axs15231b = calloc(1, sizeof(axs15231b_panel_t));
ESP_GOTO_ON_FALSE(axs15231b, ESP_ERR_NO_MEM, err, TAG, "no mem for axs15231b 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:
axs15231b->madctl_val = 0;
break;
case LCD_RGB_ELEMENT_ORDER_BGR:
axs15231b->madctl_val |= LCD_CMD_BGR_BIT;
break;
default:
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported RGB element order");
break;
}
uint8_t fb_bits_per_pixel = 0;
switch (panel_dev_config->bits_per_pixel) {
case 16: // RGB565
axs15231b->colmod_val = 0x55;
fb_bits_per_pixel = 16;
break;
case 18: // RGB666
axs15231b->colmod_val = 0x66;
// each color component (R/G/B) should occupy the 6 high bits of a byte, which means 3 full bytes are required for a pixel
fb_bits_per_pixel = 24;
break;
default:
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
break;
}
axs15231b->io = io;
axs15231b->fb_bits_per_pixel = fb_bits_per_pixel;
axs15231b->reset_gpio_num = panel_dev_config->reset_gpio_num;
axs15231b->flags.reset_level = panel_dev_config->flags.reset_active_high;
if (panel_dev_config->vendor_config) {
axs15231b->init_cmds = ((axs15231b_vendor_config_t *)panel_dev_config->vendor_config)->init_cmds;
axs15231b->init_cmds_size = ((axs15231b_vendor_config_t *)panel_dev_config->vendor_config)->init_cmds_size;
axs15231b->flags.use_qspi_interface = ((axs15231b_vendor_config_t *)panel_dev_config->vendor_config)->flags.use_qspi_interface;
}
axs15231b->base.del = panel_axs15231b_del;
axs15231b->base.reset = panel_axs15231b_reset;
axs15231b->base.init = panel_axs15231b_init;
axs15231b->base.draw_bitmap = panel_axs15231b_draw_bitmap;
axs15231b->base.invert_color = panel_axs15231b_invert_color;
axs15231b->base.set_gap = panel_axs15231b_set_gap;
axs15231b->base.mirror = panel_axs15231b_mirror;
axs15231b->base.swap_xy = panel_axs15231b_swap_xy;
axs15231b->base.disp_on_off = panel_axs15231b_disp_off;
*ret_panel = &(axs15231b->base);
ESP_LOGD(TAG, "new axs15231b panel @%p", axs15231b);
ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_AXS15231B_VER_MAJOR, ESP_LCD_AXS15231B_VER_MINOR,
ESP_LCD_AXS15231B_VER_PATCH);
return ESP_OK;
err:
if (axs15231b) {
if (panel_dev_config->reset_gpio_num >= 0) {
gpio_reset_pin(panel_dev_config->reset_gpio_num);
}
free(axs15231b);
}
return ret;
}
static esp_err_t tx_param(axs15231b_panel_t *axs15231b, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
{
if (axs15231b->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(axs15231b_panel_t *axs15231b, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
{
if (axs15231b->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_axs15231b_del(esp_lcd_panel_t *panel)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
if (axs15231b->reset_gpio_num >= 0) {
gpio_reset_pin(axs15231b->reset_gpio_num);
}
ESP_LOGD(TAG, "del axs15231b panel @%p", axs15231b);
free(axs15231b);
return ESP_OK;
}
static esp_err_t panel_axs15231b_reset(esp_lcd_panel_t *panel)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
esp_lcd_panel_io_handle_t io = axs15231b->io;
// perform hardware reset
if (axs15231b->reset_gpio_num >= 0) {
gpio_set_level(axs15231b->reset_gpio_num, !axs15231b->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(10));
gpio_set_level(axs15231b->reset_gpio_num, axs15231b->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(10));
gpio_set_level(axs15231b->reset_gpio_num, !axs15231b->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(120));
} else { // perform software reset
tx_param(axs15231b, io, LCD_CMD_SWRESET, NULL, 0);
vTaskDelay(pdMS_TO_TICKS(120)); // spec, wait at least 5m before sending new command
}
return ESP_OK;
}
static const axs15231b_lcd_init_cmd_t vendor_specific_init_default[] = {
{0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5}, 8, 0},
{0xA0, (uint8_t[]){0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x64, 0x3F, 0x20, 0x05, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00}, 17, 0},
{0xA2, (uint8_t[]){0x30, 0x04, 0x0A, 0x3C, 0xEC, 0x54, 0xC4, 0x30, 0xAC, 0x28, 0x7F, 0x7F, 0x7F, 0x20, 0xF8, 0x10, 0x02, 0xFF, 0xFF, 0xF0, 0x90, 0x01, 0x32, 0xA0, 0x91, 0xC0, 0x20, 0x7F, 0xFF, 0x00, 0x54}, 31, 0},
{0xD0, (uint8_t[]){0x30, 0xAC, 0x21, 0x24, 0x08, 0x09, 0x10, 0x01, 0xAA, 0x14, 0xC2, 0x00, 0x22, 0x22, 0xAA, 0x03, 0x10, 0x12, 0x40, 0x14, 0x1E, 0x51, 0x15, 0x00, 0x40, 0x10, 0x00, 0x03, 0x3D, 0x12}, 30, 0},
{0xA3, (uint8_t[]){0xA0, 0x06, 0xAA, 0x08, 0x08, 0x02, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x55, 0x55}, 22, 0},
{0xC1, (uint8_t[]){0x33, 0x04, 0x02, 0x02, 0x71, 0x05, 0x24, 0x55, 0x02, 0x00, 0x41, 0x00, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0x52, 0x00, 0x4F, 0x52, 0x00, 0x45, 0x3B, 0x0B, 0x02, 0x0D, 0x00, 0xFF, 0x40}, 30, 0},
{0xC3, (uint8_t[]){0x00, 0x00, 0x00, 0x50, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01}, 11, 0},
{0xC4, (uint8_t[]){0x00, 0x24, 0x33, 0x90, 0x50, 0xea, 0x64, 0x32, 0xC8, 0x64, 0xC8, 0x32, 0x90, 0x90, 0x11, 0x06, 0xDC, 0xFA, 0x04, 0x03, 0x80, 0xFE, 0x10, 0x10, 0x00, 0x0A, 0x0A, 0x44, 0x50}, 29, 0},
{0xC5, (uint8_t[]){0x18, 0x00, 0x00, 0x03, 0xFE, 0x78, 0x33, 0x20, 0x30, 0x10, 0x88, 0xDE, 0x0D, 0x08, 0x0F, 0x0F, 0x01, 0x78, 0x33, 0x20, 0x10, 0x10, 0x80}, 23, 0},
{0xC6, (uint8_t[]){0x05, 0x0A, 0x05, 0x0A, 0x00, 0xE0, 0x2E, 0x0B, 0x12, 0x22, 0x12, 0x22, 0x01, 0x00, 0x00, 0x3F, 0x6A, 0x18, 0xC8, 0x22}, 20, 0},
{0xC7, (uint8_t[]){0x50, 0x32, 0x28, 0x00, 0xa2, 0x80, 0x8f, 0x00, 0x80, 0xff, 0x07, 0x11, 0x9F, 0x6f, 0xff, 0x26, 0x0c, 0x0d, 0x0e, 0x0f}, 20, 0},
{0xC9, (uint8_t[]){0x33, 0x44, 0x44, 0x01}, 4, 0},
{0xCF, (uint8_t[]){0x34, 0x1E, 0x88, 0x58, 0x13, 0x18, 0x56, 0x18, 0x1E, 0x68, 0xF7, 0x00, 0x65, 0x0C, 0x22, 0xC4, 0x0C, 0x77, 0x22, 0x44, 0xAA, 0x55, 0x04, 0x04, 0x12, 0xA0, 0x08}, 27, 0},
{0xD5, (uint8_t[]){0x3E, 0x3E, 0x88, 0x00, 0x44, 0x04, 0x78, 0x33, 0x20, 0x78, 0x33, 0x20, 0x04, 0x28, 0xD3, 0x47, 0x03, 0x03, 0x03, 0x03, 0x86, 0x00, 0x00, 0x00, 0x30, 0x52, 0x3f, 0x40, 0x40, 0x96}, 30, 0},
{0xD6, (uint8_t[]){0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x95, 0x00, 0x01, 0x83, 0x75, 0x36, 0x20, 0x75, 0x36, 0x20, 0x3F, 0x03, 0x03, 0x03, 0x10, 0x10, 0x00, 0x04, 0x51, 0x20, 0x01, 0x00}, 30, 0},
{0xD7, (uint8_t[]){0x0a, 0x08, 0x0e, 0x0c, 0x1E, 0x18, 0x19, 0x1F, 0x00, 0x1F, 0x1A, 0x1F, 0x3E, 0x3E, 0x04, 0x00, 0x1F, 0x1F, 0x1F}, 19, 0},
{0xD8, (uint8_t[]){0x0B, 0x09, 0x0F, 0x0D, 0x1E, 0x18, 0x19, 0x1F, 0x01, 0x1F, 0x1A, 0x1F}, 12, 0},
{0xD9, (uint8_t[]){0x00, 0x0D, 0x0F, 0x09, 0x0B, 0x1F, 0x18, 0x19, 0x1F, 0x01, 0x1E, 0x1A, 0x1F}, 13, 0},
{0xDD, (uint8_t[]){0x0C, 0x0E, 0x08, 0x0A, 0x1F, 0x18, 0x19, 0x1F, 0x00, 0x1E, 0x1A, 0x1F}, 12, 0},
{0xDF, (uint8_t[]){0x44, 0x73, 0x4B, 0x69, 0x00, 0x0A, 0x02, 0x90}, 8, 0},
{0xE0, (uint8_t[]){0x19, 0x20, 0x0A, 0x13, 0x0E, 0x09, 0x12, 0x28, 0xD4, 0x24, 0x0C, 0x35, 0x13, 0x31, 0x36, 0x2f, 0x03}, 17, 0},
{0xE1, (uint8_t[]){0x38, 0x20, 0x09, 0x12, 0x0E, 0x08, 0x12, 0x28, 0xC5, 0x24, 0x0C, 0x34, 0x12, 0x31, 0x36, 0x2f, 0x27}, 17, 0},
{0xE2, (uint8_t[]){0x19, 0x20, 0x0A, 0x11, 0x09, 0x06, 0x11, 0x25, 0xD4, 0x22, 0x0B, 0x33, 0x12, 0x2D, 0x32, 0x2f, 0x03}, 17, 0},
{0xE3, (uint8_t[]){0x38, 0x20, 0x0A, 0x11, 0x09, 0x06, 0x11, 0x25, 0xC4, 0x21, 0x0A, 0x32, 0x11, 0x2C, 0x32, 0x2f, 0x27}, 17, 0},
{0xE4, (uint8_t[]){0x19, 0x20, 0x0D, 0x14, 0x0D, 0x08, 0x12, 0x2A, 0xD4, 0x26, 0x0E, 0x35, 0x13, 0x34, 0x39, 0x2f, 0x03}, 17, 0},
{0xE5, (uint8_t[]){0x38, 0x20, 0x0D, 0x13, 0x0D, 0x07, 0x12, 0x29, 0xC4, 0x25, 0x0D, 0x35, 0x12, 0x33, 0x39, 0x2f, 0x27}, 17, 0},
{0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 0},
{0x13, (uint8_t[]){0x00}, 0, 0},
{0x11, (uint8_t[]){0x00}, 0, 200},
{0x29, (uint8_t[]){0x00}, 0, 200},
{0x2C, (uint8_t[]){0x00, 0x00, 0x00, 0x00}, 4, 0},
{0x22, (uint8_t[]){0x00}, 0, 200},//All Pixels off
};
static esp_err_t panel_axs15231b_init(esp_lcd_panel_t *panel)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
esp_lcd_panel_io_handle_t io = axs15231b->io;
// LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, LCD_CMD_SLPOUT, NULL, 0), TAG, "send command failed");
vTaskDelay(pdMS_TO_TICKS(100));
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, LCD_CMD_MADCTL, (uint8_t[]) {
axs15231b->madctl_val,
}, 1), TAG, "send command failed");
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, LCD_CMD_COLMOD, (uint8_t[]) {
axs15231b->colmod_val,
}, 1), TAG, "send command failed");
const axs15231b_lcd_init_cmd_t *init_cmds = NULL;
uint16_t init_cmds_size = 0;
if (axs15231b->init_cmds) {
init_cmds = axs15231b->init_cmds;
init_cmds_size = axs15231b->init_cmds_size;
} else {
init_cmds = vendor_specific_init_default;
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(axs15231b_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;
axs15231b->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
break;
case LCD_CMD_COLMOD:
is_cmd_overwritten = true;
axs15231b->colmod_val = ((uint8_t *)init_cmds[i].data)[0];
break;
default:
is_cmd_overwritten = false;
break;
}
if (is_cmd_overwritten) {
ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence", init_cmds[i].cmd);
}
ESP_RETURN_ON_ERROR(tx_param(axs15231b, 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_LOGI(TAG, "send init commands success");
return ESP_OK;
}
static esp_err_t panel_axs15231b_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_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 = axs15231b->io;
x_start += axs15231b->x_gap;
x_end += axs15231b->x_gap;
y_start += axs15231b->y_gap;
y_end += axs15231b->y_gap;
// define an area of frame memory where MCU can access
tx_param(axs15231b, io, LCD_CMD_CASET, (uint8_t[]) {
(x_start >> 8) & 0xFF,
x_start & 0xFF,
((x_end - 1) >> 8) & 0xFF,
(x_end - 1) & 0xFF,
}, 4);
if (0 == axs15231b->flags.use_qspi_interface) {
tx_param(axs15231b, io, LCD_CMD_RASET, (uint8_t[]) {
(y_start >> 8) & 0xFF,
y_start & 0xFF,
((y_end - 1) >> 8) & 0xFF,
(y_end - 1) & 0xFF,
}, 4);
}
// transfer frame buffer
size_t len = (x_end - x_start) * (y_end - y_start) * axs15231b->fb_bits_per_pixel / 8;
if (y_start == 0) {
tx_color(axs15231b, io, LCD_CMD_RAMWR, color_data, len);//2C
} else {
tx_color(axs15231b, io, LCD_CMD_RAMWRC, color_data, len);//3C
}
return ESP_OK;
}
static esp_err_t panel_axs15231b_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
esp_lcd_panel_io_handle_t io = axs15231b->io;
int command = 0;
if (invert_color_data) {
command = LCD_CMD_INVON;
} else {
command = LCD_CMD_INVOFF;
}
tx_param(axs15231b, io, command, NULL, 0);
return ESP_OK;
}
static esp_err_t panel_axs15231b_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
esp_lcd_panel_io_handle_t io = axs15231b->io;
if (mirror_x) {
axs15231b->madctl_val |= LCD_CMD_MX_BIT;
} else {
axs15231b->madctl_val &= ~LCD_CMD_MX_BIT;
}
if (mirror_y) {
axs15231b->madctl_val |= LCD_CMD_MY_BIT;
} else {
axs15231b->madctl_val &= ~LCD_CMD_MY_BIT;
}
tx_param(axs15231b, io, LCD_CMD_MADCTL, (uint8_t[]) {
axs15231b->madctl_val
}, 1);
return ESP_OK;
}
static esp_err_t panel_axs15231b_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
esp_lcd_panel_io_handle_t io = axs15231b->io;
if (swap_axes) {
axs15231b->madctl_val |= LCD_CMD_MV_BIT;
} else {
axs15231b->madctl_val &= ~LCD_CMD_MV_BIT;
}
tx_param(axs15231b, io, LCD_CMD_MADCTL, (uint8_t[]) {
axs15231b->madctl_val
}, 1);
return ESP_OK;
}
static esp_err_t panel_axs15231b_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
axs15231b->x_gap = x_gap;
axs15231b->y_gap = y_gap;
return ESP_OK;
}
static esp_err_t panel_axs15231b_disp_off(esp_lcd_panel_t *panel, bool off)
{
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
esp_lcd_panel_io_handle_t io = axs15231b->io;
int command = 0;
if (off) {
command = LCD_CMD_DISPOFF;
} else {
command = LCD_CMD_DISPON;
}
tx_param(axs15231b, io, command, NULL, 0);
return ESP_OK;
}
esp_err_t esp_lcd_touch_new_i2c_axs15231b(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *tp)
{
ESP_RETURN_ON_FALSE(io, ESP_ERR_INVALID_ARG, TAG, "Invalid io");
ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "Invalid config");
ESP_RETURN_ON_FALSE(tp, ESP_ERR_INVALID_ARG, TAG, "Invalid touch handle");
/* Prepare main structure */
esp_err_t ret = ESP_OK;
esp_lcd_touch_handle_t axs15231b = calloc(1, sizeof(esp_lcd_touch_t));
ESP_GOTO_ON_FALSE(axs15231b, ESP_ERR_NO_MEM, err, TAG, "Touch handle malloc failed");
/* Communication interface */
axs15231b->io = io;
/* Only supported callbacks are set */
axs15231b->read_data = touch_axs15231b_read_data;
axs15231b->get_xy = touch_axs15231b_get_xy;
axs15231b->del = touch_axs15231b_del;
/* Mutex */
axs15231b->data.lock.owner = portMUX_FREE_VAL;
/* Save config */
memcpy(&axs15231b->config, config, sizeof(esp_lcd_touch_config_t));
/* Prepare pin for touch interrupt */
if (axs15231b->config.int_gpio_num != GPIO_NUM_NC) {
const gpio_config_t int_gpio_config = {
.mode = GPIO_MODE_INPUT,
.intr_type = GPIO_INTR_NEGEDGE,
.pin_bit_mask = BIT64(axs15231b->config.int_gpio_num)
};
ESP_GOTO_ON_ERROR(gpio_config(&int_gpio_config), err, TAG, "GPIO intr config failed");
/* Register interrupt callback */
if (axs15231b->config.interrupt_callback) {
esp_lcd_touch_register_interrupt_callback(axs15231b, axs15231b->config.interrupt_callback);
}
}
/* Prepare pin for touch controller reset */
if (axs15231b->config.rst_gpio_num != GPIO_NUM_NC) {
const gpio_config_t rst_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = BIT64(axs15231b->config.rst_gpio_num)
};
ESP_GOTO_ON_ERROR(gpio_config(&rst_gpio_config), err, TAG, "GPIO reset config failed");
}
/* Reset controller */
ESP_GOTO_ON_ERROR(touch_axs15231b_reset(axs15231b), err, TAG, "Reset failed");
*tp = axs15231b;
return ESP_OK;
err:
if (axs15231b) {
touch_axs15231b_del(axs15231b);
}
ESP_LOGE(TAG, "Initialization failed!");
return ret;
}
static esp_err_t touch_axs15231b_read_data(esp_lcd_touch_handle_t tp)
{
typedef struct {
uint8_t gesture; //AXS_TOUCH_GESTURE_POS:0
uint8_t num; //AXS_TOUCH_POINT_NUM:1
uint8_t x_h : 4; //AXS_TOUCH_X_H_POS:2
uint8_t : 2;
uint8_t event : 2; //AXS_TOUCH_EVENT_POS:2
uint8_t x_l; //AXS_TOUCH_X_L_POS:3
uint8_t y_h : 4; //AXS_TOUCH_Y_H_POS:4
uint8_t : 4;
uint8_t y_l; //AXS_TOUCH_Y_L_POS:5
} __attribute__((packed)) touch_record_struct_t;
touch_record_struct_t *p_touch_data = NULL;
uint8_t data[AXS_MAX_TOUCH_NUMBER * 6 + 2] = {0}; /*1 Point:8; 2 Point: 14 */
const uint8_t read_cmd[11] = {0xb5, 0xab, 0xa5, 0x5a, 0x00, 0x00, (AXS_MAX_TOUCH_NUMBER * 6 + 2) >> 8, (AXS_MAX_TOUCH_NUMBER * 6 + 2) & 0xff, 0x00, 0x00, 0x00};
ESP_RETURN_ON_ERROR(i2c_write_bytes(tp, -1, read_cmd, sizeof(read_cmd)), TAG, "I2C write failed");
ESP_RETURN_ON_ERROR(i2c_read_bytes(tp, -1, data, sizeof(data)), TAG, "I2C read failed");
p_touch_data = (touch_record_struct_t *) data;
if (p_touch_data->num && (AXS_MAX_TOUCH_NUMBER >= p_touch_data->num)) {
portENTER_CRITICAL(&tp->data.lock);
tp->data.points = p_touch_data->num;
/* Fill all coordinates */
for (int i = 0; i < tp->data.points; i++) {
tp->data.coords[i].x = ((p_touch_data->x_h & 0x0F) << 8) | p_touch_data->x_l;
tp->data.coords[i].y = ((p_touch_data->y_h & 0x0F) << 8) | p_touch_data->y_l;
}
portEXIT_CRITICAL(&tp->data.lock);
}
return ESP_OK;
}
static bool touch_axs15231b_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
{
portENTER_CRITICAL(&tp->data.lock);
/* Count of points */
*point_num = (tp->data.points > max_point_num ? max_point_num : tp->data.points);
for (size_t i = 0; i < *point_num; i++) {
x[i] = tp->data.coords[i].x;
y[i] = tp->data.coords[i].y;
if (strength) {
strength[i] = tp->data.coords[i].strength;
}
}
/* Invalidate */
tp->data.points = 0;
portEXIT_CRITICAL(&tp->data.lock);
return (*point_num > 0);
}
static esp_err_t touch_axs15231b_del(esp_lcd_touch_handle_t tp)
{
/* Reset GPIO pin settings */
if (tp->config.int_gpio_num != GPIO_NUM_NC) {
gpio_reset_pin(tp->config.int_gpio_num);
}
if (tp->config.rst_gpio_num != GPIO_NUM_NC) {
gpio_reset_pin(tp->config.rst_gpio_num);
}
/* Release memory */
free(tp);
return ESP_OK;
}
static esp_err_t touch_axs15231b_reset(esp_lcd_touch_handle_t tp)
{
if (tp->config.rst_gpio_num != GPIO_NUM_NC) {
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, tp->config.levels.reset), TAG, "GPIO set level failed");
vTaskDelay(pdMS_TO_TICKS(200));
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, !tp->config.levels.reset), TAG, "GPIO set level failed");
vTaskDelay(pdMS_TO_TICKS(200));
}
return ESP_OK;
}
static esp_err_t i2c_read_bytes(esp_lcd_touch_handle_t tp, int reg, uint8_t *data, uint8_t len)
{
ESP_RETURN_ON_FALSE(data, ESP_ERR_INVALID_ARG, TAG, "Invalid data");
return esp_lcd_panel_io_rx_param(tp->io, reg, data, len);
}
static esp_err_t i2c_write_bytes(esp_lcd_touch_handle_t tp, int reg, const uint8_t *data, uint8_t len)
{
ESP_RETURN_ON_FALSE(data, ESP_ERR_INVALID_ARG, TAG, "Invalid data");
return esp_lcd_panel_io_tx_param(tp->io, reg, data, len);
}

View File

@@ -0,0 +1,14 @@
dependencies:
cmake_utilities: 0.*
esp_lcd_touch:
public: true
version: ^1
idf: '>5.0.4,!=5.1.1'
description: ESP LCD & Touch AXS15231B
issues: https://github.com/espressif/esp-iot-solution/issues
repository: git://github.com/espressif/esp-iot-solution.git
repository_info:
commit_sha: c588f967727ca01e21c8c1f4fed575fa8907b678
path: components/display/lcd/esp_lcd_axs15231b
url: https://github.com/espressif/esp-bsp/tree/master/components/lcd/esp_lcd_axs15231b
version: 1.0.1

View File

@@ -0,0 +1,207 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LCD & Touch: AXS15231B
*/
#pragma once
#include "hal/spi_ll.h"
#include "esp_lcd_touch.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 */
} axs15231b_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 axs15231b_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 */
struct {
unsigned int use_qspi_interface: 1; /*<! Set to 1 if use QSPI interface, default is SPI interface */
} flags;
} axs15231b_vendor_config_t;
/**
* @brief Create LCD panel for model AXS15231B
*
* @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_axs15231b(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 AXS15231B_PANEL_BUS_I80_CONFIG(dc, wr, clk, d0, d1, d2, d3, d4, d5, d6, d7, b_w, max_trans_sz) \
{ \
.dc_gpio_num = dc, \
.wr_gpio_num = wr, \
.clk_src = clk, \
.data_gpio_nums = { \
d0, \
d1, \
d2, \
d3, \
d4, \
d5, \
d6, \
d7, \
}, \
.bus_width = b_w, \
.max_transfer_bytes = max_trans_sz, \
}
#define AXS15231B_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 AXS15231B_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 AXS15231B_PANEL_IO_I80_CONFIG(cs, dc, cb, cb_ctx) \
{ \
.cs_gpio_num = cs, \
.pclk_hz = 20 * 1000 * 1000, \
.on_color_trans_done = cb, \
.trans_queue_depth = 10, \
.user_ctx = cb_ctx, \
.dc_levels = { \
.dc_idle_level = 0, \
.dc_cmd_level = 0, \
.dc_dummy_level = 0, \
.dc_data_level = 1, \
}, \
.lcd_cmd_bits = 8, \
.lcd_param_bits = 8, \
}
#define AXS15231B_PANEL_IO_SPI_CONFIG(cs, dc, cb, cb_ctx) \
{ \
.cs_gpio_num = cs, \
.dc_gpio_num = dc, \
.spi_mode = 3, \
.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 AXS15231B_PANEL_IO_QSPI_CONFIG(cs, cb, cb_ctx) \
{ \
.cs_gpio_num = cs, \
.dc_gpio_num = -1, \
.spi_mode = 3, \
.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, \
}, \
}
/**
* @brief Create a new AXS15231B1B touch driver
*
* @note The I2C communication should be initialized before use this function.
*
* @param io LCD panel IO handle, it should be created by `esp_lcd_new_panel_io_i2c()`
* @param config Touch panel configuration
* @param tp Touch panel handle
* @return
* - ESP_OK: on success
*/
esp_err_t esp_lcd_touch_new_i2c_axs15231b(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *tp);
/**
* @brief I2C address of the AXS15231B controller
*
*/
#define ESP_LCD_TOUCH_IO_I2C_AXS15231B_ADDRESS (0x3B)
/**
* @brief Touch IO configuration structure
*
*/
#define ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG() \
{ \
.dev_addr = ESP_LCD_TOUCH_IO_I2C_AXS15231B_ADDRESS, \
.control_phase_bytes = 1, \
.dc_bit_offset = 0, \
.lcd_cmd_bits = 8, \
.flags = \
{ \
.disable_control_phase = 1, \
} \
}
#define ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG_EX(scl_speed_hz) \
{ \
.dev_addr = ESP_LCD_TOUCH_IO_I2C_AXS15231B_ADDRESS, \
.control_phase_bytes = 1, \
.dc_bit_offset = 0, \
.lcd_cmd_bits = 8, \
.flags = \
{ \
.disable_control_phase = 1, \
}, \
.scl_speed_hz = scl_speed_hz, \
}
#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_axs15231b)

View File

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

View File

@@ -0,0 +1,5 @@
## IDF Component Manager Manifest File
dependencies:
esp_lcd_axs15231b:
version: "*"
override_path: "../../../esp_lcd_axs15231b"

View File

@@ -0,0 +1,435 @@
/*
* SPDX-FileCopyrightText: 2023-2024 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 "driver/i2c.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 "unity_test_utils_memory.h"
#include "esp_lcd_axs15231b.h"
#define TEST_LCD_BIT_PER_PIXEL (16)
/* I80 */
#define TEST_LCD_I80_H_RES (170)
#define TEST_LCD_I80_V_RES (560)
#define TEST_LCD_I80_CLK_HZ (20 * 1000 * 1000)
#define TEST_PIN_NUM_I80_DATA0 (GPIO_NUM_7)
#define TEST_PIN_NUM_I80_DATA1 (GPIO_NUM_8)
#define TEST_PIN_NUM_I80_DATA2 (GPIO_NUM_9)
#define TEST_PIN_NUM_I80_DATA3 (GPIO_NUM_10)
#define TEST_PIN_NUM_I80_DATA4 (GPIO_NUM_11)
#define TEST_PIN_NUM_I80_DATA5 (GPIO_NUM_12)
#define TEST_PIN_NUM_I80_DATA6 (GPIO_NUM_13)
#define TEST_PIN_NUM_I80_DATA7 (GPIO_NUM_14)
#define TEST_PIN_NUM_I80_PCLK (GPIO_NUM_3)
#define TEST_PIN_NUM_I80_CS (GPIO_NUM_44)
#define TEST_PIN_NUM_I80_DC (GPIO_NUM_4)
#define TEST_PIN_NUM_I80_RD (GPIO_NUM_2)
#define TEST_PIN_NUM_I80_RST (GPIO_NUM_5)
#define TEST_PIN_NUM_I80_BL (GPIO_NUM_38)
/* SPI & QSPI */
#define TEST_LCD_SPI_H_RES (320)
#define TEST_LCD_SPI_V_RES (480)
#define TEST_LCD_SPI_HOST (SPI2_HOST)
#define TEST_PIN_NUM_SPI_CS (GPIO_NUM_45)
#define TEST_PIN_NUM_SPI_PCLK (GPIO_NUM_47)
#define TEST_PIN_NUM_SPI_DATA0 (GPIO_NUM_21)
#define TEST_PIN_NUM_SPI_DATA1 (GPIO_NUM_48)
#define TEST_PIN_NUM_SPI_DATA2 (GPIO_NUM_40)
#define TEST_PIN_NUM_SPI_DATA3 (GPIO_NUM_39)
#define TEST_PIN_NUM_SPI_RST (GPIO_NUM_NC)
#define TEST_PIN_NUM_SPI_DC (GPIO_NUM_8)
#define TEST_PIN_NUM_SPI_BL (GPIO_NUM_1)
/* Touch */
#define TEST_I2C_MASTER_NUM (I2C_NUM_0)
#define TEST_I2C_CLK_SPEED (400000)
#define TEST_PIN_NUM_TOUCH_SCL (GPIO_NUM_18)
#define TEST_PIN_NUM_TOUCH_SDA (GPIO_NUM_17)
#define TEST_PIN_NUM_TOUCH_RST (GPIO_NUM_5)
#define TEST_PIN_NUM_TOUCH_INT (GPIO_NUM_21)
#define TEST_DELAY_TIME_MS (3000)
#define TEST_READ_TIME_MS (3000)
#define TEST_READ_PERIOD_MS (30)
static char *TAG = "axs15231b_test";
static SemaphoreHandle_t refresh_finish = NULL;
static SemaphoreHandle_t touch_mux = NULL;
static const axs15231b_lcd_init_cmd_t lcd_init_cmds[] = {
{0xBB, (uint8_t []){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5}, 8, 0},
{0xA0, (uint8_t []){0xC0, 0x10, 0x00, 0x02, 0x00, 0x00, 0x04, 0x3F, 0x20, 0x05, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00}, 17, 0},
{0xA2, (uint8_t []){0x30, 0x3C, 0x24, 0x14, 0xD0, 0x20, 0xFF, 0xE0, 0x40, 0x19, 0x80, 0x80, 0x80, 0x20, 0xf9, 0x10, 0x02, 0xff, 0xff, 0xF0, 0x90, 0x01, 0x32, 0xA0, 0x91, 0xE0, 0x20, 0x7F, 0xFF, 0x00, 0x5A}, 31, 0},
{0xD0, (uint8_t []){0xE0, 0x40, 0x51, 0x24, 0x08, 0x05, 0x10, 0x01, 0x20, 0x15, 0x42, 0xC2, 0x22, 0x22, 0xAA, 0x03, 0x10, 0x12, 0x60, 0x14, 0x1E, 0x51, 0x15, 0x00, 0x8A, 0x20, 0x00, 0x03, 0x3A, 0x12}, 30, 0},
{0xA3, (uint8_t []){0xA0, 0x06, 0xAa, 0x00, 0x08, 0x02, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x55, 0x55}, 22, 0},
{0xC1, (uint8_t []){0x31, 0x04, 0x02, 0x02, 0x71, 0x05, 0x24, 0x55, 0x02, 0x00, 0x41, 0x00, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0x52, 0x00, 0x4F, 0x52, 0x00, 0x45, 0x3B, 0x0B, 0x02, 0x0d, 0x00, 0xFF, 0x40}, 30, 0},
{0xC3, (uint8_t []){0x00, 0x00, 0x00, 0x50, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01}, 11, 0},
{0xC4, (uint8_t []){0x00, 0x24, 0x33, 0x80, 0x00, 0xea, 0x64, 0x32, 0xC8, 0x64, 0xC8, 0x32, 0x90, 0x90, 0x11, 0x06, 0xDC, 0xFA, 0x00, 0x00, 0x80, 0xFE, 0x10, 0x10, 0x00, 0x0A, 0x0A, 0x44, 0x50}, 29, 0},
{0xC5, (uint8_t []){0x18, 0x00, 0x00, 0x03, 0xFE, 0x3A, 0x4A, 0x20, 0x30, 0x10, 0x88, 0xDE, 0x0D, 0x08, 0x0F, 0x0F, 0x01, 0x3A, 0x4A, 0x20, 0x10, 0x10, 0x00}, 23, 0},
{0xC6, (uint8_t []){0x05, 0x0A, 0x05, 0x0A, 0x00, 0xE0, 0x2E, 0x0B, 0x12, 0x22, 0x12, 0x22, 0x01, 0x03, 0x00, 0x3F, 0x6A, 0x18, 0xC8, 0x22}, 20, 0},
{0xC7, (uint8_t []){0x50, 0x32, 0x28, 0x00, 0xa2, 0x80, 0x8f, 0x00, 0x80, 0xff, 0x07, 0x11, 0x9c, 0x67, 0xff, 0x24, 0x0c, 0x0d, 0x0e, 0x0f}, 20, 0},
{0xC9, (uint8_t []){0x33, 0x44, 0x44, 0x01}, 4, 0},
{0xCF, (uint8_t []){0x2C, 0x1E, 0x88, 0x58, 0x13, 0x18, 0x56, 0x18, 0x1E, 0x68, 0x88, 0x00, 0x65, 0x09, 0x22, 0xC4, 0x0C, 0x77, 0x22, 0x44, 0xAA, 0x55, 0x08, 0x08, 0x12, 0xA0, 0x08}, 27, 0},
{0xD5, (uint8_t []){0x40, 0x8E, 0x8D, 0x01, 0x35, 0x04, 0x92, 0x74, 0x04, 0x92, 0x74, 0x04, 0x08, 0x6A, 0x04, 0x46, 0x03, 0x03, 0x03, 0x03, 0x82, 0x01, 0x03, 0x00, 0xE0, 0x51, 0xA1, 0x00, 0x00, 0x00}, 30, 0},
{0xD6, (uint8_t []){0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x93, 0x00, 0x01, 0x83, 0x07, 0x07, 0x00, 0x07, 0x07, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x84, 0x00, 0x20, 0x01, 0x00}, 30, 0},
{0xD7, (uint8_t []){0x03, 0x01, 0x0b, 0x09, 0x0f, 0x0d, 0x1E, 0x1F, 0x18, 0x1d, 0x1f, 0x19, 0x40, 0x8E, 0x04, 0x00, 0x20, 0xA0, 0x1F}, 19, 0},
{0xD8, (uint8_t []){0x02, 0x00, 0x0a, 0x08, 0x0e, 0x0c, 0x1E, 0x1F, 0x18, 0x1d, 0x1f, 0x19}, 12, 0},
{0xD9, (uint8_t []){0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}, 12, 0},
{0xDD, (uint8_t []){0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}, 12, 0},
{0xDF, (uint8_t []){0x44, 0x73, 0x4B, 0x69, 0x00, 0x0A, 0x02, 0x90}, 8, 0},
{0xE0, (uint8_t []){0x3B, 0x28, 0x10, 0x16, 0x0c, 0x06, 0x11, 0x28, 0x5c, 0x21, 0x0D, 0x35, 0x13, 0x2C, 0x33, 0x28, 0x0D}, 17, 0},
{0xE1, (uint8_t []){0x37, 0x28, 0x10, 0x16, 0x0b, 0x06, 0x11, 0x28, 0x5C, 0x21, 0x0D, 0x35, 0x14, 0x2C, 0x33, 0x28, 0x0F}, 17, 0},
{0xE2, (uint8_t []){0x3B, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x35, 0x44, 0x32, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0D}, 17, 0},
{0xE3, (uint8_t []){0x37, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x35, 0x44, 0x32, 0x0C, 0x14, 0x14, 0x36, 0x32, 0x2F, 0x0F}, 17, 0},
{0xE4, (uint8_t []){0x3B, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x39, 0x44, 0x2E, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0D}, 17, 0},
{0xE5, (uint8_t []){0x37, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x39, 0x44, 0x2E, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0F}, 17, 0},
{0xA4, (uint8_t []){0x85, 0x85, 0x95, 0x82, 0xAF, 0xAA, 0xAA, 0x80, 0x10, 0x30, 0x40, 0x40, 0x20, 0xFF, 0x60, 0x30}, 16, 0},
{0xA4, (uint8_t []){0x85, 0x85, 0x95, 0x85}, 4, 0},
{0xBB, (uint8_t []){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 0},
{0x13, (uint8_t []){0x00}, 0, 0},
{0x11, (uint8_t []){0x00}, 0, 120},
{0x2C, (uint8_t []){0x00, 0x00, 0x00, 0x00}, 4, 0},
};
static void test_i2c_init(void)
{
const i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = TEST_PIN_NUM_TOUCH_SDA,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = TEST_PIN_NUM_TOUCH_SCL,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = TEST_I2C_CLK_SPEED
};
TEST_ESP_OK(i2c_param_config(TEST_I2C_MASTER_NUM, &i2c_conf));
TEST_ESP_OK(i2c_driver_install(TEST_I2C_MASTER_NUM, i2c_conf.mode, 0, 0, 0));
}
static void test_touch_panel_crate(esp_lcd_panel_io_handle_t *io_handle_p, esp_lcd_touch_handle_t *tp_handle_p, esp_lcd_touch_interrupt_callback_t callback)
{
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG();
const esp_lcd_touch_config_t tp_cfg = {
.x_max = TEST_LCD_I80_H_RES,
.y_max = TEST_LCD_I80_V_RES,
.rst_gpio_num = TEST_PIN_NUM_TOUCH_RST,
.int_gpio_num = TEST_PIN_NUM_TOUCH_INT,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
.interrupt_callback = callback,
};
TEST_ESP_OK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TEST_I2C_MASTER_NUM, &tp_io_config, io_handle_p));
TEST_ESP_OK(esp_lcd_touch_new_i2c_axs15231b(*io_handle_p, &tp_cfg, tp_handle_p));
}
static void touch_callback(esp_lcd_touch_handle_t tp)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(touch_mux, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken == pdTRUE) {
portYIELD_FROM_ISR();
}
}
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);
}
IRAM_ATTR static void test_draw_bitmap(esp_lcd_panel_handle_t panel_handle, uint32_t h_res, uint32_t v_res)
{
refresh_finish = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(refresh_finish);
uint16_t row_line = ((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 * 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 * 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, 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 axs15231b to draw color bar with I80 interface", "[axs15231b][I80]")
{
gpio_config_t init_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (1ULL << TEST_PIN_NUM_I80_RD) | (1ULL << TEST_PIN_NUM_I80_PCLK) | (1ULL << TEST_PIN_NUM_I80_BL),
};
ESP_ERROR_CHECK(gpio_config(&init_gpio_config));
gpio_set_level(TEST_PIN_NUM_I80_RD, 1);
gpio_set_level(TEST_PIN_NUM_I80_PCLK, 0);
gpio_set_level(TEST_PIN_NUM_I80_BL, 1);
ESP_LOGI(TAG, "Initialize Intel 8080 bus");
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config = AXS15231B_PANEL_BUS_I80_CONFIG(
TEST_PIN_NUM_I80_DC,
TEST_PIN_NUM_I80_PCLK,
LCD_CLK_SRC_DEFAULT,
TEST_PIN_NUM_I80_DATA0,
TEST_PIN_NUM_I80_DATA1,
TEST_PIN_NUM_I80_DATA2,
TEST_PIN_NUM_I80_DATA3,
TEST_PIN_NUM_I80_DATA4,
TEST_PIN_NUM_I80_DATA5,
TEST_PIN_NUM_I80_DATA6,
TEST_PIN_NUM_I80_DATA7,
8,
TEST_LCD_I80_H_RES * TEST_LCD_I80_V_RES * TEST_LCD_BIT_PER_PIXEL / 8);
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 = AXS15231B_PANEL_IO_I80_CONFIG(TEST_PIN_NUM_I80_CS,
TEST_LCD_I80_CLK_HZ,
test_notify_refresh_ready,
NULL);
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
ESP_LOGI(TAG, "Install LCD driver of axs15231b");
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = TEST_PIN_NUM_I80_RST,
.flags.reset_active_high = 0,
.color_space = ESP_LCD_COLOR_SPACE_RGB,
.bits_per_pixel = TEST_LCD_BIT_PER_PIXEL,
};
TEST_ESP_OK(esp_lcd_new_panel_axs15231b(io_handle, &panel_config, &panel_handle));
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
test_draw_bitmap(panel_handle, TEST_LCD_I80_H_RES, TEST_LCD_I80_V_RES);
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));
}
TEST_CASE("test axs15231b to draw color bar with SPI interface", "[axs15231b][spi]")
{
ESP_LOGI(TAG, "Initialize BL");
gpio_config_t init_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (1ULL << TEST_PIN_NUM_SPI_BL),
};
ESP_ERROR_CHECK(gpio_config(&init_gpio_config));
gpio_set_level(TEST_PIN_NUM_SPI_BL, 1);
ESP_LOGI(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = AXS15231B_PANEL_BUS_SPI_CONFIG(TEST_PIN_NUM_SPI_PCLK,
TEST_PIN_NUM_SPI_DATA0,
TEST_LCD_SPI_H_RES * TEST_LCD_SPI_V_RES * TEST_LCD_BIT_PER_PIXEL / 8);
TEST_ESP_OK(spi_bus_initialize(TEST_LCD_SPI_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 = AXS15231B_PANEL_IO_SPI_CONFIG(TEST_PIN_NUM_SPI_CS,
TEST_PIN_NUM_SPI_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_SPI_HOST, &io_config, &io_handle));
ESP_LOGI(TAG, "Install AXS15231B panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = TEST_PIN_NUM_SPI_RST,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
.bits_per_pixel = TEST_LCD_BIT_PER_PIXEL,
};
TEST_ESP_OK(esp_lcd_new_panel_axs15231b(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_LCD_SPI_H_RES, TEST_LCD_SPI_V_RES);
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_SPI_HOST));
}
TEST_CASE("test axs15231b to draw color bar with QSPI interface", "[axs15231b][qspi]")
{
ESP_LOGI(TAG, "Initialize BL");
gpio_config_t init_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (1ULL << TEST_PIN_NUM_SPI_BL),
};
ESP_ERROR_CHECK(gpio_config(&init_gpio_config));
gpio_set_level(TEST_PIN_NUM_SPI_BL, 1);
ESP_LOGI(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = AXS15231B_PANEL_BUS_QSPI_CONFIG(TEST_PIN_NUM_SPI_PCLK,
TEST_PIN_NUM_SPI_DATA0,
TEST_PIN_NUM_SPI_DATA1,
TEST_PIN_NUM_SPI_DATA2,
TEST_PIN_NUM_SPI_DATA3,
TEST_LCD_SPI_H_RES * TEST_LCD_SPI_V_RES * TEST_LCD_BIT_PER_PIXEL / 8);
TEST_ESP_OK(spi_bus_initialize(TEST_LCD_SPI_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 = AXS15231B_PANEL_IO_QSPI_CONFIG(TEST_PIN_NUM_SPI_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_SPI_HOST, &io_config, &io_handle));
ESP_LOGI(TAG, "Install AXS15231B panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
const axs15231b_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(lcd_init_cmds[0]),
.flags = {
.use_qspi_interface = 1,
},
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = TEST_PIN_NUM_SPI_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_axs15231b(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_LCD_SPI_H_RES, TEST_LCD_SPI_V_RES);
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_SPI_HOST));
}
TEST_CASE("test axs15231b to read touch point with interruption", "[axs15231b][interrupt]")
{
// Todo: Need to initialize LCD panel with specific initialization sequence, will be done in the future
test_i2c_init();
touch_mux = xSemaphoreCreateBinary();
TEST_ASSERT(touch_mux != NULL);
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_touch_handle_t tp_handle = NULL;
test_touch_panel_crate(&tp_io_handle, &tp_handle, touch_callback);
bool tp_pressed = false;
uint16_t tp_x = 0;
uint16_t tp_y = 0;
uint8_t tp_cnt = 0;
for (int i = 0; i < TEST_READ_TIME_MS / TEST_READ_PERIOD_MS; i++) {
/* Read data from touch controller into memory */
if (xSemaphoreTake(touch_mux, 0) == pdTRUE) {
TEST_ESP_OK(esp_lcd_touch_read_data(tp_handle)); // read only when ISR was triggled
}
/* Read data from touch controller */
tp_pressed = esp_lcd_touch_get_coordinates(tp_handle, &tp_x, &tp_y, NULL, &tp_cnt, 1);
if (tp_pressed && (tp_cnt > 0)) {
ESP_LOGI(TAG, "Touch position: %d,%d", tp_x, tp_y);
}
vTaskDelay(pdMS_TO_TICKS(TEST_READ_PERIOD_MS));
}
i2c_driver_delete(TEST_I2C_MASTER_NUM);
esp_lcd_touch_del(tp_handle);
esp_lcd_panel_io_del(tp_io_handle);
vSemaphoreDelete(touch_mux);
gpio_uninstall_isr_service();
}
TEST_CASE("test axs15231b to read touch point with polling", "[axs15231b][poll]")
{
// Todo: Need to initialize LCD panel with specific initialization sequence, will be done in the future
test_i2c_init();
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_touch_handle_t tp_handle = NULL;
test_touch_panel_crate(&tp_io_handle, &tp_handle, NULL);
bool tp_pressed = false;
uint16_t tp_x = 0;
uint16_t tp_y = 0;
uint8_t tp_cnt = 0;
for (int i = 0; i < TEST_READ_TIME_MS / TEST_READ_PERIOD_MS; i++) {
/* Read data from touch controller into memory */
TEST_ESP_OK(esp_lcd_touch_read_data(tp_handle)); // read only when ISR was triggled
/* Read data from touch controller */
tp_pressed = esp_lcd_touch_get_coordinates(tp_handle, &tp_x, &tp_y, NULL, &tp_cnt, 1);
if (tp_pressed && (tp_cnt > 0)) {
ESP_LOGI(TAG, "Touch position: %d,%d", tp_x, tp_y);
}
vTaskDelay(pdMS_TO_TICKS(TEST_READ_PERIOD_MS));
}
i2c_driver_delete(TEST_I2C_MASTER_NUM);
esp_lcd_touch_del(tp_handle);
esp_lcd_panel_io_del(tp_io_handle);
}
// 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("esp_lcd_axs15231b TEST \n");
unity_run_menu();
}

View File

@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: 2023-2024 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_esp_lcd_axs15231b_i80(dut: Dut)-> None:
dut.expect_exact('Press ENTER to see the list of tests.')
dut.write('[I80]')
dut.expect_unity_test_output(timeout = 1000)
@pytest.mark.target('esp32s3')
@pytest.mark.env('esp32_s3_lcd_ev_board')
def test_esp_lcd_axs15231b_spi(dut: Dut)-> None:
dut.expect_exact('Press ENTER to see the list of tests.')
dut.write('[spi]')
dut.expect_unity_test_output(timeout = 1000)
@pytest.mark.target('esp32s3')
@pytest.mark.env('esp32_s3_lcd_ev_board')
def test_esp_lcd_axs15231b_qspi(dut: Dut)-> None:
dut.expect_exact('Press ENTER to see the list of tests.')
dut.write('[qspi]')
dut.expect_unity_test_output(timeout = 1000)

View File

@@ -0,0 +1,12 @@
# For IDF 5.0
CONFIG_IDF_TARGET="esp32s3"
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_IDF_TARGET="esp32s3"
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP_TASK_WDT=n