Search by Tags

Capacitive Multi-Touch Solution Source Code


Compare with Revision

Subscribe for this article updates


This article explains how to use the capacitive multi-touch hardware adaption source code.

Source Code Download

The table below shows the download links of project source codes for different touch controllers.

Touch Controllers Using Windows CE Software libraries (PXA and Tegra) Using Toradex CE libraries (Tegra, VF, iMX6, iMX7)
Atmel mXT1066t2 (Capacitive Touch Displays from Toradex Webshop) Source Code
Fusion Display Source Code Source Code
FT5x06 Source Code
PolyTouch(TM), EPxxxxM06 Source Code
PolyTouch(TM), EPxxxxM09 Source Code


  • The source code can be used as a template for customization. Please refer WinCE section of the article, First Step with Capacitive Multi-Touch Display for registry settings and bring up of touch device.
  • Questions about the structure of the Multi-Touch Solution and the source code are welcome but we can not provide detailed support for any customization.

IDE, Libraries and Specific Project Files

IDE Source code examples are Visual Studio 2008 project with Toradex Windows Embedded Compact SDK installed.


The following WinCE libraries are used:

mapreglib.lib(if using Windows CE Software Libraries) or MapMemLib.lib(if using Toradex CE Libraries)

Probably the search path for the library h-files and lib-files must be adapted in the project.

Specific project files

The Hardware Adaption project contains the following specific project files depending upon the display controller type using.

Fusion PolyTouch(TM), EPxxxxM06 PolyTouch(TM), EPxxxxM09 Remarks
HwAdapt.c HwAdapt.c HwAdapt.c Contains the main loop
TchContr_Fusion.c TchContr_EP0700.c TchContr_EPXXXXM09.c Contains all function for the handling of the touch controller
TchContr_Fusion.h TchContr_EP0700.h TchContr_EPXXXXM09.h
unfd_multitchdrv.h unfd_multitchdrv.h unfd_multitchdrv.h contains the common data type “TCHINPUT”

Source Code Description

The following topic describes the source code of the file “HwAdapt.c”. The called functions are defined in respective ".c" file of the touch controller project.

Start Sequence

After starting the application, the registry settings are read.

// Read and setup the configuration

Then the I2C communication and the GPIO for reset and interrupt are setup.

// Init the IC interface on the Colibri (makes no sense to retry)
if (FALSE==bI2C_Init())

Then the communication to the Unified Multi-Touch Driver is established.

// Get a handle to the driver. Which causes the driver's XXX_Open function to be called

Main Loop

The main loop contains the initialization of the touch controller.

if (FALSE==bInitEPxxxxM06()) // reset and start touch controller
                             // In case of Fusion "bInitFusion()"
                             // In case of EPxxxxM09 "bInitEPxxxxM09()"

If this is ok, then the program enters in another loop which reads out the status and touch position(s).

// wait for messages

Otherwise, the touch controller will be reset, and after a delay, the initialization of the touch controller will happen again.

vDeInitEPxxxxM06(); // stop (reset/powerdown) the Touch Controller
                    // In case of Fusion "vDeInitFusion();"
                    // In case of EPxxxxM09 "vDeInitEPxxxxM09();"
Sleep(400); // wait before an new try starts

This is done forever

Loop to read out the touch position

This loop waits until an interrupt from the touch controller occurs or a timeout happens.

if (FALSE==bWaitTouchDataINT())

If a timeout occurs, then the communication is tested.

// timeout, test the communication to the touch controller
if (FALSE==bCommunicationTestEPxxxxM06())  // In case of Fusion "bCommunicationTestFusion();"
                                           // In case of EPxxxxM09 "bCommunicationTestEPxxxxM09();"

Otherwise, the status and the touch position(s) are read out of the touch controller.

// get the touch events

If the touch event is valid, then it sends an IOCLT code “IOCTL_SET_TOUCH_EVENT” to the Unified Multi-Touch Driver.

// send the touch events to the unified touch driver
DeviceIoControl( hDS, IOCTL_SET_TOUCH_EVENT, &CeTchInp, sizeof(CeTchInp), NULL, 0, &BytesHandled, NULL );

Any error causes the exit of these loops, and the main loop resets and initializes the touch controller again.

Touch event type used by DeviceIoControl ()

Header File “unfd_multitchdrv.h”

The header file "tchddi.h" is part of the BSP and not available for application normally. Because of the lack of this header file, the types CETOUCHINPUT and PCETOUCHINPUT are missing. The header file “unfd_multitchdrv.h” contains a copy of these two types. To avoid type conflicts TCHINPUT, PTCHINPUT are defined and used instead CETOUCHINPUT and PCETOUCHINPUT.


Touch event type

To send data with function DeviceIoControl() all data must be packed in one structure.

typedef struct
     INT iCnt;
TchInp[MAXTOUCHES];  //An array of touch data of the type TCHINPUT (CETOUCHINPUT)
iCnt                 //Actually count of touches saved in the TchInp[].


The following topic describes the minimum data which must be defined for a touch event. Click here for more information.

typedef struct {
  LONG x;   //Specifies the x coordinate of the touch point in 4ths of a pixel.
  LONG y;   //Specifies the y coordinate of the touch point in 4ths of a pixel.
  HANDLE hSource;  //Touchpoint identifier set to zero, it is set by the
                   //Unified Multi-Touch Driver before the touch data is sent to the MDD.
DWORD dwID;        //Maintained for a contact from the time it goes down until the time it goes up. 
                   //Must be a value bigger the zero and different from other contacts (fingers).
DWORD dwFlags;     //A set of bit flags that specify various aspects of touch point press/release and motion. Valid flags are:
                   //TOUCHEVENTF_DOWN | TOUCHEVENTF_INRANGE   A finger contacts the touch
                   //TOUCHEVENTF_MOVE | TOUCHEVENTF_INRANGE   The finger moves touch
                   //TOUCHEVENTF_UP                           The finger is lifted up

All other data must be zero or set according to the specification of Microsoft

DWORD dwMask;
DWORD dwTime;
DWORD cxContact;
DWORD cyContact;
DWORD dwPropertyOffset;
DWORD cbProperty;