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