Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Revision:
33:1573db91352c
Parent:
23:dfb5ccc7b780
Child:
36:f6278b3e7c82
diff -r ef97c377d27b -r 1573db91352c Components/STMPE1600/stmpe1600_class.h
--- a/Components/STMPE1600/stmpe1600_class.h	Tue Nov 10 10:46:15 2015 +0000
+++ b/Components/STMPE1600/stmpe1600_class.h	Tue Nov 17 17:15:47 2015 +0100
@@ -43,20 +43,24 @@
 #define STMPE1600_DEF_DIGIOUT_LVL      1
 
 /**  STMPE1600 registr map **/
+#define ChipID_0_7      (uint8_t)0x00
+#define ChipID_8_15     (uint8_t)0x01
 #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_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 SYS_CTRL        (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_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 SOFT_RESET			(uint8_t)0x80
 
   typedef enum {
     // GPIO Expander pin names
@@ -75,7 +79,8 @@
     GPIO_12,
     GPIO_13,
     GPIO_14,
-    GPIO_15
+    GPIO_15,
+		NOT_CON
 } ExpGpioPinName;   
 
 typedef enum {
@@ -91,6 +96,7 @@
     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];				
+			 if (exppinname == NOT_CON) return;
        /* 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);			
@@ -103,6 +109,7 @@
     void write (int lvl) 
     {
        uint8_t data[2];			
+			 if (exppinname == NOT_CON) return;			
        /* set the exppinname state to lvl */
        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 			
@@ -128,6 +135,7 @@
     STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname) 
     {
        uint8_t data[2];
+			 if (exppinname == NOT_CON) return;			
        /* set the exppinname as input pin direction */
        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			
@@ -137,6 +145,7 @@
     bool read () 
     {
        uint8_t data[2];
+			 if (exppinname == NOT_CON) return 0;						
        /* read the exppinname */
        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
@@ -156,59 +165,76 @@
 };
 
 
-/*
 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)
-
+    STMPE1600 (DevI2C &i2c, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) : dev_i2c(i2c)
     { 
        dev_i2c = i2c;								
        expdevaddr = DevAddr;
+			 writeSYS_CTRL (SOFT_RESET);
+			
        GPDR0_15 = (uint16_t)0;	// gpio dir all IN
+			 write16bitReg (GPDR_0_7, &GPDR0_15);			
        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);	
+			 write16bitReg (GPSR_0_7, &GPSR0_15);			
     }
-											
-    void readGPSR0_15 (uint16_t * gpsr0_15)
+
+    void writeSYS_CTRL (uint8_t data)     // data = SOFT_RESET reset the device
     {
-       dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2);
-       GPSR0_15 = gpsr0_15;
+	     dev_i2c.i2c_write((uint8_t*)SYS_CTRL, expdevaddr, data, 1);
     }
 
-    void writeGPSR0_15 (uint16_t *gpsr0_15)
-    {
-       dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2);	
-       GPSR0_15 = *gpsr0_15;
-    }
+		bool setGPIO (ExpGpioPinName PinName) 
+		{
+			 if (PinName == NOT_CON) return true;			
+			 GPSR0_15 = GPSR0_15 | ((uint16_t)0x0001<<PinName);
+			 write16bitReg (GPSR_0_7 , &GPSR0_15);
+			 return false;
+		}
+
+		bool clrGPIO (ExpGpioPinName PinName) 
+		{
+			 if (PinName == NOT_CON) return true;			
+			 GPSR0_15 = GPSR0_15 & (~((uint16_t)0x0001<<PinName));
+			 write16bitReg (GPSR_0_7 , &GPSR0_15);
+			 return false;
+		}		
 		
- private:
+		bool rdGPIO (ExpGpioPinName PinName) 
+		{				
+			  uint16_t gpmr0_15;
+			  if (PinName == NOT_CON) return true;
+			  read16bitReg (GPMR_0_7, &gpmr0_15);
+			  gpmr0_15 = gpmr0_15 & ((uint16_t)0x0001<<PinName);
+			  if (gpmr0_15) return true; 			
+			  return false;			
+		}
+
+		bool setGPIOdir (ExpGpioPinName PinName, ExpGpioPinDirection PinDir) 
+		{
+				 if (PinName == NOT_CON || PinDir == NOT_CONNECTED) return true; 
+			   GPDR0_15 = GPDR0_15 & (~((uint16_t)0x0001<<PinName));  // clear the Pin
+			   GPDR0_15 = GPDR0_15 | ((uint16_t)PinDir<<PinName);
+			   write16bitReg (GPDR_0_7 , &GPDR0_15);
+			   return false;
+		}
+
+    void read16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
+    {
+       dev_i2c.i2c_read((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);	
+    }				
+		
+    void write16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
+    {
+       dev_i2c.i2c_write((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);	
+    }		
+
+ private:					
     DevI2C &dev_i2c; 	 
-    uint16_t GPDR0_15;
-    uint16_t GPSR0_15;
-    uint8_t expdevaddr;
+    uint16_t GPDR0_15;  // local copy of bit direction reg 
+    uint16_t GPSR0_15;  // local copy of bit status reg 
+    uint8_t expdevaddr; // expander device i2c addr
 };
-*/
+
 #endif // __STMPE1600_CLASS