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 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 |
Initialize Asynchronous Timer to trigger CAT module at regular intervals.
Asynchronous Timer Initialization.
STATUS_OK | Configuration OK |
ERR_BUSY | Error 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.
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(), pm_asyn_wake_up_disable(), pm_asyn_wake_up_enable(), power_save_measures_init(), 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().
|
static |
Initialize the power saving measures to lower power consumption.
Low Power Configuration Initializes the power saving measures to reduce power consumption.
References gpio_configure_group(), GPIO_DIR_INPUT, GPIO_PULL_UP, gpio_used_pins, sysclk_disable_cpu_module(), and SYSCLK_OCD.
Referenced by main().
|
static |
Initialize the touch library and touch sensors.
Touch Library & Sensors Intialization.
STATUS_OK | Configuration success |
ERR_INVALID_ARG | Error 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().
|
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.
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. |
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().
|
static |
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.
Referenced by touch_at_status_change_interrupt_callback().
|
static |
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] |
Array to hold the used GPIO pins.
Referenced by power_save_measures_init().
uint16_t measurement_period_ms |
Dummy variable for QDebug protocol for compatibility with QMatrix and QTouch.
touch_config_t touch_config |
Touch Library input configuration structure.