Library for Princeton PT6302 VFD controller. Note the PT6302 is identical to the OKI ML9208.

Dependents:   mbed_PT6302 mbed_PT6301

More information is here.

Committer:
wim
Date:
Sun Dec 03 18:02:15 2017 +0000
Revision:
0:ecc29c13a997
Library for Princeton PT6302 VFD controller.; Note the PT6302 is identical to the OKI ML9208.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:ecc29c13a997 1 /* mbed PT6302 Library, for Princeton PT6302 VFD controller
wim 0:ecc29c13a997 2 * Note the PT6302 is identical to the OKI ML9208
wim 0:ecc29c13a997 3 *
wim 0:ecc29c13a997 4 * Copyright (c) 2017, v01: WH, Initial version
wim 0:ecc29c13a997 5 *
wim 0:ecc29c13a997 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:ecc29c13a997 7 * of this software and associated documentation files (the "Software"), to deal
wim 0:ecc29c13a997 8 * in the Software without restriction, including without limitation the rights
wim 0:ecc29c13a997 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:ecc29c13a997 10 * copies of the Software, and to permit persons to whom the Software is
wim 0:ecc29c13a997 11 * furnished to do so, subject to the following conditions:
wim 0:ecc29c13a997 12 *
wim 0:ecc29c13a997 13 * The above copyright notice and this permission notice shall be included in
wim 0:ecc29c13a997 14 * all copies or substantial portions of the Software.
wim 0:ecc29c13a997 15 *
wim 0:ecc29c13a997 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:ecc29c13a997 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:ecc29c13a997 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:ecc29c13a997 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:ecc29c13a997 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:ecc29c13a997 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:ecc29c13a997 22 * THE SOFTWARE.
wim 0:ecc29c13a997 23 */
wim 0:ecc29c13a997 24
wim 0:ecc29c13a997 25 #ifndef PT6302_H
wim 0:ecc29c13a997 26 #define PT6302_H
wim 0:ecc29c13a997 27
wim 0:ecc29c13a997 28 // Select one of the testboards for Princeton PT6302 VFD controller
wim 0:ecc29c13a997 29 #include "PT6302_Config.h"
wim 0:ecc29c13a997 30 #include "PT6302_UDC.h"
wim 0:ecc29c13a997 31
wim 0:ecc29c13a997 32 /** An interface for driving Princeton PT6302 VFD controller
wim 0:ecc29c13a997 33 *
wim 0:ecc29c13a997 34 * @code
wim 0:ecc29c13a997 35 *
wim 0:ecc29c13a997 36 * #if (PT6302_TEST == 1)
wim 0:ecc29c13a997 37 * // Direct driving of PT6302 Test
wim 0:ecc29c13a997 38 *
wim 0:ecc29c13a997 39 * #include "mbed.h"
wim 0:ecc29c13a997 40 * #include "PT6302.h"
wim 0:ecc29c13a997 41 *
wim 0:ecc29c13a997 42 * DigitalOut myled(LED1);
wim 0:ecc29c13a997 43 * Serial pc(USBTX, USBRX);
wim 0:ecc29c13a997 44 *
wim 0:ecc29c13a997 45 * // PT6302 declaration, Default setting 16 Grids @ 35 Segments
wim 0:ecc29c13a997 46 * PT6302 PT6302(p5, p7, p8); // DI, CLK, CS
wim 0:ecc29c13a997 47 *
wim 0:ecc29c13a997 48 * int main() {
wim 0:ecc29c13a997 49 * pc.printf("Hello World: PT6302 test\n\r");
wim 0:ecc29c13a997 50 *
wim 0:ecc29c13a997 51 * PT6302.cls();
wim 0:ecc29c13a997 52 *
wim 0:ecc29c13a997 53 * PT6302.writeData((char)'H', 9);
wim 0:ecc29c13a997 54 * PT6302.writeData((char)'e', 8);
wim 0:ecc29c13a997 55 * PT6302.writeData((char)'l', 7);
wim 0:ecc29c13a997 56 * PT6302.writeData((char)'l', 6);
wim 0:ecc29c13a997 57 * PT6302.writeData((char)'o', 5);
wim 0:ecc29c13a997 58 * wait(2);
wim 0:ecc29c13a997 59 * PT6302.setBrightness(PT6302_BRT0);
wim 0:ecc29c13a997 60 * wait(2);
wim 0:ecc29c13a997 61 * PT6302.setBrightness(PT6302_BRT3);
wim 0:ecc29c13a997 62 *
wim 0:ecc29c13a997 63 * while(1) {
wim 0:ecc29c13a997 64 * myled = !myled;
wim 0:ecc29c13a997 65 * wait(1);
wim 0:ecc29c13a997 66 * }
wim 0:ecc29c13a997 67 * }
wim 0:ecc29c13a997 68 * #endif
wim 0:ecc29c13a997 69 *
wim 0:ecc29c13a997 70 * @endcode
wim 0:ecc29c13a997 71 */
wim 0:ecc29c13a997 72
wim 0:ecc29c13a997 73
wim 0:ecc29c13a997 74 //PT6302 Display and Annunciator data
wim 0:ecc29c13a997 75 #define PT6302_MAX_NR_GRIDS 16
wim 0:ecc29c13a997 76 #define PT6302_BYTES_PER_GRID 1
wim 0:ecc29c13a997 77
wim 0:ecc29c13a997 78 //Memory size in bytes for Display and Annunciators
wim 0:ecc29c13a997 79 #define PT6302_DSP_MEM 16
wim 0:ecc29c13a997 80 #define PT6302_ADD_MEM 16
wim 0:ecc29c13a997 81 //#define PT6302_UDC_MEM 8
wim 0:ecc29c13a997 82
wim 0:ecc29c13a997 83 //SPI Serial control data consists of an 8-bit command and one or more data bytes.
wim 0:ecc29c13a997 84 //Command and data are sent LSB first and latched on rising edge of CLK. Idle CLK is high.
wim 0:ecc29c13a997 85 //Data address is auto incremented.
wim 0:ecc29c13a997 86 //The commands and data are transmitted during CE low and latched on rising CE edge.
wim 0:ecc29c13a997 87 //Multiple PT6302 devices on the same bus can only be distinguised by the CE control.
wim 0:ecc29c13a997 88
wim 0:ecc29c13a997 89 //Command delay
wim 0:ecc29c13a997 90 #define PT6302_CMD_DLY 8
wim 0:ecc29c13a997 91 #define PT6302_CS_DLY 16
wim 0:ecc29c13a997 92
wim 0:ecc29c13a997 93 //
wim 0:ecc29c13a997 94 //Set Char data command (DCRAM)
wim 0:ecc29c13a997 95 // 0 0 0 1 DA3 DA2 DA1 DA0
wim 0:ecc29c13a997 96 #define PT6302_DATA_REG 0x10
wim 0:ecc29c13a997 97
wim 0:ecc29c13a997 98 //DA3..DA0 DCRAM Address
wim 0:ecc29c13a997 99 #define PT6302_DADR_MSK 0x0F
wim 0:ecc29c13a997 100
wim 0:ecc29c13a997 101 //Char data (2nd byte, 3rd byte ...)
wim 0:ecc29c13a997 102 //DA7..DA0 Character Data
wim 0:ecc29c13a997 103 #define PT6302_DATA_MSK 0xFF
wim 0:ecc29c13a997 104
wim 0:ecc29c13a997 105
wim 0:ecc29c13a997 106 //
wim 0:ecc29c13a997 107 //Set UDC data command (CGRAM)
wim 0:ecc29c13a997 108 // 0 0 1 0 * UA2 UA1 UA0
wim 0:ecc29c13a997 109 #define PT6302_UDC_REG 0x20
wim 0:ecc29c13a997 110
wim 0:ecc29c13a997 111 //UA2..UA0 CGRAM Address (UDC RAM address)
wim 0:ecc29c13a997 112 #define PT6302_UADR_MSK 0x07
wim 0:ecc29c13a997 113 #define PT6302_NR_UDC 8
wim 0:ecc29c13a997 114
wim 0:ecc29c13a997 115 //User Defined Characters (UDCs) consist of 5x7 dots and are defined by a 5 byte bitpattern.
wim 0:ecc29c13a997 116 //UDC data (2nd byte .. 6th byte)
wim 0:ecc29c13a997 117 // D7 D6 D5 D4.. D1 D0
wim 0:ecc29c13a997 118 // 0 * CD30 CD25 ...... CD0
wim 0:ecc29c13a997 119 // 1 * CD31 CD26 ...... CD1
wim 0:ecc29c13a997 120 // 2 * CD32 CD27 ...... CD2
wim 0:ecc29c13a997 121 // 3 * CD33 CD28 ...... CD3
wim 0:ecc29c13a997 122 // 4 * CD34 CD29 ...... CD4
wim 0:ecc29c13a997 123 //
wim 0:ecc29c13a997 124 #define PT6302_UDC_MSK 0x7F
wim 0:ecc29c13a997 125
wim 0:ecc29c13a997 126 //CD34..CD0 UDC Data
wim 0:ecc29c13a997 127 //UDC is a 5x7 Matrix pattern that will show on the VFD as
wim 0:ecc29c13a997 128 // 0 C0 C1 C2 C3 C4
wim 0:ecc29c13a997 129 // 1 C5 C6 ..... C9
wim 0:ecc29c13a997 130 // . .............
wim 0:ecc29c13a997 131 // . .............
wim 0:ecc29c13a997 132 // . .............
wim 0:ecc29c13a997 133 // 6 C30 C31 ... C34
wim 0:ecc29c13a997 134 //
wim 0:ecc29c13a997 135
wim 0:ecc29c13a997 136 //UDCs are defined by a 5x7 matrix and stored as 5 bytes
wim 0:ecc29c13a997 137 typedef char UDCData_t[5];
wim 0:ecc29c13a997 138
wim 0:ecc29c13a997 139
wim 0:ecc29c13a997 140 //
wim 0:ecc29c13a997 141 //Set Additional data command (ADRAM), Used for annunciators etc
wim 0:ecc29c13a997 142 // 0 0 1 1 AA3 AA2 AA1 AA0
wim 0:ecc29c13a997 143 #define PT6302_ADAT_REG 0x30
wim 0:ecc29c13a997 144
wim 0:ecc29c13a997 145 //AA3..AA0 ADRAM Address (Additional data)
wim 0:ecc29c13a997 146 #define PT6302_AADR_MSK 0x0F
wim 0:ecc29c13a997 147
wim 0:ecc29c13a997 148 //* * * * * * AD1 AD0 Additional Data (2nd byte, 3rd byte, ..)
wim 0:ecc29c13a997 149 #define PT6302_ADAT_MSK 0x03
wim 0:ecc29c13a997 150
wim 0:ecc29c13a997 151
wim 0:ecc29c13a997 152 //
wim 0:ecc29c13a997 153 //Set Port data command (General output)
wim 0:ecc29c13a997 154 // 0 1 0 0 * * P1 P0
wim 0:ecc29c13a997 155 #define PT6302_PDAT_REG 0x40
wim 0:ecc29c13a997 156
wim 0:ecc29c13a997 157 //P1 P0 Port data
wim 0:ecc29c13a997 158 #define PT6302_PDAT_MSK 0x03
wim 0:ecc29c13a997 159
wim 0:ecc29c13a997 160
wim 0:ecc29c13a997 161
wim 0:ecc29c13a997 162 //
wim 0:ecc29c13a997 163 //Set Brightness command
wim 0:ecc29c13a997 164 // 0 1 0 1 * DC2 DC1 DC0
wim 0:ecc29c13a997 165 #define PT6302_BRT_REG 0x50
wim 0:ecc29c13a997 166 #define PT6302_BRT_MSK 0x07
wim 0:ecc29c13a997 167
wim 0:ecc29c13a997 168 //DC2..DC0 Brightness Level (0..7)
wim 0:ecc29c13a997 169 //Note Brightness relationship between the number of active Grids (period) and the BRT value (duty cycle)
wim 0:ecc29c13a997 170 #define PT6302_BRT_0 0x00 //Duty 8/16 (Default)
wim 0:ecc29c13a997 171 #define PT6302_BRT_1 0x01
wim 0:ecc29c13a997 172 #define PT6302_BRT_2 0x02
wim 0:ecc29c13a997 173 #define PT6302_BRT_3 0x03
wim 0:ecc29c13a997 174 #define PT6302_BRT_4 0x04
wim 0:ecc29c13a997 175 #define PT6302_BRT_5 0x05
wim 0:ecc29c13a997 176 #define PT6302_BRT_6 0x06
wim 0:ecc29c13a997 177 #define PT6302_BRT_7 0x07 //Duty 15/16
wim 0:ecc29c13a997 178
wim 0:ecc29c13a997 179 #define PT6302_BRT_DEF (PT6302_BRT_2)
wim 0:ecc29c13a997 180
wim 0:ecc29c13a997 181
wim 0:ecc29c13a997 182 //
wim 0:ecc29c13a997 183 //Grid control command
wim 0:ecc29c13a997 184 // 0 1 1 0 * GN2 GN1 GN0
wim 0:ecc29c13a997 185 #define PT6302_GRID_REG 0x60
wim 0:ecc29c13a997 186 #define PT6302_GRID_MSK 0x07
wim 0:ecc29c13a997 187
wim 0:ecc29c13a997 188 //Grids
wim 0:ecc29c13a997 189 //
wim 0:ecc29c13a997 190 // GN2 GN1 GN0
wim 0:ecc29c13a997 191 // 0 0 0 G1 to G16 // Default
wim 0:ecc29c13a997 192 // 0 0 1 G1 to G9
wim 0:ecc29c13a997 193 // 0 1 0 G1 to G10
wim 0:ecc29c13a997 194 // 0 1 1 G1 to G11
wim 0:ecc29c13a997 195 // 1 0 0 G1 to G12
wim 0:ecc29c13a997 196 // 1 0 1 G1 to G13
wim 0:ecc29c13a997 197 // 1 1 0 G1 to G14
wim 0:ecc29c13a997 198 // 1 1 1 G1 to G15
wim 0:ecc29c13a997 199 #define PT6302_GR1_GR9 0x01
wim 0:ecc29c13a997 200 #define PT6302_GR1_GR10 0x02
wim 0:ecc29c13a997 201 #define PT6302_GR1_GR11 0x03
wim 0:ecc29c13a997 202 #define PT6302_GR1_GR12 0x04
wim 0:ecc29c13a997 203 #define PT6302_GR1_GR13 0x05
wim 0:ecc29c13a997 204 #define PT6302_GR1_GR14 0x06
wim 0:ecc29c13a997 205 #define PT6302_GR1_GR15 0x07
wim 0:ecc29c13a997 206 #define PT6302_GR1_GR16 0x00
wim 0:ecc29c13a997 207
wim 0:ecc29c13a997 208
wim 0:ecc29c13a997 209 //
wim 0:ecc29c13a997 210 //Display On/Off command
wim 0:ecc29c13a997 211 // 0 1 1 1 * * H L
wim 0:ecc29c13a997 212 #define PT6302_DSPL_REG 0x70
wim 0:ecc29c13a997 213 #define PT6302_DSPL_MSK 0x03
wim 0:ecc29c13a997 214
wim 0:ecc29c13a997 215 //Display Mode
wim 0:ecc29c13a997 216 // H L Display operating state
wim 0:ecc29c13a997 217 // 0 0 Normal (default)
wim 0:ecc29c13a997 218 // 0 1 Off
wim 0:ecc29c13a997 219 // 1 0 All Segments and Additional Segments On
wim 0:ecc29c13a997 220 // 1 1 All Segments and Additional Segments On
wim 0:ecc29c13a997 221 #define PT6302_DSPL_NRM 0x00
wim 0:ecc29c13a997 222 #define PT6302_DSPL_OFF 0x01
wim 0:ecc29c13a997 223 #define PT6302_DSPL_ON 0x02
wim 0:ecc29c13a997 224
wim 0:ecc29c13a997 225
wim 0:ecc29c13a997 226 /** A class for driving Princeton PT6302 VFD controller
wim 0:ecc29c13a997 227 *
wim 0:ecc29c13a997 228 * @brief Supports upto 16 Grids of 35 matrix segments.
wim 0:ecc29c13a997 229 * Also supports 2 additional segments and 2 port pins.
wim 0:ecc29c13a997 230 * SPI bus interface device.
wim 0:ecc29c13a997 231 */
wim 0:ecc29c13a997 232 class PT6302 {
wim 0:ecc29c13a997 233 public:
wim 0:ecc29c13a997 234
wim 0:ecc29c13a997 235 /** Enums for display mode */
wim 0:ecc29c13a997 236 enum Mode {
wim 0:ecc29c13a997 237 Grid9_Add2 = PT6302_GR1_GR9,
wim 0:ecc29c13a997 238 Grid10_Add2 = PT6302_GR1_GR10,
wim 0:ecc29c13a997 239 Grid11_Add2 = PT6302_GR1_GR11,
wim 0:ecc29c13a997 240 Grid12_Add2 = PT6302_GR1_GR12,
wim 0:ecc29c13a997 241 Grid13_Add2 = PT6302_GR1_GR13,
wim 0:ecc29c13a997 242 Grid14_Add2 = PT6302_GR1_GR14,
wim 0:ecc29c13a997 243 Grid15_Add2 = PT6302_GR1_GR15,
wim 0:ecc29c13a997 244 Grid16_Add2 = PT6302_GR1_GR16
wim 0:ecc29c13a997 245 };
wim 0:ecc29c13a997 246
wim 0:ecc29c13a997 247 /** Datatypes for display data */
wim 0:ecc29c13a997 248 // typedef char DisplayData_t[PT6302_DISPLAY_MEM];
wim 0:ecc29c13a997 249 // typedef char DisplayAdd_t[PT6302_ADD_MEM];
wim 0:ecc29c13a997 250
wim 0:ecc29c13a997 251 /** Constructor for class for driving Princeton PT6302 VFD controller
wim 0:ecc29c13a997 252 *
wim 0:ecc29c13a997 253 * @brief Supports upto 16 Grids of 35 matrix segments.
wim 0:ecc29c13a997 254 * Also supports 2 additional segments and 2 port pins.
wim 0:ecc29c13a997 255 * SPI bus interface device.
wim 0:ecc29c13a997 256 * @param PinName mosi, sclk, cs SPI bus pins
wim 0:ecc29c13a997 257 * @param Mode selects number of Grids and Segments (default 16 Grids, 2 additional segments)
wim 0:ecc29c13a997 258 */
wim 0:ecc29c13a997 259 PT6302(PinName mosi, PinName sclk, PinName cs, Mode mode = Grid16_Add2);
wim 0:ecc29c13a997 260
wim 0:ecc29c13a997 261 /** Clear the screen
wim 0:ecc29c13a997 262 *
wim 0:ecc29c13a997 263 * @param none
wim 0:ecc29c13a997 264 * @return none
wim 0:ecc29c13a997 265 */
wim 0:ecc29c13a997 266 void cls();
wim 0:ecc29c13a997 267
wim 0:ecc29c13a997 268 /** Set Brightness
wim 0:ecc29c13a997 269 *
wim 0:ecc29c13a997 270 * @param char brightness (3 significant bits, valid range 0..7 (dutycycle linked to number of grids)
wim 0:ecc29c13a997 271 * @return none
wim 0:ecc29c13a997 272 */
wim 0:ecc29c13a997 273 void setBrightness(char brightness = PT6302_BRT_DEF);
wim 0:ecc29c13a997 274
wim 0:ecc29c13a997 275 /** Set the Display mode On/off
wim 0:ecc29c13a997 276 *
wim 0:ecc29c13a997 277 * @param bool display mode
wim 0:ecc29c13a997 278 * @return none
wim 0:ecc29c13a997 279 */
wim 0:ecc29c13a997 280 void setDisplay(bool on);
wim 0:ecc29c13a997 281
wim 0:ecc29c13a997 282
wim 0:ecc29c13a997 283 /** Set Port
wim 0:ecc29c13a997 284 *
wim 0:ecc29c13a997 285 * @param char port (2 least significant bits)
wim 0:ecc29c13a997 286 * @return none
wim 0:ecc29c13a997 287 */
wim 0:ecc29c13a997 288 void setPort (char port = 0);
wim 0:ecc29c13a997 289
wim 0:ecc29c13a997 290 /** Set User Defined Characters (UDC)
wim 0:ecc29c13a997 291 *
wim 0:ecc29c13a997 292 * @param unsigned char udc_idx The Index of the UDC (0..7)
wim 0:ecc29c13a997 293 * @param UDCData_t udc_data The bitpattern for the UDC (5 bytes)
wim 0:ecc29c13a997 294 * @return none
wim 0:ecc29c13a997 295 */
wim 0:ecc29c13a997 296 void setUDC(unsigned char udc_idx, UDCData_t udc_data);
wim 0:ecc29c13a997 297
wim 0:ecc29c13a997 298
wim 0:ecc29c13a997 299 /** Write Data to PT6302
wim 0:ecc29c13a997 300 *
wim 0:ecc29c13a997 301 * @param char data Character code
wim 0:ecc29c13a997 302 * @param char address Parameter for data
wim 0:ecc29c13a997 303 * @return none
wim 0:ecc29c13a997 304 */
wim 0:ecc29c13a997 305 void writeData(char data, char address);
wim 0:ecc29c13a997 306
wim 0:ecc29c13a997 307 /** Write Additional Data to PT6302
wim 0:ecc29c13a997 308 *
wim 0:ecc29c13a997 309 * @param char adata Additional code (annunciator)
wim 0:ecc29c13a997 310 * @param char address Parameter for data
wim 0:ecc29c13a997 311 * @return none
wim 0:ecc29c13a997 312 */
wim 0:ecc29c13a997 313 void writeAData(char adata, char address);
wim 0:ecc29c13a997 314
wim 0:ecc29c13a997 315 protected:
wim 0:ecc29c13a997 316 /** Write command and parameters to PT6302
wim 0:ecc29c13a997 317 *
wim 0:ecc29c13a997 318 * @param char cmd Command byte
wim 0:ecc29c13a997 319 * @param char data Parameter for command
wim 0:ecc29c13a997 320 * @return none
wim 0:ecc29c13a997 321 */
wim 0:ecc29c13a997 322 void _writeCmd(char cmd, char data);
wim 0:ecc29c13a997 323
wim 0:ecc29c13a997 324 /** Write command to PT6302
wim 0:ecc29c13a997 325 *
wim 0:ecc29c13a997 326 * @param char cmd Command byte
wim 0:ecc29c13a997 327 * @return none
wim 0:ecc29c13a997 328 */
wim 0:ecc29c13a997 329 void _writeCmd(char cmd);
wim 0:ecc29c13a997 330
wim 0:ecc29c13a997 331 char _port;
wim 0:ecc29c13a997 332
wim 0:ecc29c13a997 333 private:
wim 0:ecc29c13a997 334 SPI _spi;
wim 0:ecc29c13a997 335 DigitalOut _cs;
wim 0:ecc29c13a997 336 Mode _mode;
wim 0:ecc29c13a997 337
wim 0:ecc29c13a997 338 /** Init the SPI interface and the controller
wim 0:ecc29c13a997 339 *
wim 0:ecc29c13a997 340 * @param none
wim 0:ecc29c13a997 341 * @return none
wim 0:ecc29c13a997 342 */
wim 0:ecc29c13a997 343 void _init();
wim 0:ecc29c13a997 344
wim 0:ecc29c13a997 345 /** Helper to reverse all command or databits. The PT6302 expects LSB first, whereas SPI is MSB first
wim 0:ecc29c13a997 346 *
wim 0:ecc29c13a997 347 * @param char data
wim 0:ecc29c13a997 348 * @return bitreversed data
wim 0:ecc29c13a997 349 */
wim 0:ecc29c13a997 350 char _flip(char data);
wim 0:ecc29c13a997 351
wim 0:ecc29c13a997 352 };
wim 0:ecc29c13a997 353
wim 0:ecc29c13a997 354
wim 0:ecc29c13a997 355 #if (HANNSTAR_TEST == 1)
wim 0:ecc29c13a997 356 // Derived class for HANNSTAR display unit
wim 0:ecc29c13a997 357 // Grids 1-16 all display 35 segment matrix characters and no Additional segments.
wim 0:ecc29c13a997 358 //
wim 0:ecc29c13a997 359
wim 0:ecc29c13a997 360 //HANNSTAR Display data
wim 0:ecc29c13a997 361 #define HANNSTAR_NR_GRIDS 16
wim 0:ecc29c13a997 362 #define HANNSTAR_NR_DIGITS 16
wim 0:ecc29c13a997 363 //#define HANNSTAR_NR_UDC 8
wim 0:ecc29c13a997 364
wim 0:ecc29c13a997 365 //HANNSTAR Memory size in bytes for Display
wim 0:ecc29c13a997 366 //#define HANNSTAR_DISPLAY_MEM (HANNSTAR_NR_GRIDS * PT6302_BYTES_PER_GRID)
wim 0:ecc29c13a997 367
wim 0:ecc29c13a997 368
wim 0:ecc29c13a997 369 //
wim 0:ecc29c13a997 370 //Set Port data command (General output)
wim 0:ecc29c13a997 371 // 0 1 0 0 * * P1 P0
wim 0:ecc29c13a997 372
wim 0:ecc29c13a997 373 //P0 P1 Port data, P0 is used for VGen control
wim 0:ecc29c13a997 374 #define PT6302_HANN_PDAT_MSK 0x02
wim 0:ecc29c13a997 375
wim 0:ecc29c13a997 376 //P0 is used to control the VFD Voltage generator (-24V and Filament)
wim 0:ecc29c13a997 377 #define PT6302_HANN_VGEN 0x01
wim 0:ecc29c13a997 378
wim 0:ecc29c13a997 379
wim 0:ecc29c13a997 380
wim 0:ecc29c13a997 381 /** Constructor for class for driving Princeton PT6302 VFD controller as used in HANNSTAR
wim 0:ecc29c13a997 382 *
wim 0:ecc29c13a997 383 * @brief Supports 16 Grids of 35 Segments without additional Segments.
wim 0:ecc29c13a997 384 *
wim 0:ecc29c13a997 385 * @param PinName mosi, sclk, cs SPI bus pins
wim 0:ecc29c13a997 386 */
wim 0:ecc29c13a997 387 class PT6302_HANNSTAR : public PT6302, public Stream {
wim 0:ecc29c13a997 388 public:
wim 0:ecc29c13a997 389
wim 0:ecc29c13a997 390 /** Constructor for class for driving Princeton PT6302 VFD controller as used in HANNSTAR
wim 0:ecc29c13a997 391 *
wim 0:ecc29c13a997 392 * @brief Supports 16 Grids of 35 Segments without additional Segments.
wim 0:ecc29c13a997 393 *
wim 0:ecc29c13a997 394 * @param PinName mosi, sclk, cs SPI bus pins
wim 0:ecc29c13a997 395 */
wim 0:ecc29c13a997 396 PT6302_HANNSTAR(PinName mosi, PinName sclk, PinName cs);
wim 0:ecc29c13a997 397
wim 0:ecc29c13a997 398 #if DOXYGEN_ONLY
wim 0:ecc29c13a997 399 /** Write a character to the Display
wim 0:ecc29c13a997 400 *
wim 0:ecc29c13a997 401 * @param c The character to write to the display
wim 0:ecc29c13a997 402 * @return char written
wim 0:ecc29c13a997 403 */
wim 0:ecc29c13a997 404 int putc(int c);
wim 0:ecc29c13a997 405
wim 0:ecc29c13a997 406 /** Write a formatted string to the Display
wim 0:ecc29c13a997 407 *
wim 0:ecc29c13a997 408 * @param format A printf-style format string, followed by the
wim 0:ecc29c13a997 409 * variables to use in formatting the string.
wim 0:ecc29c13a997 410 */
wim 0:ecc29c13a997 411 int printf(const char* format, ...);
wim 0:ecc29c13a997 412 #endif
wim 0:ecc29c13a997 413
wim 0:ecc29c13a997 414 /** Locate cursor to a screen column
wim 0:ecc29c13a997 415 *
wim 0:ecc29c13a997 416 * @param column The horizontal position from the left, indexed from 0
wim 0:ecc29c13a997 417 * @return none
wim 0:ecc29c13a997 418 */
wim 0:ecc29c13a997 419 void locate(int column);
wim 0:ecc29c13a997 420
wim 0:ecc29c13a997 421 /** Clear the screen and locate to 0
wim 0:ecc29c13a997 422 *
wim 0:ecc29c13a997 423 * @param bool clrAll Clear Icons also (default = false)
wim 0:ecc29c13a997 424 */
wim 0:ecc29c13a997 425 void cls(bool clrAll = false);
wim 0:ecc29c13a997 426
wim 0:ecc29c13a997 427 /** Number of screen columns
wim 0:ecc29c13a997 428 *
wim 0:ecc29c13a997 429 * @param none
wim 0:ecc29c13a997 430 * @return columns
wim 0:ecc29c13a997 431 */
wim 0:ecc29c13a997 432 int columns();
wim 0:ecc29c13a997 433
wim 0:ecc29c13a997 434 /** Set Port
wim 0:ecc29c13a997 435 *
wim 0:ecc29c13a997 436 * @param char port (Only Bit 1 is used)
wim 0:ecc29c13a997 437 * @return none
wim 0:ecc29c13a997 438 */
wim 0:ecc29c13a997 439 void setPort (char port = 0);
wim 0:ecc29c13a997 440
wim 0:ecc29c13a997 441 /** Set VFD VGen
wim 0:ecc29c13a997 442 *
wim 0:ecc29c13a997 443 * @param bool on
wim 0:ecc29c13a997 444 * @return none
wim 0:ecc29c13a997 445 */
wim 0:ecc29c13a997 446 void setVGen (bool on = true);
wim 0:ecc29c13a997 447
wim 0:ecc29c13a997 448 protected:
wim 0:ecc29c13a997 449 // Stream implementation functions
wim 0:ecc29c13a997 450 virtual int _putc(int value);
wim 0:ecc29c13a997 451 virtual int _getc();
wim 0:ecc29c13a997 452
wim 0:ecc29c13a997 453 private:
wim 0:ecc29c13a997 454 int _column; // Current cursor location
wim 0:ecc29c13a997 455 int _columns; // Max number of columns
wim 0:ecc29c13a997 456
wim 0:ecc29c13a997 457 // DisplayData_t _displaybuffer; // Local mirror for all chars and icons
wim 0:ecc29c13a997 458 };
wim 0:ecc29c13a997 459 #endif
wim 0:ecc29c13a997 460
wim 0:ecc29c13a997 461 #endif