This file is the QT60168 driver.
Definition in file qt60168.h.
Go to the source code of this file.
#define QT60168_CMD_CAL_ALL 0x03 |
#define QT60168_CMD_EEPROM_CRC 0x0E |
#define QT60168_CMD_ENTER_SETUPS_MODE 0x01 |
#define QT60168_CMD_FORCE_RESET 0x04 |
#define QT60168_CMD_GENERAL_STATUS 0x05 |
#define QT60168_CMD_NULL_COMMAND 0x00 |
#define QT60168_CMD_REPORT_1ST_KEY 0x06 |
#define QT60168_CMD_REPORT_ALL_KEYS 0x07 |
#define QT60168_CMD_STATUS_FOR_KEY_K 0x80 |
#define QT60168_KEY_STATUS_DETECTED 0x08 |
#define QT60168_MAX_NUMBER_OF_KEYS 24 |
#define QT60168_REPLY_ENTER_SETUPS_MODE 0xFE |
#define QT60168_REPLY_FORCE_RESET 0xFB |
#define QT60168_STATUS_KEY_IN_CALIBRATION_MASK 0x02 |
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 }