at42qt1060.c 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.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 "twi.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


Function Documentation

void at42qt1060_detect_int_handler ( void   ) 

Interrupt handler for the pin interrupt-.

Definition at line 161 of file at42qt1060.c.

References at42qt1060, and AT42QT1060_DETECT_PIN.

Referenced by at42qt1060_register_int().

00162 {
00163   if(gpio_get_pin_interrupt_flag(AT42QT1060_DETECT_PIN))
00164   {
00165     gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN);
00166     if(at42qt1060.touch_detect_callback)
00167         at42qt1060.touch_detect_callback();
00168   }
00169 }

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

uint8_t at42qt1060_get_status ( void   ) 

Definition at line 131 of file at42qt1060.c.

References AT42QT1060_TWI, and AT42QT1060_TWI_ADDRESS.

00132 {
00133     twi_package_t twi_package;
00134     uint16_t status_data;
00135 
00136     twi_package.chip = AT42QT1060_TWI_ADDRESS;
00137     twi_package.addr_length = 0;
00138     twi_package.buffer = &status_data;
00139     twi_package.length = 2;
00140     twi_master_read(AT42QT1060_TWI, &twi_package);
00141 
00142     return MSB(status_data);
00143 }

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 device register content.

Read register data.

Parameters:
reg_index Register address.
Returns:
Register content.

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 = &reg_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_int ( void(*)(void)  touch_detect_callback  ) 

Register a normal pin interrupt for the touch event.

Register a pin interrupt handler.

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_write_reg ( uint8_t  reg_index,
uint8_t  data 
)

Write device register content.

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


Variable Documentation

struct { ... } at42qt1060 [static]

uint32_t cpu_hz [static]

Definition at line 73 of file at42qt1060.c.

Referenced by at42qt1060_init(), and at42qt1060_read_reg().

void(* touch_detect_callback)(void)

Referenced by at42qt1060_register_int(), and main().


Generated on Fri Feb 19 02:24:02 2010 for AVR32 - AT42QT1060 Driver by  doxygen 1.5.5