This file is the AT42QT1060 driver.
Definition in file at42qt1060.h.
#include <stdint.h>
Go to the source code of this file.
#define AT42QT1060_ACTIVE_LEVEL_MASK 0x1C |
Definition at line 73 of file at42qt1060.h.
#define AT42QT1060_AKS_MASK 0x19 |
Definition at line 70 of file at42qt1060.h.
#define AT42QT1060_CAL 0x80 |
Definition at line 108 of file at42qt1060.h.
#define AT42QT1060_CALIBRATE 0x0C |
Definition at line 57 of file at42qt1060.h.
#define AT42QT1060_CHIP_ID 0x00 |
Definition at line 52 of file at42qt1060.h.
#define AT42QT1060_DETECTION_MASK 0x1B |
Definition at line 72 of file at42qt1060.h.
#define AT42QT1060_DETECTION_STATUS 0x04 |
Definition at line 55 of file at42qt1060.h.
Referenced by at42qt1060_get_detect_status(), and main().
#define AT42QT1060_DEVICE_MINOR_VERSION 0x00 |
Definition at line 119 of file at42qt1060.h.
#define AT42QT1060_DEVICE_VERSION 0x03 |
Definition at line 118 of file at42qt1060.h.
#define AT42QT1060_DI 0x1E |
#define AT42QT1060_DRIFT_OPTION 0x0E |
Definition at line 59 of file at42qt1060.h.
#define AT42QT1060_INPUT_PORT_STATUS 0x05 |
Definition at line 56 of file at42qt1060.h.
Referenced by at42qt1060_get_detect_status(), and main().
#define AT42QT1060_IO_0 0x01 |
Definition at line 110 of file at42qt1060.h.
#define AT42QT1060_IO_1 0x02 |
Definition at line 111 of file at42qt1060.h.
#define AT42QT1060_IO_2 0x04 |
Definition at line 112 of file at42qt1060.h.
#define AT42QT1060_IO_3 0x08 |
Definition at line 113 of file at42qt1060.h.
#define AT42QT1060_IO_4 0x10 |
Definition at line 114 of file at42qt1060.h.
#define AT42QT1060_IO_5 0x20 |
Definition at line 115 of file at42qt1060.h.
#define AT42QT1060_IO_6 0x40 |
Definition at line 116 of file at42qt1060.h.
#define AT42QT1060_IO_MASK 0x17 |
#define AT42QT1060_KEY_0 0x01 |
Definition at line 102 of file at42qt1060.h.
#define AT42QT1060_KEY_0_NTHR 0x10 |
#define AT42QT1060_KEY_0_REF_DATA_LSB 0x34 |
#define AT42QT1060_KEY_0_REF_DATA_MSB 0x35 |
#define AT42QT1060_KEY_0_SIGNAL_LSB 0x28 |
#define AT42QT1060_KEY_0_SIGNAL_MSB 0x29 |
#define AT42QT1060_KEY_1 0x02 |
Definition at line 103 of file at42qt1060.h.
#define AT42QT1060_KEY_1_NTHR 0x11 |
#define AT42QT1060_KEY_1_REF_DATA_LSB 0x36 |
#define AT42QT1060_KEY_1_REF_DATA_MSB 0x37 |
#define AT42QT1060_KEY_1_SIGNAL_LSB 0x2A |
#define AT42QT1060_KEY_1_SIGNAL_MSB 0x2B |
#define AT42QT1060_KEY_2 0x04 |
Definition at line 104 of file at42qt1060.h.
#define AT42QT1060_KEY_2_NTHR 0x12 |
#define AT42QT1060_KEY_2_REF_DATA_LSB 0x38 |
#define AT42QT1060_KEY_2_REF_DATA_MSB 0x39 |
#define AT42QT1060_KEY_2_SIGNAL_LSB 0x2C |
#define AT42QT1060_KEY_2_SIGNAL_MSB 0x2D |
#define AT42QT1060_KEY_3 0x08 |
Definition at line 105 of file at42qt1060.h.
#define AT42QT1060_KEY_3_NTHR 0x13 |
#define AT42QT1060_KEY_3_REF_DATA_LSB 0x3A |
#define AT42QT1060_KEY_3_REF_DATA_MSB 0x3B |
#define AT42QT1060_KEY_3_SIGNAL_LSB 0x2E |
#define AT42QT1060_KEY_3_SIGNAL_MSB 0x2F |
#define AT42QT1060_KEY_4 0x10 |
Definition at line 106 of file at42qt1060.h.
#define AT42QT1060_KEY_4_NTHR 0x14 |
#define AT42QT1060_KEY_4_REF_DATA_LSB 0x3C |
#define AT42QT1060_KEY_4_REF_DATA_MSB 0x3D |
#define AT42QT1060_KEY_4_SIGNAL_LSB 0x30 |
#define AT42QT1060_KEY_4_SIGNAL_MSB 0x31 |
#define AT42QT1060_KEY_5 0x20 |
Definition at line 107 of file at42qt1060.h.
#define AT42QT1060_KEY_5_NTHR 0x15 |
#define AT42QT1060_KEY_5_REF_DATA_LSB 0x3E |
#define AT42QT1060_KEY_5_REF_DATA_MSB 0x3F |
#define AT42QT1060_KEY_5_SIGNAL_LSB 0x32 |
#define AT42QT1060_KEY_5_SIGNAL_MSB 0x33 |
#define AT42QT1060_KEY_MASK 0x18 |
#define AT42QT1060_LP_MODE 0x16 |
#define AT42QT1060_MINOR_VERSION 0x02 |
Definition at line 54 of file at42qt1060.h.
#define AT42QT1060_POS_RECALIBRATION_DELAY 0x0F |
Definition at line 60 of file at42qt1060.h.
#define AT42QT1060_PWM_LEVEL 0x1F |
Definition at line 76 of file at42qt1060.h.
#define AT42QT1060_PWM_MASK 0x1A |
Definition at line 71 of file at42qt1060.h.
#define AT42QT1060_RESET 0x0D |
Definition at line 58 of file at42qt1060.h.
#define AT42QT1060_USER_OUTPUT_BUFFER 0x1D |
Definition at line 74 of file at42qt1060.h.
#define AT42QT1060_VERSION 0x01 |
Definition at line 53 of file at42qt1060.h.
void at42qt1060_calibrate | ( | void | ) |
Starts a re-calibration or the sensor.
uint8_t at42qt1060_get_detect_status | ( | void | ) |
Gets the touch detect status of the sensor.
Definition at line 145 of file at42qt1060.c.
References AT42QT1060_DETECTION_STATUS, AT42QT1060_INPUT_PORT_STATUS, and at42qt1060_read_reg().
Referenced by at42qt1060_init().
00146 { 00147 uint8_t status; 00148 /* We need to read both status registers to reset the CHG line */ 00149 status = at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS); 00150 at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS); 00151 return status; 00152 }
void at42qt1060_init | ( | int32_t | fcpu | ) |
Initialise touch sensor with default configuration values.
Definition at line 238 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().
00239 { 00240 volatile uint8_t tmp1, tmp2, tmp3; 00241 00242 /* Store cpu frequency locally*/ 00243 cpu_hz = fcpu; 00244 00245 /* set I/O pins as outputs in order to not let them float 00246 * This will trigger a change on the detect line although not 00247 * documented in datasheet 00248 */ 00249 at42qt1060_write_reg(AT42QT1060_IO_MASK, 0xFF); 00250 00251 /* Set keys that will trigger a change on the detect line 00252 */ 00253 at42qt1060_write_reg(AT42QT1060_KEY_MASK, AT42QT1060_KEY_MASK_VALUE); 00254 00255 at42qt1060_write_reg(AT42QT1060_DI, AT42QT1060_DETECT_INTEGRATOR_VALUE); 00256 // Set detect thresholds 00257 at42qt1060_write_reg(AT42QT1060_KEY_0_NTHR, 00258 AT42QT1060_KEY_0_NTHR_VALUE); 00259 at42qt1060_write_reg(AT42QT1060_KEY_1_NTHR, 00260 AT42QT1060_KEY_1_NTHR_VALUE); 00261 at42qt1060_write_reg(AT42QT1060_KEY_2_NTHR, 00262 AT42QT1060_KEY_2_NTHR_VALUE); 00263 at42qt1060_write_reg(AT42QT1060_KEY_3_NTHR, 00264 AT42QT1060_KEY_3_NTHR_VALUE); 00265 at42qt1060_write_reg(AT42QT1060_KEY_4_NTHR, 00266 AT42QT1060_KEY_4_NTHR_VALUE); 00267 at42qt1060_write_reg(AT42QT1060_KEY_5_NTHR, 00268 AT42QT1060_KEY_5_NTHR_VALUE); 00269 00270 tmp1 = at42qt1060_read_reg(AT42QT1060_IO_MASK); 00271 tmp2 = at42qt1060_read_reg(AT42QT1060_KEY_MASK); 00272 tmp3 = at42qt1060_read_reg(AT42QT1060_LP_MODE); 00273 00274 /* Read out touch status to reset detect line */ 00275 tmp1 = at42qt1060_get_detect_status(); 00276 }
uint8_t at42qt1060_read_reg | ( | uint8_t | reg_index | ) |
Read register data.
reg_index | Register index |
reg_index | Register address. |
Definition at line 103 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().
00104 { 00105 uint8_t data; 00106 twi_package_t twi_package; 00107 00108 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00109 twi_package.addr_length = 0; 00110 twi_package.buffer = ®_index; 00111 twi_package.length = 1; 00112 while(twi_master_write(AT42QT1060_TWI, &twi_package)!=TWI_SUCCESS); 00113 /* We need a delay here to make this work although this is not 00114 * specified in the datasheet. 00115 * Also there seems to be a bug in the TWI module or the driver 00116 * since some delay here (code or real delay) adds about 500us 00117 * between the write and the next read cycle. 00118 */ 00119 cpu_delay_us(20, cpu_hz); 00120 00121 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00122 twi_package.addr_length = 0; 00123 twi_package.buffer = &data; 00124 twi_package.length = 1; 00125 while(twi_master_read(AT42QT1060_TWI, &twi_package)!=TWI_SUCCESS); 00126 00127 00128 return data; 00129 }
void at42qt1060_register_eic_int | ( | void(*)(void) | touch_detect_callback | ) |
Register a interrupt handler for the EIC controller.
If the detect signal is on an input of the EIC controller this function can be used to register a interrupt handler for it.
touch_detect_callback | Pointer to callback function that should be called when the interrupt triggers. Keep this function as short as possible. |
Referenced by main().
void at42qt1060_register_int | ( | void(*)(void) | touch_detect_callback | ) |
Register a pin interrupt handler.
The detect signal from the touch sensor is used to generate a pin interrupt.
touch_detect_callback | Pointer to callback function that should be called when the interrupt triggers. Keep this function as short as possible. |
Definition at line 190 of file at42qt1060.c.
References at42qt1060, at42qt1060_detect_int_handler(), AT42QT1060_DETECT_PIN, and touch_detect_callback.
Referenced by main().
00191 { 00192 at42qt1060.touch_detect_callback = touch_detect_callback; 00193 00194 Disable_global_interrupt(); 00195 00196 INTC_register_interrupt(&at42qt1060_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, 0 ); 00197 // For now we only react on falling edge 00198 // Actually this is a level interrupt (low active) 00199 gpio_enable_pin_interrupt(AT42QT1060_DETECT_PIN, GPIO_FALLING_EDGE); 00200 gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); 00201 00202 Enable_global_interrupt(); 00203 return; 00204 }
void at42qt1060_reset | ( | void | ) |
Performs a software reset of the touch sensor.
void at42qt1060_set_low_power_mode | ( | uint8_t | lp_mode | ) |
Sets the current power mode of the device.
lp_mode | Determines the number of 16ms intervals between key measurements. Longer invervals between measurements -> lower power consumption but slower response A value of 0 causes the device to sleep and no measurements are performed. A value of 255 causes the device to enter "free-run" mode where measurements are continuously taken. 1 = 16ms between measurements 2 = 32ms between measurements ... |
void at42qt1060_write_reg | ( | uint8_t | reg_index, | |
uint8_t | data | |||
) |
Write data to a sensor register.
reg_index | Register index number | |
data | Register data |
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 80 of file at42qt1060.c.
References AT42QT1060_TWI, and AT42QT1060_TWI_ADDRESS.
Referenced by at42qt1060_init().
00081 { 00082 uint8_t pack[2]; 00083 twi_package_t twi_package; 00084 00085 pack[0] = reg_index; 00086 pack[1] = data; 00087 00088 twi_package.chip = AT42QT1060_TWI_ADDRESS; 00089 twi_package.addr_length = 0; 00090 twi_package.buffer = &pack; 00091 twi_package.length = sizeof(pack); 00092 00093 while(twi_master_write(AT42QT1060_TWI, &twi_package)!=TWI_SUCCESS); 00094 00095 return; 00096 }