GINPUT

From uGFX Wiki
Revision as of 21:31, 1 July 2014 by Tectu (Talk | contribs) (Touchscreen)

Jump to: navigation, search
GINPUT architecture

GINPUT is a powerful module which provides an easy way to interface different hardware peripherals such as touchscreens to the rest of the library. It provides everything which these peripherals need in order to operate properly such as calibration routines for the touchscreens.

Touchscreen

A touchscreen can be interfaced very easily through the GINPUT module. It doesn't matter if it is a resistive, capacitive or any other touchscreen technology.

Board file

The board file API for the GINPUT touchscreen module looks like the following:

static void init_board(void);
static bool_t getpin_pressed(void);
static void aquire_bus(void);
static void release_bus(void);
static uint16_t read_value(uint16_t port);

Calibration

The GINPUT module provides a calibration routine which uses a three-point algorithm. Three calibration points will show up, one after another. You have to press each. At the end of this process, a 4rd one will appear in the center of the screen. This last one is only used to test if the calibration was successful. If the offset is too big, the calibration process will be restarted automatically.

Options

The following settings can alter the behaviour of the calibration routine:

Option Description
GINPUT_MOUSE_CALIBRATE_EXTREMES If this is set to TRUE in your gfxconf.h, the calibration points are display at the very corner of the display. This gives an overall more accurate result but they are less intuitive.
GINPUT_MOUSE_MAX_CALIBRATION_ERROR This macro is part of the config file of the driver in your board directory and takes a pixel value. It defines how big the pixel offset of the test point can be before the calibration process is repeated automatically.

Storage interface

An unpleasant problem you might run into with your touchscreen device is, that you have to perform a calibration at every reset. To fight this problem, GINPUT provides an interface to easily save and restore calibration data. The interface is very flexible and you can do with the calibration data what ever you want: You can store it on an SD card, in your MCU's internal flash, on an external I²C EEprom or every other possible way to store 25 bytes.

What you need to do is providing two functions, one to save and one to restore the calibration data:

void mysave(uint16_t instance, const uint8_t *calbuf, size_t sz);
const char *myload(uint16_t instance);

These two function are passed to ginputSetMouseCalibrationRoutines():

ginputSetMouseCalibrationRoutines(0, mysave, myload, FALSE);

The first parameter is the instance of the mouse device, the second one the save, the third the restore function. The last parameter defines if the buffer allocated by this function to pass the calibration data needs to be free()'d afterwards or not.

It's very important that this function gets called before you call the ginputAttachMouse() routine.

Example

Here's a simple example which shows how to save and restore the calibration data on an SD card using FatFS. Please note that this is just for demonstration. It's highly recommended to check the return value of every function.

void mysave(uint16_t instance, const uint8_t *calbuf, size_t size)
{
	FRESULT ferr;
	FIL fi;
	UINT wr;
	uint8_t bsize;
 
	(void)instance;
 
	bsize = size;
 
	f_open(&fi, "calib", FA_CREATE_ALWAYS | FA_WRITE);
 
	f_write(&fi, &bsize, 1, &wr);
	f_write(&fi, calbuf, size, &wr);
 
	f_close(&fi);
}
 
const char *myload(uint16_t instance)
{
	FRESULT ferr;
	FIL fi;
	UINT br;
	uint8_t bsize;
	char *buffer;
 
	(void)instance;
 
	f_open(&fi, "calib", FA_READ);
	f_read(&fi, &bsize, 1, &br);
 
	buffer = gfxAlloc(bsize);
 
	f_read(&fi, buffer, bsize, &br);
	f_close(&fi);
 
	return buffer;
}

Digital input

ToDo

Analog input

ToDo