This file is the QT60168 driver.
Definition in file qt60168.c.
#include "board.h"
#include "compiler.h"
#include "gpio.h"
#include "cycle_counter.h"
#include "conf_qt60168.h"
#include "qt60168.h"
#include "spi.h"
#include "print_funcs.h"
Go to the source code of this file.
Functions | |
int | qt60168_check_device_ready () |
void | qt60168_get_reply (unsigned short *data) |
Get the QT60168 reply. | |
void | qt60168_init (U32 cpu_hz) |
Initialize the QT60168 component. | |
Bool | qt60168_is_key_pressed (U8 key_id) |
Test if no keys are pressed. | |
Bool | qt60168_is_no_key_pressed (void) |
Test if no keys are pressed. | |
int | qt60168_report_all_key (void) |
Report all key status. | |
void | qt60168_send_cmd (unsigned char cmd) |
Send a command to the QT60168. | |
static void | qt60168_setup (void) |
Init the QT60168 blocks. | |
void | qt60168_wait_cmd_received (void) |
Wait for command reception. | |
Variables | |
U32 | g_cpu_hz |
int qt60168_check_device_ready | ( | ) |
Definition at line 292 of file qt60168.c.
References g_cpu_hz.
Referenced by qt60168_wait_cmd_received().
00293 { 00294 #ifndef QT60168_DISABLE_DRDY 00295 int value; 00296 static const gpio_map_t SDRAMC_EBI_GPIO_MAP = 00297 { 00298 {AVR32_EBI_NWE1_0_PIN,AVR32_EBI_NWE1_0_FUNCTION} 00299 }; 00300 gpio_enable_gpio_pin(QT60168_DRDY_PIN); 00301 // Wait for 1 us 00302 cpu_delay_cy( cpu_us_2_cy(1, g_cpu_hz) ); 00303 // Get Value 00304 value=gpio_get_pin_value(QT60168_DRDY_PIN); 00305 // Give AVR32_EBI_NWE1_0_FUNCTION back 00306 gpio_enable_module(SDRAMC_EBI_GPIO_MAP, sizeof(SDRAMC_EBI_GPIO_MAP) / sizeof(SDRAMC_EBI_GPIO_MAP[0])); 00307 return value; 00308 #else 00309 // Wait for 3000 us 00310 cpu_delay_cy( cpu_us_2_cy(26000, g_cpu_hz) ); 00311 return 1; 00312 #endif 00313 }
void qt60168_get_reply | ( | unsigned short * | data | ) |
Get the QT60168 reply.
*data | The data to read |
Definition at line 216 of file qt60168.c.
References QT60168_CMD_NULL_COMMAND, and qt60168_wait_cmd_received().
Referenced by qt60168_init(), qt60168_is_key_pressed(), qt60168_is_no_key_pressed(), qt60168_report_all_key(), and qt60168_setup().
00217 { 00218 // Select QT60168 00219 spi_selectChip(QT60168_SPI,QT60168_SPI_NCPS); 00220 00221 // Send NULL COMMAND 00222 spi_write(QT60168_SPI, QT60168_CMD_NULL_COMMAND); 00223 00224 // Wait for DRDY 00225 qt60168_wait_cmd_received(); 00226 00227 // Read Reply 00228 spi_read(QT60168_SPI, data); 00229 00230 // Unselect QT60168 00231 spi_unselectChip(QT60168_SPI,QT60168_SPI_NCPS); 00232 00233 return; 00234 }
void qt60168_init | ( | U32 | cpu_hz | ) |
Initialize the QT60168 component.
cpu_hz | The CPU frequency in hertz. |
Definition at line 156 of file qt60168.c.
References qt60168_setups_block_t::crc, g_cpu_hz, QT60168_CMD_CAL_ALL, QT60168_CMD_EEPROM_CRC, QT60168_CMD_FORCE_RESET, QT60168_CMD_GENERAL_STATUS, qt60168_get_reply(), QT60168_REPLY_FORCE_RESET, qt60168_send_cmd(), qt60168_setup(), qt60168_setups_block, and QT60168_STATUS_KEY_IN_CALIBRATION_MASK.
Referenced by main().
00157 { 00158 unsigned short dataread; 00159 g_cpu_hz = cpu_hz; 00160 00161 // Check CRC 00162 qt60168_send_cmd(QT60168_CMD_EEPROM_CRC); 00163 qt60168_get_reply(&dataread); 00164 if(dataread != qt60168_setups_block.crc) 00165 { 00166 // Load EEPROM 00167 qt60168_setup(); 00168 00169 // Reset 00170 do 00171 { 00172 // The command must be repeated 2x within 100ms or the 00173 // command will fail. 00174 qt60168_send_cmd(QT60168_CMD_FORCE_RESET); 00175 qt60168_send_cmd(QT60168_CMD_FORCE_RESET); 00176 qt60168_get_reply(&dataread); 00177 } 00178 while(dataread != QT60168_REPLY_FORCE_RESET); 00179 } 00180 00181 // Calibration 00182 // The command must be repeated 2x within 100ms or the 00183 // command will fail. 00184 qt60168_send_cmd(QT60168_CMD_CAL_ALL); 00185 qt60168_send_cmd(QT60168_CMD_CAL_ALL); 00186 qt60168_get_reply(&dataread); 00187 00188 // Wait for Calibration 00189 do 00190 { 00191 qt60168_send_cmd(QT60168_CMD_GENERAL_STATUS); 00192 qt60168_get_reply(&dataread); 00193 00194 } 00195 while(dataread & QT60168_STATUS_KEY_IN_CALIBRATION_MASK); 00196 return; 00197 }
Bool qt60168_is_key_pressed | ( | U8 | key | ) |
Test if no keys are pressed.
key | Key id that will be tested. |
TRUE | That key is pressed. | |
FALSE | That key is not pressed. |
Definition at line 126 of file qt60168.c.
References QT60168_CMD_STATUS_FOR_KEY_K, qt60168_get_reply(), QT60168_KEY_STATUS_DETECTED, and qt60168_send_cmd().
Referenced by main().
00127 { 00128 unsigned short dataread, crc; 00129 00130 qt60168_send_cmd(QT60168_CMD_STATUS_FOR_KEY_K | (key_id &0x1F)); 00131 qt60168_get_reply(&dataread); 00132 qt60168_get_reply(&crc); // Trash CRC of QT60168_CMD_STATUS_FOR_KEY_K 00133 00134 if(dataread & QT60168_KEY_STATUS_DETECTED) return TRUE; 00135 else return FALSE; 00136 }
Bool qt60168_is_no_key_pressed | ( | void | ) |
Test if no keys are pressed.
TRUE | No key pressed (idle). | |
FALSE | One or more keys are pressed. |
Definition at line 114 of file qt60168.c.
References QT60168_CMD_REPORT_1ST_KEY, qt60168_get_reply(), and qt60168_send_cmd().
00115 { 00116 unsigned short dataread, crc; 00117 00118 qt60168_send_cmd(QT60168_CMD_REPORT_1ST_KEY); 00119 qt60168_get_reply(&dataread); 00120 qt60168_get_reply(&crc); // Trash CRC of QT60168_CMD_REPORT_1ST_KEY 00121 00122 if((dataread&0x1F)==0x1F) return TRUE; 00123 else return FALSE; 00124 }
int qt60168_report_all_key | ( | void | ) |
Report all key status.
int | where : bit0 is key 0 bit1 is key 1 bit2 is key 2 ..... ... .. bit23 is key 23 |
Definition at line 138 of file qt60168.c.
References QT60168_CMD_REPORT_ALL_KEYS, qt60168_get_reply(), and qt60168_send_cmd().
00139 { 00140 unsigned short dataread, crc; 00141 00142 int allKey=0; 00143 qt60168_send_cmd(QT60168_CMD_REPORT_ALL_KEYS); 00144 qt60168_get_reply(&dataread); 00145 allKey=dataread; 00146 qt60168_get_reply(&dataread); 00147 allKey|=dataread<<8; 00148 qt60168_get_reply(&dataread); 00149 allKey|=dataread<<16; 00150 qt60168_get_reply(&crc); // Trash CRC of QT60168_CMD_REPORT_ALL_KEYS 00151 00152 return allKey; 00153 00154 }
void qt60168_send_cmd | ( | unsigned char | cmd | ) |
Send a command to the QT60168.
cmd | Command |
Definition at line 199 of file qt60168.c.
References qt60168_wait_cmd_received().
Referenced by qt60168_init(), qt60168_is_key_pressed(), qt60168_is_no_key_pressed(), qt60168_report_all_key(), and qt60168_setup().
00200 { 00201 // Select QT60168 00202 spi_selectChip(QT60168_SPI,QT60168_SPI_NCPS); 00203 00204 // Write CMD 00205 spi_write(QT60168_SPI, cmd); 00206 00207 // Wait for DRDY 00208 qt60168_wait_cmd_received(); 00209 00210 // Unselect QT60168 00211 spi_unselectChip(QT60168_SPI,QT60168_SPI_NCPS); 00212 00213 return; 00214 }
static void qt60168_setup | ( | void | ) | [static] |
Init the QT60168 blocks.
Definition at line 240 of file qt60168.c.
References qt60168_setups_block_t::bs, qt60168_key_cfg_t::fdil_ndil, qt60168_setups_block_t::key_cfg, qt60168_setups_block_t::lsl, qt60168_setups_block_t::msync, qt60168_key_cfg_t::ndrift_nthr, qt60168_key_cfg_t::nrd, QT60168_CMD_ENTER_SETUPS_MODE, qt60168_get_reply(), QT60168_MAX_NUMBER_OF_KEYS, QT60168_REPLY_ENTER_SETUPS_MODE, qt60168_send_cmd(), qt60168_setups_block, and qt60168_key_cfg_t::ssync_aks_bl.
Referenced by qt60168_init().
00241 { 00242 unsigned short dataread; 00243 int i; 00244 00245 // The command must be repeated 2x within 100ms or the 00246 // command will fail. 00247 qt60168_send_cmd(QT60168_CMD_ENTER_SETUPS_MODE); 00248 qt60168_send_cmd(QT60168_CMD_ENTER_SETUPS_MODE); 00249 00250 qt60168_get_reply(&dataread); 00251 00252 if(dataread != QT60168_REPLY_ENTER_SETUPS_MODE) return; 00253 00254 // Send NTHR and NDRIFT 00255 for( i=0 ; i<QT60168_MAX_NUMBER_OF_KEYS ; i++ ) 00256 { 00257 qt60168_send_cmd(qt60168_setups_block.key_cfg[i].ndrift_nthr); 00258 } 00259 00260 for( i=0 ; i<QT60168_MAX_NUMBER_OF_KEYS ; i++) 00261 { 00262 qt60168_send_cmd(qt60168_setups_block.key_cfg[i].fdil_ndil); 00263 } 00264 00265 // Send NRD 00266 for( i=0 ; i<QT60168_MAX_NUMBER_OF_KEYS ; i++) 00267 { 00268 qt60168_send_cmd(qt60168_setups_block.key_cfg[i].nrd); 00269 } 00270 00271 // Send BL, AKS, SSYNC 00272 for( i=0 ; i<QT60168_MAX_NUMBER_OF_KEYS ; i++) 00273 { 00274 qt60168_send_cmd(qt60168_setups_block.key_cfg[i].ssync_aks_bl); 00275 } 00276 00277 // Send MSYNC 00278 qt60168_send_cmd(qt60168_setups_block.msync); 00279 00280 // Send BS 00281 qt60168_send_cmd(qt60168_setups_block.bs); 00282 00283 // Send LSL 00284 qt60168_send_cmd(qt60168_setups_block.lsl & 0xFF); 00285 qt60168_send_cmd(qt60168_setups_block.lsl >> 8); 00286 00287 qt60168_get_reply(&dataread); 00288 qt60168_get_reply(&dataread); 00289 return; 00290 }
void qt60168_wait_cmd_received | ( | void | ) |
Wait for command reception.
Definition at line 315 of file qt60168.c.
References g_cpu_hz, and qt60168_check_device_ready().
Referenced by qt60168_get_reply(), and qt60168_send_cmd().
00316 { 00317 00318 00319 // Wait for 40 us before looking at DRDY 00320 cpu_delay_cy( cpu_us_2_cy(40, g_cpu_hz) ); 00321 while(!qt60168_check_device_ready()); 00322 00323 return; 00324 }
U32 g_cpu_hz |
Definition at line 96 of file qt60168.c.
Referenced by qt60168_check_device_ready(), qt60168_init(), and qt60168_wait_cmd_received().