Library for Princeton PT6318 VFD controller Initial version for KUH8300.

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Mon Feb 01 20:18:04 2016 +0000
Child:
1:a7a518dbca96
Commit message:
Library for PT6318 VFD Controller

Changed in this revision

Font_16Seg.cpp Show annotated file Show diff for this revision Revisions of this file
Font_16Seg.h Show annotated file Show diff for this revision Revisions of this file
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
PT6318.cpp Show annotated file Show diff for this revision Revisions of this file
PT6318.h Show annotated file Show diff for this revision Revisions of this file
PT6318_Config.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Font_16Seg.cpp	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,160 @@
+/* mbed VFD Font Library, for Princeton PT6318 VFD controller
+ * Copyright (c) 2016, v01: WH, Initial version
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "Font_16Seg.h"
+
+// Select one of the testboards for Princeton PT6318 VFD controller
+#include "PT6318_Config.h"
+
+#if (PT6318_TEST == 1)
+
+//Mask for blending out and restoring Icons
+const char MASK_ICON_GRID[][3] = {
+                                   {LO(S16_ICON_GR1), MD(S16_ICON_GR1), HI(S16_ICON_GR1)},
+                                   {LO(S16_ICON_GR2), MD(S16_ICON_GR2), HI(S16_ICON_GR2)},
+                                   {LO(S16_ICON_GR3), MD(S16_ICON_GR3), HI(S16_ICON_GR3)},
+                                   {LO(S16_ICON_GR4), MD(S16_ICON_GR4), HI(S16_ICON_GR4)},
+                                   {LO(S16_ICON_GR5), MD(S16_ICON_GR5), HI(S16_ICON_GR5)},
+                                   {LO(S16_ICON_GR6), MD(S16_ICON_GR6), HI(S16_ICON_GR6)},
+                                   {LO(S16_ICON_GR7), MD(S16_ICON_GR7), HI(S16_ICON_GR7)},
+                                   {LO(S16_ICON_GR8), MD(S16_ICON_GR8), HI(S16_ICON_GR8)},
+                                   {LO(S16_ICON_GR9), MD(S16_ICON_GR9), HI(S16_ICON_GR9)},
+                                   {LO(S16_ICON_GR10), MD(S16_ICON_GR10), HI(S16_ICON_GR10)},
+                                   {LO(S16_ICON_GR11), MD(S16_ICON_GR11), HI(S16_ICON_GR11)}
+                                 };
+
+
+// ASCII Font definition table for transmission to PT6318
+//
+//#define FONT_16S_START     0x20
+//#define FONT_16S_END       0x7F
+//#define FONT_16S_NR_CHARS (FONT_16S_END - FONT_16S_START + 1)
+ 
+const short FONT_16S[] = { 
+                            C16_SPC, //32 0x20, Space
+                            C16_EXC,
+                            C16_QTE,
+                            C16_HSH,
+                            C16_DLR,
+                            C16_PCT,
+                            C16_AMP,
+                            C16_ACC,
+                            C16_LBR,
+                            C16_RBR,                   
+                            C16_MLT,                            
+                            C16_PLS,
+                            C16_CMA,
+                            C16_MIN,
+                            C16_DOT,                             
+                            C16_RS,
+                            C16_0, //48 0x30
+                            C16_1,
+                            C16_2,
+                            C16_3,
+                            C16_4,                   
+                            C16_5,
+                            C16_6,
+                            C16_7,
+                            C16_8,
+                            C16_9,
+                            C16_COL, //58 0x3A
+                            C16_SCL,
+                            C16_LT,
+                            C16_EQ,
+                            C16_GT,
+                            C16_QM,                             
+                            C16_AT, //64 0x40
+                            C16_A, //65 0x41, A
+                            C16_B,
+                            C16_C,
+                            C16_D,
+                            C16_E,
+                            C16_F,
+                            C16_G,
+                            C16_H,
+                            C16_I,
+                            C16_J,                   
+                            C16_K,
+                            C16_L,
+                            C16_M,
+                            C16_N,
+                            C16_O,
+                            C16_P,
+                            C16_Q,
+                            C16_R,
+                            C16_S,
+                            C16_T,
+                            C16_U,
+                            C16_V,
+                            C16_W,
+                            C16_X,
+                            C16_Y,
+                            C16_Z, //90 0x5A, Z
+                            C16_SBL, //91 0x5B
+                            C16_LS,
+                            C16_SBR,
+                            C16_PWR,
+                            C16_UDS,  
+                            C16_ACC,                             
+                            C16_A, //97 0x61, A replacing a
+                            C16_B,
+                            C16_C,
+                            C16_D,
+                            C16_E,
+                            C16_F,
+                            C16_G,
+                            C16_H,
+                            C16_I,
+                            C16_J,                   
+                            C16_K,
+                            C16_L,
+                            C16_M,
+                            C16_N,
+                            C16_O,
+                            C16_P,
+                            C16_Q,
+                            C16_R,
+                            C16_S,
+                            C16_T,
+                            C16_U,
+                            C16_V,
+                            C16_W,
+                            C16_X,
+                            C16_Y,
+                            C16_Z, // 122 0x7A, Z replacing z
+                            C16_CBL, // 123 0x7B
+                            C16_OR,
+                            C16_CBR,
+                            C16_TLD,
+                            C16_DEL
+                           }; 
+  
+ // Wheel definition table for transmission to PT6318
+const int WHEEL_ANI[] = { UDC16_WHEEL0,
+                          UDC16_WHEEL1,
+                          UDC16_WHEEL2,
+                          UDC16_WHEEL3,
+                          UDC16_WHEEL4,
+                          UDC16_WHEEL5,
+                          UDC16_WHEEL6,
+                          UDC16_WHEEL7 };
+
+#endif  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Font_16Seg.h	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,245 @@
+/* mbed VFD Font Library, for Princeton PT6318 VFD controller
+ * Copyright (c) 2016, v01: WH, Initial version
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MBED_FONT_16SEG_H
+#define MBED_FONT_16SEG_H
+
+// Select one of the testboards for Princeton PT6318 VFD controller
+#include "PT6318_Config.h"
+
+#if (PT6318_TEST == 1) 
+// Segment bit positions for 14 or 16 Segment display using the PT6318
+// Modify this table for different 'bit-to-segment' mappings. The ASCII character defines and the FONT_16S const table below 
+// 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.
+//
+//           A1   A2
+//          ---- ----
+//         |H\ J|  /K|     
+//       F |  \ | /  | B    
+//         |G1 \|/ G2|     
+//          --- + ---
+//         |   /|\   |     
+//       E |  / | \  | C    
+//         |N/ M|  \L|     
+//          ---- ----    * DP
+//           D1   D2
+//
+#define S16_A1   0x0001  // Assuming 2 part A segment
+#define S16_A2   0x0001
+#define S16_J    0x0002  // J, M linked 
+#define S16_M    0x0002
+#define S16_H    0x0004
+#define S16_K    0x0008
+#define S16_B    0x0010
+#define S16_F    0x0020
+#define S16_G2   0x0040  // 2 part G segment
+#define S16_G1   0x0080
+#define S16_C    0x0100
+#define S16_E    0x0200
+#define S16_N    0x0400
+#define S16_L    0x0800
+#define S16_D1   0x1000  // Assuming 2 part D segment
+#define S16_D2   0x1000
+#define S16_S    0x2000  // NA
+
+//Icons All Grids
+//#define S16_DP   0x8000  // Assuming single DP segment
+
+//Icons Grid 1
+#define S16_RCV  0x010000
+#define S16_ICON_GR1  (S16_RCV)
+
+//Icons Grid 2
+#define S16_ICON_GR2  (0x000000)
+
+//Icons Grid 3
+#define S16_ICON_GR3  (0x000000)
+
+//Icons Grid 4
+#define S16_ICON_GR4  (0x000000)
+
+//Icons Grid 5
+#define S16_ICON_GR5  (0x000000)
+
+//Icons Grid 6
+#define S16_ICON_GR6  (0x000000)
+
+//Icons Grid 7
+#define S16_ICON_GR7  (0x000000)
+
+//Icons Grid 8
+#define S16_SAT  0x010000
+#define S16_ICON_GR8  (S16_SAT)
+
+//Icons Grid 9
+#define S16_DRT  0x004000
+#define S16_TV   0x010000
+#define S16_ICON_GR9  (S16_DRT | S16_TV)
+
+//Icons Grid 10
+#define S16_COL4 0x004000
+#define S16_TMR  0x010000
+#define S16_ICON_GR10  (S16_COL4 | S16_TMR)
+
+//Icons Grid 11
+#define S16_COL6 0x004000
+#define S16_DP6  0x008000
+#define S16_PRS  0x010000
+#define S16_ICON_GR11 (S16_COL6 | S16_DP6 | S16_PRS)
+
+
+//Mask for blending out and restoring Icons
+extern const char MASK_ICON_GRID[][3]; 
+
+//One mask pattern will be sufficient assuming that all digits use the same mapping.
+//#define S16_ICON_MSK (S16_COL3)
+
+#endif
+
+
+// ASCII Font definitions for segments in each character
+//
+//32 0x20
+#define C16_SPC  (0x0000)    //Space
+#define C16_EXC  (S16_B | S16_C) //!
+#define C16_QTE  (S16_B | S16_F) //"
+#define C16_HSH  (S16_B | S16_C | S16_D1 | S16_D2 | S16_G1 | S16_G2 | S16_J | S16_M) //#
+#define C16_DLR  (S16_A1 | S16_A2 | S16_C | S16_D1 | S16_D2 | S16_F | S16_G1 | S16_G2 | S16_J | S16_M | S16_S) //$
+#define C16_PCT  (S16_C | S16_F | S16_K | S16_N | S16_S) //%
+//#define C16_AMP    (S16_A1 | S16_C | S16_D1 | S16_D2 | S16_E | S16_G1 | S16_J | S16_H | S16_L) // Not correct when J and M are linked
+#define C16_AMP  (S16_A1 | S16_A2 | S16_C | S16_D1 | S16_D2 | S16_H | S16_K | S16_L | S16_N | S16_S) //&
+#define C16_ACC  (S16_B) //'
+#define C16_LBR  (S16_K | S16_L) //(
+#define C16_RBR  (S16_H | S16_N) //)
+#define C16_MLT  (S16_G1 | S16_G2 | S16_J | S16_M | S16_K | S16_L | S16_H | S16_N | S16_S)  //*
+#define C16_PLS  (S16_G1 | S16_G2 | S16_J | S16_M | S16_S) //+
+#define C16_CMA  (S16_C) //,
+#define C16_MIN  (S16_G1 | S16_G2 | S16_S) //-
+#define C16_DOT  (S16_C) //.
+#define C16_RS   (S16_K | S16_N  | S16_S)  // /
+//48 0x30 digits
+#define C16_0    (S16_A1 | S16_A2 | S16_B | S16_C  | S16_D1 | S16_D2 | S16_E  | S16_F)
+#define C16_1    (S16_B  | S16_C)
+#define C16_2    (S16_A1 | S16_A2 | S16_B | S16_D1 | S16_D2 | S16_E  | S16_G1 | S16_G2 | S16_S)
+#define C16_3    (S16_A1 | S16_A2 | S16_B | S16_C  | S16_D1 | S16_D2 | S16_G2 | S16_S)
+#define C16_4    (S16_B  | S16_C  | S16_F | S16_G1 | S16_G2 | S16_S)
+#define C16_5    (S16_A1 | S16_A2 | S16_C | S16_D1 | S16_D2 | S16_F | S16_G1 | S16_G2 | S16_S)
+#define C16_6    (S16_A1 | S16_A2 | S16_C | S16_D1 | S16_D2 | S16_E | S16_F  | S16_G1 | S16_G2 | S16_S)
+#define C16_7    (S16_A1 | S16_A2 | S16_B | S16_C)
+#define C16_8    (S16_A1 | S16_A2 | S16_B | S16_C  | S16_D1 | S16_D2 | S16_E | S16_F  | S16_G1 | S16_G2 | S16_S)
+#define C16_9    (S16_A1 | S16_A2 | S16_B | S16_C  | S16_D1 | S16_D2 | S16_F | S16_G1 | S16_G2 | S16_S)
+//58 0x3A
+#define C16_COL  (S16_D1 | S16_D2 | S16_G1 | S16_G2 | S16_S) // :
+#define C16_SCL  (S16_D1 | S16_D2 | S16_G1 | S16_G2 | S16_S) // ;
+#define C16_LT   (S16_K  | S16_L  | S16_S)               // <
+#define C16_EQ   (S16_D1 | S16_D2 | S16_G1 | S16_G2 | S16_S) // =
+#define C16_GT   (S16_H  | S16_N  | S16_S)               // >   
+//#define C16_QM   (S16_A1 | S16_A2 | S16_B | S16_G2 | S16_M) // Not correct when J and M are linked
+#define C16_QM   (S16_A1 | S16_A2 | S16_B | S16_G2 | S16_N | S16_S)  // ?
+//64 0x40
+//#define C16_AT   (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_D1 | S16_D2 | S16_E | S16_G1  | S16_M | S16_S) // Not correct when J and M are linked
+#define C16_AT   (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_D1 | S16_D2 | S16_E  | S16_G1 | S16_S)  // @
+#define C16_A    (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_E  | S16_F  | S16_G1 | S16_G2 | S16_S)  // Upper case alphabet
+#define C16_B    (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_D1 | S16_D2 | S16_J  | S16_M  | S16_G2 | S16_S)
+#define C16_C    (S16_A1 | S16_A2 | S16_D1 | S16_D2 | S16_E  | S16_F)
+#define C16_D    (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_D1 | S16_D2 | S16_J  | S16_M  | S16_S)
+#define C16_E    (S16_A1 | S16_A2 | S16_D1 | S16_D2 | S16_E  | S16_F  | S16_G1 | S16_S)
+#define C16_F    (S16_A1 | S16_A2 | S16_E  | S16_F  | S16_G1 | S16_S)
+#define C16_G    (S16_A1 | S16_A2 | S16_C  | S16_D1 | S16_D2 | S16_E  | S16_F  | S16_G2 | S16_S)
+#define C16_H    (S16_B  | S16_C  | S16_E  | S16_F  | S16_G1 | S16_G2 | S16_S)
+#define C16_I    (S16_A1 | S16_A2 | S16_D1 | S16_D2 | S16_J  | S16_M  | S16_S)
+#define C16_J    (S16_B  | S16_C  | S16_D1 | S16_D2 | S16_E)
+#define C16_K    (S16_E  | S16_F  | S16_G1 | S16_K  | S16_L  | S16_S)
+#define C16_L    (S16_D1 | S16_D2 | S16_E  | S16_F)
+#define C16_M    (S16_B  | S16_C  | S16_E  | S16_F  | S16_H  | S16_K  | S16_S)
+#define C16_N    (S16_B  | S16_C  | S16_E  | S16_F  | S16_H  | S16_L  | S16_S)
+#define C16_O    (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_D1 | S16_D2 | S16_E  | S16_F)
+#define C16_P    (S16_A1 | S16_A2 | S16_B  | S16_E  | S16_F  | S16_G1 | S16_G2 | S16_S)
+#define C16_Q    (S16_A1 | S16_A2 | S16_B  | S16_C  | S16_D1 | S16_D2 | S16_E  | S16_F  | S16_L)
+#define C16_R    (S16_A1 | S16_A2 | S16_B  | S16_E  | S16_F  | S16_G1 | S16_G2 | S16_L  | S16_S)
+#define C16_S    (S16_A1 | S16_A2 | S16_C  | S16_D1 | S16_D2 | S16_F  | S16_G1 | S16_G2 | S16_S)
+#define C16_T    (S16_A1 | S16_A2 | S16_J  | S16_M  | S16_S)
+#define C16_U    (S16_B  | S16_C  | S16_D1 | S16_D2 | S16_E  | S16_F)
+#define C16_V    (S16_E  | S16_F  | S16_N  | S16_K  | S16_S)
+#define C16_W    (S16_B  | S16_C  | S16_E  | S16_F  | S16_L  | S16_N  | S16_S)
+#define C16_X    (S16_H  | S16_K  | S16_L  | S16_N  | S16_S)
+//#define C16_Y    (S16_H | S16_K | S16_M | S16_S) // Not correct when J and M are linked
+#define C16_Y    (S16_B  | S16_C  | S16_D1 | S16_D2 | S16_F  | S16_G1 | S16_G2 | S16_S)
+#define C16_Z    (S16_A1 | S16_A2 | S16_D1 | S16_D2 | S16_K  | S16_N  | S16_S)
+//91 0x5B
+#define C16_SBL  (S16_A1 | S16_D1 | S16_E  | S16_F)  // [
+#define C16_LS   (S16_H  | S16_L  | S16_S)           // left slash
+#define C16_SBR  (S16_A2 | S16_B | S16_C | S16_D2)   // ]
+#define C16_PWR  (S16_L  | S16_N  | S16_S)           // ^
+#define C16_UDS  (S16_D1 | S16_D2)                   // _
+#define C16_DSH  (S16_H)                             // `  
+//97 0x61
+// a...z No defines provided. Just use the Upper case characters again
+//122
+
+//123 0x7B
+#define C16_CBL  (S16_G1 | S16_J  | S16_M  | S16_S)          // {
+#define C16_OR   (S16_J  | S16_M  | S16_S)                   // |
+#define C16_CBR  (S16_G2 | S16_J  | S16_M  | S16_S)          // }
+#define C16_TLD  (S16_B  | S16_E  | S16_G1 | S16_G2 | S16_S) // ~
+#define C16_DEL  (0x0000)
+
+//User Defined Characters (some examples)
+#define UDC16_SANDHR  (S16_A1 | S16_A2 | S16_D1 | S16_D2 | S16_H  | S16_K | S16_L | S16_N | S16_S)  //Sandhour
+#define UDC16_DGR     (S16_A  | S16_B  | S16_F | S16_G)  // degrees
+
+#if(0)
+#define UDC16_WHEEL0  (S16_G1 | S16_G2 | S16_S)  // -
+#define UDC16_WHEEL1  (S16_H  | S16_L  | S16_S)  /* \ */
+#define UDC16_WHEEL2  (S16_J  | S16_M  | S16_S)  // |
+#define UDC16_WHEEL3  (S16_K  | S16_N  | S16_S)  // /
+#define UDC16_WHEEL4  (S16_G1 | S16_G2 | S16_S)  // -
+#define UDC16_WHEEL5  (S16_H  | S16_L  | S16_S)  /* \ */
+#define UDC16_WHEEL6  (S16_J  | S16_M  | S16_S)  // |
+#define UDC16_WHEEL7  (S16_K  | S16_N  | S16_S)  // /
+#else
+#define UDC16_WHEEL0  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_G1 | S16_G2 | S16_S)  // -
+#define UDC16_WHEEL1  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_H  | S16_L  | S16_S)  /* \ */
+#define UDC16_WHEEL2  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_J  | S16_M  | S16_S)  // |
+#define UDC16_WHEEL3  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_K  | S16_N  | S16_S)  // /
+#define UDC16_WHEEL4  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_G1 | S16_G2 | S16_S)  // -
+#define UDC16_WHEEL5  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_H  | S16_L  | S16_S)  /* \ */
+#define UDC16_WHEEL6  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_J  | S16_M  | S16_S)  // |
+#define UDC16_WHEEL7  (S16_A1 | S16_A2 | S16_B | S16_C | S16_D1 | S16_D2 | S16_E | S16_F | S16_K  | S16_N  | S16_S)  // /
+#endif
+
+// Font data selection for transmission to PT6311 memory
+#define LO(x)  ( x & 0xFF)
+#define MD(x)  ((x >>  8) & 0xFF)
+#define HI(x)  ((x >> 16) & 0xFF)
+
+// ASCII Font definition table
+//
+#define FONT_16S_START     0x20
+#define FONT_16S_END       0x7F
+//#define FONT_16S16_LR_CHARS (FONT_16S16_END - FONT_16S16_START + 1)
+extern const short FONT_16S[]; 
+
+
+// Wheel animation definition table
+extern const int WHEEL_ANI[]; 
+#endif                         
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Font_7Seg.cpp	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,166 @@
+/* mbed Font Library, for PT6318 VFD controller
+ * Copyright (c) 2016, v01: WH, Initial version, Test in KUH8300
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "Font_7Seg.h"
+
+// Select one of the testboards for PT6318 VFD controller
+#if (KUH8300_TEST == 1)
+
+//Mask for blending out and restoring Icons
+const char MASK_ICON_GRID[][3] = {
+                                   {LO(S7_ICON_GR1), MD(S7_ICON_GR1), HI(S7_ICON_GR1)},
+                                   {LO(S7_ICON_GR2), MD(S7_ICON_GR2), HI(S7_ICON_GR2)},
+                                   {LO(S7_ICON_GR3), MD(S7_ICON_GR3), HI(S7_ICON_GR3)},
+                                   {LO(S7_ICON_GR4), MD(S7_ICON_GR4), HI(S7_ICON_GR4)},
+                                   {LO(S7_ICON_GR5), MD(S7_ICON_GR5), HI(S7_ICON_GR5)},
+                                   {LO(S7_ICON_GR6), MD(S7_ICON_GR6), HI(S7_ICON_GR6)}
+                                 };
+
+// ASCII Font definition table for transmission to PT6318
+//
+//#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                             
+                        };
+ 
+#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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Font_7Seg.h	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,269 @@
+/* mbed Font Library, for PT6318 VFD Controller
+ * Copyright (c) 2016, v01: WH, Initial version, Test in KUH8300
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MBED_FONT_7SEG_H
+#define MBED_FONT_7SEG_H
+
+// Select one of the testboards for PT6318 controller
+//#include "PT6318.h"
+#include "PT6318_Config.h"
+
+#if (KUH8300_TEST == 1)
+// Segment bit positions for 7 Segment display using the KUH8300 mapping for PT6318
+// Modify this table for different 'bit-to-segment' mappings. The ASCII character defines and the FONT_7S const table below 
+// 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  
+//
+//Placeholders for remapping font to one of two digits per grid
+#define S7_A    0x0001
+#define S7_B    0x0002
+#define S7_C    0x0004
+#define S7_D    0x0008
+#define S7_E    0x0010
+#define S7_F    0x0020
+#define S7_G    0x0040 
+//#define S7_DP   0x0080 
+#define S7_DP   0x0004 
+
+//Mask for blending out and setting 7 segments digits
+#define MASK_7S_ALL = (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F | S7_G}
+
+
+//Each Grid has 2 Digits in the KUH8300
+#define S7_D0   0x000001
+#define S7_E0   0x000002
+#define S7_C0   0x000004
+#define S7_G0   0x000008 
+#define S7_F0   0x000010
+#define S7_B0   0x000020
+#define S7_A0   0x000040
+#define S7_DP0  0x000000 
+
+#define S7_A1   0x000800
+#define S7_B1   0x001000
+#define S7_F1   0x002000
+#define S7_G1   0x004000 
+#define S7_C1   0x008000
+#define S7_E1   0x010000
+#define S7_D1   0x020000
+#define S7_DP1  0x000000 
+
+//Icons Grid 1
+#define S7_CAM  0x000080
+#define S7_DIG  0x000100
+#define S7_MONO 0x000200
+#define S7_PRG  0x000400
+#define S7_DTS  0x002000
+#define S7_MEM  0x004000
+#define S7_KHZ  0x008000
+#define S7_STR  0x010000
+#define S7_MHZ  0x020000
+#define S7_ICON_GR1 (S7_CAM | S7_DIG | S7_MONO | S7_PRG | S7_DTS | S7_MEM | S7_KHZ | S7_STR | S7_MHZ)
+
+//Icons Grid 2
+#define S7_KEY  0x000080
+#define S7_ALL  0x000100
+#define S7_DP6  0x000200
+#define S7_COL6 0x000400
+#define S7_ICON_GR2 (S7_KEY | S7_ALL | S7_DP6 | S7_COL6)
+
+//Icons Grid 3
+#define S7_ARW  0x000080
+#define S7_A_   0x000100
+#define S7_B_   0x000200
+#define S7_CD4A 0x000400
+#define S7_ICON_GR3 (S7_ARW | S7_A_ | S7_B_ | S7_CD4A)
+
+//Icons Grid 4
+#define S7_CHP  0x000080
+#define S7_N3   0x000100
+#define S7_L3   0x000200
+#define S7_HK3  0x000400
+#define S7_ICON_GR4 (S7_CHP | S7_N3 | S7_L3 | S7_HK3)
+
+//Icons Grid 5
+#define S7_TTL  0x000080
+#define S7_JM1  0x000100
+#define S7_HK2  0x000400
+#define S7_ICON_GR5 (S7_TTL | S7_JM1 | S7_HK2)
+
+//Icons Grid 6
+#define S7_PSE  0x000002
+#define S7_PLY  0x000004
+#define S7_PBC  0x000008
+#define S7_DVD  0x000010
+#define S7_CD   0x000020
+#define S7_V    0x000040
+#define S7_S    0x000080
+#define S7_ICON_GR6 (S7_PSE | S7_PLY | S7_PBC | S7_DVD | S7_CD | S7_V | S7_S)
+
+//Mask for blending out and restoring Icons
+extern const char MASK_ICON_GRID[][3]; 
+//extern const char MASK_ICON_GRID[][PT6318_BYTES_PER_GRID]; 
+#endif
+
+
+// ASCII Font definitions for segments in each character
+//
+//32 0x20  Symbols
+#define C7_SPC  (0x000000)
+#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_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)
+#define C7_1    (S7_B | S7_C)
+#define C7_2    (S7_A | S7_B | S7_D | S7_E | S7_G)
+#define C7_3    (S7_A | S7_B | S7_C | S7_D | S7_G)
+#define C7_4    (S7_B | S7_C | S7_F | S7_G)
+#define C7_5    (S7_A | S7_C | S7_D | S7_F | S7_G)
+#define C7_6    (S7_A | S7_C | S7_D | S7_E | S7_F | S7_G)
+#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)
+
+//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)
+#define C7_D    (S7_B | S7_C | S7_D | S7_E | S7_G)
+#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_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 | 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_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_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
+#define C7_c     C7_C
+#define C7_d     C7_D
+#define C7_e     C7_E
+#define C7_f     C7_H
+
+#define C7_g     C7_G
+#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_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    (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  (0x000000)
+
+
+//User Defined Characters (some examples)
+#define C7_DGR   (S7_A | S7_B | S7_F | S7_G)  //Degrees
+                                                                         
+// Font data selection for transmission to PT6318 memory
+#define LO(x)  ( x & 0xFF)
+#define MD(x)  ((x >>  8) & 0xFF)
+#define HI(x)  ((x >> 16) & 0xFF)
+
+// ASCII Font definition table
+//
+#define FONT_7S_START     0x20
+#define FONT_7S_END       0x7F
+//#define FONT_7S_NR_CHARS (FONT_7S_END - FONT_7S_START + 1)
+extern const short FONT_7S[]; 
+
+#endif    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PT6318.cpp	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,646 @@
+/* mbed PT6318 Library, for Princeton PT6318 VFD controller
+ * Copyright (c) 2016, v01: WH, Initial version, for KUH8300 code
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "mbed.h" 
+#include "PT6318.h"
+
+/** Constructor for class for driving Princeton PT6318 VFD controller
+ *
+ *  @brief Supports 8 Grids of 20 Segments upto 16 Grids of 12 Segments. Also supports a scanned keyboard of upto 32 keys, 4 switches and 5 LEDs.
+ *         SPI bus interface device. 
+ *   
+ *  @param PinName mosi, miso, sclk, cs SPI bus pins
+ *  @param Mode selects either number of Digits and Segments
+*/
+PT6318::PT6318(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode) : _spi(mosi,miso,sclk), _cs(cs), _mode(mode) {
+
+  _init();
+}
+
+/** Init the SPI interface and the controller
+  * @param  none
+  * @return none
+  */ 
+void PT6318::_init(){
+  
+//init SPI
+  _cs=1;
+  _spi.format(8,3); //PT6318 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge)
+//  _spi.frequency(100000);   
+  _spi.frequency(500000);     
+
+//init controller  
+  _writeCmd(PT6318_MODE_SET_CMD, _mode);                                               // Mode set command
+
+  _display = PT6318_DSP_ON;
+  _bright  = PT6318_BRT_DEF; 
+  _writeCmd(PT6318_DSP_CTRL_CMD, _display | _bright );                                 // Display control cmd, display on/off, brightness   
+  
+  _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data  
+}   
+
+
+/** Clear the screen and locate to 0
+ */  
+void PT6318::cls() {
+  
+  _cs=0;
+  wait_us(1);    
+  _spi.write(_flip(PT6318_ADDR_SET_CMD | 0x00)); // Address set cmd, 0
+      
+  for (int cnt=0; cnt<PT6318_DISPLAY_MEM; cnt++) {
+    _spi.write(0x00); // data 
+  }
+  
+  wait_us(1);
+  _cs=1;      
+  
+}  
+
+/** Set Brightness
+  *
+  * @param  char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle)  
+  * @return none
+  */
+void PT6318::setBrightness(char brightness){
+
+  _bright = brightness & PT6318_BRT_MSK; // mask invalid bits
+  
+  _writeCmd(PT6318_DSP_CTRL_CMD, _display | _bright );  // Display control cmd, display on/off, brightness  
+
+}
+
+/** Set the Display mode On/off
+  *
+  * @param bool display mode
+  */
+void PT6318::setDisplay(bool on) {
+  
+  if (on) {
+    _display = PT6318_DSP_ON;
+  }
+  else {
+   _display = PT6318_DSP_OFF;
+  }
+  
+  _writeCmd(PT6318_DSP_CTRL_CMD, _display | _bright );  // Display control cmd, display on/off, brightness   
+}
+
+/** Write databyte to PT6318
+  *  @param  char data byte written at given address
+  *  @param  int address display memory location to write byte  
+  *  @return none
+  */ 
+void PT6318::writeData(char data, int address) {
+  _cs=0;
+  wait_us(1);    
+  _spi.write(_flip(PT6318_ADDR_SET_CMD | (address & PT6318_ADDR_MSK))); // Set Address cmd
+      
+  _spi.write(_flip(data)); // data 
+  
+  wait_us(1);
+  _cs=1;         
+    
+}
+
+/** Write Display datablock to PT6318
+  *  @param  DisplayData_t data Array of PT6318_DISPLAY_MEM (=48) bytes for displaydata (starting at address)
+  *  @param  length number bytes to write (valid range 0..PT6318_DISPLAY_MEM (=48), starting at address)   
+  *  @param  int address display memory location to write byte    
+  *  @return none
+  */    
+void PT6318::writeData(DisplayData_t data, int length, int address) {
+  _cs=0;
+  wait_us(1);    
+     
+// sanity check
+  address &= PT6318_ADDR_MSK;
+  if (length < 0) {length = 0;}
+//  if (length > PT6318_DISPLAY_MEM) {length = PT6318_DISPLAY_MEM;}
+  if ((address + length) > PT6318_DISPLAY_MEM) {length = PT6318_DISPLAY_MEM - address;}
+  
+//  _spi.write(_flip(PT6318_ADDR_SET_CMD | 0x00)); // Set Address at 0
+  _spi.write(_flip(PT6318_ADDR_SET_CMD | address)); // Set Address
+    
+//  for (int idx=0; idx<PT6318_DISPLAY_MEM; idx++) {  
+  for (int idx=0; idx<length; idx++) {    
+//    _spi.write(_flip(data[idx])); // data 
+    _spi.write(_flip(data[address + idx])); // data    
+  }
+  
+  wait_us(1);
+  _cs=1;
+}
+
+/** Read keydata block from PT6318
+  *  @param  *keydata Ptr to Array of PT6318_KEY_MEM (=6) bytes for keydata
+  *  @return bool keypress True when at least one key was pressed
+  *
+  * Note: Due to the hardware configuration the PT6318 key matrix scanner will detect multiple keys pressed at same time,
+  *       but this may also result in some spurious keys being set in keypress data array.
+  *       It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting.  
+  */ 
+bool PT6318::getKeys(KeyData_t *keydata) {
+  int keypress = 0;
+  char data;
+
+  // Read keys
+  _cs=0;
+  wait_us(1);    
+  
+  // Enable Key Read mode
+  _spi.write(_flip(PT6318_DATA_SET_CMD | PT6318_KEY_RD | PT6318_ADDR_INC | PT6318_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data
+
+  for (int idx=0; idx < PT6318_KEY_MEM; idx++) {
+    data = _flip(_spi.write(0xFF));    // read keys and correct bitorder
+    
+    data = data & PT6318_KEY_MSK; // Mask valid bits
+    if (data != 0) {  // Check for any pressed key
+      for (int bit=0; bit < 8; bit++) {
+        if (data & (1 << bit)) {keypress++;} // Test all significant bits
+      }
+    }  
+
+    (*keydata)[idx] = data;            // Store keydata after correcting bitorder
+  }
+
+  wait_us(1);
+  _cs=1;    
+
+  // Restore Data Write mode
+  _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data  
+      
+#if(1)
+// Dismiss multiple keypresses at same time
+  return (keypress == 1);    
+#else
+// Allow multiple keypress and accept possible spurious keys
+  return (keypress > 0);
+#endif  
+}
+
+/** Read switches from PT6318
+  *
+  *  @param  none
+  *  @return char for switch data (4 least significant bits) 
+  *
+  */   
+char PT6318::getSwitches() {
+  char data;
+
+  // Read switches
+  _cs=0;
+  wait_us(1);    
+  
+  // Enable Switch Read mode
+  _spi.write(_flip(PT6318_DATA_SET_CMD | PT6318_SW_RD | PT6318_ADDR_INC | PT6318_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data
+
+  data = _flip(_spi.write(0xFF)) & PT6318_SW_MSK;   // read switches and correct bitorder
+
+  wait_us(1);
+  _cs=1;    
+
+  // Restore Data Write mode
+  _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data  
+      
+  return data;       
+}
+   
+
+/** Set LEDs
+  *
+  * @param  char leds (4 least significant bits)  
+  * @return none
+  */
+void  PT6318::setLED (char leds) {
+
+  // Set LEDs
+  _cs=0;
+  wait_us(1);    
+  
+  // Enable LED Write mode
+  _spi.write(_flip(PT6318_DATA_SET_CMD | PT6318_LED_WR | PT6318_ADDR_INC | PT6318_MODE_NORM)); // Data set cmd, normal mode, auto incr, write data
+
+  _spi.write(_flip(leds & PT6318_LED_MSK));    // write LEDs in correct bitorder
+
+  wait_us(1);
+  _cs=1;    
+
+  // Restore Data Write mode
+  _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data  
+}
+
+
+
+/** Helper to reverse all command or databits. The PT6318 expects LSB first, whereas SPI is MSB first
+  *  @param  char data
+  *  @return bitreversed data
+  */ 
+char PT6318::_flip(char data) {
+ char value=0;
+  
+ if (data & 0x01) {value |= 0x80;} ;  
+ if (data & 0x02) {value |= 0x40;} ;
+ if (data & 0x04) {value |= 0x20;} ;
+ if (data & 0x08) {value |= 0x10;} ;
+ if (data & 0x10) {value |= 0x08;} ;
+ if (data & 0x20) {value |= 0x04;} ;
+ if (data & 0x40) {value |= 0x02;} ;
+ if (data & 0x80) {value |= 0x01;} ;
+ return value;       
+}
+
+
+/** Write command and parameter to PT6318
+  *  @param  int cmd Command byte
+  *  &Param  int data Parameters for command
+  *  @return none
+  */  
+void PT6318::_writeCmd(int cmd, int data){
+    
+  _cs=0;
+  wait_us(1);    
+ 
+  _spi.write(_flip( (cmd & PT6318_CMD_MSK) | (data & ~PT6318_CMD_MSK)));   
+ 
+  wait_us(1);
+  _cs=1;      
+    
+};  
+
+
+
+#if (KUH8300_TEST == 1)
+/** Constructor for class for driving Princeton PT6318 VFD controller as used in KUH8300
+  *
+  *  @brief Supports 8 Grids of 20 Segments and Icons (8 1/2 digits of 14 Segments plus some icons).  
+  *         Also supports a scanned keyboard of 12 keys and 1 LED.
+  *  
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */  
+PT6318_KUH8300::PT6318_KUH8300(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6318(mosi, miso, sclk, cs, Grid8_Seg20) {
+  _column  = 0;
+  _columns = KUH8300_NR_DIGITS;    
+}  
+
+#if(0)
+#if DOXYGEN_ONLY
+    /** Write a character to the Display
+     *
+     * @param c The character to write to the display
+     */
+    int putc(int c);
+
+    /** Write a formatted string to the Display
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formatting the string.
+     */
+    int printf(const char* format, ...);   
+#endif
+#endif
+
+/** Locate cursor to a screen column
+  *
+  * @param column  The horizontal position from the left, indexed from 0
+  */
+void PT6318_KUH8300::locate(int column) {
+  //sanity check
+  if (column < 0) {column = 0;}
+  if (column > (_columns - 1)) {column = _columns - 1;}  
+  
+  _column = column;       
+}
+
+
+/** Number of screen columns
+  *
+  * @param none
+  * @return columns
+  */
+int PT6318_KUH8300::columns() {
+    return _columns;
+}
+
+    
+/** Clear the screen and locate to 0
+  * @param bool clrAll Clear Icons also (default = false)
+  */ 
+void PT6318_KUH8300::cls(bool clrAll) {  
+  int idx;
+  
+  if (clrAll) {
+    //clear local buffer (including Icons)
+    for (idx=0; idx < (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID); idx++) {
+      _displaybuffer[idx] = 0x00;  
+    }
+  }  
+  else {
+    //clear local buffer (preserving Icons)
+    for (int grd=0; grd < KUH8300_NR_GRIDS; grd++) {
+      idx = grd * PT6318_BYTES_PER_GRID; // 3 bytes for every Grid
+      _displaybuffer[idx    ] = _displaybuffer[idx    ] & MASK_ICON_GRID[grd][0];  
+      _displaybuffer[idx + 1] = _displaybuffer[idx + 1] & MASK_ICON_GRID[grd][1];
+      _displaybuffer[idx + 2] = _displaybuffer[idx + 2] & MASK_ICON_GRID[grd][2];      
+    }  
+  }
+
+  writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID));
+
+  _column = 0;   
+}    
+
+/** Set Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs
+  * @return none
+  */
+void PT6318_KUH8300::setIcon(Icon icon) {
+  int addr, icn;
+
+   icn =        icon  & 0xFFFFFF;
+  addr = (icon >> 24) & 0xFF; 
+  addr = (addr - 1) * PT6318_BYTES_PER_GRID;  // 3 Bytes for every Grid
+    
+  //Save char...and set bits for icon to write
+  _displaybuffer[addr    ] = _displaybuffer[addr    ] | LO(icn);      
+  _displaybuffer[addr + 1] = _displaybuffer[addr + 1] | MD(icn);      
+  _displaybuffer[addr + 2] = _displaybuffer[addr + 2] | HI(icn);        
+  writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID));
+}
+
+/** Clr Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs
+  * @return none
+  */
+void PT6318_KUH8300::clrIcon(Icon icon) {
+  int addr, icn;
+
+   icn =        icon  & 0xFFFFFF;
+  addr = (icon >> 24) & 0xFF; 
+  addr = (addr - 1) * PT6318_BYTES_PER_GRID;   // 3 Bytes for every Grid
+    
+  //Save char...and clr bits for icon to write
+  _displaybuffer[addr    ] = _displaybuffer[addr    ] & ~LO(icn);      
+  _displaybuffer[addr + 1] = _displaybuffer[addr + 1] & ~MD(icn);      
+  _displaybuffer[addr + 2] = _displaybuffer[addr + 2] & ~HI(icn);        
+  writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID));
+}
+
+
+/** Set User Defined Characters (UDC)
+  *
+  * @param unsigned char udc_idx  The Index of the UDC (0..7)
+  * @param int udc_data           The bitpattern for the UDC (16 bits)       
+  */
+void PT6318_KUH8300::setUDC(unsigned char udc_idx, int udc_data) {
+
+  //Sanity check
+  if (udc_idx > (KUH8300_NR_UDC-1)) {
+    return;
+  }
+
+  // Mask out Icon bits?
+  _UDC_16S[udc_idx] = udc_data & 0xFFFF;
+}
+
+/** Write a single character (Stream implementation)
+  */
+int PT6318_KUH8300::_putc(int value) {
+    bool validChar = false;
+    bool even = false;
+    short pattern  = 0x0000;
+    int addr;
+    
+    if ((value == '\n') || (value == '\r')) {
+      //No character to write
+      validChar = false;
+      
+      //Update Cursor      
+      _column = 0;
+    }
+    else if ((value >= 0) && (value < KUH8300_NR_UDC)) {
+      //Character to write
+      validChar = true;
+      pattern = _UDC_16S[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;
+      pattern = FONT_7S[value - (int) '0'];
+    }
+    else if ((value >= (int) 'A') && (value <= (int) 'F')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[10 + value - (int) 'A'];
+    }
+    else if ((value >= (int) 'a') && (value <= (int) 'f')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[10 + value - (int) 'a'];
+    } //else
+#endif
+    if (validChar) {
+      //Character to write
+ 
+      //Translate between _column and displaybuffer entries
+      //Note that the KUH8300 has 8 7-Segment digits using 4 Grids. 
+      //Some of these Grids also have icons that need to be preserved
+      //_column ==  0 => Grid5 => addr = 12..14
+      //_column ==  1 => Grid5 => addr = 12..14
+      // ....
+      //_column ==  6 => Grid2 => addr =  3..5            
+      //_column ==  7 => Grid2 => addr =  3..5            
+      addr = 12 - ((_column >> 1) * PT6318_BYTES_PER_GRID); // 3 Bytes for every Grid;
+      even = ((_column & 0x01) == 0x00);                    // Odd or Even column
+      
+      // pattern is a placeholder, test pattern and set the actual segment depending on the odd or even _column for this Grid
+      if (pattern & S7_A) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_A0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_A1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_A0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_A1);
+        }
+      }
+
+      if (pattern & S7_B) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_B0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_B1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_B0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_B1);
+        }
+      }
+
+      if (pattern & S7_C) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_C0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_C1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_C0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_C1);
+        }
+      }
+
+      if (pattern & S7_D) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_D0);
+        }
+        else {
+          _displaybuffer[addr+2] = _displaybuffer[addr+2] | HI(S7_D1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_D0);
+        }
+        else {
+          _displaybuffer[addr+2] = _displaybuffer[addr+2] & ~HI(S7_D1);
+        }
+      }
+
+      if (pattern & S7_E) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_E0);
+        }
+        else {
+          _displaybuffer[addr+2] = _displaybuffer[addr+2] | HI(S7_E1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_E0);
+        }
+        else {
+          _displaybuffer[addr+2] = _displaybuffer[addr+2] & ~HI(S7_E1);
+        }
+      }
+
+      if (pattern & S7_F) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_F0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_F1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_F0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_F1);
+        }
+      }
+
+      if (pattern & S7_G) {
+        //Set Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   | LO(S7_G0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_G1);
+        }
+      }
+      else {
+        //Clear Segment
+        if (even) {
+          _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(S7_G0);
+        }
+        else {
+          _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_G1);
+        }
+      }
+
+//      //Save icons...and set bits for character to write
+//      _displaybuffer[addr]   = (_displaybuffer[addr]   & MASK_ICON_GRID[_column][0]) | LO(pattern);
+//      _displaybuffer[addr+1] = (_displaybuffer[addr+1] & MASK_ICON_GRID[_column][1]) | MD(pattern);
+//      _displaybuffer[addr+2] = (_displaybuffer[addr+2] & MASK_ICON_GRID[_column][2]) | HI(pattern);
+
+      writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID));
+                                
+      //Update Cursor
+      _column++;
+      if (_column > (KUH8300_NR_DIGITS - 1)) {
+        _column = 0;
+      }
+
+    } // if validChar           
+
+    return value;
+}
+
+// get a single character (Stream implementation)
+int PT6318_KUH8300::_getc() {
+    return -1;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PT6318.h	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,438 @@
+/* mbed PT6318 Library, for Princeton PT6318 VFD controller
+ * Copyright (c) 2016, v01: WH, Initial version for KUH8300
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef PT6318_H
+#define PT6318_H
+
+// Select one of the testboards for Princeton PT6318 VFD controller
+#include "PT6318_Config.h"
+
+/** An interface for driving Princeton PT6318 VFD controller
+ *
+ * @code
+ *
+ * #if (PT6318_TEST == 1)  
+ * // Direct driving of PT6318 Test
+ *
+ * #include "mbed.h"
+ * #include "PT6318.h" 
+ * 
+ * DisplayData_t size is 24 bytes (8 Grids @ 20 Segments) ... 48 bytes (16 Grids @ 12 Segments) 
+ * DisplayData_t size default is 48 bytes (16 Grids @ 12 Segments) 
+ * PT6318::DisplayData_t all_str  = {0xFF,0x0F,0x00 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00,
+ *                                   0xFF,0x0F,0x00 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00};  
+ *
+ * // KeyData_t size is 6 bytes  
+ * PT6318::KeyData_t keydata; 
+ *
+ * // PT6318 declaration, Default setting 16 Grids @ 12 Segments
+ * PT6318 PT6318(p5,p6,p7, p8);
+ *
+ * int main() {
+ *   PT6318.cls(); 
+ *   PT6318.writeData(all_str);
+ *   wait(4);
+ *   PT6318.setBrightness(PT6318_BRT0);
+ *   wait(1);
+ *   PT6318.setBrightness(PT6318_BRT3);
+ *
+ *   while (1) {
+ *    // Check and read keydata
+ *    if (PT6318.getKeys(&keydata)) {
+ *      pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]);
+ *
+ *      if (keydata[0] == 0x10) { //sw2   
+ *        PT6318.cls(); 
+ *        wait(1);
+ *        PT6318.writeData(all_str);
+ *      }  
+ *    } 
+ *   }   
+ * }
+ * #endif
+ *
+ * @endcode
+ */
+
+//PT6318 Display and Keymatrix data
+#define PT6318_MAX_NR_GRIDS   16
+#define PT6318_BYTES_PER_GRID  3
+//Significant bits Keymatrix data
+#define PT6318_KEY_MSK      0xFF 
+
+//Memory size in bytes for Display and Keymatrix
+#define PT6318_DISPLAY_MEM  (PT6318_MAX_NR_GRIDS * PT6318_BYTES_PER_GRID)
+#define PT6318_KEY_MEM         6
+
+//Reserved bits for commands
+#define PT6318_CMD_MSK      0xC0
+
+//Mode setting command
+#define PT6318_MODE_SET_CMD 0x00
+#define PT6318_GR8_SEG20    0x00
+#define PT6318_GR9_SEG19    0x08
+#define PT6318_GR10_SEG18   0x09
+#define PT6318_GR11_SEG17   0x0A
+#define PT6318_GR12_SEG16   0x0B
+#define PT6318_GR13_SEG15   0x0C
+#define PT6318_GR14_SEG14   0x0D
+#define PT6318_GR15_SEG13   0x0E
+#define PT6318_GR16_SEG12   0x0F //default
+
+//Data setting commands
+#define PT6318_DATA_SET_CMD 0x40
+#define PT6318_DATA_WR      0x00
+#define PT6318_LED_WR       0x01
+#define PT6318_KEY_RD       0x02
+#define PT6318_SW_RD        0x03
+#define PT6318_ADDR_INC     0x00
+#define PT6318_ADDR_FIXED   0x04
+#define PT6318_MODE_NORM    0x00
+#define PT6318_MODE_TEST    0x08
+
+//LED settings data
+#define PT6318_LED_MSK      0x1F
+#define PT6318_LED1         0x01
+#define PT6318_LED2         0x02
+#define PT6318_LED3         0x04
+#define PT6318_LED4         0x08
+#define PT6318_LED5         0x10
+
+//Switch settings data
+#define PT6318_SW_MSK       0x0F
+#define PT6318_SW1          0x01
+#define PT6318_SW2          0x02
+#define PT6318_SW3          0x04
+#define PT6318_SW4          0x08
+
+//Address setting commands
+#define PT6318_ADDR_SET_CMD 0xC0
+#define PT6318_ADDR_MSK     0x3F
+
+//Display control commands
+#define PT6318_DSP_CTRL_CMD 0x80
+#define PT6318_BRT_MSK      0x07
+#define PT6318_BRT0         0x00 //Pulsewidth 1/16, Default
+#define PT6318_BRT1         0x01
+#define PT6318_BRT2         0x02
+#define PT6318_BRT3         0x03
+#define PT6318_BRT4         0x04
+#define PT6318_BRT5         0x05
+#define PT6318_BRT6         0x06
+#define PT6318_BRT7         0x07 //Pulsewidth 14/16
+
+#define PT6318_BRT_DEF      PT6318_BRT3
+
+#define PT6318_DSP_OFF      0x00 //Default
+#define PT6318_DSP_ON       0x08
+
+
+/** A class for driving Princeton PT6318 VFD controller
+ *
+ * @brief Supports 8 Grids of 20 Segments upto 16 Grids of 12 Segments. Also supports a scanned keyboard of upto 32 keys, 4 switches and 5 LEDs.
+ *        SPI bus interface device. 
+ */
+class PT6318 {
+ public:
+
+  /** Enums for display mode */
+  enum Mode {  
+    Grid8_Seg20  = PT6318_GR8_SEG20,  /**<   8 Grids, 20 Segments */
+    Grid9_Seg19  = PT6318_GR9_SEG19,  /**<   9 Grids, 19 Segments */
+    Grid10_Seg18 = PT6318_GR10_SEG18, /**<  10 Grids, 18 Segments */
+    Grid11_Seg17 = PT6318_GR11_SEG17, /**<  11 Grids, 17 Segments */
+    Grid12_Seg16 = PT6318_GR12_SEG16, /**<  12 Grids, 16 Segments */
+    Grid13_Seg15 = PT6318_GR13_SEG15, /**<  13 Grids, 15 Segments */
+    Grid14_Seg14 = PT6318_GR14_SEG14, /**<  14 Grids, 14 Segments */
+    Grid15_Seg13 = PT6318_GR15_SEG13, /**<  15 Grids, 13 Segments */
+    Grid16_Seg12 = PT6318_GR16_SEG12  /**<  16 Grids, 12 Segments */
+  };
+ 
+  /** Datatypes for display and keymatrix data */
+  typedef char DisplayData_t[PT6318_DISPLAY_MEM];
+  typedef char KeyData_t[PT6318_KEY_MEM];
+    
+ /** Constructor for class for driving Princeton PT6318 VFD controller
+  *
+  *  @brief Supports 8 Grids of 20 Segments upto 16 Grids of 12 Segments. Also supports a scanned keyboard of upto 32 keys, 4 switches and 5 LEDs.
+  *         SPI bus interface device. 
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  *  @param  Mode selects either number of Grids and Segments (default 16 Grids, 12 Segments)
+  */
+  PT6318(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode=Grid16_Seg12);
+      
+  /** Clear the screen and locate to 0
+   */ 
+  void cls();  
+
+  /** Write databyte to PT6318
+   *  @param  char data byte written at given address
+   *  @param  int address display memory location to write byte   
+   *  @return none
+   */ 
+  void writeData(char data, int address); 
+ 
+  /** Write Display datablock to PT6318
+   *  @param  DisplayData_t data Array of PT6318_DISPLAY_MEM (=48) bytes for displaydata (starting at address)
+   *  @param  length number bytes to write (valid range 0..PT6318_DISPLAY_MEM (=48), starting at address)   
+   *  @param  int address display memory location to write byte (default = 0)
+   *  @return none
+   */   
+  void writeData(DisplayData_t data, int length = PT6318_DISPLAY_MEM, int address = 0);
+
+
+  /** Read keydata block from PT6318
+   *  @param  *keydata Ptr to Array of PT6318_KEY_MEM (=6) bytes for keydata
+   *  @return bool keypress True when at least one key was pressed
+   *
+   * Note: Due to the hardware configuration the PT6318 key matrix scanner will detect multiple keys pressed at same time,
+   *       but this may result in some spurious keys also being set in keypress data array.
+   *       It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting.
+   */   
+  bool getKeys(KeyData_t *keydata);
+
+
+  /** Read switches from PT6318
+   *
+   *  @param  none
+   *  @return char for switch data (4 least significant bits)
+   */   
+  char getSwitches();
+
+  /** Set LEDs
+    *
+    * @param  char leds (5 least significant bits)  
+    * @return none
+    */
+  void setLED (char leds = 0);
+
+  /** Set Brightness
+    *
+    * @param  char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle)  
+    * @return none
+    */
+  void setBrightness(char brightness = PT6318_BRT_DEF);
+  
+  /** Set the Display mode On/off
+    *
+    * @param bool display mode
+    */
+  void setDisplay(bool on);
+  
+ private:  
+  SPI _spi;
+  DigitalOut _cs;
+  Mode _mode;
+  char _display;
+  char _bright; 
+  
+  /** Init the SPI interface and the controller
+    * @param  none
+    * @return none
+    */ 
+  void _init();
+
+  /** Helper to reverse all command or databits. The PT6318 expects LSB first, whereas SPI is MSB first
+    *  @param  char data
+    *  @return bitreversed data
+    */ 
+  char _flip(char data);
+
+  /** Write command and parameter to PT6318
+    *  @param  int cmd Command byte
+    *  &Param  int data Parameters for command
+    *  @return none
+    */ 
+  void _writeCmd(int cmd, int data);  
+};
+
+
+
+#if (KUH8300_TEST == 1)
+// Derived class for KUH8300 front display unit
+//   Grids 2-11 all display 14-Segment digits and several Icons.
+//   Grid 1 and 12 display Icons. 
+
+//
+#include "Font_7Seg.h"
+
+//KUH8300 Display data
+#define KUH8300_NR_GRIDS   6
+#define KUH8300_NR_DIGITS  8
+#define KUH8300_NR_UDC     8
+
+//KUH8300 Memory size in bytes for Display
+#define KUH8300_DISPLAY_MEM (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID)
+
+
+/** Constructor for class for driving Princeton PT6318 VFD controller as used in KUH8300
+  *
+  *  @brief Supports 8 Grids of 20 Segments and Icons (8 1/2 digits of 14 segments plus some icons).
+  *         Also supports a scanned keyboard of 12 keys and 1 LED.
+  *  
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */
+class PT6318_KUH8300 : public PT6318, public Stream {
+ public:
+
+  /** Enums for Icons */
+  //  Grid encoded in 8 MSBs, Icon pattern encoded in 24 LSBs
+  enum Icon {
+    CAM  = (1<<24) | S7_CAM,
+    DIG  = (1<<24) | S7_DIG,
+    MONO = (1<<24) | S7_MONO,
+    PRG  = (1<<24) | S7_PRG,    
+    DTS  = (1<<24) | S7_DTS,
+    MEM  = (1<<24) | S7_MEM,
+    KHZ  = (1<<24) | S7_KHZ,
+    STR  = (1<<24) | S7_STR,
+    MHZ  = (1<<24) | S7_MHZ,
+
+    KEY  = (2<<24) | S7_KEY,
+    ALL  = (2<<24) | S7_ALL,
+    DP6  = (2<<24) | S7_DP6,
+    COL6 = (2<<24) | S7_COL6,    
+
+    ARW  = (3<<24) | S7_ARW,
+    A_   = (3<<24) | S7_A_,
+    B_   = (3<<24) | S7_B_,
+    CD4A = (3<<24) | S7_CD4A,    
+    
+    CHP  = (4<<24) | S7_CHP,
+    N3   = (4<<24) | S7_N3,
+    L3   = (4<<24) | S7_L3,
+    HK3  = (4<<24) | S7_HK3,    
+
+    TTL  = (5<<24) | S7_TTL,
+    JM1  = (5<<24) | S7_JM1,    
+    HK2  = (5<<24) | S7_HK2,    
+
+    PSE  = (6<<24) | S7_PSE,
+    PLY  = (6<<24) | S7_PLY,    
+    PBC  = (6<<24) | S7_PBC,    
+    DVD  = (6<<24) | S7_DVD,
+    CD   = (6<<24) | S7_CD,    
+    V    = (6<<24) | S7_V,    
+    S    = (6<<24) | S7_S
+  };
+  
+  typedef short UDCData_t[KUH8300_NR_UDC];
+
+
+/** Constructor for class for driving Princeton PT6318 VFD controller as used in KUH8300
+  *
+  *  @brief Supports 8 Grids of 20 Segments and Icons (8 1/2 digits of 14 Segments plus some icons).
+  *         Also supports a scanned keyboard of 12 keys and 1 LED.
+  *  
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */
+  PT6318_KUH8300(PinName mosi, PinName miso, PinName sclk, PinName cs);
+
+#if DOXYGEN_ONLY
+    /** Write a character to the Display
+     *
+     * @param c The character to write to the display
+     */
+    int putc(int c);
+
+    /** Write a formatted string to the Display
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formatting the string.
+     */
+    int printf(const char* format, ...);   
+#endif
+
+     /** Locate cursor to a screen column
+     *
+     * @param column  The horizontal position from the left, indexed from 0
+     */
+    void locate(int column);
+    
+    /** Clear the screen and locate to 0
+     * @param bool clrAll Clear Icons also (default = false)
+     */
+    void cls(bool clrAll = false);
+
+    /** Set Icon
+     *
+     * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs
+     * @return none
+     */
+    void setIcon(Icon icon);
+
+    /** Clr Icon
+     *
+     * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs
+     * @return none
+     */
+    void clrIcon(Icon icon);
+
+   /** Set User Defined Characters (UDC)
+     *
+     * @param unsigned char udc_idx   The Index of the UDC (0..7)
+     * @param int udc_data            The bitpattern for the UDC (16 bits)       
+     */
+    void setUDC(unsigned char udc_idx, int udc_data);
+
+
+   /** Number of screen columns
+    *
+    * @param none
+    * @return columns
+    */
+    int columns();   
+
+   /** Write databyte to PT6318
+     *  @param  char data byte written at given address
+     *  @param  int address display memory location to write byte     
+     *  @return none
+     */ 
+    void writeData(int address, char data){
+      PT6318::writeData(address, data);
+    }        
+ 
+   /** Write Display datablock to PT6318
+    *  @param  DisplayData_t data Array of PT6318_DISPLAY_MEM (=36) bytes for displaydata (starting at address)
+    *  @param  length number bytes to write (valid range 0..(KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID) == 24, starting at address)   
+    *  @param  int address display memory location to write byte (default = 0)
+    *  @return none
+    */   
+    void writeData(DisplayData_t data, int length = (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID), int address = 0) {
+      PT6318::writeData(data, length, address);
+    }  
+
+protected:  
+    // Stream implementation functions
+    virtual int _putc(int value);
+    virtual int _getc();
+
+private:
+    int _column;                     // Current cursor location
+    int _columns;                    // Max number of columns
+    
+    DisplayData_t _displaybuffer;    // Local mirror for all chars and icons
+    UDCData_t _UDC_16S;              // User Defined Character pattterns (UDC)    
+};
+#endif
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PT6318_Config.h	Mon Feb 01 20:18:04 2016 +0000
@@ -0,0 +1,33 @@
+/* mbed PT6318 Library, for Princeton PT6318 VFD controller
+ * Copyright (c) 2016, v01: WH, Initial version, KUH8300
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef PT6318_CONFIG_H
+#define PT6318_CONFIG_H
+
+// Select one of the testboards for Princeton PT6318 VFD controller
+#define PT6318_TEST    0 
+#define KUH8300_TEST   1 
+
+// Select the display mode: only digits and hex or ASCII
+#define SHOW_ASCII     1 
+
+#endif
\ No newline at end of file