Posts Tagged ‘pitft’

Getting the Adafruit PiTFT 2.8″ with capacitive touchscreen working on Hummingboard i2ex

Monday, August 17th, 2015

To get the PiTFT 2.8″ with capacitive touch up and running on the Hummingboard i2ex, a few steps are needed. I am using the Debian Wheezy image from Igor Pecovnik (http://www.igorpecovnik.com/2014/08/19/cubox-i-hummingboard-debian-sd-image/) as it includes fbtft support and everything else (almost).

Igor already explains 49% of the setup to get the unit working, as he has a small guide to setup a 2.2″ Adafruit screen on the Hummingboard. However the 2.8″ version I have, comes assembled with a pin row to fit directly on the Raspberry Pi pin header, so to fit it onto the pin header of the Hummingboard we need to tweak the IO’s used to get some picture up.

Igor writes some info here http://www.igorpecovnik.com/2014/08/19/cubox-i-hummingboard-debian-sd-image/#display which we can (almost) use out of the box. Difference is that the 2.8″ has no RESET pin (and the LED which I guess is backlight is not connected by default, I’ll look into that later) and the DC pin is on another pin. To get it working we change the line to this:

fbtft_device name=adafruit22a rotate=90 speed=48000000 fps=50 gpios=dc:67 busnum=1

And insert it into /etc/modules. It will now be seen as /dev/fb2 and can be used with utilities like fbi. To get a console up, edit /boot/boot.cmd and use the fbcon=map:<0123> thing . I just appended “fbcon=map:2” to the kernel command line, after setting up tty3 in /etc/inittab. I need to look into this again, as I think its not needed. After editing boot.cmd, it needs to be compiled to boot.scr with mkimage:

mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr

Reboot, and voila, you *should* have a console.

OK, that was the easy part. The next thing is the touchscreen. I am no device tree guru, so this was kinda trial and error for me, but also a good intro to device tree files 🙂 The thing is that:

1. There is no driver for the touchscreen in the distro…
2. The touchscreen uses a gpio input for interrupt…

So first thing is getting a driver. Adafruit has their own kernel for the Raspberry Pi that works with this touchscreen, so my idea was that there must be a driver in this kernel, therefore off to the internet to find it.

https://github.com/adafruit/adafruit-raspberrypi-linux/blob/rpi-3.18.y/drivers/input/touchscreen/ft6x06_ts.c
https://github.com/adafruit/adafruit-raspberrypi-linux/blob/rpi-3.18.y/include/linux/input/ft6x06_ts.h

Is the driver that Adafruit uses. Note that I link to the kernel 3.18 versions. First I tried to use the 3.10 versions, however that did not deal with device tree, which I spent some time on, before realizing. Anyways, download these two files onto the Hummingboard. We need to edit ft6x06_ts.c a bit but that is just to fix the ft6x06_ts.h include  (meaning changing the line to just #include “ft6x06_ts.h”) and remove the “#include <mach/irqs.h>” line, as that file is not present AFAIK. To compile, I used the standard kernel module makefile:

obj-m += ft6x06_ts.o
all:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

So put that into a Makefile along with the ft6x06_ts.h and ft6x06_ts.c and run “make”. It takes 5 seconds and we’re good. Put the built driver “ft6x06_ts.ko” into the appropriate kernel
module directory (at the time of writing that is “/lib/modules/3.14.14-cubox-i/kernel/drivers/input/touchscreen/” in my opinion) and run “depmod”.

Now, enter “ft6x06_ts” into /etc/modules also. Next step is fixing the device tree to make the driver be probed also, and add the appropriate gpio irq. Adafruit has an device tree overlay that deals with the display, however I have no clue how to use overlays in the debian distro, so instead I’m gonna put it directly into the dts file, and create a new dtb for the board.

The Debian distro has all the dtb files for supported boards inside /boot/dtb/. The Hummingboard i2ex uses “imx6q-hummingboard.dtb”, however dtb files are the compiled binary versions, which we need to convert to something human readable that we can edit. To do this, we need the device tree compiler, dtc, which we can get by installing “device-tree-compiler” via apt-get. Then decompile the dtb by writing:

dtc -I dtb -O dts -o <path-to-edit-the-file>/imx6q-hummingboard.dts /boot/dtb/imx6q-hummingboard.dtb

and edit the file with you favourite editor (nano yiss!). Around line 1182 should be a device node called “i2c@021a8000” which is the i2c-3 bus, which again is the i2c bus that
has been routed to the pin header on the Hummingboard. In that node we insert a new sub-node for the capacitive touch and its irq. Adafruit calls the node pitft_ctp in their
overlay, so I called it pitft_ctp@38 to go with the flow of the rest of the dts file, and because the controller resides at register 0x38. The node should now
look like this:

i2c@021a8000 {
    #address-cells = <0x1>;
    #size-cells = <0x0>;
    compatible = "fsl,imx6q-i2c", "fsl,imx21-i2c";
    reg = <0x21a8000 0x4000>;
    interrupts = <0x0 0x26 0x4>;
    clocks = <0x2 0x7f>;
    status = "okay";
    clock-frequency = <0x186a0>;
    pinctrl-names = "default";
    pinctrl-0 = <0x28>;
    pitft_ctp@38 {
        compatible = "focaltech,ft6x06";
        reg = <0x38>;
        irq-gpio = <&gpio6 3 2>;
        interrupts = <3 0>;
        interrupt-parent = <&gpio6>;
    };
};

Now this is somewhat stolen from the pitft28c-overlay.dts file from Adafruit, however the pin name is not the same as on the Raspberry Pi, as on the Hummingboard pin header, the corresponding pin is 195 (in linux space). This converts to gpio bank 6 bit 3 (found out by reading some imx6 wikis). The last number (2) in the irq-gpio is an description of the irq state (active low / active high). The interrupts line (I think) is which interrupt number it is bound to, and then the interrupt parent which is gpio bank 6. To get this compilable we need to make a label for gpio bank 6, which is around line 530 where it says “gpio@020b4000 {“.

Put “gpio6 :” in front of that, so the line says “gpio6: gpio@020b4000 {” and save. You should now be able to compile this with dtc again by issuing:

dtc -I dts -O dtb -o /boot/dtb/imx6q-hummingboard.dtb <path-to-edited-file>/imx6q-hummingboard.dts

ATTENTION! This will overwrite the current dtb!

Now reboot, and you should see an “input: ft6x06_ts as /devices/virtual/input/input3” or alike in the kernel log, which means evtest or something should now be able to pick up the touchscreen. Yay!

EDIT: On Jessie which changed to systemd, some minor changes are needed: Instead of editing /etc/modules, edit /etc/modules-load.d/modules.conf (although it is a symlink to /etc/modules, at least in this image) and just insert fbtft_device and ft6x06_ts. Then create a file in /etc/modprobe.d/ called fbtft_device.conf where you insert the fbtft_device options like this:

options fbtft_device name=adafruit22a rotate=90 speed=48000000 fps=50 gpios=dc:67 busnum=1

No need to edit inittab…