espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.48k stars 7.26k forks source link

Can you provide an example of using QSPI interface to drive LCD? (IDFGH-10543) #11787

Closed DoctorTag closed 11 months ago

DoctorTag commented 1 year ago

Is your feature request related to a problem?

Can you provide an example of using QSPI interface to drive LCD?

Describe the solution you'd like.

No response

Describe alternatives you've considered.

No response

Additional context.

No response

andylinpersonal commented 1 year ago

Uh, which LCD panel has a QSPI control interface?

Most LCD panels should have parallel, i2c, (1 or 2-line) SPI, MIPI DSI (out of scope) and / or eDP (out of scope) interface.

DoctorTag commented 1 year ago

For example: the LCD driver IC--GC9B71,please refer to the following,thanks. image

GC9B71 DataSheet V1.0(1).pdf

modi12jin commented 1 year ago

https://github.com/Lzw655/esp32-s3-lcd-ev-baord-docs/issues/3 https://github.com/Lzw655/esp32-s3-lcd-ev-baord-docs/issues/2

Lzw655 commented 1 year ago

@DoctorTag @modi12jin Here is an example for ST77903 QSPI LCD(ST77903_QSPI_1_6_400_400.zip). For more details, please see its README.

The hardware of the LCD Module: image

modi12jin commented 1 year ago

@Lzw655 thank you for your reply. I have successfully driven the SPD2010 screen on the ESP32S3, but the SPD2010 touch has not been driven yet.

IMG_20230717_221804

Lzw655 commented 1 year ago

@modi12jin For SPD2010 Touch, you can refer to the example: SPD2010_SPI_2_2_180_454.zip

modi12jin commented 1 year ago

@Lzw655 I'm having some issues, but I can read touch signals

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x2a (SPI_FAST_FLASH_BOOT)
Saved PC:0x42008255
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x1870
load:0x403c9700,len:0x4
load:0x403c9704,len:0xda4
load:0x403cc700,len:0x3130
entry 0x403c9934
I (27) boot: ESP-IDF v5.1-dirty 2nd stage bootloader
I (27) boot: compile time Jul 20 2023 02:47:50
I (27) boot: Multicore bootloader
I (30) boot: chip revision: v0.1
I (34) qio_mode: Enabling default flash chip QIO
I (39) boot.esp32s3: Boot SPI Speed : 80MHz
I (44) boot.esp32s3: SPI Mode       : QIO
I (49) boot.esp32s3: SPI Flash Size : 8MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (92) boot: End of partition table
I (96) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=0d808h ( 55304) map
I (113) esp_image: segment 1: paddr=0001d830 vaddr=3fc94a00 size=027e8h ( 10216) load
I (116) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=1f134h (127284) map
I (141) esp_image: segment 3: paddr=0003f15c vaddr=3fc971e8 size=00b4ch (  2892) load
I (142) esp_image: segment 4: paddr=0003fcb0 vaddr=40374000 size=109d4h ( 68052) load
I (167) boot: Loaded app from partition at offset 0x10000
I (167) boot: Disabling RNG early entropy source...
I (178) cpu_start: Multicore app
I (179) esp_psram: Found 8MB PSRAM device
I (179) esp_psram: Speed: 80MHz
I (180) cpu_start: Pro cpu up.
I (183) cpu_start: Starting app cpu, entry point is 0x403754ac
I (0) cpu_start: App cpu up.
I (1108) esp_psram: SPI SRAM memory test OK
I (1117) cpu_start: Pro cpu start user code
I (1117) cpu_start: cpu freq: 240000000 Hz
I (1117) cpu_start: Application information:
I (1120) cpu_start: Project name:     ESP32S3-IDF_SPD2010-QSPI-I2C
I (1127) cpu_start: App version:      1
I (1132) cpu_start: Compile time:     Jul 20 2023 02:47:21
I (1138) cpu_start: ELF file SHA256:  3f3893897a81ff8e...
I (1144) cpu_start: ESP-IDF:          v5.1-dirty
I (1149) cpu_start: Min chip rev:     v0.0
I (1154) cpu_start: Max chip rev:     v0.99 
I (1159) cpu_start: Chip rev:         v0.1
I (1164) heap_init: Initializing. RAM available for dynamic allocation:
I (1171) heap_init: At 3FC985F0 len 00051120 (324 KiB): DRAM
I (1177) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (1184) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (1190) heap_init: At 600FE010 len 00001FF0 (7 KiB): RTCRAM
I (1197) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
I (1205) spi_flash: detected chip: gd
I (1209) spi_flash: flash io: qio
I (1213) sleep: Configure to isolate all GPIO pins in sleep state
I (1220) sleep: Enable automatic switching of GPIO sleep configuration
I (1227) app_start: Starting scheduler on CPU0
I (1232) app_start: Starting scheduler on CPU1
I (1232) main_task: Started on CPU0
I (1242) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (1252) main_task: Calling app_main()
I (5252) example: Initialize touch IO (I2C)
I (5252) example: Initialize touch controller SPD2010
I (5252) gpio: GPIO[11]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (5262) lcd_panel_touch_spd2010: Dummy[3435887308], DVer[602], PID[1213416448], Name[1397769216-842019120]
E (5272) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(177): i2c transaction failed
E (5272) lcd_panel_touch_spd2010: Write_TP_CPU_Start_Cmd(271): Tx failed
E (5282) lcd_panel_touch_spd2010: TP_Read_Data(465): Write cpu start cmd failed
E (5292) lcd_panel_touch_spd2010: read_data(157): read data failed
E (5302) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(177): i2c transaction failed
E (5302) lcd_panel_touch_spd2010: Read_TP_Status_Length(303): Tx failed
E (5312) lcd_panel_touch_spd2010: TP_Read_Data(458): Read status length failed
E (5322) lcd_panel_touch_spd2010: read_data(157): read data failed
E (5332) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(177): i2c transaction failed
E (5332) lcd_panel_touch_spd2010: Read_TP_Status_Length(303): Tx failed
E (5342) lcd_panel_touch_spd2010: TP_Read_Data(458): Read status length failed
E (5352) lcd_panel_touch_spd2010: read_data(157): read data failed
E (5352) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(177): i2c transaction failed
E (5362) lcd_panel_touch_spd2010: Read_TP_Status_Length(303): Tx failed
E (5372) lcd_panel_touch_spd2010: TP_Read_Data(458): Read status length failed
E (5382) lcd_panel_touch_spd2010: read_data(157): read data failed
E (5382) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(177): i2c transaction failed
E (5392) lcd_panel_touch_spd2010: Read_TP_Status_Length(303): Tx failed
E (5402) lcd_panel_touch_spd2010: TP_Read_Data(458): Read status length failed
E (5412) lcd_panel_touch_spd2010: read_data(157): read data failed
x:187,y:60
x:189,y:78
x:189,y:81
x:189,y:84
x:189,y:86
x:189,y:90
x:189,y:91
x:189,y:92
x:189,y:93

https://github.com/espressif/esp-idf/assets/40233017/fd8aadd3-f80f-4f93-8c0e-139d9f36d167

Lzw655 commented 1 year ago

I also don't know the reason. But are the coordinates right? If so, you can ignore these few errors.

modi12jin commented 1 year ago

@Lzw655 Sorry to bother, I found the problem. Before the SPD2010 chip reset and touch reset were connected together. Then I divided them and reset them separately, and the error disappeared.

Lzw655 commented 1 year ago

@modi12jin Good job! I just bought two QSPI screens (SPD2010, GC9B71), and I will try to drive them recently.

HongLiangGong1990 commented 1 year ago

@modi12jin Good job! I just bought two QSPI screens (SPD2010, GC9B71), and I will try to drive them recently.

i have test qspi screens(mentioned above) on GC9B71, use this code in https://github.com/DoctorTag/esp32S3_watch .Only when refreshing the arc shape,error pixels will appear,but other shapes are normal. i have test lvgl version between 8.0~8.3, all are the same. in this video, SPD2010 has same error(https://www.bilibili.com/video/BV1Lj41197Je/), then I suspect this is a bug in lvgl,but I don't have any ideas arc-error

Lzw655 commented 1 year ago

@DoctorTag Here is a demo project for GC9B61. Please carefully read the "README.md" and configure ESP-IDF as required.

GC9B71_QSPI_1_89_320_386.zip

Lzw655 commented 1 year ago

@modi12jin Good job! I just bought two QSPI screens (SPD2010, GC9B71), and I will try to drive them recently.

i have test qspi screens(mentioned above) on GC9B71, use this code in https://github.com/DoctorTag/esp32S3_watch .Only when refreshing the arc shape,error pixels will appear,but other shapes are normal. i have test lvgl version between 8.0~8.3, all are the same. in this video, SPD2010 has same error(https://www.bilibili.com/video/BV1Lj41197Je/), then I suspect this is a bug in lvgl,but I don't have any ideas arc-error

Please refer to here.

HongLiangGong1990 commented 1 year ago

Amazing!Code runs perfectly!

HongLiangGong1990 commented 1 year ago

when i test example: lv_demo_widgets, i found a bug. d6449712f4318320101f1ed6dbd8365 i chose red theme, then flashing stripes appear on the screen,other color theme is ok. 8fd758594a5fa299d8392cb9c5fa7f4

HongLiangGong1990 commented 1 year ago

By the way, forgot to add one point. Only when ESP_LCD_IO_QSPI_GC9B71_CONFIG pclk_hz increase to 24M, this bug will appear

Lzw655 commented 1 year ago

@HongLiangGong1990 Me too. I think it's the limits of GC9B71 itself. But I can't find the timing parameters of the QSPI interface in the datasheet. And I tested another QSPI LCD (SH8601). It worked well under 40MHz PCLK.

modi12jin commented 1 year ago

@Lzw655 Thanks for your code, I tested it perfectly in WEA2012

IMG_2023-08-20-18-35-13-917_edit_1153968203418187

void lvgl_port_rounder_callback(struct _lv_disp_drv_t *disp_drv, lv_area_t *area) {
  uint16_t x1 = area->x1;
  uint16_t x2 = area->x2;

  // 将区域的起点向下舍入到最接近的偶数
  area->x1 = x1 > 0 ? (x1 - (x1 % 4)) : 0;

  // 将区域末尾四舍五入到最接近的奇数
  area->x2 = (x2 - (x2 % 4) - 1);
}

...

  disp_drv.flush_cb = my_disp_flush;
  disp_drv.rounder_cb = lvgl_port_rounder_callback;

or write like this

void lvgl_port_rounder_callback(struct _lv_disp_drv_t *disp_drv, lv_area_t *area) {

  area->x1 &= ~0x03;

  area->x2 += 3 - (area->x2 & 0x03);
}

...

  disp_drv.flush_cb = my_disp_flush;
  disp_drv.rounder_cb = lvgl_port_rounder_callback;
Lzw655 commented 1 year ago

@modi12jin Good! For lvgl_port_rounder_callback(), I prefer the following code:

void lvgl_port_rounder_callback(struct _lv_disp_drv_t * disp_drv, lv_area_t * area)
{
    uint16_t x1 = area->x1;
    uint16_t x2 = area->x2;

    // round the start of area down to the nearest 4N number
    area->x1 = (x1 >> 2) << 2;

    // round the end of area up to the nearest 4M+3 number
    area->x2 = ((x2 >> 2) << 2) + 3;
}
modi12jin commented 1 year ago

@Lzw655 I don’t know if it’s right to write it like this, it’s changed from 40M to 80M

.clock_speed_hz = SPI_MASTER_FREQ_80M,

Collage_20230821_105218_edit_1190040542603308

Lzw655 commented 1 year ago

@modi12jin The highest frequency of ESP SPI (or QSPI) is 80Mhz. It's ok to set it from 40M to 80M if the LCD IC allows it (according to its datasheet).

modi12jin commented 1 year ago

@modi12jin The highest frequency of ESP SPI (or QSPI) is 80Mhz. It's ok to set it from 40M to 80M if the LCD IC allows it (according to its datasheet).

2023-08-21_12-06

The manual says 40M, but I set it to 80M and it’s fine

Lzw655 commented 1 year ago

@modi12jin Yes, but during mass production, there might be a few products that experience issues.

Lzw655 commented 1 year ago

@modi12jin @HongLiangGong1990 The QSPI LCD drivers including SPD2010, SH8601, and GC9B71 have been uploaded to the Espressif Registry. There is a common example named qspi_with_ram for them and it can also be downloaded from Espressif Registry.

Windsssss commented 10 months ago

@modi12jin @HongLiangGong1990 The QSPI LCD drivers including SPD2010, SH8601, and GC9B71 have been uploaded to the Espressif Registry. There is a common example named qspi_with_ram for them and it can also be downloaded from Espressif Registry.

@Lzw655 hello,i just bought a spd2010 lcd,and i test the example you upload to Espressif Registry,i found a problem below, the screen lit up for a few seconds and then went out.

https://github.com/espressif/esp-idf/assets/36975516/0e8ece32-9c4d-4320-8da0-1759cce07fb1

Lzw655 commented 10 months ago

Hi @Windsssss, please open a new issue and choose "Runtime bug report" in esp-iot-solution. And it will be very helpful if you attach the detailed logs.

Windsssss commented 10 months ago

Hi @Windsssss, please open a new issue and choose "Runtime bug report" in esp-iot-solution. And it will be very helpful if you attach the detailed logs.

@Lzw655 , https://github.com/espressif/esp-iot-solution/issues/312

Lzw655 commented 10 months ago

Hi @Windsssss, please open a new issue and choose "Runtime bug report" in esp-iot-solution. And it will be very helpful if you attach the detailed logs.

@Lzw655 , espressif/esp-iot-solution#312

Ok, thank you!