#include <stdint.h>
#include <stdbool.h>
#include "board.h"
#include "compiler.h"
#include "assert.h"
#include "gpio.h"
#include "intc.h"
#include "rtouch.h"
#include "conf_rtouch.h"
#include "adc.h"
Enumerations | |
enum | rtouch_state_enum { RTOUCH_DISABLED, RTOUCH_NOT_TOUCHED, RTOUCH_READING_XL, RTOUCH_READING_XH, RTOUCH_READING_YL, RTOUCH_READING_YH, RTOUCH_PROCESSING, RTOUCH_TOUCHED } |
Driver state names. More... | |
Functions | |
void | rtouch_adc_int_handler (void) |
ADC conversion complete interrupt handler. More... | |
static void | rtouch_clear_adc_flag (void) |
static void | rtouch_clear_detect_flag (void) |
void | rtouch_compute_calibration_matrix (rtouch_calibration_points_t const *points, rtouch_calibration_matrix_t *matrix) |
Compute a raw coordinate to screen coordinate calibration matrix. More... | |
void | rtouch_detect_int_handler (void) |
Touch screen low-level detect interrupt handler. More... | |
void | rtouch_disable (void) |
Disables the resistive touch screen driver. More... | |
static void | rtouch_disable_adc_int (void) |
Disable interrupts for the touch channels. More... | |
static void | rtouch_disable_detect_int (void) |
void | rtouch_enable (void) |
Enables touch detection of the driver once initialized. More... | |
static void | rtouch_enable_adc_int (void) |
Enable interrupts for the touch channels. More... | |
static void | rtouch_enable_detect_int (void) |
static uint32_t | rtouch_get_adc_value (void) |
Return last converted value. More... | |
void | rtouch_get_calibration_matrix (rtouch_calibration_matrix_t *destination) |
Gets the currently set touch driver calibration matrix. More... | |
void | rtouch_get_event (rtouch_event_t *event) |
Retrieve the last touch event. More... | |
rtouch_event_handler_t | rtouch_get_event_handler (void) |
Gets the currently set touch screen event handler callback function. More... | |
static void | rtouch_gradient_x_surface (void) |
Drive voltage gradient on X surface (XL=GND, XH=VDD). More... | |
static void | rtouch_gradient_y_surface (void) |
Drive voltage gradient on Y surface (YL=GND, YH=VDD). More... | |
static void | rtouch_ground_x_surface (void) |
Drive X lines to ground. More... | |
static void | rtouch_ground_y_surface (void) |
Drive Y lines to ground. More... | |
void | rtouch_init (void) |
static bool | rtouch_is_detect (void) |
Test if a touch is detected. More... | |
bool | rtouch_is_touched (void) |
Determine if the screen is currently being touched. More... | |
static void | rtouch_prepare_adc (void) |
Prepare ADC for touch measuring. More... | |
static void | rtouch_prepare_detect (void) |
Prepare the rtouch detect function. More... | |
static void | rtouch_process_samples (void) |
Called from ADC ISR to compute coordinates from raw samples. More... | |
static void | rtouch_pullup_y_surface (void) |
Enable pull-ups for Y lines. More... | |
static void | rtouch_resample (void) |
Called from rtouch_process_samples or from timer module to start a new sample. More... | |
void | rtouch_set_calibration_matrix (rtouch_calibration_matrix_t const *source) |
Set the touch driver calibration matrix. More... | |
void | rtouch_set_event_handler (rtouch_event_handler_t handler) |
Set the touch screen event handler callback function. More... | |
static void | rtouch_start_read (uint32_t channel) |
static void | rtouch_tristate_x_surface (void) |
static void | rtouch_tristate_y_surface (void) |
Variables | |
struct { | |
rtouch_calibration_matrix_t * calibration_matrix | |
Current calibration matrix. More... | |
rtouch_event_handler_t event_handler | |
Current event handler, NULL if no handler defined. More... | |
rtouch_event_t last_event | |
Last touch event. More... | |
int32_t rawX | |
Temporary raw sample values for X position. More... | |
int32_t rawY | |
Temporary raw sample values for Y position. More... | |
enum rtouch_state_enum state | |
Current driver state. More... | |
} | rtouch |
static const gpio_map_t | rtouch_gpio_xmap |
static const gpio_map_t | rtouch_gpio_ymap |
enum rtouch_state_enum |
Driver state names.
void rtouch_adc_int_handler | ( | void | ) |
ADC conversion complete interrupt handler.
This interrupt handler is called repeatedly as multiple samples are taken from all touch panel lines in proper order. When all samples have been taken, the ISR defers further handling to the TOUCH_ProcessSamples() function.
References Assert, rtouch, RTOUCH_ADC, RTOUCH_ADC_XH_CHANNEL, RTOUCH_ADC_XL_CHANNEL, RTOUCH_ADC_YH_CHANNEL, RTOUCH_ADC_YL_CHANNEL, rtouch_get_adc_value(), rtouch_gradient_x_surface(), rtouch_ground_x_surface(), RTOUCH_OVERSAMPLING, rtouch_process_samples(), RTOUCH_PROCESSING, rtouch_pullup_y_surface(), RTOUCH_READING_XH, RTOUCH_READING_XL, RTOUCH_READING_YH, RTOUCH_READING_YL, rtouch_start_read(), and rtouch_tristate_y_surface().
Referenced by rtouch_prepare_adc().
|
static |
Referenced by rtouch_enable().
|
inlinestatic |
References gpio_clear_pin_interrupt_flag().
Referenced by rtouch_enable(), rtouch_process_samples(), and rtouch_resample().
void rtouch_detect_int_handler | ( | void | ) |
Touch screen low-level detect interrupt handler.
This interrupt handler is called when a low level on the YL/YH lines is detected, which means the panel is touched. The driver sets up and starts a sample of the XL line, and defers further handling to the ADC interrupt.
References Assert, rtouch, RTOUCH_ADC_XL_CHANNEL, rtouch_disable_detect_int(), rtouch_gradient_y_surface(), RTOUCH_NOT_TOUCHED, RTOUCH_READING_XL, rtouch_start_read(), RTOUCH_TOUCHED, and rtouch_tristate_x_surface().
Referenced by rtouch_prepare_detect().
|
inlinestatic |
Disable interrupts for the touch channels.
References RTOUCH_ADC, RTOUCH_ADC_XH_CHANNEL, RTOUCH_ADC_XL_CHANNEL, RTOUCH_ADC_YH_CHANNEL, and RTOUCH_ADC_YL_CHANNEL.
Referenced by rtouch_disable().
|
inlinestatic |
References gpio_clear_pin_interrupt_flag(), and gpio_disable_pin_interrupt().
Referenced by rtouch_detect_int_handler(), and rtouch_disable().
|
inlinestatic |
Enable interrupts for the touch channels.
References RTOUCH_ADC, RTOUCH_ADC_XH_CHANNEL, RTOUCH_ADC_XL_CHANNEL, RTOUCH_ADC_YH_CHANNEL, and RTOUCH_ADC_YL_CHANNEL.
Referenced by rtouch_enable().
|
inlinestatic |
References gpio_enable_pin_interrupt(), and GPIO_FALLING_EDGE.
Referenced by rtouch_enable(), rtouch_process_samples(), and rtouch_resample().
|
inlinestatic |
Return last converted value.
References ADCIFA_read_resx_sequencer_0, and RTOUCH_ADC.
Referenced by rtouch_adc_int_handler().
|
inlinestatic |
Drive voltage gradient on X surface (XL=GND, XH=VDD).
References gpio_clr_gpio_pin(), gpio_disable_pin_pull_up(), gpio_enable_gpio_pin(), and gpio_set_gpio_pin().
Referenced by rtouch_adc_int_handler().
|
inlinestatic |
Drive voltage gradient on Y surface (YL=GND, YH=VDD).
References gpio_clr_gpio_pin(), gpio_disable_pin_pull_up(), gpio_enable_gpio_pin(), and gpio_set_gpio_pin().
Referenced by rtouch_detect_int_handler(), and rtouch_resample().
|
inlinestatic |
Drive X lines to ground.
References gpio_clr_gpio_pin(), and gpio_enable_gpio_pin().
Referenced by rtouch_adc_int_handler(), rtouch_disable(), and rtouch_enable().
|
inlinestatic |
Drive Y lines to ground.
References gpio_clr_gpio_pin(), and gpio_enable_gpio_pin().
Referenced by rtouch_disable().
|
inlinestatic |
Test if a touch is detected.
Checks if one of the Y lines is pulled low due to a touch on the surface. The Y lines must be pulled up and the X lines must be GND in order to work.
true
if a touch is detected and false
if no touch is detected. References gpio_get_pin_value().
Referenced by rtouch_process_samples(), and rtouch_resample().
|
inlinestatic |
Prepare ADC for touch measuring.
Register the interrupt handler, set sample, hold and startup time.
References adcifa_configure(), Disable_global_interrupt, Enable_global_interrupt, INTC_register_interrupt(), RTOUCH_ADC, rtouch_adc_int_handler(), RTOUCH_ADC_INT_LEVEL, and RTOUCH_ADC_IRQ.
Referenced by rtouch_init().
|
inlinestatic |
Prepare the rtouch detect function.
A touch can be detected by setting the Y lines (or X lines) as inputs and enabling the internal pull-ups for these pins. The other lines, X in this case are connected to GND. By a touch the Y lines will be pulled low and an interrupt can be triggered on a low level detect.
This function does the registering of the interrupt handler for the touch detect. Currently we use a GPIO interrupt, but here it is only possible to trigger on edges but actually we should trigger on a low level. Anyway this should work too. Here we use the YL line as source input for the edge detection but it is also possible to use YH.
References Disable_global_interrupt, Enable_global_interrupt, INTC_register_interrupt(), and rtouch_detect_int_handler().
Referenced by rtouch_init().
|
static |
Called from ADC ISR to compute coordinates from raw samples.
This function takes care of the final processing and calibration of the raw panel sample values, or lack of touch.
This function is called by the ADC interrupt handler.
This function will also automatically start a resample of the panel, either immediately or delayed via the timer module, depending on the TOUCH_USE_IMMEDIATE_RESAMPLE setting from "config_touch.h".
References NULL, rtouch, rtouch_clear_detect_flag(), rtouch_enable_detect_int(), rtouch_is_detect(), RTOUCH_MOVE, RTOUCH_NO_EVENT, RTOUCH_NOT_TOUCHED, RTOUCH_PRESS, RTOUCH_RELEASE, rtouch_resample(), RTOUCH_SAMPLESCALE, and RTOUCH_TOUCHED.
Referenced by rtouch_adc_int_handler().
|
inlinestatic |
Enable pull-ups for Y lines.
Used to be able to trigger an interrupt upon a touch.
References gpio_enable_gpio_pin(), and gpio_enable_pin_pull_up().
Referenced by rtouch_adc_int_handler(), and rtouch_enable().
|
static |
Called from rtouch_process_samples or from timer module to start a new sample.
This function starts a new sampling of the touch panel.
It will be called by the driver repeatedly as long as the touch panel stays touched.
References Assert, NULL, rtouch, RTOUCH_ADC_XL_CHANNEL, rtouch_clear_detect_flag(), rtouch_enable_detect_int(), rtouch_gradient_y_surface(), rtouch_is_detect(), RTOUCH_NOT_TOUCHED, RTOUCH_READING_XL, RTOUCH_RELEASE, rtouch_start_read(), RTOUCH_TOUCHED, and rtouch_tristate_x_surface().
Referenced by rtouch_process_samples().
|
static |
References adcifa_configure_sequencer(), ADCIFA_SHG_1, adcifa_start_sequencer(), AVR32_ADCIFA_INN_GNDANA, AVR32_ADCIFA_INP_GNDANA, adcifa_sequencer_conversion_opt_t::channel_n, adcifa_sequencer_conversion_opt_t::channel_p, adcifa_sequencer_conversion_opt_t::gain, RTOUCH_ADC, RTOUCH_ADC_XH_CHANNEL, RTOUCH_ADC_XL_CHANNEL, RTOUCH_ADC_YH_CHANNEL, and RTOUCH_ADC_YL_CHANNEL.
Referenced by rtouch_adc_int_handler(), rtouch_detect_int_handler(), and rtouch_resample().
|
inlinestatic |
References gpio_disable_pin_pull_up(), gpio_enable_gpio_pin(), and gpio_enable_module_pin().
Referenced by rtouch_detect_int_handler(), and rtouch_resample().
|
inlinestatic |
References gpio_disable_pin_pull_up(), gpio_enable_gpio_pin(), and gpio_enable_module_pin().
Referenced by rtouch_adc_int_handler().
rtouch_calibration_matrix_t* calibration_matrix |
Current calibration matrix.
rtouch_event_handler_t event_handler |
Current event handler, NULL if no handler defined.
Referenced by main().
rtouch_event_t last_event |
Last touch event.
int32_t rawX |
Temporary raw sample values for X position.
int32_t rawY |
Temporary raw sample values for Y position.
struct { ... } rtouch |
Referenced by rtouch_adc_int_handler(), rtouch_detect_int_handler(), rtouch_disable(), rtouch_enable(), rtouch_get_calibration_matrix(), rtouch_get_event(), rtouch_get_event_handler(), rtouch_init(), rtouch_is_touched(), rtouch_process_samples(), rtouch_resample(), rtouch_set_calibration_matrix(), and rtouch_set_event_handler().
|
static |
|
static |
enum rtouch_state_enum state |
Current driver state.
Referenced by decode_mcu(), decode_mcu_DC_first(), main(), navauto_mov_explorer(), navauto_mov_playlist(), navauto_open(), navauto_setpos(), netif_add(), rtouch_calibrate(), and sd_mmc_select_slot().