notro / panel-mipi-dbi

13 stars 1 forks source link

Can mipi-dbi-spi work with ili9488? #2

Open hardl0ck opened 2 years ago

hardl0ck commented 2 years ago

I tried to run 3.5 inch LCD with driver ili9488 in 4-line SPI mode on fbtft overlay, but this driver (ili9488) does not support RGB565 mode in 4 line SPI. If driver init with RGB666, then i`m take wrong pictrure on the screen... image

Can you explain to the newbie how to run this display (9488) using mipi-dbi-spi?

PS: Raspberry 3b, 5.15.36-v7+

hardl0ck commented 2 years ago

OK, a little about what I did in 4 days

pi@raspberry3b:~ $ mkdir mipi
pi@raspberry3b:~ $ cd mipi
pi@raspberry3b:~/mipi $ wget https://raw.githubusercontent.com/notro/panel-mipi-dbi/main/mipi-dbi-cmd
pi@raspberry3b:~/mipi $ chmod +x mipi-dbi-cmd
pi@raspberry3b:~/mipi $ nano mkstft35.txt

insert into mkstft35.txt config file:

command 0xE0 0x00 0x03 0x09 0x08 0x16 0x0A 0x3F 0x78 0x4C 0x09 0x0A 0x08 0x16 0x1A 0x0F #Positive Gamma Control
command 0xE1 0x00 0x16 0x19 0x03 0x0F 0x05 0x32 0x45 0x46 0x04 0x0E 0x0D 0x35 0x37 0x0F #Negative Gamma Control
command 0xC0 0x17 0x15          #Power Control 1
command 0xC1 0x41           #Power Control 2
command 0xC5 0x00 0x12 0x80     #VCOM Control 1
command 0x36 0xE8           #Memory Access Control # BGR (0x0x = portrait 0° mirror, 0x8x = portrait 180°, 0x2x = landscape 90°, 0x4x = portrait 0°)
command 0x3A 0x66           #INTERFACE_PIXEL_FORMAT #0x66 - 18 bit colour for SPI, 0x55 16 bit colour for parallel
command 0xB0 0x80           #Interface Mode Control 219 page. 0x80 - SDO (MOSI) pin not used.
command 0xB1 0xA0           #Frame Rate Control
command 0xB4 0x02           #Display Inversion Control
command 0xB6 0x02 0x02 0x3B     #Display Function Control
command 0xB7 0x86           # Entry Mode Set p.233
command 0xE9 0x00           #Set Image Function
command 0xF7 0xA9 0x51 0x2C 0x82    #Adjust Control 3
command 0x11                #Sleep out
delay 150               #delay 150
command 0x29                #Display On
delay 20                #delay 20

than...

pi@raspberry3b:~/mipi $ python3 mipi-dbi-cmd panel.bin mkstft35.txt
pi@raspberry3b:~/mipi $ sudo cp panel.bin /lib/firmware
pi@raspberry3b:~/mipi $ cd ..
pi@raspberry3b:~ $
pi@raspberry3b:~ $ sudo nano /boot/config.txt

uncomment: dtparam=spi=on

add in the end of file:

dtoverlay=mipi-dbi-spi,spi0-0,speed=40000000
dtparam=width=480,height=320,width-mm=35,height-mm=28
dtparam=reset-gpio=25,dc-gpio=24
dtparam=write-only

and pi@raspberry3b:~ $ sudo reboot

after reboot:

pi@raspberry3b:~ $ dmesg
----
[   11.044055] vc4-drm soc:gpu: bound 3f902000.hdmi (ops vc4_hdmi_ops [vc4])
[   11.044725] vc4-drm soc:gpu: bound 3f004000.txp (ops vc4_txp_ops [vc4])
[   11.045196] vc4-drm soc:gpu: bound 3f206000.pixelvalve (ops vc4_crtc_ops [vc4])
[   11.045684] vc4-drm soc:gpu: bound 3f207000.pixelvalve (ops vc4_crtc_ops [vc4])
[   11.046137] vc4-drm soc:gpu: bound 3f807000.pixelvalve (ops vc4_crtc_ops [vc4])
[   11.046510] vc4-drm soc:gpu: bound 3fc00000.v3d (ops vc4_v3d_ops [vc4])
[   11.055520] [drm] Initialized vc4 0.0.0 20140616 for soc:gpu on minor 0
[   11.056186] vc4-drm soc:gpu: [drm] Cannot find any crtc or sizes
[   11.536998] panel-mipi-dbi-spi spi0.0: supply power not found, using dummy regulator
[   11.545131] [drm] Initialized panel-mipi-dbi 1.0.0 20220103 for spi0.0 on minor 1
[   11.549774] Console: switching to colour frame buffer device 60x40
[   11.549848] panel-mipi-dbi-spi spi0.0: [drm] fb0: panel-mipi-dbid frame buffer device
-----

On the screen this picture. photo_2022-05-03_22-38-21

How to get the correct data format (RGB666)?

notro commented 2 years ago

How to get the correct data format (RGB666)?

The driver does only support RGB565 as does fbtft.

hardl0ck commented 2 years ago

The driver does only support RGB565 as does fbtft. can the diver work with the ili9488 LCD in parallel mode?

notro commented 2 years ago

No the DRM driver doesn't support that. The fbtft driver supports that but it is worse than SPI with DMA because it bitbangs the bus.

hardl0ck commented 2 years ago

Thanks for your reply. Maybe you know the solution for this LCD? I could not find anything intelligible, except for the need to recompile the kernel, which is very difficult for me....

notro commented 2 years ago

Maybe you know the solution for this LCD?

Sorry no, the documentation looks horrible as is often the case with these chinese displays. But on the positive side they do publish schematics and firmware sourcecode.

It looks like the display has a USB 2.0 OTG connector, maybe you can persuade them to write firmware that implements the GUD USB display protocol: https://github.com/notro/gud/wiki/GUD-Protocol That would make the display plug and play.

hardl0ck commented 2 years ago

Perhaps we are talking about different LCDs. ili9488 is very similar to ili9486. The registers are slightly different, but this is not a problem. Datasheet below There is no USB in this LCD: ILI9488 Data Sheet.pdf

notro commented 2 years ago

Indeed we do, Robin was missing from the one I looked at. Do you have a link I can look at?

hardl0ck commented 2 years ago

Sorry, but I did not find a datasheet for this LCD (marking CL35BC106-40A). This screen (MKS Robin TFT35 v1.0) is installed on many 3D printers with the mainmoard MKS Robin nano v1.1 - v1.2. It is very similar for MKS TS35 (https://github.com/makerbase-mks/MKS-TFT-Hardware/tree/master/MKS%20TS35/MKS%20TS35%20V2.0_002). But MKS TS35 have a LCD with ST7796 driver. There is only a pinout and a wiring diagram of pcb. I just made a few jumpers on the factory board to get the correct 4-wire SPI connection.
As a result of trial and error, I found out that the controller in this LCD is lintek. ili9488 (datasheet in my previous message). 3-5-40PIN-SPI-TFT pinout IMG_20220420_154516 sch_mks_ts35_raspberry

notro commented 2 years ago

Where did you find the initialization commands?

hardl0ck commented 2 years ago

Where did you find the initialization commands?

https://github.com/notro/fbtft/issues/490

notro commented 2 years ago

Ok, a controller has certain configuration commands but it's the display panel that decides what the parameters should be. In other words: two displays with an ILI9488 controller can have two different controller configurations. You need to find a library or some code that works with your display and use those configuration commands. Is there any open source code for the MKS Robin nano you can look at?

hardl0ck commented 2 years ago

Marlin 2.0 (https://github.com/MarlinFirmware/Marlin) has support for this mainboards and this LCD. When assembling sources for my configuration, ili9488 driver is used. Conditionals_LCD.h

#elif ENABLED(MKS_ROBIN_TFT35)      // ILI9488
  #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
  #define TFT_RES_480x320
  #define TFT_INTERFACE_FSMC
hardl0ck commented 2 years ago

But I forgot to add. Robin nano 1.2 uses a parallel interface to TFT35 ...

notro commented 2 years ago

I don't think the interface matters for the commands since the interface is set using the IMx pins. This looks promising: https://github.com/MarlinFirmware/Marlin/blob/2.0.x/Marlin/src/lcd/tft_io/ili9488.h#L149-L164

hwmland commented 1 year ago

I'm afraid (based on what I saw on some pages ILI9488 does not support RGB565 while in SPI mode. It has to be RGB666. My tests confirm this. When trying to use SPI+RGB565, display does not initialize properly. With RGB666 it initializes, but I see garbage of couse (like in 1st post)

namezys commented 7 months ago

Hey. I have BigTreeTech tft35 spi v2.1 (https://github.com/bigtreetech/TFT35-SPI/tree/master/v2)

Driver IC for SPI Display: ILI9488

As I can see, there is no chance to use it? maybe something more clear rn?

notro commented 7 months ago

I have BigTreeTech tft35 spi v2.1 (https://github.com/bigtreetech/TFT35-SPI/tree/master/v2)

The readme in that repo shows that you can use the fbtft overlay in Raspberry Pi OS with the ili9486 option.

fbtft does only support rgb565 so it looks like it should work. You can get the init sequence from drivers/staging/fbtft/fb_ili9486.c. You have to calculate the value for the 0x36 command based on the logic in the set_var() function.

If I didn't mess up, this should be an equivalent command file:

# Interface Mode Control
command 0xb0 0x0
command 0x11
delay 250

# Interface Pixel Format
command 0x3A 0x55

# Power Control 3
command 0xC2 0x44

# VCOM Control 1
command 0xC5 0x00 0x00 0x00 0x00

# PGAMCTRL(Positive Gamma Control)
command 0xE0 0x0F 0x1F 0x1C 0x0C 0x0F 0x08 0x48 0x98 0x37 0x0A 0x13 0x04 0x11 0x0D 0x00

# NGAMCTRL(Negative Gamma Control)
command 0xE1 0x0F 0x32 0x2E 0x0B 0x0D 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00

# Digital Gamma Control 1
command 0xE2 0x0F 0x32 0x2E 0x0B 0x0D 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00

command 0x36 0x28

command 0x11
command 0x29

The fbtft driver has native 320x480 size which is rotated=90 in the DT overlay option, panel-mipi-dbi doesn't rotate so you have to flip width/height yourself.

namezys commented 7 months ago

I'm curious because for their board that designed to connect this display they use

    tft_35: st7789v@1 {
        status = "disabled";
        compatible = "sitronix,st7796";
        reg = <1>;
        spi-max-frequency =<12500000>;
        fps =<60>;
        buswidth = <8>;
        rotate =<0>;
        width = <480>;
        height = <320>;
        bpp = <24>;
        bgr;
        regwidth = <8>;
        debug = <0x00>;  //0x20 show fps
        txbuflen = <307200>;
        spi-cpol;
        spi-cpha;
    };

it does not look like ILI9488

BTW I will try.

notro commented 7 months ago

compatible = "sitronix,st7796";

This seems to be a driver in their custom kernel: https://github.com/bigtreetech/CB1-Kernel/blob/kernel-5.16/kernel/drivers/staging/fbtft/fb_st7796.c

  bpp = <24>;

This is curious, it's been years since I worked on fbtft, I thought it only did rgb565 on these displays but this indicates rgb666 or rgb888.

But what I find strange is that the driver does this: write_reg(par, 0x3a, 0x55); // Interface Mode Control That's the COLMOD command setting rgb565 on both interfaces.

Probably best to ask the seller about this.

namezys commented 7 months ago

Thank you. It's very helpful information. I see that I have to build custom kernel (I did it last time as child in 14-15) I suppose it's useless but I would ask.

Any way, it looks like that it can be supported by this DRM module, doesn't it?

notro commented 7 months ago

bpp = <24>;

I came across this [PATCH] Allows setting bpp from dt which didn't make it into mainline, and the CB-1 kernel doesn't have this patch either. This indicates that this bpp option is mute.

Any way, it looks like that it can be supported by this DRM module, doesn't it?

Yes

namezys commented 7 months ago

Maybe you can give guideline what to do? I'm worry that I will spend too much time to understand it by myself :(

notro commented 7 months ago

I've enabled discussions now so please create a new discussion and link to this issue so we don't clutter it further. Put the display name in the title.

Add info about the board you have.

notro commented 6 months ago

I have now had a closer look at the ILI9488 datasheet:

4.7. Display Data Format
    4.7.1. DBI Type C Option 1 (3-Line Serial Interface)
        The available display data formats are:
            - 8 colors, RGB 1, 1, 1 bits input (set Standard Command 3Ah, DBI [2:0] as 001)
            - 262K-Colors, RGB 6, 6, 6 bits input data (set Standard Command 3Ah, DBI [2:0] as 110)

    4.7.2. DBI Type-C Option 3 (4-Line Serial Interface)
        The available display data formats are:
            - 8 colors, RGB 1, 1, 1 bits input (set Standard Command 3Ah, DBI [2:0] as 001)
            - 65K-Colors, RGB 5, 6, 5 bits input data (set Standard Command 3Ah, DBI [2:0] as 101)
            - 262K-Colors, RGB 6, 6, 6 bits input data (set Standard Command 3Ah, DBI [2:0] as 110)

4-Line Serial Interface is SPI + D/C gpio, so it should be possible to use panel-mipi-dbi with this interface mode.

command 0x3a 0x55
notro commented 6 months ago

Just to cover the parallel bus options:

4.7.3. 8-bit Parallel MCU Interface 
The available display data formats are:
    - 65K-Colors, RGB 5, 6, 5 bits input data (set Standard Command 3Ah, DBI [2:0] as 101)
    - 262K-Colors, RGB 6, 6, 6 bits input data (set Standard Command 3Ah, DBI [2:0] as 110)

4.7.5. 16-bit Parallel MCU Interface
The available display data formats are:
    - 65K-Colors, RGB 5, 6, 5 bits input data (set Standard Command 3Ah, DBI [2:0] as 101)
    - 262K-Colors, RGB 6, 6, 6 bits input data (set Standard Command 3Ah, DBI [2:0] as 110)

It should be possible to use fbtft for this use case.

This comprehensive blog post: Cheap ILI9488 TFT LCD Displays, points to Cheap 3.95 TFT Screen with ili9488 from mcufriend on a Raspberry Pi Zero:

options fbtft_device name=flexpfb rotate=180 fps=60 gpios=dc:18,reset:7,wr:17,cs:4,db00:22,db01:23,db02:24,db03:10,db04:25,db05:9,db06:11,db07:8
options flexfb width=480 height=320 buswidth=8 init=-1,0xb0,0x0,-1,0x11,-2,120,-1,0x3A,0x55,-1,0xC2,0x33,-1,0xC5,0x00,0x1E,0x80,-1,0x36,0x28,-1,0xB1,0xB0,-1,0xE0,0x00,0x04,0x0E,0x08,0x17,0x0A,0x40,0x79,0x4D,0x07,0x0E,0x0A,0x1A,0x1D,0x0F,-1,0xE1,0x00,0x1B,0x1F,0x02,0x10,0x05,0x32,0x34,0x43,0x02,0x0A,0x09,0x33,0x37,0x0F,-1,0x11,-1,0x29,-3

fbtft_device and flexfp doesn't exist in the kernel any more, but it should be possible to make it work. See here for info on how to do that on a Raspberry Pi: https://github.com/notro/fbtft/wiki/FBTFT-RPI-overlays

I still haven't seen someone posting a working Devie Tree fragment for a parallel bus display, so it can't be a common setup.

notro commented 6 months ago

Sigh, I came across this from a guy that maintains a graphics library (ref):

The ILI9488 data sheet is in error (based on my empirical testing). The 16 bit mode does not work with SPI.

notro commented 5 months ago

I've sent some patches to add RGB666 support: https://lore.kernel.org/dri-devel/20240507-panel-mipi-dbi-rgb666-v1-0-6799234afa3e@tronnes.org/T/#t

notro commented 4 months ago

Linux v6.11 will have RGB666 support: https://github.com/notro/panel-mipi-dbi/wiki#rgb666