darrenliew96
Posts: 16
Joined: Mon Dec 30, 2013 1:46 am

Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 3:01 am

Anyone who used SPI display might familiar that starting from kernel 5.4, fbtft_device is obsolete and may require bit porting to DTO (Device Tree Overlay) method.

this included the gamepi20 which uses ST7789v, as upgrading to the latest retropie kernel which is on kernel 5.4 may break the standard
/etc/modprobe.d/fbtft.conf
method.
so by using, https://www.waveshare.com/wiki/GamePi20 method from their English Wiki , there will be no display as the
/dev/fb1
will not be loaded.

I think gamepi20 2 inch LCD module is somewhat similar to this Waveshare 2 inch SPI ST7789 Module https://www.waveshare.com/wiki/2inch_LCD_Module

So a standard Device Tree Overlay is needed to access the SPI display interface via kernel.
However i have issue with troubleshooting porting the code by myself.


with this Device Tress Source code, i am able to get a distorted white display, but nowhere near usable as is it distorted.

Image

This was the code i rewritten. I commented out
cs-gpios = <&gpio 8 0>;
as this will not boot the driver.


Device Tree Overlay Source Code

Code: Select all

/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

        fragment@0 {
                target = <&spi0>;
                __overlay__ {
                        status = "okay";

                        spidev@0{
                                status = "disabled";
                        };

                        spidev@1{
                                status = "disabled";
                        };
                };
        };

        fragment@1 {
                target = <&gpio>;
                __overlay__ {
                        gamepi20_pins: gamepi20 {
                                brcm,pins = <25 27 >;
                                brcm,function = <1 1>; /* out */
                                brcm,pull = <0>; /* none */
                        };
                };
        };

        fragment@2 {
                target = <&spi0>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;

                        gamepi20: gamepi20@0{
                		compatible = "sitronix,st7789v";
                                reg = <0>;
                                pinctrl-names = "default";
                                pinctrl-0 = <&gamepi20_pins>;
                                
								spi-max-frequency = <96000000>;
                                
								rotate = <0>;
                               					width = <320>;
                               					height = <240>;
								fps = <60>;
                               					 buswidth = <8>;
								/*spi-cpol;
                               					 spi-cpha;*/
								custom = <1>;
								bgr = <0>;
								
                                				reset-gpios = <&gpio 27 1>;
								dc-gpios = <&gpio 25 0>;
                               					 led-gpios = <&gpio 24 0>;
								/*cs-gpios = <&gpio 8 0>;*/
								
                                				debug = <0>;
					
								init = <0x1000011
										0x20000ff
										0x1000036 0xA0
										0x100003a 0x05
										0x1000021 
										0x100002a 0x00 0x01 0x00 0x3f
										0x100002b 0x00 0x00 0x00 0xef
										0x10000b2 0x0c 0x0c 0x00 0x33 0x33
										0x10000b7 0x35
										0x10000bb 0x1f
										0x10000c0 0x2c
										0x10000c2 0x01
										0x10000c3 0x12
										0x10000c4 0x20
										0x10000c6 0x0f
										0x10000d0 0xa4 0xa1
										0x10000e0 0xd0 0x08 0x11 0x08 0x0C 0x15 0x39 0x33 0x50 0x36 0x13 0x14 0x29 0x2d
										0x10000e1 0xd0 0x08 0x10 0x08 0x06 0x06 0x39 0x44 0x51 0x0b 0x16 0x14 0x2f 0x31
										0x1000029>;
                        };
                };
        };


        __overrides__ {
                speed =   <&gamepi20>,"spi-max-frequency:0";
                rotate =  <&gamepi20>,"rotate:0";
                width =   <&gamepi20>,"width:0";
                height =  <&gamepi20>,"height:0";
                fps =     <&gamepi20>,"fps:0";
                debug =   <&gamepi20>,"debug:0";
        };
};
compile with this command

Code: Select all

dtc -@ -I dts -O dtb -o gamepi20.dtbo gamepi20.dts
copy to /boot/overlays

Code: Select all

sudo cp gamepi20.dtbo /boot/overlays/
append the /boot/config.txt file by adding the following code below

Code: Select all

dtoverlay=gamepi20
the init section in the DTS is derived from this old code used to boot the lcd

Code: Select all

options fbtft_device name=flexfb gpios=reset:27,dc:25,cs:8,led:24 speed=96000000 bgr=1 fps=60 custom=1 height=240 width=320
options flexfb setaddrwin=0 width=320 height=240 init=-1,0x11,-2,120,-1,0x36,0xA0,-1,0x3A,0x05,-1,0x21,-1,0x2A,0x00,0x01,0x00,0x3F,-1,0x2B,0x00,0x00,0x00,0xEF,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1F,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x12,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0xE0,0xD0,0x08,0x11,0x08,0x0C,0x15,0x39,0x33,0x50,0x36,0x13,0x14,0x29,0x2D,-1,0xE1,0xD0,0x08,0x10,0x08,0x06,0x06,0x39,0x44,0x51,0x0B,0x16,0x14,0x2F,0x31,-1,0x29,-3


more additional gpio pinout of gamepi20 can be found at their Waveshare Chinese Wiki which is https://www.waveshare.net/wiki/GamePi20


and i tried comparing the gpio pins of the lcd to the code. enable each one one by one.
Image


SOLVED: viewtopic.php?p=1826410#p1826410
Last edited by darrenliew96 on Thu Feb 25, 2021 6:03 am, edited 1 time in total.

DarkElvenAngel
Posts: 2952
Joined: Tue Mar 20, 2018 9:53 pm

Re: [Help] Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 3:32 am

I don't know if this will work for you but have a look here viewtopic.php?f=28&t=281931&hilit=Spi

darrenliew96
Posts: 16
Joined: Mon Dec 30, 2013 1:46 am

Re: [Help] Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 3:43 am

DarkElvenAngel wrote:
Thu Feb 25, 2021 3:32 am
I don't know if this will work for you but have a look here viewtopic.php?f=28&t=281931&hilit=Spi
are you using this st7789v overlay that comes with the adafruit raspberry pi installer ?


https://github.com/adafruit/Raspberry-P ... verlay.dts

DarkElvenAngel
Posts: 2952
Joined: Tue Mar 20, 2018 9:53 pm

Re: [Help] Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 5:26 am

Yes but I had to modify it this was a while ago but I just needed to add one pin assignment to the overlay. That's why it doesn't work. I'm not sure if they have updated the overlay since I tried it but it worked.

I can look and see if I still have it setup but I don't have that handy.

Edit:
I reread my thread and the missing pin was the reset line. Looks like GPIO 27

darrenliew96
Posts: 16
Joined: Mon Dec 30, 2013 1:46 am

Re: [Help] Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 6:02 am

ok i have solved the issue, now its working perfectly normal.

Image

it seems like I mistaken for the height and width section, so it became distorted.

So i have written an created a repo of Device Tree Overlay Source in github so anyone can use the updated drivers.

https://github.com/darrenliew96/gamepi20_drivers

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 16115
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 11:35 am

https://github.com/raspberrypi/firmware/issues/1524 is a similar st7789v display.

If you have a working dtoverlay then please submit it (and a matching README entry) as a pull request into the Pi kernel (https://github.com/rasperrypi/linux)
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

DarkElvenAngel
Posts: 2952
Joined: Tue Mar 20, 2018 9:53 pm

Re: Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Thu Feb 25, 2021 8:16 pm

Great you got it working did you check if it works on 5.10 kernel? That seems to be the most up-to-date kernel we have. I haven't tried my display yet with it.

darrenliew96
Posts: 16
Joined: Mon Dec 30, 2013 1:46 am

Re: Waveshare 2.0 inch LCD ST7789V SPI drivers for kernel 5.4

Fri Feb 26, 2021 5:25 am

Yes this is the latest up to date kernel on retropie. 5.7.11 if im not mistaken.

This dto is for GamePi20 as others might have different initcode

Return to “Graphics, sound and multimedia”