{"id":618,"date":"2013-03-27T17:50:38","date_gmt":"2013-03-27T15:50:38","guid":{"rendered":"http:\/\/lallafa.de\/blog\/?p=618"},"modified":"2013-04-21T20:23:01","modified_gmt":"2013-04-21T18:23:01","slug":"adding-touch-support-for-the-mi0283qt-displays","status":"publish","type":"post","link":"https:\/\/lallafa.de\/blog\/2013\/03\/adding-touch-support-for-the-mi0283qt-displays\/","title":{"rendered":"Adding touch support for the MI0283QT* displays"},"content":{"rendered":"<p>In my last posts I showed how to integrate Watterott&#8217;s <a title=\"Watterott Display on Raspberry Pi\" href=\"http:\/\/lallafa.de\/blog\/2013\/03\/watterott-display-on-raspberry-pi\/\">MI0283QT-2<\/a> and the newer\u00c2\u00a0<a title=\"Watterott MI0283QT-9A Display for the Rasbperry Pi\" href=\"http:\/\/lallafa.de\/blog\/2013\/03\/watterott-mi0283qt-9a-display-for-the-rasbperry-pi\/\">-9<\/a> displays as a frame buffer device in Raspberry Pi&#8217;s Linux kernel. Now I will focus on adding support for the touch controller found on the display boards.<\/p>\n<p>The touch controller is an ADS7846 chip that already has a device driver in the Linux kernel. User <a href=\"https:\/\/github.com\/dronus\">dronus<\/a> has patched the vanilla driver to make it work with the MI0283QT displays and the Raspberry Pi.<\/p>\n<p>Fine, we already have everything in place now to give it a try!<\/p>\n<h4>Hardware<\/h4>\n<p>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:<\/p>\n<pre>Signal     Raspi      Display   Comment\r\nT_IRQ      GPIO25       13       Interrupt line from ADS7846\r\nT_CS       SPI0_CE0_N\u00c2\u00a0  11       SPI chip select 0<\/pre>\n<h4>Software<\/h4>\n<p>I assume you already have a patched Linux kernel with the tft driver patches applied. Here is quick list with the next steps:<\/p>\n<ul>\n<li>(Manually) apply <a href=\"https:\/\/github.com\/dronus\/linux\/commit\/24666a13e8dfac1dfeaf55fa3c6e413b64af1a42\">dronus small patch<\/a> to your kernel tree. This adds the necessary modifications of the ADS driver.<\/li>\n<li>Note: I had to replace the<strong> invert_x<\/strong> with the <strong>invert_y<\/strong> entry in the ADS configuration to match the display orientation we use in the frame buffer driver<\/li>\n<li>Your SPI config for the display now should look like this (for the newer *-9 display): <strong>linux\/file\u00c2\u00a0arch\/arm\/mach-bcm2708\/bcm2708.c<\/strong><\/li>\n<\/ul>\n<pre>static struct ads7846_platform_data ads7846_config = {\r\n  .x_max      = 0x0fff,\r\n  .y_max      = 0x0fff,\r\n  .x_plate_ohms    = 180,\r\n  .pressure_max    = 255,\r\n  .debounce_max    = 10,\r\n  .debounce_tol    = 3,\r\n  .debounce_rep    = 1,\r\n  .gpio_pendown    = 25,\r\n  .keep_vref_on    = 1,\r\n  .swap_xy     = true,\r\n  .invert_y    = true\r\n};\r\n\r\nstatic struct spi_board_info bcm2708_spi_devices[] = {\r\n        {\r\n                \/\/ ads7846 touchscreen on chipsel=0 device\r\n                .modalias    = \"ads7846\",\r\n                .bus_num    = 0,\r\n                .chip_select    = 0,\r\n                .max_speed_hz           = 500000,\r\n                .irq      = GPIO_IRQ_START+25,\r\n                .platform_data    = &amp;ads7846_config,\r\n                .mode = SPI_MODE_0\r\n        }, {\r\n                \/\/ display on chipsel=1 device\r\n                .modalias = \"ili9341fb\",\r\n                .max_speed_hz = 16000000,\r\n                .bus_num = 0,\r\n                .chip_select = 1,\r\n                .mode = SPI_MODE_0,\r\n                .platform_data = &amp;(struct fbtft_platform_data) {\r\n                        .gpios = (const struct fbtft_gpio []) {\r\n                                { \"reset\", 23 },\r\n                                { \"led\", 24 },\r\n                                {},\r\n                        },\r\n                        .fps = 10\r\n                }\r\n        }\r\n};<\/pre>\n<ul>\n<li>I use <strong>GPIO 25<\/strong> for the touch IRQ (mainly because wiring was easier this way \ud83d\ude42 and had to change the relevant entries. dronus used GPIO 17 instead.<\/li>\n<li>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.<\/li>\n<li>The older <strong>-2<\/strong> display works similarly. You only have to exchange the second block with the one of the <strong>r61505u<\/strong> driver. See <a title=\"Watterott Display on Raspberry Pi\" href=\"http:\/\/lallafa.de\/blog\/2013\/03\/watterott-display-on-raspberry-pi\/\">old post<\/a> for details<\/li>\n<li>Open the configuration of the kernel and select the ADS driver:<\/li>\n<\/ul>\n<pre>&gt; make menuconfig\r\nSelect \"Device Drivers -&gt; Input Device Support -&gt; [*] Touchscreens -&gt; [*] ADS7846...\"<\/pre>\n<ul>\n<li>Make sure to include the ADS driver directly into the kernel and NOT in a module<\/li>\n<li>Ok, thats it! (Re-)compile kernel and install it on your RPi&#8230;<\/li>\n<\/ul>\n<h4>Test<\/h4>\n<p>After a reboot your system shows a new input device in <strong>\/dev\/input\/*<\/strong>. If no other USB mouse or keyboard is connected then the devices found there are all created by the touch controller.<\/p>\n<p>You can use the <strong>evtest<\/strong> utility to check the touch operation (Install with &#8216;apt-get install evtest&#8217; first!):<\/p>\n<pre>&gt; evtest \/dev\/input\/event0<\/pre>\n<p>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.<\/p>\n<p>Now with the basic operation tested you can start X11 on your display (see <a title=\"Watterott MI0283QT-9A Display for the Rasbperry Pi\" href=\"http:\/\/lallafa.de\/blog\/2013\/03\/watterott-mi0283qt-9a-display-for-the-rasbperry-pi\/\">last post<\/a>) and use your fingers or a stylus to navigate the mouse cursor!<\/p>\n<h4>Open Topic<\/h4>\n<p>While touch operation with this driver is rock solid and works very precisely I have found one little nuisance: I can&#8217;t move the X11 cursor into the border regions of the display \ud83d\ude41 Approx 5 mm at the border of the visibile display area my touch movements are not recognized anymore and I can&#8217;t move the pointer there&#8230; I am not sure if this is a limitation of the display, of the ADS driver or the parameter set for the driver&#8230; If you find a workaround for this then please post a comment!<\/p>\n<h4>[Update: 21.4.2013] Pre-compiled Kernel<\/h4>\n<p>A pre-compiled Raspbian Wheezy Kernel 3.6.11+ with both\u00c2\u00a0ili9341 display and ads7846 touch driver (i.e. supporting all devices on the\u00c2\u00a0MI0283QT-9 board) is available for download here:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.lallafa.de\/files\/raspi\/raspi-linux-3.6.11-ili9341-ads7846.tar.gz\">raspi-linux-3.6.11-ili9341-ads7846.tar.gz<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In my last posts I showed how to integrate Watterott&#8217;s MI0283QT-2 and the newer\u00c2\u00a0-9 displays as a frame buffer device in Raspberry Pi&#8217;s Linux kernel. Now I will focus on adding support for the touch controller found on the display &hellip; <a href=\"https:\/\/lallafa.de\/blog\/2013\/03\/adding-touch-support-for-the-mi0283qt-displays\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8,1,9],"tags":[],"class_list":["post-618","post","type-post","status-publish","format-standard","hentry","category-hardware","category-misc","category-software"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/piBMF-9Y","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/comments?post=618"}],"version-history":[{"count":8,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/618\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/618\/revisions\/626"}],"wp:attachment":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/media?parent=618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/categories?post=618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/tags?post=618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}