Definition in file qt60168_controller_init.c.
#include "board.h"
#include "gpio.h"
#include "rtc.h"
#include "spi.h"
#include "intc.h"
#include "qt60168.h"
#include "conf_qt60168.h"
Go to the source code of this file.
Functions | |
void | rtc_init_qt (void) |
void | rtc_irq (void) |
static int | special_qt60168_get_reply (unsigned short *data) |
Bool | special_qt60168_report_all_key (unsigned short *data) |
static int | special_qt60168_send_cmd (unsigned char cmd) |
Variables | |
static unsigned short | Data |
static unsigned short | New_status = 0 |
static unsigned short | Old_status = 0 |
static int | Read_data = 0 |
static int | report_state = 0 |
void rtc_init_qt | ( | void | ) |
Definition at line 116 of file qt60168_controller_init.c.
References rtc_irq().
Referenced by controller_init().
00116 { 00117 00118 // Disable all interrupts. */ 00119 Disable_global_interrupt(); 00120 00121 // Register the RTC interrupt handler to the interrupt controller. 00122 INTC_register_interrupt(&rtc_irq, AVR32_RTC_IRQ, AVR32_INTC_INT0); 00123 00124 // Initialize the RTC 00125 // Frtc = 1024Hz 00126 rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, 4); 00127 00128 // Set top value to 0 to generate an interrupt every seconds */ 00129 rtc_set_top_value(&AVR32_RTC, 1); 00130 // Enable the interrupts 00131 rtc_enable_interrupt(&AVR32_RTC); 00132 00133 // Enable the RTC 00134 rtc_enable(&AVR32_RTC); 00135 00136 // Enable global interrupts 00137 Enable_global_interrupt(); 00138 00139 }
void rtc_irq | ( | void | ) |
Definition at line 69 of file qt60168_controller_init.c.
References Data, New_status, Old_status, Read_data, special_qt60168_report_all_key(), and update_joystick_status().
Referenced by rtc_init_qt().
00070 { 00071 static volatile int delay_count=0; 00072 static unsigned short all_key= 0; 00073 static int update_delay = 0; 00074 00075 delay_count++; 00076 update_delay++; 00077 00078 if(update_delay>10) { 00079 if(special_qt60168_report_all_key(&all_key)==TRUE) { 00080 update_delay=0; 00081 //gpio_tgl_gpio_pin(LED2_GPIO); 00082 Old_status = New_status; 00083 New_status = all_key; // The one that has just benn read 00084 if(Old_status != New_status) { 00085 update_joystick_status( New_status); 00086 } 00087 if(New_status!=0) { // LED2 on if key is currently pressed 00088 gpio_clr_gpio_pin(LED2_GPIO); 00089 } 00090 else { 00091 gpio_set_gpio_pin(LED2_GPIO); 00092 } 00093 } 00094 } 00095 00096 if(Read_data==1) { 00097 Read_data=2; 00098 delay_count=0; 00099 } 00100 if((delay_count>1)&&(Read_data==2)) { 00101 // We can read the DATA 00102 // Select QT60168 00103 spi_selectChip(QT60168_SPI,QT60168_SPI_NCPS); 00104 // Read Reply 00105 spi_read(QT60168_SPI, &Data); 00106 // Unselect QT60168 00107 spi_unselectChip(QT60168_SPI,QT60168_SPI_NCPS); 00108 Read_data=0; 00109 } 00110 00111 // clear the interrupt flag 00112 rtc_clear_interrupt(&AVR32_RTC); 00113 00114 }
static int special_qt60168_get_reply | ( | unsigned short * | data | ) | [static] |
Definition at line 215 of file qt60168_controller_init.c.
References Data, and special_qt60168_send_cmd().
Referenced by special_qt60168_report_all_key().
00216 { 00217 // Send NULL COMMAND 00218 if(special_qt60168_send_cmd(QT60168_CMD_NULL_COMMAND)==0) { 00219 *data = Data; 00220 return 0; 00221 } 00222 else { 00223 return 1; 00224 }; 00225 }
Bool special_qt60168_report_all_key | ( | unsigned short * | data | ) |
Definition at line 141 of file qt60168_controller_init.c.
References report_state, special_qt60168_get_reply(), and special_qt60168_send_cmd().
Referenced by rtc_irq().
00142 { 00143 static int AllKey=0; 00144 unsigned short dataread; 00145 00146 switch(report_state) { 00147 case 0: 00148 AllKey=0; 00149 if(special_qt60168_send_cmd(QT60168_CMD_REPORT_ALL_KEYS)==0 ) { 00150 report_state=1; 00151 } 00152 break; 00153 case 1: 00154 if(special_qt60168_get_reply(&dataread)==0 ) { 00155 AllKey=dataread; 00156 report_state=2; 00157 } 00158 break; 00159 case 2: 00160 if(special_qt60168_get_reply(&dataread)==0 ) { 00161 AllKey|=dataread<<8; 00162 report_state=3; 00163 } 00164 break; 00165 case 3: 00166 if(special_qt60168_get_reply(&dataread)==0 ) { 00167 AllKey|=dataread<<16; 00168 report_state=4; 00169 } 00170 break; 00171 case 4: 00172 if(special_qt60168_get_reply(&dataread)==0 ) { // Trash CRC of QT60168_CMD_REPORT_ALL_KEYS 00173 // Update data 00174 *data = AllKey; 00175 report_state=0; 00176 } 00177 break; 00178 default: 00179 report_state=0; 00180 } 00181 if (report_state==0) { 00182 return TRUE; 00183 } 00184 else { 00185 return FALSE; 00186 } 00187 }
static int special_qt60168_send_cmd | ( | unsigned char | cmd | ) | [static] |
Definition at line 189 of file qt60168_controller_init.c.
References Read_data.
Referenced by special_qt60168_get_reply(), and special_qt60168_report_all_key().
00190 { 00191 static int state=0; 00192 switch(state) { 00193 case 0: 00194 // Select QT60168 00195 spi_selectChip(QT60168_SPI,QT60168_SPI_NCPS); 00196 // Write CMD 00197 spi_write(QT60168_SPI, cmd); 00198 // Unselect QT60168 00199 spi_unselectChip(QT60168_SPI,QT60168_SPI_NCPS); 00200 state = 1; 00201 Read_data=1; 00202 break; 00203 case 1: 00204 if(Read_data==0) { 00205 state=0; 00206 } 00207 break; 00208 default: 00209 state=0; 00210 } 00211 00212 return state; 00213 }
unsigned short Data [static] |
Definition at line 57 of file qt60168_controller_init.c.
Referenced by rtc_irq(), and special_qt60168_get_reply().
unsigned short New_status = 0 [static] |
unsigned short Old_status = 0 [static] |
int Read_data = 0 [static] |
Definition at line 56 of file qt60168_controller_init.c.
Referenced by rtc_irq(), and special_qt60168_send_cmd().
int report_state = 0 [static] |
Definition at line 58 of file qt60168_controller_init.c.
Referenced by special_qt60168_report_all_key().