Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PT6315.h
00001 /* mbed PT6315 Library, for Princeton PT6315 VFD controller 00002 * Copyright (c) 2016, v01: WH, Initial version for DVDR3510 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #ifndef PT6315_H 00024 #define PT6315_H 00025 00026 // Select one of the testboards for Princeton PT6315 VFD controller 00027 #include "PT6315_Config.h" 00028 00029 /** An interface for driving Princeton PT6315 VFD controller 00030 * 00031 * @code 00032 * 00033 * #if (PT6315_TEST == 1) 00034 * // Direct driving of PT6315 Test 00035 * 00036 * #include "mbed.h" 00037 * #include "PT6315.h" 00038 * 00039 * DisplayData_t size is 24 bytes (8 Grids @ 20 Segments) ... 48 bytes (16 Grids @ 12 Segments) 00040 * DisplayData_t size default is 48 bytes (16 Grids @ 12 Segments) 00041 * PT6315::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, 00042 * 0xFF,0x0F,0x00 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00}; 00043 * 00044 * // KeyData_t size is 6 bytes 00045 * PT6315::KeyData_t keydata; 00046 * 00047 * // PT6315 declaration, Default setting 16 Grids @ 12 Segments 00048 * PT6315 PT6315(p5,p6,p7, p8); 00049 * 00050 * int main() { 00051 * PT6315.cls(); 00052 * PT6315.writeData(all_str); 00053 * wait(4); 00054 * PT6315.setBrightness(PT6315_BRT0); 00055 * wait(1); 00056 * PT6315.setBrightness(PT6315_BRT3); 00057 * 00058 * while (1) { 00059 * // Check and read keydata 00060 * if (PT6315.getKeys(&keydata)) { 00061 * pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]); 00062 * 00063 * if (keydata[0] == 0x10) { //sw2 00064 * PT6315.cls(); 00065 * wait(1); 00066 * PT6315.writeData(all_str); 00067 * } 00068 * } 00069 * } 00070 * } 00071 * #endif 00072 * 00073 * @endcode 00074 */ 00075 00076 //PT6315 Display and Keymatrix data 00077 #define PT6315_MAX_NR_GRIDS 12 00078 #define PT6315_BYTES_PER_GRID 3 00079 //Significant bits Keymatrix data 00080 #define PT6315_KEY_MSK 0xFF 00081 00082 //Memory size in bytes for Display and Keymatrix 00083 #define PT6315_DISPLAY_MEM (PT6315_MAX_NR_GRIDS * PT6315_BYTES_PER_GRID) 00084 #define PT6315_KEY_MEM 4 00085 00086 //Reserved bits for commands 00087 #define PT6315_CMD_MSK 0xC0 00088 00089 //Mode setting command 00090 #define PT6315_MODE_SET_CMD 0x00 00091 #define PT6315_GR4_SEG24 0x00 00092 #define PT6315_GR5_SEG23 0x01 00093 #define PT6315_GR6_SEG22 0x02 00094 #define PT6315_GR7_SEG21 0x03 00095 #define PT6315_GR8_SEG20 0x04 00096 #define PT6315_GR9_SEG19 0x05 00097 #define PT6315_GR10_SEG18 0x06 00098 #define PT6315_GR11_SEG17 0x07 00099 #define PT6315_GR12_SEG16 0x08 //default 00100 00101 //Data setting commands 00102 #define PT6315_DATA_SET_CMD 0x40 00103 #define PT6315_DATA_WR 0x00 00104 #define PT6315_LED_WR 0x01 00105 #define PT6315_KEY_RD 0x02 00106 #define PT6315_SW_RD 0x03 00107 #define PT6315_ADDR_INC 0x00 00108 #define PT6315_ADDR_FIXED 0x04 00109 #define PT6315_MODE_NORM 0x00 00110 #define PT6315_MODE_TEST 0x08 00111 00112 //LED settings data 00113 #define PT6315_LED_MSK 0x0F 00114 #define PT6315_LED1 0x01 00115 #define PT6315_LED2 0x02 00116 #define PT6315_LED3 0x04 00117 #define PT6315_LED4 0x08 00118 00119 //Address setting commands 00120 #define PT6315_ADDR_SET_CMD 0xC0 00121 #define PT6315_ADDR_MSK 0x3F 00122 00123 //Display control commands 00124 #define PT6315_DSP_CTRL_CMD 0x80 00125 #define PT6315_BRT_MSK 0x07 00126 #define PT6315_BRT0 0x00 //Pulsewidth 1/16, Default 00127 #define PT6315_BRT1 0x01 00128 #define PT6315_BRT2 0x02 00129 #define PT6315_BRT3 0x03 00130 #define PT6315_BRT4 0x04 00131 #define PT6315_BRT5 0x05 00132 #define PT6315_BRT6 0x06 00133 #define PT6315_BRT7 0x07 //Pulsewidth 14/16 00134 00135 #define PT6315_BRT_DEF PT6315_BRT3 00136 00137 #define PT6315_DSP_OFF 0x00 //Default 00138 #define PT6315_DSP_ON 0x08 00139 00140 00141 /** A class for driving Princeton PT6315 VFD controller 00142 * 00143 * @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. 00144 * SPI bus interface device. 00145 */ 00146 class PT6315 { 00147 public: 00148 00149 /** Enums for display mode */ 00150 enum Mode { 00151 Grid4_Seg24 = PT6315_GR4_SEG24, 00152 Grid5_Seg23 = PT6315_GR5_SEG23, 00153 Grid6_Seg22 = PT6315_GR6_SEG22, 00154 Grid7_Seg21 = PT6315_GR7_SEG21, 00155 Grid8_Seg20 = PT6315_GR8_SEG20, 00156 Grid9_Seg19 = PT6315_GR9_SEG19, 00157 Grid10_Seg18 = PT6315_GR10_SEG18, 00158 Grid11_Seg17 = PT6315_GR11_SEG17, 00159 Grid12_Seg16 = PT6315_GR12_SEG16 00160 }; 00161 00162 /** Datatypes for display and keymatrix data */ 00163 typedef char DisplayData_t[PT6315_DISPLAY_MEM]; 00164 typedef char KeyData_t[PT6315_KEY_MEM]; 00165 00166 /** Constructor for class for driving Princeton PT6315 VFD controller 00167 * 00168 * @brief Supports 4 Grids of 24 Segments upto 12 Grids of 16 Segments. Also supports a scanned keyboard of upto 32 keys and 4 LEDs. 00169 * SPI bus interface device. 00170 * @param PinName mosi, miso, sclk, cs SPI bus pins 00171 * @param Mode selects either number of Grids and Segments (default 12 Grids, 16 Segments) 00172 */ 00173 PT6315(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode=Grid12_Seg16); 00174 00175 /** Clear the screen and locate to 0 00176 */ 00177 void cls(); 00178 00179 /** Write databyte to PT6315 00180 * @param int address display memory location to write byte 00181 * @param char data byte written at given address 00182 * @return none 00183 */ 00184 void writeData(int address, char data); 00185 00186 /** Write Display datablock to PT6315 00187 * @param DisplayData_t data Array of PT6315_DISPLAY_MEM (=36) bytes for displaydata (starting at address 0) 00188 * @param length number bytes to write (valid range 0..PT6315_DISPLAY_MEM (=36), starting at address 0) 00189 * @return none 00190 */ 00191 void writeData(DisplayData_t data, int length = PT6315_DISPLAY_MEM); 00192 00193 00194 /** Read keydata block from PT6315 00195 * @param *keydata Ptr to Array of PT6315_KEY_MEM (=4) bytes for keydata 00196 * @return bool keypress True when at least one key was pressed 00197 * 00198 * Note: Due to the hardware configuration the PT6315 key matrix scanner will detect multiple keys pressed at same time, 00199 * but this may result in some spurious keys also being set in keypress data array. 00200 * It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting. 00201 */ 00202 bool getKeys(KeyData_t *keydata); 00203 00204 00205 /** Set LEDs 00206 * 00207 * @param char leds (4 least significant bits) 00208 * @return none 00209 */ 00210 void setLED (char leds = 0); 00211 00212 /** Set Brightness 00213 * 00214 * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle) 00215 * @return none 00216 */ 00217 void setBrightness(char brightness = PT6315_BRT_DEF); 00218 00219 /** Set the Display mode On/off 00220 * 00221 * @param bool display mode 00222 */ 00223 void setDisplay(bool on); 00224 00225 private: 00226 SPI _spi; 00227 DigitalOut _cs; 00228 Mode _mode; 00229 char _display; 00230 char _bright; 00231 00232 /** Init the SPI interface and the controller 00233 * @param none 00234 * @return none 00235 */ 00236 void _init(); 00237 00238 /** Helper to reverse all command or databits. The PT6315 expects LSB first, whereas SPI is MSB first 00239 * @param char data 00240 * @return bitreversed data 00241 */ 00242 char _flip(char data); 00243 00244 /** Write command and parameter to PT6315 00245 * @param int cmd Command byte 00246 * &Param int data Parameters for command 00247 * @return none 00248 */ 00249 void _writeCmd(int cmd, int data); 00250 }; 00251 00252 00253 00254 #if (DVDR3510_TEST == 1) 00255 // Derived class for DVDR3510 front display unit 00256 // Grids 2-11 all display 14-Segment digits and several Icons. 00257 // Grid 1 and 12 display Icons. 00258 00259 // 00260 #include "Font_16Seg.h" 00261 00262 //DVDR3510 Display data 00263 #define DVDR3510_NR_GRIDS 11 00264 #define DVDR3510_NR_DIGITS 8 00265 #define DVDR3510_NR_UDC 8 00266 00267 //DVDR3510 Memory size in bytes for Display 00268 #define DVDR3510_DISPLAY_MEM (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID) 00269 00270 00271 /** Constructor for class for driving Princeton PT6315 VFD controller as used in DVDR3510 00272 * 00273 * @brief Supports 11 Grids of 17 Segments and Icons (8 digits of 14 segments plus some icons). 00274 * Also supports a scanned keyboard of 11 keys and 1 LED. 00275 * 00276 * @param PinName mosi, miso, sclk, cs SPI bus pins 00277 */ 00278 class PT6315_DVDR3510 : public PT6315, public Stream { 00279 public: 00280 00281 /** Enums for Icons */ 00282 // Grid encoded in 8 MSBs, Icon pattern encoded in 24 LSBs 00283 enum Icon { 00284 RCV = (1<<24) | S16_RCV, 00285 SAT = (8<<24) | S16_SAT, 00286 DRT = (9<<24) | S16_DRT, 00287 TV = (9<<24) | S16_TV, 00288 COL4 = (10<<24) | S16_COL4, 00289 TMR = (10<<24) | S16_TMR, 00290 COL6 = (11<<24) | S16_COL6, 00291 DP6 = (11<<24) | S16_DP6, 00292 PRS = (11<<24) | S16_PRS 00293 }; 00294 00295 typedef short UDCData_t[DVDR3510_NR_UDC]; 00296 00297 00298 /** Constructor for class for driving Princeton PT6315 VFD controller as used in DVDR3510 00299 * 00300 * @brief Supports 8 Grids of 16 Segments and Icons (8 digits of 14 Segments plus some icons). 00301 * Also supports a scanned keyboard of 11 keys and 1 LED. 00302 * 00303 * @param PinName mosi, miso, sclk, cs SPI bus pins 00304 */ 00305 PT6315_DVDR3510(PinName mosi, PinName miso, PinName sclk, PinName cs); 00306 00307 #if DOXYGEN_ONLY 00308 /** Write a character to the Display 00309 * 00310 * @param c The character to write to the display 00311 */ 00312 int putc(int c); 00313 00314 /** Write a formatted string to the Display 00315 * 00316 * @param format A printf-style format string, followed by the 00317 * variables to use in formatting the string. 00318 */ 00319 int printf(const char* format, ...); 00320 #endif 00321 00322 /** Locate cursor to a screen column 00323 * 00324 * @param column The horizontal position from the left, indexed from 0 00325 */ 00326 void locate(int column); 00327 00328 /** Clear the screen and locate to 0 00329 * @param bool clrAll Clear Icons also (default = false) 00330 */ 00331 void cls(bool clrAll = false); 00332 00333 /** Set Icon 00334 * 00335 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs 00336 * @return none 00337 */ 00338 void setIcon(Icon icon); 00339 00340 /** Clr Icon 00341 * 00342 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 24 LSBs 00343 * @return none 00344 */ 00345 void clrIcon(Icon icon); 00346 00347 /** Set User Defined Characters (UDC) 00348 * 00349 * @param unsigned char udc_idx The Index of the UDC (0..7) 00350 * @param int udc_data The bitpattern for the UDC (16 bits) 00351 */ 00352 void setUDC(unsigned char udc_idx, int udc_data); 00353 00354 00355 /** Number of screen columns 00356 * 00357 * @param none 00358 * @return columns 00359 */ 00360 int columns(); 00361 00362 /** Write databyte to PT6315 00363 * @param int address display memory location to write byte 00364 * @param char data byte written at given address 00365 * @return none 00366 */ 00367 void writeData(int address, char data){ 00368 PT6315::writeData(address, data); 00369 } 00370 00371 /** Write Display datablock to PT6315 00372 * @param DisplayData_t data Array of PT6315_DISPLAY_MEM (=36) bytes for displaydata (starting at address 0) 00373 * @param length number bytes to write (valid range 0..(DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID) == 24, starting at address 0) 00374 * @return none 00375 */ 00376 void writeData(DisplayData_t data, int length = (DVDR3510_NR_GRIDS * PT6315_BYTES_PER_GRID)) { 00377 PT6315::writeData(data, length); 00378 } 00379 00380 protected: 00381 // Stream implementation functions 00382 virtual int _putc(int value); 00383 virtual int _getc(); 00384 00385 private: 00386 int _column; // Current cursor location 00387 int _columns; // Max number of columns 00388 00389 DisplayData_t _displaybuffer; // Local mirror for all chars and icons 00390 UDCData_t _UDC_16S; // User Defined Character pattterns (UDC) 00391 }; 00392 #endif 00393 00394 #endif
Generated on Wed Jul 13 2022 03:15:57 by
1.7.2
PT6315 VFD driver (192 segm max), Keyboard scan (32 max).