Microchip® Advanced Software Framework

rtouch.c File Reference

Resistive Touch Service.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include "board.h"
#include "ioport.h"
#include "rtouch.h"

Macros

#define DEBOUNCE_TIME   6 /* 10 * 6 = 60 ms */
 Delay for pushbutton debouncing (the time-base is 10 ms). More...
 
#define MULTI_FACTOR   1024
 The multiplicator value used by the calibration algorithm to avoid working on float values. More...
 
#define POINTS_MAX_ERROR   5
 Maximum difference in pixels between the test point and the measured point. More...
 

Typedefs

typedef enum rtouch_pen_state_enum rtouch_pen_state_t
 Pen state definitions. More...
 

Enumerations

enum  rtouch_pen_state_enum {
  STATE_PEN_RELEASED = 0,
  STATE_PEN_PRESSED = 1,
  STATE_PEN_DEBOUNCE = 2
}
 Pen state definitions. 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...
 
static void rtouch_disable_pen_interrupt (void)
 Disable PEN interrupts. More...
 
void rtouch_enable (void)
 Enable the resistive touch service for touch detection and sampling. More...
 
static void rtouch_enable_pen_interrupt (void)
 Enable PEN interrupts. More...
 
static void rtouch_get_calibrated_point (const rtouch_point_t *p_raw, rtouch_point_t *p_point)
 Interpolate the provided raw measurements using the previously calculated slope. 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...
 
static uint8_t rtouch_is_calibrated (void)
 Indicates if the calibration of the touch screen is Ok. More...
 
static void rtouch_pen_handler (void)
 Handler for PEN interrupts. 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...
 

Variables

static rtouch_calibration_point_t calibration_point_0
 First calibration point (required for processing point). More...
 
static rtouch_event_t event
 Current touch screen event. More...
 
static rtouch_event_handler_t event_handler
 User event handler function pointer. More...
 
static int32_t g_l_xslope
 Slope for interpoling touchscreen measurements along the X-axis. More...
 
static int32_t g_l_yslope
 Slope for interpoling touchscreen measurements along the Y-axis. More...
 
static uint32_t g_ul_height
 
static volatile uint32_t g_ul_is_calibrated = 0
 indicates if the touch screen has been calibrated. More...
 
static volatile uint32_t g_ul_is_rtouch_enabled = 0
 Touch screen enable flag. More...
 
static volatile uint32_t g_ul_timepress = 0
 last time when the pen is pressed on the touchscreen. More...
 
static volatile uint32_t g_ul_timerelease = 0
 last time when the pen is released. More...
 
static volatile uint32_t g_ul_timestamp = 0
 Global g_ul_timestamp in milliseconds since start of application. More...
 
static uint32_t g_ul_width
 Panel size. More...
 
static volatile rtouch_pen_state_t pen_state = STATE_PEN_RELEASED
 Pen current state. More...
 

#define DEBOUNCE_TIME   6 /* 10 * 6 = 60 ms */

Delay for pushbutton debouncing (the time-base is 10 ms).

Referenced by rtouch_process().

#define MULTI_FACTOR   1024

The multiplicator value used by the calibration algorithm to avoid working on float values.

Referenced by rtouch_compute_calibration(), and rtouch_get_calibrated_point().

#define POINTS_MAX_ERROR   5

Maximum difference in pixels between the test point and the measured point.

Referenced by rtouch_compute_calibration(), and rtouch_process().

Pen state definitions.

Pen state definitions.

Enumerator
STATE_PEN_RELEASED 
STATE_PEN_PRESSED 
STATE_PEN_DEBOUNCE 

static void rtouch_disable_pen_interrupt ( void  )
static

Disable PEN interrupts.

Disable the interrupt

References rtouch_disable_interrupt.

Referenced by rtouch_disable().

static void rtouch_enable_pen_interrupt ( void  )
static

Enable PEN interrupts.

Initialize interrupts

Enable the interrupt

References rtouch_enable_interrupt, rtouch_pen_handler(), and rtouch_set_handler.

Referenced by rtouch_enable().

static void rtouch_get_calibrated_point ( const rtouch_point_t p_raw,
rtouch_point_t p_point 
)
static

Interpolate the provided raw measurements using the previously calculated slope.

The resulting x and y coordinates are stored in an array.

Parameters
p_dataRaw measurement data.
p_pointArray in which x and y will be stored.

References g_l_xslope, g_l_yslope, g_ul_height, g_ul_width, MULTI_FACTOR, rtouch_calibration_point_struct::panel, rtouch_calibration_point_struct::raw, rtouch_point_struct::x, and rtouch_point_struct::y.

Referenced by rtouch_compute_calibration(), and rtouch_process().

static uint8_t rtouch_is_calibrated ( void  )
static

Indicates if the calibration of the touch screen is Ok.

Returns
1 calibration Ok, 0 if not.

References g_ul_is_calibrated.

Referenced by rtouch_process().

static void rtouch_pen_handler ( void  )
static

Handler for PEN interrupts.

Check if the touch screen has been pressed

References g_ul_timestamp, rtouch_is_pressed, STATE_PEN_DEBOUNCE, STATE_PEN_PRESSED, and STATE_PEN_RELEASED.

Referenced by rtouch_enable_pen_interrupt().

rtouch_calibration_point_t calibration_point_0
static

First calibration point (required for processing point).

Current touch screen event.

rtouch_event_handler_t event_handler
static

User event handler function pointer.

Referenced by rtouch_get_event_handler(), and rtouch_process().

int32_t g_l_xslope
static

Slope for interpoling touchscreen measurements along the X-axis.

Referenced by rtouch_get_calibrated_point().

int32_t g_l_yslope
static

Slope for interpoling touchscreen measurements along the Y-axis.

Referenced by rtouch_get_calibrated_point().

uint32_t g_ul_height
static
volatile uint32_t g_ul_is_calibrated = 0
static

indicates if the touch screen has been calibrated.

If not, Callback functions are not called.

Referenced by rtouch_is_calibrated().

volatile uint32_t g_ul_is_rtouch_enabled = 0
static

Touch screen enable flag.

volatile uint32_t g_ul_timepress = 0
static

last time when the pen is pressed on the touchscreen.

Referenced by rtouch_process().

volatile uint32_t g_ul_timerelease = 0
static

last time when the pen is released.

Referenced by rtouch_process().

volatile uint32_t g_ul_timestamp = 0
static

Global g_ul_timestamp in milliseconds since start of application.

Referenced by rtouch_pen_handler(), and rtouch_process().

uint32_t g_ul_width
static

Panel size.

Referenced by rtouch_get_calibrated_point().

volatile rtouch_pen_state_t pen_state = STATE_PEN_RELEASED
static

Pen current state.