Microchip® Advanced Software Framework

qtouch_example.c File Reference
#include "compiler.h"
#include "conf_example.h"
#include "gpio.h"
#include "sysclk.h"
#include "tc.h"
#include "intc.h"
#include "touch_api.h"

Macros

#define PORTA   (((volatile avr32_gpio_port_t *) &AVR32_GPIO) + 0)
 
#define PORTB   (((volatile avr32_gpio_port_t *) &AVR32_GPIO) + 1)
 
#define PORTC   (((volatile avr32_gpio_port_t *) &AVR32_GPIO) + 2)
 
SENSOR STATE CONFIGURATIONS
#define GET_SENSOR_STATE(SENSOR_NUMBER)   qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8))
 To get the sensor state that it is in detect or not. More...
 
#define GET_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER)   qt_measure_data.qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER]
 To get the rotor angle or slider position. More...
 

Functions

static void config_keys (void)
 prototypes for rotor_slider configuration for various channels More...
 
static void config_sensors (void)
 Configure the sensors. More...
 
static void init_timer_isr (void)
 Configures ISR to fire regularly. More...
 
 ISR (tc_irq, GRP, LVL)
 TIMER ISR. More...
 
int main (void)
 Main Application Code. More...
 
int16_t qt_get_sensor_delta (uint8_t sensor)
 Get sensor delta values. More...
 
static void qt_set_parameters (void)
 Initializes configuration data for processing. More...
 
static void qtouch_init (void)
 Initializes the necessary parameters for QTouch library. More...
 

Variables

static volatile uint16_t current_time_ms_touch = 0u
 
qt_touch_lib_measure_data_tpqt_measure_data = &qt_measure_data
 Output can be observed in the watch window using this pointer. More...
 
qt_touch_lib_config_data_t qt_config_data
 This configuration data structure parameters if needs to be changed will be changed in the qt_set_parameters function. More...
 
qt_touch_lib_measure_data_t qt_measure_data
 Touch Measurement data. More...
 
uint16_t qt_measurement_period_msec = 25u
 timer period in msec. More...
 
static volatile uint8_t time_to_measure_touch = 0u
 
uint16_t timestamp1_hword
 
uint16_t timestamp1_lword
 
uint16_t timestamp2_hword
 
uint16_t timestamp2_lword
 
uint16_t timestamp3_hword
 
uint16_t timestamp3_lword
 

#define GET_ROTOR_SLIDER_POSITION (   ROTOR_SLIDER_NUMBER)    qt_measure_data.qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER]

To get the rotor angle or slider position.

These values are valid only when the sensor state for corresponding rotor or slider shows in detect.

Parameters
ROTOR_SLIDER_NUMBERfor which the position to be known
Returns
Returns rotor angle or sensor position
#define GET_SENSOR_STATE (   SENSOR_NUMBER)    qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8))

To get the sensor state that it is in detect or not.

Parameters
SENSOR_NUMBERfor which the state to be detected
Returns
Returns either 0 or 1 If the bit value is 0, it is not in detect If the bit value is 1, it is in detect
#define PORTA   (((volatile avr32_gpio_port_t *) &AVR32_GPIO) + 0)
#define PORTB   (((volatile avr32_gpio_port_t *) &AVR32_GPIO) + 1)
#define PORTC   (((volatile avr32_gpio_port_t *) &AVR32_GPIO) + 2)

static void config_keys ( void  )
static

prototypes for rotor_slider configuration for various channels

Configure the sensors as keys only.

Configure the sensors for Keys configuration

Referenced by config_sensors().

static void config_sensors ( void  )
static

Configure the sensors.

Configure the QTouch sensors.

References config_keys().

Referenced by qtouch_init().

void init_timer_isr ( void  )
static

Configures ISR to fire regularly.

Function to initialize the Timer/Counter module in Waveform mode.

It fires the ISR at regular intervals to start QTouch Acquisition.

References tc_waveform_opt_t::channel, tc_interrupt_t::etrgs, irq_initialize_vectors, irq_register_handler, sysclk_get_pba_hz(), TC_CHANNEL, 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, and tc_write_rc().

Referenced by main().

ISR ( tc_irq  ,
GRP  ,
LVL   
)

TIMER ISR.

Parameters
tc_irqis the subroutine function name
GRPis the group under which the interrupt lies
LVLis the priority level assigned for the group

References current_time_ms_touch, qt_measurement_period_msec, TC_CHANNEL, tc_read_sr(), and time_to_measure_touch.

int main ( void  )

Main Application Code.

  • Initialize the system clocks
  • Initialize the touch functions
  • Initialize the timer
  • if debug interface is enabled, initialize the qdebug commmands
  • When touch status in detect, Set the led & send data to QTouch Studio

Initialize the system clock Clock settings are done in cof_clock.h It sets the cpu to run at crystal frequency which uses OSC0 as souce

Initializes the functions necessary for QTouch

Configure the timer ISR to fire regularly for QTouch Acquisition

Address to pass address of user functions

This function is called after the library has made capacitive measurements, but before it has processed them. The user can use this hook to apply filter functions to the measured signal values.(Possibly to fix sensor layout faults)

References cpu_irq_enable, current_time_ms_touch, gpio_clr_gpio_pin(), gpio_set_gpio_pin(), init_timer_isr(), qt_filter_callback, qt_measure_sensors(), tag_qt_touch_lib_measure_data_t::qt_touch_status, QTLIB_BURST_AGAIN, qtouch_init(), tag_qt_touch_status_t::sensor_states, sysclk_init(), and time_to_measure_touch.

int16_t qt_get_sensor_delta ( uint8_t  sensor)

Get sensor delta values.

static void qt_set_parameters ( void  )
static

Initializes configuration data for processing.

Initialize configuration data for processing This will fill the default threshold values in the configuration data structure.But User can change the values of these parameters.

This will fill the default threshold values in the configuration data structure.But User can change the values of these parameters. Values can be changed in "touch_api.h"

Values can be changed in "touch_api.h"

This can be modified by the user to different values

References DEF_QT_DI, DEF_QT_DRIFT_HOLD_TIME, DEF_QT_MAX_ON_DURATION, DEF_QT_NEG_DRIFT_RATE, DEF_QT_POS_DRIFT_RATE, DEF_QT_POS_RECAL_DELAY, DEF_QT_RECAL_THRESHOLD, tag_qt_touch_lib_config_data_t::qt_di, tag_qt_touch_lib_config_data_t::qt_drift_hold_time, tag_qt_touch_lib_config_data_t::qt_max_on_duration, tag_qt_touch_lib_config_data_t::qt_neg_drift_rate, tag_qt_touch_lib_config_data_t::qt_pos_drift_rate, tag_qt_touch_lib_config_data_t::qt_pos_recal_delay, and tag_qt_touch_lib_config_data_t::qt_recal_threshold.

Referenced by qtouch_init().

static void qtouch_init ( void  )
static

Initializes the necessary parameters for QTouch library.

Initialize QTouch Configuration and sensors.

Configures sensors for rotor, slider or for button based on the options given in the SYMBOLS

References config_sensors(), qt_init_sensing, and qt_set_parameters().

Referenced by main().

volatile uint16_t current_time_ms_touch = 0u
static

Referenced by ISR(), and main().

Output can be observed in the watch window using this pointer.

This configuration data structure parameters if needs to be changed will be changed in the qt_set_parameters function.

qt_touch_lib_measure_data_t qt_measure_data

Touch Measurement data.

volatile uint8_t time_to_measure_touch = 0u
static

Referenced by ISR(), and main().

uint16_t timestamp1_hword
uint16_t timestamp1_lword
uint16_t timestamp2_hword
uint16_t timestamp2_lword
uint16_t timestamp3_hword
uint16_t timestamp3_lword