Atmel Software Framework

multi-touch_demo.c File Reference

mXT143E Xplained multi-touch demo application

Copyright (C) 2012-2015 Atmel Corporation. All rights reserved.

#include <asf.h>
#include <stdio.h>

Data Structures

struct  finger
 Struct for touch visualization data. More...
 

Macros

#define DISPLAY_COLOR   GFX_COLOR_BLACK
 Background color of display. More...
 
#define ENABLE_COORDINATE_DISPLAY
 Define to enable display of touch coordinates with each square. More...
 
#define ENABLE_TOUCH_SIZE_DISPLAY
 Define to enable resizing of the touch square based on the touch size. More...
 
#define MAX_TOUCHES   8
 Maximum number of touches to track. More...
 
#define MAXTOUCH_TWI_ADDRESS   0x4a
 Address of the mXT143E on TWI bus. More...
 
#define MIN_SQUARE_SIZE   70
 Minimum size of touch squares to draw. More...
 

Functions

static void draw_finger_square (const struct finger *draw_finger, const gfx_color_t color)
 Draw square around a finger. More...
 
static void get_finger_display_coordinates (const struct mxt_touch_event *touch_event, struct finger *finger_data)
 Compute display coordinates for touch. More...
 
int main (void)
 Main application loop. More...
 
static void mxt_handler (struct mxt_device *device)
 Handle maXTouch messages. More...
 
static void mxt_init (struct mxt_device *device)
 Set maXTouch configuration. More...
 

#define DISPLAY_COLOR   GFX_COLOR_BLACK

Background color of display.

Referenced by main(), and mxt_handler().

#define ENABLE_COORDINATE_DISPLAY

Define to enable display of touch coordinates with each square.

#define ENABLE_TOUCH_SIZE_DISPLAY

Define to enable resizing of the touch square based on the touch size.

#define MAX_TOUCHES   8

Maximum number of touches to track.

Referenced by mxt_handler().

#define MAXTOUCH_TWI_ADDRESS   0x4a

Address of the mXT143E on TWI bus.

Referenced by mxt_init().

#define MIN_SQUARE_SIZE   70

Minimum size of touch squares to draw.

Referenced by draw_finger_square().

static void draw_finger_square ( const struct finger draw_finger,
const gfx_color_t  color 
)
static

Draw square around a finger.

This function draws an unfilled square around the specified finger.

Parameters
draw_fingerPointer to finger struct
colorColor to draw with

References GFX_COLOR_TRANSPARENT, gfx_draw_string(), gfx_generic_draw_rect(), gfx_get_string_bounding_box(), MIN_SQUARE_SIZE, finger::size, sysfont, finger::x, and finger::y.

Referenced by mxt_handler().

static void get_finger_display_coordinates ( const struct mxt_touch_event touch_event,
struct finger finger_data 
)
static

Compute display coordinates for touch.

This function computes the display coordinates for a given touch event, and stores it in the specified X- and Y-coordinate containers.

Parameters
touch_eventPointer to touch event
finger_dataPointer to finger struct

References gfx_get_height(), gfx_get_width(), finger::size, mxt_touch_event::size, finger::x, mxt_touch_event::x, finger::y, and mxt_touch_event::y.

Referenced by mxt_handler().

int main ( void  )

Main application loop.

This is the main application function, which runs all the initialization code, clears the display and enters a loop in which it continuously polls for new messages from the maXTouch device. If one or more messages are pending, the maXTouch message handler is invoked.

References board_init(), DISPLAY_COLOR, gfx_draw_filled_rect, gfx_get_height(), gfx_get_width(), gfx_init, mxt_handler(), mxt_init(), mxt_is_message_pending(), and sysclk_init.

static void mxt_handler ( struct mxt_device device)
static

Handle maXTouch messages.

This function handles the maXTouch messages, triggering the drawing of squares around new or moved touches, and removing the squares around released touches.

Parameters
devicePointer to mxt_device struct

References DISPLAY_COLOR, draw_finger_square(), finger::enable, get_finger_display_coordinates(), GFX_COLOR_BLUE, GFX_COLOR_CYAN, GFX_COLOR_GRAY, GFX_COLOR_GREEN, GFX_COLOR_MAGENTA, GFX_COLOR_RED, GFX_COLOR_WHITE, GFX_COLOR_YELLOW, mxt_touch_event::id, MAX_TOUCHES, mxt_is_message_pending(), MXT_MOVE_EVENT, MXT_PRESS_EVENT, mxt_read_touch_event(), MXT_RELEASE_EVENT, mxt_touch_event::status, and STATUS_OK.

Referenced by main().

static void mxt_init ( struct mxt_device device)
static