Microchip® Advanced Software Framework

thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_at/main.c File Reference

Autonomous QTouch Example with CAT module using SleepWalking feature in AT32UC3L series.

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

#include <stdbool.h>
#include <stdint.h>
#include "compiler.h"
#include "board.h"
#include "conf_example.h"
#include "ast.h"
#include "gpio.h"
#include "pm_uc3l.h"
#include "scif_uc3l.h"
#include "intc.h"
#include "sysclk.h"
#include "sleepmgr.h"
#include "status_codes.h"
#include "touch_api_at32uc3l.h"

Macros

APPLICATION SPECIFIC CONFIGURATION
#define STATUS_LED   LED1_GPIO
 LED1_GPIO is used as status LED. More...
 
#define ERROR_LED   LED0_GPIO
 LED0_GPIO is used as error status LED. More...
 
#define POWER_SUPPLY_MODE_1_8V   false
 Enable when operated in 1.8V VDDIN. More...
 
#define AST_CLOCK_SOURCE   AST_OSC_32KHZ
 32KHz external oscillator is used as AST source More...
 
#define AST_PRESCALER   AST_PSEL_32KHZ_1HZ
 Prescaler is set to AST_PSEL_32KHZ_1HZ to run at 1Hz. More...
 
#define AST_TRIGGER_PRESCALER   10
 Periodic interrupt prescaler is set to 10 for trigger in every 62.5ms. More...
 
#define NB_GPIO_USED_PINS   6
 

Functions

static status_code_t ast_init (void)
 Initialize Asynchronous Timer to trigger CAT module at regular intervals. More...
 
int main (void)
 Main Application Routine. More...
 
static void power_save_measures_init (void)
 Initialize the power saving measures to lower power consumption. More...
 
static status_code_t touch_api_init (void)
 Initialize the touch library and touch sensors. More...
 
static void touch_at_status_change_interrupt_callback (touch_at_status *p_at_status)
 Autonomous QTouch Group status change callback function example prototype. More...
 

Variables

static touch_at_config_t at_config
 Autonomous QTouch Configuration structure provided as input to Touch Library. More...
 
volatile int8_t autonomous_qtouch_in_touch = -1
 Flag set by touch_at_status_change_interrupt_callback() function when a fresh touch status is available. 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...
 
unsigned int gpio_used_pins [NB_GPIO_USED_PINS]
 Array to hold the used GPIO pins. More...
 
uint16_t measurement_period_ms
 Dummy variable for QDebug protocol for compatibility with QMatrix and QTouch. More...
 
touch_config_t touch_config
 Touch Library input configuration structure. More...
 

#define AST_CLOCK_SOURCE   AST_OSC_32KHZ

32KHz external oscillator is used as AST source

Referenced by ast_init().

#define AST_PRESCALER   AST_PSEL_32KHZ_1HZ

Prescaler is set to AST_PSEL_32KHZ_1HZ to run at 1Hz.

Referenced by ast_init().

#define AST_TRIGGER_PRESCALER   10

Periodic interrupt prescaler is set to 10 for trigger in every 62.5ms.

Referenced by ast_init().

#define ERROR_LED   LED0_GPIO

LED0_GPIO is used as error status LED.

Referenced by main().

#define NB_GPIO_USED_PINS   6
#define POWER_SUPPLY_MODE_1_8V   false

Enable when operated in 1.8V VDDIN.

#define STATUS_LED   LED1_GPIO

LED1_GPIO is used as status LED.

Referenced by main(), and touch_at_status_change_interrupt_callback().

static status_code_t ast_init ( void  )
static

Initialize Asynchronous Timer to trigger CAT module at regular intervals.

Asynchronous Timer Initialization.

  • Start the 32KHz Oscillator
  • Initializes the AST module with periodic trigger events
Return values
STATUS_OKConfiguration OK
ERR_BUSYError in configuring the AST module

References ast_clear_all_status_flags(), AST_CLOCK_SOURCE, ast_enable(), ast_enable_periodic0(), ast_init_counter(), AST_PRESCALER, ast_set_periodic0_value(), AST_TRIGGER_PRESCALER, BOARD_OSC32_PINSEL, ERR_BUSY, scif_osc32_opt_t::mode, OSC32_STARTUP_8192, SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR, SCIF_OSC_MODE_EXT_CLK, scif_start_osc32(), STATUS_OK, SYSCLK_AST, sysclk_disable_pba_module(), sysclk_enable_hsb_module(), sysclk_enable_pba_module(), and SYSCLK_EVENT.

Referenced by main().

int main ( void  )

Main Application Routine.

  • Initialize the system clocks
  • Initialize the sleep manager
  • Initialize the power save measures
  • Initialize the touch library and sensors
  • Initialize the AST to trigger CAT at regular intervals
  • Go to STATIC sleep mode and wake up on a touch status change

When woken up by Autonomous QTouch interrupt, the touch_at_status_change_interrupt_callback() is called that updates the autonomous_qtouch_in_touch status flag.

References ast_clear_all_status_flags(), ast_init(), ERROR_LED, gpio_clr_gpio_pin(), gpio_set_gpio_pin(), gpio_tgl_gpio_pin(), i, pm_asyn_wake_up_disable(), pm_asyn_wake_up_enable(), power_save_measures_init(), QDebug_Init(), QDebug_ProcessCommands(), QDebug_SendData(), sleepmgr_enter_sleep(), sleepmgr_init(), sleepmgr_lock_mode(), SLEEPMGR_STATIC, STATUS_LED, STATUS_OK, sysclk_disable_pba_module(), sysclk_enable_peripheral_clock(), SYSCLK_GPIO, sysclk_init(), and touch_api_init().

void power_save_measures_init ( void  )
static

Initialize the power saving measures to lower power consumption.

Low Power Configuration Initializes the power saving measures to reduce power consumption.

  • Enable pull ups on GPIO pins
  • Disable the clocks to unwanted modules
  • Disable internal voltage regulator when in 1.8V supply mode

References gpio_configure_group(), GPIO_DIR_INPUT, GPIO_PULL_UP, gpio_used_pins, i, sysclk_disable_cpu_module(), SYSCLK_OCD, and tmp.

Referenced by main().

static status_code_t touch_api_init ( )
static

Initialize the touch library and touch sensors.

Touch Library & Sensors Intialization.

  • Register the CAT interrupt with priority level 3
  • Initialize the touch library
  • Intilialize the Autonomous touch sensor
Return values
STATUS_OKConfiguration success
ERR_INVALID_ARGError in configuration parameters

References cpu_irq_disable, cpu_irq_enable, ERR_INVALID_ARG, irq_initialize_vectors, irq_register_handler, STATUS_OK, SYSCLK_CAT, sysclk_enable_pba_module(), touch_at_sensor_enable(), touch_at_sensor_init(), touch_at_status_change_interrupt_callback(), and TOUCH_SUCCESS.

Referenced by main().

void touch_at_status_change_interrupt_callback ( touch_at_status p_at_status)
static

Autonomous QTouch Group status change callback function example prototype.

Autonomous QTouch status change interrupt callback function.

This callback function is called by the Touch library in the CAT Autonomous QTouch status change Interrupt context, each time there is a status change in the Autonomous Touch sensor.

Parameters
p_at_status,:Autonomous QTouch status. p_at_status->status_change: Autonomous QTouch status change. p_at_status->base_count: Autonomous QTouch base count value. p_at_status->current_count: Autonomous QTouch current count value.
Note
1. CAUTION - This callback function is called in the CAT Autonomous QTouch Status change INTERRUPT SERVICE ROUTINE by the Touch Library.
  1. The Autonomous QTouch Status change callback is called both for an IN_TOUCH status change and an OUT_OF_TOUCH status change.

References autonomous_qtouch_in_touch, gpio_clr_gpio_pin(), gpio_set_gpio_pin(), IN_TOUCH, tag_touch_at_status_t::status_change, STATUS_LED, sysclk_enable_pba_module(), and SYSCLK_GPIO.

Referenced by touch_api_init().

touch_at_config_t at_config
static
Initial value:
= {
{
},
{
{
}
}
}
#define AT_CHLEN
Autonomous QTouch Charge Length For Autonomous QTouch sensor, specifies how many burst prescaler cloc...
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:560
#define AT_PTHR
Autonomous Touch Positive Recalibration Threshold.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:665
#define AT_PDRIFT
Autonomous Touch Positive Drift Compensation.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:676
#define AT_DISHIFT
Autonomous QTouch Discharge Shift.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:586
#define AT_SELEN
Autonomous QTouch Settle Length.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:569
#define AT_SENSE
Autonomous Touch Sensitivity.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:657
#define AT_FILTER
Autonomous Touch Filter Setting.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:620
#define AT_ENABLE_EXTERNAL_SYNC
Autonomous QTouch External synchronization to reduce 50 or 60 Hz mains interference.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:610
#define AT_CAT_CLK_DIV
Autonomous QTouch burst timing clock Divider.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:551
#define AT_ENABLE_SPREAD_SPECTRUM
Autonomous QTouch Spread Spectrum Sensor Drive.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:601
#define AT_SP_SELECTED
Autonomous QTouch Clock dependency note: The Example application uses a PBA clock of 48MHz...
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:534
#define AT_NDRIFT
Autonomous Touch Negative Drift Compensation.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:687
#define AT_OUTSENS
Autonomous Touch Out-of-Touch Sensitivity.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:639
#define AT_MAX_ACQ_COUNT
Autonomous QTouch Maximum Count.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:594
#define AT_DILEN
Autonomous QTouch Discharge Length.
Definition: avr32/applications/uc3-l0_xplained-demo/touch_config_at32uc3l.h:578

Autonomous QTouch 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.

volatile int8_t autonomous_qtouch_in_touch = -1

Flag set by touch_at_status_change_interrupt_callback() function when a fresh touch status is available.

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_qt/touch_config_at32uc3l.h:1291
#define TOUCH_CSARES
Touch Resistive Drive Enable for CSA lines.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qt/touch_config_at32uc3l.h:1302
#define TOUCH_CSBRES
Touch Resistive Drive Enable for CSB lines.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qt/touch_config_at32uc3l.h:1313
#define TOUCH_SYNC_PIN_OPTION
Touch Sync Pin option.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_qt/touch_config_at32uc3l.h:1275

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.

unsigned int gpio_used_pins[NB_GPIO_USED_PINS]
Initial value:
= {
EXAMPLE_CAT_SNS_PIN,
EXAMPLE_CAT_SNSK_PIN,
AVR32_SCIF_XIN32_0_PIN,
AVR32_SCIF_XOUT32_0_PIN
}
#define STATUS_LED
LED1_GPIO is used as status LED.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_at/main.c:130
#define ERROR_LED
LED0_GPIO is used as error status LED.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_at/main.c:132

Array to hold the used GPIO pins.

uint16_t measurement_period_ms

Dummy variable for QDebug protocol for compatibility with QMatrix and QTouch.

Touch Measurement period in milliseconds.

touch_config_t touch_config
Initial value:
= {
NULL,
NULL,
NULL,
}
#define NULL
Definition: lwip-1.4.0/src/include/lwip/def.h:47
static touch_at_config_t at_config
Autonomous QTouch Configuration structure provided as input to Touch Library.
Definition: thirdparty/qtouch/devspecific/uc3/uc3l0/examples/example_at/main.c:212
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_at/main.c:250

Touch Library input configuration structure.