Ken Parish / Mbed 2 deprecated XYZ_01

Dependencies:   QT60486 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "QT60486.h"
00003 
00004 #define NUM_KEYS 48
00005 
00006 SPI captouch(p5,p6,p7);
00007 DigitalOut qt_cs (p8);
00008 DigitalOut qt_wake (p9);
00009 DigitalIn qt_drdy (p10);
00010 Serial pc(USBTX, USBRX);
00011 
00012 uint16_t keydata[NUM_KEYS];
00013 uint16_t * p;
00014 
00015 void qt_signalAll(void);
00016 
00017 bool qt_proxsetup(void);
00018 
00019 bool qt_calAll(void);
00020 
00021 void setup() {
00022     pc.baud(38400);
00023     pc.printf("baudset\r\n");
00024     captouch.format(8,3);
00025     pc.printf("formated\r\n");
00026     qt_cs = 1; // set pin high, disables communication
00027     while(qt_proxsetup() == false)
00028        {;;}   
00029     pc.printf("setup_done\r\n");
00030  }
00031  
00032  
00033 int main()                     
00034  {
00035     setup();
00036     
00037    qt_signalAll();
00038    
00039    for(uint8_t i = 0; i < NUM_KEYS; i ++)
00040    {
00041    pc.printf("%i\t",keydata[i]); 
00042    }
00043    pc.printf("\r\n");
00044    
00045    wait(0.001);
00046  }
00047  
00048 
00049 void qt_signalAll(void) 
00050   {
00051     qt_cs = 0;
00052     captouch.write(SIGNAL_ALL);
00053     while(qt_drdy == 0){
00054         for(uint8_t i = 0; i < NUM_KEYS; i ++ ){
00055             keydata[i] = ((captouch.write(0x00) << 8) & captouch.write(0x00));
00056              }
00057     }
00058 
00059 };
00060 
00061 
00062    
00063  
00064  
00065 bool qt_proxsetup(void)
00066   { 
00067     //bool ret = false;
00068     //qt_cs = 0;
00069     //uint8_t ret = 0x00;
00070     //while(captouch.write(0x0F) != 0xF0)
00071     //  {;;}
00072     //ret = captouch.write(ENTER_SETUP);
00073     //ret = captouch.write(ENTER_SETUP);
00074       
00075     //while(captouch.write(0x00) != 0xFE)
00076      // {;;}    
00077       
00078      // captouch.write(0x00);
00079      // captouch.write(0x00);
00080       
00081      // qt_cs = 1;
00082       
00083      // wait(0.025);
00084       
00085       qt_cs = 0;
00086       
00087       //captouch.write(FORCE_RESET);
00088     
00089       //while(captouch.write(0x0F) != 0xF0)
00090       //  {;;}  
00091       
00092       while(qt_calAll() == false)
00093         {;;}  
00094     
00095       pc.printf("caldone\r\n");
00096       captouch.write(REPORT_FIRST);
00097       
00098        if (qt_drdy == 0) {
00099             while (qt_drdy == 0)
00100             {;;}
00101             }
00102       
00103       if (captouch.write(0x00) != 0x3F)
00104             {qt_calAll();
00105             }  
00106       while(qt_calAll() == false)
00107         {;;}  
00108       
00109       return true;
00110   };
00111   
00112   
00113   bool qt_calAll(void)
00114       { 
00115       pc.printf("calibrating...\r\n");
00116         bool ret = false;
00117         captouch.write(CAL_ALL);
00118         if (qt_drdy == 0) {
00119             while (qt_drdy == 0)
00120             {;;}
00121             }
00122         captouch.write(CAL_ALL);
00123         if (qt_drdy == 0) {
00124             while (qt_drdy == 0)
00125             {;;}
00126             }
00127             pc.printf("comms...\r\n");
00128         while(captouch.write(0x00) != 0xFC)
00129             {;;}  
00130         
00131         //uint8_t genstat = captouch.write(GENERAL_STATUS);
00132         //ret = !(genstat & 0x04);
00133         ret = true;
00134         pc.printf("ret %i\r\n", ret);
00135         return ret; 
00136   }
00137   
00138   
00139   
00140   
00141   
00142   
00143