Library for Princeton PT6318 VFD controller Initial version for KUH8300.
PT6318.cpp@0:e5741b4e6a1a, 2016-02-01 (annotated)
- Committer:
- wim
- Date:
- Mon Feb 01 20:18:04 2016 +0000
- Revision:
- 0:e5741b4e6a1a
- Child:
- 1:a7a518dbca96
Library for PT6318 VFD Controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:e5741b4e6a1a | 1 | /* mbed PT6318 Library, for Princeton PT6318 VFD controller |
wim | 0:e5741b4e6a1a | 2 | * Copyright (c) 2016, v01: WH, Initial version, for KUH8300 code |
wim | 0:e5741b4e6a1a | 3 | * |
wim | 0:e5741b4e6a1a | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:e5741b4e6a1a | 5 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:e5741b4e6a1a | 6 | * in the Software without restriction, including without limitation the rights |
wim | 0:e5741b4e6a1a | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:e5741b4e6a1a | 8 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:e5741b4e6a1a | 9 | * furnished to do so, subject to the following conditions: |
wim | 0:e5741b4e6a1a | 10 | * |
wim | 0:e5741b4e6a1a | 11 | * The above copyright notice and this permission notice shall be included in |
wim | 0:e5741b4e6a1a | 12 | * all copies or substantial portions of the Software. |
wim | 0:e5741b4e6a1a | 13 | * |
wim | 0:e5741b4e6a1a | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:e5741b4e6a1a | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:e5741b4e6a1a | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:e5741b4e6a1a | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:e5741b4e6a1a | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:e5741b4e6a1a | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:e5741b4e6a1a | 20 | * THE SOFTWARE. |
wim | 0:e5741b4e6a1a | 21 | */ |
wim | 0:e5741b4e6a1a | 22 | #include "mbed.h" |
wim | 0:e5741b4e6a1a | 23 | #include "PT6318.h" |
wim | 0:e5741b4e6a1a | 24 | |
wim | 0:e5741b4e6a1a | 25 | /** Constructor for class for driving Princeton PT6318 VFD controller |
wim | 0:e5741b4e6a1a | 26 | * |
wim | 0:e5741b4e6a1a | 27 | * @brief Supports 8 Grids of 20 Segments upto 16 Grids of 12 Segments. Also supports a scanned keyboard of upto 32 keys, 4 switches and 5 LEDs. |
wim | 0:e5741b4e6a1a | 28 | * SPI bus interface device. |
wim | 0:e5741b4e6a1a | 29 | * |
wim | 0:e5741b4e6a1a | 30 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:e5741b4e6a1a | 31 | * @param Mode selects either number of Digits and Segments |
wim | 0:e5741b4e6a1a | 32 | */ |
wim | 0:e5741b4e6a1a | 33 | PT6318::PT6318(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode) : _spi(mosi,miso,sclk), _cs(cs), _mode(mode) { |
wim | 0:e5741b4e6a1a | 34 | |
wim | 0:e5741b4e6a1a | 35 | _init(); |
wim | 0:e5741b4e6a1a | 36 | } |
wim | 0:e5741b4e6a1a | 37 | |
wim | 0:e5741b4e6a1a | 38 | /** Init the SPI interface and the controller |
wim | 0:e5741b4e6a1a | 39 | * @param none |
wim | 0:e5741b4e6a1a | 40 | * @return none |
wim | 0:e5741b4e6a1a | 41 | */ |
wim | 0:e5741b4e6a1a | 42 | void PT6318::_init(){ |
wim | 0:e5741b4e6a1a | 43 | |
wim | 0:e5741b4e6a1a | 44 | //init SPI |
wim | 0:e5741b4e6a1a | 45 | _cs=1; |
wim | 0:e5741b4e6a1a | 46 | _spi.format(8,3); //PT6318 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge) |
wim | 0:e5741b4e6a1a | 47 | // _spi.frequency(100000); |
wim | 0:e5741b4e6a1a | 48 | _spi.frequency(500000); |
wim | 0:e5741b4e6a1a | 49 | |
wim | 0:e5741b4e6a1a | 50 | //init controller |
wim | 0:e5741b4e6a1a | 51 | _writeCmd(PT6318_MODE_SET_CMD, _mode); // Mode set command |
wim | 0:e5741b4e6a1a | 52 | |
wim | 0:e5741b4e6a1a | 53 | _display = PT6318_DSP_ON; |
wim | 0:e5741b4e6a1a | 54 | _bright = PT6318_BRT_DEF; |
wim | 0:e5741b4e6a1a | 55 | _writeCmd(PT6318_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:e5741b4e6a1a | 56 | |
wim | 0:e5741b4e6a1a | 57 | _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e5741b4e6a1a | 58 | } |
wim | 0:e5741b4e6a1a | 59 | |
wim | 0:e5741b4e6a1a | 60 | |
wim | 0:e5741b4e6a1a | 61 | /** Clear the screen and locate to 0 |
wim | 0:e5741b4e6a1a | 62 | */ |
wim | 0:e5741b4e6a1a | 63 | void PT6318::cls() { |
wim | 0:e5741b4e6a1a | 64 | |
wim | 0:e5741b4e6a1a | 65 | _cs=0; |
wim | 0:e5741b4e6a1a | 66 | wait_us(1); |
wim | 0:e5741b4e6a1a | 67 | _spi.write(_flip(PT6318_ADDR_SET_CMD | 0x00)); // Address set cmd, 0 |
wim | 0:e5741b4e6a1a | 68 | |
wim | 0:e5741b4e6a1a | 69 | for (int cnt=0; cnt<PT6318_DISPLAY_MEM; cnt++) { |
wim | 0:e5741b4e6a1a | 70 | _spi.write(0x00); // data |
wim | 0:e5741b4e6a1a | 71 | } |
wim | 0:e5741b4e6a1a | 72 | |
wim | 0:e5741b4e6a1a | 73 | wait_us(1); |
wim | 0:e5741b4e6a1a | 74 | _cs=1; |
wim | 0:e5741b4e6a1a | 75 | |
wim | 0:e5741b4e6a1a | 76 | } |
wim | 0:e5741b4e6a1a | 77 | |
wim | 0:e5741b4e6a1a | 78 | /** Set Brightness |
wim | 0:e5741b4e6a1a | 79 | * |
wim | 0:e5741b4e6a1a | 80 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle) |
wim | 0:e5741b4e6a1a | 81 | * @return none |
wim | 0:e5741b4e6a1a | 82 | */ |
wim | 0:e5741b4e6a1a | 83 | void PT6318::setBrightness(char brightness){ |
wim | 0:e5741b4e6a1a | 84 | |
wim | 0:e5741b4e6a1a | 85 | _bright = brightness & PT6318_BRT_MSK; // mask invalid bits |
wim | 0:e5741b4e6a1a | 86 | |
wim | 0:e5741b4e6a1a | 87 | _writeCmd(PT6318_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:e5741b4e6a1a | 88 | |
wim | 0:e5741b4e6a1a | 89 | } |
wim | 0:e5741b4e6a1a | 90 | |
wim | 0:e5741b4e6a1a | 91 | /** Set the Display mode On/off |
wim | 0:e5741b4e6a1a | 92 | * |
wim | 0:e5741b4e6a1a | 93 | * @param bool display mode |
wim | 0:e5741b4e6a1a | 94 | */ |
wim | 0:e5741b4e6a1a | 95 | void PT6318::setDisplay(bool on) { |
wim | 0:e5741b4e6a1a | 96 | |
wim | 0:e5741b4e6a1a | 97 | if (on) { |
wim | 0:e5741b4e6a1a | 98 | _display = PT6318_DSP_ON; |
wim | 0:e5741b4e6a1a | 99 | } |
wim | 0:e5741b4e6a1a | 100 | else { |
wim | 0:e5741b4e6a1a | 101 | _display = PT6318_DSP_OFF; |
wim | 0:e5741b4e6a1a | 102 | } |
wim | 0:e5741b4e6a1a | 103 | |
wim | 0:e5741b4e6a1a | 104 | _writeCmd(PT6318_DSP_CTRL_CMD, _display | _bright ); // Display control cmd, display on/off, brightness |
wim | 0:e5741b4e6a1a | 105 | } |
wim | 0:e5741b4e6a1a | 106 | |
wim | 0:e5741b4e6a1a | 107 | /** Write databyte to PT6318 |
wim | 0:e5741b4e6a1a | 108 | * @param char data byte written at given address |
wim | 0:e5741b4e6a1a | 109 | * @param int address display memory location to write byte |
wim | 0:e5741b4e6a1a | 110 | * @return none |
wim | 0:e5741b4e6a1a | 111 | */ |
wim | 0:e5741b4e6a1a | 112 | void PT6318::writeData(char data, int address) { |
wim | 0:e5741b4e6a1a | 113 | _cs=0; |
wim | 0:e5741b4e6a1a | 114 | wait_us(1); |
wim | 0:e5741b4e6a1a | 115 | _spi.write(_flip(PT6318_ADDR_SET_CMD | (address & PT6318_ADDR_MSK))); // Set Address cmd |
wim | 0:e5741b4e6a1a | 116 | |
wim | 0:e5741b4e6a1a | 117 | _spi.write(_flip(data)); // data |
wim | 0:e5741b4e6a1a | 118 | |
wim | 0:e5741b4e6a1a | 119 | wait_us(1); |
wim | 0:e5741b4e6a1a | 120 | _cs=1; |
wim | 0:e5741b4e6a1a | 121 | |
wim | 0:e5741b4e6a1a | 122 | } |
wim | 0:e5741b4e6a1a | 123 | |
wim | 0:e5741b4e6a1a | 124 | /** Write Display datablock to PT6318 |
wim | 0:e5741b4e6a1a | 125 | * @param DisplayData_t data Array of PT6318_DISPLAY_MEM (=48) bytes for displaydata (starting at address) |
wim | 0:e5741b4e6a1a | 126 | * @param length number bytes to write (valid range 0..PT6318_DISPLAY_MEM (=48), starting at address) |
wim | 0:e5741b4e6a1a | 127 | * @param int address display memory location to write byte |
wim | 0:e5741b4e6a1a | 128 | * @return none |
wim | 0:e5741b4e6a1a | 129 | */ |
wim | 0:e5741b4e6a1a | 130 | void PT6318::writeData(DisplayData_t data, int length, int address) { |
wim | 0:e5741b4e6a1a | 131 | _cs=0; |
wim | 0:e5741b4e6a1a | 132 | wait_us(1); |
wim | 0:e5741b4e6a1a | 133 | |
wim | 0:e5741b4e6a1a | 134 | // sanity check |
wim | 0:e5741b4e6a1a | 135 | address &= PT6318_ADDR_MSK; |
wim | 0:e5741b4e6a1a | 136 | if (length < 0) {length = 0;} |
wim | 0:e5741b4e6a1a | 137 | // if (length > PT6318_DISPLAY_MEM) {length = PT6318_DISPLAY_MEM;} |
wim | 0:e5741b4e6a1a | 138 | if ((address + length) > PT6318_DISPLAY_MEM) {length = PT6318_DISPLAY_MEM - address;} |
wim | 0:e5741b4e6a1a | 139 | |
wim | 0:e5741b4e6a1a | 140 | // _spi.write(_flip(PT6318_ADDR_SET_CMD | 0x00)); // Set Address at 0 |
wim | 0:e5741b4e6a1a | 141 | _spi.write(_flip(PT6318_ADDR_SET_CMD | address)); // Set Address |
wim | 0:e5741b4e6a1a | 142 | |
wim | 0:e5741b4e6a1a | 143 | // for (int idx=0; idx<PT6318_DISPLAY_MEM; idx++) { |
wim | 0:e5741b4e6a1a | 144 | for (int idx=0; idx<length; idx++) { |
wim | 0:e5741b4e6a1a | 145 | // _spi.write(_flip(data[idx])); // data |
wim | 0:e5741b4e6a1a | 146 | _spi.write(_flip(data[address + idx])); // data |
wim | 0:e5741b4e6a1a | 147 | } |
wim | 0:e5741b4e6a1a | 148 | |
wim | 0:e5741b4e6a1a | 149 | wait_us(1); |
wim | 0:e5741b4e6a1a | 150 | _cs=1; |
wim | 0:e5741b4e6a1a | 151 | } |
wim | 0:e5741b4e6a1a | 152 | |
wim | 0:e5741b4e6a1a | 153 | /** Read keydata block from PT6318 |
wim | 0:e5741b4e6a1a | 154 | * @param *keydata Ptr to Array of PT6318_KEY_MEM (=6) bytes for keydata |
wim | 0:e5741b4e6a1a | 155 | * @return bool keypress True when at least one key was pressed |
wim | 0:e5741b4e6a1a | 156 | * |
wim | 0:e5741b4e6a1a | 157 | * Note: Due to the hardware configuration the PT6318 key matrix scanner will detect multiple keys pressed at same time, |
wim | 0:e5741b4e6a1a | 158 | * but this may also result in some spurious keys being set in keypress data array. |
wim | 0:e5741b4e6a1a | 159 | * It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting. |
wim | 0:e5741b4e6a1a | 160 | */ |
wim | 0:e5741b4e6a1a | 161 | bool PT6318::getKeys(KeyData_t *keydata) { |
wim | 0:e5741b4e6a1a | 162 | int keypress = 0; |
wim | 0:e5741b4e6a1a | 163 | char data; |
wim | 0:e5741b4e6a1a | 164 | |
wim | 0:e5741b4e6a1a | 165 | // Read keys |
wim | 0:e5741b4e6a1a | 166 | _cs=0; |
wim | 0:e5741b4e6a1a | 167 | wait_us(1); |
wim | 0:e5741b4e6a1a | 168 | |
wim | 0:e5741b4e6a1a | 169 | // Enable Key Read mode |
wim | 0:e5741b4e6a1a | 170 | _spi.write(_flip(PT6318_DATA_SET_CMD | PT6318_KEY_RD | PT6318_ADDR_INC | PT6318_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data |
wim | 0:e5741b4e6a1a | 171 | |
wim | 0:e5741b4e6a1a | 172 | for (int idx=0; idx < PT6318_KEY_MEM; idx++) { |
wim | 0:e5741b4e6a1a | 173 | data = _flip(_spi.write(0xFF)); // read keys and correct bitorder |
wim | 0:e5741b4e6a1a | 174 | |
wim | 0:e5741b4e6a1a | 175 | data = data & PT6318_KEY_MSK; // Mask valid bits |
wim | 0:e5741b4e6a1a | 176 | if (data != 0) { // Check for any pressed key |
wim | 0:e5741b4e6a1a | 177 | for (int bit=0; bit < 8; bit++) { |
wim | 0:e5741b4e6a1a | 178 | if (data & (1 << bit)) {keypress++;} // Test all significant bits |
wim | 0:e5741b4e6a1a | 179 | } |
wim | 0:e5741b4e6a1a | 180 | } |
wim | 0:e5741b4e6a1a | 181 | |
wim | 0:e5741b4e6a1a | 182 | (*keydata)[idx] = data; // Store keydata after correcting bitorder |
wim | 0:e5741b4e6a1a | 183 | } |
wim | 0:e5741b4e6a1a | 184 | |
wim | 0:e5741b4e6a1a | 185 | wait_us(1); |
wim | 0:e5741b4e6a1a | 186 | _cs=1; |
wim | 0:e5741b4e6a1a | 187 | |
wim | 0:e5741b4e6a1a | 188 | // Restore Data Write mode |
wim | 0:e5741b4e6a1a | 189 | _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e5741b4e6a1a | 190 | |
wim | 0:e5741b4e6a1a | 191 | #if(1) |
wim | 0:e5741b4e6a1a | 192 | // Dismiss multiple keypresses at same time |
wim | 0:e5741b4e6a1a | 193 | return (keypress == 1); |
wim | 0:e5741b4e6a1a | 194 | #else |
wim | 0:e5741b4e6a1a | 195 | // Allow multiple keypress and accept possible spurious keys |
wim | 0:e5741b4e6a1a | 196 | return (keypress > 0); |
wim | 0:e5741b4e6a1a | 197 | #endif |
wim | 0:e5741b4e6a1a | 198 | } |
wim | 0:e5741b4e6a1a | 199 | |
wim | 0:e5741b4e6a1a | 200 | /** Read switches from PT6318 |
wim | 0:e5741b4e6a1a | 201 | * |
wim | 0:e5741b4e6a1a | 202 | * @param none |
wim | 0:e5741b4e6a1a | 203 | * @return char for switch data (4 least significant bits) |
wim | 0:e5741b4e6a1a | 204 | * |
wim | 0:e5741b4e6a1a | 205 | */ |
wim | 0:e5741b4e6a1a | 206 | char PT6318::getSwitches() { |
wim | 0:e5741b4e6a1a | 207 | char data; |
wim | 0:e5741b4e6a1a | 208 | |
wim | 0:e5741b4e6a1a | 209 | // Read switches |
wim | 0:e5741b4e6a1a | 210 | _cs=0; |
wim | 0:e5741b4e6a1a | 211 | wait_us(1); |
wim | 0:e5741b4e6a1a | 212 | |
wim | 0:e5741b4e6a1a | 213 | // Enable Switch Read mode |
wim | 0:e5741b4e6a1a | 214 | _spi.write(_flip(PT6318_DATA_SET_CMD | PT6318_SW_RD | PT6318_ADDR_INC | PT6318_MODE_NORM)); // Data set cmd, normal mode, auto incr, read data |
wim | 0:e5741b4e6a1a | 215 | |
wim | 0:e5741b4e6a1a | 216 | data = _flip(_spi.write(0xFF)) & PT6318_SW_MSK; // read switches and correct bitorder |
wim | 0:e5741b4e6a1a | 217 | |
wim | 0:e5741b4e6a1a | 218 | wait_us(1); |
wim | 0:e5741b4e6a1a | 219 | _cs=1; |
wim | 0:e5741b4e6a1a | 220 | |
wim | 0:e5741b4e6a1a | 221 | // Restore Data Write mode |
wim | 0:e5741b4e6a1a | 222 | _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e5741b4e6a1a | 223 | |
wim | 0:e5741b4e6a1a | 224 | return data; |
wim | 0:e5741b4e6a1a | 225 | } |
wim | 0:e5741b4e6a1a | 226 | |
wim | 0:e5741b4e6a1a | 227 | |
wim | 0:e5741b4e6a1a | 228 | /** Set LEDs |
wim | 0:e5741b4e6a1a | 229 | * |
wim | 0:e5741b4e6a1a | 230 | * @param char leds (4 least significant bits) |
wim | 0:e5741b4e6a1a | 231 | * @return none |
wim | 0:e5741b4e6a1a | 232 | */ |
wim | 0:e5741b4e6a1a | 233 | void PT6318::setLED (char leds) { |
wim | 0:e5741b4e6a1a | 234 | |
wim | 0:e5741b4e6a1a | 235 | // Set LEDs |
wim | 0:e5741b4e6a1a | 236 | _cs=0; |
wim | 0:e5741b4e6a1a | 237 | wait_us(1); |
wim | 0:e5741b4e6a1a | 238 | |
wim | 0:e5741b4e6a1a | 239 | // Enable LED Write mode |
wim | 0:e5741b4e6a1a | 240 | _spi.write(_flip(PT6318_DATA_SET_CMD | PT6318_LED_WR | PT6318_ADDR_INC | PT6318_MODE_NORM)); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e5741b4e6a1a | 241 | |
wim | 0:e5741b4e6a1a | 242 | _spi.write(_flip(leds & PT6318_LED_MSK)); // write LEDs in correct bitorder |
wim | 0:e5741b4e6a1a | 243 | |
wim | 0:e5741b4e6a1a | 244 | wait_us(1); |
wim | 0:e5741b4e6a1a | 245 | _cs=1; |
wim | 0:e5741b4e6a1a | 246 | |
wim | 0:e5741b4e6a1a | 247 | // Restore Data Write mode |
wim | 0:e5741b4e6a1a | 248 | _writeCmd(PT6318_DATA_SET_CMD, PT6318_DATA_WR | PT6318_ADDR_INC | PT6318_MODE_NORM); // Data set cmd, normal mode, auto incr, write data |
wim | 0:e5741b4e6a1a | 249 | } |
wim | 0:e5741b4e6a1a | 250 | |
wim | 0:e5741b4e6a1a | 251 | |
wim | 0:e5741b4e6a1a | 252 | |
wim | 0:e5741b4e6a1a | 253 | /** Helper to reverse all command or databits. The PT6318 expects LSB first, whereas SPI is MSB first |
wim | 0:e5741b4e6a1a | 254 | * @param char data |
wim | 0:e5741b4e6a1a | 255 | * @return bitreversed data |
wim | 0:e5741b4e6a1a | 256 | */ |
wim | 0:e5741b4e6a1a | 257 | char PT6318::_flip(char data) { |
wim | 0:e5741b4e6a1a | 258 | char value=0; |
wim | 0:e5741b4e6a1a | 259 | |
wim | 0:e5741b4e6a1a | 260 | if (data & 0x01) {value |= 0x80;} ; |
wim | 0:e5741b4e6a1a | 261 | if (data & 0x02) {value |= 0x40;} ; |
wim | 0:e5741b4e6a1a | 262 | if (data & 0x04) {value |= 0x20;} ; |
wim | 0:e5741b4e6a1a | 263 | if (data & 0x08) {value |= 0x10;} ; |
wim | 0:e5741b4e6a1a | 264 | if (data & 0x10) {value |= 0x08;} ; |
wim | 0:e5741b4e6a1a | 265 | if (data & 0x20) {value |= 0x04;} ; |
wim | 0:e5741b4e6a1a | 266 | if (data & 0x40) {value |= 0x02;} ; |
wim | 0:e5741b4e6a1a | 267 | if (data & 0x80) {value |= 0x01;} ; |
wim | 0:e5741b4e6a1a | 268 | return value; |
wim | 0:e5741b4e6a1a | 269 | } |
wim | 0:e5741b4e6a1a | 270 | |
wim | 0:e5741b4e6a1a | 271 | |
wim | 0:e5741b4e6a1a | 272 | /** Write command and parameter to PT6318 |
wim | 0:e5741b4e6a1a | 273 | * @param int cmd Command byte |
wim | 0:e5741b4e6a1a | 274 | * &Param int data Parameters for command |
wim | 0:e5741b4e6a1a | 275 | * @return none |
wim | 0:e5741b4e6a1a | 276 | */ |
wim | 0:e5741b4e6a1a | 277 | void PT6318::_writeCmd(int cmd, int data){ |
wim | 0:e5741b4e6a1a | 278 | |
wim | 0:e5741b4e6a1a | 279 | _cs=0; |
wim | 0:e5741b4e6a1a | 280 | wait_us(1); |
wim | 0:e5741b4e6a1a | 281 | |
wim | 0:e5741b4e6a1a | 282 | _spi.write(_flip( (cmd & PT6318_CMD_MSK) | (data & ~PT6318_CMD_MSK))); |
wim | 0:e5741b4e6a1a | 283 | |
wim | 0:e5741b4e6a1a | 284 | wait_us(1); |
wim | 0:e5741b4e6a1a | 285 | _cs=1; |
wim | 0:e5741b4e6a1a | 286 | |
wim | 0:e5741b4e6a1a | 287 | }; |
wim | 0:e5741b4e6a1a | 288 | |
wim | 0:e5741b4e6a1a | 289 | |
wim | 0:e5741b4e6a1a | 290 | |
wim | 0:e5741b4e6a1a | 291 | #if (KUH8300_TEST == 1) |
wim | 0:e5741b4e6a1a | 292 | /** Constructor for class for driving Princeton PT6318 VFD controller as used in KUH8300 |
wim | 0:e5741b4e6a1a | 293 | * |
wim | 0:e5741b4e6a1a | 294 | * @brief Supports 8 Grids of 20 Segments and Icons (8 1/2 digits of 14 Segments plus some icons). |
wim | 0:e5741b4e6a1a | 295 | * Also supports a scanned keyboard of 12 keys and 1 LED. |
wim | 0:e5741b4e6a1a | 296 | * |
wim | 0:e5741b4e6a1a | 297 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:e5741b4e6a1a | 298 | */ |
wim | 0:e5741b4e6a1a | 299 | PT6318_KUH8300::PT6318_KUH8300(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6318(mosi, miso, sclk, cs, Grid8_Seg20) { |
wim | 0:e5741b4e6a1a | 300 | _column = 0; |
wim | 0:e5741b4e6a1a | 301 | _columns = KUH8300_NR_DIGITS; |
wim | 0:e5741b4e6a1a | 302 | } |
wim | 0:e5741b4e6a1a | 303 | |
wim | 0:e5741b4e6a1a | 304 | #if(0) |
wim | 0:e5741b4e6a1a | 305 | #if DOXYGEN_ONLY |
wim | 0:e5741b4e6a1a | 306 | /** Write a character to the Display |
wim | 0:e5741b4e6a1a | 307 | * |
wim | 0:e5741b4e6a1a | 308 | * @param c The character to write to the display |
wim | 0:e5741b4e6a1a | 309 | */ |
wim | 0:e5741b4e6a1a | 310 | int putc(int c); |
wim | 0:e5741b4e6a1a | 311 | |
wim | 0:e5741b4e6a1a | 312 | /** Write a formatted string to the Display |
wim | 0:e5741b4e6a1a | 313 | * |
wim | 0:e5741b4e6a1a | 314 | * @param format A printf-style format string, followed by the |
wim | 0:e5741b4e6a1a | 315 | * variables to use in formatting the string. |
wim | 0:e5741b4e6a1a | 316 | */ |
wim | 0:e5741b4e6a1a | 317 | int printf(const char* format, ...); |
wim | 0:e5741b4e6a1a | 318 | #endif |
wim | 0:e5741b4e6a1a | 319 | #endif |
wim | 0:e5741b4e6a1a | 320 | |
wim | 0:e5741b4e6a1a | 321 | /** Locate cursor to a screen column |
wim | 0:e5741b4e6a1a | 322 | * |
wim | 0:e5741b4e6a1a | 323 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:e5741b4e6a1a | 324 | */ |
wim | 0:e5741b4e6a1a | 325 | void PT6318_KUH8300::locate(int column) { |
wim | 0:e5741b4e6a1a | 326 | //sanity check |
wim | 0:e5741b4e6a1a | 327 | if (column < 0) {column = 0;} |
wim | 0:e5741b4e6a1a | 328 | if (column > (_columns - 1)) {column = _columns - 1;} |
wim | 0:e5741b4e6a1a | 329 | |
wim | 0:e5741b4e6a1a | 330 | _column = column; |
wim | 0:e5741b4e6a1a | 331 | } |
wim | 0:e5741b4e6a1a | 332 | |
wim | 0:e5741b4e6a1a | 333 | |
wim | 0:e5741b4e6a1a | 334 | /** Number of screen columns |
wim | 0:e5741b4e6a1a | 335 | * |
wim | 0:e5741b4e6a1a | 336 | * @param none |
wim | 0:e5741b4e6a1a | 337 | * @return columns |
wim | 0:e5741b4e6a1a | 338 | */ |
wim | 0:e5741b4e6a1a | 339 | int PT6318_KUH8300::columns() { |
wim | 0:e5741b4e6a1a | 340 | return _columns; |
wim | 0:e5741b4e6a1a | 341 | } |
wim | 0:e5741b4e6a1a | 342 | |
wim | 0:e5741b4e6a1a | 343 | |
wim | 0:e5741b4e6a1a | 344 | /** Clear the screen and locate to 0 |
wim | 0:e5741b4e6a1a | 345 | * @param bool clrAll Clear Icons also (default = false) |
wim | 0:e5741b4e6a1a | 346 | */ |
wim | 0:e5741b4e6a1a | 347 | void PT6318_KUH8300::cls(bool clrAll) { |
wim | 0:e5741b4e6a1a | 348 | int idx; |
wim | 0:e5741b4e6a1a | 349 | |
wim | 0:e5741b4e6a1a | 350 | if (clrAll) { |
wim | 0:e5741b4e6a1a | 351 | //clear local buffer (including Icons) |
wim | 0:e5741b4e6a1a | 352 | for (idx=0; idx < (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID); idx++) { |
wim | 0:e5741b4e6a1a | 353 | _displaybuffer[idx] = 0x00; |
wim | 0:e5741b4e6a1a | 354 | } |
wim | 0:e5741b4e6a1a | 355 | } |
wim | 0:e5741b4e6a1a | 356 | else { |
wim | 0:e5741b4e6a1a | 357 | //clear local buffer (preserving Icons) |
wim | 0:e5741b4e6a1a | 358 | for (int grd=0; grd < KUH8300_NR_GRIDS; grd++) { |
wim | 0:e5741b4e6a1a | 359 | idx = grd * PT6318_BYTES_PER_GRID; // 3 bytes for every Grid |
wim | 0:e5741b4e6a1a | 360 | _displaybuffer[idx ] = _displaybuffer[idx ] & MASK_ICON_GRID[grd][0]; |
wim | 0:e5741b4e6a1a | 361 | _displaybuffer[idx + 1] = _displaybuffer[idx + 1] & MASK_ICON_GRID[grd][1]; |
wim | 0:e5741b4e6a1a | 362 | _displaybuffer[idx + 2] = _displaybuffer[idx + 2] & MASK_ICON_GRID[grd][2]; |
wim | 0:e5741b4e6a1a | 363 | } |
wim | 0:e5741b4e6a1a | 364 | } |
wim | 0:e5741b4e6a1a | 365 | |
wim | 0:e5741b4e6a1a | 366 | writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID)); |
wim | 0:e5741b4e6a1a | 367 | |
wim | 0:e5741b4e6a1a | 368 | _column = 0; |
wim | 0:e5741b4e6a1a | 369 | } |
wim | 0:e5741b4e6a1a | 370 | |
wim | 0:e5741b4e6a1a | 371 | /** Set Icon |
wim | 0:e5741b4e6a1a | 372 | * |
wim | 0:e5741b4e6a1a | 373 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:e5741b4e6a1a | 374 | * @return none |
wim | 0:e5741b4e6a1a | 375 | */ |
wim | 0:e5741b4e6a1a | 376 | void PT6318_KUH8300::setIcon(Icon icon) { |
wim | 0:e5741b4e6a1a | 377 | int addr, icn; |
wim | 0:e5741b4e6a1a | 378 | |
wim | 0:e5741b4e6a1a | 379 | icn = icon & 0xFFFFFF; |
wim | 0:e5741b4e6a1a | 380 | addr = (icon >> 24) & 0xFF; |
wim | 0:e5741b4e6a1a | 381 | addr = (addr - 1) * PT6318_BYTES_PER_GRID; // 3 Bytes for every Grid |
wim | 0:e5741b4e6a1a | 382 | |
wim | 0:e5741b4e6a1a | 383 | //Save char...and set bits for icon to write |
wim | 0:e5741b4e6a1a | 384 | _displaybuffer[addr ] = _displaybuffer[addr ] | LO(icn); |
wim | 0:e5741b4e6a1a | 385 | _displaybuffer[addr + 1] = _displaybuffer[addr + 1] | MD(icn); |
wim | 0:e5741b4e6a1a | 386 | _displaybuffer[addr + 2] = _displaybuffer[addr + 2] | HI(icn); |
wim | 0:e5741b4e6a1a | 387 | writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID)); |
wim | 0:e5741b4e6a1a | 388 | } |
wim | 0:e5741b4e6a1a | 389 | |
wim | 0:e5741b4e6a1a | 390 | /** Clr Icon |
wim | 0:e5741b4e6a1a | 391 | * |
wim | 0:e5741b4e6a1a | 392 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:e5741b4e6a1a | 393 | * @return none |
wim | 0:e5741b4e6a1a | 394 | */ |
wim | 0:e5741b4e6a1a | 395 | void PT6318_KUH8300::clrIcon(Icon icon) { |
wim | 0:e5741b4e6a1a | 396 | int addr, icn; |
wim | 0:e5741b4e6a1a | 397 | |
wim | 0:e5741b4e6a1a | 398 | icn = icon & 0xFFFFFF; |
wim | 0:e5741b4e6a1a | 399 | addr = (icon >> 24) & 0xFF; |
wim | 0:e5741b4e6a1a | 400 | addr = (addr - 1) * PT6318_BYTES_PER_GRID; // 3 Bytes for every Grid |
wim | 0:e5741b4e6a1a | 401 | |
wim | 0:e5741b4e6a1a | 402 | //Save char...and clr bits for icon to write |
wim | 0:e5741b4e6a1a | 403 | _displaybuffer[addr ] = _displaybuffer[addr ] & ~LO(icn); |
wim | 0:e5741b4e6a1a | 404 | _displaybuffer[addr + 1] = _displaybuffer[addr + 1] & ~MD(icn); |
wim | 0:e5741b4e6a1a | 405 | _displaybuffer[addr + 2] = _displaybuffer[addr + 2] & ~HI(icn); |
wim | 0:e5741b4e6a1a | 406 | writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID)); |
wim | 0:e5741b4e6a1a | 407 | } |
wim | 0:e5741b4e6a1a | 408 | |
wim | 0:e5741b4e6a1a | 409 | |
wim | 0:e5741b4e6a1a | 410 | /** Set User Defined Characters (UDC) |
wim | 0:e5741b4e6a1a | 411 | * |
wim | 0:e5741b4e6a1a | 412 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 0:e5741b4e6a1a | 413 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 0:e5741b4e6a1a | 414 | */ |
wim | 0:e5741b4e6a1a | 415 | void PT6318_KUH8300::setUDC(unsigned char udc_idx, int udc_data) { |
wim | 0:e5741b4e6a1a | 416 | |
wim | 0:e5741b4e6a1a | 417 | //Sanity check |
wim | 0:e5741b4e6a1a | 418 | if (udc_idx > (KUH8300_NR_UDC-1)) { |
wim | 0:e5741b4e6a1a | 419 | return; |
wim | 0:e5741b4e6a1a | 420 | } |
wim | 0:e5741b4e6a1a | 421 | |
wim | 0:e5741b4e6a1a | 422 | // Mask out Icon bits? |
wim | 0:e5741b4e6a1a | 423 | _UDC_16S[udc_idx] = udc_data & 0xFFFF; |
wim | 0:e5741b4e6a1a | 424 | } |
wim | 0:e5741b4e6a1a | 425 | |
wim | 0:e5741b4e6a1a | 426 | /** Write a single character (Stream implementation) |
wim | 0:e5741b4e6a1a | 427 | */ |
wim | 0:e5741b4e6a1a | 428 | int PT6318_KUH8300::_putc(int value) { |
wim | 0:e5741b4e6a1a | 429 | bool validChar = false; |
wim | 0:e5741b4e6a1a | 430 | bool even = false; |
wim | 0:e5741b4e6a1a | 431 | short pattern = 0x0000; |
wim | 0:e5741b4e6a1a | 432 | int addr; |
wim | 0:e5741b4e6a1a | 433 | |
wim | 0:e5741b4e6a1a | 434 | if ((value == '\n') || (value == '\r')) { |
wim | 0:e5741b4e6a1a | 435 | //No character to write |
wim | 0:e5741b4e6a1a | 436 | validChar = false; |
wim | 0:e5741b4e6a1a | 437 | |
wim | 0:e5741b4e6a1a | 438 | //Update Cursor |
wim | 0:e5741b4e6a1a | 439 | _column = 0; |
wim | 0:e5741b4e6a1a | 440 | } |
wim | 0:e5741b4e6a1a | 441 | else if ((value >= 0) && (value < KUH8300_NR_UDC)) { |
wim | 0:e5741b4e6a1a | 442 | //Character to write |
wim | 0:e5741b4e6a1a | 443 | validChar = true; |
wim | 0:e5741b4e6a1a | 444 | pattern = _UDC_16S[value]; |
wim | 0:e5741b4e6a1a | 445 | } |
wim | 0:e5741b4e6a1a | 446 | #if (SHOW_ASCII == 1) |
wim | 0:e5741b4e6a1a | 447 | //display all ASCII characters |
wim | 0:e5741b4e6a1a | 448 | else if ((value >= FONT_7S_START) && (value <= FONT_7S_END)) { |
wim | 0:e5741b4e6a1a | 449 | //Character to write |
wim | 0:e5741b4e6a1a | 450 | validChar = true; |
wim | 0:e5741b4e6a1a | 451 | pattern = FONT_7S[value - FONT_7S_START]; |
wim | 0:e5741b4e6a1a | 452 | } // else |
wim | 0:e5741b4e6a1a | 453 | #else |
wim | 0:e5741b4e6a1a | 454 | //display only digits and hex characters |
wim | 0:e5741b4e6a1a | 455 | else if (value == '-') { |
wim | 0:e5741b4e6a1a | 456 | //Character to write |
wim | 0:e5741b4e6a1a | 457 | validChar = true; |
wim | 0:e5741b4e6a1a | 458 | pattern = C7_MIN; |
wim | 0:e5741b4e6a1a | 459 | } |
wim | 0:e5741b4e6a1a | 460 | else if ((value >= (int)'0') && (value <= (int) '9')) { |
wim | 0:e5741b4e6a1a | 461 | //Character to write |
wim | 0:e5741b4e6a1a | 462 | validChar = true; |
wim | 0:e5741b4e6a1a | 463 | pattern = FONT_7S[value - (int) '0']; |
wim | 0:e5741b4e6a1a | 464 | } |
wim | 0:e5741b4e6a1a | 465 | else if ((value >= (int) 'A') && (value <= (int) 'F')) { |
wim | 0:e5741b4e6a1a | 466 | //Character to write |
wim | 0:e5741b4e6a1a | 467 | validChar = true; |
wim | 0:e5741b4e6a1a | 468 | pattern = FONT_7S[10 + value - (int) 'A']; |
wim | 0:e5741b4e6a1a | 469 | } |
wim | 0:e5741b4e6a1a | 470 | else if ((value >= (int) 'a') && (value <= (int) 'f')) { |
wim | 0:e5741b4e6a1a | 471 | //Character to write |
wim | 0:e5741b4e6a1a | 472 | validChar = true; |
wim | 0:e5741b4e6a1a | 473 | pattern = FONT_7S[10 + value - (int) 'a']; |
wim | 0:e5741b4e6a1a | 474 | } //else |
wim | 0:e5741b4e6a1a | 475 | #endif |
wim | 0:e5741b4e6a1a | 476 | if (validChar) { |
wim | 0:e5741b4e6a1a | 477 | //Character to write |
wim | 0:e5741b4e6a1a | 478 | |
wim | 0:e5741b4e6a1a | 479 | //Translate between _column and displaybuffer entries |
wim | 0:e5741b4e6a1a | 480 | //Note that the KUH8300 has 8 7-Segment digits using 4 Grids. |
wim | 0:e5741b4e6a1a | 481 | //Some of these Grids also have icons that need to be preserved |
wim | 0:e5741b4e6a1a | 482 | //_column == 0 => Grid5 => addr = 12..14 |
wim | 0:e5741b4e6a1a | 483 | //_column == 1 => Grid5 => addr = 12..14 |
wim | 0:e5741b4e6a1a | 484 | // .... |
wim | 0:e5741b4e6a1a | 485 | //_column == 6 => Grid2 => addr = 3..5 |
wim | 0:e5741b4e6a1a | 486 | //_column == 7 => Grid2 => addr = 3..5 |
wim | 0:e5741b4e6a1a | 487 | addr = 12 - ((_column >> 1) * PT6318_BYTES_PER_GRID); // 3 Bytes for every Grid; |
wim | 0:e5741b4e6a1a | 488 | even = ((_column & 0x01) == 0x00); // Odd or Even column |
wim | 0:e5741b4e6a1a | 489 | |
wim | 0:e5741b4e6a1a | 490 | // pattern is a placeholder, test pattern and set the actual segment depending on the odd or even _column for this Grid |
wim | 0:e5741b4e6a1a | 491 | if (pattern & S7_A) { |
wim | 0:e5741b4e6a1a | 492 | //Set Segment |
wim | 0:e5741b4e6a1a | 493 | if (even) { |
wim | 0:e5741b4e6a1a | 494 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_A0); |
wim | 0:e5741b4e6a1a | 495 | } |
wim | 0:e5741b4e6a1a | 496 | else { |
wim | 0:e5741b4e6a1a | 497 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_A1); |
wim | 0:e5741b4e6a1a | 498 | } |
wim | 0:e5741b4e6a1a | 499 | } |
wim | 0:e5741b4e6a1a | 500 | else { |
wim | 0:e5741b4e6a1a | 501 | //Clear Segment |
wim | 0:e5741b4e6a1a | 502 | if (even) { |
wim | 0:e5741b4e6a1a | 503 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_A0); |
wim | 0:e5741b4e6a1a | 504 | } |
wim | 0:e5741b4e6a1a | 505 | else { |
wim | 0:e5741b4e6a1a | 506 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_A1); |
wim | 0:e5741b4e6a1a | 507 | } |
wim | 0:e5741b4e6a1a | 508 | } |
wim | 0:e5741b4e6a1a | 509 | |
wim | 0:e5741b4e6a1a | 510 | if (pattern & S7_B) { |
wim | 0:e5741b4e6a1a | 511 | //Set Segment |
wim | 0:e5741b4e6a1a | 512 | if (even) { |
wim | 0:e5741b4e6a1a | 513 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_B0); |
wim | 0:e5741b4e6a1a | 514 | } |
wim | 0:e5741b4e6a1a | 515 | else { |
wim | 0:e5741b4e6a1a | 516 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_B1); |
wim | 0:e5741b4e6a1a | 517 | } |
wim | 0:e5741b4e6a1a | 518 | } |
wim | 0:e5741b4e6a1a | 519 | else { |
wim | 0:e5741b4e6a1a | 520 | //Clear Segment |
wim | 0:e5741b4e6a1a | 521 | if (even) { |
wim | 0:e5741b4e6a1a | 522 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_B0); |
wim | 0:e5741b4e6a1a | 523 | } |
wim | 0:e5741b4e6a1a | 524 | else { |
wim | 0:e5741b4e6a1a | 525 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_B1); |
wim | 0:e5741b4e6a1a | 526 | } |
wim | 0:e5741b4e6a1a | 527 | } |
wim | 0:e5741b4e6a1a | 528 | |
wim | 0:e5741b4e6a1a | 529 | if (pattern & S7_C) { |
wim | 0:e5741b4e6a1a | 530 | //Set Segment |
wim | 0:e5741b4e6a1a | 531 | if (even) { |
wim | 0:e5741b4e6a1a | 532 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_C0); |
wim | 0:e5741b4e6a1a | 533 | } |
wim | 0:e5741b4e6a1a | 534 | else { |
wim | 0:e5741b4e6a1a | 535 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_C1); |
wim | 0:e5741b4e6a1a | 536 | } |
wim | 0:e5741b4e6a1a | 537 | } |
wim | 0:e5741b4e6a1a | 538 | else { |
wim | 0:e5741b4e6a1a | 539 | //Clear Segment |
wim | 0:e5741b4e6a1a | 540 | if (even) { |
wim | 0:e5741b4e6a1a | 541 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_C0); |
wim | 0:e5741b4e6a1a | 542 | } |
wim | 0:e5741b4e6a1a | 543 | else { |
wim | 0:e5741b4e6a1a | 544 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_C1); |
wim | 0:e5741b4e6a1a | 545 | } |
wim | 0:e5741b4e6a1a | 546 | } |
wim | 0:e5741b4e6a1a | 547 | |
wim | 0:e5741b4e6a1a | 548 | if (pattern & S7_D) { |
wim | 0:e5741b4e6a1a | 549 | //Set Segment |
wim | 0:e5741b4e6a1a | 550 | if (even) { |
wim | 0:e5741b4e6a1a | 551 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_D0); |
wim | 0:e5741b4e6a1a | 552 | } |
wim | 0:e5741b4e6a1a | 553 | else { |
wim | 0:e5741b4e6a1a | 554 | _displaybuffer[addr+2] = _displaybuffer[addr+2] | HI(S7_D1); |
wim | 0:e5741b4e6a1a | 555 | } |
wim | 0:e5741b4e6a1a | 556 | } |
wim | 0:e5741b4e6a1a | 557 | else { |
wim | 0:e5741b4e6a1a | 558 | //Clear Segment |
wim | 0:e5741b4e6a1a | 559 | if (even) { |
wim | 0:e5741b4e6a1a | 560 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_D0); |
wim | 0:e5741b4e6a1a | 561 | } |
wim | 0:e5741b4e6a1a | 562 | else { |
wim | 0:e5741b4e6a1a | 563 | _displaybuffer[addr+2] = _displaybuffer[addr+2] & ~HI(S7_D1); |
wim | 0:e5741b4e6a1a | 564 | } |
wim | 0:e5741b4e6a1a | 565 | } |
wim | 0:e5741b4e6a1a | 566 | |
wim | 0:e5741b4e6a1a | 567 | if (pattern & S7_E) { |
wim | 0:e5741b4e6a1a | 568 | //Set Segment |
wim | 0:e5741b4e6a1a | 569 | if (even) { |
wim | 0:e5741b4e6a1a | 570 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_E0); |
wim | 0:e5741b4e6a1a | 571 | } |
wim | 0:e5741b4e6a1a | 572 | else { |
wim | 0:e5741b4e6a1a | 573 | _displaybuffer[addr+2] = _displaybuffer[addr+2] | HI(S7_E1); |
wim | 0:e5741b4e6a1a | 574 | } |
wim | 0:e5741b4e6a1a | 575 | } |
wim | 0:e5741b4e6a1a | 576 | else { |
wim | 0:e5741b4e6a1a | 577 | //Clear Segment |
wim | 0:e5741b4e6a1a | 578 | if (even) { |
wim | 0:e5741b4e6a1a | 579 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_E0); |
wim | 0:e5741b4e6a1a | 580 | } |
wim | 0:e5741b4e6a1a | 581 | else { |
wim | 0:e5741b4e6a1a | 582 | _displaybuffer[addr+2] = _displaybuffer[addr+2] & ~HI(S7_E1); |
wim | 0:e5741b4e6a1a | 583 | } |
wim | 0:e5741b4e6a1a | 584 | } |
wim | 0:e5741b4e6a1a | 585 | |
wim | 0:e5741b4e6a1a | 586 | if (pattern & S7_F) { |
wim | 0:e5741b4e6a1a | 587 | //Set Segment |
wim | 0:e5741b4e6a1a | 588 | if (even) { |
wim | 0:e5741b4e6a1a | 589 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_F0); |
wim | 0:e5741b4e6a1a | 590 | } |
wim | 0:e5741b4e6a1a | 591 | else { |
wim | 0:e5741b4e6a1a | 592 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_F1); |
wim | 0:e5741b4e6a1a | 593 | } |
wim | 0:e5741b4e6a1a | 594 | } |
wim | 0:e5741b4e6a1a | 595 | else { |
wim | 0:e5741b4e6a1a | 596 | //Clear Segment |
wim | 0:e5741b4e6a1a | 597 | if (even) { |
wim | 0:e5741b4e6a1a | 598 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_F0); |
wim | 0:e5741b4e6a1a | 599 | } |
wim | 0:e5741b4e6a1a | 600 | else { |
wim | 0:e5741b4e6a1a | 601 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_F1); |
wim | 0:e5741b4e6a1a | 602 | } |
wim | 0:e5741b4e6a1a | 603 | } |
wim | 0:e5741b4e6a1a | 604 | |
wim | 0:e5741b4e6a1a | 605 | if (pattern & S7_G) { |
wim | 0:e5741b4e6a1a | 606 | //Set Segment |
wim | 0:e5741b4e6a1a | 607 | if (even) { |
wim | 0:e5741b4e6a1a | 608 | _displaybuffer[addr] = _displaybuffer[addr] | LO(S7_G0); |
wim | 0:e5741b4e6a1a | 609 | } |
wim | 0:e5741b4e6a1a | 610 | else { |
wim | 0:e5741b4e6a1a | 611 | _displaybuffer[addr+1] = _displaybuffer[addr+1] | MD(S7_G1); |
wim | 0:e5741b4e6a1a | 612 | } |
wim | 0:e5741b4e6a1a | 613 | } |
wim | 0:e5741b4e6a1a | 614 | else { |
wim | 0:e5741b4e6a1a | 615 | //Clear Segment |
wim | 0:e5741b4e6a1a | 616 | if (even) { |
wim | 0:e5741b4e6a1a | 617 | _displaybuffer[addr] = _displaybuffer[addr] & ~LO(S7_G0); |
wim | 0:e5741b4e6a1a | 618 | } |
wim | 0:e5741b4e6a1a | 619 | else { |
wim | 0:e5741b4e6a1a | 620 | _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~MD(S7_G1); |
wim | 0:e5741b4e6a1a | 621 | } |
wim | 0:e5741b4e6a1a | 622 | } |
wim | 0:e5741b4e6a1a | 623 | |
wim | 0:e5741b4e6a1a | 624 | // //Save icons...and set bits for character to write |
wim | 0:e5741b4e6a1a | 625 | // _displaybuffer[addr] = (_displaybuffer[addr] & MASK_ICON_GRID[_column][0]) | LO(pattern); |
wim | 0:e5741b4e6a1a | 626 | // _displaybuffer[addr+1] = (_displaybuffer[addr+1] & MASK_ICON_GRID[_column][1]) | MD(pattern); |
wim | 0:e5741b4e6a1a | 627 | // _displaybuffer[addr+2] = (_displaybuffer[addr+2] & MASK_ICON_GRID[_column][2]) | HI(pattern); |
wim | 0:e5741b4e6a1a | 628 | |
wim | 0:e5741b4e6a1a | 629 | writeData(_displaybuffer, (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID)); |
wim | 0:e5741b4e6a1a | 630 | |
wim | 0:e5741b4e6a1a | 631 | //Update Cursor |
wim | 0:e5741b4e6a1a | 632 | _column++; |
wim | 0:e5741b4e6a1a | 633 | if (_column > (KUH8300_NR_DIGITS - 1)) { |
wim | 0:e5741b4e6a1a | 634 | _column = 0; |
wim | 0:e5741b4e6a1a | 635 | } |
wim | 0:e5741b4e6a1a | 636 | |
wim | 0:e5741b4e6a1a | 637 | } // if validChar |
wim | 0:e5741b4e6a1a | 638 | |
wim | 0:e5741b4e6a1a | 639 | return value; |
wim | 0:e5741b4e6a1a | 640 | } |
wim | 0:e5741b4e6a1a | 641 | |
wim | 0:e5741b4e6a1a | 642 | // get a single character (Stream implementation) |
wim | 0:e5741b4e6a1a | 643 | int PT6318_KUH8300::_getc() { |
wim | 0:e5741b4e6a1a | 644 | return -1; |
wim | 0:e5741b4e6a1a | 645 | } |
wim | 0:e5741b4e6a1a | 646 | #endif |