for motor

Fork of TM1638 by Wim Huiskamp

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Fri Jan 15 19:09:59 2016 +0000
Parent:
1:1f2453ed85d7
Child:
3:25ddabfadc8c
Commit message:
Refactored display and keyboard defines, added ASCII font.

Changed in this revision

Font_7Seg.cpp Show annotated file Show diff for this revision Revisions of this file
Font_7Seg.h Show annotated file Show diff for this revision Revisions of this file
TM1638.cpp Show annotated file Show diff for this revision Revisions of this file
TM1638.h Show annotated file Show diff for this revision Revisions of this file
TM1638_Config.h Show annotated file Show diff for this revision Revisions of this file
--- a/Font_7Seg.cpp	Sat Jan 09 14:30:43 2016 +0000
+++ b/Font_7Seg.cpp	Fri Jan 15 19:09:59 2016 +0000
@@ -1,5 +1,6 @@
 /* mbed LED Font Library, for TM1638 LED controller
  * Copyright (c) 2015, v01: WH, Initial version, Test in LEDKEY8
+ *               2016, v02: WH, Added ASCII alphabet, changed fonttable into short
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -33,35 +34,136 @@
                                    {LO(S7_ICON_GR5), HI(S7_ICON_GR5)},
                                    {LO(S7_ICON_GR6), HI(S7_ICON_GR6)},
                                    {LO(S7_ICON_GR7), HI(S7_ICON_GR7)},
-                                   {LO(S7_ICON_GR8), HI(S7_ICON_GR8)},
-                                   {LO(S7_ICON_GR9), HI(S7_ICON_GR9)},
-                                   {LO(S7_ICON_GR10), HI(S7_ICON_GR10)}                                   
+                                   {LO(S7_ICON_GR8), HI(S7_ICON_GR8)}
                                  };
 
-
 // ASCII Font definition table for transmission to TM1638
 //
 //#define FONT_7S_START     0x20
 //#define FONT_7S_END       0x7F
 //#define FONT_7S_NR_CHARS (FONT_7_END - FONT_7S_START + 1)
+
+#if (SHOW_ASCII == 1)
+//display all ASCII characters
+const short FONT_7S[]  = { 
+                             C7_SPC, //32 0x20, Space
+                             C7_EXC,
+                             C7_QTE,
+                             C7_HSH,
+                             C7_DLR,
+                             C7_PCT,
+                             C7_AMP,
+                             C7_ACC,
+                             C7_LBR,
+                             C7_RBR,                   
+                             C7_MLT,                            
+                             C7_PLS,
+                             C7_CMA,
+                             C7_MIN,
+                             C7_DPT,                             
+                             C7_RS,
+                             C7_0,   //48 0x30
+                             C7_1,
+                             C7_2,
+                             C7_3,
+                             C7_4,                   
+                             C7_5,
+                             C7_6,
+                             C7_7,
+                             C7_8,
+                             C7_9,
+                             C7_COL, //58 0x3A
+                             C7_SCL,
+                             C7_LT,
+                             C7_EQ,
+                             C7_GT,
+                             C7_QM,                             
+                             C7_AT,  //64 0x40
+                             C7_A,   //65 0x41, A
+                             C7_B,
+                             C7_C,
+                             C7_D,
+                             C7_E,
+                             C7_F,
+                             C7_G,
+                             C7_H,
+                             C7_I,
+                             C7_J,                   
+                             C7_K,
+                             C7_L,
+                             C7_M,
+                             C7_N,
+                             C7_O,
+                             C7_P,
+                             C7_Q,
+                             C7_R,
+                             C7_S,
+                             C7_T,
+                             C7_U,
+                             C7_V,
+                             C7_W,
+                             C7_X,
+                             C7_Y,
+                             C7_Z,   //90 0x5A, Z
+                             C7_SBL, //91 0x5B
+                             C7_LS,
+                             C7_SBR,
+                             C7_PWR,
+                             C7_UDS,  
+                             C7_ACC,                             
+                             C7_A,   //97 0x61, A replacing a
+                             C7_B,
+                             C7_C,
+                             C7_D,
+                             C7_E,
+                             C7_F,
+                             C7_G,
+                             C7_H,
+                             C7_I,
+                             C7_J,                   
+                             C7_K,
+                             C7_L,
+                             C7_M,
+                             C7_N,
+                             C7_O,
+                             C7_P,
+                             C7_Q,
+                             C7_R,
+                             C7_S,
+                             C7_T,
+                             C7_U,
+                             C7_V,
+                             C7_W,
+                             C7_X,
+                             C7_Y,
+                             C7_Z,   // 122 0x7A, Z replacing z
+                             C7_CBL, // 123 0x7B
+                             C7_OR,
+                             C7_CBR,
+                             C7_TLD,
+                             C7_DEL  // 127                             
+                        };
  
-const char FONT_7S[] = { 
-                         C7_0, //48 0x30
-                         C7_1,
-                         C7_2,
-                         C7_3,
-                         C7_4,                   
-                         C7_5,
-                         C7_6,
-                         C7_7,
-                         C7_8,
-                         C7_9,
-                         C7_A, //65 0x41, A
-                         C7_B,
-                         C7_C,
-                         C7_D,
-                         C7_E,
-                         C7_F
-                             };// 127                             
+#else
+//display only digits and hex characters
+const short FONT_7S[] = { 
+                           C7_0, //48 0x30
+                           C7_1,
+                           C7_2,
+                           C7_3,
+                           C7_4,                   
+                           C7_5,
+                           C7_6,
+                           C7_7,
+                           C7_8,
+                           C7_9,
+                           C7_A, //65 0x41, A
+                           C7_B,
+                           C7_C,
+                           C7_D,
+                           C7_E,
+                           C7_F
+                        };// 127
+#endif
   
 #endif 
\ No newline at end of file
--- a/Font_7Seg.h	Sat Jan 09 14:30:43 2016 +0000
+++ b/Font_7Seg.h	Fri Jan 15 19:09:59 2016 +0000
@@ -1,5 +1,6 @@
 /* mbed LED Font Library, for TM1638 LED Controller
  * Copyright (c) 2015, v01: WH, Initial version, Test in LEDKEY8
+ *               2016, v02: WH, Added ASCII alphabet, changed fonttable into short 
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -31,6 +32,18 @@
 // will be adapted automatically according to the bit-to-segment mapping. Obviously this will only work when the segment
 // mapping is identical for every digit position. This will be the case unless the hardware designer really hates software developers.
 //
+//            A
+//          -----
+//         |     |     
+//       F |     | B    
+//         |  G  |     
+//          -----
+//         |     |     
+//       E |     | C    
+//         |     |     
+//          -----   * DP
+//            D  
+//
 #define S7_A    0x0001
 #define S7_B    0x0002
 #define S7_C    0x0004
@@ -91,17 +104,6 @@
 #define S7_ICON_GR8 (S7_LD8)
 //#define S7_ICON_GR8 (S7_LD8 | S7_DP8)
 
-//Icons Grid 9
-#define S7_DP9  0x0080
-#define S7_LD9  0x0100
-#define S7_ICON_GR9 (S7_LD9)
-//#define S7_ICON_GR9 (S7_LD9 | S7_DP9)
-
-//Icons Grid 10
-#define S7_DP10 0x0080
-#define S7_LD10 0x0100
-#define S7_ICON_GR10 (S7_LD10)
-//#define S7_ICON_GR10 (S7_LD10 | S7_DP10)
 
 //Mask for blending out and restoring Icons
 extern const char MASK_ICON_GRID[][2]; 
@@ -112,9 +114,21 @@
 //
 //32 0x20  Symbols
 #define C7_SPC  (0x0000)
+#define C7_EXC  (S7_B | S7_C) //!
+#define C7_QTE  (S7_B | S7_F) //"
+#define C7_HSH  (S7_C | S7_D | S7_E | S7_G) //#
+#define C7_DLR  (S7_A | S7_C | S7_D | S7_F | S7_G) //$
+#define C7_PCT  (S7_C | S7_F) //%
+#define C7_AMP  (S7_A | S7_C | S7_D | S7_E | S7_F | S7_G) //&
+#define C7_ACC  (S7_B) //'
+#define C7_LBR  (S7_A | S7_D | S7_E | S7_F) //(
+#define C7_RBR  (S7_A | S7_B | S7_C | S7_D) //)
+#define C7_MLT  (S7_B | S7_C | S7_E | S7_F | S7_G)  //*
+#define C7_PLS  (S7_B | S7_C | S7_G) //+
 #define C7_CMA  (S7_DP)
+#define C7_MIN  (S7_G)
 #define C7_DPT  (S7_DP)
-#define C7_MIN  (S7_G)
+#define C7_RS   (S7_B | S7_E  | S7_G)  // /
 
 //48 0x30  Digits
 #define C7_0    (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F)
@@ -127,7 +141,17 @@
 #define C7_7    (S7_A | S7_B | S7_C)
 #define C7_8    (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F | S7_G)
 #define C7_9    (S7_A | S7_B | S7_C | S7_D | S7_F | S7_G)
-//64 0x40  Upper case alphabet
+
+//58 0x3A
+#define C7_COL  (S7_D | S7_G) // :
+#define C7_SCL  (S7_D | S7_G) // ;
+#define C7_LT   (S7_D | S7_E | S7_G)             // <
+#define C7_EQ   (S7_D | S7_G)                    // =
+#define C7_GT   (S7_C | S7_D | S7_G)             // >   
+#define C7_QM   (S7_A | S7_B | S7_E | S7_G)      // ?
+#define C7_AT   (S7_A | S7_B | S7_C | S7_D | S7_E  | S7_G)  // @
+
+//65 0x41  Upper case alphabet
 #define C7_A    (S7_A | S7_B | S7_C | S7_E | S7_F | S7_G )
 #define C7_B    (S7_C | S7_D | S7_E | S7_F | S7_G)
 #define C7_C    (S7_A | S7_D | S7_E | S7_F)
@@ -135,23 +159,35 @@
 #define C7_E    (S7_A | S7_D | S7_E | S7_F | S7_G)
 #define C7_F    (S7_A | S7_E | S7_F | S7_G)
 
-#define C7_G    (S7_A | S7_B | S7_C | S7_F | S7_G)
+#define C7_G    (S7_A | S7_C | S7_D | S7_E | S7_F)
 #define C7_H    (S7_B | S7_C | S7_E | S7_F | S7_G)
 #define C7_I    (S7_B | S7_C)
-#define C7_J    (S7_B | S7_C | S7_D)
+#define C7_J    (S7_B | S7_C | S7_D | S7_E)
+#define C7_K    (S7_B | S7_C | S7_E | S7_F | S7_G)
 #define C7_L    (S7_D | S7_E | S7_F)
-#define C7_M    (S7_C | S7_E | S7_G)
-#define C7_N    (S7_C | S7_E | S7_G)
+#define C7_M    (S7_A | S7_C | S7_E)
+#define C7_N    (S7_A | S7_B | S7_C | S7_E | S7_F)
 #define C7_O    (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F)
 #define C7_P    (S7_A | S7_B | S7_E | S7_F | S7_G)
 #define C7_Q    (S7_A | S7_B | S7_C | S7_F | S7_G)
-#define C7_R    (S7_E | S7_G)
+#define C7_R    (S7_E | S7_G )
 #define C7_S    (S7_A | S7_C | S7_D | S7_F | S7_G)
 #define C7_T    (S7_D | S7_E | S7_F | S7_G)
 #define C7_U    (S7_B | S7_C | S7_D | S7_E | S7_F)
+#define C7_V    (S7_B | S7_C | S7_D | S7_E | S7_F)
+#define C7_W    (S7_B | S7_D | S7_F)
+#define C7_X    (S7_B | S7_C | S7_E | S7_F | S7_G)
 #define C7_Y    (S7_B | S7_C | S7_D | S7_F | S7_G)
 #define C7_Z    (S7_A | S7_B | S7_D | S7_E | S7_G)
 
+//91 0x5B
+#define C7_SBL  (S7_A | S7_D | S7_E | S7_F) // [
+#define C7_LS   (S7_C | S7_F | S7_G)        // left slash
+#define C7_SBR  (S7_A | S7_B | S7_C | S7_D) // ]
+#define C7_PWR  (S7_A | S7_B | S7_F)        // ^
+#define C7_UDS  (S7_D)                      // _
+#define C7_DSH  (S7_F)                      // `  
+
 //97 0x61  Lower case alphabet
 #define C7_a     C7_A
 #define C7_b     C7_B
@@ -164,22 +200,37 @@
 #define C7_h     C7_H
 #define C7_i     C7_I
 #define C7_j     C7_J
+#define C7_k     C7_K
 #define C7_l     C7_L
 #define C7_m     C7_M
-#define C7_n     C7_N
-#define C7_o     C7_O
+//#define C7_n     C7_N
+#define C7_n    (S7_C | S7_E | S7_G)
+//#define C7_o     C7_O
+#define C7_o    (S7_C | S7_D | S7_E | S7_G)
 #define C7_p     C7_P
 #define C7_q     C7_Q
-#define C7_r     C7_R
+//#define C7_r     C7_R
+#define C7_r    (S7_E | S7_G)
 #define C7_s     C7_S
 #define C7_t     C7_T
 #define C7_u     C7_U
+#define C7_v     C7_V
+#define C7_w     C7_W
+#define C7_x     C7_X
 #define C7_y     C7_Y
 #define C7_z     C7_Z
 
+//123 0x7B
+#define C7_CBL  (S7_A | S7_D | S7_E | S7_F)        // {
+#define C7_OR   (S7_B | S7_C)                      // |
+#define C7_CBR  (S7_A | S7_B | S7_C | S7_D)        // }
+#define C7_TLD  (S7_B | S7_E | S7_G )              // ~
+#define C7_DEL  (0x0000)
+
 
 //User Defined Characters (some examples)
-                                                                          
+#define C7_DGR   (S7_A | S7_B | S7_F | S7_G)  //Degrees
+                                                                         
 // Font data selection for transmission to TM1638 memory
 #define LO(x)  ( x & 0xFF)
 #define HI(x)  ((x >> 8) & 0xFF)
@@ -187,9 +238,9 @@
 
 // ASCII Font definition table
 //
-//#define FONT_7S_START     0x20
-//#define FONT_7S_END       0x7F
+#define FONT_7S_START     0x20
+#define FONT_7S_END       0x7F
 //#define FONT_7S_NR_CHARS (FONT_7S_END - FONT_7S_START + 1)
-extern const char FONT_7S[]; 
+extern const short FONT_7S[]; 
 
 #endif    
\ No newline at end of file
--- a/TM1638.cpp	Sat Jan 09 14:30:43 2016 +0000
+++ b/TM1638.cpp	Fri Jan 15 19:09:59 2016 +0000
@@ -1,5 +1,6 @@
 /* mbed TM1638 Library, for TM1638 LED controller
  * Copyright (c) 2015, v01: WH, Initial version
+ *               2016, v02: WH, Added ASCII alphabet display selector, refactored display and keyboard defines 
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -159,8 +160,9 @@
   for (int idx=0; idx < TM1638_KEY_MEM; idx++) {
     data = _flip(_spi.write(0xFF));    // read keys and correct bitorder
 
+    data = data & TM1638_KEY_MSK; // Mask valid bits
     if (data != 0) {  // Check for any pressed key
-      for (int bit=0; bit < TM1638_KEY_BITS; bit++) {
+      for (int bit=0; bit < 8; bit++) {
         if (data & (1 << bit)) {keypress++;} // Test all significant bits
       }
     }  
@@ -294,7 +296,7 @@
     }  
   }
 
-  writeData(_displaybuffer, (LEDKEY8_NR_GRIDS*2));
+  writeData(_displaybuffer, (LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID));
 
   _column = 0;   
 }     
@@ -309,12 +311,12 @@
 
    icn =        icon  & 0xFFFF;
   addr = (icon >> 24) & 0xFF; 
-  addr = (addr - 1) << 1;   
+  addr = (addr - 1) << 1;   // * PT1638_BYTES_PER_GRID
     
   //Save char...and set bits for icon to write
   _displaybuffer[addr]   = _displaybuffer[addr]   | LO(icn);      
   _displaybuffer[addr+1] = _displaybuffer[addr+1] | HI(icn);      
-  writeData(_displaybuffer, (LEDKEY8_NR_GRIDS*2));
+  writeData(_displaybuffer, (LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID));
 }
 
 /** Clr Icon
@@ -327,12 +329,12 @@
 
    icn =        icon  & 0xFFFF;
   addr = (icon >> 24) & 0xFF; 
-  addr = (addr - 1) << 1;   
+  addr = (addr - 1) << 1;   // * TM1638_BYTES_PER_GRID
     
   //Save char...and clr bits for icon to write
   _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(icn);      
   _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~HI(icn);      
-  writeData(_displaybuffer, (LEDKEY8_NR_GRIDS*2));
+  writeData(_displaybuffer, (LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID));
 }
 
 
@@ -376,27 +378,37 @@
       if (_column > 0) {
         //Translate between _column and displaybuffer entries
         //Add DP to bitpattern of digit left of current column.
-        addr = (_column - 1) << 1;
+        addr = (_column - 1) << 1; // * PT1638_BYTES_PER_GRID
       
         //Save icons...and set bits for decimal point to write
         _displaybuffer[addr]   = _displaybuffer[addr] | pattern;
 //        _displaybuffer[addr+1] = _displaybuffer[addr+1] | pattern;
 
-        writeData(_displaybuffer, (LEDKEY8_NR_GRIDS*2));
+        writeData(_displaybuffer, (LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID));
         
         //No Cursor Update
       }
-    }  
-    else if (value == '-') {
-      //No character to write
-      validChar = true;
-      pattern = C7_MIN;         
     }
     else if ((value >= 0) && (value < LEDKEY8_NR_UDC)) {
       //Character to write
       validChar = true;
       pattern = _UDC_7S[value];
     }  
+    
+#if (SHOW_ASCII == 1)
+    //display all ASCII characters
+    else if ((value >= FONT_7S_START) && (value <= FONT_7S_END)) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[value - FONT_7S_START];
+    } // else
+#else    
+    //display only digits and hex characters      
+    else if (value == '-') {
+      //Character to write
+      validChar = true;
+      pattern = C7_MIN;         
+    }
     else if ((value >= (int)'0') && (value <= (int) '9')) {   
       //Character to write
       validChar = true;
@@ -412,18 +424,19 @@
       validChar = true;
       pattern = FONT_7S[10 + value - (int) 'a'];
     } //else
+#endif
 
     if (validChar) {
       //Character to write
  
       //Translate between _column and displaybuffer entries
-      addr = _column << 1;
+      addr = _column << 1; // * TM1638_BYTES_PER_GRID
 
       //Save icons...and set bits for character to write
       _displaybuffer[addr]   = (_displaybuffer[addr]   & MASK_ICON_GRID[_column][0]) | pattern;
 //      _displaybuffer[addr+1] = (_displaybuffer[addr+1] & MASK_ICON_GRID[_column][0]) | pattern;
 
-      writeData(_displaybuffer, (LEDKEY8_NR_GRIDS*2));
+      writeData(_displaybuffer, (LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID));
                                 
       //Update Cursor
       _column++;
--- a/TM1638.h	Sat Jan 09 14:30:43 2016 +0000
+++ b/TM1638.h	Fri Jan 15 19:09:59 2016 +0000
@@ -1,5 +1,6 @@
 /* mbed TM1638 Library, for TM1638 LED controller
  * Copyright (c) 2015, v01: WH, Initial version
+ *               2016, v02: WH, refactored display and keyboard defines 
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -64,11 +65,17 @@
  * @endcode
  */
 
+
+//TM1638 Display and Keymatrix data
+#define TM1638_MAX_NR_GRIDS    8
+#define TM1638_BYTES_PER_GRID  2
+//Significant bits Keymatrix data
+#define TM1638_KEY_MSK      0x77 
+
 //Memory size in bytes for Display and Keymatrix
-#define TM1638_DISPLAY_MEM    16
+#define TM1638_DISPLAY_MEM  (TM1638_MAX_NR_GRIDS * TM1638_BYTES_PER_GRID)
 #define TM1638_KEY_MEM         4
-//Significant bits Keymatrix data
-#define TM1638_KEY_BITS        6 
+
 
 //Reserved bits for commands
 #define TM1638_CMD_MSK      0xC0
--- a/TM1638_Config.h	Sat Jan 09 14:30:43 2016 +0000
+++ b/TM1638_Config.h	Fri Jan 15 19:09:59 2016 +0000
@@ -1,5 +1,6 @@
 /* mbed TM1638 Library, for TM1638 LEDcontroller
  * Copyright (c) 2015, v01: WH, Initial version
+ *               2016, v02: WH, Added ASCII alphabet display selector
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -27,4 +28,7 @@
 #define TM1638_TEST  0
 #define LEDKEY8_TEST 1 
 
+// Select the display mode: only digits and hex or ASCII
+#define SHOW_ASCII   1 
+
 #endif
\ No newline at end of file