UC3-L0 Xplained demo touch handler.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include "compiler.h"
#include "board.h"
#include "gpio.h"
#include "sysclk.h"
#include "scif_uc3l.h"
#include "tc.h"
#include "pwma.h"
#include "print_funcs.h"
#include "touch_config_at32uc3l.h"
#include "touch_api_at32uc3l.h"
#include "uc3-l0_xplained_demo.h"
#include "QDebug_at32uc3l.h"
Macros | |
#define | TOUCH_MEASUREMENT_PERIOD_MS 25 |
#define | TOUCH_MEASUREMENT_TC (&AVR32_TC0) |
#define | TOUCH_MEASUREMENT_TC_CHANNEL 0 |
#define | TOUCH_MEASUREMENT_TC_IRQ AVR32_TC0_IRQ0 |
#define | TOUCH_MEASUREMENT_TC_IRQ_GROUP AVR32_TC0_IRQ_GROUP |
Functions | |
static void | handle_touch_error (touch_ret_t touch_error) |
handles errors during touch acquisition in the touch library. More... | |
static void | init_timer (void) |
Initializes the touch measurement timer. More... | |
void | init_touch (void) |
Initializes the touch library ready for acquisition of touch data. More... | |
ISR (tc_irq, TOUCH_MEASUREMENT_TC_IRQ_GROUP, 1) | |
Touch measurement timer interrupt. More... | |
static void | touch_at_status_change_callback (touch_at_status *at_status) |
Callback for autonomous touch status changes. More... | |
void | touch_handler (void) |
static void | touch_qm_measurement_complete_callback (touch_measure_data_t *measured_data) |
QMatrix measurement complete callback. More... | |
Variables | |
static volatile bool | autonomous_qtouch_in_touch = false |
Touch detection flag for autonomous touch. More... | |
static volatile uint16_t | current_time_ms = 0 |
Current time in ms. More... | |
uint16_t | measurement_period_ms = TOUCH_MEASUREMENT_PERIOD_MS |
Time measurement period in ms. More... | |
touch_measure_data_t * | p_qm_measure_data = NULL |
Pointer to the measured data. More... | |
bool | p_qm_measurement_done = false |
Touch measurement complete flag. More... | |
static led_pwm_channel_t | rgb_led = PWM_CHANNEL_RED |
Currently selected RGB LED to manipulate. More... | |
static volatile bool | time_to_measure_touch = false |
Touch measurement flag. More... | |
uint8_t | qm_burst_length [QM_NUM_CHANNELS] |
The below data is required for the QTouch library. More... | |
static uint8_t | qm_data_blk [PRIV_QM_DATA_BLK_SIZE] |
QMatrix Data block provided as input to the QTouch library. More... | |
static touch_qm_config_t | qm_config |
QMatrix configuration input. More... | |
static touch_at_config_t | at_config |
Autonomous Touch configuration input. More... | |
static touch_general_config_t | touch_common_config |
General touch configuration values. More... | |
static touch_config_t | touch_config |
Main touch library configuration options. More... | |
static touch_qm_dma_t | qm_dma |
Touch DMA configuration options. More... | |
#define TOUCH_MEASUREMENT_PERIOD_MS 25 |
#define TOUCH_MEASUREMENT_TC (&AVR32_TC0) |
Referenced by init_timer(), and ISR().
#define TOUCH_MEASUREMENT_TC_CHANNEL 0 |
Referenced by init_timer(), and ISR().
#define TOUCH_MEASUREMENT_TC_IRQ AVR32_TC0_IRQ0 |
Referenced by init_timer().
#define TOUCH_MEASUREMENT_TC_IRQ_GROUP AVR32_TC0_IRQ_GROUP |
|
static |
handles errors during touch acquisition in the touch library.
Write debug messages to the debug USART to indicate the problem that occurred.
References print_dbg(), print_dbg_hex(), TOUCH_ACQ_INCOMPLETE, TOUCH_INVALID_AT_CONFIG_PARAM, TOUCH_INVALID_INPUT_PARAM, TOUCH_INVALID_LIB_STATE, and TOUCH_INVALID_QM_CONFIG_PARAM.
Referenced by init_touch(), and touch_handler().
|
static |
Initializes the touch measurement timer.
We need a timer that triggers approx. every millisecond. The touch library needs this as time-base.
Software trigger effect on TIOB.
External event effect on TIOB.
RC compare effect on TIOB.
RB compare effect on TIOB.
Software trigger effect on TIOA.
External event effect on TIOA.
RC compare effect on TIOA.
RA compare effect on TIOA.
Waveform selection
External event trigger enable.
External event selection.
External event edge selection.
Counter disable when RC compare.
Counter clock stopped with RC compare.
Burst signal selection.
Clock inversion selection.
Internal source clock 3 (fPBA / 8).
References tc_waveform_opt_t::channel, Disable_global_interrupt, Enable_global_interrupt, tc_interrupt_t::etrgs, INTC_register_interrupt(), sysclk_get_pba_hz(), TC_CLOCK_SOURCE_TC3, tc_configure_interrupts(), TC_EVT_EFFECT_NOOP, tc_init_waveform(), tc_irq(), TC_SEL_NO_EDGE, tc_start(), TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, tc_write_rc(), TOUCH_MEASUREMENT_TC, TOUCH_MEASUREMENT_TC_CHANNEL, and TOUCH_MEASUREMENT_TC_IRQ.
Referenced by init_touch().
void init_touch | ( | void | ) |
Initializes the touch library ready for acquisition of touch data.
Sets up all required hardware and initializes the touch library.
References Disable_global_interrupt, Enable_global_interrupt, handle_touch_error(), HYST_12_5, HYST_6_25, init_timer(), INTC_register_interrupt(), NO_AKS_GROUP, QDebug_Init(), QM_GCLK_CAT_DIV, RES_1_BIT, RES_8_BIT, scif_gc_enable(), scif_gc_setup(), SCIF_GCCTRL_DFLL0, SENSOR_TYPE_KEY, SENSOR_TYPE_SLIDER, sysclk_enable_hsb_module(), sysclk_enable_peripheral_clock(), SYSCLK_EVENT, touch_at_sensor_enable(), touch_at_sensor_init(), touch_at_status_change_callback(), touch_qm_sensor_config(), touch_qm_sensors_calibrate(), touch_qm_sensors_init, and TOUCH_SUCCESS.
Referenced by main().
ISR | ( | tc_irq | , |
TOUCH_MEASUREMENT_TC_IRQ_GROUP | , | ||
1 | |||
) |
Touch measurement timer interrupt.
Initiates periodically touch measurements. Triggers every 1ms and will set the flag time_to_measure_touch every TOUCH_MEASUREMENT_PERIOD_MS.
References current_time_ms, measurement_period_ms, tc_read_sr(), time_to_measure_touch, TOUCH_MEASUREMENT_TC, and TOUCH_MEASUREMENT_TC_CHANNEL.
|
static |
Callback for autonomous touch status changes.
at_status | Pointer to autonomous touch status data. |
References autonomous_qtouch_in_touch, IN_TOUCH, PWM_CHANNEL_BLUE, PWM_CHANNEL_GREEN, PWM_CHANNEL_RED, rgb_led, and tag_touch_at_status_t::status_change.
Referenced by init_touch().
void touch_handler | ( | void | ) |
References tag_touch_measure_data_t::acq_status, current_time_ms, handle_touch_error(), NORMAL_ACQ_MODE, p_qm_measurement_done, tag_touch_measure_data_t::p_rotor_slider_values, tag_touch_measure_data_t::p_sensor_states, pwma_set_channels_value(), QDebug_ProcessCommands(), QDebug_SendData(), rgb_led, time_to_measure_touch, touch_event_dispatcher(), touch_qm_measurement_complete_callback(), touch_qm_sensors_start_acquisition(), and TOUCH_SUCCESS.
Referenced by main().
|
static |
QMatrix measurement complete callback.
This function will be called from the touch library each time a measurement is completed.
measured_data | Pointer to the measured data. |
References p_qm_measurement_done.
Referenced by touch_handler().
|
static |
Autonomous Touch configuration input.
Touch detection flag for autonomous touch.
This flag will be set in the touch library callback function for the autonomous touch when a touch change was detected. This must be volatile since the callback will be called from an ISR.
|
static |
Current time in ms.
This is required for the touch library. The time is updated in the timer ISR so this must be volatile.
Referenced by ISR(), and touch_handler().
uint16_t measurement_period_ms = TOUCH_MEASUREMENT_PERIOD_MS |
Time measurement period in ms.
Touch Measurement period in milliseconds.
Needs to be global since it is required for the QDebug module.
touch_measure_data_t* p_qm_measure_data = NULL |
Pointer to the measured data.
QMatrix measured data pointer.
Needs to be global since it is required for the QDebug module.
Touch measurement complete flag.
This flag is set by the touch library callback function once a touch measurement is completed.
Referenced by touch_handler(), and touch_qm_measurement_complete_callback().
uint8_t qm_burst_length[QM_NUM_CHANNELS] |
The below data is required for the QTouch library.
Do not alter these here since they are usually configured via the touch_config_at32uc3l.hQMatrix burst length.
Specify the number of QMatrix burst pulses for each channel. In order to disable bursting on a individual channel, a value of 1u has to be specified.
When the burst length value corresponding to (X0,Y1),(X0,Y2)...(Xn,Yn) are same or set to 0x01(disabled), enabling the 1k ohm resistive drive on Y lines is optional.
|
static |
QMatrix configuration input.
|
static |
QMatrix Data block provided as input to the QTouch library.
|
static |
Touch DMA configuration options.
Referenced by main().
|
static |
Currently selected RGB LED to manipulate.
This enum indicates the currently selected RGB, whose brightness will be altered by a touch of the board's slider control.
Referenced by touch_at_status_change_callback(), and touch_handler().
Touch measurement flag.
Indicates when a new touch measurement should be done. This is set in the timer ISR so this must be volatile.
|
static |
General touch configuration values.
|
static |
Main touch library configuration options.