Bert Gereels & Dylan Timmerman

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
bertgereels
Date:
Wed Dec 14 13:35:53 2016 +0000
Commit message:
Capacitive Touch program; by Bert Gereels & Dylan Timmerman

Changed in this revision

i2c_qt1070.cpp Show annotated file Show diff for this revision Revisions of this file
i2c_qt1070.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
qt1070.cpp Show annotated file Show diff for this revision Revisions of this file
qt1070.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 620ca2412ef6 i2c_qt1070.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/i2c_qt1070.cpp	Wed Dec 14 13:35:53 2016 +0000
@@ -0,0 +1,73 @@
+#include "i2c_qt1070.h"
+extern "C" void mbed_reset();
+
+namespace I2cQt1070Device{
+    I2cQt1070::I2cQt1070(PinName sda, PinName scl, int address, int frequency)
+    : I2CSlave(sda, scl){
+        
+        this->address(address);
+        this->frequency(frequency);
+    }
+    
+    void I2cQt1070::check_for_instruction(void){
+        int addressed = receive(); 
+        switch (addressed) {
+            case I2CSlave::WriteAddressed:{
+                printf("Write addressedd\r\n");
+                process_write_request();
+                break;
+            }   
+            case I2CSlave::ReadAddressed:{
+                printf("Read addressedd\r\n");
+                send_register_to_master();
+                break;
+            }   
+        }
+    }
+    
+    void I2cQt1070::send_register_to_master(void){ 
+        switch(qt1070Address){
+            case READ_ID:{
+                printf("Received id command\r\n");
+                char id = qt1070.getId();
+                char buffer[1];
+                buffer[0] = id;
+                write(buffer,1);
+                break;
+            } 
+            case READ_FIRMWARE:{
+                printf("Received firmware command\r\n");
+                char version = qt1070.getFirmware();  
+                char buffer[1];
+                buffer[0] = version;
+                write(buffer,1);     
+                break;
+            }
+            case READ_KEY_STATUS:{
+                printf("Received key status command\r\n");
+                char status = qt1070.getStatus();
+                char buffer[1];
+                buffer[0] = status;
+                write(buffer,1);
+                break;
+            }
+            
+            case RESET:{
+                printf("Received reset command\r\n");
+                mbed_reset();
+                stop();
+                break;
+            }
+            default:{
+                printf("Unknown command byte recieved from master\r\n");
+            }
+        }  
+    }
+
+    int I2cQt1070::process_write_request(void){
+        char nextQt1070Address = this->read();
+            this->qt1070Address = nextQt1070Address;
+        this->stop();
+    }
+
+};
\ No newline at end of file
diff -r 000000000000 -r 620ca2412ef6 i2c_qt1070.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/i2c_qt1070.h	Wed Dec 14 13:35:53 2016 +0000
@@ -0,0 +1,28 @@
+#pragma once
+#include "qt1070.h"
+#include "mbed.h"
+
+namespace I2cQt1070Device{
+    
+   enum I2cInstruction{
+        READ_ID = 0, //adres 0x00
+        READ_FIRMWARE = 1, //adres 0x01
+        READ_KEY_STATUS  = 3,  //adres 0x03
+        RESET = 57//0x57  
+    };
+    
+    class I2cQt1070: public I2CSlave{
+        
+        private:
+            Qt1070 qt1070;
+            char qt1070Address;
+            void send_register_to_master(void);
+            int process_write_request(void);
+            
+        public:
+            I2cQt1070(PinName sda, PinName scl, int address=0x36, int frequency=100000);
+            void check_for_instruction(void);
+
+    };
+    
+};
\ No newline at end of file
diff -r 000000000000 -r 620ca2412ef6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 14 13:35:53 2016 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "qt1070.h"
+#include "i2c_qt1070.h"
+
+DigitalOut myled3(LED3);
+DigitalOut myled2(LED2);
+DigitalOut myled1(LED1);
+
+using namespace I2cQt1070Device;
+int main() {
+    
+    I2cQt1070 i2cQt1070(p28, p27, 0x36, 100000);
+    int cycleCounter = 0;
+    while(1){
+      i2cQt1070.check_for_instruction();
+        
+       cycleCounter ++;
+       
+       if(cycleCounter >= 100000){
+            myled1 = !myled1;
+            myled2 = !myled2;
+            myled3 = !myled3;
+            cycleCounter = 0;
+        }
+    }
+}
diff -r 000000000000 -r 620ca2412ef6 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 14 13:35:53 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0
\ No newline at end of file
diff -r 000000000000 -r 620ca2412ef6 qt1070.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qt1070.cpp	Wed Dec 14 13:35:53 2016 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+#include "qt1070.h"
+
+BusIn joy(p15,p12,p13,p16,p14);
+
+namespace I2cQt1070Device{
+    
+    Qt1070::Qt1070(unsigned int version, unsigned int id){
+        this->id = id;
+        this->version = version;
+        this->status = 0;
+    }
+        
+    int Qt1070::getId(){   //Address 0: Chip ID
+        return id;
+    }
+    
+     int Qt1070::getFirmware(){ //Address 1: Firmware Version
+        return version;
+    }
+    
+    int Qt1070::getStatus(){ //Address 3: Key Status
+        int status = joy.read();
+        return status;
+    }
+    
+};
\ No newline at end of file
diff -r 000000000000 -r 620ca2412ef6 qt1070.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qt1070.h	Wed Dec 14 13:35:53 2016 +0000
@@ -0,0 +1,29 @@
+#pragma once                
+#include "mbed.h"
+
+namespace I2cQt1070Device{       
+    
+    enum ButtonState{     
+        UP = 0x04,
+        DOWN = 0x08,  
+        LEFT = 0x01,
+        RIGHT = 0x02,
+        CENTER = 0x10 
+    };
+    
+    class Qt1070{
+        
+        private:
+            unsigned int version;
+            unsigned int id;
+            char status;
+        
+        public:
+            Qt1070(unsigned int version = 0x01, unsigned int id = 0xE2);
+            int getFirmware();
+            int getId();
+            int getStatus(); //status van knop (byte)
+          
+    };
+};
+