PT6315 VFD driver. Supports DVDR3510.
Revision 0:d93c23711ca8, committed 2016-01-20
- Comitter:
- wim
- Date:
- Wed Jan 20 19:24:17 2016 +0000
- Commit message:
- PT6315 VFD driver library. Supports DVDR3510. First release.
Changed in this revision
diff -r 000000000000 -r d93c23711ca8 Font_16Seg.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Font_16Seg.cpp Wed Jan 20 19:24:17 2016 +0000 @@ -0,0 +1,160 @@ +/* mbed VFD Font Library, for Princeton PT6315 VFD controller as used in DVDR3510 + * Copyright (c) 2016, v01: WH, Initial version for DVDR3510 + * + * 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 PT6315 VFD controller +#include "PT6315_Config.h" + +#if (DVDR3510_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 PT6315 +// +//#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 PT6315 +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
diff -r 000000000000 -r d93c23711ca8 Font_16Seg.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Font_16Seg.h Wed Jan 20 19:24:17 2016 +0000 @@ -0,0 +1,246 @@ +/* mbed VFD Font Library, for Princeton PT6315 VFD controller as used in DVDR3510 + * Copyright (c) 2016, v01: WH, Initial version for DVDR3510 + * + * 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 PT6315 VFD controller +#include "PT6315_Config.h" + +#if (DVDR3510_TEST == 1) +//#if (1) +// Segment bit positions for 14 or 16 Segment display using the DVDR3510 mapping for PT6315 +// 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
diff -r 000000000000 -r d93c23711ca8 PT6315.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PT6315.cpp Wed Jan 20 19:24:17 2016 +0000 @@ -0,0 +1,476 @@ +/* mbed PT6315 Library, for Princeton PT6315 VFD controller + * Copyright (c) 2016, v01: WH, Initial version, for DVDR3510 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 "PT6315.h" + +/** Constructor for class for driving Princeton PT6315 VFD controller + * + * @brief Supports 4 Grids of 24 Segments upto 12 Grids of 16 Segments. Also supports a scanned keyboard of upto 32 keys and 4 LEDs. + * SPI bus interface device. + * + * @param PinName mosi, miso, sclk, cs SPI bus pins + * @param Mode selects either number of Digits and Segments +*/ +PT6315::PT6315(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 PT6315::_init(){ + +//init SPI + _cs=1; + _spi.format(8,3); //PT6315 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge) +// _spi.frequency(100000); + _spi.frequency(500000); + +//init controller + _writeCmd(PT6315_MODE_SET_CMD, _mode); // Mode set command + + _display = PT6315_DSP_ON; + _bright = PT6315_BRT_DEF; + _writeCmd(PT6315_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness + + _writeCmd(PT6315_DATA_SET_CMD, PT6315_DATA_WR | PT6315_ADDR_INC | PT6315_MODE_NORM); // Data set cmd, normal mode, auto incr, write data +} + + +/** Clear the screen and locate to 0 + */ +void PT6315::cls() { + + _cs=0; + wait_us(1); + _spi.write(_flip(PT6315_ADDR_SET_CMD | 0x00)); // Address set cmd, 0 + + for (int cnt=0; cnt<PT6315_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/14 dutycycle) + * @return none + */ +void PT6315::setBrightness(char brightness){ + + _bright = brightness & PT6315_BRT_MSK; // mask invalid bits + + _writeCmd(PT6315_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness + +} + +/** Set the Display mode On/off + * + * @param bool display mode + */ +void PT6315::setDisplay(bool on) { + + if (on) { + _display = PT6315_DSP_ON; + } + else { + _display = PT6315_DSP_OFF; + } + + _writeCmd(PT6315_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness +} + +/** Write databyte to PT6315 + * @param int address display memory location to write byte + * @param char data byte written at given address + * @return none + */ +void PT6315::writeData(int address, char data) { + _cs=0; + wait_us(1); + _spi.write(_flip(PT6315_ADDR_SET_CMD | (address & PT6315_ADDR_MSK))); // Set Address cmd + + _spi.write(_flip(data)); // data + + wait_us(1); + _cs=1; + +} + +/** Write Display datablock to PT6315 + * @param DisplayData_t data Array of PT6315_DISPLAY_MEM (=48) bytes for displaydata (starting at address 0) + * @param length number bytes to write (valid range 0..PT6315_DISPLAY_MEM (=48), starting at address 0) + * @return none + */ +void PT6315::writeData(DisplayData_t data, int length) { + _cs=0; + wait_us(1); + _spi.write(_flip(PT6315_ADDR_SET_CMD | 0x00)); // Set Address at 0 + +// sanity check + if (length < 0) {length = 0;} + if (length > PT6315_DISPLAY_MEM) {length = PT6315_DISPLAY_MEM;} + +// for (int idx=0; idx<PT6315_DISPLAY_MEM; idx++) { + for (int idx=0; idx<length; idx++) { + _spi.write(_flip(data[idx])); // data + } + + wait_us(1); + _cs=1; + +} + +/** Read keydata block from PT6315 + * @param *keydata Ptr to Array of PT6315_KEY_MEM (=4) bytes for keydata + * @return bool keypress True when at least one key was pressed + * + * Note: Due to the hardware configuration the PT6315 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 PT6315::getKeys(KeyData_t *keydata) { + int keypress = 0; + char data; + + // Read keys + _cs=0; + wait_us(1); + + // Enable Key Read mode + _spi.write(_flip(PT6315_DATA_SET_CMD | PT6315_KEY_RD | PT6315_ADDR_INC | PT6315_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data + + for (int idx=0; idx < PT6315_KEY_MEM; idx++) { + data = _flip(_spi.write(0xFF)); // read keys and correct bitorder + + data = data & PT6315_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(PT6315_DATA_SET_CMD, PT6315_DATA_WR | PT6315_ADDR_INC | PT6315_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 +} + +/** Set LEDs + * + * @param char leds (4 least significant bits) + * @return none + */ +void PT6315::setLED (char leds) { + + // Set LEDs + _cs=0; + wait_us(1); + + // Enable LED Write mode + _spi.write(_flip(PT6315_DATA_SET_CMD | PT6315_LED_WR | PT6315_ADDR_INC | PT6315_MODE_NORM)); // Data set cmd, normal mode, auto incr, write data + + _spi.write(_flip(leds & PT6315_LED_MSK)); // write LEDs in correct bitorder + + wait_us(1); + _cs=1; + + // Restore Data Write mode + _writeCmd(PT6315_DATA_SET_CMD, PT6315_DATA_WR | PT6315_ADDR_INC | PT6315_MODE_NORM); // Data set cmd, normal mode, auto incr, write data +} + + + +/** Helper to reverse all command or databits. The PT6315 expects LSB first, whereas SPI is MSB first + * @param char data + * @return bitreversed data + */ +char PT6315::_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 PT6315 + * @param int cmd Command byte + * &Param int data Parameters for command + * @return none + */ +void PT6315::_writeCmd(int cmd, int data){ + + _cs=0; + wait_us(1); + + _spi.write(_flip( (cmd & PT6315_CMD_MSK) | (data & ~PT6315_CMD_MSK))); + + wait_us(1); + _cs=1; + +}; + + + +#if (DVDR3510_TEST == 1) +/** Constructor for class for driving Princeton PT6315 VFD controller as used in DVDR3510 + * + * @brief Supports 11 Grids of 17 Segments and Icons (8 digits of 14 Segments plus some icons). + * Also supports a scanned keyboard of 11 keys and 1 LED. + * + * @param PinName mosi, miso, sclk, cs SPI bus pins + */ +PT6315_DVDR3510::PT6315_DVDR3510(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6315(mosi, miso, sclk, cs, Grid11_Seg17) { + _column = 0; + _columns = DVDR3510_NR_DIGITS; +} + +#if(0) +#if DOXYGEN_ONLY + /** Write a character to the LCD + * + * @param c The character to write to the display + */ + int putc(int c); + + /** Write a formatted string to the LCD + * + * @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 PT6315_DVDR3510::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 PT6315_DVDR3510::columns() { + return _columns; +} + + +/** Clear the screen and locate to 0 + * @param bool clrAll Clear Icons also (default = false) + */ +void PT6315_DVDR3510::cls(bool clrAll) { + int idx; + + if (clrAll) { + //clear local buffer (including Icons) + for (idx=0; idx < (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID); idx++) { + _displaybuffer[idx] = 0x00; + } + } + else { + //clear local buffer (preserving Icons) + for (int grd=0; grd < DVDR3510_NR_GRIDS; grd++) { + idx = grd * PT6315_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, (DVDR3510_NR_GRIDS * PT6315_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 PT6315_DVDR3510::setIcon(Icon icon) { + int addr, icn; + + icn = icon & 0xFFFFFF; + addr = (icon >> 24) & 0xFF; + addr = (addr - 1) * PT6315_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, (DVDR3510_NR_GRIDS * PT6315_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 PT6315_DVDR3510::clrIcon(Icon icon) { + int addr, icn; + + icn = icon & 0xFFFFFF; + addr = (icon >> 24) & 0xFF; + addr = (addr - 1) * PT6315_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, (DVDR3510_NR_GRIDS * PT6315_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 PT6315_DVDR3510::setUDC(unsigned char udc_idx, int udc_data) { + + //Sanity check + if (udc_idx > (DVDR3510_NR_UDC-1)) { + return; + } + + // Mask out Icon bits? + _UDC_16S[udc_idx] = udc_data & 0xFFFF; +} + +/** Write a single character (Stream implementation) + */ +int PT6315_DVDR3510::_putc(int value) { + bool validChar = 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 < DVDR3510_NR_UDC)) { + //Character to write + validChar = true; + pattern = _UDC_16S[value]; + } +#if (SHOW_ASCII == 1) + //display all ASCII characters + else if ((value >= FONT_16S_START) && (value <= FONT_16S_END)) { + //Character to write + validChar = true; + pattern = FONT_16S[value - FONT_16S_START]; + } // else +#else + //display only digits and hex characters + else if (value == '-') { + //Character to write + validChar = true; + pattern = C16_MIN; + } + else if ((value >= (int)'0') && (value <= (int) '9')) { + //Character to write + validChar = true; + pattern = FONT_16S[value - (int) '0']; + } + else if ((value >= (int) 'A') && (value <= (int) 'F')) { + //Character to write + validChar = true; + pattern = FONT_16S[10 + value - (int) 'A']; + } + else if ((value >= (int) 'a') && (value <= (int) 'f')) { + //Character to write + validChar = true; + pattern = FONT_16S[10 + value - (int) 'a']; + } //else +#endif + if (validChar) { + //Character to write + + //Translate between _column and displaybuffer entries + //Note that the DVDR3510 has eight 14 Segment digits/grids. + //Some of these Grids also have icons that need to be preserved + //_column == 0 => Grid1 => addr = 0 + //_column == 1 => Grid2 => addr = 3 + // .... + //_column == 7 => Grid8 => addr = 21 + addr = (_column * PT6315_BYTES_PER_GRID); // 3 Bytes for every Grid; + + //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, (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)); + + //Update Cursor + _column++; + if (_column > (DVDR3510_NR_DIGITS - 1)) { + _column = 0; + } + + } // if validChar + + return value; +} + +// get a single character (Stream implementation) +int PT6315_DVDR3510::_getc() { + return -1; +} +#endif
diff -r 000000000000 -r d93c23711ca8 PT6315.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PT6315.h Wed Jan 20 19:24:17 2016 +0000 @@ -0,0 +1,394 @@ +/* mbed PT6315 Library, for Princeton PT6315 VFD controller + * Copyright (c) 2016, v01: WH, Initial version for DVDR3510 + * + * 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 PT6315_H +#define PT6315_H + +// Select one of the testboards for Princeton PT6315 VFD controller +#include "PT6315_Config.h" + +/** An interface for driving Princeton PT6315 VFD controller + * + * @code + * + * #if (PT6315_TEST == 1) + * // Direct driving of PT6315 Test + * + * #include "mbed.h" + * #include "PT6315.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) + * PT6315::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 + * PT6315::KeyData_t keydata; + * + * // PT6315 declaration, Default setting 16 Grids @ 12 Segments + * PT6315 PT6315(p5,p6,p7, p8); + * + * int main() { + * PT6315.cls(); + * PT6315.writeData(all_str); + * wait(4); + * PT6315.setBrightness(PT6315_BRT0); + * wait(1); + * PT6315.setBrightness(PT6315_BRT3); + * + * while (1) { + * // Check and read keydata + * if (PT6315.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 + * PT6315.cls(); + * wait(1); + * PT6315.writeData(all_str); + * } + * } + * } + * } + * #endif + * + * @endcode + */ + +//PT6315 Display and Keymatrix data +#define PT6315_MAX_NR_GRIDS 12 +#define PT6315_BYTES_PER_GRID 3 +//Significant bits Keymatrix data +#define PT6315_KEY_MSK 0xFF + +//Memory size in bytes for Display and Keymatrix +#define PT6315_DISPLAY_MEM (PT6315_MAX_NR_GRIDS * PT6315_BYTES_PER_GRID) +#define PT6315_KEY_MEM 4 + +//Reserved bits for commands +#define PT6315_CMD_MSK 0xC0 + +//Mode setting command +#define PT6315_MODE_SET_CMD 0x00 +#define PT6315_GR4_SEG24 0x00 +#define PT6315_GR5_SEG23 0x01 +#define PT6315_GR6_SEG22 0x02 +#define PT6315_GR7_SEG21 0x03 +#define PT6315_GR8_SEG20 0x04 +#define PT6315_GR9_SEG19 0x05 +#define PT6315_GR10_SEG18 0x06 +#define PT6315_GR11_SEG17 0x07 +#define PT6315_GR12_SEG16 0x08 //default + +//Data setting commands +#define PT6315_DATA_SET_CMD 0x40 +#define PT6315_DATA_WR 0x00 +#define PT6315_LED_WR 0x01 +#define PT6315_KEY_RD 0x02 +#define PT6315_SW_RD 0x03 +#define PT6315_ADDR_INC 0x00 +#define PT6315_ADDR_FIXED 0x04 +#define PT6315_MODE_NORM 0x00 +#define PT6315_MODE_TEST 0x08 + +//LED settings data +#define PT6315_LED_MSK 0x0F +#define PT6315_LED1 0x01 +#define PT6315_LED2 0x02 +#define PT6315_LED3 0x04 +#define PT6315_LED4 0x08 + +//Address setting commands +#define PT6315_ADDR_SET_CMD 0xC0 +#define PT6315_ADDR_MSK 0x3F + +//Display control commands +#define PT6315_DSP_CTRL_CMD 0x80 +#define PT6315_BRT_MSK 0x07 +#define PT6315_BRT0 0x00 //Pulsewidth 1/16, Default +#define PT6315_BRT1 0x01 +#define PT6315_BRT2 0x02 +#define PT6315_BRT3 0x03 +#define PT6315_BRT4 0x04 +#define PT6315_BRT5 0x05 +#define PT6315_BRT6 0x06 +#define PT6315_BRT7 0x07 //Pulsewidth 14/16 + +#define PT6315_BRT_DEF PT6315_BRT3 + +#define PT6315_DSP_OFF 0x00 //Default +#define PT6315_DSP_ON 0x08 + + +/** A class for driving Princeton PT6315 VFD controller + * + * @brief Supports 8 Grids of 20 Segments upto 16 Grids of 12 Segments. Also supports a scanned keyboard of upto 48 keys, 4 switches and 5 LEDs. + * SPI bus interface device. + */ +class PT6315 { + public: + + /** Enums for display mode */ + enum Mode { + Grid4_Seg24 = PT6315_GR4_SEG24, + Grid5_Seg23 = PT6315_GR5_SEG23, + Grid6_Seg22 = PT6315_GR6_SEG22, + Grid7_Seg21 = PT6315_GR7_SEG21, + Grid8_Seg20 = PT6315_GR8_SEG20, + Grid9_Seg19 = PT6315_GR9_SEG19, + Grid10_Seg18 = PT6315_GR10_SEG18, + Grid11_Seg17 = PT6315_GR11_SEG17, + Grid12_Seg16 = PT6315_GR12_SEG16 + }; + + /** Datatypes for display and keymatrix data */ + typedef char DisplayData_t[PT6315_DISPLAY_MEM]; + typedef char KeyData_t[PT6315_KEY_MEM]; + + /** Constructor for class for driving Princeton PT6315 VFD controller + * + * @brief Supports 4 Grids of 24 Segments upto 12 Grids of 16 Segments. Also supports a scanned keyboard of upto 32 keys and 4 LEDs. + * SPI bus interface device. + * @param PinName mosi, miso, sclk, cs SPI bus pins + * @param Mode selects either number of Grids and Segments (default 12 Grids, 16 Segments) + */ + PT6315(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode=Grid12_Seg16); + + /** Clear the screen and locate to 0 + */ + void cls(); + + /** Write databyte to PT6315 + * @param int address display memory location to write byte + * @param char data byte written at given address + * @return none + */ + void writeData(int address, char data); + + /** Write Display datablock to PT6315 + * @param DisplayData_t data Array of PT6315_DISPLAY_MEM (=36) bytes for displaydata (starting at address 0) + * @param length number bytes to write (valid range 0..PT6315_DISPLAY_MEM (=36), starting at address 0) + * @return none + */ + void writeData(DisplayData_t data, int length = PT6315_DISPLAY_MEM); + + + /** Read keydata block from PT6315 + * @param *keydata Ptr to Array of PT6315_KEY_MEM (=4) bytes for keydata + * @return bool keypress True when at least one key was pressed + * + * Note: Due to the hardware configuration the PT6315 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); + + + /** Set LEDs + * + * @param char leds (4 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 = PT6315_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 PT6315 expects LSB first, whereas SPI is MSB first + * @param char data + * @return bitreversed data + */ + char _flip(char data); + + /** Write command and parameter to PT6315 + * @param int cmd Command byte + * &Param int data Parameters for command + * @return none + */ + void _writeCmd(int cmd, int data); +}; + + + +#if (DVDR3510_TEST == 1) +// Derived class for DVDR3510 front display unit +// Grids 2-11 all display 14-Segment digits and several Icons. +// Grid 1 and 12 display Icons. + +// +#include "Font_16Seg.h" + +//DVDR3510 Display data +#define DVDR3510_NR_GRIDS 11 +#define DVDR3510_NR_DIGITS 8 +#define DVDR3510_NR_UDC 8 + +//DVDR3510 Memory size in bytes for Display +#define DVDR3510_DISPLAY_MEM (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID) + + +/** Constructor for class for driving Princeton PT6315 VFD controller as used in DVDR3510 + * + * @brief Supports 11 Grids of 17 Segments and Icons (8 digits of 14 segments plus some icons). + * Also supports a scanned keyboard of 11 keys and 1 LED. + * + * @param PinName mosi, miso, sclk, cs SPI bus pins + */ +class PT6315_DVDR3510 : public PT6315, public Stream { + public: + + /** Enums for Icons */ + // Grid encoded in 8 MSBs, Icon pattern encoded in 24 LSBs + enum Icon { + RCV = (1<<24) | S16_RCV, + SAT = (8<<24) | S16_SAT, + DRT = (9<<24) | S16_DRT, + TV = (9<<24) | S16_TV, + COL4 = (10<<24) | S16_COL4, + TMR = (10<<24) | S16_TMR, + COL6 = (11<<24) | S16_COL6, + DP6 = (11<<24) | S16_DP6, + PRS = (11<<24) | S16_PRS + }; + + typedef short UDCData_t[DVDR3510_NR_UDC]; + + +/** Constructor for class for driving Princeton PT6315 VFD controller as used in DVDR3510 + * + * @brief Supports 8 Grids of 16 Segments and Icons (8 digits of 14 Segments plus some icons). + * Also supports a scanned keyboard of 11 keys and 1 LED. + * + * @param PinName mosi, miso, sclk, cs SPI bus pins + */ + PT6315_DVDR3510(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 PT6315 + * @param int address display memory location to write byte + * @param char data byte written at given address + * @return none + */ + void writeData(int address, char data){ + PT6315::writeData(address, data); + } + + /** Write Display datablock to PT6315 + * @param DisplayData_t data Array of PT6315_DISPLAY_MEM (=36) bytes for displaydata (starting at address 0) + * @param length number bytes to write (valid range 0..(DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID) == 24, starting at address 0) + * @return none + */ + void writeData(DisplayData_t data, int length = (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)) { + PT6315::writeData(data, length); + } + +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
diff -r 000000000000 -r d93c23711ca8 PT6315_Config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PT6315_Config.h Wed Jan 20 19:24:17 2016 +0000 @@ -0,0 +1,33 @@ +/* mbed PT6315 Library, for Princeton PT6315 VFD controller + * Copyright (c) 2016, v01: WH, Initial version, DVDR3510 + * + * 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 PT6315_CONFIG_H +#define PT6315_CONFIG_H + +// Select one of the testboards for Princeton PT6315 VFD controller +#define PT6315_TEST 0 +#define DVDR3510_TEST 1 + +// Select the display mode: only digits and hex or ASCII +#define SHOW_ASCII 1 + +#endif \ No newline at end of file