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