Atmel Software Framework

ui.c File Reference

User interface for mXT143E Xplained trackpad demo.

Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.

#include <asf.h>
#include <conf_example.h>
#include "ui.h"
#include "conf_usb.h"

Data Structures

struct  trace_info
 Information for one trace point. More...
 

Macros

Touch trace settings
#define TRACE_RECT_SIZE   10
 Size (width/height) of trace-rectangle. More...
 
#define NUM_TRACES   150
 Number of rectangles in the touch trace. More...
 

Functions

static void draw_frame (const uint8_t start, const uint8_t thickness, const gfx_color_t color)
 Draw a frame. More...
 
static void handle_trace (gfx_coord_t x, gfx_coord_t y)
 Handle finger traces on display. More...
 
void ui_init (void)
 Initialize the user interface. More...
 
void ui_powerdown (void)
 Put the user interface in power down. More...
 
void ui_process (uint16_t framenumber)
 Process the user interface. More...
 
void ui_wakeup (void)
 Wake the user interface up. More...
 
void ui_wakeup_disable (void)
 Disable asynchronous interrupts of the user interface. More...
 
void ui_wakeup_enable (void)
 Enable asynchronous interrupts of the user interface. More...
 

Variables

static struct trace_info trace [NUM_TRACES]
 Array to hold all trace points. More...
 
bool ui_new_touch_event
 Flag that a new touch event is pending. More...
 
struct mxt_touch_event ui_touch_event
 Struct to hold touch events to process. More...
 
Display size containers

To avoid fetching the display size multiple times from the graphics service, store them in these two variables upon initialization.

static uint16_t display_w
 Display width. More...
 
static uint16_t display_h
 Display height. More...
 

#define NUM_TRACES   150

Number of rectangles in the touch trace.

Note
This macro essentially sets the length of the trace.

Referenced by handle_trace(), and ui_init().

#define TRACE_RECT_SIZE   10

Size (width/height) of trace-rectangle.

Referenced by handle_trace().

static void draw_frame ( const uint8_t  start,
const uint8_t  thickness,
const gfx_color_t  color 
)
static

Draw a frame.

This function draws a frame with the specified thickness and color on the display, at the specified start offset from the edges.

Parameters
startStart offset (x and y, from 0) of frame
thicknessThickness (in pixels) of frame
colorColor of frame

References display_h, display_w, and gfx_draw_rect.

Referenced by ui_process().

static void handle_trace ( gfx_coord_t  x,
gfx_coord_t  y 
)
static

Handle finger traces on display.

This function updates the traces, drawing a new one at the specified coordinates and clearing the oldest one. It must be called at regular intervals to give a smooth trace animation.

Parameters
xX-coordinate of finger touch
yY-coordinate of finger touch
Note
The coordinate (0,0) is used to indicate no touch, thus only causing the oldest trace to be cleared.

References display_h, display_w, GFX_COLOR_WHITE, gfx_draw_rect, max, min, NUM_TRACES, trace, TRACE_RECT_SIZE, trace_info::x, and trace_info::y.

Referenced by ui_process().

void ui_init ( void  )

Initialize the user interface.

Initializes the user interface.

References display_h, display_w, gfx_get_height(), gfx_get_width(), NUM_TRACES, trace, ui_new_touch_event, trace_info::x, and trace_info::y.

Referenced by main().

void ui_powerdown ( void  )

Put the user interface in power down.

Enters the user interface in power down mode.

Referenced by main(), main_hid_set_feature(), and main_suspend_action().

void ui_process ( uint16_t  framenumber)

Process the user interface.

This process is called each 1ms It is called only if the USB interface is enabled.

This function processes user touch events and updates the display.

The first registered touch is used to control the cursor. Its presence is indicated with a red frame around the display. When the cursor touch moves, its movement is visualized with a trace on the display.

The second registered touch is used to control mouse buttons, and is indicated with an inner frame of which the color depends on which side the touch is for: blue for left and green for right button click. The frame is shown until the touch is released. To detect which side click it is, the position relative to the cursor touch is used, i.e., a touch to the left of the first touch will cause a left mouse click.

Parameters
framenumberCurrent USB frame number
Note
This function should be called every millisecond, e.g., for each USB frame.

References draw_frame(), GFX_COLOR_BLUE, GFX_COLOR_GREEN, GFX_COLOR_RED, handle_trace(), HID_MOUSE_BTN_DOWN, HID_MOUSE_BTN_UP, mxt_touch_event::id, MXT_DETECT_EVENT, MXT_PRESS_EVENT, MXT_RELEASE_EVENT, mxt_touch_event::status, udi_hid_mouse_btnleft(), udi_hid_mouse_btnright(), udi_hid_mouse_moveX(), udi_hid_mouse_moveY(), ui_new_touch_event, ui_touch_event, mxt_touch_event::x, and mxt_touch_event::y.

Referenced by main(), and main_sof_action().

void ui_wakeup ( void  )

Wake the user interface up.

Exits the user interface of power down mode.

Referenced by main_resume_action().

void ui_wakeup_disable ( void  )

Disable asynchronous interrupts of the user interface.

Disables the asynchronous interrupts of the user interface.

Referenced by main_remotewakeup_disable().

void ui_wakeup_enable ( void  )

Enable asynchronous interrupts of the user interface.

Enables the asynchronous interrupts of the user interface.

Referenced by main_remotewakeup_enable().

uint16_t display_h
static

Display height.

Referenced by draw_frame(), handle_trace(), and ui_init().

uint16_t display_w
static

Display width.

Referenced by draw_frame(), handle_trace(), and ui_init().

struct trace_info trace[NUM_TRACES]
static

Array to hold all trace points.

Referenced by handle_trace(), and ui_init().

bool ui_new_touch_event

Flag that a new touch event is pending.

Referenced by ui_flag_new_touch_event(), ui_init(), and ui_process().

struct mxt_touch_event ui_touch_event

Struct to hold touch events to process.

Referenced by main(), and ui_process().