Skip to content

Touch panel driver provides functions for touch and gesture detection as well as reading out touch coordinates.

To use this library

Header: #include "tp.h"

memake: MikroSDK.TouchPanel

Touch Panel library is responsible for controlling any of the supported touch controller drivers.

It provides functionality for reading out coordinates of up to five detected touch events, gesture recognition and selection of the touch panel orientation (placement).
This library has modular architecture, so it can work with any driver which implements tp_drv_t interface.

Initialization

static tp_t touch_panel;
static tp_drv_t tp_interface;
tp_cfg_t tp_cfg;         // Configuration structure for touch panel object
static ft5xx6_t ft5xx6;  // Selected touch controller object

tp_init( &touch_panel, &tp_cfg, &tp_interface, &ft5xx6 );

tp_cfg consists of fields of touch panel configuration which is dependant on the selected display. tp_interface and ft5xx6 must be initialized before the initialization of the touch panel library and they are specific to the touch controller driver. Middleware libraries usually provide the initialization function for the tp_interface instance as well as ft5xx6 touch controller object. In order to see how to properly initialize a certain component's driver, refer to the component's documentation.

Usage of the Touch Panel Library

Touch Panel Library implements a tp_process() function which relies on user configured callback functions. It is a non blocking function which checks for all possible events and calls the appropriate callback functions. These callback functions must have the appropriate declarations.

void touch_callback( tp_event_t event, tp_coord_t x, tp_coord_t y,
                     tp_touch_id_t id )
{
    // User code
}

void gesture_callback( tp_event_t event )
{
    // User code
}

void application_init( void )
{
    // Touch panel and selected touch controller initialization

    tp_press_callback_setup( &touch_panel, touch_callback );
    tp_gesture_callback_setup( &touch_panel, gesture_callback );
}

void application_task( void )
{ 
    tp_process( &touch_panel );

    // User code
}

Coordinate system

The library uses cartesian coordinate system in plane, and each point represents one pixel on display. The origin is placed in top-left corner of a display. The x value increases to the right and the y value increases downwards. This can be modified by the tp_rotate() function.

Reference