Skip to content

Commit fae572f

Browse files
committed
feat(examples): add lcd mip_dsi
1 parent af6f1e0 commit fae572f

File tree

3 files changed

+387
-0
lines changed

3 files changed

+387
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10+
///////////////////////////////////////////////// Debug Configurations /////////////////////////////////////////////////
11+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12+
/* Set to 1 if assert on error. Otherwise print error message */
13+
#define ESP_PANEL_CHECK_RESULT_ASSERT (0) // 0/1
14+
15+
/* Set to 1 if print log message for debug */
16+
#define ESP_PANEL_ENABLE_LOG (0) // 0/1
17+
18+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19+
///////////////////////////////////////////// Touch Driver Configurations //////////////////////////////////////////////
20+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21+
/* Maximum point number */
22+
#define ESP_PANEL_TOUCH_MAX_POINTS (5)
23+
/* Maximum button number */
24+
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
25+
26+
/**
27+
* XPT2046 related
28+
*
29+
*/
30+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
31+
/**
32+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
33+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
34+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
35+
*/
36+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
37+
/**
38+
* Keep internal Vref enabled.
39+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
40+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
41+
*
42+
*/
43+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
44+
/**
45+
* Convert touch coordinates to screen coordinates.
46+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
47+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
48+
* screen coordinate.
49+
*
50+
*/
51+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
52+
/**
53+
* Enable data structure locking.
54+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
55+
* XPT2046 and when reading position data via API.
56+
* WARNING: enabling this option may result in unintended crashes.
57+
*
58+
*/
59+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
60+
61+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62+
/////////////////////////////////////////////// File Version ///////////////////////////////////////////////////////////
63+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64+
/**
65+
* Do not change the following versions, they are used to check if the configurations in this file are compatible with
66+
* the current version of `ESP_Panel_Conf.h` in the library. The detailed rules are as follows:
67+
*
68+
* 1. If the major version is not consistent, then the configurations in this file are incompatible with the library
69+
* and must be replaced with the file from the library.
70+
* 2. If the minor version is not consistent, this file might be missing some new configurations, which will be set to
71+
* default values. It is recommended to replace it with the file from the library.
72+
* 3. Even if the patch version is not consistent, it will not affect normal functionality.
73+
*
74+
*/
75+
#define ESP_PANEL_CONF_FILE_VERSION_MAJOR 0
76+
#define ESP_PANEL_CONF_FILE_VERSION_MINOR 1
77+
#define ESP_PANEL_CONF_FILE_VERSION_PATCH 2

examples/LCD/MIPI_DSI/MIPI_DSI.ino

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
/**
2+
* | Supported ESP SoCs | ESP32-P4 |
3+
* | ------------------ | -------- |
4+
*
5+
* | Supported LCD Controllers | EK79007 |
6+
* | ------------------------- | ------- |
7+
*
8+
* # MIPI-DSI LCD Example
9+
*
10+
* The example demonstrates how to develop different model LCDs with MIPI-DSI interface using standalone drivers and test them by displaying color bars.
11+
*
12+
* ## How to use
13+
*
14+
* 1. [Configure drivers](../../../docs/How_To_Use.md#configuring-drivers) if needed.
15+
* 2. Modify the macros in the example to match the parameters according to your hardware.
16+
* 3. Navigate to the `Tools` menu in the Arduino IDE to choose a ESP board and configure its parameters, please refter to [Configuring Supported Development Boards](../../../docs/How_To_Use.md#configuring-supported-development-boards)
17+
* 4. Verify and upload the example to your ESP board.
18+
*
19+
* ## Serial Output
20+
*
21+
* ```
22+
* ...
23+
* MIPI-DSI LCD example start
24+
* Initialize backlight control pin and turn it on
25+
* Create MIPI-DSI LCD bus
26+
* Create LCD device
27+
* Show MIPI-DSI patterns
28+
* Draw color bar from top left to bottom right, the order is B - G - R
29+
* Draw bitmap finish callback
30+
* Draw bitmap finish callback
31+
* Draw bitmap finish callback
32+
* Draw bitmap finish callback
33+
* Draw bitmap finish callback
34+
* Draw bitmap finish callback
35+
* Draw bitmap finish callback
36+
* Draw bitmap finish callback
37+
* Draw bitmap finish callback
38+
* Draw bitmap finish callback
39+
* Draw bitmap finish callback
40+
* Draw bitmap finish callback
41+
* Draw bitmap finish callback
42+
* Draw bitmap finish callback
43+
* Draw bitmap finish callback
44+
* Draw bitmap finish callback
45+
* Draw bitmap finish callback
46+
* Draw bitmap finish callback
47+
* Draw bitmap finish callback
48+
* Draw bitmap finish callback
49+
* Draw bitmap finish callback
50+
* Draw bitmap finish callback
51+
* Draw bitmap finish callback
52+
* Draw bitmap finish callback
53+
* MIPI-DSI LCD example end
54+
* MIPI-DSI refresh rate: 0
55+
* MIPI-DSI refresh rate: 69
56+
* MIPI-DSI refresh rate: 69
57+
* MIPI-DSI refresh rate: 69
58+
* ...
59+
* ```
60+
*
61+
* ## Troubleshooting
62+
*
63+
* Please check the [FAQ](../../../docs/FAQ.md) first to see if the same question exists. If not, please create a [Github issue](https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues). We will get back to you as soon as possible.
64+
*
65+
*/
66+
67+
#include <Arduino.h>
68+
#include <ESP_Panel_Library.h>
69+
70+
/* The following default configurations are for the board 'Espressif: ESP32-P4-Function-EV-Board, EK79007' */
71+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72+
//////////////////// Please update the following configuration according to your LCD spec //////////////////////////////
73+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74+
/**
75+
* Currently, the library supports the following MIPI-DSI LCDs:
76+
* - EK79007
77+
*/
78+
#define EXAMPLE_LCD_NAME EK79007
79+
#define EXAMPLE_LCD_WIDTH (1024)
80+
#define EXAMPLE_LCD_HEIGHT (600)
81+
#define EXAMPLE_LCD_COLOR_BITS (ESP_PANEL_LCD_RGB888_COLOR_BITS_24)
82+
#define EXAMPLE_LCD_DSI_PHY_LDO_ID (3) // -1 if not used
83+
#define EXAMPLE_LCD_DSI_LANE_NUM (2) // ESP32-P4 supports 1 or 2 lanes
84+
#define EXAMPLE_LCD_DSI_LANE_RATE_MBPS (1000) /* Single lane bit rate, should consult the LCD supplier or check the
85+
* LCD drive IC datasheet for the supported lane rate.
86+
* ESP32-P4 supports max 1500Mbps
87+
*/
88+
#define EXAMPLE_LCD_DPI_CLK_MHZ (52)
89+
#define EXAMPLE_LCD_DPI_COLOR_BITS (EXAMPLE_LCD_COLOR_BITS)
90+
#define EXAMPLE_LCD_DPI_HPW (10)
91+
#define EXAMPLE_LCD_DPI_HBP (160)
92+
#define EXAMPLE_LCD_DPI_HFP (160)
93+
#define EXAMPLE_LCD_DPI_VPW (1)
94+
#define EXAMPLE_LCD_DPI_VBP (23)
95+
#define EXAMPLE_LCD_DPI_VFP (12)
96+
#define EXAMPLE_LCD_USE_EXTERNAL_CMD (0)
97+
#if EXAMPLE_LCD_USE_EXTERNAL_CMD
98+
/**
99+
* LCD initialization commands.
100+
*
101+
* Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for
102+
* initialization sequence code.
103+
*
104+
* Please uncomment and change the following macro definitions, then use `configVendorCommands()` to pass them in the
105+
* same format if needed. Otherwise, the LCD driver will use the default initialization sequence code.
106+
*
107+
* There are two formats for the sequence code:
108+
* 1. Raw data: {command, (uint8_t []){ data0, data1, ... }, data_size, delay_ms}
109+
* 2. Formatter: ESP_PANEL_LCD_CMD_WITH_8BIT_PARAM(delay_ms, command, { data0, data1, ... }) and
110+
* ESP_PANEL_LCD_CMD_WITH_NONE_PARAM(delay_ms, command)
111+
*/
112+
const esp_lcd_panel_vendor_init_cmd_t lcd_init_cmd[] = {
113+
// {0xFF, (uint8_t []){0x77, 0x01, 0x00, 0x00, 0x10}, 5, 0},
114+
// {0xC0, (uint8_t []){0x3B, 0x00}, 2, 0},
115+
// {0xC1, (uint8_t []){0x0D, 0x02}, 2, 0},
116+
// {0x29, (uint8_t []){0x00}, 0, 120},
117+
// // or
118+
// ESP_PANEL_LCD_CMD_WITH_8BIT_PARAM(0, 0xFF, {0x77, 0x01, 0x00, 0x00, 0x10}),
119+
// ESP_PANEL_LCD_CMD_WITH_8BIT_PARAM(0, 0xC0, {0x3B, 0x00}),
120+
// ESP_PANEL_LCD_CMD_WITH_8BIT_PARAM(0, 0xC1, {0x0D, 0x02}),
121+
// ESP_PANEL_LCD_CMD_WITH_NONE_PARAM(120, 0x29),
122+
};
123+
#endif
124+
125+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126+
//////////////////// Please update the following configuration according to your board spec ////////////////////////////
127+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128+
#define EXAMPLE_LCD_PIN_NUM_RST (27) // Set to -1 if not used
129+
#define EXAMPLE_LCD_PIN_NUM_BK_LIGHT (26) // Set to -1 if not used
130+
#define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL (1)
131+
#define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL
132+
133+
/* Enable or disable pattern test */
134+
#define EXAMPLE_ENABLE_PATTERN_EXAMPLE (1)
135+
/* Enable or disable the attachment of a callback function that is called after each bitmap drawing is completed */
136+
#define EXAMPLE_ENABLE_ATTACH_CALLBACK (1)
137+
/* Enable or disable the attachment of a callback function that is called after each bitmap drawing is completed */
138+
#define EXAMPLE_ENABLE_PRINT_LCD_FPS (1)
139+
140+
#define _EXAMPLE_LCD_CLASS(name, ...) ESP_PanelLcd_##name(__VA_ARGS__)
141+
#define EXAMPLE_LCD_CLASS(name, ...) _EXAMPLE_LCD_CLASS(name, ##__VA_ARGS__)
142+
143+
#if EXAMPLE_ENABLE_ATTACH_CALLBACK
144+
IRAM_ATTR bool onDrawBitmapFinishCallback(void *user_data)
145+
{
146+
esp_rom_printf("Draw bitmap finish callback\n");
147+
148+
return false;
149+
}
150+
#endif
151+
152+
#if EXAMPLE_ENABLE_PRINT_LCD_FPS
153+
#define EXAMPLE_LCD_FPS_COUNT_MAX (100)
154+
155+
DRAM_ATTR int frame_count = 0;
156+
DRAM_ATTR int fps = 0;
157+
DRAM_ATTR long start_time = 0;
158+
159+
IRAM_ATTR bool onVsyncEndCallback(void *user_data)
160+
{
161+
long frame_start_time = *(long *)user_data;
162+
if (frame_start_time == 0) {
163+
(*(long *)user_data) = millis();
164+
165+
return false;
166+
}
167+
168+
frame_count++;
169+
if (frame_count >= EXAMPLE_LCD_FPS_COUNT_MAX) {
170+
fps = EXAMPLE_LCD_FPS_COUNT_MAX * 1000 / (millis() - frame_start_time);
171+
frame_count = 0;
172+
(*(long *)user_data) = millis();
173+
}
174+
175+
return false;
176+
}
177+
#endif
178+
179+
void setup()
180+
{
181+
Serial.begin(115200);
182+
Serial.println("MIPI-DSI LCD example start");
183+
184+
#if EXAMPLE_LCD_PIN_NUM_BK_LIGHT >= 0
185+
Serial.println("Initialize backlight control pin and turn it on");
186+
ESP_PanelBacklight *backlight = new ESP_PanelBacklight(
187+
EXAMPLE_LCD_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL, true
188+
);
189+
backlight->begin();
190+
backlight->on();
191+
#endif
192+
193+
Serial.println("Create MIPI-DSI LCD bus");
194+
ESP_PanelBus_DSI *panel_bus = new ESP_PanelBus_DSI(
195+
EXAMPLE_LCD_DSI_LANE_NUM, EXAMPLE_LCD_DSI_LANE_RATE_MBPS,
196+
EXAMPLE_LCD_DPI_CLK_MHZ, EXAMPLE_LCD_DPI_COLOR_BITS, EXAMPLE_LCD_WIDTH, EXAMPLE_LCD_HEIGHT,
197+
EXAMPLE_LCD_DPI_HPW, EXAMPLE_LCD_DPI_HBP, EXAMPLE_LCD_DPI_HFP,
198+
EXAMPLE_LCD_DPI_VPW, EXAMPLE_LCD_DPI_VBP, EXAMPLE_LCD_DPI_VFP,
199+
EXAMPLE_LCD_DSI_PHY_LDO_ID
200+
);
201+
panel_bus->begin();
202+
203+
Serial.println("Create LCD device");
204+
ESP_PanelLcd *lcd = new EXAMPLE_LCD_CLASS(EXAMPLE_LCD_NAME, panel_bus, EXAMPLE_LCD_COLOR_BITS, EXAMPLE_LCD_PIN_NUM_RST);
205+
#if EXAMPLE_LCD_USE_EXTERNAL_CMD
206+
// Configure external initialization commands, should called before `init()`
207+
lcd->configVendorCommands(lcd_init_cmd, sizeof(lcd_init_cmd)/sizeof(lcd_init_cmd[0]));
208+
#endif
209+
lcd->init();
210+
lcd->reset();
211+
lcd->begin();
212+
lcd->displayOn();
213+
214+
#if EXAMPLE_ENABLE_PATTERN_EXAMPLE
215+
Serial.println("Show MIPI-DSI patterns");
216+
lcd->showDsiPattern(ESP_PanelLcd::DsiPatternType::BAR_HORIZONTAL);
217+
delay(1000);
218+
lcd->showDsiPattern(ESP_PanelLcd::DsiPatternType::BAR_VERTICAL);
219+
delay(1000);
220+
lcd->showDsiPattern(ESP_PanelLcd::DsiPatternType::BER_VERTICAL);
221+
delay(1000);
222+
lcd->showDsiPattern(ESP_PanelLcd::DsiPatternType::NONE);
223+
#endif
224+
#if EXAMPLE_ENABLE_ATTACH_CALLBACK
225+
/* Attach a callback function which will be called when every bitmap drawing is completed */
226+
lcd->attachDrawBitmapFinishCallback(onDrawBitmapFinishCallback, NULL);
227+
#endif
228+
#if EXAMPLE_ENABLE_PRINT_LCD_FPS
229+
/* Attach a callback function which will be called when the Vsync signal is detected */
230+
lcd->attachRefreshFinishCallback(onVsyncEndCallback, (void *)&start_time);
231+
#endif
232+
233+
Serial.println("Draw color bar from top left to bottom right, the order is B - G - R");
234+
/* Users can refer to the implementation within `colorBardTest()` to draw patterns on the LCD */
235+
lcd->colorBarTest(EXAMPLE_LCD_WIDTH, EXAMPLE_LCD_HEIGHT);
236+
237+
Serial.println("MIPI-DSI LCD example end");
238+
}
239+
240+
void loop()
241+
{
242+
delay(1000);
243+
#if EXAMPLE_ENABLE_PRINT_LCD_FPS
244+
Serial.println("MIPI-DSI refresh rate: " + String(fps));
245+
#else
246+
Serial.println("IDLE loop");
247+
#endif
248+
}

examples/LCD/MIPI_DSI/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
| Supported ESP SoCs | ESP32-P4 |
2+
| ------------------ | -------- |
3+
4+
| Supported LCD Controllers | EK79007 |
5+
| ------------------------- | ------- |
6+
7+
# MIPI-DSI LCD Example
8+
9+
The example demonstrates how to develop different model LCDs with MIPI-DSI interface using standalone drivers and test them by displaying color bars.
10+
11+
## How to use
12+
13+
1. [Configure drivers](../../../docs/How_To_Use.md#configuring-drivers) if needed.
14+
2. Modify the macros in the example to match the parameters according to your hardware.
15+
3. Navigate to the `Tools` menu in the Arduino IDE to choose a ESP board and configure its parameters, please refter to [Configuring Supported Development Boards](../../../docs/How_To_Use.md#configuring-supported-development-boards)
16+
4. Verify and upload the example to your ESP board.
17+
18+
## Serial Output
19+
20+
```
21+
...
22+
MIPI-DSI LCD example start
23+
Initialize backlight control pin and turn it on
24+
Create MIPI-DSI LCD bus
25+
Create LCD device
26+
Show MIPI-DSI patterns
27+
Draw color bar from top left to bottom right, the order is B - G - R
28+
Draw bitmap finish callback
29+
Draw bitmap finish callback
30+
Draw bitmap finish callback
31+
Draw bitmap finish callback
32+
Draw bitmap finish callback
33+
Draw bitmap finish callback
34+
Draw bitmap finish callback
35+
Draw bitmap finish callback
36+
Draw bitmap finish callback
37+
Draw bitmap finish callback
38+
Draw bitmap finish callback
39+
Draw bitmap finish callback
40+
Draw bitmap finish callback
41+
Draw bitmap finish callback
42+
Draw bitmap finish callback
43+
Draw bitmap finish callback
44+
Draw bitmap finish callback
45+
Draw bitmap finish callback
46+
Draw bitmap finish callback
47+
Draw bitmap finish callback
48+
Draw bitmap finish callback
49+
Draw bitmap finish callback
50+
Draw bitmap finish callback
51+
Draw bitmap finish callback
52+
MIPI-DSI LCD example end
53+
MIPI-DSI refresh rate: 0
54+
MIPI-DSI refresh rate: 69
55+
MIPI-DSI refresh rate: 69
56+
MIPI-DSI refresh rate: 69
57+
...
58+
```
59+
60+
## Troubleshooting
61+
62+
Please check the [FAQ](../../../docs/FAQ.md) first to see if the same question exists. If not, please create a [Github issue](https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues). We will get back to you as soon as possible.

0 commit comments

Comments
 (0)