Waveshare35a overlay

I used device trees in raspbian to configure the waveshare 4″ display (DEVICE TREES, OVERLAYS, AND PARAMETERS). 

Raspberry Pi’s latest kernels and firmware, including Raspbian and NOOBS releases, now use a Device Tree (DT) to manage some resource allocation and module loading by default

Following that information from the raspberry pi site somehow I created an overlay below (note the frequency may be incorrect).

EDIT: The waveshare overlays have been found here.

/*
 * Device Tree overlay for waveshare 3.5inch TFT LCD
 *
 */

/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__ {
			waveshare35a_pins: waveshare35a_pins {
				brcm,pins = <17 25 24>;
				brcm,function = <0 0 0>; /* in in in */
			};
		};
	};

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

			waveshare35a: waveshare35a@0{
				compatible = "ilitek,ili9486";
				reg = <0>;
				pinctrl-names = "default";
				pinctrl-0 = <&waveshare35a_pins>;

				spi-max-frequency = <16000000>;
				txbuflen = <32768>;
				rotate = <90>;
				bgr = <0>;
				fps = <30>;
				buswidth = <8>;
				regwidth = <16>;
				reset-gpios = <&gpio 25 0>;
				dc-gpios = <&gpio 24 0>;
				debug = <0>;

				init = <0x10000b0 0x00 0x1000011 0x20000ff 0x100003a 0x55 0x1000036 0x28 0x10000c2 0x44 0x10000c5 0x00 0x00 0x00 0x00 0x10000e0 0x0f 0x1f 0x1c 0x0c 0x0f 0x08 0x48 0x98 0x37 0x0a 0x13 0x04 0x11 0x0d 0x00 0x10000e1 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00 0x10000e2 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00 /* piscreen -> waveshare35a */
					0x1000036 0x28
					0x1000011
					0x1000029>;
			};

			waveshare35a_ts: waveshare35a-ts@1 {
				compatible = "ti,ads7846";
				reg = <1>;

				spi-max-frequency = <2000000>;
				interrupts = <17 2>; /* high-to-low edge triggered */
				interrupt-parent = <&gpio>;
				pendown-gpio = <&gpio 17 0>;
				ti,x-plate-ohms = /bits/ 16 <60>;
				ti,pressure-max = /bits/ 16 <255>;
			};
		};
	};
	__overrides__ {
		speed =		<&waveshare35a>,"spi-max-frequency:0";
		txbuflen =	<&waveshare35a>,"txbuflen:0";
		rotate =	<&waveshare35a>,"rotate:0";
		fps =		<&waveshare35a>,"fps:0";
		bgr =		<&waveshare35a>,"bgr:0";
		debug =		<&waveshare35a>,"debug:0";
		swapxy =	<&waveshare35a_ts>,"ti,swap-xy?";
	};
};

The overlay needs to be compiled where .dts is the source and the .dtbo file is the compiled source:

dtc -@ -I dts -O dtb -o waveshare35a-overlay.dtbo waveshare35a-overlay.dts

The -@ surpresses errors to do with references.

With the created overlay object .dtbo that needs to be copied into the boot partition:

sudo cp waveshare35a-overlay.dtbo /boot/overlays/waveshare35a-overlay.dtbo

At the end of /boot/config.txt add the following (omit the dtparam=spi=on if it is already enabled):

dtparam=spi=on
dtoverlay=waveshare35a-overlay

The dtoverlay should match the name of the .dtbo file copied into /boot/overlays.

At the moment the raspberry pi will still use its default frame buffer so the screen will initialise as a blank screen and not display anything although the framebuffer /dev/fb1 for this screen is available. To get the console to use the screen’s framebuffer a change in the boot configuration is required [lallafa.de]. In /boot/cmdline.txt add to the end:

fbcon=map:10

There is an option to use smaller fonts with the option fbcon=font:VGA8x8 but for the 4″ version the regular font is fine.

Finarlly reboot the device and the screen should be up and running.