Jump to content

Connecting banana pi m2 zero with ili9341 display over spi on latest armbian image


yaya8888

Recommended Posts

I tried all weekend to add the touch function of the LCD's XPT2046

 

With this DTS:

Spoiler
/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun8i-h3";
fragment@0 {
	target = <&pio>;
	__overlay__ {
		display_pins: display_pins {
			pins = "PC4", "PA2"; /*reset,dc*/
			function = "gpio_out", "gpio_out";
		};
		ads7846_pins: ads7846_pins {
			pins = "PA19"; /*irq*/
			function = "irq";
		};
		spi0_cs0: spi0_cs0 {
			pins = "PC3";
			function = "gpio_out";
			output-high;
		};
		spi0_cs1: spi0_cs1 {
			pins = "PC7";
			function = "gpio_out";
			output-high;
		};
	};
}; /*closing of fragment@0*/

fragment@1 {
	target = <&spi0>;
	__overlay__ {
		pinctrl-names = "default", "default";
		pinctrl-1 = <&spi0_cs1>;
		cs-gpios = <0>, <&pio 2 7 0>; /* PC7 */
	};
};  /*closing of fragment@1*/

fragment@2 {
	target = <&spi0>;
	__overlay__ {
		/* needed to avoid dtc warning */
		#address-cells = <1>;
		#size-cells = <0>;
		status="okay";
		pinctrl-names = "default", "default"; /*added by ryjelsum*/
		cs-gpios = <&pio 2 3 0>, <&pio 2 7 0>; /* cs0=C3,cs1=C7 */
		#num-chipselects = <2>; /*deleted by ryjelsum*/
		display: display@0 {
			/*compatible = "ilitek,ili9341";*/
			compatible = "adafruit,yx240qv29", "ilitek,ili9341";
			reg = <0>;
			pinctrl-names = "default";
			pinctrl-0 = <&display_pins>;
			pinctrl-1 = <&spi1_cs0>; /*added by ryjelsum*/
			spi-max-frequency = <24000000>;
			status="okay"; /*added by ryjelsum*/
			rotation= <90>;
			bgr = <0>;
			fps = <15>;
			buswidth = <8>;
			height = <320>;
			width = <240>;
			reset-gpios = <&pio 2 4 0>; /* C4,GPIO 24 polarity 0 for adafruit */
			dc-gpios    = <&pio 0 2 0>; /* A2,GPIO 25 */
			debug = <3>;
		};
		ads7846: ads7846@1 { /*this whole block added by ryjelsum*/
			reg = <1>; /* Chip Select 1 */
			compatible = "ti,ads7846";
			spi-max-frequency = <1000000>;
			status = "okay";
			pinctrl-2=<&spi0_cs1 &spi0_cs1>;
			pinctrl-names = "default";
			pinctrl-3 = <&ads7846_pins>;
			interrupt-parent = <&pio>;
			interrupts = <0 19 2>; /* PA19 IRQ_TYPE_EDGE_FALLING */
			pendown-gpio = <&pio 0 19 0>; /* PA19 */
			/* driver defaults, optional */
			ti,x-min = /bits/ 16 <0>;
			ti,y-min = /bits/ 16 <0>;
			ti,x-max = /bits/ 16 <0x0FFF>;
			ti,y-max = /bits/ 16 <0x0FFF>;
			ti,pressure-min = /bits/ 16 <0>;
			ti,pressure-max = /bits/ 16 <0xFFFF>;
			ti,x-plate-ohms = /bits/ 16 <400>;
		};
	};
}; /*closing of fragment@2*/

__overrides__ {
	rotation = <&display>, "rotation:0";
	fps = <&display>, "fps:0";
	debug = <&display>, "debug:0";
}; /* closing of overrides */
};

 

It gets compiled, but the bootloader rejects it:

Applying user provided DT overlay ili9341-touch-sp0.dtbo

failed on fdt_overlay_apply(): FDT_ERR_NOT_FOUND

Error applying DT overlays, restoring original DT

(i included the spi-add-cs1.dtbo as suggested in https://ryjelsum.me/homelab/xpt2046-ili9341-opi-zero/ )

 

 

Link to comment
Share on other sites

Armbian & Khadas are rewarding contributors

Hi robertoj,

 

I can see some lines that look problematic. Firstly you are defining cs-gpio twice.

 

Once here:

5 hours ago, robertoj said:
fragment@1 {
	target = <&spi0>;
	__overlay__ {
		pinctrl-names = "default", "default";
		pinctrl-1 = <&spi0_cs1>;
		cs-gpios = <0>, <&pio 2 7 0>; /* PC7 */
	};

 Note - Remember that 0 refers to the native cs line (PC3)

 

5 hours ago, robertoj said:
fragment@2 {
	target = <&spi0>;
	__overlay__ {
		/* needed to avoid dtc warning */
		#address-cells = <1>;
		#size-cells = <0>;
		status="okay";
		pinctrl-names = "default", "default"; /*added by ryjelsum*/
		cs-gpios = <&pio 2 3 0>, <&pio 2 7 0>; /* cs0=C3,cs1=C7 */

 

Here the pinctrl references are wrong. I am not sure how strictly the ordering matters but for clarity 'pinctrl-names' should be before the actual pin control nodes.

5 hours ago, robertoj said:
pinctrl-2=<&spi0_cs1 &spi0_cs1>;
			pinctrl-names = "default";
			pinctrl-3 = <&ads7846_pins>;

 

Adding spi-add-cs1.dtbo is not needed as all it does it defined the pins to use as cs lines which you have already done above anyway. My other suggestion would be to look into what the latest bindings should for the ads7846 touch controller. Let me know how you get on with following overlay:

 

Spoiler

/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun8i-h3";
fragment@0 {
    target = <&pio>;
    __overlay__ {
        display_pins: display_pins {
            pins = "PC4", "PA2"; /*reset,dc*/
            function = "gpio_out", "gpio_out";
        };
        ads7846_pins: ads7846_pins {
            pins = "PA19"; /*irq*/
            function = "irq";
        };
        spi0_cs0: spi0_cs0 {
            pins = "PC3";
            function = "gpio_out";
            output-high;
        };
        spi0_cs1: spi0_cs1 {
            pins = "PC7";
            function = "gpio_out";
            output-high;
        };
    };
}; /*closing of fragment@0*/

fragment@1 {
    target = <&spi0>;
    __overlay__ {
        /* needed to avoid dtc warning */
        #address-cells = <1>;
        #size-cells = <0>;
        status="okay";
        pinctrl-names = "default", "default"; /*added by ryjelsum*/
        pinctrl-1 = <&spi0_cs1>; /* pinctrl-0 is already declared in the primary dts */
        cs-gpios = <0>, <&pio 2 7 0>; /* cs0=C3,cs1=C7 */
        num-chipselects = <2>;
        display: display@0 {
            /*compatible = "ilitek,ili9341";*/
            compatible = "adafruit,yx240qv29", "ilitek,ili9341";
            reg = <0>;
            pinctrl-names ="default";
            pinctrl-0 = <&display_pins>;
            spi-max-frequency = <24000000>;
            status="okay";
            rotation= <90>;
            bgr = <0>;
            fps = <15>;
            buswidth = <8>;
            height = <320>;
            width = <240>;
            reset-gpios = <&pio 2 4 0>; /* C4,GPIO 24 polarity 0 for adafruit */
            dc-gpios    = <&pio 0 2 0>; /* A2,GPIO 25 */
            debug = <3>;
        };
        ads7846: ads7846@1 {
            reg = <1>; /* Chip Select 1 */
            compatible = "ti,ads7846";
            spi-max-frequency = <1000000>;
            status = "okay";
            pinctrl-names ="default";
            pinctrl-0 = <&ads7846_pins>;
            interrupt-parent = <&pio>;
            interrupts = <0 19 2>; /* PA19 IRQ_TYPE_EDGE_FALLING */
            pendown-gpio = <&pio 0 19 0>; /* PA19 */
            /* driver defaults, optional */
            ti,x-min = /bits/ 16 <0>;
            ti,y-min = /bits/ 16 <0>;
            ti,x-max = /bits/ 16 <0x0FFF>;
            ti,y-max = /bits/ 16 <0x0FFF>;
            ti,pressure-min = /bits/ 16 <0>;
            ti,pressure-max = /bits/ 16 <0xFFFF>;
            ti,x-plate-ohms = /bits/ 16 <400>;
        };
    };
}; /*closing of fragment@2*/

__overrides__ {
    rotation = <&display>, "rotation:0";
    fps = <&display>, "fps:0";
    debug = <&display>, "debug:0";
}; /* closing of overrides */
};

 

best of luck

 

Ryzer

Link to comment
Share on other sites

I went with your corrected DTS ... so far it looks great

Spoiler
roberto@bananapim2zero:~$ lsmod |grep ads
ads7846                20480  0
roberto@bananapim2zero:~$ lsmod |grep spi
roberto@bananapim2zero:~$ sudo cat /proc/interrupts | grep ads
[sudo] password for roberto: 
 59:        574          0          0          0  sunxi_pio_edge  19 Edge      ads7846
roberto@bananapim2zero:~$ dmesg | grep spi
[    7.139676] ads7846 spi0.1: supply vcc not found, using dummy regulator
[    7.140801] ads7846 spi0.1: touchscreen, irq 59
[    7.153779] input: ADS7846 Touchscreen as /devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.1/input/input1
[    7.195022] panel-ilitek-ili9341 spi0.0: get optional vcc failed
[    7.196412] [drm] Initialized ili9341 1.0.0 20210716 for spi0.0 on minor 1
[    7.702554] panel-ilitek-ili9341 spi0.0: [drm] Initialized display serial interface
[    7.762184] panel-ilitek-ili9341 spi0.0: [drm] fb0: ili9341drmfb frame buffer device

 

(Did NOT use the spi-add-cs1.dtbo, as advised)

I went out running to work, and I will continue tests when I go back home

 

Day 2 of testing:

Spoiler
roberto@bananapim2zero:~$ dmesg | grep ads
[    1.702669] ads7846@1 enforce active low on GPIO handle
[    7.139676] ads7846 spi0.1: supply vcc not found, using dummy regulator
[    7.140801] ads7846 spi0.1: touchscreen, irq 59

roberto@bananapim2zero:~$ sudo cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
 gpio-0   (CON2-P13            )
 gpio-1   (CON2-P11            )
 gpio-2   (CON2-P22            |dc                  ) out hi 
 gpio-3   (CON2-P15            )
 gpio-4   (CON3-P03            )
 gpio-5   (CON3-P02            )
 gpio-6   (CON2-P07            )
 gpio-7   (CON2-P29            )
 gpio-8   (CON2-P31            )
 gpio-9   (CON2-P33            )
 gpio-10  (CON2-P35            )
 gpio-11  (CON2-P05            )
 gpio-12  (CON2-P03            )
 gpio-13  (CON2-P08            )
 gpio-14  (CON2-P10            )
 gpio-15  (CON2-P16            )
 gpio-16  (CON2-P12            )
 gpio-17  (CON2-P37            )
 gpio-18  (CON2-P28            )
 gpio-19  (CON2-P27            |pendown             ) in  hi IRQ 
 gpio-20  (CON2-P40            )
 gpio-21  (CON2-P38            )
 gpio-64  (CON2-P19            )
 gpio-65  (CON2-P21            )
 gpio-66  (CON2-P23            )
 gpio-67  (CON2-P24            )
 gpio-68  (CON2-P18            |reset               ) out hi 
 gpio-71  (CON2-P26            |spi0 CS1            ) out hi ACTIVE LOW
 gpio-110 (CSI-PWR-EN          )
 gpio-128 (CN3-P17             )
 gpio-129 (CN3-P13             )
 gpio-130 (CN3-P09             )
 gpio-131 (CN3-P07             )
 gpio-132 (CN3-P19             )
 gpio-133 (CN3-P21             )
 gpio-134 (CN3-P22             )
 gpio-135 (CN3-P20             )
 gpio-136 (CN3-P18             )
 gpio-137 (CN3-P16             )
 gpio-138 (CN3-P14             )
 gpio-139 (CN3-P12             )
 gpio-140 (CN3-P05             )
 gpio-141 (CN3-P03             )
 gpio-142 (CN3-P06             )
 gpio-143 (CN3-P08             )
 gpio-160 (SDC0-D1             )
 gpio-161 (SDC0-D0             )
 gpio-162 (SDC0-CLK            )
 gpio-163 (SDC0-CMD            )
 gpio-164 (SDC0-D3             )
 gpio-165 (SDC0-D2             )
 gpio-166 (SDC0-DET            |cd                  ) in  hi 
 gpio-192 (WL-SDIO-CLK         )
 gpio-193 (WL-SDIO-CMD         )
 gpio-194 (WL-SDIO-D0          )
 gpio-195 (WL-SDIO-D1          )
 gpio-196 (WL-SDIO-D2          )
 gpio-197 (WL-SDIO-D3          )
 gpio-198 (BT-UART-TX          )
 gpio-199 (BT-UART-RX          )
 gpio-200 (BT-UART-RTS         )
 gpio-201 (BT-UART-CTS         )
 gpio-202 (WL-WAKE-AP          )
 gpio-203 (BT-WAKE-AP          |host-wakeup         ) in  lo 
 gpio-204 (BT-RST-N            |shutdown            ) out hi 
 gpio-205 (AP-WAKE-BT          |device-wakeup       ) out hi 

gpiochip1: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
 gpio-353 (CPUX-SET            |vdd-cpux            ) out hi 
 gpio-354 (CON2-P32            )
 gpio-355 (POWER-KEY           |power               ) in  hi IRQ ACTIVE LOW
 gpio-356 (CON2-P36            )
 gpio-357 (VCC-IO-EN           )
 gpio-358 (USB0-ID             |usb0_id_det         ) in  hi IRQ 
 gpio-359 (WL-PWR-EN           |reset               ) out hi ACTIVE LOW
 gpio-360 (PWR-STB             |vcc1v2              ) out hi 
 gpio-361 (PWR-DRAM            |vcc-dram            ) out hi 
 gpio-362 (PWR-LED             |bananapi-m2-zero:red) out lo ACTIVE LOW
 gpio-363 (IR-RX               )

roberto@bananapim2zero:~$ sudo apt install evtest
...done

roberto@bananapim2zero:~$ sudo evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:	gpio-keys
/dev/input/event1:	ADS7846 Touchscreen
Select the device event number [0-1]: 1
Input driver version is 1.0.1
Input device ID: bus 0x1c vendor 0x0 product 0x1ea6 version 0x0
Input device name: "ADS7846 Touchscreen"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 330 (BTN_TOUCH)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value   3303
      Min        0
      Max     4095
    Event code 1 (ABS_Y)
      Value   2584
      Min        0
      Max     4095
    Event code 24 (ABS_PRESSURE)
      Value  62397
      Min        0
      Max    65535
Properties:
Testing ... (interrupt to exit)
Event: time 1726556440.417809, type 3 (EV_ABS), code 0 (ABS_X), value 3294
Event: time 1726556440.417809, type 3 (EV_ABS), code 1 (ABS_Y), value 2585
Event: time 1726556440.417809, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 64811
Event: time 1726556440.417809, -------------- SYN_REPORT ------------
Event: time 1726556440.477739, type 3 (EV_ABS), code 0 (ABS_X), value 3303
Event: time 1726556440.477739, type 3 (EV_ABS), code 1 (ABS_Y), value 2584
Event: time 1726556440.477739, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 63498
...

 

 

evtest shows a random stream of events, then stops... then lcd touches dont get reactions.

 

I will check my wiring and order a new LCD, because mine has a cracked glass

 

Is there any way to tell that the SPI, IRQ, CS inputs/outputs to the XPT2046 (ADS 7846) is working correctly, and blame everything on a bad resistive panel?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines