Library for the Princeton PT6312 Vacuum Fluorescent Display (VFD) driver.

Dependents:   mbed_PT6312

This library is documented here.

Committer:
wim
Date:
Tue Aug 25 20:38:30 2015 +0000
Revision:
1:c5e247159aa6
Parent:
0:e59142cded2b
Child:
2:f010b7022803
First lib version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:e59142cded2b 1 /* mbed PT6312 Library, for Princeton PT6312 VFD controller
wim 0:e59142cded2b 2 * Copyright (c) 2015, v01: WH, Initial version
wim 0:e59142cded2b 3 *
wim 0:e59142cded2b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:e59142cded2b 5 * of this software and associated documentation files (the "Software"), to deal
wim 0:e59142cded2b 6 * in the Software without restriction, including without limitation the rights
wim 0:e59142cded2b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:e59142cded2b 8 * copies of the Software, and to permit persons to whom the Software is
wim 0:e59142cded2b 9 * furnished to do so, subject to the following conditions:
wim 0:e59142cded2b 10 *
wim 0:e59142cded2b 11 * The above copyright notice and this permission notice shall be included in
wim 0:e59142cded2b 12 * all copies or substantial portions of the Software.
wim 0:e59142cded2b 13 *
wim 0:e59142cded2b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:e59142cded2b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:e59142cded2b 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:e59142cded2b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:e59142cded2b 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:e59142cded2b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:e59142cded2b 20 * THE SOFTWARE.
wim 0:e59142cded2b 21 */
wim 0:e59142cded2b 22
wim 0:e59142cded2b 23 #ifndef PT6312_H
wim 0:e59142cded2b 24 #define PT6312_H
wim 0:e59142cded2b 25
wim 0:e59142cded2b 26 /** An interface for driving Princeton PT6312 VFD controller
wim 0:e59142cded2b 27 *
wim 0:e59142cded2b 28 * @code
wim 0:e59142cded2b 29 * #include "mbed.h"
wim 0:e59142cded2b 30 *
wim 0:e59142cded2b 31 * DisplayData_t size is 8 bytes (4 digits max 16 segments) ... 22 bytes (11 digits at max 11 segments)
wim 0:e59142cded2b 32 * DisplayData_t size default is 14 bytes (7 digits max 15 segments)
wim 0:e59142cded2b 33 * PT6312::DisplayData_t mbed_str = {0xDA,0x00, 0x7C,0x00, 0x3C,0x01, 0xF6,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};
wim 0:e59142cded2b 34 * PT6312::DisplayData_t all_str = {0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F};
wim 0:e59142cded2b 35 *
wim 0:e59142cded2b 36 * // KeyData_t size is 3 bytes
wim 0:e59142cded2b 37 * PT6312::KeyData_t keydata;
wim 0:e59142cded2b 38 *
wim 0:e59142cded2b 39 * // PT6191 declaration, Default setting x Digits, y Segments
wim 0:e59142cded2b 40 * PT6312 PT6312(p5,p6,p7, p8);
wim 0:e59142cded2b 41 *
wim 0:e59142cded2b 42 * int main() {
wim 0:e59142cded2b 43 * PT6312.cls();
wim 0:e59142cded2b 44 * PT6312.writeData(all_str);
wim 0:e59142cded2b 45 * wait(4);
wim 0:e59142cded2b 46 * PT6312.writeData(mbed_str);
wim 0:e59142cded2b 47 * wait(1);
wim 0:e59142cded2b 48 * PT6312.setBrightness(PT6312_BRT0);
wim 0:e59142cded2b 49 * wait(1);
wim 0:e59142cded2b 50 * PT6312.setBrightness(PT6312_BRT3);
wim 0:e59142cded2b 51 *
wim 0:e59142cded2b 52 * while (1) {
wim 0:e59142cded2b 53 * // Check and read keydata
wim 1:c5e247159aa6 54 * if (PT6312.getKeys(&keydata)) {
wim 0:e59142cded2b 55 * pc.printf("Keydata 0..2 = 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2]);
wim 0:e59142cded2b 56 *
wim 0:e59142cded2b 57 * if (keydata[0] == 0x10) { //sw2
wim 0:e59142cded2b 58 * PT6312.cls();
wim 0:e59142cded2b 59 * PT6312.writeData(all_str);
wim 0:e59142cded2b 60 * }
wim 0:e59142cded2b 61 * }
wim 0:e59142cded2b 62 * }
wim 0:e59142cded2b 63 * }
wim 0:e59142cded2b 64 * @endcode
wim 0:e59142cded2b 65 */
wim 0:e59142cded2b 66
wim 0:e59142cded2b 67 //Memory size in bytes for Display and Keymatrix
wim 0:e59142cded2b 68 #define PT6312_DISPLAY_MEM 22
wim 0:e59142cded2b 69 #define PT6312_KEY_MEM 3
wim 0:e59142cded2b 70 //Significant bits Keymatrix data
wim 0:e59142cded2b 71 #define PT6312_KEY_BITS 8
wim 0:e59142cded2b 72
wim 0:e59142cded2b 73 //Reserved bits for commands
wim 0:e59142cded2b 74 #define PT6312_CMD_MSK 0xE0
wim 0:e59142cded2b 75
wim 0:e59142cded2b 76 //Mode setting command
wim 0:e59142cded2b 77 #define PT6312_MODE_SET_CMD 0x00
wim 0:e59142cded2b 78 #define PT6312_DIG4_SEG16 0x00
wim 0:e59142cded2b 79 #define PT6312_DIG5_SEG16 0x01
wim 0:e59142cded2b 80 #define PT6312_DIG6_SEG16 0x02
wim 0:e59142cded2b 81 #define PT6312_DIG7_SEG15 0x03 //default
wim 0:e59142cded2b 82 #define PT6312_DIG8_SEG14 0x04
wim 0:e59142cded2b 83 #define PT6312_DIG9_SEG13 0x05
wim 0:e59142cded2b 84 #define PT6312_DIG10_SEG12 0x06
wim 0:e59142cded2b 85 #define PT6312_DIG11_SEG11 0x07
wim 0:e59142cded2b 86
wim 0:e59142cded2b 87
wim 0:e59142cded2b 88 //Data setting commands
wim 0:e59142cded2b 89 #define PT6312_DATA_SET_CMD 0x40
wim 0:e59142cded2b 90 #define PT6312_DATA_WR 0x00
wim 0:e59142cded2b 91 #define PT6312_LED_WR 0x01
wim 0:e59142cded2b 92 #define PT6312_KEY_RD 0x02
wim 0:e59142cded2b 93 #define PT6312_SW_RD 0x03
wim 0:e59142cded2b 94 #define PT6312_ADDR_INC 0x00
wim 0:e59142cded2b 95 #define PT6312_ADDR_FIXED 0x04
wim 0:e59142cded2b 96 #define PT6312_MODE_NORM 0x00
wim 0:e59142cded2b 97 #define PT6312_MODE_TEST 0x08
wim 0:e59142cded2b 98
wim 0:e59142cded2b 99 //LED settings data
wim 0:e59142cded2b 100 #define PT6312_LED_MSK 0x0F
wim 0:e59142cded2b 101 #define PT6312_LED1 0x01
wim 0:e59142cded2b 102 #define PT6312_LED2 0x02
wim 0:e59142cded2b 103 #define PT6312_LED3 0x04
wim 0:e59142cded2b 104 #define PT6312_LED4 0x08
wim 0:e59142cded2b 105
wim 0:e59142cded2b 106 //Switch settings data
wim 0:e59142cded2b 107 #define PT6312_SW_MSK 0x0F
wim 0:e59142cded2b 108 #define PT6312_SW1 0x01
wim 0:e59142cded2b 109 #define PT6312_SW2 0x02
wim 0:e59142cded2b 110 #define PT6312_SW3 0x04
wim 0:e59142cded2b 111 #define PT6312_SW4 0x08
wim 0:e59142cded2b 112
wim 0:e59142cded2b 113 //Address setting commands
wim 0:e59142cded2b 114 #define PT6312_ADDR_SET_CMD 0xC0
wim 0:e59142cded2b 115 #define PT6312_ADDR_MSK 0x1F
wim 0:e59142cded2b 116
wim 0:e59142cded2b 117 //Display control commands
wim 0:e59142cded2b 118 #define PT6312_DSP_CTRL_CMD 0x80
wim 0:e59142cded2b 119 #define PT6312_BRT_MSK 0x07
wim 0:e59142cded2b 120 #define PT6312_BRT0 0x00 //Pulsewidth 1/16
wim 0:e59142cded2b 121 #define PT6312_BRT1 0x01
wim 0:e59142cded2b 122 #define PT6312_BRT2 0x02
wim 0:e59142cded2b 123 #define PT6312_BRT3 0x03
wim 0:e59142cded2b 124 #define PT6312_BRT4 0x04
wim 0:e59142cded2b 125 #define PT6312_BRT5 0x05
wim 0:e59142cded2b 126 #define PT6312_BRT6 0x06
wim 0:e59142cded2b 127 #define PT6312_BRT7 0x07 //Pulsewidth 14/16
wim 0:e59142cded2b 128
wim 0:e59142cded2b 129 #define PT6312_BRT_DEF PT6312_BRT3
wim 0:e59142cded2b 130
wim 0:e59142cded2b 131 #define PT6312_DSP_OFF 0x00
wim 0:e59142cded2b 132 #define PT6312_DSP_ON 0x08
wim 0:e59142cded2b 133
wim 0:e59142cded2b 134
wim 0:e59142cded2b 135 /** A class for driving Princeton PT6312 VFD controller
wim 0:e59142cded2b 136 *
wim 0:e59142cded2b 137 * @brief Supports 4 Digits of 16 Segments upto 11 Digits of 11 Segments. Also supports a scanned keyboard of upto 24 keys, 4 switches and 4 LEDs.
wim 0:e59142cded2b 138 * SPI bus interface device.
wim 0:e59142cded2b 139 */
wim 0:e59142cded2b 140 class PT6312 {
wim 0:e59142cded2b 141 public:
wim 0:e59142cded2b 142
wim 0:e59142cded2b 143 /** Enums for display mode */
wim 0:e59142cded2b 144 enum Mode {
wim 0:e59142cded2b 145 Dig4_Seg16 = PT6312_DIG4_SEG16,
wim 0:e59142cded2b 146 Dig5_Seg16 = PT6312_DIG5_SEG16,
wim 0:e59142cded2b 147 Dig6_Seg16 = PT6312_DIG6_SEG16,
wim 0:e59142cded2b 148 Dig7_Seg15 = PT6312_DIG7_SEG15,
wim 0:e59142cded2b 149 Dig8_Seg14 = PT6312_DIG8_SEG14,
wim 0:e59142cded2b 150 Dig9_Seg13 = PT6312_DIG9_SEG13,
wim 0:e59142cded2b 151 Dig10_Seg12 = PT6312_DIG10_SEG12,
wim 0:e59142cded2b 152 Dig11_Seg11 = PT6312_DIG11_SEG11
wim 0:e59142cded2b 153 };
wim 0:e59142cded2b 154
wim 0:e59142cded2b 155 /** Datatypes for display and keymatrix data */
wim 0:e59142cded2b 156 typedef char DisplayData_t[PT6312_DISPLAY_MEM];
wim 0:e59142cded2b 157 typedef char KeyData_t[PT6312_KEY_MEM];
wim 0:e59142cded2b 158
wim 1:c5e247159aa6 159 /** Constructor for class for driving Princeton PT6312 VFD controller
wim 0:e59142cded2b 160 *
wim 0:e59142cded2b 161 * @brief Supports 4 Digits of 16 Segments upto 11 Digits of 11 Segments. Also supports a scanned keyboard of upto 24 keys, 4 switches and 4 LEDs.
wim 0:e59142cded2b 162 * SPI bus interface device.
wim 0:e59142cded2b 163 * @param PinName mosi, miso, sclk, cs SPI bus pins
wim 0:e59142cded2b 164 * @param Mode selects either number of Digits and 12 Segments (default 7 Digits, 15 Segments)
wim 0:e59142cded2b 165 */
wim 0:e59142cded2b 166 PT6312(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode=Dig7_Seg15);
wim 0:e59142cded2b 167
wim 0:e59142cded2b 168 /** Clear the screen and locate to 0
wim 0:e59142cded2b 169 */
wim 0:e59142cded2b 170 void cls();
wim 0:e59142cded2b 171
wim 0:e59142cded2b 172 /** Write databyte to PT6312
wim 0:e59142cded2b 173 * @param int address display memory location to write byte
wim 0:e59142cded2b 174 * @param char data byte written at given address
wim 0:e59142cded2b 175 * @return none
wim 0:e59142cded2b 176 */
wim 0:e59142cded2b 177 void writeData(int address, char data);
wim 0:e59142cded2b 178
wim 0:e59142cded2b 179 /** Write Display datablock to PT6312
wim 0:e59142cded2b 180 * @param DisplayData_t data Array of PT6312_DISPLAY_MEM (=16) bytes for displaydata (starting at address 0)
wim 0:e59142cded2b 181 * @return none
wim 0:e59142cded2b 182 */
wim 0:e59142cded2b 183 void writeData(DisplayData_t data);
wim 0:e59142cded2b 184
wim 0:e59142cded2b 185
wim 0:e59142cded2b 186 /** Read keydata block from PT6312
wim 0:e59142cded2b 187 * @param *keydata Ptr to Array of PT6312_KEY_MEM (=3) bytes for keydata
wim 0:e59142cded2b 188 * @return bool keypress True when at least one key was pressed
wim 0:e59142cded2b 189 *
wim 0:e59142cded2b 190 * Note: Due to the hardware configuration the PT6312 key matrix scanner will detect multiple keys pressed at same time,
wim 0:e59142cded2b 191 * but this may result in some spurious keys also being set in keypress data array.
wim 0:e59142cded2b 192 * It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting.
wim 0:e59142cded2b 193 */
wim 1:c5e247159aa6 194 bool getKeys(KeyData_t *keydata);
wim 0:e59142cded2b 195
wim 0:e59142cded2b 196
wim 0:e59142cded2b 197 /** Read switches from PT6312
wim 0:e59142cded2b 198 *
wim 0:e59142cded2b 199 * @param none
wim 0:e59142cded2b 200 * @return char for switch data (4 least significant bits)
wim 0:e59142cded2b 201 *
wim 0:e59142cded2b 202 */
wim 1:c5e247159aa6 203 char getSwitches();
wim 0:e59142cded2b 204
wim 0:e59142cded2b 205 /** Set LEDs
wim 0:e59142cded2b 206 *
wim 0:e59142cded2b 207 * @param char leds (4 least significant bits)
wim 0:e59142cded2b 208 * @return none
wim 0:e59142cded2b 209 */
wim 0:e59142cded2b 210 void setLED (char leds = 0);
wim 0:e59142cded2b 211
wim 0:e59142cded2b 212 /** Set Brightness
wim 0:e59142cded2b 213 *
wim 0:e59142cded2b 214 * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)
wim 0:e59142cded2b 215 * @return none
wim 0:e59142cded2b 216 */
wim 0:e59142cded2b 217 void setBrightness(char brightness = PT6312_BRT_DEF);
wim 0:e59142cded2b 218
wim 0:e59142cded2b 219 /** Set the Display mode On/off
wim 0:e59142cded2b 220 *
wim 0:e59142cded2b 221 * @param bool display mode
wim 0:e59142cded2b 222 */
wim 0:e59142cded2b 223 void setDisplay(bool on);
wim 0:e59142cded2b 224
wim 0:e59142cded2b 225 private:
wim 0:e59142cded2b 226 SPI _spi;
wim 0:e59142cded2b 227 DigitalOut _cs;
wim 0:e59142cded2b 228 Mode _mode;
wim 0:e59142cded2b 229 char _display;
wim 0:e59142cded2b 230 char _bright;
wim 0:e59142cded2b 231
wim 0:e59142cded2b 232 /** Init the SPI interface and the controller
wim 0:e59142cded2b 233 * @param none
wim 0:e59142cded2b 234 * @return none
wim 0:e59142cded2b 235 */
wim 0:e59142cded2b 236 void _init();
wim 0:e59142cded2b 237
wim 0:e59142cded2b 238 /** Helper to reverse all command or databits. The PT6312 expects LSB first, whereas SPI is MSB first
wim 0:e59142cded2b 239 * @param char data
wim 0:e59142cded2b 240 * @return bitreversed data
wim 0:e59142cded2b 241 */
wim 0:e59142cded2b 242 char _flip(char data);
wim 0:e59142cded2b 243
wim 0:e59142cded2b 244 /** Write command and parameter to PT6312
wim 0:e59142cded2b 245 * @param int cmd Command byte
wim 0:e59142cded2b 246 * &Param int data Parameters for command
wim 0:e59142cded2b 247 * @return none
wim 0:e59142cded2b 248 */
wim 0:e59142cded2b 249 void _writeCmd(int cmd, int data);
wim 0:e59142cded2b 250 };
wim 0:e59142cded2b 251
wim 1:c5e247159aa6 252
wim 1:c5e247159aa6 253
wim 1:c5e247159aa6 254 /** Constructor for class for driving Princeton PT6312 VFD controller as used in Philips DVD625
wim 1:c5e247159aa6 255 *
wim 1:c5e247159aa6 256 * @brief Supports 7 Digits of 15 Segments. Also supports a scanned keyboard of 3 keys, 3 switches and 1 LED.
wim 1:c5e247159aa6 257 * SPI bus interface device.
wim 1:c5e247159aa6 258 * @param PinName mosi, miso, sclk, cs SPI bus pins
wim 1:c5e247159aa6 259 */
wim 1:c5e247159aa6 260 class PT6312_DVD625 : public PT6312, public Stream {
wim 1:c5e247159aa6 261 public:
wim 1:c5e247159aa6 262
wim 1:c5e247159aa6 263 /** Constructor for class for driving Princeton PT6312 VFD controller as used in Philips DVD625
wim 1:c5e247159aa6 264 *
wim 1:c5e247159aa6 265 * @brief Supports 7 Digits of 15 Segments. Also supports a scanned keyboard of 3 keys, 3 switches and 1 LED.
wim 1:c5e247159aa6 266 * SPI bus interface device.
wim 1:c5e247159aa6 267 * @param PinName mosi, miso, sclk, cs SPI bus pins
wim 1:c5e247159aa6 268 */
wim 1:c5e247159aa6 269 PT6312_DVD625(PinName mosi, PinName miso, PinName sclk, PinName cs);
wim 1:c5e247159aa6 270
wim 1:c5e247159aa6 271 #if DOXYGEN_ONLY
wim 1:c5e247159aa6 272 /** Write a character to the LCD
wim 1:c5e247159aa6 273 *
wim 1:c5e247159aa6 274 * @param c The character to write to the display
wim 1:c5e247159aa6 275 */
wim 1:c5e247159aa6 276 int putc(int c);
wim 1:c5e247159aa6 277
wim 1:c5e247159aa6 278 /** Write a formatted string to the LCD
wim 1:c5e247159aa6 279 *
wim 1:c5e247159aa6 280 * @param format A printf-style format string, followed by the
wim 1:c5e247159aa6 281 * variables to use in formatting the string.
wim 1:c5e247159aa6 282 */
wim 1:c5e247159aa6 283 int printf(const char* format, ...);
wim 1:c5e247159aa6 284 #endif
wim 1:c5e247159aa6 285
wim 1:c5e247159aa6 286 /** Locate cursor to a screen column
wim 1:c5e247159aa6 287 *
wim 1:c5e247159aa6 288 * @param column The horizontal position from the left, indexed from 0
wim 1:c5e247159aa6 289 */
wim 1:c5e247159aa6 290 void locate(int column);
wim 1:c5e247159aa6 291
wim 1:c5e247159aa6 292 /** Clear the screen and locate to 0
wim 1:c5e247159aa6 293 */
wim 1:c5e247159aa6 294 void cls();
wim 1:c5e247159aa6 295
wim 1:c5e247159aa6 296 /** Number of screen columns
wim 1:c5e247159aa6 297 *
wim 1:c5e247159aa6 298 * @param none
wim 1:c5e247159aa6 299 * @return columns
wim 1:c5e247159aa6 300 */
wim 1:c5e247159aa6 301 int columns();
wim 1:c5e247159aa6 302
wim 1:c5e247159aa6 303 protected:
wim 1:c5e247159aa6 304 // Stream implementation functions
wim 1:c5e247159aa6 305 virtual int _putc(int value);
wim 1:c5e247159aa6 306 virtual int _getc();
wim 1:c5e247159aa6 307
wim 1:c5e247159aa6 308 private:
wim 1:c5e247159aa6 309 int _column;
wim 1:c5e247159aa6 310 int _columns;
wim 1:c5e247159aa6 311 };
wim 1:c5e247159aa6 312
wim 0:e59142cded2b 313 #endif