Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Revision:
16:0d4776564733
Parent:
15:454710d17358
Child:
23:dfb5ccc7b780
diff -r 454710d17358 -r 0d4776564733 Components/STMPE1600/stmpe1600_class.h
--- a/Components/STMPE1600/stmpe1600_class.h	Tue Oct 20 16:44:28 2015 +0200
+++ b/Components/STMPE1600/stmpe1600_class.h	Tue Oct 27 15:25:11 2015 +0100
@@ -43,20 +43,20 @@
 #define STMPE1600_DEF_DIGIOUT_LVL      1
 
 /**  STMPE1600 registr map **/
-#define VersionId			(uint8_t)0x02
-#define SystemControl (uint8_t)0x03
-#define IEGPIOR_0_7		(uint8_t)0x08
+#define VersionId       (uint8_t)0x02
+#define SystemControl   (uint8_t)0x03
+#define IEGPIOR_0_7	(uint8_t)0x08
 #define IEGPIOR_8_15	(uint8_t)0x09
-#define ISGPIOR_0_7		(uint8_t)0x0A
+#define ISGPIOR_0_7	(uint8_t)0x0A
 #define ISGPIOR_8_15	(uint8_t)0x0B
-#define GPMR_0_7			(uint8_t)0x10
-#define GPMR_8_15			(uint8_t)0x11
-#define GPSR_0_7			(uint8_t)0x12
-#define GPSR_8_15			(uint8_t)0x13
-#define GPDR_0_7			(uint8_t)0x14
-#define GPDR_8_15			(uint8_t)0x15
-#define GPIR_0_7			(uint8_t)0x16
-#define GPIR_8_15			(uint8_t)0x17
+#define GPMR_0_7	(uint8_t)0x10
+#define GPMR_8_15	(uint8_t)0x11
+#define GPSR_0_7	(uint8_t)0x12
+#define GPSR_8_15	(uint8_t)0x13
+#define GPDR_0_7	(uint8_t)0x14
+#define GPDR_8_15	(uint8_t)0x15
+#define GPIR_0_7	(uint8_t)0x16
+#define GPIR_8_15	(uint8_t)0x17
 
   typedef enum {
     // GPIO Expander pin names
@@ -79,9 +79,9 @@
 } ExpGpioPinName;   
 
 typedef enum {
-    INPUT,
+    INPUT = 0,
     OUTPUT,
-	  NOT_CONNECTED
+    NOT_CONNECTED
 }ExpGpioPinDirection;
 
 
@@ -89,74 +89,122 @@
 	
  public: 
     STMPE1600DigiOut (DevI2C &i2c, ExpGpioPinName outpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS, bool lvl=STMPE1600_DEF_DIGIOUT_LVL): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(outpinname) 
-		{
-			uint8_t data[2];				
-			/* set the exppinname as output */
-			dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1);
-			dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1);			
-			*(uint16_t*)data = *(uint16_t*)data | (1<<(uint16_t)exppinname);  // set gpio as out 			
-			dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1);
-			dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1);			
-			write(lvl);
-			
-		}         
+    {
+       uint8_t data[2];				
+       /* set the exppinname as output */
+       dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1);
+       dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1);			
+       *(uint16_t*)data = *(uint16_t*)data | (1<<(uint16_t)exppinname);  // set gpio as out 			
+       dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1);
+       dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1);			
+       write(lvl);
+    }         
 
 		void write (int lvl) {
 			uint8_t data[2];			
 			/* set the exppinname state to lvl */
-			dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 1);
-			dev_i2c.i2c_read(&data[1], expdevaddr, GPSR_8_15, 1);			
+			dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 2);
 			*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname));  // set pin mask 			
-			if(lvl) 
-				 *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
-			dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 1);
-			dev_i2c.i2c_write(&data[1], expdevaddr, GPSR_8_15, 1);			
+			if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
+			dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2);
 		}
 		
-		STMPE1600DigiOut& operator=(int lvl) {
-			write (lvl);
-			return *this;
-		}		
+    STMPE1600DigiOut& operator=(int lvl)
+    {
+       write (lvl);
+       return *this;
+    }		
 		
  private:
-    DevI2C          &dev_i2c; 
-    uint8_t     		expdevaddr;
-    ExpGpioPinName 	exppinname; 	
+    DevI2C &dev_i2c; 
+    uint8_t expdevaddr;
+    ExpGpioPinName exppinname; 	
 };
 
-class STMPE1600DigiIn {
-	
+class STMPE1600DigiIn 
+{	
  public: 
-    STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr*2), exppinname(inpinname) 
+    STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname) 
 		{
 			uint8_t data[2];
 			/* set the exppinname as input pin direction */
-			dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1);
-			dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1);			
+			dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 2);
 			*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname));  // set gpio as in			
-			dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1);
-			dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1);						
+			dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2);
 		}         
 
 		bool read () {
 			uint8_t data[2];
 			/* read the exppinname */
-			dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 1);
-			dev_i2c.i2c_read(&data[1], expdevaddr, GPMR_8_15, 1);			
+			dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 2);
 			*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(1<<(uint16_t)exppinname);  // mask the in gpio
 			if (data[0] || data[1]) return 1;
 			return 0;
 		}
 		
-		operator int() {		
-			return read();
-		}		
+    operator int() 
+    {		
+       return read();
+    }		
 		
  private:
-    DevI2C          &dev_i2c; 
-    uint8_t     		expdevaddr;
-    ExpGpioPinName 	exppinname;      
+    DevI2C &dev_i2c; 
+    uint8_t expdevaddr;
+    ExpGpioPinName exppinname;      
 };
 
 
+/*
+class STMPE1600 {
+	
+ public: 
+    STMPE1600 (DevI2C &i2c, 
+											ExpGpioPinDirection GPDR0, ExpGpioPinDirection GPDR1, ExpGpioPinDirection GPDR2,
+                      ExpGpioPinDirection GPDR3, ExpGpioPinDirection GPDR4, ExpGpioPinDirection GPDR5,
+                      ExpGpioPinDirection GPDR6, ExpGpioPinDirection GPDR7, ExpGpioPinDirection GPDR8,
+                      ExpGpioPinDirection GPDR9, ExpGpioPinDirection GPDR10, ExpGpioPinDirection GPDR11,
+ ExpGpioPinDirection GPDR12, ExpGpioPinDirection GPDR13, ExpGpioPinDirection GPDR14, ExpGpioPinDirection GPDR15, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) :dev_i2c(i2c)
+
+ { 
+				dev_i2c = i2c;								
+				expdevaddr = DevAddr;
+			  GPDR0_15 = (uint16_t)0;	// gpio dir all IN
+			  GPSR0_15 = (uint16_t)0x0ffff;  // gpio status all 1
+				if (GPDR0  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0001;
+				if (GPDR1  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0002;																		 
+				if (GPDR2  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0004;
+				if (GPDR3  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0008;																		 
+				if (GPDR4  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0010;
+				if (GPDR5  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0020;																		 
+				if (GPDR6  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0040;
+				if (GPDR7  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0080;
+				if (GPDR8  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0100;
+				if (GPDR9  == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0200;
+				if (GPDR10 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0400;
+				if (GPDR11 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0800;																		 
+				if (GPDR12 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x1000;																		 
+				if (GPDR13 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x2000;																		 
+				if (GPDR14 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x4000;									
+				if (GPDR15 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x8000;	
+				dev_i2c.i2c_write((uint8_t*)&GPDR0_15, expdevaddr, GPDR_0_7, 2);	
+				dev_i2c.i2c_write((uint8_t*)&GPSR0_15, expdevaddr, GPSR_0_7, 2);	
+		}
+											
+		void readGPSR0_15 (uint16_t * gpsr0_15){
+			dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2);
+			GPSR0_15 = gpsr0_15;
+		}
+
+		void writeGPSR0_15 (uint16_t *gpsr0_15){
+			dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2);	
+			GPSR0_15 = *gpsr0_15;
+		}
+		
+ private:
+    DevI2C           &dev_i2c; 	 
+		uint16_t 					GPDR0_15;
+		uint16_t					GPSR0_15;
+		uint8_t     		  expdevaddr;
+ };
+*/
 #endif // __STMPE1600_CLASS