Skip to content

Commit fb53176

Browse files
committed
feat: update
1 parent 477b8f9 commit fb53176

File tree

8 files changed

+224
-23
lines changed

8 files changed

+224
-23
lines changed

test_apps/touch/i2c/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
5+
project(i2c_touch_test)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
idf_component_register(
2+
SRCS "test_app_main.c" "test_i2c_touch.cpp"
3+
PRIV_REQUIRES esp_lcd driver
4+
WHOLE_ARCHIVE
5+
)
6+
7+
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-missing-field-initializers)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
test_utils:
4+
path: ${IDF_PATH}/tools/unit-test-app/components/test_utils
5+
test_driver_utils:
6+
path: ${IDF_PATH}/components/driver/test_apps/components/test_driver_utils
7+
ESP32_Display_Panel:
8+
version: "*"
9+
override_path: "../../../../../ESP32_Display_Panel"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
#include <inttypes.h>
7+
#include "freertos/FreeRTOS.h"
8+
#include "freertos/task.h"
9+
#include "esp_heap_caps.h"
10+
#include "unity.h"
11+
#include "unity_test_runner.h"
12+
13+
// Some resources are lazy allocated in the LCD driver, the threadhold is left for that case
14+
#define TEST_MEMORY_LEAK_THRESHOLD (-300)
15+
16+
static size_t before_free_8bit;
17+
static size_t before_free_32bit;
18+
19+
static void check_leak(size_t before_free, size_t after_free, const char *type)
20+
{
21+
ssize_t delta = after_free - before_free;
22+
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
23+
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
24+
}
25+
26+
void setUp(void)
27+
{
28+
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
29+
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
30+
}
31+
32+
void tearDown(void)
33+
{
34+
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
35+
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
36+
check_leak(before_free_8bit, after_free_8bit, "8BIT");
37+
check_leak(before_free_32bit, after_free_32bit, "32BIT");
38+
}
39+
40+
void app_main(void)
41+
{
42+
/**
43+
* ______ ______ ______ ________ __
44+
* | \ / \ / \ | \ | \
45+
* \$$$$$$| $$$$$$\| $$$$$$\ \$$$$$$$$______ __ __ _______ | $$____
46+
* | $$ \$$__| $$| $$ \$$ | $$ / \ | \ | \ / \| $$ \
47+
* | $$ / $$| $$ | $$ | $$$$$$\| $$ | $$| $$$$$$$| $$$$$$$\
48+
* | $$ | $$$$$$ | $$ __ | $$ | $$ | $$| $$ | $$| $$ | $$ | $$
49+
* _| $$_ | $$_____ | $$__/ \ | $$ | $$__/ $$| $$__/ $$| $$_____ | $$ | $$
50+
* | $$ \| $$ \ \$$ $$ | $$ \$$ $$ \$$ $$ \$$ \| $$ | $$
51+
* \$$$$$$ \$$$$$$$$ \$$$$$$ \$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$ \$$
52+
*/
53+
printf(" ______ ______ ______ ________ __\r\n");
54+
printf("| \\ / \\ / \\ | \\ | \\\r\n");
55+
printf(" \\$$$$$$| $$$$$$\\| $$$$$$\\ \\$$$$$$$$______ __ __ _______ | $$____\r\n");
56+
printf(" | $$ \\$$__| $$| $$ \\$$ | $$ / \\ | \\ | \\ / \\| $$ \\\r\n");
57+
printf(" | $$ / $$| $$ | $$ | $$$$$$\\| $$ | $$| $$$$$$$| $$$$$$$\\\r\n");
58+
printf(" | $$ | $$$$$$ | $$ __ | $$ | $$ | $$| $$ | $$| $$ | $$ | $$\r\n");
59+
printf(" _| $$_ | $$_____ | $$__/ \\ | $$ | $$__/ $$| $$__/ $$| $$_____ | $$ | $$\r\n");
60+
printf("| $$ \\| $$ \\ \\$$ $$ | $$ \\$$ $$ \\$$ $$ \\$$ \\| $$ | $$\r\n");
61+
printf(" \\$$$$$$ \\$$$$$$$$ \\$$$$$$ \\$$ \\$$$$$$ \\$$$$$$ \\$$$$$$$ \\$$ \\$$\r\n");
62+
unity_run_menu();
63+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
#include <memory>
7+
#include "freertos/FreeRTOS.h"
8+
#include "freertos/task.h"
9+
#include "esp_heap_caps.h"
10+
#include "esp_log.h"
11+
#include "unity.h"
12+
#include "unity_test_runner.h"
13+
#include "ESP_Panel_Library.h"
14+
15+
using namespace std;
16+
17+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18+
//////////////////// Please update the following configuration according to your touch_device spec ////////////////////////////
19+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20+
#define TEST_TOUCH_ADDRESS (0) // Typically set to 0 to use the default address.
21+
// - For touchs with only one address, set to 0
22+
// - For touchs with multiple addresses, set to 0 or the address
23+
// Like GT911, there are two addresses: 0x5D(default) and 0x14
24+
#define TEST_TOUCH_WIDTH (480)
25+
#define TEST_TOUCH_HEIGHT (480)
26+
#define TEST_TOUCH_I2C_FREQ_HZ (400 * 1000)
27+
#define TEST_TOUCH_READ_POINTS_NUM (5)
28+
29+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30+
//////////////////// Please update the following configuration according to your board spec ////////////////////////////
31+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32+
#define TEST_TOUCH_PIN_NUM_I2C_SCL (10)
33+
#define TEST_TOUCH_PIN_NUM_I2C_SDA (9)
34+
#define TEST_TOUCH_PIN_NUM_RST (13) // Set to `-1` if not used
35+
// For GT911, the RST pin is also used to configure the I2C address
36+
#define TEST_TOUCH_PIN_NUM_INT (14) // Set to `-1` if not used
37+
// For GT911, the INT pin is also used to configure the I2C address
38+
39+
#define TEST_READ_TOUCH_DELAY_MS (30)
40+
#define TEST_READ_TOUCH_TIME_MS (3000)
41+
42+
static const char *TAG = "test_i2c_touch";
43+
44+
#define delay(x) vTaskDelay(pdMS_TO_TICKS(x))
45+
46+
#if TEST_TOUCH_PIN_NUM_INT >= 0
47+
IRAM_ATTR static bool onTouchInterruptCallback(void *user_data)
48+
{
49+
esp_rom_printf("Touch interrupt callback\n");
50+
51+
return false;
52+
}
53+
#endif
54+
55+
static void run_test(shared_ptr<ESP_PanelTouch> touch_device)
56+
{
57+
touch_device->init();
58+
touch_device->begin();
59+
#if TEST_TOUCH_PIN_NUM_INT >= 0
60+
touch_device->attachInterruptCallback(onTouchInterruptCallback, NULL);
61+
#endif
62+
63+
uint32_t t = 0;
64+
while (t++ < TEST_READ_TOUCH_TIME_MS / TEST_READ_TOUCH_DELAY_MS) {
65+
ESP_PanelTouchPoint point[TEST_TOUCH_READ_POINTS_NUM];
66+
int read_touch_result = touch_device->readPoints(point, TEST_TOUCH_READ_POINTS_NUM, TEST_READ_TOUCH_DELAY_MS);
67+
68+
if (read_touch_result > 0) {
69+
for (int i = 0; i < read_touch_result; i++) {
70+
ESP_LOGI(TAG, "Touch point(%d): x %d, y %d, strength %d\n", i, point[i].x, point[i].y, point[i].strength);
71+
}
72+
} else if (read_touch_result < 0) {
73+
ESP_LOGE(TAG, "Read touch_device point failed");
74+
}
75+
#if TEST_TOUCH_PIN_NUM_INT < 0
76+
delay(TEST_READ_TOUCH_DELAY_MS);
77+
#endif
78+
}
79+
}
80+
81+
#define CREATE_TOUCH_BUS(name) \
82+
({ \
83+
ESP_LOGI(TAG, "Create touch bus"); \
84+
shared_ptr<ESP_PanelBus_I2C> touch_bus = make_shared<ESP_PanelBus_I2C>( \
85+
TEST_TOUCH_PIN_NUM_I2C_SCL, TEST_TOUCH_PIN_NUM_I2C_SDA, \
86+
(esp_lcd_panel_io_i2c_config_t)ESP_PANEL_TOUCH_I2C_PANEL_IO_CONFIG(name) \
87+
); \
88+
TEST_ASSERT_NOT_NULL_MESSAGE(touch_bus, "Create panel bus object failed"); \
89+
touch_bus->configI2cFreqHz(TEST_TOUCH_I2C_FREQ_HZ); \
90+
TEST_ASSERT_TRUE_MESSAGE(touch_bus->begin(), "Panel bus begin failed"); \
91+
touch_bus; \
92+
})
93+
#define CREATE_TOUCH(name, touch_bus) \
94+
({ \
95+
ESP_LOGI(TAG, "Create touch device: " #name); \
96+
shared_ptr<ESP_PanelTouch> touch_device = make_shared<ESP_PanelTouch_##name>( \
97+
touch_bus, TEST_TOUCH_WIDTH, TEST_TOUCH_HEIGHT, TEST_TOUCH_PIN_NUM_RST, TEST_TOUCH_PIN_NUM_INT \
98+
); \
99+
TEST_ASSERT_NOT_NULL_MESSAGE(touch_device, "Create TOUCH object failed"); \
100+
touch_device; \
101+
})
102+
#define CREATE_TEST_CASE(name) \
103+
TEST_CASE("Test touch (" #name ") to draw color bar", "[i2c_touch][" #name "]") \
104+
{ \
105+
shared_ptr<ESP_PanelBus_I2C> touch_bus = CREATE_TOUCH_BUS(name); \
106+
shared_ptr<ESP_PanelTouch> touch_device = CREATE_TOUCH(name, touch_bus.get()); \
107+
run_test(touch_device); \
108+
}
109+
110+
/**
111+
* Here to create test cases for different touchs
112+
*
113+
*/
114+
CREATE_TEST_CASE(CST816S)
115+
CREATE_TEST_CASE(FT5x06)
116+
CREATE_TEST_CASE(GT1151)
117+
CREATE_TEST_CASE(TT21100)
118+
CREATE_TEST_CASE(ST1633)
119+
CREATE_TEST_CASE(ST7123)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ESP_TASK_WDT=
2+
CONFIG_FREERTOS_HZ=1000

test_apps/touch/spi/main/test_app_main.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ void tearDown(void)
4040
void app_main(void)
4141
{
4242
/**
43-
* ______ _______ ______ __ ______ _______
44-
* / \ | \| \ | \ / \ | \
45-
* | $$$$$$\| $$$$$$$\\$$$$$$ | $$ | $$$$$$\| $$$$$$$\
46-
* | $$___\$$| $$__/ $$ | $$ | $$ | $$ \$$| $$ | $$
47-
* \$$ \ | $$ $$ | $$ | $$ | $$ | $$ | $$
48-
* _\$$$$$$\| $$$$$$$ | $$ | $$ | $$ __ | $$ | $$
49-
* | \__| $$| $$ _| $$_ | $$_____| $$__/ \| $$__/ $$
50-
* \$$ $$| $$ | $$ \ | $$ \\$$ $$| $$ $$
51-
* \$$$$$$ \$$ \$$$$$$ \$$$$$$$$ \$$$$$$ \$$$$$$$
43+
* ______ _______ ______ ________ __
44+
* / \ | \| \ | \ | \
45+
* | $$$$$$\| $$$$$$$\\$$$$$$ \$$$$$$$$______ __ __ _______ | $$____
46+
* | $$___\$$| $$__/ $$ | $$ | $$ / \ | \ | \ / \| $$ \
47+
* \$$ \ | $$ $$ | $$ | $$ | $$$$$$\| $$ | $$| $$$$$$$| $$$$$$$\
48+
* _\$$$$$$\| $$$$$$$ | $$ | $$ | $$ | $$| $$ | $$| $$ | $$ | $$
49+
* | \__| $$| $$ _| $$_ | $$ | $$__/ $$| $$__/ $$| $$_____ | $$ | $$
50+
* \$$ $$| $$ | $$ \ | $$ \$$ $$ \$$ $$ \$$ \| $$ | $$
51+
* \$$$$$$ \$$ \$$$$$$ \$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$ \$$
5252
*/
53-
printf(" ______ _______ ______ __ ______ _______\r\n");
54-
printf(" / \\ | \\| \\ | \\ / \\ | \\\r\n");
55-
printf("| $$$$$$\\| $$$$$$$\\\\$$$$$$ | $$ | $$$$$$\\| $$$$$$$\\\r\n");
56-
printf("| $$___\\$$| $$__/ $$ | $$ | $$ | $$ \\$$| $$ | $$\r\n");
57-
printf(" \\$$ \\ | $$ $$ | $$ | $$ | $$ | $$ | $$\r\n");
58-
printf(" _\\$$$$$$\\| $$$$$$$ | $$ | $$ | $$ __ | $$ | $$\r\n");
59-
printf("| \\__| $$| $$ _| $$_ | $$_____| $$__/ \\| $$__/ $$\r\n");
60-
printf(" \\$$ $$| $$ | $$ \\ | $$ \\\\$$ $$| $$ $$\r\n");
61-
printf(" \\$$$$$$ \\$$ \\$$$$$$ \\$$$$$$$$ \\$$$$$$ \\$$$$$$$\r\n");
53+
printf(" ______ _______ ______ ________ __\r\n");
54+
printf(" / \\ | \\| \\ | \\ | \\\r\n");
55+
printf("| $$$$$$\\| $$$$$$$\\\\$$$$$$ \\$$$$$$$$______ __ __ _______ | $$____\r\n");
56+
printf("| $$___\\$$| $$__/ $$ | $$ | $$ / \\ | \\ | \\ / \\| $$ \\\r\n");
57+
printf(" \\$$ \\ | $$ $$ | $$ | $$ | $$$$$$\\| $$ | $$| $$$$$$$| $$$$$$$\\\r\n");
58+
printf(" _\\$$$$$$\\| $$$$$$$ | $$ | $$ | $$ | $$| $$ | $$| $$ | $$ | $$\r\n");
59+
printf("| \\__| $$| $$ _| $$_ | $$ | $$__/ $$| $$__/ $$| $$_____ | $$ | $$\r\n");
60+
printf(" \\$$ $$| $$ | $$ \\ | $$ \\$$ $$ \\$$ $$ \\$$ \\| $$ | $$\r\n");
61+
printf(" \\$$$$$$ \\$$ \\$$$$$$ \\$$ \\$$$$$$ \\$$$$$$ \\$$$$$$$ \\$$ \\$$\r\n");
6262
unity_run_menu();
6363
}

test_apps/touch/spi/main/test_spi_touch.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ using namespace std;
1717
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1818
//////////////////// Please update the following configuration according to your touch_device spec ////////////////////////////
1919
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20-
#define TEST_TOUCH_ADDRESS (0) // Typically set to 0 to use the default address.
21-
// - For touchs with only one address, set to 0
22-
// - For touchs with multiple addresses, set to 0 or the address
23-
// Like GT911, there are two addresses: 0x5D(default) and 0x14
2420
#define TEST_TOUCH_WIDTH (240)
2521
#define TEST_TOUCH_HEIGHT (320)
2622
#define TEST_TOUCH_SPI_FREQ_HZ (1 * 1000 * 1000)
@@ -108,7 +104,7 @@ static void run_test(shared_ptr<ESP_PanelTouch> touch_device)
108104
}
109105

110106
/**
111-
* Here to create test cases for different TOUCHs
107+
* Here to create test cases for different touchs
112108
*
113109
*/
114110
CREATE_TEST_CASE(XPT2046)

0 commit comments

Comments
 (0)