00001 /*This file is prepared for Doxygen automatic documentation generation.*/ 00015 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * 00020 * 1. Redistributions of source code must retain the above copyright notice, this 00021 * list of conditions and the following disclaimer. 00022 * 00023 * 2. Redistributions in binary form must reproduce the above copyright notice, 00024 * this list of conditions and the following disclaimer in the documentation 00025 * and/or other materials provided with the distribution. 00026 * 00027 * 3. The name of ATMEL may not be used to endorse or promote products derived 00028 * from this software without specific prior written permission. 00029 * 00030 * 4. ATMEL grants developer a non-exclusive, limited license to use the Software 00031 * as a development platform solely in connection with an Atmel AVR product 00032 * ("Atmel Product"). 00033 * 00034 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED 00035 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00036 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00037 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00038 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00039 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00040 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00041 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00042 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00043 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00044 */ 00045 #include "board.h" 00046 #include "gpio.h" 00047 #include "intc.h" 00048 00049 #include "controller.h" 00050 #include "at42qt1060.h" 00051 #include "conf_at42qt1060.h" 00052 #include "cycle_counter.h" 00053 00054 #define JOYSTICK_KEY_DEBOUNCE_MS 200 00055 00056 volatile Bool touch_detect = FALSE; 00057 static U32 static_fcpu_hz; 00058 t_cpu_time joystick_key_sensibility_timer; 00059 struct at42qt1060_data { 00060 uint8_t detect_status; 00061 uint16_t key_signal[6]; 00062 uint8_t key_threshold[6]; 00063 uint16_t key_ref_value[6]; 00064 }; 00065 00068 void touch_detect_callback(void) 00069 { 00070 touch_detect = TRUE; 00071 } 00072 00073 struct at42qt1060_data touch_data; 00074 00075 void controller_task(void) 00076 { 00077 // if a touch is detected we read the status 00078 if(touch_detect) 00079 { 00080 touch_data.detect_status = 00081 at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS); 00082 // need to read input port status too to reset CHG line 00083 at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS); 00084 touch_detect = FALSE; 00085 } 00086 } 00087 00088 void controller_init(U32 fcpu_hz, U32 fhsb_hz, U32 fpbb_hz, U32 fpba_hz) 00089 { 00090 // wait until the device settles its CHG line 00091 cpu_delay_ms(230, fcpu_hz); 00092 at42qt1060_init(fcpu_hz); 00093 at42qt1060_register_int(&touch_detect_callback); 00094 //static_fcpu_hz = fcpu_hz; 00095 cpu_set_timeout(cpu_ms_2_cy(JOYSTICK_KEY_DEBOUNCE_MS, static_fcpu_hz), 00096 &joystick_key_sensibility_timer); 00097 } 00098 00099 // FCT3/ Up 00100 Bool controller_key_fct3(void) 00101 { 00102 if (touch_data.detect_status & (1 << 0)) 00103 { 00104 return TRUE; 00105 } 00106 return FALSE; 00107 } 00108 00109 // FCT4/ Down 00110 Bool controller_key_fct4(void) 00111 { 00112 if (touch_data.detect_status & (1 << 1)) 00113 { 00114 return TRUE; 00115 } 00116 return FALSE; 00117 } 00118 00119 // FCT1/ Right button 00120 Bool controller_key_fct1(void) 00121 { 00122 if (touch_data.detect_status & (1 << 2)) 00123 { 00124 return TRUE; 00125 } 00126 return FALSE; 00127 } 00128 00129 // FCT2/ Left 00130 Bool controller_key_fct2(void) 00131 { 00132 if (touch_data.detect_status & (1 << 3)) 00133 { 00134 return TRUE; 00135 } 00136 return FALSE; 00137 } 00138 00139 // FCT5/ Middle 00140 Bool controller_key_fct5(void) 00141 { 00142 if (touch_data.detect_status & (1 << 4)) 00143 { 00144 return TRUE; 00145 } 00146 return FALSE; 00147 } 00148