/*! \brief Example application entry function. */ touch_ret_t touch_sensors_init (void) { touch_ret_t touch_ret = TOUCH_SUCCESS; touch_qt_time.measurement_period_ms = TOUCH_MEASUREMENT_PERIOD_MS; /* Initialize touch library and sam4l cat module for QTouch Library operation. */ touch_ret = touch_qt_sensors_init (&touch_config); if (touch_ret != TOUCH_SUCCESS) { while (1u); /* Check API Error return code. */ } #if DEF_TOUCH_QDEBUG_ENABLE == 1 /* Initialize the debug interface. */ QDebug_Init (); #endif /* configure the touch library sensors. */ touch_ret = touch_sensors_config (); if (touch_ret != TOUCH_SUCCESS) { while (1u); /* Check API Error return code. */ } /* Initialize touch sensing. */ touch_ret = touch_qt_sensors_calibrate (); if (touch_ret != TOUCH_SUCCESS) { while (1u); /* Check API Error return code. */ } // Set up CATB interrupt handler NVIC_ClearPendingIRQ(CATB_IRQn); NVIC_SetPriority(CATB_IRQn,0); NVIC_EnableIRQ(CATB_IRQn); return (touch_ret); }
/*! \brief Example application entry function. */ int main (void) { /* BEFORE USING THE EXAMPLE PROJECTS. 1. For support queries on, - QTouch Library usage - Capacitive Touch Sensor Tuning - Capacitive Touch Schematic design - Capacitive Touch Sensor design refer to http://www.atmel.com/design-support/ 2. For more QTouch Library documentation, refer Atmel QTouch Library User Guide doc8207.pdf. For Capacitive Touch Sensor tuning guidelines, refer QTAN0062: QTouch and QMatrix Sensitivity Tuning for Keys, Sliders and Wheels. For Capacitive Touch Sensor design, refer doc10620.pdf: Touch Sensors Design Guide. http://www.atmel.com/dyn/products/app_notes.asp?family_id=697 3. The Example application uses a CPU, PBA and PBB clock of 48MHz. When using a different frequency setting, the following parameters must be changed accordingly to ensure proper QTouch operation. a. QTx_CAT_CLK_DIV. b. TOUCH_SPREAD_SPECTRUM_MAX_DEV, when Spread spectrum is enabled. c. PBA_HZ, when using qdebug/SPI_Master.c d. TARGET_PBA_FREQ_HZ and TARGET_CPU_FREQ_HZ, when using qdebug/SERIAL.c 4. STK600-QTouch Test setup pin information. The following table indicates the STK600 pin connections for the STK600-QTouch test setup. Important Note: The (csa1/csab1) and (csa2/csb2) Touch channel connections are multiplexed with the JTAG pins. So, when using the JTAG debugging mode, these Touch channel connections MUST be removed. In the Flash mode, this will not cause any issues. ---------------------------------------------- CAT CSA/CSB name - STK600 board Port-pin name ---------------------------------------------- ROTOR/WHEEL csa1 - pa1 (This pair is multiplexed with JTAG pins. csb1 - pa6 Remove Touch connections on these pins during JTAG debug mode.) csa2 - pa0 (This pair is multiplexed with JTAG pins. csb2 - pa7 Remove Touch connections on these pins during JTAG debug mode.) csa5 - pb2 csb5 - pb4 SLIDER csa9 - pd0 csb9 - pd1 csa7 - pa4 csb7 - pa5 csa8 - pc0 csb8 - pc1 KEY 1 csa15 - pe4 csb15 - pe1 KEY 2 csa16 - pe3 csb16 - pe2 ---------------------------------------------- QT600 USB Bridge 'TOUCH DATA' Header Pin name - STK600 board Port-pin name ---------------------------------------------- PA22 - 'TOUCH DATA' header pin 8 - clk - pc6 PA21 - 'TOUCH DATA' header pin 7 - miso - pc5 PA20 - 'TOUCH DATA' header pin 6 - mosi - pc4 PA14 - 'TOUCH DATA' header pin 5 - nss - pb6 5. When two or more acquisition methods are used, care must be taken such that a given port pin is not used by more than one method at the same time. The following pin configuration options available in touch_config_at32uc3l.h must be carefully chosen to avoid any overlapping. a. QMatrix Pin Configuration Options. b. Autonomous QTouch Pin Configuration Options. c. QTouch Group A Pin Configuration Options. d. QTouch Group B Pin Configuration Options. e. Touch Sync Pin option. */ touch_ret_t touch_ret = TOUCH_SUCCESS; touch_qt_dma_t qt_dma_ch; /* Initialize host clock, pins, watchdog, etc. */ init_system (); /* Disable interrupts. */ Disable_global_interrupt (); /* The INTC driver has to be used only for GNU GCC for AVR32. */ #if (defined __GNUC__) /* initialize interrupt vectors. */ INTC_init_interrupts (); /* Register the Timer interrupt handler to the interrupt controller. */ INTC_register_interrupt (&tc_irq, EXAMPLE_TC_IRQ, AVR32_INTC_INT0); /* Register the Touch Library CAT interrupt handler to the interrupt controller. Note: This interrupt registration is a MUST before using the Touch Library with the GCC compiler. For the case of IAR the registration of interrupt is automatically taken care by the compiler. The Touch Libary CAT interrupt level for the case of IAR is fixed to Interrupt level 3. */ INTC_register_interrupt (&touch_acq_done_irq, AVR32_CAT_IRQ, AVR32_INTC_INT3); #endif /* Enable interrupts. */ Enable_global_interrupt (); /* Configure timer to fire ISR regularly. */ init_timer (); /* Initialize touch library and uc3l cat module for QTouch Group A operation. */ touch_ret = touch_qt_sensors_init (TOUCH_QT_GRP_A, &touch_config); if (touch_ret != TOUCH_SUCCESS) { while (1u); /* Check API Error return code. */ } #if DEF_TOUCH_QDEBUG_ENABLE == 1 /* Initialize the debug interface. */ QDebug_Init (); #endif /* configure the touch library sensors. */ touch_ret = config_qt_grp_a_touch_sensors (); if (touch_ret != TOUCH_SUCCESS) { while (1u); /* Check API Error return code. */ } /* Initialize touch sensing. */ touch_ret = touch_qt_sensors_calibrate (TOUCH_QT_GRP_A); if (touch_ret != TOUCH_SUCCESS) { while (1u); /* Check API Error return code. */ } /* Provide the dma channel to be used by the CAT module. For each acquisition cycle, any different dma channel from 0 to 11 can be provided. The touch library can handle a different dma channel for each call of the touch_qt_sensors_start_acquisition API. */ qt_dma_ch = QTA_DMA_CHANNEL_0; /* Loop forever */ for (;;) { /* Process touch library events. The touch_event_dispatcher API needs to be called as frequently as possible in order to have a good touch response. */ touch_event_dispatcher (); if (time_to_measure_touch == 1u) { /* Clear flag: it's time to measure touch */ time_to_measure_touch = 0u; /* Start a touch sensors measurement process. */ touch_ret = touch_qt_sensors_start_acquisition (TOUCH_QT_GRP_A, current_time_ms_touch, qt_dma_ch, NORMAL_ACQ_MODE, touch_qta_measure_complete_callback); if ((touch_ret != TOUCH_SUCCESS) && (touch_ret != TOUCH_ACQ_INCOMPLETE)) { while (1); /* Reaching this point can be due to - 1. The api has retured an error due to a invalid input parameter. 2. The api has been called during a invalid Touch Library state. */ } } /* Host application code goes here */ if (qta_measurement_done_touch == 1u) { /* Clear flag: QTouch Group A measurement complete. */ qta_measurement_done_touch = 0u; #if DEF_TOUCH_QDEBUG_ENABLE == 1 /* QT600 two-way QDebug communication application Example. */ /* Process any commands received from QTouch Studio. */ QDebug_ProcessCommands (); /* Send out the Touch debug information data each time when Touch measurement process is completed . */ QDebug_SendData (p_qta_measure_data->acq_status); #endif } } /* Loop forever */ }