Tontec 3.5" Pi Touch Screen driver

Discuss development specific to the Pi version of ADFFS
Post Reply
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

Have ordered a Tontec 3.5" Pi Touch Screen to use as a debugger display. It hangs off the SPI interface, so can be driven independently of the GPU - ideal for debugging. I need to code a driver from scratch though, so its going to be an interesting challenge. I've emailed them for a TRM, so fingers crossed.

I'm also looking to code a GraphicsV driver so RISCOS can use it as a screen that hangs off DA2, with touch screen driver for the mouse based on Chris Mahoney's work.

Image


I'm also looking at the Chalkboard Electronics 10" HD+ 1920x1200 display with a view to making a RISCOS tablet based on the Compute - I need someone with electronics skills to progress that though.

I don't think there's a market for a tablet - not without a decent web browser at any rate, but it would be cool for playing games. I can overlay a joystick and keys in the same way iPhone/iPad devices do it - all very trivial to implement.

Image
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

eMailed Tontec earlier for a TRM and they very promptly provided both the linux driver source code and the TRM.

Screen TRM: Tontec R61581 TRM rev. 1.20.pdf

ADS7846 Touch Screen TRM: ADS7846 Touch Screen Controller.pdf
XPT2046 Touch Screen TRM: XPT2046 Touch Screen Controller.pdf

Linux source:

Code: Select all

/*
 * FB driver for Tontec Screen with R61581 LCD Controller
 *
 * Copyright (C) 2014 Noralf Tronnes
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#include "fbtft.h"

#define DRVNAME		"fb_r61581"
#define WIDTH		320
#define HEIGHT		480


/* this init sequence matches Tontec Screen */
static int default_init_sequence[] = {
	-1,0xB0,0x00,
	-1,0x11,
	-2,250,
	-1,0xB3,0x02,0x00,0x00,0x00,
	-1,0xC0,0x13,0x3B,0x00,0x02,0x00,0x01,0x00,0x43,
	-1,0xC1,0x08,0x16,0x08,0x08,
	-1,0xC4,0x11,0x07,0x03,0x03,
	-1,0xC6,0x00,
	-1,0xC8,0x03,0x03,0x13,0x5C,0x03,0x07,0x14,0x08,0x00,0x21,0x08,0x14,0x07,0x53,0x0C,0x13,0x03,0x03,0x21,0x00,
	-1,0x35,0x00,
	-1,0x36,0xa0,
	-1,0x3A,0x55,
	-1,0x44,0x00,0x01,
	-1,0xD0,0x07,0x07,0x1D,0x03,
	-1,0xD1,0x03,0x30,0x10,
	-1,0xD2,0x03,0x14,0x04,
	-1,0x29,
	-1,0x2C,
	-3
};

static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
	fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
		"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);

	/* Column address */
	write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);

	/* Row adress */
	write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);

	/* Memory write */
	write_reg(par, 0x2C);
}

static int set_var(struct fbtft_par *par)
{
	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

	switch (par->info->var.rotate) {
	case 0:
		write_reg(par, 0x36, 0x00 | (par->bgr << 3));
		break;
	case 90:
		write_reg(par, 0x36, 0x60 | (par->bgr << 3));
		break;
	case 180:
		write_reg(par, 0x36, 0xc0 | (par->bgr << 3));
		break;
	case 270:
		write_reg(par, 0x36, 0xA0 | (par->bgr << 3));
		break;
	default:
		break;
	}
	return 0;
}


static struct fbtft_display display = {
	.regwidth = 8,
	.width = WIDTH,
	.height = HEIGHT,
	.init_sequence = default_init_sequence,
	.fbtftops = {
		.set_addr_win = set_addr_win,
		.set_var = set_var,
	},
};
FBTFT_REGISTER_DRIVER(DRVNAME, "rense,r61581", &display);

MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME);
MODULE_ALIAS("spi:r61581");
MODULE_ALIAS("platform:r61581");

MODULE_DESCRIPTION("FB driver for the R61581 LCD Controller");
MODULE_AUTHOR("Noralf Tronnes");
MODULE_LICENSE("GPL");
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

As you can see from the source above, its fairly easy to interact with. Once the initial init sequence to initialize the screen is performed, you follow it with commands to send display data. There's quite an extensive command list, I count 60 in total allowing you to control everything from pixel depth to screen geometry.

You can even read which scanline the raster is currently on to avoid tearing.

Natively its an 18 bpp display in the format RRRRRRGGGGGGBBBBBB and takes data in either a packed bitstream which can be formed of 16 bpp, 18 bpp or 24 bpp data or a byte stream where the R,G,B are byte aligned with bit 7 being the high bit and the lower bits ignored.

The display itself can be configured to be 8, 12, 16, 18 or 24 bpp and supports the equivalent of VIDC1/20 HSYNC, HBSR, HDSR, HBER, VSYNC, VBSR, VDSR and VBER. It looks like I can pass VIDC20 parameters straight to it and just adjust them to centre the display.

The only restriction on the parameters being the bandwidth - which isn't a problem as we want 50Hz and ensuring the final geometry matches the screen dimensions, which is just a case of altering the borders. All parameters are on an individual pixel basis, so there's no /2 restrictions that VIDC1/20 have.

The 2A / 2B / 2C sequence in the set_addr_win function above is pretty much the equivalent to PRINT TAB(xs, ys) par$ in BASIC.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: Tontec 3.5" Pi Touch Screen driver

Post by richw »

The tablet idea sounds fun, but how usable will an on-screen keyboard be? Surely a proper keyboard, mouse and perhaps joystick is essential for Arc gaming?

I want to build a JASPP/Pi rig soon, and cannot decide on the parts. I quite fancy something portable that I can plug into a TV, perhaps built into an old Archimedes keyboard.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

richw wrote:I want to build a JASPP/Pi rig soon, and cannot decide on the parts. I quite fancy something portable that I can plug into a TV, perhaps built into an old Archimedes keyboard.
I'd like to build a Pi into an XB360 controller that you can plug into a TV, but can't find anyone with USB knowledge to get the project off the ground. An old keyboard sounds like a neat idea if you can get it into USB, create a thread on here and post pics etc. I'm interested to see what you come up with.

I've not added Pi2 support yet, so you're restricted to the original Pi for the time being. Once this next release is out the door, I'm going to take a break to play around with this screen, so don't expect to start looking at Pi2 or any other big ticket aspect until the summer hols.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

The screen arrived today, here's some photos of what you receive, assembly and general comments. Click on the images for the high res originals.

In the box you receive some installation instructions to get it running under Linux on the Pi, laser etched built it yourself clear perspex case, the screen with GPIO attachment board already connected, heatsinks for the CPU and ancillary chip and plastic mounting nuts, bolts and screws for the Pi itself. Note, this version is the Pi2 version, there's a different case for the original Pi.
Image

Opening the case, it's a neat clip together design. All the ports are laser etched which is a nice touch, although sadly they've etched the wrong side of three of them in my case. One side has a thin film of paper which should be removed, I couldn't get it off easily though so it may need soaking in warm soapy water to dissolve. I actually quite liked the "Amazon delivery box" retro look of it so left it on:
Image

Attach the bolts to the base, ready to install the Pi2:
Image

...and attach the Pi2 itself having stuck the heatsinks on. The heatsinks have heat transfer sticky pads on them already, so you just peel and attach them to the two chips:
Image

Now assemble the sides:
Image
Image
Image

Finally insert the screen into the pivot holes and attach to the GPIO header. Note the cable rotates 180 degrees, so be careful when lowering the screen ensuring it doesn't snag:
Image
Image

I powered the Pi2 up, powering it from my laptop USB port to check it didn't report any power issues, all looked good, the GPU didn't report any issues and the screen backlight was on indicating it was working.

Next...coding the driver, which I'll start next week.
colin
Posts: 1
Joined: Tue Mar 31, 2015 11:51 am

Re: Tontec 3.5" Pi Touch Screen driver

Post by colin »

Here's my USBDescriptors program. You Just run it and it will list the USBDescriptors for all attached devices in a taskwindow.

Just search for 'usage' and it should find the hid descriptors for the various devices. It may help.
Attachments
USBDescriptors.zip
(55.21 KiB) Downloaded 314 times
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

Thanks Colin. I've not heard back from Tontec yet, so will run this when I get a chance and see if it appears as a USB device - I suspect it won't and is via SPI.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: Tontec 3.5" Pi Touch Screen driver

Post by JonAbbott »

I've had confirmation back from Tontec that the touchscreen is communicating via SPI not USB. Unfortunately, they don't have any technical details, but are going to contact the manufacturer next week on my behalf.
Post Reply