Microchip® Advanced Software Framework

thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c File Reference
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "tc.h"
#include "intc.h"
#include "touch_api_at32uc3l.h"

Macros

Example Timer configuration settings.

Includes for Clock and Timer.

Includes for Touch Library.

#define EXAMPLE_TC   (&AVR32_TC0)
 timer number. More...
 
#define EXAMPLE_TC_IRQ_GROUP   (AVR32_TC0_IRQ_GROUP)
 timer irq group. More...
 
#define EXAMPLE_TC_IRQ   (AVR32_TC0_IRQ0)
 timer irq. More...
 
#define EXAMPLE_TC_CHANNEL   (0u)
 timer channel. More...
 
#define EXAMPLE_RC_VALUE   (6000u)
 set RC value for 1ms tick. More...
 
Example Clock configuration settings.

Note: The QDebug protocol USART clock settings are available in qdebug/Serial.h. When modifying the EXAMPLE_CPUCLK_HZ clock, care must be taken to modify the TARGET_PBA_FREQ_HZ and TARGET_CPU_FREQ_HZ defines in the Serial.h file for the QDebug protocol to work correctly.

#define EXAMPLE_TARGET_DFLL_FREQ_HZ   (96000000)
 DFLL target frequency, in Hz. More...
 
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ   (48000000)
 MCU clock target frequency, in Hz. More...
 
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   (48000000)
 PBA clock target frequency, in Hz. More...
 
#define EXAMPLE_TARGET_PBBCLK_FREQ_HZ   (48000000)
 PBA clock target frequency, in Hz. More...
 

Functions

static touch_ret_t config_64ch_touch_keys_rotors_sliders (void)
 Example configuration for touch keys, rotors and sliders. More...
 
static unsigned long init_clock (void)
 Initialize clock. More...
 
static void init_system (void)
 Initialize host app, pins, watchdog, clock etc. More...
 
static void init_timer (void)
 Configure timer to fire ISR regularly. More...
 
int main (void)
 Example application entry function. More...
 
void qm_filter_callback (touch_filter_data_t *p_filter_data)
 Example signal filtering function. More...
 
static void tc_irq (void)
 Timer compare ISR. More...
 
static void touch_qm_measure_complete_callback (touch_measure_data_t *p_measure_data)
 Timer ISR. More...
 

Variables

volatile uint16_t current_time_ms_touch = 0u
 Current time, set by timer ISR. More...
 
static touch_general_config_t general_config
 General configuration options common to QMatrix, QTouch and Autonomous Touch provided as input to Touch library. More...
 
uint16_t measurement_period_ms = 25u
 Touch Measurement period in milliseconds. More...
 
touch_measure_data_tp_qm_measure_data = NULL
 QMatrix measured data pointer. More...
 
uint8_t qm_burst_length [QM_NUM_CHANNELS]
 QMatrix burst length. More...
 
static touch_qm_config_t qm_config
 QMatrix Configuration structure provided as input to Touch Library. More...
 
static uint8_t qm_data_blk [PRIV_QM_DATA_BLK_SIZE]
 QMatrix Data block provided as input to Touch library. More...
 
static uint16_t qm_filter [QM_NUM_CHANNELS][4]
 Filter for channel signals. More...
 
volatile uint8_t qm_measurement_done_touch = 0u
 Flag set by touch_qm_measure_complete_callback() function when a fresh Touch status is available. More...
 
volatile uint8_t time_to_measure_touch = 0u
 Flag set by timer ISR when it's time to measure touch. More...
 
touch_config_t touch_config
 Touch Library input configuration structure. More...
 
Parameters to pcl_configure_clocks().
static scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false }
 
static pcl_freq_param_t pcl_dfll_freq_param
 

#define EXAMPLE_RC_VALUE   (6000u)

set RC value for 1ms tick.

Referenced by init_timer().

#define EXAMPLE_TARGET_DFLL_FREQ_HZ   (96000000)

DFLL target frequency, in Hz.

Referenced by main().

#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ   (48000000)

MCU clock target frequency, in Hz.

Referenced by main().

#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   (48000000)

PBA clock target frequency, in Hz.

Referenced by at45dbx_resources_init(), and main().

#define EXAMPLE_TARGET_PBBCLK_FREQ_HZ   (48000000)

PBA clock target frequency, in Hz.

#define EXAMPLE_TC   (&AVR32_TC0)

timer number.

Referenced by init_timer(), main(), and tc_irq().

#define EXAMPLE_TC_CHANNEL   (0u)

timer channel.

Referenced by init_timer(), tc_init(), and tc_irq().

#define EXAMPLE_TC_IRQ   (AVR32_TC0_IRQ0)

timer irq.

Referenced by main().

#define EXAMPLE_TC_IRQ_GROUP   (AVR32_TC0_IRQ_GROUP)

timer irq group.

touch_ret_t config_64ch_touch_keys_rotors_sliders ( void  )
static

Example configuration for touch keys, rotors and sliders.

Return values
TOUCH_SUCCESSConfiguration setting successful.
TOUCH_INVALID_xxInvalid input configuration setting.

References AKS_GROUP_1, HYST_6_25, i, RES_1_BIT, RES_8_BIT, SENSOR_TYPE_KEY, SENSOR_TYPE_ROTOR, SENSOR_TYPE_SLIDER, touch_qm_sensor_config(), and TOUCH_SUCCESS.

Referenced by main().

static unsigned long init_clock ( void  )
static

Initialize clock.

Initialize Clock.

References pcl_configure_clocks(), pcl_dfll_freq_param, QM_GCLK_CAT_DIV, scif_gc_enable(), scif_gc_setup(), and SCIF_GCCTRL_DFLL0.

Referenced by init_system().

void init_system ( void  )
static

Initialize host app, pins, watchdog, clock etc.

Initialize host clock, pins, watchdog, etc.

References init_clock().

Referenced by main().

void init_timer ( void  )
static
void qm_filter_callback ( touch_filter_data_t p_filter_data)

Example signal filtering function.

Parameters
p_filter_dataBase address of the touch_filter_data_t instance.

Mean Filter function.

Parameters
p_filter_dataBase address of the touch_filter_data_t instance.

References i, tag_touch_filter_data_t::num_channel_signals, tag_touch_filter_data_t::p_channel_signals, and qm_filter.

static void tc_irq ( void  )
static
void touch_qm_measure_complete_callback ( touch_measure_data_t p_measure_data)
static

Timer ISR.

QMatrix measure complete callback function.

QMatrix measure complete callback function example prototype.

This function is called by the library when the touch measurement process for QMatrix Sensors is completed.

Parameters
p_measure_dataBase address of touch_measure_data_t instance.
Note
A touch_qm_measure_complete_callback() call signifies that fresh values of touch status, rotor/slider position, measured signals, references and Sensor data is available. The QMatrix measured data can be accessed using the p_measure_data pointer.

References qm_measurement_done_touch.

Referenced by main().

volatile uint16_t current_time_ms_touch = 0u

Current time, set by timer ISR.

Referenced by main(), and tc_irq().

scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false }
static

Referenced by clockfrequencies_configure(), and main().

touch_general_config_t general_config
static
Initial value:
= {
}
#define TOUCH_SPREAD_SPECTRUM_MAX_DEV
Touch Maximum Deviation.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/touch_config_at32uc3l.h:1291
#define TOUCH_CSBRES
Touch Resistive Drive Enable for CSB lines.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/touch_config_at32uc3l.h:1313
#define TOUCH_SYNC_PIN_OPTION
Touch Sync Pin option.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/touch_config_at32uc3l.h:1275
#define TOUCH_CSARES
Touch Resistive Drive Enable for CSA lines.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/touch_config_at32uc3l.h:1302

General configuration options common to QMatrix, QTouch and Autonomous Touch provided as input to Touch library.

Note: Use the touch_config_at32uc3l.h configuration header file to fill in the elements of this structure. DO NOT modify any of the input values directly in this structure.

uint16_t measurement_period_ms = 25u

Touch Measurement period in milliseconds.

This variable determines how often a new touch measurement must be done. Default value: Every 25 milliseconds.

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

touch_measure_data_t* p_qm_measure_data = NULL

QMatrix measured data pointer.

pcl_freq_param_t pcl_dfll_freq_param
static
Initial value:
= {
.main_clk_src = PCL_MC_DFLL0,
.pextra_params = &gc_dfllif_ref_opt
}
Definition: power_clocks_lib.h:106
#define EXAMPLE_TARGET_PBBCLK_FREQ_HZ
PBA clock target frequency, in Hz.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:108
static scif_gclk_opt_t gc_dfllif_ref_opt
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:269
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ
MCU clock target frequency, in Hz.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:106
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ
PBA clock target frequency, in Hz.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:107
#define EXAMPLE_TARGET_DFLL_FREQ_HZ
DFLL target frequency, in Hz.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:105

Referenced by clockfrequencies_configure(), init_clock(), and main().

uint8_t qm_burst_length[QM_NUM_CHANNELS]

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

CAUTION: QMatrix Burst length setting recommendation. The following are the three possible Scenario's of Burst length usage when using the UC3L CAT module.

Scenario 1: The burst length of all channels has the same count value. Additionally, any or all of the (X, Y) pairs can have a count value of 1 (when a channel is to be disabled, the count value is set as 1).

Scenario 2: For a given X Line, the count value of all enabled Y Lines MUST be of the same value. Additionally, for this X Line, any or all of these (X, Y) pairs can have a value of 1.

Example, when X0, X1, X2 and Y0, Y1, Y2 lines are used in a design, then, X0Y0, X0Y1 and X0Y2 can have count values (48, 48, 48) or (48, 48, 1) or (1, 1, 48) etc respectively, 48 is an example value here. X1Y0, X1Y1 and X1Y2 can have count values (64, 64, 64) or (64, 64, 1) or (1, 1, 64) etc respectively, 64 is an example value here. X2Y0, X2Y1 and X2Y2 can have count values (32, 32, 32) or (32, 32, 1) or (1, 1, 32) etc respectively, 32 is an example value here.

Scenario 3: It is recommended to have the burst length settings as given in Scenario 1 or Scenario 2. However, in a case wherein it is required to have different count values on different channels, 1k ohm resistive drive MUST be used on all the enabled Y lines by setting the corresponding bits in the CSARES register.

touch_qm_config_t qm_config
static

QMatrix Configuration structure provided as input to Touch Library.

Note: Use the touch_config_at32uc3l.h configuration header file to fill in the elements of this structure. DO NOT modify any of the input values directly in this structure.

uint8_t qm_data_blk[PRIV_QM_DATA_BLK_SIZE]
static

QMatrix Data block provided as input to Touch library.

uint16_t qm_filter[QM_NUM_CHANNELS][4]
static

Filter for channel signals.

Referenced by qm_filter_callback().

volatile uint8_t qm_measurement_done_touch = 0u

Flag set by touch_qm_measure_complete_callback() function when a fresh Touch status is available.

Referenced by main(), process_buttons(), and touch_qm_measure_complete_callback().

volatile uint8_t time_to_measure_touch = 0u

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

Referenced by ISR(), main(), tc_irq(), and touch_handler().

touch_config_t touch_config
Initial value:
= {
NULL,
NULL,
NULL,
}
#define NULL
Definition: lwip-1.4.1/src/include/lwip/def.h:47
static touch_qm_config_t qm_config
QMatrix Configuration structure provided as input to Touch Library.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:299
static touch_general_config_t general_config
General configuration options common to QMatrix, QTouch and Autonomous Touch provided as input to Tou...
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qm/main.c:376

Touch Library input configuration structure.