PT6315 VFD driver. Supports DVDR3510.
PT6315.cpp@0:d93c23711ca8, 2016-01-20 (annotated)
- Committer:
- wim
- Date:
- Wed Jan 20 19:24:17 2016 +0000
- Revision:
- 0:d93c23711ca8
PT6315 VFD driver library. Supports DVDR3510. First release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:d93c23711ca8 | 1 | /* mbed PT6315 Library, for Princeton PT6315 VFD controller |
wim | 0:d93c23711ca8 | 2 | * Copyright (c) 2016, v01: WH, Initial version, for DVDR3510 code |
wim | 0:d93c23711ca8 | 3 | * |
wim | 0:d93c23711ca8 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:d93c23711ca8 | 5 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:d93c23711ca8 | 6 | * in the Software without restriction, including without limitation the rights |
wim | 0:d93c23711ca8 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:d93c23711ca8 | 8 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:d93c23711ca8 | 9 | * furnished to do so, subject to the following conditions: |
wim | 0:d93c23711ca8 | 10 | * |
wim | 0:d93c23711ca8 | 11 | * The above copyright notice and this permission notice shall be included in |
wim | 0:d93c23711ca8 | 12 | * all copies or substantial portions of the Software. |
wim | 0:d93c23711ca8 | 13 | * |
wim | 0:d93c23711ca8 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:d93c23711ca8 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:d93c23711ca8 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:d93c23711ca8 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:d93c23711ca8 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:d93c23711ca8 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:d93c23711ca8 | 20 | * THE SOFTWARE. |
wim | 0:d93c23711ca8 | 21 | */ |
wim | 0:d93c23711ca8 | 22 | #include "mbed.h" |
wim | 0:d93c23711ca8 | 23 | #include "PT6315.h" |
wim | 0:d93c23711ca8 | 24 | |
wim | 0:d93c23711ca8 | 25 | /** Constructor for class for driving Princeton PT6315 VFD controller |
wim | 0:d93c23711ca8 | 26 | * |
wim | 0:d93c23711ca8 | 27 | * @brief Supports 4 Grids of 24 Segments upto 12 Grids of 16 Segments. Also supports a scanned keyboard of upto 32 keys and 4 LEDs. |
wim | 0:d93c23711ca8 | 28 | * SPI bus interface device. |
wim | 0:d93c23711ca8 | 29 | * |
wim | 0:d93c23711ca8 | 30 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:d93c23711ca8 | 31 | * @param Mode selects either number of Digits and Segments |
wim | 0:d93c23711ca8 | 32 | */ |
wim | 0:d93c23711ca8 | 33 | PT6315::PT6315(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode) : _spi(mosi,miso,sclk), _cs(cs), _mode(mode) { |
wim | 0:d93c23711ca8 | 34 | |
wim | 0:d93c23711ca8 | 35 | _init(); |
wim | 0:d93c23711ca8 | 36 | } |
wim | 0:d93c23711ca8 | 37 | |
wim | 0:d93c23711ca8 | 38 | /** Init the SPI interface and the controller |
wim | 0:d93c23711ca8 | 39 | * @param none |
wim | 0:d93c23711ca8 | 40 | * @return none |
wim | 0:d93c23711ca8 | 41 | */ |
wim | 0:d93c23711ca8 | 42 | void PT6315::_init(){ |
wim | 0:d93c23711ca8 | 43 | |
wim | 0:d93c23711ca8 | 44 | //init SPI |
wim | 0:d93c23711ca8 | 45 | _cs=1; |
wim | 0:d93c23711ca8 | 46 | _spi.format(8,3); //PT6315 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge) |
wim | 0:d93c23711ca8 | 47 | // _spi.frequency(100000); |
wim | 0:d93c23711ca8 | 48 | _spi.frequency(500000); |
wim | 0:d93c23711ca8 | 49 | |
wim | 0:d93c23711ca8 | 50 | //init controller |
wim | 0:d93c23711ca8 | 51 | _writeCmd(PT6315_MODE_SET_CMD, _mode); // Mode set command |
wim | 0:d93c23711ca8 | 52 | |
wim | 0:d93c23711ca8 | 53 | _display = PT6315_DSP_ON; |
wim | 0:d93c23711ca8 | 54 | _bright = PT6315_BRT_DEF; |
wim | 0:d93c23711ca8 | 55 | _writeCmd(PT6315_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:d93c23711ca8 | 56 | |
wim | 0:d93c23711ca8 | 57 | _writeCmd(PT6315_DATA_SET_CMD, PT6315_DATA_WR | PT6315_ADDR_INC | PT6315_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:d93c23711ca8 | 58 | } |
wim | 0:d93c23711ca8 | 59 | |
wim | 0:d93c23711ca8 | 60 | |
wim | 0:d93c23711ca8 | 61 | /** Clear the screen and locate to 0 |
wim | 0:d93c23711ca8 | 62 | */ |
wim | 0:d93c23711ca8 | 63 | void PT6315::cls() { |
wim | 0:d93c23711ca8 | 64 | |
wim | 0:d93c23711ca8 | 65 | _cs=0; |
wim | 0:d93c23711ca8 | 66 | wait_us(1); |
wim | 0:d93c23711ca8 | 67 | _spi.write(_flip(PT6315_ADDR_SET_CMD | 0x00)); // Address set cmd, 0 |
wim | 0:d93c23711ca8 | 68 | |
wim | 0:d93c23711ca8 | 69 | for (int cnt=0; cnt<PT6315_DISPLAY_MEM; cnt++) { |
wim | 0:d93c23711ca8 | 70 | _spi.write(0x00); // data |
wim | 0:d93c23711ca8 | 71 | } |
wim | 0:d93c23711ca8 | 72 | |
wim | 0:d93c23711ca8 | 73 | wait_us(1); |
wim | 0:d93c23711ca8 | 74 | _cs=1; |
wim | 0:d93c23711ca8 | 75 | |
wim | 0:d93c23711ca8 | 76 | } |
wim | 0:d93c23711ca8 | 77 | |
wim | 0:d93c23711ca8 | 78 | /** Set Brightness |
wim | 0:d93c23711ca8 | 79 | * |
wim | 0:d93c23711ca8 | 80 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle) |
wim | 0:d93c23711ca8 | 81 | * @return none |
wim | 0:d93c23711ca8 | 82 | */ |
wim | 0:d93c23711ca8 | 83 | void PT6315::setBrightness(char brightness){ |
wim | 0:d93c23711ca8 | 84 | |
wim | 0:d93c23711ca8 | 85 | _bright = brightness & PT6315_BRT_MSK; // mask invalid bits |
wim | 0:d93c23711ca8 | 86 | |
wim | 0:d93c23711ca8 | 87 | _writeCmd(PT6315_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:d93c23711ca8 | 88 | |
wim | 0:d93c23711ca8 | 89 | } |
wim | 0:d93c23711ca8 | 90 | |
wim | 0:d93c23711ca8 | 91 | /** Set the Display mode On/off |
wim | 0:d93c23711ca8 | 92 | * |
wim | 0:d93c23711ca8 | 93 | * @param bool display mode |
wim | 0:d93c23711ca8 | 94 | */ |
wim | 0:d93c23711ca8 | 95 | void PT6315::setDisplay(bool on) { |
wim | 0:d93c23711ca8 | 96 | |
wim | 0:d93c23711ca8 | 97 | if (on) { |
wim | 0:d93c23711ca8 | 98 | _display = PT6315_DSP_ON; |
wim | 0:d93c23711ca8 | 99 | } |
wim | 0:d93c23711ca8 | 100 | else { |
wim | 0:d93c23711ca8 | 101 | _display = PT6315_DSP_OFF; |
wim | 0:d93c23711ca8 | 102 | } |
wim | 0:d93c23711ca8 | 103 | |
wim | 0:d93c23711ca8 | 104 | _writeCmd(PT6315_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:d93c23711ca8 | 105 | } |
wim | 0:d93c23711ca8 | 106 | |
wim | 0:d93c23711ca8 | 107 | /** Write databyte to PT6315 |
wim | 0:d93c23711ca8 | 108 | * @param int address display memory location to write byte |
wim | 0:d93c23711ca8 | 109 | * @param char data byte written at given address |
wim | 0:d93c23711ca8 | 110 | * @return none |
wim | 0:d93c23711ca8 | 111 | */ |
wim | 0:d93c23711ca8 | 112 | void PT6315::writeData(int address, char data) { |
wim | 0:d93c23711ca8 | 113 | _cs=0; |
wim | 0:d93c23711ca8 | 114 | wait_us(1); |
wim | 0:d93c23711ca8 | 115 | _spi.write(_flip(PT6315_ADDR_SET_CMD | (address & PT6315_ADDR_MSK))); // Set Address cmd |
wim | 0:d93c23711ca8 | 116 | |
wim | 0:d93c23711ca8 | 117 | _spi.write(_flip(data)); // data |
wim | 0:d93c23711ca8 | 118 | |
wim | 0:d93c23711ca8 | 119 | wait_us(1); |
wim | 0:d93c23711ca8 | 120 | _cs=1; |
wim | 0:d93c23711ca8 | 121 | |
wim | 0:d93c23711ca8 | 122 | } |
wim | 0:d93c23711ca8 | 123 | |
wim | 0:d93c23711ca8 | 124 | /** Write Display datablock to PT6315 |
wim | 0:d93c23711ca8 | 125 | * @param DisplayData_t data Array of PT6315_DISPLAY_MEM (=48) bytes for displaydata (starting at address 0) |
wim | 0:d93c23711ca8 | 126 | * @param length number bytes to write (valid range 0..PT6315_DISPLAY_MEM (=48), starting at address 0) |
wim | 0:d93c23711ca8 | 127 | * @return none |
wim | 0:d93c23711ca8 | 128 | */ |
wim | 0:d93c23711ca8 | 129 | void PT6315::writeData(DisplayData_t data, int length) { |
wim | 0:d93c23711ca8 | 130 | _cs=0; |
wim | 0:d93c23711ca8 | 131 | wait_us(1); |
wim | 0:d93c23711ca8 | 132 | _spi.write(_flip(PT6315_ADDR_SET_CMD | 0x00)); // Set Address at 0 |
wim | 0:d93c23711ca8 | 133 | |
wim | 0:d93c23711ca8 | 134 | // sanity check |
wim | 0:d93c23711ca8 | 135 | if (length < 0) {length = 0;} |
wim | 0:d93c23711ca8 | 136 | if (length > PT6315_DISPLAY_MEM) {length = PT6315_DISPLAY_MEM;} |
wim | 0:d93c23711ca8 | 137 | |
wim | 0:d93c23711ca8 | 138 | // for (int idx=0; idx<PT6315_DISPLAY_MEM; idx++) { |
wim | 0:d93c23711ca8 | 139 | for (int idx=0; idx<length; idx++) { |
wim | 0:d93c23711ca8 | 140 | _spi.write(_flip(data[idx])); // data |
wim | 0:d93c23711ca8 | 141 | } |
wim | 0:d93c23711ca8 | 142 | |
wim | 0:d93c23711ca8 | 143 | wait_us(1); |
wim | 0:d93c23711ca8 | 144 | _cs=1; |
wim | 0:d93c23711ca8 | 145 | |
wim | 0:d93c23711ca8 | 146 | } |
wim | 0:d93c23711ca8 | 147 | |
wim | 0:d93c23711ca8 | 148 | /** Read keydata block from PT6315 |
wim | 0:d93c23711ca8 | 149 | * @param *keydata Ptr to Array of PT6315_KEY_MEM (=4) bytes for keydata |
wim | 0:d93c23711ca8 | 150 | * @return bool keypress True when at least one key was pressed |
wim | 0:d93c23711ca8 | 151 | * |
wim | 0:d93c23711ca8 | 152 | * Note: Due to the hardware configuration the PT6315 key matrix scanner will detect multiple keys pressed at same time, |
wim | 0:d93c23711ca8 | 153 | * but this may also result in some spurious keys being set in keypress data array. |
wim | 0:d93c23711ca8 | 154 | * It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting. |
wim | 0:d93c23711ca8 | 155 | */ |
wim | 0:d93c23711ca8 | 156 | bool PT6315::getKeys(KeyData_t *keydata) { |
wim | 0:d93c23711ca8 | 157 | int keypress = 0; |
wim | 0:d93c23711ca8 | 158 | char data; |
wim | 0:d93c23711ca8 | 159 | |
wim | 0:d93c23711ca8 | 160 | // Read keys |
wim | 0:d93c23711ca8 | 161 | _cs=0; |
wim | 0:d93c23711ca8 | 162 | wait_us(1); |
wim | 0:d93c23711ca8 | 163 | |
wim | 0:d93c23711ca8 | 164 | // Enable Key Read mode |
wim | 0:d93c23711ca8 | 165 | _spi.write(_flip(PT6315_DATA_SET_CMD | PT6315_KEY_RD | PT6315_ADDR_INC | PT6315_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data |
wim | 0:d93c23711ca8 | 166 | |
wim | 0:d93c23711ca8 | 167 | for (int idx=0; idx < PT6315_KEY_MEM; idx++) { |
wim | 0:d93c23711ca8 | 168 | data = _flip(_spi.write(0xFF)); // read keys and correct bitorder |
wim | 0:d93c23711ca8 | 169 | |
wim | 0:d93c23711ca8 | 170 | data = data & PT6315_KEY_MSK; // Mask valid bits |
wim | 0:d93c23711ca8 | 171 | if (data != 0) { // Check for any pressed key |
wim | 0:d93c23711ca8 | 172 | for (int bit=0; bit < 8; bit++) { |
wim | 0:d93c23711ca8 | 173 | if (data & (1 << bit)) {keypress++;} // Test all significant bits |
wim | 0:d93c23711ca8 | 174 | } |
wim | 0:d93c23711ca8 | 175 | } |
wim | 0:d93c23711ca8 | 176 | |
wim | 0:d93c23711ca8 | 177 | (*keydata)[idx] = data; // Store keydata after correcting bitorder |
wim | 0:d93c23711ca8 | 178 | } |
wim | 0:d93c23711ca8 | 179 | |
wim | 0:d93c23711ca8 | 180 | wait_us(1); |
wim | 0:d93c23711ca8 | 181 | _cs=1; |
wim | 0:d93c23711ca8 | 182 | |
wim | 0:d93c23711ca8 | 183 | // Restore Data Write mode |
wim | 0:d93c23711ca8 | 184 | _writeCmd(PT6315_DATA_SET_CMD, PT6315_DATA_WR | PT6315_ADDR_INC | PT6315_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:d93c23711ca8 | 185 | |
wim | 0:d93c23711ca8 | 186 | #if(1) |
wim | 0:d93c23711ca8 | 187 | // Dismiss multiple keypresses at same time |
wim | 0:d93c23711ca8 | 188 | return (keypress == 1); |
wim | 0:d93c23711ca8 | 189 | #else |
wim | 0:d93c23711ca8 | 190 | // Allow multiple keypress and accept possible spurious keys |
wim | 0:d93c23711ca8 | 191 | return (keypress > 0); |
wim | 0:d93c23711ca8 | 192 | #endif |
wim | 0:d93c23711ca8 | 193 | } |
wim | 0:d93c23711ca8 | 194 | |
wim | 0:d93c23711ca8 | 195 | /** Set LEDs |
wim | 0:d93c23711ca8 | 196 | * |
wim | 0:d93c23711ca8 | 197 | * @param char leds (4 least significant bits) |
wim | 0:d93c23711ca8 | 198 | * @return none |
wim | 0:d93c23711ca8 | 199 | */ |
wim | 0:d93c23711ca8 | 200 | void PT6315::setLED (char leds) { |
wim | 0:d93c23711ca8 | 201 | |
wim | 0:d93c23711ca8 | 202 | // Set LEDs |
wim | 0:d93c23711ca8 | 203 | _cs=0; |
wim | 0:d93c23711ca8 | 204 | wait_us(1); |
wim | 0:d93c23711ca8 | 205 | |
wim | 0:d93c23711ca8 | 206 | // Enable LED Write mode |
wim | 0:d93c23711ca8 | 207 | _spi.write(_flip(PT6315_DATA_SET_CMD | PT6315_LED_WR | PT6315_ADDR_INC | PT6315_MODE_NORM)); // Data set cmd, normal mode, auto incr, write data |
wim | 0:d93c23711ca8 | 208 | |
wim | 0:d93c23711ca8 | 209 | _spi.write(_flip(leds & PT6315_LED_MSK)); // write LEDs in correct bitorder |
wim | 0:d93c23711ca8 | 210 | |
wim | 0:d93c23711ca8 | 211 | wait_us(1); |
wim | 0:d93c23711ca8 | 212 | _cs=1; |
wim | 0:d93c23711ca8 | 213 | |
wim | 0:d93c23711ca8 | 214 | // Restore Data Write mode |
wim | 0:d93c23711ca8 | 215 | _writeCmd(PT6315_DATA_SET_CMD, PT6315_DATA_WR | PT6315_ADDR_INC | PT6315_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:d93c23711ca8 | 216 | } |
wim | 0:d93c23711ca8 | 217 | |
wim | 0:d93c23711ca8 | 218 | |
wim | 0:d93c23711ca8 | 219 | |
wim | 0:d93c23711ca8 | 220 | /** Helper to reverse all command or databits. The PT6315 expects LSB first, whereas SPI is MSB first |
wim | 0:d93c23711ca8 | 221 | * @param char data |
wim | 0:d93c23711ca8 | 222 | * @return bitreversed data |
wim | 0:d93c23711ca8 | 223 | */ |
wim | 0:d93c23711ca8 | 224 | char PT6315::_flip(char data) { |
wim | 0:d93c23711ca8 | 225 | char value=0; |
wim | 0:d93c23711ca8 | 226 | |
wim | 0:d93c23711ca8 | 227 | if (data & 0x01) {value |= 0x80;} ; |
wim | 0:d93c23711ca8 | 228 | if (data & 0x02) {value |= 0x40;} ; |
wim | 0:d93c23711ca8 | 229 | if (data & 0x04) {value |= 0x20;} ; |
wim | 0:d93c23711ca8 | 230 | if (data & 0x08) {value |= 0x10;} ; |
wim | 0:d93c23711ca8 | 231 | if (data & 0x10) {value |= 0x08;} ; |
wim | 0:d93c23711ca8 | 232 | if (data & 0x20) {value |= 0x04;} ; |
wim | 0:d93c23711ca8 | 233 | if (data & 0x40) {value |= 0x02;} ; |
wim | 0:d93c23711ca8 | 234 | if (data & 0x80) {value |= 0x01;} ; |
wim | 0:d93c23711ca8 | 235 | return value; |
wim | 0:d93c23711ca8 | 236 | } |
wim | 0:d93c23711ca8 | 237 | |
wim | 0:d93c23711ca8 | 238 | |
wim | 0:d93c23711ca8 | 239 | /** Write command and parameter to PT6315 |
wim | 0:d93c23711ca8 | 240 | * @param int cmd Command byte |
wim | 0:d93c23711ca8 | 241 | * &Param int data Parameters for command |
wim | 0:d93c23711ca8 | 242 | * @return none |
wim | 0:d93c23711ca8 | 243 | */ |
wim | 0:d93c23711ca8 | 244 | void PT6315::_writeCmd(int cmd, int data){ |
wim | 0:d93c23711ca8 | 245 | |
wim | 0:d93c23711ca8 | 246 | _cs=0; |
wim | 0:d93c23711ca8 | 247 | wait_us(1); |
wim | 0:d93c23711ca8 | 248 | |
wim | 0:d93c23711ca8 | 249 | _spi.write(_flip( (cmd & PT6315_CMD_MSK) | (data & ~PT6315_CMD_MSK))); |
wim | 0:d93c23711ca8 | 250 | |
wim | 0:d93c23711ca8 | 251 | wait_us(1); |
wim | 0:d93c23711ca8 | 252 | _cs=1; |
wim | 0:d93c23711ca8 | 253 | |
wim | 0:d93c23711ca8 | 254 | }; |
wim | 0:d93c23711ca8 | 255 | |
wim | 0:d93c23711ca8 | 256 | |
wim | 0:d93c23711ca8 | 257 | |
wim | 0:d93c23711ca8 | 258 | #if (DVDR3510_TEST == 1) |
wim | 0:d93c23711ca8 | 259 | /** Constructor for class for driving Princeton PT6315 VFD controller as used in DVDR3510 |
wim | 0:d93c23711ca8 | 260 | * |
wim | 0:d93c23711ca8 | 261 | * @brief Supports 11 Grids of 17 Segments and Icons (8 digits of 14 Segments plus some icons). |
wim | 0:d93c23711ca8 | 262 | * Also supports a scanned keyboard of 11 keys and 1 LED. |
wim | 0:d93c23711ca8 | 263 | * |
wim | 0:d93c23711ca8 | 264 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:d93c23711ca8 | 265 | */ |
wim | 0:d93c23711ca8 | 266 | PT6315_DVDR3510::PT6315_DVDR3510(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6315(mosi, miso, sclk, cs, Grid11_Seg17) { |
wim | 0:d93c23711ca8 | 267 | _column = 0; |
wim | 0:d93c23711ca8 | 268 | _columns = DVDR3510_NR_DIGITS; |
wim | 0:d93c23711ca8 | 269 | } |
wim | 0:d93c23711ca8 | 270 | |
wim | 0:d93c23711ca8 | 271 | #if(0) |
wim | 0:d93c23711ca8 | 272 | #if DOXYGEN_ONLY |
wim | 0:d93c23711ca8 | 273 | /** Write a character to the LCD |
wim | 0:d93c23711ca8 | 274 | * |
wim | 0:d93c23711ca8 | 275 | * @param c The character to write to the display |
wim | 0:d93c23711ca8 | 276 | */ |
wim | 0:d93c23711ca8 | 277 | int putc(int c); |
wim | 0:d93c23711ca8 | 278 | |
wim | 0:d93c23711ca8 | 279 | /** Write a formatted string to the LCD |
wim | 0:d93c23711ca8 | 280 | * |
wim | 0:d93c23711ca8 | 281 | * @param format A printf-style format string, followed by the |
wim | 0:d93c23711ca8 | 282 | * variables to use in formatting the string. |
wim | 0:d93c23711ca8 | 283 | */ |
wim | 0:d93c23711ca8 | 284 | int printf(const char* format, ...); |
wim | 0:d93c23711ca8 | 285 | #endif |
wim | 0:d93c23711ca8 | 286 | #endif |
wim | 0:d93c23711ca8 | 287 | |
wim | 0:d93c23711ca8 | 288 | /** Locate cursor to a screen column |
wim | 0:d93c23711ca8 | 289 | * |
wim | 0:d93c23711ca8 | 290 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:d93c23711ca8 | 291 | */ |
wim | 0:d93c23711ca8 | 292 | void PT6315_DVDR3510::locate(int column) { |
wim | 0:d93c23711ca8 | 293 | //sanity check |
wim | 0:d93c23711ca8 | 294 | if (column < 0) {column = 0;} |
wim | 0:d93c23711ca8 | 295 | if (column > (_columns - 1)) {column = _columns - 1;} |
wim | 0:d93c23711ca8 | 296 | |
wim | 0:d93c23711ca8 | 297 | _column = column; |
wim | 0:d93c23711ca8 | 298 | } |
wim | 0:d93c23711ca8 | 299 | |
wim | 0:d93c23711ca8 | 300 | |
wim | 0:d93c23711ca8 | 301 | /** Number of screen columns |
wim | 0:d93c23711ca8 | 302 | * |
wim | 0:d93c23711ca8 | 303 | * @param none |
wim | 0:d93c23711ca8 | 304 | * @return columns |
wim | 0:d93c23711ca8 | 305 | */ |
wim | 0:d93c23711ca8 | 306 | int PT6315_DVDR3510::columns() { |
wim | 0:d93c23711ca8 | 307 | return _columns; |
wim | 0:d93c23711ca8 | 308 | } |
wim | 0:d93c23711ca8 | 309 | |
wim | 0:d93c23711ca8 | 310 | |
wim | 0:d93c23711ca8 | 311 | /** Clear the screen and locate to 0 |
wim | 0:d93c23711ca8 | 312 | * @param bool clrAll Clear Icons also (default = false) |
wim | 0:d93c23711ca8 | 313 | */ |
wim | 0:d93c23711ca8 | 314 | void PT6315_DVDR3510::cls(bool clrAll) { |
wim | 0:d93c23711ca8 | 315 | int idx; |
wim | 0:d93c23711ca8 | 316 | |
wim | 0:d93c23711ca8 | 317 | if (clrAll) { |
wim | 0:d93c23711ca8 | 318 | //clear local buffer (including Icons) |
wim | 0:d93c23711ca8 | 319 | for (idx=0; idx < (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID); idx++) { |
wim | 0:d93c23711ca8 | 320 | _displaybuffer[idx] = 0x00; |
wim | 0:d93c23711ca8 | 321 | } |
wim | 0:d93c23711ca8 | 322 | } |
wim | 0:d93c23711ca8 | 323 | else { |
wim | 0:d93c23711ca8 | 324 | //clear local buffer (preserving Icons) |
wim | 0:d93c23711ca8 | 325 | for (int grd=0; grd < DVDR3510_NR_GRIDS; grd++) { |
wim | 0:d93c23711ca8 | 326 | idx = grd * PT6315_BYTES_PER_GRID; // 3 bytes for every Grid |
wim | 0:d93c23711ca8 | 327 | _displaybuffer[idx ] = _displaybuffer[idx ] & MASK_ICON_GRID[grd][0]; |
wim | 0:d93c23711ca8 | 328 | _displaybuffer[idx + 1] = _displaybuffer[idx + 1] & MASK_ICON_GRID[grd][1]; |
wim | 0:d93c23711ca8 | 329 | _displaybuffer[idx + 2] = _displaybuffer[idx + 2] & MASK_ICON_GRID[grd][2]; |
wim | 0:d93c23711ca8 | 330 | } |
wim | 0:d93c23711ca8 | 331 | } |
wim | 0:d93c23711ca8 | 332 | |
wim | 0:d93c23711ca8 | 333 | writeData(_displaybuffer, (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)); |
wim | 0:d93c23711ca8 | 334 | |
wim | 0:d93c23711ca8 | 335 | _column = 0; |
wim | 0:d93c23711ca8 | 336 | } |
wim | 0:d93c23711ca8 | 337 | |
wim | 0:d93c23711ca8 | 338 | /** Set Icon |
wim | 0:d93c23711ca8 | 339 | * |
wim | 0:d93c23711ca8 | 340 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:d93c23711ca8 | 341 | * @return none |
wim | 0:d93c23711ca8 | 342 | */ |
wim | 0:d93c23711ca8 | 343 | void PT6315_DVDR3510::setIcon(Icon icon) { |
wim | 0:d93c23711ca8 | 344 | int addr, icn; |
wim | 0:d93c23711ca8 | 345 | |
wim | 0:d93c23711ca8 | 346 | icn = icon & 0xFFFFFF; |
wim | 0:d93c23711ca8 | 347 | addr = (icon >> 24) & 0xFF; |
wim | 0:d93c23711ca8 | 348 | addr = (addr - 1) * PT6315_BYTES_PER_GRID; // 3 Bytes for every Grid |
wim | 0:d93c23711ca8 | 349 | |
wim | 0:d93c23711ca8 | 350 | //Save char...and set bits for icon to write |
wim | 0:d93c23711ca8 | 351 | _displaybuffer[addr ] = _displaybuffer[addr ] | LO(icn); |
wim | 0:d93c23711ca8 | 352 | _displaybuffer[addr + 1] = _displaybuffer[addr + 1] | MD(icn); |
wim | 0:d93c23711ca8 | 353 | _displaybuffer[addr + 2] = _displaybuffer[addr + 2] | HI(icn); |
wim | 0:d93c23711ca8 | 354 | writeData(_displaybuffer, (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)); |
wim | 0:d93c23711ca8 | 355 | } |
wim | 0:d93c23711ca8 | 356 | |
wim | 0:d93c23711ca8 | 357 | /** Clr Icon |
wim | 0:d93c23711ca8 | 358 | * |
wim | 0:d93c23711ca8 | 359 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:d93c23711ca8 | 360 | * @return none |
wim | 0:d93c23711ca8 | 361 | */ |
wim | 0:d93c23711ca8 | 362 | void PT6315_DVDR3510::clrIcon(Icon icon) { |
wim | 0:d93c23711ca8 | 363 | int addr, icn; |
wim | 0:d93c23711ca8 | 364 | |
wim | 0:d93c23711ca8 | 365 | icn = icon & 0xFFFFFF; |
wim | 0:d93c23711ca8 | 366 | addr = (icon >> 24) & 0xFF; |
wim | 0:d93c23711ca8 | 367 | addr = (addr - 1) * PT6315_BYTES_PER_GRID; // 3 Bytes for every Grid |
wim | 0:d93c23711ca8 | 368 | |
wim | 0:d93c23711ca8 | 369 | //Save char...and clr bits for icon to write |
wim | 0:d93c23711ca8 | 370 | _displaybuffer[addr ] = _displaybuffer[addr ] & ~LO(icn); |
wim | 0:d93c23711ca8 | 371 | _displaybuffer[addr + 1] = _displaybuffer[addr + 1] & ~MD(icn); |
wim | 0:d93c23711ca8 | 372 | _displaybuffer[addr + 2] = _displaybuffer[addr + 2] & ~HI(icn); |
wim | 0:d93c23711ca8 | 373 | writeData(_displaybuffer, (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)); |
wim | 0:d93c23711ca8 | 374 | } |
wim | 0:d93c23711ca8 | 375 | |
wim | 0:d93c23711ca8 | 376 | |
wim | 0:d93c23711ca8 | 377 | /** Set User Defined Characters (UDC) |
wim | 0:d93c23711ca8 | 378 | * |
wim | 0:d93c23711ca8 | 379 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 0:d93c23711ca8 | 380 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 0:d93c23711ca8 | 381 | */ |
wim | 0:d93c23711ca8 | 382 | void PT6315_DVDR3510::setUDC(unsigned char udc_idx, int udc_data) { |
wim | 0:d93c23711ca8 | 383 | |
wim | 0:d93c23711ca8 | 384 | //Sanity check |
wim | 0:d93c23711ca8 | 385 | if (udc_idx > (DVDR3510_NR_UDC-1)) { |
wim | 0:d93c23711ca8 | 386 | return; |
wim | 0:d93c23711ca8 | 387 | } |
wim | 0:d93c23711ca8 | 388 | |
wim | 0:d93c23711ca8 | 389 | // Mask out Icon bits? |
wim | 0:d93c23711ca8 | 390 | _UDC_16S[udc_idx] = udc_data & 0xFFFF; |
wim | 0:d93c23711ca8 | 391 | } |
wim | 0:d93c23711ca8 | 392 | |
wim | 0:d93c23711ca8 | 393 | /** Write a single character (Stream implementation) |
wim | 0:d93c23711ca8 | 394 | */ |
wim | 0:d93c23711ca8 | 395 | int PT6315_DVDR3510::_putc(int value) { |
wim | 0:d93c23711ca8 | 396 | bool validChar = false; |
wim | 0:d93c23711ca8 | 397 | short pattern = 0x0000; |
wim | 0:d93c23711ca8 | 398 | int addr; |
wim | 0:d93c23711ca8 | 399 | |
wim | 0:d93c23711ca8 | 400 | if ((value == '\n') || (value == '\r')) { |
wim | 0:d93c23711ca8 | 401 | //No character to write |
wim | 0:d93c23711ca8 | 402 | validChar = false; |
wim | 0:d93c23711ca8 | 403 | |
wim | 0:d93c23711ca8 | 404 | //Update Cursor |
wim | 0:d93c23711ca8 | 405 | _column = 0; |
wim | 0:d93c23711ca8 | 406 | } |
wim | 0:d93c23711ca8 | 407 | else if ((value >= 0) && (value < DVDR3510_NR_UDC)) { |
wim | 0:d93c23711ca8 | 408 | //Character to write |
wim | 0:d93c23711ca8 | 409 | validChar = true; |
wim | 0:d93c23711ca8 | 410 | pattern = _UDC_16S[value]; |
wim | 0:d93c23711ca8 | 411 | } |
wim | 0:d93c23711ca8 | 412 | #if (SHOW_ASCII == 1) |
wim | 0:d93c23711ca8 | 413 | //display all ASCII characters |
wim | 0:d93c23711ca8 | 414 | else if ((value >= FONT_16S_START) && (value <= FONT_16S_END)) { |
wim | 0:d93c23711ca8 | 415 | //Character to write |
wim | 0:d93c23711ca8 | 416 | validChar = true; |
wim | 0:d93c23711ca8 | 417 | pattern = FONT_16S[value - FONT_16S_START]; |
wim | 0:d93c23711ca8 | 418 | } // else |
wim | 0:d93c23711ca8 | 419 | #else |
wim | 0:d93c23711ca8 | 420 | //display only digits and hex characters |
wim | 0:d93c23711ca8 | 421 | else if (value == '-') { |
wim | 0:d93c23711ca8 | 422 | //Character to write |
wim | 0:d93c23711ca8 | 423 | validChar = true; |
wim | 0:d93c23711ca8 | 424 | pattern = C16_MIN; |
wim | 0:d93c23711ca8 | 425 | } |
wim | 0:d93c23711ca8 | 426 | else if ((value >= (int)'0') && (value <= (int) '9')) { |
wim | 0:d93c23711ca8 | 427 | //Character to write |
wim | 0:d93c23711ca8 | 428 | validChar = true; |
wim | 0:d93c23711ca8 | 429 | pattern = FONT_16S[value - (int) '0']; |
wim | 0:d93c23711ca8 | 430 | } |
wim | 0:d93c23711ca8 | 431 | else if ((value >= (int) 'A') && (value <= (int) 'F')) { |
wim | 0:d93c23711ca8 | 432 | //Character to write |
wim | 0:d93c23711ca8 | 433 | validChar = true; |
wim | 0:d93c23711ca8 | 434 | pattern = FONT_16S[10 + value - (int) 'A']; |
wim | 0:d93c23711ca8 | 435 | } |
wim | 0:d93c23711ca8 | 436 | else if ((value >= (int) 'a') && (value <= (int) 'f')) { |
wim | 0:d93c23711ca8 | 437 | //Character to write |
wim | 0:d93c23711ca8 | 438 | validChar = true; |
wim | 0:d93c23711ca8 | 439 | pattern = FONT_16S[10 + value - (int) 'a']; |
wim | 0:d93c23711ca8 | 440 | } //else |
wim | 0:d93c23711ca8 | 441 | #endif |
wim | 0:d93c23711ca8 | 442 | if (validChar) { |
wim | 0:d93c23711ca8 | 443 | //Character to write |
wim | 0:d93c23711ca8 | 444 | |
wim | 0:d93c23711ca8 | 445 | //Translate between _column and displaybuffer entries |
wim | 0:d93c23711ca8 | 446 | //Note that the DVDR3510 has eight 14 Segment digits/grids. |
wim | 0:d93c23711ca8 | 447 | //Some of these Grids also have icons that need to be preserved |
wim | 0:d93c23711ca8 | 448 | //_column == 0 => Grid1 => addr = 0 |
wim | 0:d93c23711ca8 | 449 | //_column == 1 => Grid2 => addr = 3 |
wim | 0:d93c23711ca8 | 450 | // .... |
wim | 0:d93c23711ca8 | 451 | //_column == 7 => Grid8 => addr = 21 |
wim | 0:d93c23711ca8 | 452 | addr = (_column * PT6315_BYTES_PER_GRID); // 3 Bytes for every Grid; |
wim | 0:d93c23711ca8 | 453 | |
wim | 0:d93c23711ca8 | 454 | //Save icons...and set bits for character to write |
wim | 0:d93c23711ca8 | 455 | _displaybuffer[addr] = (_displaybuffer[addr] & MASK_ICON_GRID[_column][0]) | LO(pattern); |
wim | 0:d93c23711ca8 | 456 | _displaybuffer[addr+1] = (_displaybuffer[addr+1] & MASK_ICON_GRID[_column][1]) | MD(pattern); |
wim | 0:d93c23711ca8 | 457 | _displaybuffer[addr+2] = (_displaybuffer[addr+2] & MASK_ICON_GRID[_column][2]) | HI(pattern); |
wim | 0:d93c23711ca8 | 458 | |
wim | 0:d93c23711ca8 | 459 | writeData(_displaybuffer, (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)); |
wim | 0:d93c23711ca8 | 460 | |
wim | 0:d93c23711ca8 | 461 | //Update Cursor |
wim | 0:d93c23711ca8 | 462 | _column++; |
wim | 0:d93c23711ca8 | 463 | if (_column > (DVDR3510_NR_DIGITS - 1)) { |
wim | 0:d93c23711ca8 | 464 | _column = 0; |
wim | 0:d93c23711ca8 | 465 | } |
wim | 0:d93c23711ca8 | 466 | |
wim | 0:d93c23711ca8 | 467 | } // if validChar |
wim | 0:d93c23711ca8 | 468 | |
wim | 0:d93c23711ca8 | 469 | return value; |
wim | 0:d93c23711ca8 | 470 | } |
wim | 0:d93c23711ca8 | 471 | |
wim | 0:d93c23711ca8 | 472 | // get a single character (Stream implementation) |
wim | 0:d93c23711ca8 | 473 | int PT6315_DVDR3510::_getc() { |
wim | 0:d93c23711ca8 | 474 | return -1; |
wim | 0:d93c23711ca8 | 475 | } |
wim | 0:d93c23711ca8 | 476 | #endif |