This file is the AT42QT1060 driver.
Definition in file at42qt1060.c.
#include "board.h"
#include "compiler.h"
#include "gpio.h"
#include "conf_at42qt1060.h"
#include "at42qt1060.h"
#include "intc.h"
#include "cycle_counter.h"
#include "twim.h"
Go to the source code of this file.
Functions | |
void | at42qt1060_detect_int_handler (void) |
Interrupt handler for the pin interrupt-. | |
uint8_t | at42qt1060_get_detect_status (void) |
Gets the touch detect status of the sensor. | |
uint8_t | at42qt1060_get_status (void) |
void | at42qt1060_init (int32_t fcpu) |
Initialise touch sensor with default configuration values. | |
uint8_t | at42qt1060_read_reg (uint8_t reg_index) |
Read device register content. | |
void | at42qt1060_register_int (void(*touch_detect_callback)(void)) |
Register a normal pin interrupt for the touch event. | |
void | at42qt1060_write_reg (uint8_t reg_index, uint8_t data) |
Write device register content. | |
Variables | |
struct { | |
void(* touch_detect_callback )(void) | |
} | at42qt1060 |
static uint32_t | cpu_hz |
void at42qt1060_detect_int_handler | ( | void | ) |
Interrupt handler for the pin interrupt-.
Definition at line 162 of file at42qt1060.c.
References at42qt1060, and AT42QT1060_DETECT_PIN.
Referenced by at42qt1060_register_int().
00163 { 00164 if(gpio_get_pin_interrupt_flag(AT42QT1060_DETECT_PIN)) 00165 { 00166 gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); 00167 if(at42qt1060.touch_detect_callback) 00168 at42qt1060.touch_detect_callback(); 00169 } 00170 }
uint8_t at42qt1060_get_detect_status | ( | void | ) |
Gets the touch detect status of the sensor.
Definition at line 146 of file at42qt1060.c.
References AT42QT1060_DETECTION_STATUS, AT42QT1060_INPUT_PORT_STATUS, and at42qt1060_read_reg().
Referenced by at42qt1060_init().
00147 { 00148 uint8_t status; 00149 /* We need to read both status registers to reset the CHG line */ 00150 status = at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS); 00151 at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS); 00152 return status; 00153 }
uint8_t at42qt1060_get_status | ( | void | ) |
Definition at line 132 of file at42qt1060.c.
References AT42QT1060_TWI, and AT42QT1060_TWI_ADDRESS.
00133 { 00134 twi_package_t twi_package; 00135 uint16_t status_data; 00136 00137 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00138 twi_package.addr_length = 0; 00139 twi_package.buffer = &status_data; 00140 twi_package.length = 2; 00141 twi_master_read(AT42QT1060_TWI, &twi_package); 00142 00143 return MSB(status_data); 00144 }
void at42qt1060_init | ( | int32_t | fcpu | ) |
Initialise touch sensor with default configuration values.
Definition at line 239 of file at42qt1060.c.
References AT42QT1060_DETECT_INTEGRATOR_VALUE, AT42QT1060_DI, at42qt1060_get_detect_status(), AT42QT1060_IO_MASK, AT42QT1060_KEY_0_NTHR, AT42QT1060_KEY_0_NTHR_VALUE, AT42QT1060_KEY_1_NTHR, AT42QT1060_KEY_1_NTHR_VALUE, AT42QT1060_KEY_2_NTHR, AT42QT1060_KEY_2_NTHR_VALUE, AT42QT1060_KEY_3_NTHR, AT42QT1060_KEY_3_NTHR_VALUE, AT42QT1060_KEY_4_NTHR, AT42QT1060_KEY_4_NTHR_VALUE, AT42QT1060_KEY_5_NTHR, AT42QT1060_KEY_5_NTHR_VALUE, AT42QT1060_KEY_MASK, AT42QT1060_KEY_MASK_VALUE, AT42QT1060_LP_MODE, at42qt1060_read_reg(), at42qt1060_write_reg(), and cpu_hz.
Referenced by main().
00240 { 00241 volatile uint8_t tmp1, tmp2, tmp3; 00242 00243 /* Store cpu frequency locally*/ 00244 cpu_hz = fcpu; 00245 00246 /* set I/O pins as outputs in order to not let them float 00247 * This will trigger a change on the detect line although not 00248 * documented in datasheet 00249 */ 00250 at42qt1060_write_reg(AT42QT1060_IO_MASK, 0xFF); 00251 00252 /* Set keys that will trigger a change on the detect line 00253 */ 00254 at42qt1060_write_reg(AT42QT1060_KEY_MASK, AT42QT1060_KEY_MASK_VALUE); 00255 00256 at42qt1060_write_reg(AT42QT1060_DI, AT42QT1060_DETECT_INTEGRATOR_VALUE); 00257 // Set detect thresholds 00258 at42qt1060_write_reg(AT42QT1060_KEY_0_NTHR, 00259 AT42QT1060_KEY_0_NTHR_VALUE); 00260 at42qt1060_write_reg(AT42QT1060_KEY_1_NTHR, 00261 AT42QT1060_KEY_1_NTHR_VALUE); 00262 at42qt1060_write_reg(AT42QT1060_KEY_2_NTHR, 00263 AT42QT1060_KEY_2_NTHR_VALUE); 00264 at42qt1060_write_reg(AT42QT1060_KEY_3_NTHR, 00265 AT42QT1060_KEY_3_NTHR_VALUE); 00266 at42qt1060_write_reg(AT42QT1060_KEY_4_NTHR, 00267 AT42QT1060_KEY_4_NTHR_VALUE); 00268 at42qt1060_write_reg(AT42QT1060_KEY_5_NTHR, 00269 AT42QT1060_KEY_5_NTHR_VALUE); 00270 00271 tmp1 = at42qt1060_read_reg(AT42QT1060_IO_MASK); 00272 tmp2 = at42qt1060_read_reg(AT42QT1060_KEY_MASK); 00273 tmp3 = at42qt1060_read_reg(AT42QT1060_LP_MODE); 00274 00275 /* Read out touch status to reset detect line */ 00276 tmp1 = at42qt1060_get_detect_status(); 00277 }
uint8_t at42qt1060_read_reg | ( | uint8_t | reg_index | ) |
Read device register content.
Read register data.
reg_index | Register address. |
Definition at line 104 of file at42qt1060.c.
References AT42QT1060_TWI, AT42QT1060_TWI_ADDRESS, and cpu_hz.
Referenced by at42qt1060_get_detect_status(), at42qt1060_init(), get_key_ref_values(), get_key_signal_values(), and main().
00105 { 00106 uint8_t data; 00107 twi_package_t twi_package; 00108 00109 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00110 twi_package.addr_length = 0; 00111 twi_package.buffer = ®_index; 00112 twi_package.length = 1; 00113 while(twi_master_write(AT42QT1060_TWI, &twi_package)!=TWI_SUCCESS); 00114 /* We need a delay here to make this work although this is not 00115 * specified in the datasheet. 00116 * Also there seems to be a bug in the TWI module or the driver 00117 * since some delay here (code or real delay) adds about 500us 00118 * between the write and the next read cycle. 00119 */ 00120 cpu_delay_us(20, cpu_hz); 00121 00122 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00123 twi_package.addr_length = 0; 00124 twi_package.buffer = &data; 00125 twi_package.length = 1; 00126 while(twi_master_read(AT42QT1060_TWI, &twi_package)!=TWI_SUCCESS); 00127 00128 00129 return data; 00130 }
void at42qt1060_register_int | ( | void(*)(void) | touch_detect_callback | ) |
Register a normal pin interrupt for the touch event.
Register a pin interrupt handler.
Definition at line 191 of file at42qt1060.c.
References at42qt1060, at42qt1060_detect_int_handler(), AT42QT1060_DETECT_PIN, and touch_detect_callback.
Referenced by main().
00192 { 00193 at42qt1060.touch_detect_callback = touch_detect_callback; 00194 00195 Disable_global_interrupt(); 00196 00197 INTC_register_interrupt(&at42qt1060_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, 0 ); 00198 // For now we only react on falling edge 00199 // Actually this is a level interrupt (low active) 00200 gpio_enable_pin_interrupt(AT42QT1060_DETECT_PIN, GPIO_FALLING_EDGE); 00201 gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); 00202 00203 Enable_global_interrupt(); 00204 return; 00205 }
void at42qt1060_write_reg | ( | uint8_t | reg_index, | |
uint8_t | data | |||
) |
Write device register content.
Write data to a sensor register.
reg_index | Register address. Use macros as defined in the header file. | |
data | Data that should be written to the device register. |
Definition at line 81 of file at42qt1060.c.
References AT42QT1060_TWI, and AT42QT1060_TWI_ADDRESS.
Referenced by at42qt1060_init().
00082 { 00083 uint8_t pack[2]; 00084 twi_package_t twi_package; 00085 00086 pack[0] = reg_index; 00087 pack[1] = data; 00088 00089 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00090 twi_package.addr_length = 0; 00091 twi_package.buffer = &pack; 00092 twi_package.length = sizeof(pack); 00093 00094 while(twi_master_write(AT42QT1060_TWI, &twi_package)!=TWI_SUCCESS); 00095 00096 return; 00097 }
struct { ... } at42qt1060 [static] |
Referenced by at42qt1060_detect_int_handler(), and at42qt1060_register_int().
uint32_t cpu_hz [static] |
Definition at line 74 of file at42qt1060.c.
Referenced by at42qt1060_init(), and at42qt1060_read_reg().
void(* touch_detect_callback)(void) |
Referenced by at42qt1060_register_int(), and main().