Library for Princeton PT6318 VFD controller Initial version for KUH8300.
PT6318.h@1:a7a518dbca96, 2016-06-19 (annotated)
- Committer:
- wim
- Date:
- Sun Jun 19 13:27:07 2016 +0000
- Revision:
- 1:a7a518dbca96
- Parent:
- 0:e5741b4e6a1a
Library for Princeton PT6318 VFD controller; Initial version for KUH8300.
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 |
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 | |
wim | 0:e5741b4e6a1a | 23 | #ifndef PT6318_H |
wim | 0:e5741b4e6a1a | 24 | #define PT6318_H |
wim | 0:e5741b4e6a1a | 25 | |
wim | 0:e5741b4e6a1a | 26 | // Select one of the testboards for Princeton PT6318 VFD controller |
wim | 0:e5741b4e6a1a | 27 | #include "PT6318_Config.h" |
wim | 0:e5741b4e6a1a | 28 | |
wim | 0:e5741b4e6a1a | 29 | /** An interface for driving Princeton PT6318 VFD controller |
wim | 0:e5741b4e6a1a | 30 | * |
wim | 0:e5741b4e6a1a | 31 | * @code |
wim | 0:e5741b4e6a1a | 32 | * |
wim | 0:e5741b4e6a1a | 33 | * #if (PT6318_TEST == 1) |
wim | 0:e5741b4e6a1a | 34 | * // Direct driving of PT6318 Test |
wim | 0:e5741b4e6a1a | 35 | * |
wim | 0:e5741b4e6a1a | 36 | * #include "mbed.h" |
wim | 0:e5741b4e6a1a | 37 | * #include "PT6318.h" |
wim | 0:e5741b4e6a1a | 38 | * |
wim | 0:e5741b4e6a1a | 39 | * DisplayData_t size is 24 bytes (8 Grids @ 20 Segments) ... 48 bytes (16 Grids @ 12 Segments) |
wim | 0:e5741b4e6a1a | 40 | * DisplayData_t size default is 48 bytes (16 Grids @ 12 Segments) |
wim | 0:e5741b4e6a1a | 41 | * PT6318::DisplayData_t all_str = {0xFF,0x0F,0x00 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, |
wim | 0:e5741b4e6a1a | 42 | * 0xFF,0x0F,0x00 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00}; |
wim | 0:e5741b4e6a1a | 43 | * |
wim | 0:e5741b4e6a1a | 44 | * // KeyData_t size is 6 bytes |
wim | 0:e5741b4e6a1a | 45 | * PT6318::KeyData_t keydata; |
wim | 0:e5741b4e6a1a | 46 | * |
wim | 0:e5741b4e6a1a | 47 | * // PT6318 declaration, Default setting 16 Grids @ 12 Segments |
wim | 0:e5741b4e6a1a | 48 | * PT6318 PT6318(p5,p6,p7, p8); |
wim | 0:e5741b4e6a1a | 49 | * |
wim | 0:e5741b4e6a1a | 50 | * int main() { |
wim | 0:e5741b4e6a1a | 51 | * PT6318.cls(); |
wim | 0:e5741b4e6a1a | 52 | * PT6318.writeData(all_str); |
wim | 0:e5741b4e6a1a | 53 | * wait(4); |
wim | 0:e5741b4e6a1a | 54 | * PT6318.setBrightness(PT6318_BRT0); |
wim | 0:e5741b4e6a1a | 55 | * wait(1); |
wim | 0:e5741b4e6a1a | 56 | * PT6318.setBrightness(PT6318_BRT3); |
wim | 0:e5741b4e6a1a | 57 | * |
wim | 0:e5741b4e6a1a | 58 | * while (1) { |
wim | 0:e5741b4e6a1a | 59 | * // Check and read keydata |
wim | 0:e5741b4e6a1a | 60 | * if (PT6318.getKeys(&keydata)) { |
wim | 1:a7a518dbca96 | 61 | * pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]); |
wim | 0:e5741b4e6a1a | 62 | * |
wim | 1:a7a518dbca96 | 63 | * if (keydata[0] == 0x01) { //sw1 |
wim | 0:e5741b4e6a1a | 64 | * PT6318.cls(); |
wim | 0:e5741b4e6a1a | 65 | * wait(1); |
wim | 0:e5741b4e6a1a | 66 | * PT6318.writeData(all_str); |
wim | 0:e5741b4e6a1a | 67 | * } |
wim | 0:e5741b4e6a1a | 68 | * } |
wim | 0:e5741b4e6a1a | 69 | * } |
wim | 0:e5741b4e6a1a | 70 | * } |
wim | 0:e5741b4e6a1a | 71 | * #endif |
wim | 0:e5741b4e6a1a | 72 | * |
wim | 0:e5741b4e6a1a | 73 | * @endcode |
wim | 0:e5741b4e6a1a | 74 | */ |
wim | 0:e5741b4e6a1a | 75 | |
wim | 0:e5741b4e6a1a | 76 | //PT6318 Display and Keymatrix data |
wim | 0:e5741b4e6a1a | 77 | #define PT6318_MAX_NR_GRIDS 16 |
wim | 0:e5741b4e6a1a | 78 | #define PT6318_BYTES_PER_GRID 3 |
wim | 0:e5741b4e6a1a | 79 | //Significant bits Keymatrix data |
wim | 0:e5741b4e6a1a | 80 | #define PT6318_KEY_MSK 0xFF |
wim | 0:e5741b4e6a1a | 81 | |
wim | 0:e5741b4e6a1a | 82 | //Memory size in bytes for Display and Keymatrix |
wim | 0:e5741b4e6a1a | 83 | #define PT6318_DISPLAY_MEM (PT6318_MAX_NR_GRIDS * PT6318_BYTES_PER_GRID) |
wim | 0:e5741b4e6a1a | 84 | #define PT6318_KEY_MEM 6 |
wim | 0:e5741b4e6a1a | 85 | |
wim | 0:e5741b4e6a1a | 86 | //Reserved bits for commands |
wim | 0:e5741b4e6a1a | 87 | #define PT6318_CMD_MSK 0xC0 |
wim | 0:e5741b4e6a1a | 88 | |
wim | 0:e5741b4e6a1a | 89 | //Mode setting command |
wim | 0:e5741b4e6a1a | 90 | #define PT6318_MODE_SET_CMD 0x00 |
wim | 0:e5741b4e6a1a | 91 | #define PT6318_GR8_SEG20 0x00 |
wim | 0:e5741b4e6a1a | 92 | #define PT6318_GR9_SEG19 0x08 |
wim | 0:e5741b4e6a1a | 93 | #define PT6318_GR10_SEG18 0x09 |
wim | 0:e5741b4e6a1a | 94 | #define PT6318_GR11_SEG17 0x0A |
wim | 0:e5741b4e6a1a | 95 | #define PT6318_GR12_SEG16 0x0B |
wim | 0:e5741b4e6a1a | 96 | #define PT6318_GR13_SEG15 0x0C |
wim | 0:e5741b4e6a1a | 97 | #define PT6318_GR14_SEG14 0x0D |
wim | 0:e5741b4e6a1a | 98 | #define PT6318_GR15_SEG13 0x0E |
wim | 0:e5741b4e6a1a | 99 | #define PT6318_GR16_SEG12 0x0F //default |
wim | 0:e5741b4e6a1a | 100 | |
wim | 0:e5741b4e6a1a | 101 | //Data setting commands |
wim | 0:e5741b4e6a1a | 102 | #define PT6318_DATA_SET_CMD 0x40 |
wim | 0:e5741b4e6a1a | 103 | #define PT6318_DATA_WR 0x00 |
wim | 0:e5741b4e6a1a | 104 | #define PT6318_LED_WR 0x01 |
wim | 0:e5741b4e6a1a | 105 | #define PT6318_KEY_RD 0x02 |
wim | 0:e5741b4e6a1a | 106 | #define PT6318_SW_RD 0x03 |
wim | 0:e5741b4e6a1a | 107 | #define PT6318_ADDR_INC 0x00 |
wim | 0:e5741b4e6a1a | 108 | #define PT6318_ADDR_FIXED 0x04 |
wim | 0:e5741b4e6a1a | 109 | #define PT6318_MODE_NORM 0x00 |
wim | 0:e5741b4e6a1a | 110 | #define PT6318_MODE_TEST 0x08 |
wim | 0:e5741b4e6a1a | 111 | |
wim | 0:e5741b4e6a1a | 112 | //LED settings data |
wim | 0:e5741b4e6a1a | 113 | #define PT6318_LED_MSK 0x1F |
wim | 0:e5741b4e6a1a | 114 | #define PT6318_LED1 0x01 |
wim | 0:e5741b4e6a1a | 115 | #define PT6318_LED2 0x02 |
wim | 0:e5741b4e6a1a | 116 | #define PT6318_LED3 0x04 |
wim | 0:e5741b4e6a1a | 117 | #define PT6318_LED4 0x08 |
wim | 0:e5741b4e6a1a | 118 | #define PT6318_LED5 0x10 |
wim | 0:e5741b4e6a1a | 119 | |
wim | 0:e5741b4e6a1a | 120 | //Switch settings data |
wim | 0:e5741b4e6a1a | 121 | #define PT6318_SW_MSK 0x0F |
wim | 0:e5741b4e6a1a | 122 | #define PT6318_SW1 0x01 |
wim | 0:e5741b4e6a1a | 123 | #define PT6318_SW2 0x02 |
wim | 0:e5741b4e6a1a | 124 | #define PT6318_SW3 0x04 |
wim | 0:e5741b4e6a1a | 125 | #define PT6318_SW4 0x08 |
wim | 0:e5741b4e6a1a | 126 | |
wim | 0:e5741b4e6a1a | 127 | //Address setting commands |
wim | 0:e5741b4e6a1a | 128 | #define PT6318_ADDR_SET_CMD 0xC0 |
wim | 0:e5741b4e6a1a | 129 | #define PT6318_ADDR_MSK 0x3F |
wim | 0:e5741b4e6a1a | 130 | |
wim | 0:e5741b4e6a1a | 131 | //Display control commands |
wim | 0:e5741b4e6a1a | 132 | #define PT6318_DSP_CTRL_CMD 0x80 |
wim | 0:e5741b4e6a1a | 133 | #define PT6318_BRT_MSK 0x07 |
wim | 0:e5741b4e6a1a | 134 | #define PT6318_BRT0 0x00 //Pulsewidth 1/16, Default |
wim | 0:e5741b4e6a1a | 135 | #define PT6318_BRT1 0x01 |
wim | 0:e5741b4e6a1a | 136 | #define PT6318_BRT2 0x02 |
wim | 0:e5741b4e6a1a | 137 | #define PT6318_BRT3 0x03 |
wim | 0:e5741b4e6a1a | 138 | #define PT6318_BRT4 0x04 |
wim | 0:e5741b4e6a1a | 139 | #define PT6318_BRT5 0x05 |
wim | 0:e5741b4e6a1a | 140 | #define PT6318_BRT6 0x06 |
wim | 0:e5741b4e6a1a | 141 | #define PT6318_BRT7 0x07 //Pulsewidth 14/16 |
wim | 0:e5741b4e6a1a | 142 | |
wim | 0:e5741b4e6a1a | 143 | #define PT6318_BRT_DEF PT6318_BRT3 |
wim | 0:e5741b4e6a1a | 144 | |
wim | 0:e5741b4e6a1a | 145 | #define PT6318_DSP_OFF 0x00 //Default |
wim | 0:e5741b4e6a1a | 146 | #define PT6318_DSP_ON 0x08 |
wim | 0:e5741b4e6a1a | 147 | |
wim | 0:e5741b4e6a1a | 148 | |
wim | 0:e5741b4e6a1a | 149 | /** A class for driving Princeton PT6318 VFD controller |
wim | 0:e5741b4e6a1a | 150 | * |
wim | 1:a7a518dbca96 | 151 | * @brief Supports 8 Grids of 20 Segments upto 16 Grids of 12 Segments. Also supports a scanned keyboard of upto 48 keys, 4 switches and 5 LEDs. |
wim | 0:e5741b4e6a1a | 152 | * SPI bus interface device. |
wim | 0:e5741b4e6a1a | 153 | */ |
wim | 0:e5741b4e6a1a | 154 | class PT6318 { |
wim | 0:e5741b4e6a1a | 155 | public: |
wim | 0:e5741b4e6a1a | 156 | |
wim | 0:e5741b4e6a1a | 157 | /** Enums for display mode */ |
wim | 0:e5741b4e6a1a | 158 | enum Mode { |
wim | 0:e5741b4e6a1a | 159 | Grid8_Seg20 = PT6318_GR8_SEG20, /**< 8 Grids, 20 Segments */ |
wim | 0:e5741b4e6a1a | 160 | Grid9_Seg19 = PT6318_GR9_SEG19, /**< 9 Grids, 19 Segments */ |
wim | 0:e5741b4e6a1a | 161 | Grid10_Seg18 = PT6318_GR10_SEG18, /**< 10 Grids, 18 Segments */ |
wim | 0:e5741b4e6a1a | 162 | Grid11_Seg17 = PT6318_GR11_SEG17, /**< 11 Grids, 17 Segments */ |
wim | 0:e5741b4e6a1a | 163 | Grid12_Seg16 = PT6318_GR12_SEG16, /**< 12 Grids, 16 Segments */ |
wim | 0:e5741b4e6a1a | 164 | Grid13_Seg15 = PT6318_GR13_SEG15, /**< 13 Grids, 15 Segments */ |
wim | 0:e5741b4e6a1a | 165 | Grid14_Seg14 = PT6318_GR14_SEG14, /**< 14 Grids, 14 Segments */ |
wim | 0:e5741b4e6a1a | 166 | Grid15_Seg13 = PT6318_GR15_SEG13, /**< 15 Grids, 13 Segments */ |
wim | 0:e5741b4e6a1a | 167 | Grid16_Seg12 = PT6318_GR16_SEG12 /**< 16 Grids, 12 Segments */ |
wim | 0:e5741b4e6a1a | 168 | }; |
wim | 0:e5741b4e6a1a | 169 | |
wim | 0:e5741b4e6a1a | 170 | /** Datatypes for display and keymatrix data */ |
wim | 0:e5741b4e6a1a | 171 | typedef char DisplayData_t[PT6318_DISPLAY_MEM]; |
wim | 0:e5741b4e6a1a | 172 | typedef char KeyData_t[PT6318_KEY_MEM]; |
wim | 0:e5741b4e6a1a | 173 | |
wim | 0:e5741b4e6a1a | 174 | /** Constructor for class for driving Princeton PT6318 VFD controller |
wim | 0:e5741b4e6a1a | 175 | * |
wim | 0:e5741b4e6a1a | 176 | * @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 | 177 | * SPI bus interface device. |
wim | 0:e5741b4e6a1a | 178 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:e5741b4e6a1a | 179 | * @param Mode selects either number of Grids and Segments (default 16 Grids, 12 Segments) |
wim | 0:e5741b4e6a1a | 180 | */ |
wim | 0:e5741b4e6a1a | 181 | PT6318(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode=Grid16_Seg12); |
wim | 0:e5741b4e6a1a | 182 | |
wim | 0:e5741b4e6a1a | 183 | /** Clear the screen and locate to 0 |
wim | 0:e5741b4e6a1a | 184 | */ |
wim | 0:e5741b4e6a1a | 185 | void cls(); |
wim | 0:e5741b4e6a1a | 186 | |
wim | 0:e5741b4e6a1a | 187 | /** Write databyte to PT6318 |
wim | 0:e5741b4e6a1a | 188 | * @param char data byte written at given address |
wim | 0:e5741b4e6a1a | 189 | * @param int address display memory location to write byte |
wim | 0:e5741b4e6a1a | 190 | * @return none |
wim | 0:e5741b4e6a1a | 191 | */ |
wim | 0:e5741b4e6a1a | 192 | void writeData(char data, int address); |
wim | 0:e5741b4e6a1a | 193 | |
wim | 0:e5741b4e6a1a | 194 | /** Write Display datablock to PT6318 |
wim | 0:e5741b4e6a1a | 195 | * @param DisplayData_t data Array of PT6318_DISPLAY_MEM (=48) bytes for displaydata (starting at address) |
wim | 0:e5741b4e6a1a | 196 | * @param length number bytes to write (valid range 0..PT6318_DISPLAY_MEM (=48), starting at address) |
wim | 0:e5741b4e6a1a | 197 | * @param int address display memory location to write byte (default = 0) |
wim | 0:e5741b4e6a1a | 198 | * @return none |
wim | 0:e5741b4e6a1a | 199 | */ |
wim | 0:e5741b4e6a1a | 200 | void writeData(DisplayData_t data, int length = PT6318_DISPLAY_MEM, int address = 0); |
wim | 0:e5741b4e6a1a | 201 | |
wim | 0:e5741b4e6a1a | 202 | |
wim | 0:e5741b4e6a1a | 203 | /** Read keydata block from PT6318 |
wim | 0:e5741b4e6a1a | 204 | * @param *keydata Ptr to Array of PT6318_KEY_MEM (=6) bytes for keydata |
wim | 0:e5741b4e6a1a | 205 | * @return bool keypress True when at least one key was pressed |
wim | 0:e5741b4e6a1a | 206 | * |
wim | 0:e5741b4e6a1a | 207 | * Note: Due to the hardware configuration the PT6318 key matrix scanner will detect multiple keys pressed at same time, |
wim | 0:e5741b4e6a1a | 208 | * but this may result in some spurious keys also being set in keypress data array. |
wim | 0:e5741b4e6a1a | 209 | * 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 | 210 | */ |
wim | 0:e5741b4e6a1a | 211 | bool getKeys(KeyData_t *keydata); |
wim | 0:e5741b4e6a1a | 212 | |
wim | 0:e5741b4e6a1a | 213 | |
wim | 0:e5741b4e6a1a | 214 | /** Read switches from PT6318 |
wim | 0:e5741b4e6a1a | 215 | * |
wim | 0:e5741b4e6a1a | 216 | * @param none |
wim | 0:e5741b4e6a1a | 217 | * @return char for switch data (4 least significant bits) |
wim | 0:e5741b4e6a1a | 218 | */ |
wim | 0:e5741b4e6a1a | 219 | char getSwitches(); |
wim | 0:e5741b4e6a1a | 220 | |
wim | 0:e5741b4e6a1a | 221 | /** Set LEDs |
wim | 0:e5741b4e6a1a | 222 | * |
wim | 0:e5741b4e6a1a | 223 | * @param char leds (5 least significant bits) |
wim | 0:e5741b4e6a1a | 224 | * @return none |
wim | 0:e5741b4e6a1a | 225 | */ |
wim | 0:e5741b4e6a1a | 226 | void setLED (char leds = 0); |
wim | 0:e5741b4e6a1a | 227 | |
wim | 0:e5741b4e6a1a | 228 | /** Set Brightness |
wim | 0:e5741b4e6a1a | 229 | * |
wim | 0:e5741b4e6a1a | 230 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle) |
wim | 0:e5741b4e6a1a | 231 | * @return none |
wim | 0:e5741b4e6a1a | 232 | */ |
wim | 0:e5741b4e6a1a | 233 | void setBrightness(char brightness = PT6318_BRT_DEF); |
wim | 0:e5741b4e6a1a | 234 | |
wim | 0:e5741b4e6a1a | 235 | /** Set the Display mode On/off |
wim | 0:e5741b4e6a1a | 236 | * |
wim | 0:e5741b4e6a1a | 237 | * @param bool display mode |
wim | 0:e5741b4e6a1a | 238 | */ |
wim | 0:e5741b4e6a1a | 239 | void setDisplay(bool on); |
wim | 0:e5741b4e6a1a | 240 | |
wim | 0:e5741b4e6a1a | 241 | private: |
wim | 0:e5741b4e6a1a | 242 | SPI _spi; |
wim | 0:e5741b4e6a1a | 243 | DigitalOut _cs; |
wim | 0:e5741b4e6a1a | 244 | Mode _mode; |
wim | 0:e5741b4e6a1a | 245 | char _display; |
wim | 0:e5741b4e6a1a | 246 | char _bright; |
wim | 0:e5741b4e6a1a | 247 | |
wim | 0:e5741b4e6a1a | 248 | /** Init the SPI interface and the controller |
wim | 0:e5741b4e6a1a | 249 | * @param none |
wim | 0:e5741b4e6a1a | 250 | * @return none |
wim | 0:e5741b4e6a1a | 251 | */ |
wim | 0:e5741b4e6a1a | 252 | void _init(); |
wim | 0:e5741b4e6a1a | 253 | |
wim | 0:e5741b4e6a1a | 254 | /** Helper to reverse all command or databits. The PT6318 expects LSB first, whereas SPI is MSB first |
wim | 0:e5741b4e6a1a | 255 | * @param char data |
wim | 0:e5741b4e6a1a | 256 | * @return bitreversed data |
wim | 0:e5741b4e6a1a | 257 | */ |
wim | 0:e5741b4e6a1a | 258 | char _flip(char data); |
wim | 0:e5741b4e6a1a | 259 | |
wim | 0:e5741b4e6a1a | 260 | /** Write command and parameter to PT6318 |
wim | 0:e5741b4e6a1a | 261 | * @param int cmd Command byte |
wim | 0:e5741b4e6a1a | 262 | * &Param int data Parameters for command |
wim | 0:e5741b4e6a1a | 263 | * @return none |
wim | 0:e5741b4e6a1a | 264 | */ |
wim | 0:e5741b4e6a1a | 265 | void _writeCmd(int cmd, int data); |
wim | 0:e5741b4e6a1a | 266 | }; |
wim | 0:e5741b4e6a1a | 267 | |
wim | 0:e5741b4e6a1a | 268 | |
wim | 0:e5741b4e6a1a | 269 | |
wim | 0:e5741b4e6a1a | 270 | #if (KUH8300_TEST == 1) |
wim | 0:e5741b4e6a1a | 271 | // Derived class for KUH8300 front display unit |
wim | 0:e5741b4e6a1a | 272 | // Grids 2-11 all display 14-Segment digits and several Icons. |
wim | 0:e5741b4e6a1a | 273 | // Grid 1 and 12 display Icons. |
wim | 0:e5741b4e6a1a | 274 | |
wim | 0:e5741b4e6a1a | 275 | // |
wim | 0:e5741b4e6a1a | 276 | #include "Font_7Seg.h" |
wim | 0:e5741b4e6a1a | 277 | |
wim | 0:e5741b4e6a1a | 278 | //KUH8300 Display data |
wim | 0:e5741b4e6a1a | 279 | #define KUH8300_NR_GRIDS 6 |
wim | 0:e5741b4e6a1a | 280 | #define KUH8300_NR_DIGITS 8 |
wim | 0:e5741b4e6a1a | 281 | #define KUH8300_NR_UDC 8 |
wim | 0:e5741b4e6a1a | 282 | |
wim | 0:e5741b4e6a1a | 283 | //KUH8300 Memory size in bytes for Display |
wim | 0:e5741b4e6a1a | 284 | #define KUH8300_DISPLAY_MEM (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID) |
wim | 0:e5741b4e6a1a | 285 | |
wim | 0:e5741b4e6a1a | 286 | |
wim | 0:e5741b4e6a1a | 287 | /** Constructor for class for driving Princeton PT6318 VFD controller as used in KUH8300 |
wim | 0:e5741b4e6a1a | 288 | * |
wim | 0:e5741b4e6a1a | 289 | * @brief Supports 8 Grids of 20 Segments and Icons (8 1/2 digits of 14 segments plus some icons). |
wim | 0:e5741b4e6a1a | 290 | * Also supports a scanned keyboard of 12 keys and 1 LED. |
wim | 0:e5741b4e6a1a | 291 | * |
wim | 0:e5741b4e6a1a | 292 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:e5741b4e6a1a | 293 | */ |
wim | 0:e5741b4e6a1a | 294 | class PT6318_KUH8300 : public PT6318, public Stream { |
wim | 0:e5741b4e6a1a | 295 | public: |
wim | 0:e5741b4e6a1a | 296 | |
wim | 0:e5741b4e6a1a | 297 | /** Enums for Icons */ |
wim | 0:e5741b4e6a1a | 298 | // Grid encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:e5741b4e6a1a | 299 | enum Icon { |
wim | 0:e5741b4e6a1a | 300 | CAM = (1<<24) | S7_CAM, |
wim | 0:e5741b4e6a1a | 301 | DIG = (1<<24) | S7_DIG, |
wim | 0:e5741b4e6a1a | 302 | MONO = (1<<24) | S7_MONO, |
wim | 0:e5741b4e6a1a | 303 | PRG = (1<<24) | S7_PRG, |
wim | 0:e5741b4e6a1a | 304 | DTS = (1<<24) | S7_DTS, |
wim | 0:e5741b4e6a1a | 305 | MEM = (1<<24) | S7_MEM, |
wim | 0:e5741b4e6a1a | 306 | KHZ = (1<<24) | S7_KHZ, |
wim | 0:e5741b4e6a1a | 307 | STR = (1<<24) | S7_STR, |
wim | 0:e5741b4e6a1a | 308 | MHZ = (1<<24) | S7_MHZ, |
wim | 0:e5741b4e6a1a | 309 | |
wim | 0:e5741b4e6a1a | 310 | KEY = (2<<24) | S7_KEY, |
wim | 0:e5741b4e6a1a | 311 | ALL = (2<<24) | S7_ALL, |
wim | 0:e5741b4e6a1a | 312 | DP6 = (2<<24) | S7_DP6, |
wim | 0:e5741b4e6a1a | 313 | COL6 = (2<<24) | S7_COL6, |
wim | 0:e5741b4e6a1a | 314 | |
wim | 0:e5741b4e6a1a | 315 | ARW = (3<<24) | S7_ARW, |
wim | 0:e5741b4e6a1a | 316 | A_ = (3<<24) | S7_A_, |
wim | 0:e5741b4e6a1a | 317 | B_ = (3<<24) | S7_B_, |
wim | 0:e5741b4e6a1a | 318 | CD4A = (3<<24) | S7_CD4A, |
wim | 0:e5741b4e6a1a | 319 | |
wim | 0:e5741b4e6a1a | 320 | CHP = (4<<24) | S7_CHP, |
wim | 0:e5741b4e6a1a | 321 | N3 = (4<<24) | S7_N3, |
wim | 0:e5741b4e6a1a | 322 | L3 = (4<<24) | S7_L3, |
wim | 0:e5741b4e6a1a | 323 | HK3 = (4<<24) | S7_HK3, |
wim | 0:e5741b4e6a1a | 324 | |
wim | 0:e5741b4e6a1a | 325 | TTL = (5<<24) | S7_TTL, |
wim | 0:e5741b4e6a1a | 326 | JM1 = (5<<24) | S7_JM1, |
wim | 0:e5741b4e6a1a | 327 | HK2 = (5<<24) | S7_HK2, |
wim | 0:e5741b4e6a1a | 328 | |
wim | 0:e5741b4e6a1a | 329 | PSE = (6<<24) | S7_PSE, |
wim | 0:e5741b4e6a1a | 330 | PLY = (6<<24) | S7_PLY, |
wim | 0:e5741b4e6a1a | 331 | PBC = (6<<24) | S7_PBC, |
wim | 0:e5741b4e6a1a | 332 | DVD = (6<<24) | S7_DVD, |
wim | 0:e5741b4e6a1a | 333 | CD = (6<<24) | S7_CD, |
wim | 0:e5741b4e6a1a | 334 | V = (6<<24) | S7_V, |
wim | 0:e5741b4e6a1a | 335 | S = (6<<24) | S7_S |
wim | 0:e5741b4e6a1a | 336 | }; |
wim | 0:e5741b4e6a1a | 337 | |
wim | 1:a7a518dbca96 | 338 | typedef char UDCData_t[KUH8300_NR_UDC]; |
wim | 0:e5741b4e6a1a | 339 | |
wim | 0:e5741b4e6a1a | 340 | |
wim | 0:e5741b4e6a1a | 341 | /** Constructor for class for driving Princeton PT6318 VFD controller as used in KUH8300 |
wim | 0:e5741b4e6a1a | 342 | * |
wim | 0:e5741b4e6a1a | 343 | * @brief Supports 8 Grids of 20 Segments and Icons (8 1/2 digits of 14 Segments plus some icons). |
wim | 0:e5741b4e6a1a | 344 | * Also supports a scanned keyboard of 12 keys and 1 LED. |
wim | 0:e5741b4e6a1a | 345 | * |
wim | 0:e5741b4e6a1a | 346 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:e5741b4e6a1a | 347 | */ |
wim | 0:e5741b4e6a1a | 348 | PT6318_KUH8300(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 0:e5741b4e6a1a | 349 | |
wim | 0:e5741b4e6a1a | 350 | #if DOXYGEN_ONLY |
wim | 0:e5741b4e6a1a | 351 | /** Write a character to the Display |
wim | 0:e5741b4e6a1a | 352 | * |
wim | 0:e5741b4e6a1a | 353 | * @param c The character to write to the display |
wim | 0:e5741b4e6a1a | 354 | */ |
wim | 0:e5741b4e6a1a | 355 | int putc(int c); |
wim | 0:e5741b4e6a1a | 356 | |
wim | 0:e5741b4e6a1a | 357 | /** Write a formatted string to the Display |
wim | 0:e5741b4e6a1a | 358 | * |
wim | 0:e5741b4e6a1a | 359 | * @param format A printf-style format string, followed by the |
wim | 0:e5741b4e6a1a | 360 | * variables to use in formatting the string. |
wim | 0:e5741b4e6a1a | 361 | */ |
wim | 0:e5741b4e6a1a | 362 | int printf(const char* format, ...); |
wim | 0:e5741b4e6a1a | 363 | #endif |
wim | 0:e5741b4e6a1a | 364 | |
wim | 0:e5741b4e6a1a | 365 | /** Locate cursor to a screen column |
wim | 0:e5741b4e6a1a | 366 | * |
wim | 0:e5741b4e6a1a | 367 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:e5741b4e6a1a | 368 | */ |
wim | 0:e5741b4e6a1a | 369 | void locate(int column); |
wim | 0:e5741b4e6a1a | 370 | |
wim | 0:e5741b4e6a1a | 371 | /** Clear the screen and locate to 0 |
wim | 0:e5741b4e6a1a | 372 | * @param bool clrAll Clear Icons also (default = false) |
wim | 0:e5741b4e6a1a | 373 | */ |
wim | 0:e5741b4e6a1a | 374 | void cls(bool clrAll = false); |
wim | 0:e5741b4e6a1a | 375 | |
wim | 0:e5741b4e6a1a | 376 | /** Set Icon |
wim | 0:e5741b4e6a1a | 377 | * |
wim | 0:e5741b4e6a1a | 378 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:e5741b4e6a1a | 379 | * @return none |
wim | 0:e5741b4e6a1a | 380 | */ |
wim | 0:e5741b4e6a1a | 381 | void setIcon(Icon icon); |
wim | 0:e5741b4e6a1a | 382 | |
wim | 0:e5741b4e6a1a | 383 | /** Clr Icon |
wim | 0:e5741b4e6a1a | 384 | * |
wim | 0:e5741b4e6a1a | 385 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs |
wim | 0:e5741b4e6a1a | 386 | * @return none |
wim | 0:e5741b4e6a1a | 387 | */ |
wim | 0:e5741b4e6a1a | 388 | void clrIcon(Icon icon); |
wim | 0:e5741b4e6a1a | 389 | |
wim | 0:e5741b4e6a1a | 390 | /** Set User Defined Characters (UDC) |
wim | 0:e5741b4e6a1a | 391 | * |
wim | 0:e5741b4e6a1a | 392 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 0:e5741b4e6a1a | 393 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 0:e5741b4e6a1a | 394 | */ |
wim | 0:e5741b4e6a1a | 395 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 0:e5741b4e6a1a | 396 | |
wim | 0:e5741b4e6a1a | 397 | |
wim | 0:e5741b4e6a1a | 398 | /** Number of screen columns |
wim | 0:e5741b4e6a1a | 399 | * |
wim | 0:e5741b4e6a1a | 400 | * @param none |
wim | 0:e5741b4e6a1a | 401 | * @return columns |
wim | 0:e5741b4e6a1a | 402 | */ |
wim | 0:e5741b4e6a1a | 403 | int columns(); |
wim | 0:e5741b4e6a1a | 404 | |
wim | 0:e5741b4e6a1a | 405 | /** Write databyte to PT6318 |
wim | 0:e5741b4e6a1a | 406 | * @param char data byte written at given address |
wim | 0:e5741b4e6a1a | 407 | * @param int address display memory location to write byte |
wim | 0:e5741b4e6a1a | 408 | * @return none |
wim | 0:e5741b4e6a1a | 409 | */ |
wim | 0:e5741b4e6a1a | 410 | void writeData(int address, char data){ |
wim | 0:e5741b4e6a1a | 411 | PT6318::writeData(address, data); |
wim | 0:e5741b4e6a1a | 412 | } |
wim | 0:e5741b4e6a1a | 413 | |
wim | 0:e5741b4e6a1a | 414 | /** Write Display datablock to PT6318 |
wim | 0:e5741b4e6a1a | 415 | * @param DisplayData_t data Array of PT6318_DISPLAY_MEM (=36) bytes for displaydata (starting at address) |
wim | 0:e5741b4e6a1a | 416 | * @param length number bytes to write (valid range 0..(KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID) == 24, starting at address) |
wim | 0:e5741b4e6a1a | 417 | * @param int address display memory location to write byte (default = 0) |
wim | 0:e5741b4e6a1a | 418 | * @return none |
wim | 0:e5741b4e6a1a | 419 | */ |
wim | 0:e5741b4e6a1a | 420 | void writeData(DisplayData_t data, int length = (KUH8300_NR_GRIDS * PT6318_BYTES_PER_GRID), int address = 0) { |
wim | 0:e5741b4e6a1a | 421 | PT6318::writeData(data, length, address); |
wim | 0:e5741b4e6a1a | 422 | } |
wim | 0:e5741b4e6a1a | 423 | |
wim | 0:e5741b4e6a1a | 424 | protected: |
wim | 0:e5741b4e6a1a | 425 | // Stream implementation functions |
wim | 0:e5741b4e6a1a | 426 | virtual int _putc(int value); |
wim | 0:e5741b4e6a1a | 427 | virtual int _getc(); |
wim | 0:e5741b4e6a1a | 428 | |
wim | 0:e5741b4e6a1a | 429 | private: |
wim | 0:e5741b4e6a1a | 430 | int _column; // Current cursor location |
wim | 0:e5741b4e6a1a | 431 | int _columns; // Max number of columns |
wim | 0:e5741b4e6a1a | 432 | |
wim | 0:e5741b4e6a1a | 433 | DisplayData_t _displaybuffer; // Local mirror for all chars and icons |
wim | 1:a7a518dbca96 | 434 | UDCData_t _UDC_7S; // User Defined Character pattterns (UDC) |
wim | 1:a7a518dbca96 | 435 | }; |
wim | 0:e5741b4e6a1a | 436 | #endif |
wim | 0:e5741b4e6a1a | 437 | |
wim | 0:e5741b4e6a1a | 438 | #endif |