In my last posts I showed how to integrate Watterott’s MI0283QT-2 and the newer -9 displays as a frame buffer device in Raspberry Pi’s Linux kernel. Now I will focus on adding support for the touch controller found on the display boards.
The touch controller is an ADS7846 chip that already has a device driver in the Linux kernel. User dronus has patched the vanilla driver to make it work with the MI0283QT displays and the Raspberry Pi.
Fine, we already have everything in place now to give it a try!
Hardware
First, we need to add two additional wires in our hardware setup to connect the touch controller (see old wiring in last post) with the RPi:
Signal Raspi Display Comment
T_IRQ GPIO25 13 Interrupt line from ADS7846
T_CS SPI0_CE0_NÂ 11 SPI chip select 0
Software
I assume you already have a patched Linux kernel with the tft driver patches applied. Here is quick list with the next steps:
- (Manually) apply dronus small patch to your kernel tree. This adds the necessary modifications of the ADS driver.
- Note: I had to replace the invert_x with the invert_y entry in the ADS configuration to match the display orientation we use in the frame buffer driver
- Your SPI config for the display now should look like this (for the newer *-9 display): linux/file arch/arm/mach-bcm2708/bcm2708.c
static struct ads7846_platform_data ads7846_config = {
.x_max = 0x0fff,
.y_max = 0x0fff,
.x_plate_ohms = 180,
.pressure_max = 255,
.debounce_max = 10,
.debounce_tol = 3,
.debounce_rep = 1,
.gpio_pendown = 25,
.keep_vref_on = 1,
.swap_xy = true,
.invert_y = true
};
static struct spi_board_info bcm2708_spi_devices[] = {
{
// ads7846 touchscreen on chipsel=0 device
.modalias = "ads7846",
.bus_num = 0,
.chip_select = 0,
.max_speed_hz = 500000,
.irq = GPIO_IRQ_START+25,
.platform_data = &ads7846_config,
.mode = SPI_MODE_0
}, {
// display on chipsel=1 device
.modalias = "ili9341fb",
.max_speed_hz = 16000000,
.bus_num = 0,
.chip_select = 1,
.mode = SPI_MODE_0,
.platform_data = &(struct fbtft_platform_data) {
.gpios = (const struct fbtft_gpio []) {
{ "reset", 23 },
{ "led", 24 },
{},
},
.fps = 10
}
}
};
- I use GPIO 25 for the touch IRQ (mainly because wiring was easier this way 🙂 and had to change the relevant entries. dronus used GPIO 17 instead.
- I reduced the SPI rate of the display to 16 MHz and the frame rate to 10 fps. This proved to be more stable with activated touch controller.
- The older -2 display works similarly. You only have to exchange the second block with the one of the r61505u driver. See old post for details
- Open the configuration of the kernel and select the ADS driver:
> make menuconfig
Select "Device Drivers -> Input Device Support -> [*] Touchscreens -> [*] ADS7846..."
- Make sure to include the ADS driver directly into the kernel and NOT in a module
- Ok, thats it! (Re-)compile kernel and install it on your RPi…
Test
After a reboot your system shows a new input device in /dev/input/*. If no other USB mouse or keyboard is connected then the devices found there are all created by the touch controller.
You can use the evtest utility to check the touch operation (Install with ‘apt-get install evtest’ first!):
> evtest /dev/input/event0
When you tap on the display you will see the incoming events. Note the x and y coordinates mapping if you tap on different corners of the display.
Now with the basic operation tested you can start X11 on your display (see last post) and use your fingers or a stylus to navigate the mouse cursor!
Open Topic
While touch operation with this driver is rock solid and works very precisely I have found one little nuisance: I can’t move the X11 cursor into the border regions of the display 🙁 Approx 5 mm at the border of the visibile display area my touch movements are not recognized anymore and I can’t move the pointer there… I am not sure if this is a limitation of the display, of the ADS driver or the parameter set for the driver… If you find a workaround for this then please post a comment!
[Update: 21.4.2013] Pre-compiled Kernel
A pre-compiled Raspbian Wheezy Kernel 3.6.11+ with both ili9341 display and ads7846 touch driver (i.e. supporting all devices on the MI0283QT-9 board) is available for download here:
Like this:
Like Loading...