|
| 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 | +} |
0 commit comments