Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Revision:
36:f6278b3e7c82
Parent:
34:5bcffb4c5b47
Child:
39:3cce4ba37695
diff -r 407b0b127eb8 -r f6278b3e7c82 Components/Display/Display_class.h
--- a/Components/Display/Display_class.h	Wed Nov 18 16:35:04 2015 +0000
+++ b/Components/Display/Display_class.h	Tue Nov 24 16:04:41 2015 +0000
@@ -47,12 +47,6 @@
 extern "C" {
 #endif
 
-#define DISPLAY_USING_STMPE1600  	
-	
-#ifndef DISPLAY_USING_STMPE1600
-#define FAST_DISPLAY   // fast quick and dirty display to speed up
-#endif	
-
 #define DP  (1<<7)
 #define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP )
 #define S0 (1<<0)
@@ -141,8 +135,6 @@
       ['X']=           NOT_7_NO_DP(S0+S3), // similar to H
       ['Y']=           NOT_7_NO_DP(S0+S4),
       ['Z']=           S0+S1+S6+S4+S3, // same as 2
-
-
 };
 
 #undef S0
@@ -159,232 +151,37 @@
 /* Classes -------------------------------------------------------------------*/
 /** Class representing Display
  */ 
-#ifndef DISPLAY_USING_STMPE1600
 
 class Display
 {
  public:
-
-#ifndef FAST_DISPLAY
- 
-    Display(DevI2C &i2c, STMPE1600DigiOut &D1,	STMPE1600DigiOut &D2, STMPE1600DigiOut &D3, STMPE1600DigiOut &D4,
-	    STMPE1600DigiOut &D_A, STMPE1600DigiOut &D_B, STMPE1600DigiOut &D_C, STMPE1600DigiOut &D_D,
-	    STMPE1600DigiOut &D_E, STMPE1600DigiOut &D_F, STMPE1600DigiOut &D_G)
-	    : Display_D1(D1), Display_D2(D2), Display_D3(D3), Display_D4(D4), Display_A(D_A), Display_B(D_B), 
-            Display_C(D_C), Display_D(D_D), Display_E(D_E), Display_F(D_F), Display_G(D_G), dev_i2c(i2c)
-	    {
-	       pDisplay_DGT[0] = &Display_D1;
-	       pDisplay_DGT[1] = &Display_D2;
-	       pDisplay_DGT[2] = &Display_D3;
-	       pDisplay_DGT[3] = &Display_D4;	
-	       pDisplay_SEG[0] = &Display_A;
-	       pDisplay_SEG[1] = &Display_B;
-	       pDisplay_SEG[2] = &Display_C;
-	       pDisplay_SEG[3] = &Display_D;
-	       pDisplay_SEG[4] = &Display_E;
-	       pDisplay_SEG[5] = &Display_F;
-	       pDisplay_SEG[6] = &Display_G;		
-
-	       for (int i=0; i<4; i++) { *pDisplay_DGT[i]=1; }
-	       for (int i=0; i<7; i++) { *pDisplay_SEG[i]=1; }		
-	    }
-#else		
-    Display(DevI2C &i2c) :  dev_i2c(i2c) {}
-#endif		
-
-#ifndef FAST_DISPLAY			
-    void Digits_off (void)  // all 4 digits off
-    {
-       Display_D1=1;
-       Display_D2=1; 
-       Display_D3=1; 
-       Display_D4=1;  			
-    }
-
-    void Digits_on (void)  // all 4 digits on
-    {
-       Display_D1=0;
-       Display_D2=0; 
-       Display_D3=0; 
-       Display_D4=0;  			
-    }
-
-    void Digit_on (int digit)  // digits on
-    {
-       *pDisplay_DGT[digit] = 0;
-    }
-
-    void Digit_off (int digit)  // digits off
-    {
-       *pDisplay_DGT[digit] = 1;
-    }
-		
-    void Segments_off ()   // all 7 segments off			
-    {
-       Display_A=1;
-       Display_B=1;
-       Display_C=1;
-       Display_D=1;
-       Display_E=1;
-       Display_F=1;			
-       Display_G=1;						
-    }		
-		
-    void Segment_off (int seg)   // segment off			
-    {
-       *pDisplay_SEG[seg] = 1;
-    }
-		
-    void Segment_on (int seg)   // segment on			
-    {
-       *pDisplay_SEG[seg] = 0;
-    }
-		
-		
-    void DisplayString (char str[4])
-    {
-       int i;
-       const char *pc;
- 
-       for( i=0, pc=str; i<4 && *pc!=0 ; i++, pc++)
-       {
-          _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], i);
-          if( *(pc+1)== '.')
-          {
-             pc++;
-          }
-          wait_ms(DISPLAY_DELAY);
-          Digits_off();
-       }			
-    }
-				
- 
-    void _V2_Set7Segment( int Leds, int digit )
-    {
-       //Digits_off();
-       Segments_off();     // 7 seg off */
-       int mask=1;
-       for (int i=0; i<7; i++) 
-       { 
-          if (Leds & mask) Segment_on(i);
-          mask = mask<<1;
-       }		 
-       Digit_on(digit);
-    }
-
-
-#else
-
-    void DisplayDigit (char *val, char dgt)	
-    {
-       uint8_t data[2];
-       uint16_t *pdata = (uint16_t*)data;				
-       dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7					
-       *pdata = *pdata | (uint16_t)0x0780;				// all digits off
-       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
-			
-       _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);						
-    }
-		
-    void DisplayString (char str[4], char strlen)
-    {
-       int i, dgt;
-       const char *pc;
-       uint8_t data[2];
-       uint16_t *pdata = (uint16_t*)data;	
-			
-       //dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7					
-       //*pdata = *pdata | (uint16_t)0x0780;				// all digits off
-       //dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
-			
-       for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++)
-       {
-          _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
-          if( *(pc+1)== '.')
-          {
-             pc++;
-          }
-          wait_ms(DISPLAY_DELAY);
-          dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7
-          *pdata = *pdata | (uint16_t)0x0780;				// all digits off
-          dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7	
-       }			
-    }
-				
- 
-    void _V2_Set7Segment( int Leds, int digit )
-    {
-       //Digits_off();
-       uint16_t dgt;
-       dgt = 1<<digit;
-       dgt = ((uint16_t)dgt)<<7;
-       dgt = ~dgt;	
-       uint8_t data[2];
-       uint16_t *pdata = (uint16_t*)data;			 
-
-		 
-       /* set the exppinname state to lvl */
-       dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7  		 
-       *pdata = *pdata  | (uint16_t)0x007F;      // 7 segments off
-       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
-		 
-       int mask=1;
-       for (int i=0; i<7; i++) 
-       { 
-          if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;  
-          mask = mask<<1;
-       }		 
-       *pdata = *pdata & dgt;
-       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 			
-   }
-#endif		
-		
-		
- private:		
-		
-#ifndef FAST_DISPLAY
-   STMPE1600DigiOut &Display_D1;
-   STMPE1600DigiOut &Display_D2;
-   STMPE1600DigiOut &Display_D3;
-   STMPE1600DigiOut &Display_D4;
-   STMPE1600DigiOut *pDisplay_DGT[4];		// the 4 display digits
-		
-   STMPE1600DigiOut &Display_A;
-   STMPE1600DigiOut &Display_B;
-   STMPE1600DigiOut &Display_C;
-   STMPE1600DigiOut &Display_D;
-   STMPE1600DigiOut &Display_E; 
-   STMPE1600DigiOut &Display_F;
-   STMPE1600DigiOut &Display_G; 
-   STMPE1600DigiOut *pDisplay_SEG[7];		// the 7 digit segmments
-#endif
-    DevI2C &dev_i2c; 		
-};
-
-#else  // defined DISPLAY_USING_STMPE1600
-
-class Display
-{
- public:
- 
- Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
-	 stmpe1600.setGPIOdir (GPIO_7,  OUTPUT);  // Digit1	 
-	 stmpe1600.setGPIOdir (GPIO_8,  OUTPUT);  // Digit2	 
-	 stmpe1600.setGPIOdir (GPIO_9,  OUTPUT);  // Digit3	 
-	 stmpe1600.setGPIOdir (GPIO_10, OUTPUT);  // Digit4	 	 
+     /** Constructor
+     * @param[in] &stmpe_1600 device handler to be used for display control
+     */    
+     Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
+	    stmpe1600.setGPIOdir (GPIO_7,  OUTPUT);  // Digit1	 
+	    stmpe1600.setGPIOdir (GPIO_8,  OUTPUT);  // Digit2	 
+	    stmpe1600.setGPIOdir (GPIO_9,  OUTPUT);  // Digit3	 
+	    stmpe1600.setGPIOdir (GPIO_10, OUTPUT);  // Digit4	 	 
 	 
-	 stmpe1600.setGPIOdir (GPIO_0,  OUTPUT);  // Digit4	 	 	 
-	 stmpe1600.setGPIOdir (GPIO_1,  OUTPUT);  // Digit4	 	 	 	 
-	 stmpe1600.setGPIOdir (GPIO_2,  OUTPUT);  // Digit4	 	 	 
-	 stmpe1600.setGPIOdir (GPIO_3,  OUTPUT);  // Digit4	 	 	 
-	 stmpe1600.setGPIOdir (GPIO_4,  OUTPUT);  // Digit4	 	 	 
-	 stmpe1600.setGPIOdir (GPIO_5,  OUTPUT);  // Digit4	 	 	 
-	 stmpe1600.setGPIOdir (GPIO_6,  OUTPUT);  // Digit4	 	 	 
-	 	 
- }
-
+	    stmpe1600.setGPIOdir (GPIO_0,  OUTPUT);  // SegmentA	 	 	 
+	    stmpe1600.setGPIOdir (GPIO_1,  OUTPUT);  // SegmentB	 	 	 
+	    stmpe1600.setGPIOdir (GPIO_2,  OUTPUT);  // SegmentC	 	 
+	    stmpe1600.setGPIOdir (GPIO_3,  OUTPUT);  // SegmentD	 	 
+	    stmpe1600.setGPIOdir (GPIO_4,  OUTPUT);  // SegmentE	 	 
+	    stmpe1600.setGPIOdir (GPIO_5,  OUTPUT);  // SegmentF	 	 
+	    stmpe1600.setGPIOdir (GPIO_6,  OUTPUT);  // SegmentG	 	 	  	 
+     }
+     
+	/*** Interface Methods ***/	     
+	/**
+	 * @brief       Print the string on display
+	 * @param[in]   String to be printed
+	 * @param[in]   String lenght [min 1, max 4]
+	 * @return      void
+	 */				
      void DisplayString (char str[4], char strlen)
-    {
+     {
        int i, dgt;
        const char *pc;
        uint8_t data[2];
@@ -403,21 +200,28 @@
 					stmpe1600.write16bitReg(GPSR_0_7, pdata);
        }						
 			
-		}
- 
-    void DisplayDigit (char *val, char dgt)	
-    {
+	 }
+	 
+	/**
+	 * @brief       Print the digit on display
+	 * @param[in]   Digit value to be printed
+	 * @param[in]   Digit to be used [min 0, max 3]
+	 * @return      void
+	 */				 
+     void DisplayDigit (char *val, char dgt)	
+     {
        uint8_t data[2];
        uint16_t *pdata = (uint16_t*)data;		
 			
-			 stmpe1600.read16bitReg(GPSR_0_7, pdata);
+	   stmpe1600.read16bitReg(GPSR_0_7, pdata);
        *pdata = *pdata | (uint16_t)0x0780;				// all digits off
-			 stmpe1600.write16bitReg(GPSR_0_7, pdata);
+	   stmpe1600.write16bitReg(GPSR_0_7, pdata);
        _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);						
-    }		
+     }		
 		
-    void _V2_Set7Segment( int Leds, int digit )
-    {
+private:		
+     void _V2_Set7Segment( int Leds, int digit )
+     {
        //Digits_off();
        uint16_t dgt;
        dgt = 1<<digit;
@@ -428,9 +232,9 @@
 
 		 
        /* set the exppinname state to lvl */
-			 stmpe1600.read16bitReg(GPSR_0_7, pdata);
+	   stmpe1600.read16bitReg(GPSR_0_7, pdata);
        *pdata = *pdata  | (uint16_t)0x007F;      // 7 segments off
-			 stmpe1600.write16bitReg(GPSR_0_7, pdata);
+	   stmpe1600.write16bitReg(GPSR_0_7, pdata);
 		 
        int mask=1;
        for (int i=0; i<7; i++) 
@@ -439,14 +243,10 @@
           mask = mask<<1;
        }		 
        *pdata = *pdata & dgt;
-			 stmpe1600.write16bitReg(GPSR_0_7, pdata);
-   }		
-		
-  private:
-		STMPE1600 &stmpe1600;
- 
+	   stmpe1600.write16bitReg(GPSR_0_7, pdata);
+     }				
+	 STMPE1600 &stmpe1600;
 };
-#endif
 
 #ifdef __cplusplus
 }