Microchip® Advanced Software Framework

touch.c File Reference

UC3-A3 Xplained Application Touch functions.

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

#include "board.h"
#include "gpio.h"
#include "sysclk.h"
#include "tc.h"
#include "uc3-a3_xplained_demo.h"
#include "touch_api.h"
#include "QDebug.h"
#include "QDebugTransport.h"

Macros

#define _DEBUG_INTERFACE_
 
#define TOUCH_MEASUREMENT_PERIOD_MS   25
 
#define TOUCH_MEASUREMENT_TC   (&AVR32_TC1)
 
#define TOUCH_MEASUREMENT_TC_CHANNEL   0
 
#define TOUCH_MEASUREMENT_TC_IRQ   AVR32_TC1_IRQ0
 
#define TOUCH_MEASUREMENT_TC_IRQ_GROUP   AVR32_TC1_IRQ_GROUP
 

Functions

static void init_timer (void)
 Initializes the touch measurement timer. More...
 
 ISR (tc_irq, TOUCH_MEASUREMENT_TC_IRQ_GROUP, AVR32_INTC_INT0)
 Touch measurement timer interrupt. More...
 
static void qt_set_parameters (void)
 Initializes the touch library configuration. More...
 
void touch_handler (void)
 Measure touch sensors and do appropriate action. More...
 
void touch_init (void)
 Initialize touch sensors. More...
 

Variables

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...
 
static volatile bool time_to_measure_touch = true
 Touch measurement flag. More...
 

#define _DEBUG_INTERFACE_
#define TOUCH_MEASUREMENT_PERIOD_MS   25
#define TOUCH_MEASUREMENT_TC   (&AVR32_TC1)

Referenced by init_timer(), and ISR().

#define TOUCH_MEASUREMENT_TC_CHANNEL   0

Referenced by init_timer(), and ISR().

#define TOUCH_MEASUREMENT_TC_IRQ   AVR32_TC1_IRQ0

Referenced by init_timer().

#define TOUCH_MEASUREMENT_TC_IRQ_GROUP   AVR32_TC1_IRQ_GROUP

static void init_timer ( void  )
static

Initializes the touch measurement timer.

We need a timer that triggers approx. every millisecond. The touch library seems to need 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: toggle.

RA compare effect on TIOA: toggle.

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_enable_peripheral_clock(), sysclk_get_pba_hz(), TC_CLOCK_SOURCE_TC3, tc_configure_interrupts(), TC_EVT_EFFECT_NOOP, tc_init_waveform(), tc_interrupt, 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 touch_init().

ISR ( tc_irq  ,
TOUCH_MEASUREMENT_TC_IRQ_GROUP  ,
AVR32_INTC_INT0   
)

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 ms.

References current_time_ms, measurement_period_ms, tc_read_sr(), time_to_measure_touch, TOUCH_MEASUREMENT_TC, and TOUCH_MEASUREMENT_TC_CHANNEL.

void touch_init ( void  )

Initialize touch sensors.

The touch channels are connected on the GPIO controller 4 which is a part of port X

Touch Button: GPIO 98 SNSK1 CHANNEL1_SNS 99 SNS1 CHANNEL1_SNSK

Touch Slider: 100 SNS0 CHANNEL2_SNS 101 SNSK0 CHANNEL2_SNSK 102 SNS1 CHANNEL3_SNS 103 SNSK1 CHANNEL3_SNSK 104 SNS2 CHANNEL4_SNS 105 SNSK2 CHANNEL4_SNSK

References CHANNEL_1, CHANNEL_2, CHANNEL_4, HYST_12_5, init_timer(), NO_AKS_GROUP, QDebug_Init(), QDebug_ProcessCommands(), qt_enable_key(), qt_enable_slider(), qt_init_sensing, qt_set_parameters(), RES_8_BIT, and sysclk_enable_peripheral_clock().

Referenced by main().

volatile uint16_t current_time_ms = 0
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.

Needs to be global since it is required for the QDebug module.

Referenced by ISR(), Set_Measurement_Period(), and Transmit_Global_Config().

volatile bool time_to_measure_touch = true
static

Touch measurement flag.

Indicates when a new touch measurement should be done. This is set in the timer ISR so this must be volatile.

Referenced by ISR(), and touch_handler().