Microchip® Advanced Software Framework

qtouch_demo.c File Reference

SAM4S-Xplained QTouch and LED demonstration.

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

#include "asf.h"
#include "conf_example.h"

Macros

#define DEFAULT_LED_FREQ   4
 Set default LED blink period to 250ms*3. More...
 
#define GET_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER)
 
#define GET_SENSOR_STATE(SENSOR_NUMBER)
 
#define LED_BLINK_PERIOD   3
 LED blink period. More...
 
#define LED_FREQ_DIV   3
 frequency divider for LED blinking More...
 
#define QT_MAX_DATA   255
 QTouch max data value. More...
 
#define QTOUCH_LIB_COMPILER_MASK   0x01
 QTouch library compiler type mask. More...
 
#define QTOUCH_LIB_COMPILER_OFFSET   2
 QTouch library compiler type offset: GCC / IAR. More...
 
#define QTOUCH_LIB_KEY_ONLY_MASK   0x01
 QTouch library supports keys only mask. More...
 
#define QTOUCH_LIB_KEY_ONLY_OFFSET   10
 QTouch library supports keys only offset. More...
 
#define QTOUCH_LIB_MAX_CHANNEL_MASK   0x7F
 QTouch library maximum channels mask. More...
 
#define QTOUCH_LIB_MAX_CHANNEL_OFFSET   3
 QTouch library maximum channels offset. More...
 
#define QTOUCH_LIB_ROTOR_NUM_MASK   0x1F
 QTouch library maximum rotors/sliders mask. More...
 
#define QTOUCH_LIB_ROTOR_NUM_OFFSET   11
 QTouch library maximum rotors/sliders offset. More...
 
#define QTOUCH_LIB_TPYE_MASK   0x01
 QTouch library type: QTouch / QMatrix. More...
 

Functions

static void config_sensors (void)
 Configure the sensors. More...
 
static void configure_tc (uint32_t freq)
 Configure Timer Counter 0 to generate an interrupt with the specific frequency. More...
 
static void init_system (void)
 initialize pins, watchdog, etc. More...
 
static void init_timer_isr (void)
 Configure timer ISR to fire regularly. More...
 
int main (void)
 getting-started Application entry point. More...
 
static void qt_set_parameters (void)
 This will fill the default threshold values in the configuration data structure.But User can change the values of these parameters. More...
 
void SysTick_Handler (void)
 Handler for System Tick interrupt. More...
 
void TC0_Handler (void)
 Interrupt handler for TC0 interrupt. More...
 

Variables

static volatile uint16_t current_time_ms_touch = 0u
 Current time, set by timer ISR. More...
 
static volatile uint32_t led_blink_period = 0
 LED blink period. More...
 
uint16_t qt_measurement_period_msec = 25u
 Timer period in msec. More...
 
uint32_t qt_shift_data = 0
 Shift data gotten from the QTouch. More...
 
static volatile uint8_t time_to_measure_touch = 0u
 Flag set by timer ISR when it's time to measure touch. More...
 

#define DEFAULT_LED_FREQ   4

Set default LED blink period to 250ms*3.

Referenced by init_system().

#define GET_ROTOR_SLIDER_POSITION (   ROTOR_SLIDER_NUMBER)
Value:
qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER]
qt_touch_lib_measure_data_t qt_measure_data
measurement data.

Referenced by main().

#define GET_SENSOR_STATE (   SENSOR_NUMBER)
Value:
sensor_states[(SENSOR_NUMBER / \
8)] & (1 << (SENSOR_NUMBER % 8)))
qt_touch_lib_measure_data_t qt_measure_data
measurement data.
qt_touch_status_t qt_touch_status
state of sensors.
Definition: touch_api.h:899
#define LED_BLINK_PERIOD   3

LED blink period.

Referenced by TC0_Handler().

#define LED_FREQ_DIV   3

frequency divider for LED blinking

Referenced by main().

#define QT_MAX_DATA   255

QTouch max data value.

Referenced by main().

#define QTOUCH_LIB_COMPILER_MASK   0x01

QTouch library compiler type mask.

#define QTOUCH_LIB_COMPILER_OFFSET   2

QTouch library compiler type offset: GCC / IAR.

#define QTOUCH_LIB_KEY_ONLY_MASK   0x01

QTouch library supports keys only mask.

#define QTOUCH_LIB_KEY_ONLY_OFFSET   10

QTouch library supports keys only offset.

#define QTOUCH_LIB_MAX_CHANNEL_MASK   0x7F

QTouch library maximum channels mask.

#define QTOUCH_LIB_MAX_CHANNEL_OFFSET   3

QTouch library maximum channels offset.

#define QTOUCH_LIB_ROTOR_NUM_MASK   0x1F

QTouch library maximum rotors/sliders mask.

#define QTOUCH_LIB_ROTOR_NUM_OFFSET   11

QTouch library maximum rotors/sliders offset.

#define QTOUCH_LIB_TPYE_MASK   0x01

QTouch library type: QTouch / QMatrix.

static void config_sensors ( void  )
static

Configure the sensors.

References AKS_GROUP_1, HYST_6_25, and RES_8_BIT.

Referenced by main().

static void configure_tc ( uint32_t  freq)
static

Configure Timer Counter 0 to generate an interrupt with the specific frequency.

Parameters
freqTimer counter frequency.

Configure TC with the frequency and trigger on RC compare.

Start the counter.

References sysclk_get_cpu_hz(), tc_disable_interrupt(), tc_enable_interrupt(), tc_find_mck_divisor(), tc_init(), tc_start(), tc_stop(), and tc_write_rc().

Referenced by init_system(), and main().

static void init_system ( void  )
static

initialize pins, watchdog, etc.

References configure_tc(), DEFAULT_LED_FREQ, gpio_configure_pin, pmc_enable_periph_clk(), sysclk_init(), and wdt_disable().

Referenced by main().

static void init_timer_isr ( void  )
static

Configure timer ISR to fire regularly.

References qt_measurement_period_msec, and sysclk_get_cpu_hz().

Referenced by main().

void SysTick_Handler ( void  )

Handler for System Tick interrupt.

Process System Tick Event

References current_time_ms_touch, qt_measurement_period_msec, and time_to_measure_touch.

void TC0_Handler ( void  )

Interrupt handler for TC0 interrupt.

Toggles the state of LEDs.

Toggle LED state.

References gpio_toggle_pin, LED_BLINK_PERIOD, led_blink_period, and tc_get_status().

volatile uint16_t current_time_ms_touch = 0u
static

Current time, set by timer ISR.

volatile uint32_t led_blink_period = 0
static

LED blink period.

Referenced by TC0_Handler().

uint32_t qt_shift_data = 0

Shift data gotten from the QTouch.

Referenced by main().

volatile uint8_t time_to_measure_touch = 0u
static

Flag set by timer ISR when it's time to measure touch.