# ESP LCD JD9366
[](https://components.espressif.com/components/espressif/esp_lcd_jd9366)
[中文文档](README_CN.md)
Implementation of the JD9366 LCD controller with the ESP-IDF `esp_lcd` component.
## Supported Hardware
This driver is developed and tested for the **Yuying Optoelectronics 10.1-inch MIPI incell touch panel**:
| Item | Value |
| :--- | :--- |
| Manufacturer | Yuying Optoelectronics |
| Size | 10.1 inch |
| Resolution | 800 × 1280 |
| Interface | MIPI-DSI (2-lane) |
| Touch | In-cell (JD9366 I2C touch, see `esp_lcd_touch_jd9366`) |
| LCD Controller | JD9366 |
| Product Link | [Taobao](https://item.taobao.com/item.htm?id=1057448450181) |
| LCD controller | Communication interface | Component name | Link to datasheet |
| :------------: | :---------------------: | :------------: | :---------------: |
| JD9366 | MIPI-DSI | esp_lcd_jd9366 | Vendor init sequence in `docs/` |
**Note**: MIPI-DSI interface only supports ESP-IDF v5.3 and above on ESP32-P4.
For more information on LCD, please refer to the [LCD documentation](https://docs.espressif.com/projects/esp-iot-solution/en/latest/display/lcd/index.html).
## Add to project
Packages from this repository can be uploaded to [Espressif's component service](https://components.espressif.com/).
You can add them to your project via `idf.py add-dependency`, e.g.
```bash
idf.py add-dependency "kevincoooool/esp_lcd_jd9366^1.0.1"
```
Alternatively, you can create `idf_component.yml`. More details are in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html).
## Example use
```c
ESP_LOGI(TAG, "MIPI DSI PHY Powered on");
esp_ldo_channel_handle_t ldo_mipi_phy = NULL;
esp_ldo_channel_config_t ldo_mipi_phy_config = {
.chan_id = 3,
.voltage_mv = 2500,
};
ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy));
ESP_LOGI(TAG, "Initialize MIPI DSI bus");
esp_lcd_dsi_bus_handle_t mipi_dsi_bus = NULL;
esp_lcd_dsi_bus_config_t bus_config = JD9366_PANEL_BUS_DSI_2CH_CONFIG();
ESP_ERROR_CHECK(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus));
ESP_LOGI(TAG, "Install panel IO");
esp_lcd_panel_io_handle_t mipi_dbi_io = NULL;
esp_lcd_dbi_io_config_t dbi_config = JD9366_PANEL_IO_DBI_CONFIG();
ESP_ERROR_CHECK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &mipi_dbi_io));
ESP_LOGI(TAG, "Install JD9366 panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
const esp_lcd_dpi_panel_config_t dpi_config = JD9366_800_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_FORMAT_RGB565);
#else
const esp_lcd_dpi_panel_config_t dpi_config = JD9366_800_1280_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);
#endif
jd9366_vendor_config_t vendor_config = {
.mipi_config = {
.dsi_bus = mipi_dsi_bus,
.dpi_config = &dpi_config,
},
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = EXAMPLE_LCD_IO_RST,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
.bits_per_pixel = 16,
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_jd9366(mipi_dbi_io, &panel_config, &panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
ESP_ERROR_CHECK(esp_lcd_dpi_panel_enable_dma2d(panel_handle, true));
#endif
```
## ESP-IDF v6 Compatibility
- Use `JD9366_800_1280_PANEL_60HZ_DPI_CONFIG()` with `lcd_color_format_t` on ESP-IDF v6.x.
- Use `JD9366_800_1280_PANEL_60HZ_DPI_CONFIG()` with `lcd_color_rgb_pixel_format_t` on ESP-IDF v5.x.
- On ESP-IDF v6.x, call `esp_lcd_dpi_panel_enable_dma2d()` after panel creation if DMA2D is required.
- Set `phy_clk_src = 0` in bus config to let ESP-IDF choose the correct PHY clock source for your chip revision.
idf.py add-dependency "kevincoooool/esp_lcd_jd9366^1.0.1"