qt1081_example.c File Reference


Detailed Description

Touch button example for QT1081.

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

Definition in file qt1081_example.c.

#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "pm.h"
#include "gpio.h"
#include "eic.h"
#include "qt1081.h"
#include "intc.h"

Go to the source code of this file.

Defines

#define INT_MODE   INT_MODE_EIC
#define INT_MODE_EIC   0
#define INT_MODE_GPIO   1
#define is_touch_center()   is_touch_sensor_4()
#define is_touch_down()   is_touch_sensor_1()
#define is_touch_left()   is_touch_sensor_3()
#define is_touch_right()   is_touch_sensor_2()
#define is_touch_up()   is_touch_sensor_0()

Functions

int main (void)
void touch_button_isr (void)

Variables

eic_options_t eic_options [2]
 Structure holding the configuration parameters of the EIC module.


Define Documentation

#define INT_MODE   INT_MODE_EIC

Definition at line 96 of file qt1081_example.c.

#define INT_MODE_EIC   0

Definition at line 92 of file qt1081_example.c.

#define INT_MODE_GPIO   1

Definition at line 93 of file qt1081_example.c.

 
#define is_touch_center (  )     is_touch_sensor_4()

Definition at line 106 of file qt1081_example.c.

Referenced by touch_button_isr().

 
#define is_touch_down (  )     is_touch_sensor_1()

Definition at line 103 of file qt1081_example.c.

Referenced by touch_button_isr().

 
#define is_touch_left (  )     is_touch_sensor_3()

Definition at line 105 of file qt1081_example.c.

Referenced by touch_button_isr().

 
#define is_touch_right (  )     is_touch_sensor_2()

Definition at line 104 of file qt1081_example.c.

Referenced by touch_button_isr().

 
#define is_touch_up (  )     is_touch_sensor_0()

Definition at line 102 of file qt1081_example.c.

Referenced by touch_button_isr().


Function Documentation

int main ( void   ) 

Definition at line 176 of file qt1081_example.c.

References eic_options, and touch_button_isr().

00176                {
00177 
00178     pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00179 
00180     // Enable edge-triggered interrupt.
00181     eic_options[0].eic_mode  = EIC_MODE_EDGE_TRIGGERED;
00182     // Interrupt will trigger on falling edge (this is a must-do for the keypad scan
00183     // feature if the chosen mode is edge-triggered).
00184     eic_options[0].eic_edge  = EIC_EDGE_RISING_EDGE;
00185     // Initialize in synchronous mode : interrupt is synchronized to the clock
00186     eic_options[0].eic_async = EIC_SYNCH_MODE;
00187     // Set the interrupt line number.
00188     eic_options[0].eic_line  = QT1081_EIC_EXTINT_INT;
00189 
00190     // Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output mode and switch them off.
00191     gpio_set_gpio_pin(LED0_GPIO);
00192     gpio_set_gpio_pin(LED1_GPIO);
00193     gpio_set_gpio_pin(LED2_GPIO);
00194     gpio_set_gpio_pin(LED3_GPIO);
00195 
00196     gpio_enable_module_pin( QT1081_EIC_EXTINT_PIN, QT1081_EIC_EXTINT_FUNCTION);
00197 
00198 #if( INT_MODE == INT_MODE_GPIO)
00199     Disable_global_interrupt();
00200     
00201 #if __GNUC__
00202     INTC_init_interrupts();
00203     /* Register interrupt handler to the interrupt controller
00204      * up, down buttons on PB22, PB23 -> GPIO_IRQ_6
00205      */
00206     INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_6, 0);//AVR32_INTC_INT0);
00207     /* Other buttons on PB[24..26] -> GPIO_IRQ_7 (PB23 - PB31) */
00208     INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_7, 0);
00209 #endif
00210     gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_0, GPIO_RISING_EDGE);
00211     gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_1, GPIO_RISING_EDGE);
00212     gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_2, GPIO_RISING_EDGE);
00213     gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_3, GPIO_RISING_EDGE);
00214     gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_4, GPIO_RISING_EDGE);
00215     
00216     Enable_global_interrupt();
00217 #endif
00218 
00219 #if(INT_MODE == INT_MODE_EIC)   
00220     Disable_global_interrupt();
00221 
00222 #if __GNUC__
00223     INTC_init_interrupts();
00224     /* Register the EXTINT1 interrupt handler to the interrupt controller
00225      */
00226     INTC_register_interrupt(&touch_button_isr, QT1081_EIC_EXTINT_IRQ, AVR32_INTC_INT0);
00227 #endif
00228 
00229       // Init the EIC controller with the options
00230       eic_init(&AVR32_EIC, eic_options, 1);
00231       // Enable the EIC lines.
00232       eic_enable_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
00233       // Enable the interrupt for each EIC line.
00234       eic_enable_interrupt_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
00235 
00236     Enable_global_interrupt();
00237 #endif
00238     
00239     while(TRUE);
00240 
00241     return 0;
00242 }

void touch_button_isr ( void   ) 

Definition at line 153 of file qt1081_example.c.

References is_touch_center, is_touch_down, is_touch_left, is_touch_right, and is_touch_up.

Referenced by main().

00153                            {
00154 
00155     if(is_touch_up()){
00156         gpio_tgl_gpio_pin(LED0_GPIO);
00157     }
00158     if(is_touch_down()){
00159         gpio_tgl_gpio_pin(LED1_GPIO);
00160     }
00161     if(is_touch_right()){
00162         gpio_tgl_gpio_pin(LED1_GPIO);
00163     }
00164     if(is_touch_left()){
00165         gpio_tgl_gpio_pin(LED2_GPIO);
00166     }
00167     if(is_touch_center()){
00168         gpio_tgl_gpio_pin(LED2_GPIO);
00169     }
00170 
00171     eic_clear_interrupt_line(&AVR32_EIC, QT1081_EIC_EXTINT_INT);
00172 }


Variable Documentation

eic_options_t eic_options[2]

Structure holding the configuration parameters of the EIC module.

Definition at line 109 of file qt1081_example.c.

Referenced by main().


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