at42qt1060.h File Reference


Detailed Description

AT42QT1060 driver for AVR32 UC3.

This file is the AT42QT1060 driver.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file at42qt1060.h.

#include <stdint.h>

Go to the source code of this file.

Defines

#define AT42QT1060_ACTIVE_LEVEL_MASK   0x1C
#define AT42QT1060_AKS_MASK   0x19
#define AT42QT1060_CAL   0x80
#define AT42QT1060_CALIBRATE   0x0C
#define AT42QT1060_CHIP_ID   0x00
#define AT42QT1060_DETECTION_MASK   0x1B
#define AT42QT1060_DETECTION_STATUS   0x04
#define AT42QT1060_DEVICE_MINOR_VERSION   0x00
#define AT42QT1060_DEVICE_VERSION   0x03
#define AT42QT1060_DI   0x1E
#define AT42QT1060_DRIFT_OPTION   0x0E
#define AT42QT1060_INPUT_PORT_STATUS   0x05
#define AT42QT1060_IO_0   0x01
#define AT42QT1060_IO_1   0x02
#define AT42QT1060_IO_2   0x04
#define AT42QT1060_IO_3   0x08
#define AT42QT1060_IO_4   0x10
#define AT42QT1060_IO_5   0x20
#define AT42QT1060_IO_6   0x40
#define AT42QT1060_IO_MASK   0x17
#define AT42QT1060_KEY_0   0x01
#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
#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
#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
#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
#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
#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
#define AT42QT1060_POS_RECALIBRATION_DELAY   0x0F
#define AT42QT1060_PWM_LEVEL   0x1F
#define AT42QT1060_PWM_MASK   0x1A
#define AT42QT1060_RESET   0x0D
#define AT42QT1060_USER_OUTPUT_BUFFER   0x1D
#define AT42QT1060_VERSION   0x01

Functions

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.
void at42qt1060_init (int32_t fcpu)
 Initialise touch sensor with default configuration values.
uint8_t at42qt1060_read_reg (uint8_t reg_index)
 Read register data.
void at42qt1060_register_eic_int (void(*touch_detect_callback)(void))
 Register a interrupt handler for the EIC controller.
void at42qt1060_register_int (void(*touch_detect_callback)(void))
 Register a pin interrupt handler.
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.
void at42qt1060_write_reg (uint8_t reg_index, uint8_t data)
 Write data to a sensor register.


Define Documentation

#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

Definition at line 75 of file at42qt1060.h.

Referenced by at42qt1060_init().

#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

Definition at line 68 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_0   0x01

Definition at line 102 of file at42qt1060.h.

#define AT42QT1060_KEY_0_NTHR   0x10

Definition at line 61 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_0_REF_DATA_LSB   0x34

Definition at line 89 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_0_REF_DATA_MSB   0x35

Definition at line 90 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_0_SIGNAL_LSB   0x28

Definition at line 77 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_0_SIGNAL_MSB   0x29

Definition at line 78 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_1   0x02

Definition at line 103 of file at42qt1060.h.

#define AT42QT1060_KEY_1_NTHR   0x11

Definition at line 62 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_1_REF_DATA_LSB   0x36

Definition at line 91 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_1_REF_DATA_MSB   0x37

Definition at line 92 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_1_SIGNAL_LSB   0x2A

Definition at line 79 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_1_SIGNAL_MSB   0x2B

Definition at line 80 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_2   0x04

Definition at line 104 of file at42qt1060.h.

#define AT42QT1060_KEY_2_NTHR   0x12

Definition at line 63 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_2_REF_DATA_LSB   0x38

Definition at line 93 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_2_REF_DATA_MSB   0x39

Definition at line 94 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_2_SIGNAL_LSB   0x2C

Definition at line 81 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_2_SIGNAL_MSB   0x2D

Definition at line 82 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_3   0x08

Definition at line 105 of file at42qt1060.h.

#define AT42QT1060_KEY_3_NTHR   0x13

Definition at line 64 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_3_REF_DATA_LSB   0x3A

Definition at line 95 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_3_REF_DATA_MSB   0x3B

Definition at line 96 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_3_SIGNAL_LSB   0x2E

Definition at line 83 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_3_SIGNAL_MSB   0x2F

Definition at line 84 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_4   0x10

Definition at line 106 of file at42qt1060.h.

#define AT42QT1060_KEY_4_NTHR   0x14

Definition at line 65 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_4_REF_DATA_LSB   0x3C

Definition at line 97 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_4_REF_DATA_MSB   0x3D

Definition at line 98 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_4_SIGNAL_LSB   0x30

Definition at line 85 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_4_SIGNAL_MSB   0x31

Definition at line 86 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_5   0x20

Definition at line 107 of file at42qt1060.h.

#define AT42QT1060_KEY_5_NTHR   0x15

Definition at line 66 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_KEY_5_REF_DATA_LSB   0x3E

Definition at line 99 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_5_REF_DATA_MSB   0x3F

Definition at line 100 of file at42qt1060.h.

Referenced by get_key_ref_values().

#define AT42QT1060_KEY_5_SIGNAL_LSB   0x32

Definition at line 87 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_5_SIGNAL_MSB   0x33

Definition at line 88 of file at42qt1060.h.

Referenced by get_key_signal_values().

#define AT42QT1060_KEY_MASK   0x18

Definition at line 69 of file at42qt1060.h.

Referenced by at42qt1060_init().

#define AT42QT1060_LP_MODE   0x16

Definition at line 67 of file at42qt1060.h.

Referenced by at42qt1060_init().

#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.


Function Documentation

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.

Returns:
Register content of the touch detect register.

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 }

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 register data.

Parameters:
reg_index Register index
Returns:
Register value
Read register data.

Parameters:
reg_index Register address.
Returns:
Register content.

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 = &reg_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_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.

Parameters:
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.

Parameters:
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 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_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.

Parameters:
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.

Parameters:
reg_index Register index number
data Register data
Write data to a sensor register.

Parameters:
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 }


Generated on Thu Dec 17 19:57:50 2009 for AVR32 - AT42QT1060 Driver by  doxygen 1.5.5