Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Resistive Touch Service

This service provides an interface for handling resistive touch component.

The resistive touch service consists of the following:

The resistive touch service provides an general interface to be used by the application or by libraries. It can support various touch component and also provide convenient routines to handle touch screen calibration.

Modules

 
 ADS7843 Touch Controller
 This is hardware specific configuration that configures the resistive touch service for use with the ADS7843 touch controller.
 

Data Structures

struct  rtouch_calibration_point_struct
 Storage structure for calibration point (actual and raw positions). More...
 
struct  rtouch_calibration_points_struct
 Collection of the five calibration points required to compute calibration. More...
 
struct  rtouch_event_struct
 User touch event structure. More...
 
struct  rtouch_point_struct
 Point definition. More...
 

Typedefs

typedef struct
rtouch_calibration_point_struct 
rtouch_calibration_point_t
 Storage structure for calibration point (actual and raw positions). More...
 
typedef struct
rtouch_calibration_points_struct 
rtouch_calibration_points_t
 Collection of the five calibration points required to compute calibration. More...
 
typedef void(* rtouch_event_handler_t )(rtouch_event_t const *event)
 
typedef struct rtouch_event_struct rtouch_event_t
 User touch event structure. More...
 
typedef enum rtouch_event_type_enum rtouch_event_type_t
 Touch events enumeration. More...
 
typedef struct rtouch_point_struct rtouch_point_t
 Point definition. More...
 

Enumerations

enum  rtouch_event_type_enum {
  RTOUCH_PRESS,
  RTOUCH_MOVE,
  RTOUCH_RELEASE
}
 Touch events enumeration. More...
 

Functions

uint32_t rtouch_compute_calibration (rtouch_calibration_point_t *points)
 Perform the calibration process using the provided points. More...
 
void rtouch_disable (void)
 Disable the resistive touch service. More...
 
void rtouch_enable (void)
 Enable the resistive touch service for touch detection and sampling. More...
 
rtouch_event_handler_t rtouch_get_event_handler (void)
 Get the touch event handler. More...
 
uint32_t rtouch_init (const uint32_t ul_width, const uint32_t ul_height)
 Initialize the resistive touch service. More...
 
void rtouch_process (void)
 Core function for resistive touch service. More...
 
void rtouch_set_calibration_parameter (int32_t xslope, int32_t yslope, int32_t rawx, int32_t rawy)
 Set calibration parameters when manual calibration procedure is not performed. More...
 
void rtouch_set_event_handler (rtouch_event_handler_t handler)
 Set the touch event handler. More...
 
void rtouch_wait_pressed (void)
 Wait touch pressed. More...
 
void rtouch_wait_released (void)
 Wait touch released. More...
 

Storage structure for calibration point (actual and raw positions).

Collection of the five calibration points required to compute calibration.

typedef void(* rtouch_event_handler_t)(rtouch_event_t const *event)

User touch event structure.

Touch events enumeration.

Point definition.

Touch events enumeration.

Enumerator
RTOUCH_PRESS 
RTOUCH_MOVE 
RTOUCH_RELEASE 

uint32_t rtouch_compute_calibration ( rtouch_calibration_point_t points)

Perform the calibration process using the provided points.

Parameters
pointsCalibration and raw points.
Returns
1 if calibration was successful; 0 otherwise.

Calculate slopes using the calibration data Theory behind those calculations:

  • We suppose the touchscreen measurements are linear, so the following equations are true (simple linear regression) for any two 'a' and 'b' points of the screen: dx = (a.data[0] - b.data[0]) / (a.x - b.x) dy = (a.data[1] - b.data[1]) / (a.y - b.y)
  • We calculate dx and dy (called xslope and yslope here) using the calibration points.
  • We can then use dx and dy to infer the position of a point 'p' given the measurements performed by the touchscreen ('c' is any of the calibration points): dx = (p.data[0] - c.data[0]) / (p.x - c.x) dy = (p.data[1] - c.data[1]) / (p.y - c.y) Thus: p.x = c.x - (p.data[0] - c.data[0]) / dx p.y = c.y - (p.data[1] - c.data[1]) / dy
  • Since there are four calibration points, dx and dy can be calculated twice, so we average the two values.

Backup calibration point 0, used for point processing

Check resulting x and y

Check calibration result

References MULTI_FACTOR, rtouch_calibration_point_struct::panel, POINTS_MAX_ERROR, rtouch_calibration_point_struct::raw, rtouch_get_calibrated_point(), rtouch_point_struct::x, and rtouch_point_struct::y.

Referenced by main(), and rtouch_calibrate().

void rtouch_disable ( void  )

Disable the resistive touch service.

Touch interrupt will be disabled as well.

References rtouch_disable_pen_interrupt().

void rtouch_enable ( void  )

Enable the resistive touch service for touch detection and sampling.

References rtouch_enable_pen_interrupt().

Referenced by main().

rtouch_event_handler_t rtouch_get_event_handler ( void  )

Get the touch event handler.

Note
Use this to store the old handler while replacing it for a short while, e.g. for calibration.
Returns
Current touch event handler pointer.

References event_handler.

uint32_t rtouch_init ( const uint32_t  ul_width,
const uint32_t  ul_height 
)

Initialize the resistive touch service.

Parameters
ul_widthThe panel width in pixels.
ul_heightThe panel height in pixels.
Returns
0 on success.

References rtouch_init_device.

Referenced by main().

void rtouch_process ( void  )

Core function for resistive touch service.

Note
An external timer interrupt should call rtouch_process() per 10ms in order to compute the touch state and eventually generate one of the following events: RTOUCH_PRESS or RTOUCH_RELEASE or RTOUCH_MOVE.

Get the current position of the pen if penIRQ has low value (pen pressed)

Get the current position of the pressed pen

call the callback function

Filter move event if the move is too low

Determine the pen state

Touch pressed: reinit the last time when release

pen is pressed during an enough time : the state change

call the callback function

Touch released: reinit the last time when release

pen is pressed during an enough time : the state change

call the callback function

References DEBOUNCE_TIME, event_handler, g_ul_timepress, g_ul_timerelease, g_ul_timestamp, rtouch_event_struct::panel, POINTS_MAX_ERROR, rtouch_event_struct::raw, rtouch_get_calibrated_point(), rtouch_get_raw_point, rtouch_is_calibrated(), rtouch_is_pressed, RTOUCH_MOVE, RTOUCH_PRESS, RTOUCH_RELEASE, STATE_PEN_DEBOUNCE, STATE_PEN_PRESSED, STATE_PEN_RELEASED, rtouch_point_struct::x, and rtouch_point_struct::y.

Referenced by SysTick_Handler().

void rtouch_set_calibration_parameter ( int32_t  xslope,
int32_t  yslope,
int32_t  rawx,
int32_t  rawy 
)

Set calibration parameters when manual calibration procedure is not performed.

References rtouch_calibration_point_struct::raw, rtouch_point_struct::x, and rtouch_point_struct::y.

void rtouch_set_event_handler ( rtouch_event_handler_t  handler)

Set the touch event handler.

Note
This handler is called whenever the position or state of the touch screen changes. The handler is called from the rtouch_process() function.
Parameters
handlerPointer to the touch event handler, or NULL to disable the handler.

This needs to be an atomic operation, in case an interrupt fires while we change the handler. ENTER_CRITICAL_SECTION( SET_HANDLER );

LEAVE_CRITICAL_SECTION( SET_HANDLER );

Referenced by main().

void rtouch_wait_pressed ( void  )

Wait touch pressed.

Wait for touch & end of conversion

References STATE_PEN_PRESSED, and STATE_PEN_RELEASED.

Referenced by rtouch_calibrate().

void rtouch_wait_released ( void  )

Wait touch released.

Wait for contact loss

References STATE_PEN_PRESSED, and STATE_PEN_RELEASED.

Referenced by rtouch_calibrate().