Fork of I2C_LEDs by Matthias Hemmer

Revision:
1:97a7e9e9a229
Parent:
0:d7de08989175
--- a/I2C.cpp	Mon Feb 29 12:06:30 2016 +0000
+++ b/I2C.cpp	Sun Apr 24 08:29:05 2016 +0000
@@ -1,54 +1,51 @@
+#include "I2C.h"
 #include "mbed.h"
-#include "I2C.h"
 
-I2C pc9555 (p28, p27);    //SDA,SCL
+I2C i2c(p28, p27);   // (SDA, SCL)
 
-void bertl_PC9555_init()
-{
-    char data[2];
-    
-    // I2C Initialisierung
-    pc9555.frequency(PC9555_FREQUENCY);
-    
-    // Port 0 = LEDs
-    
-    // Adresse, RW# = 0, Config Port 0 (6) = 0x00 (=OutPut), Stop
-    data[0] = PC9555_Port0_DIR_IN;
-    data[1] = 0x00;     // Output    
-    pc9555.write(PC9555_ADDR, data, 2);  
-    
-    // Adresse, RW# = 0, Config Port 1 (7) = 0x00 (=InPut), Stop
-    data[0] = PC9555_Port1_DIR_IN;
-    data[1] = 0xFF;     // Input
-    pc9555.write(PC9555_ADDR, data, 2);  
+void init(){
+        char data[2];
+        
+        i2c.frequency(FREQUENCY);
+        
+        // port 0 = LEDs
+        
+        // declaration of polarity inversion port 0
+        data[0] = Invers0;
+        data[1] = 0xFF;     // Input
+        i2c.write(Addrs, data, 2);
+        
+        // declaration of polarity inversion port 1
+        data[0] = Invers1;
+        data[1] = 0x00;     // Output
+        i2c.write(Addrs, data, 2);
+        
+        // declaration of the Configuration port 0
+        data[0] = Config0;
+        data[1] = 0x00;     // Input
+        i2c.write(Addrs, data, 2);
+        
+        // declaration of the Configuration port 1
+        data[0] = Config1;
+        data[1] = 0xFF;     // Output
+        i2c.write(Addrs, data, 2);
+    }
     
-    // Adresse, RW# = 0, Polarity Inversion Port 0 (4) = 0xFF (= inverted) , Stop  
-    data[0] = PC9555_Port0_INV;
-    data[1] = 0xFF;
-    pc9555.write(PC9555_ADDR, data, 2); 
-    
-     // Adresse, RW# = 0, Polarity Inversion Port 1 (5) = 0x00 (=NonInverted) , Stop
-    data[0] = PC9555_Port1_INV;
-    data[1] = 0x00;
-    pc9555.write(PC9555_ADDR, data, 2);      
-}
-
-void bertl_PC9555_leds(unsigned char leds)
-{
-    char data[2];   // Two Bytes for Transmitt via I2C
+void leds(unsigned char leds){
+        char data[2];
+        
+        data[0] = Output0;
+        data[1] = ~leds;        // look PCA9555 datasheet
+        i2c.write(Addrs, data, 2);
+    }
     
-    // Send leds to Port0 of PC9555 tp I2C: 
-    // Start, Adress, RW# = 0, CMD I2C_Port0_OUT , leds, Stop
-    data[0] = PC9555_Port0_OUT;
-    data[1] = ~leds;        //bitwise inversion since HW is switched on with 0 (invers logic)
-    pc9555.write(PC9555_ADDR, data, 2);
-}
-
-unsigned char bertl_PC9555_switches()
-{
-    char data[1];
-    data[0] = PC9555_Port1_IN;
-    pc9555.write(PC9555_ADDR, data, 1, true); // tell him, we want to read Port1, no STOP
-    pc9555.read(PC9555_ADDR, data, 1, false); // read 1 byte, then send STOP
-    return((unsigned char) data[0]);
-}
\ No newline at end of file
+unsigned char buttons(){
+        char data[1];
+        
+        data[0] = Input1;
+        i2c.write(Addrs, data, 1, false);       // don't stop, becouse we want to read from Input1 the buttons
+        i2c.read(Addrs, data, 1, true);
+        
+        return ((unsigned char) data[0]);
+        
+    }
\ No newline at end of file