Library for the Princeton PT6312 Vacuum Fluorescent Display (VFD) driver.
This library is documented here.
PT6312.cpp@5:be9ec73af639, 2015-12-20 (annotated)
- Committer:
- wim
- Date:
- Sun Dec 20 14:41:58 2015 +0000
- Revision:
- 5:be9ec73af639
- Parent:
- 3:156c23d9652a
- Child:
- 6:d3dc313a6840
Added Tests and Fonts for 7Segment displays of DVD462 and C2233.
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:be9ec73af639 | 3 | * 2015, v02: WH, rename Digit/Grid, added DVD462 code, added C2233 code |
wim | 0:e59142cded2b | 4 | * |
wim | 0:e59142cded2b | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:e59142cded2b | 6 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:e59142cded2b | 7 | * in the Software without restriction, including without limitation the rights |
wim | 0:e59142cded2b | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:e59142cded2b | 9 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:e59142cded2b | 10 | * furnished to do so, subject to the following conditions: |
wim | 0:e59142cded2b | 11 | * |
wim | 0:e59142cded2b | 12 | * The above copyright notice and this permission notice shall be included in |
wim | 0:e59142cded2b | 13 | * all copies or substantial portions of the Software. |
wim | 0:e59142cded2b | 14 | * |
wim | 0:e59142cded2b | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:e59142cded2b | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:e59142cded2b | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:e59142cded2b | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:e59142cded2b | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:e59142cded2b | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:e59142cded2b | 21 | * THE SOFTWARE. |
wim | 0:e59142cded2b | 22 | */ |
wim | 0:e59142cded2b | 23 | #include "mbed.h" |
wim | 0:e59142cded2b | 24 | #include "PT6312.h" |
wim | 0:e59142cded2b | 25 | |
wim | 0:e59142cded2b | 26 | /** Constructor for class for driving Princeton PT6312 VFD controller |
wim | 0:e59142cded2b | 27 | * |
wim | 5:be9ec73af639 | 28 | * @brief Supports 4 Grids of 16 Segments upto 10 Grids of 12 Segments. Also supports a scanned keyboard of upto 24 keys, 4 switches and 4 LEDs. |
wim | 0:e59142cded2b | 29 | * SPI bus interface device. |
wim | 0:e59142cded2b | 30 | * |
wim | 0:e59142cded2b | 31 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:e59142cded2b | 32 | * @param Mode selects either number of Digits and Segments |
wim | 0:e59142cded2b | 33 | */ |
wim | 0:e59142cded2b | 34 | PT6312::PT6312(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode) : _spi(mosi,miso,sclk), _cs(cs), _mode(mode) { |
wim | 0:e59142cded2b | 35 | |
wim | 0:e59142cded2b | 36 | _init(); |
wim | 0:e59142cded2b | 37 | } |
wim | 0:e59142cded2b | 38 | |
wim | 0:e59142cded2b | 39 | /** Init the SPI interface and the controller |
wim | 0:e59142cded2b | 40 | * @param none |
wim | 0:e59142cded2b | 41 | * @return none |
wim | 0:e59142cded2b | 42 | */ |
wim | 0:e59142cded2b | 43 | void PT6312::_init(){ |
wim | 0:e59142cded2b | 44 | |
wim | 0:e59142cded2b | 45 | //init SPI |
wim | 0:e59142cded2b | 46 | _cs=1; |
wim | 0:e59142cded2b | 47 | _spi.format(8,3); //PT6312 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge) |
wim | 1:c5e247159aa6 | 48 | // _spi.frequency(100000); |
wim | 1:c5e247159aa6 | 49 | _spi.frequency(500000); |
wim | 0:e59142cded2b | 50 | |
wim | 0:e59142cded2b | 51 | //init controller |
wim | 0:e59142cded2b | 52 | _writeCmd(PT6312_MODE_SET_CMD, _mode); // Mode set command |
wim | 0:e59142cded2b | 53 | |
wim | 0:e59142cded2b | 54 | _display = PT6312_DSP_ON; |
wim | 0:e59142cded2b | 55 | _bright = PT6312_BRT_DEF; |
wim | 0:e59142cded2b | 56 | _writeCmd(PT6312_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:e59142cded2b | 57 | |
wim | 0:e59142cded2b | 58 | _writeCmd(PT6312_DATA_SET_CMD, PT6312_DATA_WR | PT6312_ADDR_INC | PT6312_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e59142cded2b | 59 | } |
wim | 0:e59142cded2b | 60 | |
wim | 0:e59142cded2b | 61 | |
wim | 0:e59142cded2b | 62 | /** Clear the screen and locate to 0 |
wim | 0:e59142cded2b | 63 | */ |
wim | 0:e59142cded2b | 64 | void PT6312::cls() { |
wim | 0:e59142cded2b | 65 | |
wim | 0:e59142cded2b | 66 | _cs=0; |
wim | 0:e59142cded2b | 67 | wait_us(1); |
wim | 0:e59142cded2b | 68 | _spi.write(_flip(PT6312_ADDR_SET_CMD | 0x00)); // Address set cmd, 0 |
wim | 0:e59142cded2b | 69 | |
wim | 0:e59142cded2b | 70 | for (int cnt=0; cnt<PT6312_DISPLAY_MEM; cnt++) { |
wim | 0:e59142cded2b | 71 | _spi.write(0x00); // data |
wim | 0:e59142cded2b | 72 | } |
wim | 0:e59142cded2b | 73 | |
wim | 0:e59142cded2b | 74 | wait_us(1); |
wim | 0:e59142cded2b | 75 | _cs=1; |
wim | 0:e59142cded2b | 76 | |
wim | 0:e59142cded2b | 77 | } |
wim | 0:e59142cded2b | 78 | |
wim | 0:e59142cded2b | 79 | /** Set Brightness |
wim | 0:e59142cded2b | 80 | * |
wim | 0:e59142cded2b | 81 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle) |
wim | 0:e59142cded2b | 82 | * @return none |
wim | 0:e59142cded2b | 83 | */ |
wim | 0:e59142cded2b | 84 | void PT6312::setBrightness(char brightness){ |
wim | 0:e59142cded2b | 85 | |
wim | 0:e59142cded2b | 86 | _bright = brightness & PT6312_BRT_MSK; // mask invalid bits |
wim | 0:e59142cded2b | 87 | |
wim | 0:e59142cded2b | 88 | _writeCmd(PT6312_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:e59142cded2b | 89 | |
wim | 0:e59142cded2b | 90 | } |
wim | 0:e59142cded2b | 91 | |
wim | 0:e59142cded2b | 92 | /** Set the Display mode On/off |
wim | 0:e59142cded2b | 93 | * |
wim | 0:e59142cded2b | 94 | * @param bool display mode |
wim | 0:e59142cded2b | 95 | */ |
wim | 0:e59142cded2b | 96 | void PT6312::setDisplay(bool on) { |
wim | 0:e59142cded2b | 97 | |
wim | 0:e59142cded2b | 98 | if (on) { |
wim | 0:e59142cded2b | 99 | _display = PT6312_DSP_ON; |
wim | 0:e59142cded2b | 100 | } |
wim | 0:e59142cded2b | 101 | else { |
wim | 0:e59142cded2b | 102 | _display = PT6312_DSP_OFF; |
wim | 0:e59142cded2b | 103 | } |
wim | 0:e59142cded2b | 104 | |
wim | 0:e59142cded2b | 105 | _writeCmd(PT6312_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:e59142cded2b | 106 | } |
wim | 0:e59142cded2b | 107 | |
wim | 0:e59142cded2b | 108 | /** Write databyte to PT6312 |
wim | 0:e59142cded2b | 109 | * @param int address display memory location to write byte |
wim | 0:e59142cded2b | 110 | * @param char data byte written at given address |
wim | 0:e59142cded2b | 111 | * @return none |
wim | 0:e59142cded2b | 112 | */ |
wim | 0:e59142cded2b | 113 | void PT6312::writeData(int address, char data) { |
wim | 0:e59142cded2b | 114 | _cs=0; |
wim | 0:e59142cded2b | 115 | wait_us(1); |
wim | 0:e59142cded2b | 116 | _spi.write(_flip(PT6312_ADDR_SET_CMD | (address & PT6312_ADDR_MSK))); // Set Address cmd |
wim | 0:e59142cded2b | 117 | |
wim | 0:e59142cded2b | 118 | _spi.write(_flip(data)); // data |
wim | 0:e59142cded2b | 119 | |
wim | 0:e59142cded2b | 120 | wait_us(1); |
wim | 0:e59142cded2b | 121 | _cs=1; |
wim | 0:e59142cded2b | 122 | |
wim | 0:e59142cded2b | 123 | } |
wim | 0:e59142cded2b | 124 | |
wim | 0:e59142cded2b | 125 | /** Write Display datablock to PT6312 |
wim | 3:156c23d9652a | 126 | * @param DisplayData_t data Array of PT6312_DISPLAY_MEM (=22) bytes for displaydata (starting at address 0) |
wim | 3:156c23d9652a | 127 | * @param length number bytes to write (valid range 0..PT6312_DISPLAY_MEM (=22), starting at address 0) |
wim | 0:e59142cded2b | 128 | * @return none |
wim | 0:e59142cded2b | 129 | */ |
wim | 2:f010b7022803 | 130 | void PT6312::writeData(DisplayData_t data, int length) { |
wim | 0:e59142cded2b | 131 | _cs=0; |
wim | 0:e59142cded2b | 132 | wait_us(1); |
wim | 0:e59142cded2b | 133 | _spi.write(_flip(PT6312_ADDR_SET_CMD | 0x00)); // Set Address at 0 |
wim | 0:e59142cded2b | 134 | |
wim | 2:f010b7022803 | 135 | // sanity check |
wim | 2:f010b7022803 | 136 | if (length < 0) {length = 0;} |
wim | 2:f010b7022803 | 137 | if (length > PT6312_DISPLAY_MEM) {length = PT6312_DISPLAY_MEM;} |
wim | 2:f010b7022803 | 138 | |
wim | 2:f010b7022803 | 139 | // for (int idx=0; idx<PT6312_DISPLAY_MEM; idx++) { |
wim | 2:f010b7022803 | 140 | for (int idx=0; idx<length; idx++) { |
wim | 0:e59142cded2b | 141 | _spi.write(_flip(data[idx])); // data |
wim | 0:e59142cded2b | 142 | } |
wim | 0:e59142cded2b | 143 | |
wim | 0:e59142cded2b | 144 | wait_us(1); |
wim | 0:e59142cded2b | 145 | _cs=1; |
wim | 0:e59142cded2b | 146 | |
wim | 0:e59142cded2b | 147 | } |
wim | 0:e59142cded2b | 148 | |
wim | 0:e59142cded2b | 149 | /** Read keydata block from PT6312 |
wim | 0:e59142cded2b | 150 | * @param *keydata Ptr to Array of PT6312_KEY_MEM (=3) bytes for keydata |
wim | 0:e59142cded2b | 151 | * @return bool keypress True when at least one key was pressed |
wim | 0:e59142cded2b | 152 | * |
wim | 0:e59142cded2b | 153 | * Note: Due to the hardware configuration the PT6312 key matrix scanner will detect multiple keys pressed at same time, |
wim | 0:e59142cded2b | 154 | * but this may also result in some spurious keys being set in keypress data array. |
wim | 0:e59142cded2b | 155 | * 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 | 156 | */ |
wim | 1:c5e247159aa6 | 157 | bool PT6312::getKeys(KeyData_t *keydata) { |
wim | 0:e59142cded2b | 158 | int keypress = 0; |
wim | 0:e59142cded2b | 159 | char data; |
wim | 0:e59142cded2b | 160 | |
wim | 0:e59142cded2b | 161 | // Read keys |
wim | 0:e59142cded2b | 162 | _cs=0; |
wim | 0:e59142cded2b | 163 | wait_us(1); |
wim | 0:e59142cded2b | 164 | |
wim | 0:e59142cded2b | 165 | // Enable Key Read mode |
wim | 0:e59142cded2b | 166 | _spi.write(_flip(PT6312_DATA_SET_CMD | PT6312_KEY_RD | PT6312_ADDR_INC | PT6312_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data |
wim | 0:e59142cded2b | 167 | |
wim | 0:e59142cded2b | 168 | for (int idx=0; idx < PT6312_KEY_MEM; idx++) { |
wim | 0:e59142cded2b | 169 | data = _flip(_spi.write(0xFF)); // read keys and correct bitorder |
wim | 0:e59142cded2b | 170 | |
wim | 0:e59142cded2b | 171 | if (data != 0) { // Check for any pressed key |
wim | 0:e59142cded2b | 172 | for (int bit=0; bit < PT6312_KEY_BITS; bit++) { |
wim | 0:e59142cded2b | 173 | if (data & (1 << bit)) {keypress++;} // Test all significant bits |
wim | 0:e59142cded2b | 174 | } |
wim | 0:e59142cded2b | 175 | } |
wim | 0:e59142cded2b | 176 | |
wim | 0:e59142cded2b | 177 | (*keydata)[idx] = data; // Store keydata after correcting bitorder |
wim | 0:e59142cded2b | 178 | } |
wim | 0:e59142cded2b | 179 | |
wim | 0:e59142cded2b | 180 | wait_us(1); |
wim | 0:e59142cded2b | 181 | _cs=1; |
wim | 0:e59142cded2b | 182 | |
wim | 0:e59142cded2b | 183 | // Restore Data Write mode |
wim | 0:e59142cded2b | 184 | _writeCmd(PT6312_DATA_SET_CMD, PT6312_DATA_WR | PT6312_ADDR_INC | PT6312_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e59142cded2b | 185 | |
wim | 0:e59142cded2b | 186 | #if(1) |
wim | 0:e59142cded2b | 187 | // Dismiss multiple keypresses at same time |
wim | 0:e59142cded2b | 188 | return (keypress == 1); |
wim | 0:e59142cded2b | 189 | #else |
wim | 0:e59142cded2b | 190 | // Allow multiple keypress and accept possible spurious keys |
wim | 0:e59142cded2b | 191 | return (keypress > 0); |
wim | 0:e59142cded2b | 192 | #endif |
wim | 0:e59142cded2b | 193 | } |
wim | 0:e59142cded2b | 194 | |
wim | 0:e59142cded2b | 195 | |
wim | 0:e59142cded2b | 196 | /** Read switches from PT6312 |
wim | 0:e59142cded2b | 197 | * |
wim | 0:e59142cded2b | 198 | * @param none |
wim | 0:e59142cded2b | 199 | * @return char for switch data (4 least significant bits) |
wim | 0:e59142cded2b | 200 | * |
wim | 0:e59142cded2b | 201 | */ |
wim | 1:c5e247159aa6 | 202 | char PT6312::getSwitches() { |
wim | 0:e59142cded2b | 203 | char data; |
wim | 0:e59142cded2b | 204 | |
wim | 0:e59142cded2b | 205 | // Read switches |
wim | 0:e59142cded2b | 206 | _cs=0; |
wim | 0:e59142cded2b | 207 | wait_us(1); |
wim | 0:e59142cded2b | 208 | |
wim | 0:e59142cded2b | 209 | // Enable Switch Read mode |
wim | 0:e59142cded2b | 210 | _spi.write(_flip(PT6312_DATA_SET_CMD | PT6312_SW_RD | PT6312_ADDR_INC | PT6312_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data |
wim | 0:e59142cded2b | 211 | |
wim | 0:e59142cded2b | 212 | data = _flip(_spi.write(0xFF)) & PT6312_SW_MSK; // read switches and correct bitorder |
wim | 0:e59142cded2b | 213 | |
wim | 0:e59142cded2b | 214 | wait_us(1); |
wim | 0:e59142cded2b | 215 | _cs=1; |
wim | 0:e59142cded2b | 216 | |
wim | 0:e59142cded2b | 217 | // Restore Data Write mode |
wim | 0:e59142cded2b | 218 | _writeCmd(PT6312_DATA_SET_CMD, PT6312_DATA_WR | PT6312_ADDR_INC | PT6312_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e59142cded2b | 219 | |
wim | 0:e59142cded2b | 220 | return data; |
wim | 0:e59142cded2b | 221 | } |
wim | 0:e59142cded2b | 222 | |
wim | 0:e59142cded2b | 223 | |
wim | 0:e59142cded2b | 224 | /** Set LEDs |
wim | 0:e59142cded2b | 225 | * |
wim | 0:e59142cded2b | 226 | * @param char leds (4 least significant bits) |
wim | 0:e59142cded2b | 227 | * @return none |
wim | 0:e59142cded2b | 228 | */ |
wim | 0:e59142cded2b | 229 | void PT6312::setLED (char leds) { |
wim | 0:e59142cded2b | 230 | |
wim | 0:e59142cded2b | 231 | // Set LEDs |
wim | 0:e59142cded2b | 232 | _cs=0; |
wim | 0:e59142cded2b | 233 | wait_us(1); |
wim | 0:e59142cded2b | 234 | |
wim | 0:e59142cded2b | 235 | // Enable LED Write mode |
wim | 0:e59142cded2b | 236 | _spi.write(_flip(PT6312_DATA_SET_CMD | PT6312_LED_WR | PT6312_ADDR_INC | PT6312_MODE_NORM)); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e59142cded2b | 237 | |
wim | 0:e59142cded2b | 238 | _spi.write(_flip(leds & PT6312_LED_MSK)); // write LEDs in correct bitorder |
wim | 0:e59142cded2b | 239 | |
wim | 0:e59142cded2b | 240 | wait_us(1); |
wim | 0:e59142cded2b | 241 | _cs=1; |
wim | 0:e59142cded2b | 242 | |
wim | 0:e59142cded2b | 243 | // Restore Data Write mode |
wim | 0:e59142cded2b | 244 | _writeCmd(PT6312_DATA_SET_CMD, PT6312_DATA_WR | PT6312_ADDR_INC | PT6312_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e59142cded2b | 245 | } |
wim | 0:e59142cded2b | 246 | |
wim | 0:e59142cded2b | 247 | |
wim | 0:e59142cded2b | 248 | |
wim | 0:e59142cded2b | 249 | /** Helper to reverse all command or databits. The PT6312 expects LSB first, whereas SPI is MSB first |
wim | 0:e59142cded2b | 250 | * @param char data |
wim | 0:e59142cded2b | 251 | * @return bitreversed data |
wim | 0:e59142cded2b | 252 | */ |
wim | 0:e59142cded2b | 253 | char PT6312::_flip(char data) { |
wim | 0:e59142cded2b | 254 | char value=0; |
wim | 0:e59142cded2b | 255 | |
wim | 0:e59142cded2b | 256 | if (data & 0x01) {value |= 0x80;} ; |
wim | 0:e59142cded2b | 257 | if (data & 0x02) {value |= 0x40;} ; |
wim | 0:e59142cded2b | 258 | if (data & 0x04) {value |= 0x20;} ; |
wim | 0:e59142cded2b | 259 | if (data & 0x08) {value |= 0x10;} ; |
wim | 0:e59142cded2b | 260 | if (data & 0x10) {value |= 0x08;} ; |
wim | 0:e59142cded2b | 261 | if (data & 0x20) {value |= 0x04;} ; |
wim | 0:e59142cded2b | 262 | if (data & 0x40) {value |= 0x02;} ; |
wim | 0:e59142cded2b | 263 | if (data & 0x80) {value |= 0x01;} ; |
wim | 0:e59142cded2b | 264 | return value; |
wim | 0:e59142cded2b | 265 | } |
wim | 0:e59142cded2b | 266 | |
wim | 0:e59142cded2b | 267 | |
wim | 0:e59142cded2b | 268 | /** Write command and parameter to PT6312 |
wim | 0:e59142cded2b | 269 | * @param int cmd Command byte |
wim | 0:e59142cded2b | 270 | * &Param int data Parameters for command |
wim | 0:e59142cded2b | 271 | * @return none |
wim | 0:e59142cded2b | 272 | */ |
wim | 0:e59142cded2b | 273 | void PT6312::_writeCmd(int cmd, int data){ |
wim | 0:e59142cded2b | 274 | |
wim | 0:e59142cded2b | 275 | _cs=0; |
wim | 0:e59142cded2b | 276 | wait_us(1); |
wim | 3:156c23d9652a | 277 | |
wim | 0:e59142cded2b | 278 | _spi.write(_flip( (cmd & PT6312_CMD_MSK) | (data & ~PT6312_CMD_MSK))); |
wim | 0:e59142cded2b | 279 | |
wim | 0:e59142cded2b | 280 | wait_us(1); |
wim | 0:e59142cded2b | 281 | _cs=1; |
wim | 0:e59142cded2b | 282 | |
wim | 0:e59142cded2b | 283 | }; |
wim | 0:e59142cded2b | 284 | |
wim | 0:e59142cded2b | 285 | |
wim | 5:be9ec73af639 | 286 | #if (DVP630_TEST == 1) |
wim | 2:f010b7022803 | 287 | /** Constructor for class for driving Princeton PT6312 VFD controller as used in Philips DVP630 |
wim | 1:c5e247159aa6 | 288 | * |
wim | 3:156c23d9652a | 289 | * @brief Supports 7 Digits of 15 Segments. Also supports a scanned keyboard of 3 keys, 3 switches and 1 LED. |
wim | 3:156c23d9652a | 290 | * |
wim | 1:c5e247159aa6 | 291 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 1:c5e247159aa6 | 292 | */ |
wim | 5:be9ec73af639 | 293 | PT6312_DVP630::PT6312_DVP630(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6312(mosi, miso, sclk, cs, Grid7_Seg15) { |
wim | 2:f010b7022803 | 294 | _column = 0; |
wim | 2:f010b7022803 | 295 | _columns = DVP630_NR_DIGITS; |
wim | 1:c5e247159aa6 | 296 | } |
wim | 1:c5e247159aa6 | 297 | |
wim | 1:c5e247159aa6 | 298 | #if(0) |
wim | 1:c5e247159aa6 | 299 | #if DOXYGEN_ONLY |
wim | 1:c5e247159aa6 | 300 | /** Write a character to the LCD |
wim | 1:c5e247159aa6 | 301 | * |
wim | 1:c5e247159aa6 | 302 | * @param c The character to write to the display |
wim | 1:c5e247159aa6 | 303 | */ |
wim | 1:c5e247159aa6 | 304 | int putc(int c); |
wim | 1:c5e247159aa6 | 305 | |
wim | 1:c5e247159aa6 | 306 | /** Write a formatted string to the LCD |
wim | 1:c5e247159aa6 | 307 | * |
wim | 1:c5e247159aa6 | 308 | * @param format A printf-style format string, followed by the |
wim | 1:c5e247159aa6 | 309 | * variables to use in formatting the string. |
wim | 1:c5e247159aa6 | 310 | */ |
wim | 1:c5e247159aa6 | 311 | int printf(const char* format, ...); |
wim | 1:c5e247159aa6 | 312 | #endif |
wim | 1:c5e247159aa6 | 313 | #endif |
wim | 1:c5e247159aa6 | 314 | |
wim | 1:c5e247159aa6 | 315 | /** Locate cursor to a screen column |
wim | 1:c5e247159aa6 | 316 | * |
wim | 1:c5e247159aa6 | 317 | * @param column The horizontal position from the left, indexed from 0 |
wim | 1:c5e247159aa6 | 318 | */ |
wim | 2:f010b7022803 | 319 | void PT6312_DVP630::locate(int column) { |
wim | 2:f010b7022803 | 320 | //sanity check |
wim | 2:f010b7022803 | 321 | if (column < 0) {column = 0;} |
wim | 2:f010b7022803 | 322 | if (column > (_columns - 1)) {column = _columns - 1;} |
wim | 2:f010b7022803 | 323 | |
wim | 2:f010b7022803 | 324 | _column = column; |
wim | 1:c5e247159aa6 | 325 | } |
wim | 1:c5e247159aa6 | 326 | |
wim | 1:c5e247159aa6 | 327 | |
wim | 1:c5e247159aa6 | 328 | /** Number of screen columns |
wim | 1:c5e247159aa6 | 329 | * |
wim | 1:c5e247159aa6 | 330 | * @param none |
wim | 1:c5e247159aa6 | 331 | * @return columns |
wim | 1:c5e247159aa6 | 332 | */ |
wim | 2:f010b7022803 | 333 | int PT6312_DVP630::columns() { |
wim | 1:c5e247159aa6 | 334 | return _columns; |
wim | 1:c5e247159aa6 | 335 | } |
wim | 1:c5e247159aa6 | 336 | |
wim | 1:c5e247159aa6 | 337 | |
wim | 1:c5e247159aa6 | 338 | /** Clear the screen and locate to 0 |
wim | 5:be9ec73af639 | 339 | * @param bool clrAll Clear Icons also (default = false) |
wim | 5:be9ec73af639 | 340 | */ |
wim | 5:be9ec73af639 | 341 | void PT6312_DVP630::cls(bool clrAll) { |
wim | 2:f010b7022803 | 342 | |
wim | 5:be9ec73af639 | 343 | if (clrAll) { |
wim | 5:be9ec73af639 | 344 | //clear local buffer (including Icons) |
wim | 5:be9ec73af639 | 345 | for (int idx=0; idx < (DVP630_NR_GRIDS*2); idx++) { |
wim | 5:be9ec73af639 | 346 | _displaybuffer[idx] = 0x00; |
wim | 5:be9ec73af639 | 347 | } |
wim | 5:be9ec73af639 | 348 | } |
wim | 5:be9ec73af639 | 349 | else { |
wim | 5:be9ec73af639 | 350 | //clear local buffer (preserving Icons) |
wim | 5:be9ec73af639 | 351 | for (int idx=0; idx < DVP630_NR_GRIDS; idx++) { |
wim | 5:be9ec73af639 | 352 | _displaybuffer[(idx<<1)] = _displaybuffer[(idx<<1)] & LO(S_ICON_MSK); |
wim | 5:be9ec73af639 | 353 | _displaybuffer[(idx<<1) + 1] = _displaybuffer[(idx<<1) + 1] & HI(S_ICON_MSK); |
wim | 5:be9ec73af639 | 354 | } |
wim | 5:be9ec73af639 | 355 | } |
wim | 3:156c23d9652a | 356 | |
wim | 5:be9ec73af639 | 357 | writeData(_displaybuffer, (DVP630_NR_GRIDS*2)); |
wim | 3:156c23d9652a | 358 | |
wim | 2:f010b7022803 | 359 | _column = 0; |
wim | 1:c5e247159aa6 | 360 | } |
wim | 1:c5e247159aa6 | 361 | |
wim | 3:156c23d9652a | 362 | /** Set Icon |
wim | 3:156c23d9652a | 363 | * |
wim | 5:be9ec73af639 | 364 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 3:156c23d9652a | 365 | * @return none |
wim | 3:156c23d9652a | 366 | */ |
wim | 3:156c23d9652a | 367 | void PT6312_DVP630::setIcon(Icon icon) { |
wim | 3:156c23d9652a | 368 | int addr, icn; |
wim | 3:156c23d9652a | 369 | |
wim | 3:156c23d9652a | 370 | icn = icon & 0xFFFF; |
wim | 5:be9ec73af639 | 371 | addr = (icon >> 24) & 0xFF; |
wim | 5:be9ec73af639 | 372 | addr = (addr - 1) << 1; |
wim | 3:156c23d9652a | 373 | |
wim | 3:156c23d9652a | 374 | //Save char...and set bits for icon to write |
wim | 3:156c23d9652a | 375 | _displaybuffer[addr] = _displaybuffer[addr] | LO(icn); |
wim | 3:156c23d9652a | 376 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | HI(icn); |
wim | 5:be9ec73af639 | 377 | writeData(_displaybuffer, (DVP630_NR_GRIDS*2)); |
wim | 3:156c23d9652a | 378 | } |
wim | 3:156c23d9652a | 379 | |
wim | 3:156c23d9652a | 380 | /** Clr Icon |
wim | 3:156c23d9652a | 381 | * |
wim | 5:be9ec73af639 | 382 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 3:156c23d9652a | 383 | * @return none |
wim | 3:156c23d9652a | 384 | */ |
wim | 3:156c23d9652a | 385 | void PT6312_DVP630::clrIcon(Icon icon) { |
wim | 3:156c23d9652a | 386 | int addr, icn; |
wim | 3:156c23d9652a | 387 | |
wim | 3:156c23d9652a | 388 | icn = icon & 0xFFFF; |
wim | 5:be9ec73af639 | 389 | addr = (icon >> 24) & 0xFF; |
wim | 5:be9ec73af639 | 390 | addr = (addr - 1) << 1; |
wim | 3:156c23d9652a | 391 | |
wim | 3:156c23d9652a | 392 | //Save char...and clr bits for icon to write |
wim | 3:156c23d9652a | 393 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(icn); |
wim | 3:156c23d9652a | 394 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~HI(icn); |
wim | 5:be9ec73af639 | 395 | writeData(_displaybuffer, (DVP630_NR_GRIDS*2)); |
wim | 3:156c23d9652a | 396 | } |
wim | 3:156c23d9652a | 397 | |
wim | 3:156c23d9652a | 398 | |
wim | 3:156c23d9652a | 399 | /** Set User Defined Characters (UDC) |
wim | 3:156c23d9652a | 400 | * |
wim | 3:156c23d9652a | 401 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 3:156c23d9652a | 402 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 3:156c23d9652a | 403 | */ |
wim | 3:156c23d9652a | 404 | void PT6312_DVP630::setUDC(unsigned char udc_idx, int udc_data) { |
wim | 3:156c23d9652a | 405 | |
wim | 3:156c23d9652a | 406 | //Sanity check |
wim | 3:156c23d9652a | 407 | if (udc_idx > (DVP630_NR_UDC-1)) { |
wim | 3:156c23d9652a | 408 | return; |
wim | 3:156c23d9652a | 409 | } |
wim | 3:156c23d9652a | 410 | // Mask out Icon bits? |
wim | 3:156c23d9652a | 411 | |
wim | 3:156c23d9652a | 412 | _UDC_16S[udc_idx][0] = LO(udc_data); |
wim | 3:156c23d9652a | 413 | _UDC_16S[udc_idx][1] = HI(udc_data); |
wim | 3:156c23d9652a | 414 | } |
wim | 1:c5e247159aa6 | 415 | |
wim | 1:c5e247159aa6 | 416 | /** Write a single character (Stream implementation) |
wim | 1:c5e247159aa6 | 417 | */ |
wim | 2:f010b7022803 | 418 | int PT6312_DVP630::_putc(int value) { |
wim | 1:c5e247159aa6 | 419 | int addr; |
wim | 1:c5e247159aa6 | 420 | |
wim | 3:156c23d9652a | 421 | if ((value == '\n') || (value == '\r')) { |
wim | 1:c5e247159aa6 | 422 | //No character to write |
wim | 1:c5e247159aa6 | 423 | |
wim | 1:c5e247159aa6 | 424 | //Update Cursor |
wim | 1:c5e247159aa6 | 425 | _column = 0; |
wim | 1:c5e247159aa6 | 426 | } |
wim | 3:156c23d9652a | 427 | else if ((value >= 0) && (value < DVP630_NR_UDC)) { |
wim | 1:c5e247159aa6 | 428 | //Character to write |
wim | 3:156c23d9652a | 429 | addr = ((DVP630_NR_DIGITS - 1) - _column) * 2; |
wim | 2:f010b7022803 | 430 | |
wim | 3:156c23d9652a | 431 | //Save icons...and set bits for character to write |
wim | 3:156c23d9652a | 432 | _displaybuffer[addr] = (_displaybuffer[addr] & LO(S_ICON_MSK)) | _UDC_16S[value][0]; |
wim | 3:156c23d9652a | 433 | _displaybuffer[addr+1] = (_displaybuffer[addr+1] & HI(S_ICON_MSK)) | _UDC_16S[value][1]; |
wim | 2:f010b7022803 | 434 | writeData(_displaybuffer, (DVP630_NR_DIGITS*2)); |
wim | 2:f010b7022803 | 435 | |
wim | 1:c5e247159aa6 | 436 | //Update Cursor |
wim | 1:c5e247159aa6 | 437 | _column++; |
wim | 3:156c23d9652a | 438 | if (_column > (DVP630_NR_DIGITS - 1)) { |
wim | 3:156c23d9652a | 439 | _column = 0; |
wim | 3:156c23d9652a | 440 | } |
wim | 3:156c23d9652a | 441 | } |
wim | 3:156c23d9652a | 442 | else if ((value >= FONT_16S_START) && (value <= FONT_16S_END)) { |
wim | 3:156c23d9652a | 443 | //Character to write |
wim | 3:156c23d9652a | 444 | value = value - FONT_16S_START; |
wim | 3:156c23d9652a | 445 | addr = ((DVP630_NR_DIGITS - 1) - _column) * 2; |
wim | 3:156c23d9652a | 446 | |
wim | 3:156c23d9652a | 447 | //Save icons...and set bits for character to write |
wim | 3:156c23d9652a | 448 | _displaybuffer[addr] = (_displaybuffer[addr] & LO(S_ICON_MSK)) | FONT_16S[value][0]; |
wim | 3:156c23d9652a | 449 | _displaybuffer[addr+1] = (_displaybuffer[addr+1] & HI(S_ICON_MSK)) | FONT_16S[value][1]; |
wim | 3:156c23d9652a | 450 | writeData(_displaybuffer, (DVP630_NR_DIGITS*2)); |
wim | 3:156c23d9652a | 451 | |
wim | 3:156c23d9652a | 452 | //Update Cursor |
wim | 3:156c23d9652a | 453 | _column++; |
wim | 3:156c23d9652a | 454 | if (_column > (DVP630_NR_DIGITS - 1)) { |
wim | 1:c5e247159aa6 | 455 | _column = 0; |
wim | 1:c5e247159aa6 | 456 | } |
wim | 1:c5e247159aa6 | 457 | } //else |
wim | 1:c5e247159aa6 | 458 | |
wim | 1:c5e247159aa6 | 459 | return value; |
wim | 1:c5e247159aa6 | 460 | } |
wim | 1:c5e247159aa6 | 461 | |
wim | 1:c5e247159aa6 | 462 | |
wim | 1:c5e247159aa6 | 463 | // get a single character (Stream implementation) |
wim | 2:f010b7022803 | 464 | int PT6312_DVP630::_getc() { |
wim | 1:c5e247159aa6 | 465 | return -1; |
wim | 1:c5e247159aa6 | 466 | } |
wim | 5:be9ec73af639 | 467 | #endif |
wim | 5:be9ec73af639 | 468 | |
wim | 5:be9ec73af639 | 469 | |
wim | 5:be9ec73af639 | 470 | #if (DVD462_TEST == 1) |
wim | 5:be9ec73af639 | 471 | /** Constructor for class for driving Princeton PT6312 VFD controller as used in DVD462 |
wim | 5:be9ec73af639 | 472 | * |
wim | 5:be9ec73af639 | 473 | * @brief Supports 7 Digits of 7 Segments and icons. Also supports a scanned keyboard of 7 keys and 1 LED. |
wim | 5:be9ec73af639 | 474 | * |
wim | 5:be9ec73af639 | 475 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 5:be9ec73af639 | 476 | */ |
wim | 5:be9ec73af639 | 477 | PT6312_DVD462::PT6312_DVD462(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6312(mosi, miso, sclk, cs, Grid6_Seg16) { |
wim | 5:be9ec73af639 | 478 | _column = 0; |
wim | 5:be9ec73af639 | 479 | _columns = DVD462_NR_DIGITS; |
wim | 5:be9ec73af639 | 480 | } |
wim | 5:be9ec73af639 | 481 | |
wim | 5:be9ec73af639 | 482 | #if(0) |
wim | 5:be9ec73af639 | 483 | #if DOXYGEN_ONLY |
wim | 5:be9ec73af639 | 484 | /** Write a character to the LCD |
wim | 5:be9ec73af639 | 485 | * |
wim | 5:be9ec73af639 | 486 | * @param c The character to write to the display |
wim | 5:be9ec73af639 | 487 | */ |
wim | 5:be9ec73af639 | 488 | int putc(int c); |
wim | 5:be9ec73af639 | 489 | |
wim | 5:be9ec73af639 | 490 | /** Write a formatted string to the LCD |
wim | 5:be9ec73af639 | 491 | * |
wim | 5:be9ec73af639 | 492 | * @param format A printf-style format string, followed by the |
wim | 5:be9ec73af639 | 493 | * variables to use in formatting the string. |
wim | 5:be9ec73af639 | 494 | */ |
wim | 5:be9ec73af639 | 495 | int printf(const char* format, ...); |
wim | 5:be9ec73af639 | 496 | #endif |
wim | 5:be9ec73af639 | 497 | #endif |
wim | 5:be9ec73af639 | 498 | |
wim | 5:be9ec73af639 | 499 | /** Locate cursor to a screen column |
wim | 5:be9ec73af639 | 500 | * |
wim | 5:be9ec73af639 | 501 | * @param column The horizontal position from the left, indexed from 0 |
wim | 5:be9ec73af639 | 502 | */ |
wim | 5:be9ec73af639 | 503 | void PT6312_DVD462::locate(int column) { |
wim | 5:be9ec73af639 | 504 | //sanity check |
wim | 5:be9ec73af639 | 505 | if (column < 0) {column = 0;} |
wim | 5:be9ec73af639 | 506 | if (column > (_columns - 1)) {column = _columns - 1;} |
wim | 5:be9ec73af639 | 507 | |
wim | 5:be9ec73af639 | 508 | _column = column; |
wim | 5:be9ec73af639 | 509 | } |
wim | 5:be9ec73af639 | 510 | |
wim | 5:be9ec73af639 | 511 | |
wim | 5:be9ec73af639 | 512 | /** Number of screen columns |
wim | 5:be9ec73af639 | 513 | * |
wim | 5:be9ec73af639 | 514 | * @param none |
wim | 5:be9ec73af639 | 515 | * @return columns |
wim | 5:be9ec73af639 | 516 | */ |
wim | 5:be9ec73af639 | 517 | int PT6312_DVD462::columns() { |
wim | 5:be9ec73af639 | 518 | return _columns; |
wim | 5:be9ec73af639 | 519 | } |
wim | 5:be9ec73af639 | 520 | |
wim | 5:be9ec73af639 | 521 | |
wim | 5:be9ec73af639 | 522 | /** Clear the screen and locate to 0 |
wim | 5:be9ec73af639 | 523 | * @param bool clrAll Clear Icons also (default = false) |
wim | 5:be9ec73af639 | 524 | */ |
wim | 5:be9ec73af639 | 525 | void PT6312_DVD462::cls(bool clrAll) { |
wim | 5:be9ec73af639 | 526 | |
wim | 5:be9ec73af639 | 527 | if (clrAll) { |
wim | 5:be9ec73af639 | 528 | //clear local buffer (including Icons) |
wim | 5:be9ec73af639 | 529 | for (int idx=0; idx < (DVD462_NR_GRIDS << 1); idx++) { |
wim | 5:be9ec73af639 | 530 | _displaybuffer[idx] = 0x00; |
wim | 5:be9ec73af639 | 531 | } |
wim | 5:be9ec73af639 | 532 | } |
wim | 5:be9ec73af639 | 533 | else { |
wim | 5:be9ec73af639 | 534 | //clear local buffer (preserving Icons) |
wim | 5:be9ec73af639 | 535 | for (int idx=0; idx < DVD462_NR_GRIDS; idx++) { |
wim | 5:be9ec73af639 | 536 | _displaybuffer[(idx<<1)] = _displaybuffer[(idx<<1)] & MASK_ICON_GRID[idx][0]; |
wim | 5:be9ec73af639 | 537 | _displaybuffer[(idx<<1) + 1] = _displaybuffer[(idx<<1) + 1] & MASK_ICON_GRID[idx][1]; |
wim | 5:be9ec73af639 | 538 | } |
wim | 5:be9ec73af639 | 539 | } |
wim | 5:be9ec73af639 | 540 | |
wim | 5:be9ec73af639 | 541 | writeData(_displaybuffer, (DVD462_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 542 | |
wim | 5:be9ec73af639 | 543 | _column = 0; |
wim | 5:be9ec73af639 | 544 | } |
wim | 5:be9ec73af639 | 545 | |
wim | 5:be9ec73af639 | 546 | /** Set Icon |
wim | 5:be9ec73af639 | 547 | * |
wim | 5:be9ec73af639 | 548 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 5:be9ec73af639 | 549 | * @return none |
wim | 5:be9ec73af639 | 550 | */ |
wim | 5:be9ec73af639 | 551 | void PT6312_DVD462::setIcon(Icon icon) { |
wim | 5:be9ec73af639 | 552 | int addr, icn; |
wim | 5:be9ec73af639 | 553 | |
wim | 5:be9ec73af639 | 554 | icn = icon & 0xFFFF; |
wim | 5:be9ec73af639 | 555 | addr = (icon >> 24) & 0xFF; |
wim | 5:be9ec73af639 | 556 | addr = (addr - 1) << 1; |
wim | 5:be9ec73af639 | 557 | |
wim | 5:be9ec73af639 | 558 | //Save char...and set bits for icon to write |
wim | 5:be9ec73af639 | 559 | _displaybuffer[addr] = _displaybuffer[addr] | LO(icn); |
wim | 5:be9ec73af639 | 560 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | HI(icn); |
wim | 5:be9ec73af639 | 561 | writeData(_displaybuffer, (DVD462_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 562 | } |
wim | 5:be9ec73af639 | 563 | |
wim | 5:be9ec73af639 | 564 | /** Clr Icon |
wim | 5:be9ec73af639 | 565 | * |
wim | 5:be9ec73af639 | 566 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 5:be9ec73af639 | 567 | * @return none |
wim | 5:be9ec73af639 | 568 | */ |
wim | 5:be9ec73af639 | 569 | void PT6312_DVD462::clrIcon(Icon icon) { |
wim | 5:be9ec73af639 | 570 | int addr, icn; |
wim | 5:be9ec73af639 | 571 | |
wim | 5:be9ec73af639 | 572 | icn = icon & 0xFFFF; |
wim | 5:be9ec73af639 | 573 | addr = (icon >> 24) & 0xFF; |
wim | 5:be9ec73af639 | 574 | addr = (addr -1 ) << 1; |
wim | 5:be9ec73af639 | 575 | |
wim | 5:be9ec73af639 | 576 | //Save char...and clr bits for icon to write |
wim | 5:be9ec73af639 | 577 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(icn); |
wim | 5:be9ec73af639 | 578 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~HI(icn); |
wim | 5:be9ec73af639 | 579 | writeData(_displaybuffer, (DVD462_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 580 | } |
wim | 5:be9ec73af639 | 581 | |
wim | 5:be9ec73af639 | 582 | |
wim | 5:be9ec73af639 | 583 | /** Set User Defined Characters (UDC) |
wim | 5:be9ec73af639 | 584 | * |
wim | 5:be9ec73af639 | 585 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 5:be9ec73af639 | 586 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 5:be9ec73af639 | 587 | */ |
wim | 5:be9ec73af639 | 588 | void PT6312_DVD462::setUDC(unsigned char udc_idx, int udc_data) { |
wim | 5:be9ec73af639 | 589 | |
wim | 5:be9ec73af639 | 590 | //Sanity check |
wim | 5:be9ec73af639 | 591 | if (udc_idx > (DVD462_NR_UDC-1)) { |
wim | 5:be9ec73af639 | 592 | return; |
wim | 5:be9ec73af639 | 593 | } |
wim | 5:be9ec73af639 | 594 | // Mask out Icon bits? |
wim | 5:be9ec73af639 | 595 | |
wim | 5:be9ec73af639 | 596 | _UDC_7S[udc_idx] = LO(udc_data); |
wim | 5:be9ec73af639 | 597 | // _UDC_7S[udc_idx][1] = HI(udc_data); |
wim | 5:be9ec73af639 | 598 | } |
wim | 5:be9ec73af639 | 599 | |
wim | 5:be9ec73af639 | 600 | /** Write a single character (Stream implementation) |
wim | 5:be9ec73af639 | 601 | */ |
wim | 5:be9ec73af639 | 602 | int PT6312_DVD462::_putc(int value) { |
wim | 5:be9ec73af639 | 603 | bool validChar = false; |
wim | 5:be9ec73af639 | 604 | char pattern = 0x00; |
wim | 5:be9ec73af639 | 605 | |
wim | 5:be9ec73af639 | 606 | if ((value == '\n') || (value == '\r')) { |
wim | 5:be9ec73af639 | 607 | //No character to write |
wim | 5:be9ec73af639 | 608 | validChar = false; |
wim | 5:be9ec73af639 | 609 | |
wim | 5:be9ec73af639 | 610 | //Update Cursor |
wim | 5:be9ec73af639 | 611 | _column = 0; |
wim | 5:be9ec73af639 | 612 | } |
wim | 5:be9ec73af639 | 613 | else if ((value >= 0) && (value < DVD462_NR_UDC)) { |
wim | 5:be9ec73af639 | 614 | //Character to write |
wim | 5:be9ec73af639 | 615 | validChar = true; |
wim | 5:be9ec73af639 | 616 | pattern = _UDC_7S[value]; |
wim | 5:be9ec73af639 | 617 | } |
wim | 5:be9ec73af639 | 618 | else if ((value >= (int)'0') && (value <= (int) '9')) { |
wim | 5:be9ec73af639 | 619 | //Character to write |
wim | 5:be9ec73af639 | 620 | validChar = true; |
wim | 5:be9ec73af639 | 621 | pattern = FONT_7S[value - (int) '0']; |
wim | 5:be9ec73af639 | 622 | } |
wim | 5:be9ec73af639 | 623 | else if ((value >= (int) 'A') && (value <= (int) 'F')) { |
wim | 5:be9ec73af639 | 624 | //Character to write |
wim | 5:be9ec73af639 | 625 | validChar = true; |
wim | 5:be9ec73af639 | 626 | pattern = FONT_7S[10 + value - (int) 'A']; |
wim | 5:be9ec73af639 | 627 | } |
wim | 5:be9ec73af639 | 628 | else if ((value >= (int) 'a') && (value <= (int) 'f')) { |
wim | 5:be9ec73af639 | 629 | //Character to write |
wim | 5:be9ec73af639 | 630 | validChar = true; |
wim | 5:be9ec73af639 | 631 | pattern = FONT_7S[10 + value - (int) 'a']; |
wim | 5:be9ec73af639 | 632 | } //else |
wim | 5:be9ec73af639 | 633 | |
wim | 5:be9ec73af639 | 634 | if (validChar) { |
wim | 5:be9ec73af639 | 635 | //Character to write |
wim | 5:be9ec73af639 | 636 | |
wim | 5:be9ec73af639 | 637 | //Translate between _column and displaybuffer entries |
wim | 5:be9ec73af639 | 638 | //Note that the DVD462 has two 7Segment digits for several Grids. |
wim | 5:be9ec73af639 | 639 | //Some of these Grids also have icons that need to be preserved |
wim | 5:be9ec73af639 | 640 | switch (_column) { |
wim | 5:be9ec73af639 | 641 | case 0 : //Grid 5, LSB; idx=8 |
wim | 5:be9ec73af639 | 642 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 643 | _displaybuffer[8] = pattern; |
wim | 5:be9ec73af639 | 644 | break; |
wim | 5:be9ec73af639 | 645 | case 1 : //Grid 4, MSB; idx=7 |
wim | 5:be9ec73af639 | 646 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 647 | _displaybuffer[7] = pattern; |
wim | 5:be9ec73af639 | 648 | break; |
wim | 5:be9ec73af639 | 649 | case 2 : //Grid 4, LSB; idx=6 |
wim | 5:be9ec73af639 | 650 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 651 | _displaybuffer[6] = (_displaybuffer[6] & MASK_ICON_GRID[3][0]) | pattern; |
wim | 5:be9ec73af639 | 652 | break; |
wim | 5:be9ec73af639 | 653 | case 3 : //Grid 3, MSB; idx=5 |
wim | 5:be9ec73af639 | 654 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 655 | _displaybuffer[5] = pattern; |
wim | 5:be9ec73af639 | 656 | break; |
wim | 5:be9ec73af639 | 657 | case 4 : //Grid 3, LSB; idx=4 |
wim | 5:be9ec73af639 | 658 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 659 | _displaybuffer[4] = (_displaybuffer[4] & MASK_ICON_GRID[2][0]) | pattern; |
wim | 5:be9ec73af639 | 660 | break; |
wim | 5:be9ec73af639 | 661 | case 5 : //Grid 2, MSB; idx=3 |
wim | 5:be9ec73af639 | 662 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 663 | //This grid has a different mapping of digits |
wim | 5:be9ec73af639 | 664 | _displaybuffer[3] = (_displaybuffer[3] & MASK_ICON_GRID[1][1]) | (pattern >> 1); |
wim | 5:be9ec73af639 | 665 | _displaybuffer[2] = (_displaybuffer[2] & 0x7F) | ((pattern & 0x01) << 7); |
wim | 5:be9ec73af639 | 666 | break; |
wim | 5:be9ec73af639 | 667 | case 6 : //Grid 2, LSB; idx=2 |
wim | 5:be9ec73af639 | 668 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 669 | //This grid has a different mapping of digits |
wim | 5:be9ec73af639 | 670 | _displaybuffer[2] = (_displaybuffer[2] & 0x80) | (pattern & 0x7F); |
wim | 5:be9ec73af639 | 671 | break; |
wim | 5:be9ec73af639 | 672 | } |
wim | 5:be9ec73af639 | 673 | writeData(_displaybuffer, (DVD462_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 674 | |
wim | 5:be9ec73af639 | 675 | //Update Cursor |
wim | 5:be9ec73af639 | 676 | _column++; |
wim | 5:be9ec73af639 | 677 | if (_column > (DVD462_NR_DIGITS - 1)) { |
wim | 5:be9ec73af639 | 678 | _column = 0; |
wim | 5:be9ec73af639 | 679 | } |
wim | 5:be9ec73af639 | 680 | |
wim | 5:be9ec73af639 | 681 | } // if validChar |
wim | 5:be9ec73af639 | 682 | |
wim | 5:be9ec73af639 | 683 | return value; |
wim | 5:be9ec73af639 | 684 | } |
wim | 5:be9ec73af639 | 685 | |
wim | 5:be9ec73af639 | 686 | // get a single character (Stream implementation) |
wim | 5:be9ec73af639 | 687 | int PT6312_DVD462::_getc() { |
wim | 5:be9ec73af639 | 688 | return -1; |
wim | 5:be9ec73af639 | 689 | } |
wim | 5:be9ec73af639 | 690 | #endif |
wim | 5:be9ec73af639 | 691 | |
wim | 5:be9ec73af639 | 692 | #if (C2233_TEST == 1) |
wim | 5:be9ec73af639 | 693 | /** Constructor for class for driving Princeton PT6312 VFD controller as used in C2233 |
wim | 5:be9ec73af639 | 694 | * |
wim | 5:be9ec73af639 | 695 | * @brief Supports 7 Digits of 7 Segments and icons. Also supports a scanned keyboard of 7 keys. |
wim | 5:be9ec73af639 | 696 | * |
wim | 5:be9ec73af639 | 697 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 5:be9ec73af639 | 698 | */ |
wim | 5:be9ec73af639 | 699 | PT6312_C2233::PT6312_C2233(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6312(mosi, miso, sclk, cs, Grid6_Seg16) { |
wim | 5:be9ec73af639 | 700 | _column = 0; |
wim | 5:be9ec73af639 | 701 | _columns = C2233_NR_DIGITS; |
wim | 5:be9ec73af639 | 702 | } |
wim | 5:be9ec73af639 | 703 | |
wim | 5:be9ec73af639 | 704 | #if(0) |
wim | 5:be9ec73af639 | 705 | #if DOXYGEN_ONLY |
wim | 5:be9ec73af639 | 706 | /** Write a character to the LCD |
wim | 5:be9ec73af639 | 707 | * |
wim | 5:be9ec73af639 | 708 | * @param c The character to write to the display |
wim | 5:be9ec73af639 | 709 | */ |
wim | 5:be9ec73af639 | 710 | int putc(int c); |
wim | 5:be9ec73af639 | 711 | |
wim | 5:be9ec73af639 | 712 | /** Write a formatted string to the LCD |
wim | 5:be9ec73af639 | 713 | * |
wim | 5:be9ec73af639 | 714 | * @param format A printf-style format string, followed by the |
wim | 5:be9ec73af639 | 715 | * variables to use in formatting the string. |
wim | 5:be9ec73af639 | 716 | */ |
wim | 5:be9ec73af639 | 717 | int printf(const char* format, ...); |
wim | 5:be9ec73af639 | 718 | #endif |
wim | 5:be9ec73af639 | 719 | #endif |
wim | 5:be9ec73af639 | 720 | |
wim | 5:be9ec73af639 | 721 | /** Locate cursor to a screen column |
wim | 5:be9ec73af639 | 722 | * |
wim | 5:be9ec73af639 | 723 | * @param column The horizontal position from the left, indexed from 0 |
wim | 5:be9ec73af639 | 724 | */ |
wim | 5:be9ec73af639 | 725 | void PT6312_C2233::locate(int column) { |
wim | 5:be9ec73af639 | 726 | //sanity check |
wim | 5:be9ec73af639 | 727 | if (column < 0) {column = 0;} |
wim | 5:be9ec73af639 | 728 | if (column > (_columns - 1)) {column = _columns - 1;} |
wim | 5:be9ec73af639 | 729 | |
wim | 5:be9ec73af639 | 730 | _column = column; |
wim | 5:be9ec73af639 | 731 | } |
wim | 5:be9ec73af639 | 732 | |
wim | 5:be9ec73af639 | 733 | |
wim | 5:be9ec73af639 | 734 | /** Number of screen columns |
wim | 5:be9ec73af639 | 735 | * |
wim | 5:be9ec73af639 | 736 | * @param none |
wim | 5:be9ec73af639 | 737 | * @return columns |
wim | 5:be9ec73af639 | 738 | */ |
wim | 5:be9ec73af639 | 739 | int PT6312_C2233::columns() { |
wim | 5:be9ec73af639 | 740 | return _columns; |
wim | 5:be9ec73af639 | 741 | } |
wim | 5:be9ec73af639 | 742 | |
wim | 5:be9ec73af639 | 743 | |
wim | 5:be9ec73af639 | 744 | /** Clear the screen and locate to 0 |
wim | 5:be9ec73af639 | 745 | * @param bool clrAll Clear Icons also (default = false) |
wim | 5:be9ec73af639 | 746 | */ |
wim | 5:be9ec73af639 | 747 | void PT6312_C2233::cls(bool clrAll) { |
wim | 5:be9ec73af639 | 748 | |
wim | 5:be9ec73af639 | 749 | if (clrAll) { |
wim | 5:be9ec73af639 | 750 | //clear local buffer (including Icons) |
wim | 5:be9ec73af639 | 751 | for (int idx=0; idx < (C2233_NR_GRIDS << 1); idx++) { |
wim | 5:be9ec73af639 | 752 | _displaybuffer[idx] = 0x00; |
wim | 5:be9ec73af639 | 753 | } |
wim | 5:be9ec73af639 | 754 | } |
wim | 5:be9ec73af639 | 755 | else { |
wim | 5:be9ec73af639 | 756 | //clear local buffer (preserving Icons) |
wim | 5:be9ec73af639 | 757 | for (int idx=0; idx < C2233_NR_GRIDS; idx++) { |
wim | 5:be9ec73af639 | 758 | _displaybuffer[(idx<<1)] = _displaybuffer[(idx<<1)] & MASK_ICON_GRID[idx][0]; |
wim | 5:be9ec73af639 | 759 | _displaybuffer[(idx<<1) + 1] = _displaybuffer[(idx<<1) + 1] & MASK_ICON_GRID[idx][1]; |
wim | 5:be9ec73af639 | 760 | } |
wim | 5:be9ec73af639 | 761 | } |
wim | 5:be9ec73af639 | 762 | |
wim | 5:be9ec73af639 | 763 | writeData(_displaybuffer, (C2233_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 764 | |
wim | 5:be9ec73af639 | 765 | _column = 0; |
wim | 5:be9ec73af639 | 766 | } |
wim | 5:be9ec73af639 | 767 | |
wim | 5:be9ec73af639 | 768 | /** Set Icon |
wim | 5:be9ec73af639 | 769 | * |
wim | 5:be9ec73af639 | 770 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 5:be9ec73af639 | 771 | * @return none |
wim | 5:be9ec73af639 | 772 | */ |
wim | 5:be9ec73af639 | 773 | void PT6312_C2233::setIcon(Icon icon) { |
wim | 5:be9ec73af639 | 774 | int addr, icn; |
wim | 5:be9ec73af639 | 775 | |
wim | 5:be9ec73af639 | 776 | icn = icon & 0xFFFF; |
wim | 5:be9ec73af639 | 777 | addr = (icon >> 24) & 0xFF; |
wim | 5:be9ec73af639 | 778 | addr = (addr - 1) << 1; |
wim | 5:be9ec73af639 | 779 | |
wim | 5:be9ec73af639 | 780 | //Save char...and set bits for icon to write |
wim | 5:be9ec73af639 | 781 | _displaybuffer[addr] = _displaybuffer[addr] | LO(icn); |
wim | 5:be9ec73af639 | 782 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | HI(icn); |
wim | 5:be9ec73af639 | 783 | writeData(_displaybuffer, (C2233_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 784 | } |
wim | 5:be9ec73af639 | 785 | |
wim | 5:be9ec73af639 | 786 | /** Clr Icon |
wim | 5:be9ec73af639 | 787 | * |
wim | 5:be9ec73af639 | 788 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 5:be9ec73af639 | 789 | * @return none |
wim | 5:be9ec73af639 | 790 | */ |
wim | 5:be9ec73af639 | 791 | void PT6312_C2233::clrIcon(Icon icon) { |
wim | 5:be9ec73af639 | 792 | int addr, icn; |
wim | 5:be9ec73af639 | 793 | |
wim | 5:be9ec73af639 | 794 | icn = icon & 0xFFFF; |
wim | 5:be9ec73af639 | 795 | addr = (icon >> 24) & 0xFF; |
wim | 5:be9ec73af639 | 796 | addr = (addr -1 ) << 1; |
wim | 5:be9ec73af639 | 797 | |
wim | 5:be9ec73af639 | 798 | //Save char...and clr bits for icon to write |
wim | 5:be9ec73af639 | 799 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(icn); |
wim | 5:be9ec73af639 | 800 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~HI(icn); |
wim | 5:be9ec73af639 | 801 | writeData(_displaybuffer, (C2233_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 802 | } |
wim | 5:be9ec73af639 | 803 | |
wim | 5:be9ec73af639 | 804 | |
wim | 5:be9ec73af639 | 805 | /** Set User Defined Characters (UDC) |
wim | 5:be9ec73af639 | 806 | * |
wim | 5:be9ec73af639 | 807 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 5:be9ec73af639 | 808 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 5:be9ec73af639 | 809 | */ |
wim | 5:be9ec73af639 | 810 | void PT6312_C2233::setUDC(unsigned char udc_idx, int udc_data) { |
wim | 5:be9ec73af639 | 811 | |
wim | 5:be9ec73af639 | 812 | //Sanity check |
wim | 5:be9ec73af639 | 813 | if (udc_idx > (C2233_NR_UDC-1)) { |
wim | 5:be9ec73af639 | 814 | return; |
wim | 5:be9ec73af639 | 815 | } |
wim | 5:be9ec73af639 | 816 | // Mask out Icon bits? |
wim | 5:be9ec73af639 | 817 | |
wim | 5:be9ec73af639 | 818 | _UDC_7S[udc_idx] = LO(udc_data); |
wim | 5:be9ec73af639 | 819 | // _UDC_7S[udc_idx][1] = HI(udc_data); |
wim | 5:be9ec73af639 | 820 | } |
wim | 5:be9ec73af639 | 821 | |
wim | 5:be9ec73af639 | 822 | /** Write a single character (Stream implementation) |
wim | 5:be9ec73af639 | 823 | */ |
wim | 5:be9ec73af639 | 824 | int PT6312_C2233::_putc(int value) { |
wim | 5:be9ec73af639 | 825 | bool validChar = false; |
wim | 5:be9ec73af639 | 826 | char pattern = 0x00; |
wim | 5:be9ec73af639 | 827 | |
wim | 5:be9ec73af639 | 828 | if ((value == '\n') || (value == '\r')) { |
wim | 5:be9ec73af639 | 829 | //No character to write |
wim | 5:be9ec73af639 | 830 | validChar = false; |
wim | 5:be9ec73af639 | 831 | |
wim | 5:be9ec73af639 | 832 | //Update Cursor |
wim | 5:be9ec73af639 | 833 | _column = 0; |
wim | 5:be9ec73af639 | 834 | } |
wim | 5:be9ec73af639 | 835 | else if ((value >= 0) && (value < C2233_NR_UDC)) { |
wim | 5:be9ec73af639 | 836 | //Character to write |
wim | 5:be9ec73af639 | 837 | validChar = true; |
wim | 5:be9ec73af639 | 838 | pattern = _UDC_7S[value]; |
wim | 5:be9ec73af639 | 839 | } |
wim | 5:be9ec73af639 | 840 | else if ((value >= (int)'0') && (value <= (int) '9')) { |
wim | 5:be9ec73af639 | 841 | //Character to write |
wim | 5:be9ec73af639 | 842 | validChar = true; |
wim | 5:be9ec73af639 | 843 | pattern = FONT_7S[value - (int) '0']; |
wim | 5:be9ec73af639 | 844 | } |
wim | 5:be9ec73af639 | 845 | else if ((value >= (int) 'A') && (value <= (int) 'F')) { |
wim | 5:be9ec73af639 | 846 | //Character to write |
wim | 5:be9ec73af639 | 847 | validChar = true; |
wim | 5:be9ec73af639 | 848 | pattern = FONT_7S[10 + value - (int) 'A']; |
wim | 5:be9ec73af639 | 849 | } |
wim | 5:be9ec73af639 | 850 | else if ((value >= (int) 'a') && (value <= (int) 'f')) { |
wim | 5:be9ec73af639 | 851 | //Character to write |
wim | 5:be9ec73af639 | 852 | validChar = true; |
wim | 5:be9ec73af639 | 853 | pattern = FONT_7S[10 + value - (int) 'a']; |
wim | 5:be9ec73af639 | 854 | } //else |
wim | 5:be9ec73af639 | 855 | |
wim | 5:be9ec73af639 | 856 | if (validChar) { |
wim | 5:be9ec73af639 | 857 | //Character to write |
wim | 5:be9ec73af639 | 858 | |
wim | 5:be9ec73af639 | 859 | //Translate between _column and displaybuffer entries |
wim | 5:be9ec73af639 | 860 | //Note that the C2233 has two 7Segment digits for several Grids. |
wim | 5:be9ec73af639 | 861 | //Some of these Grids also have icons that need to be preserved |
wim | 5:be9ec73af639 | 862 | switch (_column) { |
wim | 5:be9ec73af639 | 863 | case 0 : //Grid 5, LSB; idx=8 |
wim | 5:be9ec73af639 | 864 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 865 | _displaybuffer[8] = pattern; |
wim | 5:be9ec73af639 | 866 | break; |
wim | 5:be9ec73af639 | 867 | case 1 : //Grid 4, MSB; idx=7 |
wim | 5:be9ec73af639 | 868 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 869 | _displaybuffer[7] = (_displaybuffer[7] & MASK_ICON_GRID[3][1]) | pattern; |
wim | 5:be9ec73af639 | 870 | break; |
wim | 5:be9ec73af639 | 871 | case 2 : //Grid 4, LSB; idx=6 |
wim | 5:be9ec73af639 | 872 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 873 | _displaybuffer[6] = (_displaybuffer[6] & MASK_ICON_GRID[3][0]) | pattern; |
wim | 5:be9ec73af639 | 874 | break; |
wim | 5:be9ec73af639 | 875 | case 3 : //Grid 3, MSB; idx=5 |
wim | 5:be9ec73af639 | 876 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 877 | _displaybuffer[5] = (_displaybuffer[5] & MASK_ICON_GRID[2][1]) | pattern; |
wim | 5:be9ec73af639 | 878 | break; |
wim | 5:be9ec73af639 | 879 | case 4 : //Grid 3, LSB; idx=4 |
wim | 5:be9ec73af639 | 880 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 881 | _displaybuffer[4] = (_displaybuffer[4] & MASK_ICON_GRID[2][0]) | pattern; |
wim | 5:be9ec73af639 | 882 | break; |
wim | 5:be9ec73af639 | 883 | case 5 : //Grid 2, MSB; idx=3 |
wim | 5:be9ec73af639 | 884 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 885 | //This grid has a different mapping of digits |
wim | 5:be9ec73af639 | 886 | _displaybuffer[3] = (_displaybuffer[3] & MASK_ICON_GRID[1][1]) | (pattern >> 1); |
wim | 5:be9ec73af639 | 887 | _displaybuffer[2] = (_displaybuffer[2] & 0x7F) | ((pattern & 0x01) << 7); |
wim | 5:be9ec73af639 | 888 | break; |
wim | 5:be9ec73af639 | 889 | case 6 : //Grid 2, LSB; idx=2 |
wim | 5:be9ec73af639 | 890 | //Save icons...and set bits for character to write |
wim | 5:be9ec73af639 | 891 | //This grid has a different mapping of digits |
wim | 5:be9ec73af639 | 892 | _displaybuffer[2] = (_displaybuffer[2] & 0x80) | (pattern & 0x7F); |
wim | 5:be9ec73af639 | 893 | break; |
wim | 5:be9ec73af639 | 894 | } |
wim | 5:be9ec73af639 | 895 | writeData(_displaybuffer, (C2233_NR_GRIDS*2)); |
wim | 5:be9ec73af639 | 896 | |
wim | 5:be9ec73af639 | 897 | //Update Cursor |
wim | 5:be9ec73af639 | 898 | _column++; |
wim | 5:be9ec73af639 | 899 | if (_column > (C2233_NR_DIGITS - 1)) { |
wim | 5:be9ec73af639 | 900 | _column = 0; |
wim | 5:be9ec73af639 | 901 | } |
wim | 5:be9ec73af639 | 902 | |
wim | 5:be9ec73af639 | 903 | } // if validChar |
wim | 5:be9ec73af639 | 904 | |
wim | 5:be9ec73af639 | 905 | return value; |
wim | 5:be9ec73af639 | 906 | } |
wim | 5:be9ec73af639 | 907 | |
wim | 5:be9ec73af639 | 908 | // get a single character (Stream implementation) |
wim | 5:be9ec73af639 | 909 | int PT6312_C2233::_getc() { |
wim | 5:be9ec73af639 | 910 | return -1; |
wim | 5:be9ec73af639 | 911 | } |
wim | 5:be9ec73af639 | 912 | #endif |