Skip to content

Commit

Permalink
Merge pull request #474 from espressif/test/touch_components_tests
Browse files Browse the repository at this point in the history
fix(esp_lcd_touch_cst816s): Fixed compilation error for IDF5.1 and lower
  • Loading branch information
espzav authored Jan 10, 2025
2 parents 938b0c3 + 6efe603 commit 70a95af
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .idf_build_apps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ recursive = true
exclude = [
"SquareLine",
]
manifest_file = ["components/.build-test-rules.yml", "components/io_expander/.build-test-rules.yml", "components/lcd/.build-test-rules.yml", "test_apps/.build-test-rules.yml", "examples/.build-test-rules.yml"]
manifest_file = ["components/.build-test-rules.yml", "components/io_expander/.build-test-rules.yml", "components/lcd/.build-test-rules.yml", "components/lcd_touch/.build-test-rules.yml", "test_apps/.build-test-rules.yml", "examples/.build-test-rules.yml"]
check_warnings = true
ignore_warning_file = ".ignore_build_warnings.txt"
config = "sdkconfig.bsp.*"
Expand Down
8 changes: 8 additions & 0 deletions components/lcd_touch/.build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# LCD Touch components: Build only on related changes
components/lcd_touch/esp_lcd_touch_cst816s:
depends_filepatterns:
- "components/lcd_touch/esp_lcd_touch_cst816s/**"

components/lcd_touch/esp_lcd_touch_stmpe610:
depends_filepatterns:
- "components/lcd_touch/esp_lcd_touch_stmpe610/**"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.4"
version: "1.0.5"
description: ESP LCD Touch CST816S - touch controller CST816S
url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch_cst816s
dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once

#include "esp_idf_version.h"
#include "esp_lcd_touch.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -40,6 +41,23 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons
* @brief Touch IO configuration structure
*
*/
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
#define ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG() \
{ \
.dev_addr = ESP_LCD_TOUCH_IO_I2C_CST816S_ADDRESS, \
.on_color_trans_done = 0, \
.user_ctx = 0, \
.control_phase_bytes = 1, \
.dc_bit_offset = 0, \
.lcd_cmd_bits = 8, \
.lcd_param_bits = 0, \
.flags = \
{ \
.dc_low_on_data = 0, \
.disable_control_phase = 1, \
} \
}
#else
#define ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG() \
{ \
.dev_addr = ESP_LCD_TOUCH_IO_I2C_CST816S_ADDRESS, \
Expand All @@ -56,6 +74,7 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons
}, \
.scl_speed_hz = 0 \
}
#endif

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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_touch_cst816s)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
idf_component_register(SRCS "test_esp_lcd_touch_cst816s.c")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=4.4"
esp_lcd_touch_cst816s:
version: "*"
override_path: "../../../esp_lcd_touch_cst816s"
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/

#include <inttypes.h>
#include "driver/i2c.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "unity.h"
#include "unity_test_runner.h"

#include "esp_lcd_touch_cst816s.h"

#define TEST_TOUCH_I2C_NUM (0)
#define TEST_TOUCH_I2C_CLK_HZ (400000)

#define TEST_LCD_H_RES (240)
#define TEST_LCD_V_RES (240)

/* LCD touch pins */
#define TEST_TOUCH_I2C_SCL (GPIO_NUM_18)
#define TEST_TOUCH_I2C_SDA (GPIO_NUM_8)
#define TEST_TOUCH_GPIO_INT (GPIO_NUM_3)

TEST_CASE("test cst816s to initialize touch", "[cst816s][i2c]")
{
/* Initilize I2C */
const i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = TEST_TOUCH_I2C_SDA,
.sda_pullup_en = GPIO_PULLUP_DISABLE,
.scl_io_num = TEST_TOUCH_I2C_SCL,
.scl_pullup_en = GPIO_PULLUP_DISABLE,
.master.clk_speed = TEST_TOUCH_I2C_CLK_HZ
};
TEST_ESP_OK(i2c_param_config(TEST_TOUCH_I2C_NUM, &i2c_conf));
TEST_ESP_OK(i2c_driver_install(TEST_TOUCH_I2C_NUM, i2c_conf.mode, 0, 0, 0));

/* Initialize touch HW */
const esp_lcd_touch_config_t tp_cfg = {
.x_max = TEST_LCD_H_RES,
.y_max = TEST_LCD_V_RES,
.rst_gpio_num = GPIO_NUM_NC, // Shared with LCD reset
.int_gpio_num = TEST_TOUCH_GPIO_INT,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 1,
.mirror_y = 0,
},
};

esp_lcd_touch_handle_t touch_handle;
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
TEST_ESP_OK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TEST_TOUCH_I2C_NUM, &tp_io_config, &tp_io_handle));
TEST_ESP_OK(esp_lcd_touch_new_i2c_cst816s(tp_io_handle, &tp_cfg, &touch_handle));
}

void app_main(void)
{
printf("CST816S Test\r\n");
unity_run_menu();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_EN=n
Original file line number Diff line number Diff line change
@@ -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_touch_stmpe610)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
idf_component_register(SRCS "test_esp_lcd_touch_stmpe610.c")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=4.4"
esp_lcd_touch_stmpe610:
version: "*"
override_path: "../../../esp_lcd_touch_stmpe610"
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/

#include <inttypes.h>
#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "unity.h"
#include "unity_test_runner.h"

#include "esp_lcd_touch_stmpe610.h"

#define TEST_LCD_PIXEL_CLOCK_HZ (20 * 1000 * 1000)
#define TEST_PIN_NUM_SCLK 18
#define TEST_PIN_NUM_MOSI 19
#define TEST_PIN_NUM_MISO 21
#define TEST_PIN_NUM_TOUCH_CS 15

#define TEST_LCD_H_RES (240)
#define TEST_LCD_V_RES (240)

/* LCD touch pins */
#define TEST_TOUCH_I2C_SCL (GPIO_NUM_18)
#define TEST_TOUCH_I2C_SDA (GPIO_NUM_8)
#define TEST_TOUCH_GPIO_INT (GPIO_NUM_3)

TEST_CASE("test stmpe610 to initialize touch", "[stmpe610][i2c]")
{
/* Initilize SPI bus */
spi_bus_config_t buscfg = {
.sclk_io_num = TEST_PIN_NUM_SCLK,
.mosi_io_num = TEST_PIN_NUM_MOSI,
.miso_io_num = TEST_PIN_NUM_MISO,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = TEST_LCD_H_RES * 80 * sizeof(uint16_t),
};
TEST_ESP_OK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));

esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_panel_io_spi_config_t tp_io_config = ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG(TEST_PIN_NUM_TOUCH_CS);
// Attach the TOUCH to the SPI bus
TEST_ESP_OK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &tp_io_config, &tp_io_handle));

esp_lcd_touch_config_t tp_cfg = {
.x_max = TEST_LCD_H_RES,
.y_max = TEST_LCD_V_RES,
.rst_gpio_num = -1,
.int_gpio_num = -1,
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
esp_lcd_touch_handle_t tp = NULL;

TEST_ESP_OK(esp_lcd_touch_new_spi_stmpe610(tp_io_handle, &tp_cfg, &tp));
}

void app_main(void)
{
printf("STMPE610 Test\r\n");
unity_run_menu();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_EN=n

0 comments on commit 70a95af

Please sign in to comment.