Skip to content

Commit a09335f

Browse files
committed
feat: update
1 parent fb53176 commit a09335f

12 files changed

+240
-13
lines changed

CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ file(GLOB_RECURSE C_SRCS "${SRCS_DIR}/*.c")
55

66
idf_component_register(
77
SRCS
8-
${C_SRCS}
9-
${CPP_SRCS}
8+
${C_SRCS} ${CPP_SRCS}
109
INCLUDE_DIRS
1110
${SRCS_DIR}
1211
REQUIRES
13-
driver
14-
esp_lcd
15-
esp-io-expander
12+
driver esp_lcd
1613
)
1714

1815
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-missing-field-initializers -Wno-narrowing)

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ url: https://github.com/esp-arduino-libs/ESP32_Display_Panel
44
repository: https://github.com/esp-arduino-libs/ESP32_Display_Panel.git
55
issues: https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues
66
dependencies:
7-
idf: ">=5.0"
7+
idf: ">=5.1"
88
esp-arduino-libs/esp-io-expander:
99
git: https://github.com/esp-arduino-libs/ESP32_IO_Expander.git

src/ESP_Panel.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace std;
1717
* Macros for adding host of bus
1818
*
1919
*/
20-
#define _ADD_HOST(name, host, config, id) host.addHost##name(config, id)
20+
#define _ADD_HOST(name, host, config, id) host->addHost##name(config, id)
2121
#define ADD_HOST(name, host, config, id) _ADD_HOST(name, host, config, id)
2222
/**
2323
* Macros for creating panel bus
@@ -62,6 +62,7 @@ ESP_Panel::ESP_Panel():
6262
_lcd_ptr(nullptr),
6363
_touch_ptr(nullptr),
6464
_backlight_ptr(nullptr),
65+
_host_ptr(nullptr),
6566
_expander_ptr(nullptr)
6667
{
6768
}
@@ -98,13 +99,13 @@ bool ESP_Panel::init(void)
9899
{
99100
ESP_PANEL_ENABLE_TAG_DEBUG_LOG();
100101

101-
ESP_PanelHost host;
102+
shared_ptr<ESP_PanelHost> host_ptr = make_shared<ESP_PanelHost>();
102103
shared_ptr<ESP_PanelBus> lcd_bus_ptr = nullptr;
103104
shared_ptr<ESP_PanelLcd> lcd_ptr = nullptr;
104105
shared_ptr<ESP_PanelBus> touch_bus_ptr = nullptr;
105106
shared_ptr<ESP_PanelTouch> touch_ptr = nullptr;
106-
shared_ptr<ESP_IOExpander> expander_ptr = _expander_ptr;
107107
shared_ptr<ESP_PanelBacklight> backlight_ptr = nullptr;
108+
shared_ptr<ESP_IOExpander> expander_ptr = _expander_ptr;
108109

109110
ESP_LOGD(TAG, "Panel init start");
110111

@@ -310,7 +311,7 @@ bool ESP_Panel::init(void)
310311
#else
311312
/* For non-RGB LCD, should use `ADD_HOST()` to init host when `ESP_PANEL_LCD_BUS_SKIP_INIT_HOST` enabled */
312313
#if !ESP_PANEL_LCD_BUS_SKIP_INIT_HOST
313-
ESP_PANEL_CHECK_FALSE_RET(ADD_HOST(ESP_PANEL_LCD_BUS_NAME, host, lcd_bus_host_config, ESP_PANEL_LCD_BUS_HOST),
314+
ESP_PANEL_CHECK_FALSE_RET(ADD_HOST(ESP_PANEL_LCD_BUS_NAME, host_ptr, lcd_bus_host_config, ESP_PANEL_LCD_BUS_HOST),
314315
false, "Add host failed");
315316
#endif
316317
lcd_bus_ptr = CREATE_BUS_SKIP_HOST(ESP_PANEL_LCD_BUS_NAME, lcd_panel_io_config, ESP_PANEL_LCD_BUS_HOST);
@@ -403,7 +404,7 @@ bool ESP_Panel::init(void)
403404
};
404405

405406
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
406-
ESP_PANEL_CHECK_FALSE_RET(ADD_HOST(ESP_PANEL_TOUCH_BUS_NAME, host, touch_host_config, ESP_PANEL_TOUCH_BUS_HOST),
407+
ESP_PANEL_CHECK_FALSE_RET(ADD_HOST(ESP_PANEL_TOUCH_BUS_NAME, host_ptr, touch_host_config, ESP_PANEL_TOUCH_BUS_HOST),
407408
false, "Add host failed");
408409
#endif
409410

@@ -440,22 +441,23 @@ bool ESP_Panel::init(void)
440441
},
441442
.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL,
442443
};
443-
ESP_PANEL_CHECK_FALSE_RET(ADD_HOST(I2C, host, expander_host_config, ESP_PANEL_EXPANDER_HOST), false,
444+
ESP_PANEL_CHECK_FALSE_RET(ADD_HOST(I2C, host_ptr, expander_host_config, ESP_PANEL_EXPANDER_HOST), false,
444445
"Add host failed");
445446
#endif
446447
expander_ptr = CREATE_EXPANDER(ESP_PANEL_EXPANDER_NAME, ESP_PANEL_EXPANDER_HOST, ESP_PANEL_EXPANDER_I2C_ADDRESS);
447448
}
448449
#endif /* ESP_PANEL_USE_EXPANDER */
449450

450451
ESP_LOGD(TAG, "Initialize host");
451-
ESP_PANEL_CHECK_FALSE_RET(host.begin(), false, "Initialize host failed");
452+
ESP_PANEL_CHECK_FALSE_RET(host_ptr->begin(), false, "Initialize host failed");
452453

453454
// Save the created devices
454455
_lcd_bus_ptr = lcd_bus_ptr;
455456
_lcd_ptr = lcd_ptr;
456457
_touch_bus_ptr = touch_bus_ptr;
457458
_touch_ptr = touch_ptr;
458459
_backlight_ptr = backlight_ptr;
460+
_host_ptr = host_ptr;
459461
_expander_ptr = expander_ptr;
460462
_is_initialed = true;
461463

@@ -625,6 +627,11 @@ bool ESP_Panel::del(void)
625627
_expander_ptr = nullptr;
626628
}
627629

630+
if (_host_ptr != nullptr) {
631+
ESP_LOGD(TAG, "Delete host");
632+
_host_ptr = nullptr;
633+
}
634+
628635
_is_initialed = false;
629636
ESP_LOGD(TAG, "Delete panel");
630637

src/ESP_Panel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class ESP_Panel {
102102
std::shared_ptr<ESP_PanelLcd> _lcd_ptr;
103103
std::shared_ptr<ESP_PanelTouch> _touch_ptr;
104104
std::shared_ptr<ESP_PanelBacklight> _backlight_ptr;
105+
std::shared_ptr<ESP_PanelHost> _host_ptr;
105106
std::shared_ptr<ESP_IOExpander> _expander_ptr;
106107
};
107108

src/host/ESP_PanelHost.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ ESP_PanelHost::~ESP_PanelHost()
2020
{
2121
ESP_PANEL_ENABLE_TAG_DEBUG_LOG();
2222

23+
if (!del()) {
24+
ESP_LOGE(TAG, "Delete panel host failed");
25+
}
2326
ESP_LOGD(TAG, "Destroyed");
2427
}
2528

@@ -165,6 +168,31 @@ bool ESP_PanelHost::begin(void)
165168
return true;
166169
}
167170

171+
bool ESP_PanelHost::del(void)
172+
{
173+
ESP_PANEL_ENABLE_TAG_DEBUG_LOG();
174+
175+
// Uninstall all I2C hosts
176+
if (_i2c_host_config_map.size() > 0) {
177+
for (auto &it : _i2c_host_config_map) {
178+
ESP_PANEL_CHECK_ERR_RET(i2c_driver_delete(it.first), false, "I2C[%d] delete driver failed", it.first);
179+
ESP_LOGD(TAG, "Delete host I2C[%d]", (int)it.first);
180+
}
181+
_i2c_host_config_map.clear();
182+
}
183+
184+
// Uninstall all SPI hosts
185+
if (_spi_host_config_map.size() > 0) {
186+
for (auto &it : _spi_host_config_map) {
187+
ESP_PANEL_CHECK_ERR_RET(spi_bus_free(it.first), false, "SPI[%d] free failed", it.first);
188+
ESP_LOGD(TAG, "Delete host SPI[%d]", (int)it.first);
189+
}
190+
_spi_host_config_map.clear();
191+
}
192+
193+
return true;
194+
}
195+
168196
bool ESP_PanelHost::compare_spi_host_config(spi_bus_config_t &old_config, const spi_bus_config_t &new_config)
169197
{
170198
spi_bus_config_t temp_config = { };

src/host/ESP_PanelHost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ESP_PanelHost {
8888
bool addHostQSPI(int sck_io, int d0_io, int d1_io, int d2_io, int d3_io, spi_host_device_t host_id);
8989

9090
bool begin(void);
91+
bool del(void);
9192

9293
private:
9394
bool compare_spi_host_config(spi_bus_config_t &old_config, const spi_bus_config_t &new_config);

test_apps/panel/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(panal_test)

test_apps/panel/main/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(
2+
SRCS "test_app_main.c" "test_panel.cpp"
3+
WHOLE_ARCHIVE
4+
)
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"

test_apps/panel/main/test_app_main.c

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+
}

test_apps/panel/main/test_panel.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
#define TEST_LCD_ENABLE_ATTACH_CALLBACK (1)
16+
#define TEST_TOUCH_ENABLE_ATTACH_CALLBACK (1)
17+
#define TEST_TOUCH_READ_POINTS_NUM (5)
18+
19+
#define TEST_READ_TOUCH_DELAY_MS (30)
20+
#define TEST_READ_TOUCH_TIME_MS (3000)
21+
22+
#define delay(x) vTaskDelay(pdMS_TO_TICKS(x))
23+
24+
using namespace std;
25+
26+
static const char *TAG = "test_panel";
27+
28+
#if TEST_LCD_ENABLE_ATTACH_CALLBACK
29+
IRAM_ATTR static bool onRefreshFinishCallback(void *user_data)
30+
{
31+
esp_rom_printf("Refresh finish callback\n");
32+
33+
return false;
34+
}
35+
#endif
36+
37+
#if TEST_TOUCH_ENABLE_ATTACH_CALLBACK
38+
IRAM_ATTR static bool onTouchInterruptCallback(void *user_data)
39+
{
40+
esp_rom_printf("Touch interrupt callback\n");
41+
42+
return false;
43+
}
44+
#endif
45+
46+
TEST_CASE("Test panel to draw color bar and read touch", "[panel]")
47+
{
48+
shared_ptr<ESP_Panel> panel = make_shared<ESP_Panel>();
49+
TEST_ASSERT_NOT_NULL_MESSAGE(panel, "Create panel object failed");
50+
51+
ESP_LOGI(TAG, "Initialize display panel");
52+
TEST_ASSERT_TRUE_MESSAGE(panel->init(), "Panel init failed");
53+
TEST_ASSERT_TRUE_MESSAGE(panel->begin(), "Panel begin failed");
54+
55+
ESP_PanelLcd *lcd = panel->getLcd();
56+
ESP_PanelTouch *touch = panel->getTouch();
57+
ESP_PanelBacklight *backlight = panel->getBacklight();
58+
59+
if (backlight != nullptr) {
60+
ESP_LOGI(TAG, "Turn off the backlight");
61+
backlight->off();
62+
} else {
63+
ESP_LOGI(TAG, "Backlight is not available");
64+
}
65+
66+
if (lcd != nullptr) {
67+
#if TEST_LCD_ENABLE_ATTACH_CALLBACK
68+
TEST_ASSERT_TRUE_MESSAGE(
69+
lcd->attachRefreshFinishCallback(onRefreshFinishCallback, NULL), "Attach refresh callback failed"
70+
);
71+
#endif
72+
ESP_LOGI(TAG, "Draw color bar from top to bottom, the order is B - G - R");
73+
TEST_ASSERT_TRUE_MESSAGE(
74+
lcd->colorBarTest(panel->getLcdWidth(), panel->getLcdHeight()), "LCD color bar test failed"
75+
);
76+
} else {
77+
ESP_LOGI(TAG, "LCD is not available");
78+
}
79+
80+
if (backlight != nullptr) {
81+
ESP_LOGI(TAG, "Turn on the backlight");
82+
TEST_ASSERT_TRUE_MESSAGE(backlight->on(), "Backlight on failed");
83+
}
84+
85+
if (touch != nullptr) {
86+
#if TEST_TOUCH_ENABLE_ATTACH_CALLBACK
87+
TEST_ASSERT_TRUE_MESSAGE(
88+
touch->attachInterruptCallback(onTouchInterruptCallback, NULL), "Attach touch interrupt callback failed"
89+
);
90+
#endif
91+
uint32_t t = 0;
92+
ESP_PanelTouchPoint point[TEST_TOUCH_READ_POINTS_NUM];
93+
int read_touch_result = 0;
94+
while (t++ < TEST_READ_TOUCH_TIME_MS / TEST_READ_TOUCH_DELAY_MS) {
95+
read_touch_result = touch->readPoints(point, TEST_TOUCH_READ_POINTS_NUM, TEST_READ_TOUCH_DELAY_MS);
96+
if (read_touch_result > 0) {
97+
for (int i = 0; i < read_touch_result; i++) {
98+
ESP_LOGI(TAG, "Touch point(%d): x %d, y %d, strength %d\n", i, point[i].x, point[i].y, point[i].strength);
99+
}
100+
} else if (read_touch_result < 0) {
101+
ESP_LOGE(TAG, "Read touch_device point failed");
102+
}
103+
#if ESP_PANEL_TOUCH_IO_INT < 0
104+
delay(TEST_READ_TOUCH_DELAY_MS);
105+
#endif
106+
}
107+
} else {
108+
ESP_LOGI(TAG, "Touch is not available");
109+
}
110+
}

test_apps/panel/sdkconfig.defaults

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

0 commit comments

Comments
 (0)