qt60168.h File Reference


Detailed Description

QT60168 driver for AVR32 UC3.

This file is the QT60168 driver.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file qt60168.h.

Go to the source code of this file.

Data Structures

struct  qt60168_key_cfg_t
struct  qt60168_setups_block_t

Defines

#define QT60168_CMD_CAL_ALL   0x03
#define QT60168_CMD_CAL_KEY_K   0xC0
#define QT60168_CMD_DATA_FOR_1_KEY   0x40
#define QT60168_CMD_DUMP_SETUPS   0x0D
#define QT60168_CMD_EEPROM_CRC   0x0E
#define QT60168_CMD_ENTER_SETUPS_MODE   0x01
#define QT60168_CMD_ERROR_FLAGS_FOR_ALL   0x0B
#define QT60168_CMD_FMEA_STATUS   0x0C
#define QT60168_CMD_FORCE_RESET   0x04
#define QT60168_CMD_GENERAL_STATUS   0x05
#define QT60168_CMD_INTERNAL_CODE_0X10   0x10
#define QT60168_CMD_INTERNAL_CODE_0X12   0x12
#define QT60168_CMD_NULL_COMMAND   0x00
#define QT60168_CMD_REPORT_1ST_KEY   0x06
#define QT60168_CMD_REPORT_ALL_KEYS   0x07
#define QT60168_CMD_RETURN_LAST_CMMD   0x0F
#define QT60168_CMD_STATUS_FOR_KEY_K   0x80
#define QT60168_KEY_STATUS_CAL_FAILED   0x01
#define QT60168_KEY_STATUS_DETECTED   0x08
#define QT60168_KEY_STATUS_ENABLED   0x10
#define QT60168_KEY_STATUS_IN_CAL   0x02
#define QT60168_KEY_STATUS_LOW_SIGNAL   0x04
#define QT60168_MAX_NUMBER_OF_KEYS   24
#define QT60168_REPLY_ENTER_SETUPS_MODE   0xFE
#define QT60168_REPLY_FORCE_RESET   0xFB
#define QT60168_STATUS_CALIBRATION_FAILED_MASK   0x04
#define QT60168_STATUS_COMM_ERROR_MASK   0x40
#define QT60168_STATUS_FMEA_ERROR_MASK   0x20
#define QT60168_STATUS_KEY_DETECTED_MASK   0x01
#define QT60168_STATUS_KEY_IN_CALIBRATION_MASK   0x02
#define QT60168_STATUS_MAIN_SYNC_ERROR_MASK   0x08

Functions

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)
 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.


Define Documentation

#define QT60168_CMD_CAL_ALL   0x03

Definition at line 54 of file qt60168.h.

Referenced by qt60168_init().

#define QT60168_CMD_CAL_KEY_K   0xC0

Definition at line 68 of file qt60168.h.

#define QT60168_CMD_DATA_FOR_1_KEY   0x40

Definition at line 66 of file qt60168.h.

#define QT60168_CMD_DUMP_SETUPS   0x0D

Definition at line 61 of file qt60168.h.

#define QT60168_CMD_EEPROM_CRC   0x0E

Definition at line 62 of file qt60168.h.

Referenced by qt60168_init().

#define QT60168_CMD_ENTER_SETUPS_MODE   0x01

Definition at line 53 of file qt60168.h.

Referenced by qt60168_setup().

#define QT60168_CMD_ERROR_FLAGS_FOR_ALL   0x0B

Definition at line 59 of file qt60168.h.

#define QT60168_CMD_FMEA_STATUS   0x0C

Definition at line 60 of file qt60168.h.

#define QT60168_CMD_FORCE_RESET   0x04

Definition at line 55 of file qt60168.h.

Referenced by qt60168_init().

#define QT60168_CMD_GENERAL_STATUS   0x05

Definition at line 56 of file qt60168.h.

Referenced by qt60168_init().

#define QT60168_CMD_INTERNAL_CODE_0X10   0x10

Definition at line 64 of file qt60168.h.

#define QT60168_CMD_INTERNAL_CODE_0X12   0x12

Definition at line 65 of file qt60168.h.

#define QT60168_CMD_NULL_COMMAND   0x00

Definition at line 52 of file qt60168.h.

Referenced by qt60168_get_reply().

#define QT60168_CMD_REPORT_1ST_KEY   0x06

Definition at line 57 of file qt60168.h.

Referenced by qt60168_is_no_key_pressed().

#define QT60168_CMD_REPORT_ALL_KEYS   0x07

Definition at line 58 of file qt60168.h.

Referenced by qt60168_report_all_key().

#define QT60168_CMD_RETURN_LAST_CMMD   0x0F

Definition at line 63 of file qt60168.h.

#define QT60168_CMD_STATUS_FOR_KEY_K   0x80

Definition at line 67 of file qt60168.h.

Referenced by qt60168_is_key_pressed().

#define QT60168_KEY_STATUS_CAL_FAILED   0x01

Definition at line 81 of file qt60168.h.

#define QT60168_KEY_STATUS_DETECTED   0x08

Definition at line 84 of file qt60168.h.

Referenced by qt60168_is_key_pressed().

#define QT60168_KEY_STATUS_ENABLED   0x10

Definition at line 85 of file qt60168.h.

#define QT60168_KEY_STATUS_IN_CAL   0x02

Definition at line 82 of file qt60168.h.

#define QT60168_KEY_STATUS_LOW_SIGNAL   0x04

Definition at line 83 of file qt60168.h.

#define QT60168_MAX_NUMBER_OF_KEYS   24

Definition at line 88 of file qt60168.h.

Referenced by qt60168_setup().

#define QT60168_REPLY_ENTER_SETUPS_MODE   0xFE

Definition at line 71 of file qt60168.h.

Referenced by qt60168_setup().

#define QT60168_REPLY_FORCE_RESET   0xFB

Definition at line 70 of file qt60168.h.

Referenced by qt60168_init().

#define QT60168_STATUS_CALIBRATION_FAILED_MASK   0x04

Definition at line 75 of file qt60168.h.

#define QT60168_STATUS_COMM_ERROR_MASK   0x40

Definition at line 78 of file qt60168.h.

#define QT60168_STATUS_FMEA_ERROR_MASK   0x20

Definition at line 77 of file qt60168.h.

#define QT60168_STATUS_KEY_DETECTED_MASK   0x01

Definition at line 73 of file qt60168.h.

#define QT60168_STATUS_KEY_IN_CALIBRATION_MASK   0x02

Definition at line 74 of file qt60168.h.

Referenced by qt60168_init().

#define QT60168_STATUS_MAIN_SYNC_ERROR_MASK   0x08

Definition at line 76 of file qt60168.h.


Function Documentation

void qt60168_get_reply ( unsigned short *  data  ) 

Get the QT60168 reply.

Parameters:
*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.

Parameters:
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.

Parameters:
key Key id that will be tested.
Return values:
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.

Return values:
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.

Return values:
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.

Parameters:
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 }


Generated on Fri Feb 19 02:24:04 2010 for AVR32 - QT60168 Driver by  doxygen 1.5.5