Definition in file at42qt1060_example.c.
#include <avr32/io.h>
#include "compiler.h"
#include "print_funcs.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "twim.h"
#include "gpio.h"
#include "intc.h"
#include "cycle_counter.h"
#include "flashc.h"
#include "at42qt1060.h"
#include "conf_at42qt1060.h"
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | at42qt1060_data |
Defines | |
#define | FCPU_HZ 60000000 |
#define | FPBA_HZ 60000000 |
Functions | |
void | get_key_ref_values (struct at42qt1060_data *touch_data) |
void | get_key_signal_values (struct at42qt1060_data *touch_data) |
static void | init_sys_clocks (void) |
Initializes the MCU system clocks. | |
int | main (void) |
void | print_key_data (int key, const char *key_name, struct at42qt1060_data *touch_data) |
Print touch key status to debug output. | |
void | print_touch_data (struct at42qt1060_data *touch_data) |
Print key touch data to debug output. | |
void | touch_detect_callback (void) |
Callback function for a detect event of the touch sensor device. | |
static void | twi_init (void) |
Variables | |
volatile Bool | touch_detect = FALSE |
System Clock Frequencies | |
static pcl_freq_param_t | pcl_freq_param |
#define FCPU_HZ 60000000 |
#define FPBA_HZ 60000000 |
void get_key_ref_values | ( | struct at42qt1060_data * | touch_data | ) |
Definition at line 201 of file at42qt1060_example.c.
References AT42QT1060_KEY_0_REF_DATA_LSB, AT42QT1060_KEY_0_REF_DATA_MSB, AT42QT1060_KEY_1_REF_DATA_LSB, AT42QT1060_KEY_1_REF_DATA_MSB, AT42QT1060_KEY_2_REF_DATA_LSB, AT42QT1060_KEY_2_REF_DATA_MSB, AT42QT1060_KEY_3_REF_DATA_LSB, AT42QT1060_KEY_3_REF_DATA_MSB, AT42QT1060_KEY_4_REF_DATA_LSB, AT42QT1060_KEY_4_REF_DATA_MSB, AT42QT1060_KEY_5_REF_DATA_LSB, AT42QT1060_KEY_5_REF_DATA_MSB, at42qt1060_read_reg(), and at42qt1060_data::key_ref_value.
Referenced by main().
00202 { 00203 LSB(touch_data->key_ref_value[0]) = 00204 at42qt1060_read_reg(AT42QT1060_KEY_0_REF_DATA_LSB); 00205 MSB(touch_data->key_ref_value[0]) = 00206 at42qt1060_read_reg(AT42QT1060_KEY_0_REF_DATA_MSB); 00207 LSB(touch_data->key_ref_value[1]) = 00208 at42qt1060_read_reg(AT42QT1060_KEY_1_REF_DATA_LSB); 00209 MSB(touch_data->key_ref_value[1]) = 00210 at42qt1060_read_reg(AT42QT1060_KEY_1_REF_DATA_MSB); 00211 LSB(touch_data->key_ref_value[2]) = 00212 at42qt1060_read_reg(AT42QT1060_KEY_2_REF_DATA_LSB); 00213 MSB(touch_data->key_ref_value[2]) = 00214 at42qt1060_read_reg(AT42QT1060_KEY_2_REF_DATA_MSB); 00215 LSB(touch_data->key_ref_value[3]) = 00216 at42qt1060_read_reg(AT42QT1060_KEY_3_REF_DATA_LSB); 00217 MSB(touch_data->key_ref_value[3]) = 00218 at42qt1060_read_reg(AT42QT1060_KEY_3_REF_DATA_MSB); 00219 LSB(touch_data->key_ref_value[4]) = 00220 at42qt1060_read_reg(AT42QT1060_KEY_4_REF_DATA_LSB); 00221 MSB(touch_data->key_ref_value[4]) = 00222 at42qt1060_read_reg(AT42QT1060_KEY_4_REF_DATA_MSB); 00223 LSB(touch_data->key_ref_value[5]) = 00224 at42qt1060_read_reg(AT42QT1060_KEY_5_REF_DATA_LSB); 00225 MSB(touch_data->key_ref_value[5]) = 00226 at42qt1060_read_reg(AT42QT1060_KEY_5_REF_DATA_MSB); 00227 }
void get_key_signal_values | ( | struct at42qt1060_data * | touch_data | ) |
Definition at line 173 of file at42qt1060_example.c.
References AT42QT1060_KEY_0_SIGNAL_LSB, AT42QT1060_KEY_0_SIGNAL_MSB, AT42QT1060_KEY_1_SIGNAL_LSB, AT42QT1060_KEY_1_SIGNAL_MSB, AT42QT1060_KEY_2_SIGNAL_LSB, AT42QT1060_KEY_2_SIGNAL_MSB, AT42QT1060_KEY_3_SIGNAL_LSB, AT42QT1060_KEY_3_SIGNAL_MSB, AT42QT1060_KEY_4_SIGNAL_LSB, AT42QT1060_KEY_4_SIGNAL_MSB, AT42QT1060_KEY_5_SIGNAL_LSB, AT42QT1060_KEY_5_SIGNAL_MSB, at42qt1060_read_reg(), and at42qt1060_data::key_signal.
Referenced by main().
00174 { 00175 LSB(touch_data->key_signal[0]) = 00176 at42qt1060_read_reg(AT42QT1060_KEY_0_SIGNAL_LSB); 00177 MSB(touch_data->key_signal[0]) = 00178 at42qt1060_read_reg(AT42QT1060_KEY_0_SIGNAL_MSB); 00179 LSB(touch_data->key_signal[1]) = 00180 at42qt1060_read_reg(AT42QT1060_KEY_1_SIGNAL_LSB); 00181 MSB(touch_data->key_signal[1]) = 00182 at42qt1060_read_reg(AT42QT1060_KEY_1_SIGNAL_MSB); 00183 LSB(touch_data->key_signal[2]) = 00184 at42qt1060_read_reg(AT42QT1060_KEY_2_SIGNAL_LSB); 00185 MSB(touch_data->key_signal[2]) = 00186 at42qt1060_read_reg(AT42QT1060_KEY_2_SIGNAL_MSB); 00187 LSB(touch_data->key_signal[3]) = 00188 at42qt1060_read_reg(AT42QT1060_KEY_3_SIGNAL_LSB); 00189 MSB(touch_data->key_signal[3]) = 00190 at42qt1060_read_reg(AT42QT1060_KEY_3_SIGNAL_MSB); 00191 LSB(touch_data->key_signal[4]) = 00192 at42qt1060_read_reg(AT42QT1060_KEY_4_SIGNAL_LSB); 00193 MSB(touch_data->key_signal[4]) = 00194 at42qt1060_read_reg(AT42QT1060_KEY_4_SIGNAL_MSB); 00195 LSB(touch_data->key_signal[5]) = 00196 at42qt1060_read_reg(AT42QT1060_KEY_5_SIGNAL_LSB); 00197 MSB(touch_data->key_signal[5]) = 00198 at42qt1060_read_reg(AT42QT1060_KEY_5_SIGNAL_MSB); 00199 }
static void init_sys_clocks | ( | void | ) | [static] |
Initializes the MCU system clocks.
Definition at line 144 of file at42qt1060_example.c.
References pcl_freq_param.
Referenced by main().
00145 { 00146 // Configure system clocks. 00147 if (pcl_configure_clocks(&pcl_freq_param) != PASS) 00148 while(1); 00149 }
int main | ( | void | ) |
Definition at line 292 of file at42qt1060_example.c.
References AT42QT1060_DETECTION_STATUS, at42qt1060_init(), AT42QT1060_INPUT_PORT_STATUS, at42qt1060_read_reg(), at42qt1060_register_eic_int(), at42qt1060_register_int(), at42qt1060_data::detect_status, FCPU_HZ, FPBA_HZ, get_key_ref_values(), get_key_signal_values(), init_sys_clocks(), print_touch_data(), touch_detect, touch_detect_callback, and twi_init().
00292 { 00293 00294 struct at42qt1060_data touch_data; 00295 t_cpu_time timeout; 00296 00297 //pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 00298 init_sys_clocks(); 00299 init_dbg_rs232(FPBA_HZ); 00300 print_dbg("AT42QT1060 Touch demo\n"); 00301 00302 INTC_init_interrupts(); 00303 00304 // Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output mode and switch them off. 00305 gpio_set_gpio_pin(LED0_GPIO); 00306 gpio_set_gpio_pin(LED1_GPIO); 00307 gpio_set_gpio_pin(LED2_GPIO); 00308 gpio_set_gpio_pin(LED3_GPIO); 00309 twi_init(); 00310 00311 /* Power up delay: This device needs a maximum of 230ms before it 00312 * can be accessed. Another method would be to wait until the the 00313 * detect line goes low but this won't work during a debugging session 00314 * since the device is not reset.*/ 00315 cpu_delay_ms(230, FCPU_HZ); 00316 00317 at42qt1060_init(FCPU_HZ); 00318 00319 #if BOARD == EVK1105 00320 /* Register an interrupt for the detect signal line either as gpio interrupt 00321 * or as EIC interrupt (if pin is multiplexed on a EIC channel). */ 00322 //at42qt1060_register_int(&touch_detect_callback); 00323 at42qt1060_register_eic_int(&touch_detect_callback); 00324 #else 00325 at42qt1060_register_int(&touch_detect_callback); 00326 #endif 00327 00328 cpu_set_timeout( cpu_ms_2_cy(1000, FCPU_HZ), &timeout); 00329 00330 while(TRUE) 00331 { 00332 // if a touch is detected we read the status 00333 if(touch_detect) 00334 { 00335 touch_data.detect_status = 00336 at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS); 00337 // need to read input port status too to reset CHG line 00338 at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS); 00339 touch_detect = FALSE; 00340 } 00341 if(cpu_is_timeout(&timeout)) 00342 { 00343 get_key_signal_values(&touch_data); 00344 get_key_ref_values(&touch_data); 00345 print_touch_data(&touch_data); 00346 00347 cpu_set_timeout(cpu_ms_2_cy(500, FCPU_HZ), &timeout); 00348 } 00349 } 00350 00351 return 0; 00352 }
void print_key_data | ( | int | key, | |
const char * | key_name, | |||
struct at42qt1060_data * | touch_data | |||
) |
Print touch key status to debug output.
key | Key index for key data in touch_data. | |
key_name | Pointer to key name. Should be less than 7 chars or the table will not be aligned. | |
touch_data | Pointer to touch data structure. |
Definition at line 237 of file at42qt1060_example.c.
References at42qt1060_data::detect_status, at42qt1060_data::key_ref_value, and at42qt1060_data::key_signal.
Referenced by print_touch_data().
00239 { 00240 char tmp[128]; 00241 char detect = (touch_data->detect_status & (1 << key)) ? 00242 'T' : '-'; 00243 00244 sprintf(tmp, "| %6s | %4u | %4u | %4d | %c |\n", 00245 key_name, 00246 touch_data->key_signal[key], 00247 touch_data->key_ref_value[key], 00248 (signed short) touch_data->key_ref_value[key] - 00249 touch_data->key_signal[key], 00250 detect 00251 ); 00252 print_dbg(tmp); 00253 }
void print_touch_data | ( | struct at42qt1060_data * | touch_data | ) |
Print key touch data to debug output.
touch_data | Pointer to structure that holds the touch data. |
Definition at line 260 of file at42qt1060_example.c.
References print_key_data().
Referenced by main().
00261 { 00262 00263 print_dbg("\f"); // start with an empty display 00264 print_dbg("| Key | signal | reference | delta | detect |\n"); 00265 print_dbg("|----------------------------------------------|\n"); 00266 #if BOARD == EVK1105 00267 print_key_data(0, "left", touch_data); 00268 print_key_data(1, "down", touch_data); 00269 print_key_data(2, "right", touch_data); 00270 print_key_data(3, "up", touch_data); 00271 print_key_data(4, "middle", touch_data); 00272 print_key_data(5, "home", touch_data); 00273 #elif BOARD == UC3C_EK 00274 print_key_data(0, "up", touch_data); 00275 print_key_data(1, "down", touch_data); 00276 print_key_data(2, "right", touch_data); 00277 print_key_data(3, "left", touch_data); 00278 print_key_data(4, "middle", touch_data); 00279 print_key_data(5, "home", touch_data); 00280 #endif 00281 }
void touch_detect_callback | ( | void | ) |
Callback function for a detect event of the touch sensor device.
Definition at line 285 of file at42qt1060_example.c.
References touch_detect.
00286 { 00287 touch_detect = TRUE; 00288 gpio_tgl_gpio_pin(LED3_GPIO); 00289 }
static void twi_init | ( | void | ) | [static] |
Definition at line 151 of file at42qt1060_example.c.
References AT42QT1060_TWI, AT42QT1060_TWI_ADDRESS, AT42QT1060_TWI_MASTER_SPEED, AT42QT1060_TWI_SCL_FUNCTION, AT42QT1060_TWI_SCL_PIN, AT42QT1060_TWI_SDA_FUNCTION, AT42QT1060_TWI_SDA_PIN, and FPBA_HZ.
Referenced by main().
00152 { 00153 const gpio_map_t AT42QT1060_TWI_GPIO_MAP = 00154 { 00155 {AT42QT1060_TWI_SCL_PIN, AT42QT1060_TWI_SCL_FUNCTION}, 00156 {AT42QT1060_TWI_SDA_PIN, AT42QT1060_TWI_SDA_FUNCTION} 00157 }; 00158 00159 const twi_options_t AT42QT1060_TWI_OPTIONS = 00160 { 00161 .pba_hz = FPBA_HZ, 00162 .speed = AT42QT1060_TWI_MASTER_SPEED, 00163 .chip = AT42QT1060_TWI_ADDRESS 00164 }; 00165 00166 // Assign I/Os to SPI. 00167 gpio_enable_module(AT42QT1060_TWI_GPIO_MAP, 00168 sizeof(AT42QT1060_TWI_GPIO_MAP) / sizeof(AT42QT1060_TWI_GPIO_MAP[0])); 00169 // Initialize as master. 00170 twi_master_init(AT42QT1060_TWI, &AT42QT1060_TWI_OPTIONS); 00171 00172 }
pcl_freq_param_t pcl_freq_param [static] |
Initial value:
Definition at line 133 of file at42qt1060_example.c.
Referenced by init_sys_clocks().
volatile Bool touch_detect = FALSE |
Definition at line 114 of file at42qt1060_example.c.
Referenced by main(), and touch_detect_callback().