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.
Revision 1:aa0195b0f83c, committed 2021-06-13
- Comitter:
- wim
- Date:
- Sun Jun 13 13:14:12 2021 +0000
- Parent:
- 0:ecc29c13a997
- Commit message:
- First release.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PT6301.cpp Sun Jun 13 13:14:12 2021 +0000
@@ -0,0 +1,674 @@
+/* mbed PT6301 Library, for Princeton LC7571X VFD controller
+ * The controller is used by Futaba 'Chip In Glass' (CIG) VFD tubes.
+ *
+ * Copyright (c) 2021, v01: WH, Initial version
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "PT6301.h"
+#include "PT6301_UDC.inc"
+
+
+ /** Constructor for class for driving Princeton PT6301 VFD controller
+ *
+ * @brief Supports upto 20 Grids of 5x7 matrix segments for 2 rows of characters (row A and B).
+ * also supports 2 additional segments for 2 rows of characters (row A and B).
+ * SPI bus interface device.
+ * @param PinName mosi, sclk, cs SPI bus pins
+ * @param Mode selects number of Grids and Rows (default 20 Grids, 2 rows)
+ * @param bool inverted_rows selects mapping of Data onto Display layout (default false)
+ * @param Columns selects number of characters per row (default 20, same as Mode Grids)
+ * @param Rows selects number of rows (default 2, same as Mode Rows)
+ */
+PT6301::PT6301(PinName mosi, PinName sclk, PinName cs, PinName rst, Mode mode, bool inverted_rows, int columns, int rows) : _spi(mosi,NC,sclk), _cs(cs), _rst(rst), _mode(mode), _inverted_rows(inverted_rows), _columns(columns), _rows(rows) {
+
+ _init();
+}
+
+
+/** Init the PT6301 interface and the controller
+ *
+ * @param none
+ * @return none
+ */
+void PT6301::_init(){
+
+//init SPI
+ _cs=1;
+ _spi.format(8,3); //PT6301 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge)
+ _spi.frequency(100000);
+// _spi.frequency(250000);
+
+//init controller
+#if(0)
+ // Reset (3V3 level too low? Add pull-up to 5V)
+ _rst=1;
+ wait_ms(PT6301_RST_DLY);
+ _rst=0;
+ wait_ms(PT6301_RST_DLY);
+ _rst=1;
+ wait_ms(PT6301_RST_DLY);
+#endif
+
+ // Set number of Grids
+ _writeCmd((PT6301_GRID_REG | (_mode & PT6301_GRID_MSK))); // Command register & value
+
+ setBrightness(PT6301_BRT_DEF); // Default Brightness
+
+ // Clear the DCRAM and ADRAM (undefined at Reset) and reset (_row, _column)
+ cls(true);
+
+ // Clear the UDC RAM (undefined at Reset)
+ const char udc_none[] = {0x00,0x00,0x00,0x00,0x00};
+ for (int idx=0; idx < PT6301_NR_UDC; idx++) {
+ setUDC(idx, (char *)udc_none);
+ }
+
+ // Update the display
+ refresh();
+
+ setDisplay(true); // Display On
+}
+
+
+/** Clear the screen and locate to (0,0)
+ *
+ * @param bool clrAll Clear Icons also (default = false)
+ * @return none
+ */
+void PT6301::cls(bool clrAll) {
+
+ for (_row = 0; _row < _rows; _row++) {
+ for (_column = 0; _column < _columns; _column++) {
+ _displaybuffer[_row][_column] = ' '; // data
+
+ if (clrAll) {
+ _addbuffer[_row][_column] = 0; // icons
+ }
+ }
+ }
+
+ _row = 0;
+ _column = 0;
+}
+
+
+/** Locate cursor to a screen row, column
+ *
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return none
+ */
+void PT6301::locate(int row, int column) {
+ //sanity check
+ if (row < 0) {row = 0;}
+ if (row > (_rows - 1)) {row = _rows - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (_columns - 1)) {column = _columns - 1;}
+
+ _row = row;
+ _column = column;
+}
+
+/** Number of screen columns
+ *
+ * @param none
+ * @return columns
+ */
+int PT6301::columns(){
+ return _columns;
+}
+
+
+/** Number of screen rows
+ *
+ * @param none
+ * @return rows
+ */
+int PT6301::rows() {
+ return _rows;
+}
+
+
+/** Refresh screen and show data in local mirrors on the display
+ *
+ * @param bool copyAll Copy Icons in Adat local mirror also (default = true)
+ * @return none
+ */
+void PT6301::refresh(bool copyAll) {
+ int row_cnt, col_cnt;
+
+//Copy character data mirror to display
+ _cs=0; // Send Command for DATA_A_REG
+ wait_us(1);
+ _spi.write(_flip(PT6301_DATA_A_REG)); // Command register for DATA_A
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ row_cnt = _row_flip(0); // Reorder rows depending on VFD layout
+ for (col_cnt = 0; col_cnt < _columns; col_cnt++) {
+ _spi.write(_flip(_displaybuffer[row_cnt][col_cnt])); // DATA_A Row
+ }
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command & Params
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ _cs=0; // Send Command for DATA_B_REG
+ wait_us(1);
+ _spi.write(_flip(PT6301_DATA_B_REG)); // Command register for DATA_B
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ row_cnt = _row_flip(1); // Reorder rows depending on VFD layout
+ for (col_cnt = 0; col_cnt < _columns; col_cnt++) {
+ _spi.write(_flip(_displaybuffer[row_cnt][col_cnt])); // DATA_B Row
+ }
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command & Params
+
+//Copy icon data mirror to display
+ if (copyAll) {
+ _cs=0; // Send Command for ADAT_A_REG
+ wait_us(1);
+ _spi.write(_flip(PT6301_ADAT_A_REG)); // Command register for ADAT_A
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ row_cnt = _row_flip(0); // Reorder rows depending on VFD layout
+ for (col_cnt = 0; col_cnt < _columns; col_cnt++) {
+ _spi.write(_flip(_addbuffer[row_cnt][col_cnt])); // ADAT_A Row
+ }
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command & Params
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ _cs=0; // Send Command for ADAT_B_REG
+ wait_us(1);
+ _spi.write(_flip(PT6301_ADAT_B_REG)); // Command register for ADAT_B
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ row_cnt = _row_flip(1); // Reorder rows depending on VFD layout
+ for (col_cnt = 0; col_cnt < _columns; col_cnt++) {
+ _spi.write(_flip(_addbuffer[row_cnt][col_cnt])); // ADAT_B Row
+ }
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command & Params
+ }
+}
+
+
+/** Set Brightness
+ *
+ * @param char brightness (valid range 0..255)
+ * @return none
+ */
+void PT6301::setBrightness(char brightness){
+
+//Sanity check
+//
+
+ _writeCmd(PT6301_BRT_REG, brightness); // Command register & value
+}
+
+
+/** Set the Display mode On/off
+ *
+ * @param bool display mode
+ * @return none
+ */
+void PT6301::setDisplay(bool on) {
+ char display;
+
+ if (on) {
+ display = PT6301_DSPL_NRM; // normal mode, show Display RAM content
+ }
+ else {
+ display = PT6301_DSPL_OFF; // all segments off
+ }
+
+ _writeCmd((PT6301_DSPL_REG | display)); // Command register & value
+}
+
+
+/** Set the Display test mode On/off
+ *
+ * @param bool display test mode
+ * @return none
+ */
+void PT6301::setDisplayTest(bool on) {
+ char display;
+
+ if (on) {
+ display = PT6301_DSPL_ON; // test mode, all segments on
+ }
+ else {
+ display = PT6301_DSPL_NRM; // normal mode, show Display RAM content
+ }
+
+ _writeCmd((PT6301_DSPL_REG | display)); // Command register & value
+}
+
+
+/** Set User Defined Characters (UDC) for A and B
+ *
+ * @param unsigned char udc_idx The Index of the UDC (0..15)
+ * @param UDCData_t udc_data The bitpattern for the UDC (5 bytes)
+ * @return none
+ */
+void PT6301::setUDC(unsigned char udc_idx, UDCData_t udc_data) {
+
+//Sanity check
+ udc_idx = udc_idx & PT6301_UADR_MSK; // mask invalid bits
+
+ _cs=0; // Send Command & Params for UDC_A
+ wait_us(1);
+ _spi.write(_flip(PT6301_UDC_A_REG | udc_idx)); // Command register & address for UDC_A
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ _spi.write(_flip(udc_data[0] & PT6301_UDC_MSK)); // CD30 CD25 ...... CD0
+ _spi.write(_flip(udc_data[1] & PT6301_UDC_MSK)); // CD31 CD26 ...... CD1
+ _spi.write(_flip(udc_data[2] & PT6301_UDC_MSK)); // CD32 CD27 ...... CD2
+ _spi.write(_flip(udc_data[3] & PT6301_UDC_MSK)); // CD33 CD28 ...... CD3
+ _spi.write(_flip(udc_data[4] & PT6301_UDC_MSK)); // CD34 CD29 ...... CD4
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command & Params
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+
+ _cs=0; // Send Command & Params for UDC B
+ wait_us(1);
+ _spi.write(_flip(PT6301_UDC_B_REG | udc_idx)); // Command register & address for UDC_B
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ _spi.write(_flip(udc_data[0] & PT6301_UDC_MSK)); // CD30 CD25 ...... CD0
+ _spi.write(_flip(udc_data[1] & PT6301_UDC_MSK)); // CD31 CD26 ...... CD1
+ _spi.write(_flip(udc_data[2] & PT6301_UDC_MSK)); // CD32 CD27 ...... CD2
+ _spi.write(_flip(udc_data[3] & PT6301_UDC_MSK)); // CD33 CD28 ...... CD3
+ _spi.write(_flip(udc_data[4] & PT6301_UDC_MSK)); // CD34 CD29 ...... CD4
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command & Params
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+}
+
+/** Set Icon
+ *
+ * @param int row The row of the icon (0..(rows-1))
+ * @param int column The column of the icon (0..(cols-1))
+ * @return none
+ */
+void PT6301::setIcon(int row, int column){
+ //sanity check
+ if (row < 0) {row = 0;}
+ if (row > (_rows - 1)) {row = _rows - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (_columns - 1)) {column = _columns - 1;}
+
+ _addbuffer[row][column] = PT6301_ADAT_MSK;
+}
+
+/** Clr Icon
+ *
+ * @param int row The row of the icon (0..(rows-1))
+ * @param int column The column of the icon (0..(cols-1))
+ * @return none
+ */
+void PT6301::clrIcon(int row, int column){
+ //sanity check
+ if (row < 0) {row = 0;}
+ if (row > (_rows - 1)) {row = _rows - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (_columns - 1)) {column = _columns - 1;}
+
+ _addbuffer[row][column] = 0x00;
+}
+
+
+/** Write command to PT6301
+ *
+ * @param char cmd Command byte
+ * @return none
+ */
+void PT6301::_writeCmd(char cmd){
+
+ _cs=0; // Prepare to send Command
+ wait_us(1);
+
+ _spi.write(_flip(cmd)); // Command register & value
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+}
+
+
+/** Write command and data to PT6301
+ *
+ * @param char cmd Command byte
+ * @param char data Parameter for command
+ * @return none
+ */
+void PT6301::_writeCmd(char cmd, char data){
+
+ _cs=0; // Prepare to send Command and data
+ wait_us(1);
+
+ _spi.write(_flip(cmd)); // Command register & value
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+
+ _spi.write(_flip(data)); // data
+
+ wait_us(PT6301_CS_DLY); // CS Hold Delay
+ _cs=1; // Latch Command and data
+
+ wait_us(PT6301_CMD_DLY); // Command Delay
+}
+
+/** Write Data to local mirror
+ *
+ * @param char data The databyte
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return none
+ */
+void PT6301::setData(char data, int row, int column){
+
+ //Sanity check, allow access to all of local mirror
+ if (row < 0) {row = 0;}
+ if (row > (PT6301_MAX_NR_ROWS - 1)) {row = PT6301_MAX_NR_ROWS - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (PT6301_MAX_NR_GRIDS - 1)) {column = PT6301_MAX_NR_GRIDS - 1;}
+
+ _displaybuffer[row][column] = data;
+}
+
+/** Read Data from local mirror
+ *
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return char The databyte
+ */
+char PT6301::getData(int row, int column){
+
+ //Sanity check, allow access to all of local mirror
+ if (row < 0) {row = 0;}
+ if (row > (PT6301_MAX_NR_ROWS - 1)) {row = PT6301_MAX_NR_ROWS - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (PT6301_MAX_NR_GRIDS - 1)) {column = PT6301_MAX_NR_GRIDS - 1;}
+
+ return _displaybuffer[row][column];
+}
+
+/** Write AData to local mirror
+ *
+ * @param char data The symbol databyte
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return none
+ */
+void PT6301::setAData(char data, int row, int column){
+
+ //Sanity check, allow access to all of local mirror
+ if (row < 0) {row = 0;}
+ if (row > (PT6301_MAX_NR_ROWS - 1)) {row = PT6301_MAX_NR_ROWS - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (PT6301_MAX_NR_GRIDS - 1)) {column = PT6301_MAX_NR_GRIDS - 1;}
+
+ _addbuffer[row][column] = data & PT6301_ADAT_MSK;
+}
+
+/** Read AData from local mirror
+ *
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return char The symbol databyte
+ */
+char PT6301::getAData(int row, int column){
+
+ //Sanity check, allow access to all of local mirror
+ if (row < 0) {row = 0;}
+ if (row > (PT6301_MAX_NR_ROWS - 1)) {row = PT6301_MAX_NR_ROWS - 1;}
+
+ if (column < 0) {column = 0;}
+ if (column > (PT6301_MAX_NR_GRIDS - 1)) {column = PT6301_MAX_NR_GRIDS - 1;}
+
+ return _addbuffer[row][column];
+}
+
+
+
+
+/** Helper to reverse all command or databits. The PT6301 expects LSB first, whereas SPI is MSB first
+ *
+ * @param char data
+ * @return bitreversed data
+ */
+char PT6301::_flip(char data) {
+ char value=0;
+
+ if (data & 0x01) {value |= 0x80;} ;
+ if (data & 0x02) {value |= 0x40;} ;
+ if (data & 0x04) {value |= 0x20;} ;
+ if (data & 0x08) {value |= 0x10;} ;
+ if (data & 0x10) {value |= 0x08;} ;
+ if (data & 0x20) {value |= 0x04;} ;
+ if (data & 0x40) {value |= 0x02;} ;
+ if (data & 0x80) {value |= 0x01;} ;
+ return value;
+}
+
+
+/** Helper to reverse row idx depending on VFD layout
+ *
+ * @param int row_idx
+ * @return adjusted row_idx
+ */
+int PT6301::_row_flip(int row_idx) {
+ if (_inverted_rows) {
+ return (1 - row_idx); // Reorder row mapping to match VFD layout
+ // Top line is DATA_B_REG, ADAT_B_REG
+ // Bottom line is DATA_A_REG, ADAT_A_REG
+ }
+ else {
+ return row_idx; // Maintain row mapping to match VFD layout
+ // Top line is DATA_A_REG, ADAT_A_REG
+ // Bottom line is DATA_B_REG, ADAT_B_REG
+ }
+}
+
+
+/** Write a single character (Stream implementation)
+ *
+ * @param value char to print
+ * @return value;
+ */
+int PT6301::_putc(int value) {
+
+ if (value == '\r') {
+ //No character to write
+
+ //Update Cursor
+ _column = 0;
+ }
+ else if (value == '\n') {
+ //No character to write
+
+ //Update Cursor
+ _row++;
+ if (_row > (_rows - 1)) {
+ _row = 0;
+ }
+ }
+ else if ((value >= 0) && (value < 256)) {
+ //Valid character to write
+
+ //Write displaybuffer entry
+ _displaybuffer[_row][_column] = value;
+
+ //Update Cursor
+ _column++;
+ if (_column > (_columns - 1)) {
+ _column = 0;
+ _row++;
+ }
+ if (_row > (_rows - 1)) {
+ _row = 0;
+ }
+ } // if validChar
+
+ return value;
+}
+
+/** Get a single character (Stream implementation)
+ *
+ * @param none
+ * @return -1
+ */
+int PT6301::_getc() {
+ return -1;
+}
+
+
+
+#if (SMTG7400_TEST == 1)
+
+/** Constructor for class for Princeton PT6301 VFD controller as used in SMTG7400
+ *
+ * @brief Supports 16 Grids of 5x7 Segments with 4 additional Segments in use.
+ *
+ * @param PinName mosi, miso, sclk, cs SPI bus pins
+ * @param PinName rst Reset pin
+ */
+PT6301_SMTG7400::PT6301_SMTG7400(PinName mosi, PinName sclk, PinName cs, PinName rst) : PT6301(mosi, sclk, cs, rst, Grid16, true, SMTG7400_NR_COLS, SMTG7400_NR_ROWS) {
+
+}
+
+/** Set Icon
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+void PT6301_SMTG7400::setIcon(int icon) {
+ PT6301::setIcon((icon >> SMTG7400_ICON_ROW_SHFT), (icon & SMTG7400_ICON_COL_MSK));
+}
+
+/** Clr Icon
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+void PT6301_SMTG7400::clrIcon(int icon) {
+ PT6301::clrIcon((icon >> SMTG7400_ICON_ROW_SHFT), (icon & SMTG7400_ICON_COL_MSK));
+}
+
+#endif
+
+
+#if (SMTC7140_TEST == 1)
+
+/** Constructor for class for Princeton PT6301 VFD controller as used in SMTC7140
+ *
+ * @brief Supports 12 Grids of 5x7 Segments without additional Icon Segments, for 2 Rows.
+ * Grid13 is used for icons displayed by a UDC symbol.
+ *
+ * @param PinName mosi, miso, sclk, cs SPI bus pins
+ * @param PinName rst Reset pin
+ */
+PT6301_SMTC7140::PT6301_SMTC7140(PinName mosi, PinName sclk, PinName cs, PinName rst) : PT6301(mosi, sclk, cs, rst, Grid13, true, SMTC7140_NR_COLS, SMTC7140_NR_ROWS) {
+
+ //Enable VGen for VFD Power Supply
+ //Note this is wrong because we should send the init commands to the PT6301 before the 5V powersupply is enabled !
+// setVGen(true);
+
+}
+
+/** Set VFD VGen
+ *
+ * @param bool on
+ * @return none
+ */
+void PT6301_SMTC7140::setVGen (bool on) {
+
+}
+
+
+/** Set IconGrid13
+ * Icons are shown on Grid13 using the UDC at index=0. The UDC char=0 is stored in _displaybuffer[0][12] at reset.
+ * This method will set the correct segment in the UDC for each icon.
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+void PT6301_SMTC7140::setIconGrid13(int icon) {
+
+#if(0)
+ //Test version to check all bits
+ // clear icon
+ for (int udc_col=0; udc_col<5; udc_col++) {
+ _icon_data[udc_col] = 0x00;
+ };
+
+ _icon_data[icon >> 8] = (icon & 0x7F);
+ setUDC(0, (char *) _icon_data); // Store mirror for UDC_idx=0
+
+#else
+ //Normal version
+ for (int udc_col=0; udc_col<5; udc_col++) {
+ _icon_data[udc_col] = _icon_data[udc_col] | SMTC7140_ICONS[icon][udc_col]; // OR icon bitpattern with UDC mirror for UDC_idx=0
+ }
+
+ setUDC(0, (char *) _icon_data); // Store mirror for UDC_idx=0
+#endif
+
+}
+
+/** Clr IconGrid13
+ * Icons are shown on Grid13 using the UDC at index=0. The UDC char=0 is stored in _displaybuffer[0][12] at reset.
+ * This method will clr the correct segment in the UDC for each icon.
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+void PT6301_SMTC7140::clrIconGrid13(int icon) {
+
+ for (int udc_col=0; udc_col<5; udc_col++) {
+ _icon_data[udc_col] = _icon_data[udc_col] & ~(SMTC7140_ICONS[icon][udc_col]); // AND inverted icon bitpattern with UDC mirror for UDC_idx=0
+ }
+
+ setUDC(0, (char *) _icon_data); // Store mirror for UDC_idx=0
+}
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PT6301.h Sun Jun 13 13:14:12 2021 +0000
@@ -0,0 +1,663 @@
+/* mbed PT6301 Library, for Princeton PT6301 VFD controller
+ * The controller is used by Futaba 'Chip In Glass' (CIG) VFD tubes.
+ *
+ * Copyright (c) 2021, v01: WH, Initial version
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef PT6301_H
+#define PT6301_H
+
+// Select one of the testboards for Princeton PT6301 VFD controller
+#include "PT6301_Config.h"
+#include "PT6301_UDC.h"
+
+/** An interface for driving Princeton PT6301 VFD controller
+ *
+ * @code
+ *
+ * #if (PT6301_TEST == 1)
+ * // Direct driving of PT6301 Test
+ *
+ * #include "mbed.h"
+ * #include "PT6301.h"
+ *
+ * DigitalOut myled(LED1);
+ * Serial pc(USBTX, USBRX);
+ *
+ * // PT6301 declaration, Default setting 2x20 Grids @ 5x7 Segments, 2 Icon segments for each Grid
+ * PT6301 PT6301(p5, p7, p8, p9); // DI, CLK, CS, RST
+ *
+ * int main() {
+ * pc.printf("Hello World: PT6301 test\n\r");
+ *
+ * PT6301.cls();
+ *
+ * // PT6301.writeData((char)'H',0,0);
+ * // PT6301.writeData((char)'e',0,1);
+ * // PT6301.writeData((char)'l',0,2);
+ * // PT6301.writeData((char)'l',0,3);
+ * // PT6301.writeData((char)'o',0,4);
+ * PT6301.printf("Hello World");
+ * PT6301.refresh();
+ * wait(2);
+ *
+ * PT6301.setBrightness(PT6301_BRT0);
+ * wait(2);
+ * PT6301.setBrightness(PT6301_BRT3);
+ *
+ * while(1) {
+ * myled = !myled;
+ * wait(1);
+ * }
+ * }
+ * #endif
+ *
+ * @endcode
+ */
+
+
+//PT6301 Display and Annunciator data
+#define PT6301_MAX_NR_GRIDS 20
+#define PT6301_MAX_NR_ROWS 2
+#define PT6301_BYTES_PER_GRID 1
+
+
+//The PT6301 has internal memory for all characters and icons. The content is automatically displayed on the tube.
+//The memory consists of two banks (row A and row B) for character memory and two banks (row A and row B) for icon memory.
+//Each of those banks is accessed by separate commands.
+//However, these command do not support addressing individual locations in the memory. Memory updates always start at
+//address 0 in the selected row A or B. Consequently, the whole displaymemory needs to be rewritten when any
+//location (except for 0) is to be updated.
+//The library therefor uses a local mirror memory to store the display content, update one or more characters in
+//the mirrormemory as needed, and rewrite the whole displaymemory from the mirrorcontent.
+//The write-back is performed by calling the 'refresh' method.
+//Additional advantage of the mirror-memory is that we can also implement wrap-around and scrolling from row A to B for multi-line displays.
+
+//Memory size in bytes for Display and Annunciators in total
+//#define PT6301_DSP_MEM (PT6301_MAX_NR_ROWS * PT6301_MAX_NR_GRIDS * PT6301_BYTES_PER_GRID)
+//#define PT6301_ADD_MEM (PT6301_MAX_NR_ROWS * PT6301_MAX_NR_GRIDS)
+//Memory size in bytes for Display and Annunciators per Row
+#define PT6301_DSP_MEM (PT6301_MAX_NR_GRIDS * PT6301_BYTES_PER_GRID)
+#define PT6301_ADD_MEM (PT6301_MAX_NR_GRIDS * PT6301_BYTES_PER_GRID)
+
+//User Defined Characters
+//Note that the PT6301 actually has two separate UDC banks for row A and B.
+//In this lib both UDC memories are always identical.
+#define PT6301_UDC_MEM 16
+
+//SPI Serial control data consists of an 8-bit command and one or more data bytes.
+//Command and data are sent LSB first and latched on rising edge of CLK. Idle CLK is high.
+//Data address is auto incremented.
+//The commands and data are transmitted during CE low and latched on rising CE edge.
+//Multiple PT6301 devices on the same bus can only be distinguised by the CE control.
+//Normal SPI methods send data MSB first. This lib uses a helper method to flip the bits before transmission.
+
+//Command delay in us
+#define PT6301_CMD_DLY 8
+#define PT6301_CS_DLY 16
+//Reset delay in ms
+#define PT6301_RST_DLY 10
+
+//
+//Set Char data command (DCRAM_A)
+// 0 0 0 1 x x x x
+#define PT6301_DATA_A_REG 0x10
+//Set Char data command (DCRAM_B)
+// 1 0 0 1 x x x x
+#define PT6301_DATA_B_REG 0x90
+
+
+//Note: The PT6301 does not support address selection. The commandformat allows
+//only 4bits for the address anyhow and this would be insufficient for a display
+//controller that can support upto 20 Grids.
+//Some other controllers with very similar commandsets and a max of 16 Grids do use the available 4 addressbits.
+//
+//No DCRAM Address Support, Always starts at address 0x00
+#define PT6301_DADR_MSK 0x0F
+
+//Char data (2nd byte, 3rd byte ...)
+//DA7..DA0 Character Data
+#define PT6301_DATA_MSK 0xFF
+
+//Note: The PT6301 supports separate UDCs banks for both rows A and B.
+//However, this lib always keeps both UDC banks identical.
+
+//Set UDC data command (CGRAM_A)
+// 0 0 1 0 UA3 UA2 UA1 UA0
+#define PT6301_UDC_A_REG 0x20
+//Set UDC data command (CGRAM_B)
+// 1 0 1 0 UA3 UA2 UA1 UA0
+#define PT6301_UDC_B_REG 0xA0
+
+//UA3..UA0 CGRAM Address (UDC RAM address)
+#define PT6301_UADR_MSK 0x0F
+#define PT6301_NR_UDC 16
+
+//User Defined Characters (UDCs) consist of 5x7 dots and are defined by a 5 byte bitpattern.
+//UDC data (2nd byte .. 6th byte)
+// D7 D6 D5 D4.. D1 D0
+// 0 * CD30 CD25 ...... CD0
+// 1 * CD31 CD26 ...... CD1
+// 2 * CD32 CD27 ...... CD2
+// 3 * CD33 CD28 ...... CD3
+// 4 * CD34 CD29 ...... CD4
+//
+#define PT6301_UDC_MSK 0x7F
+
+//CD34..CD0 UDC Data
+//UDC is a 5x7 Matrix pattern that will show on the VFD as
+// 0 C0 C1 C2 C3 C4
+// 1 C5 C6 ....... C9
+// . .............
+// . .............
+// . .............
+// 6 C30 C31 ... C34
+//
+
+//UDCs are defined by a 5x7 matrix and stored as 5 bytes
+typedef char UDCData_t[5];
+
+
+//Set Additional data command (ADRAM_A), Used for annunciators etc
+// 0 0 1 1 x x x x
+#define PT6301_ADAT_A_REG 0x30
+//Set Additional data command (ADRAM_B), Used for annunciators etc
+// 1 0 1 1 x x x x
+#define PT6301_ADAT_B_REG 0xB0
+
+//Note: The PT6301 does not support address selection for icons. The commandformat allows
+//only 4bits for the address anyhow and this would be insufficient for a display with upto 20 Grids
+//
+//No ADRAM Address (Additional data), always starts at 0x00
+#define PT6301_AADR_MSK 0x0F
+
+//* * * * * * * AD0 Additional Data (2nd byte, 3rd byte, ..)
+#define PT6301_ADAT_MSK 0x01
+
+//
+//Set Brightness command
+// 0 1 0 1 * * DC1 DC0
+#define PT6301_BRT_REG 0x50
+#define PT6301_BRT_MSK 0x03
+
+//Set Brightness command (2nd Byte)
+// DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2
+
+
+//Brightness Level (0..7), mapped onto Brightness command 2nd databyte
+//Note Brightness relationship between the number of active Grids (period) and the BRT value (duty cycle)
+#define PT6301_BRT_0 0x00 //Duty 0/1024 (Default)
+#define PT6301_BRT_1 0x20
+#define PT6301_BRT_2 0x40
+#define PT6301_BRT_3 0x80
+#define PT6301_BRT_4 0xA0
+#define PT6301_BRT_5 0xB0
+#define PT6301_BRT_6 0xD0
+#define PT6301_BRT_7 0xFF //Duty 960/1024
+
+#define PT6301_BRT_DEF (PT6301_BRT_2)
+
+
+//
+//Grid control command
+// 0 1 1 0 GN3 GN2 GN1 GN0
+#define PT6301_GRID_REG 0x60
+#define PT6301_GRID_MSK 0x0F
+
+//Grids. Each Grid controls 2 characters (A and B) and 2 icons (A and B)
+//
+// GN3 GN2 GN1 GN0
+// 0 0 0 0 G1 to G20 // Default
+// 0 0 0 1 G1 to G5
+// 0 0 1 0 G1 to G6
+// 0 0 1 1 G1 to G7
+//...
+// 1 0 0 0 G1 to G12
+// 1 0 0 1 G1 to G13
+// 1 0 1 0 G1 to G14
+//...
+// 1 1 1 1 G1 to G19
+//
+#define PT6301_GR1_GR5 0x01
+#define PT6301_GR1_GR6 0x02
+#define PT6301_GR1_GR7 0x03
+#define PT6301_GR1_GR8 0x04
+#define PT6301_GR1_GR9 0x05
+#define PT6301_GR1_GR10 0x06
+#define PT6301_GR1_GR11 0x07
+#define PT6301_GR1_GR12 0x08
+#define PT6301_GR1_GR13 0x09
+#define PT6301_GR1_GR14 0x0A
+#define PT6301_GR1_GR15 0x0B
+#define PT6301_GR1_GR16 0x0C
+#define PT6301_GR1_GR17 0x0D
+#define PT6301_GR1_GR18 0x0E
+#define PT6301_GR1_GR19 0x0F
+#define PT6301_GR1_GR20 0x00
+
+//
+//Display On/Off command
+// 0 1 1 1 * * H L
+#define PT6301_DSPL_REG 0x70
+#define PT6301_DSPL_MSK 0x03
+
+//Display Mode
+// H L Display operating state
+// 0 0 Normal display (default)
+// 0 1 Off
+// 1 0 All Segments and Additional Segments On
+// 1 1 All Segments and Additional Segments On
+#define PT6301_DSPL_NRM 0x00
+#define PT6301_DSPL_OFF 0x01
+#define PT6301_DSPL_ON 0x02
+
+
+/** A class for driving Princeton PT6301 VFD controller
+ *
+ * @brief Supports upto 20 Grids of 5x7 matrix segments for 2 rows of characters (A and B).
+ * Also supports 1 additional segment for 2 rows (A and B).
+ * SPI bus interface device (LSB first).
+ */
+class PT6301 : public Stream {
+ public:
+
+ /** Enums for display mode */
+ enum Mode {
+ Grid5 = PT6301_GR1_GR5,
+ Grid6 = PT6301_GR1_GR6,
+ Grid7 = PT6301_GR1_GR7,
+ Grid8 = PT6301_GR1_GR8,
+ Grid9 = PT6301_GR1_GR9,
+ Grid10 = PT6301_GR1_GR10,
+ Grid11 = PT6301_GR1_GR11,
+ Grid12 = PT6301_GR1_GR12,
+ Grid13 = PT6301_GR1_GR13,
+ Grid14 = PT6301_GR1_GR14,
+ Grid15 = PT6301_GR1_GR15,
+ Grid16 = PT6301_GR1_GR16,
+ Grid17 = PT6301_GR1_GR17,
+ Grid18 = PT6301_GR1_GR18,
+ Grid19 = PT6301_GR1_GR19,
+ Grid20 = PT6301_GR1_GR20
+ };
+
+ /** Datatypes for display data */
+typedef char DisplayData_t[PT6301_MAX_NR_ROWS][PT6301_DSP_MEM];
+typedef char DisplayAdd_t[PT6301_MAX_NR_ROWS][PT6301_ADD_MEM];
+
+ /** Constructor for class for driving Princeton PT6301 VFD controller
+ *
+ * @brief Supports upto 20 Grids of 5x7 matrix segments for 2 rows of characters (row A and B).
+ * Also supports 1 additional segment for 2 rows of characters (row A and B).
+ * SPI bus interface device.
+ * @param PinName mosi, sclk, cs SPI bus pins
+ * @param PinName rst reset pin
+ * @param Mode selects number of Grids and Segments (default 20 Grids, 5x7 matrix segments + 1 additional segment for 2 rows)
+ * @param bool inverted_rows selects mapping of Data onto Display layout (default false)
+ * @param Columns selects number of characters per row (default 20, same as Grids)
+ * @param Rows selects number of rows (default 2)
+ */
+ PT6301(PinName mosi, PinName sclk, PinName cs, PinName rst, Mode mode = Grid20, bool inverted_rows = false, int columns = PT6301_MAX_NR_GRIDS, int rows = PT6301_MAX_NR_ROWS);
+
+ /** Set Brightness
+ *
+ * @param char brightness (3 significant bits, valid range 0..7 (dutycycle linked to number of grids)
+ * @return none
+ */
+ void setBrightness(char brightness = PT6301_BRT_DEF);
+
+ /** Set the Display mode On/off
+ *
+ * @param bool display mode
+ * @return none
+ */
+ void setDisplay(bool on);
+
+ /** Set the Display test mode On/off
+ *
+ * @param bool display test mode
+ * @return none
+ */
+ void setDisplayTest(bool on);
+
+ /** Set User Defined Characters (UDC) for A and B row
+ *
+ * @param unsigned char udc_idx The Index of the UDC (0..15)
+ * @param UDCData_t udc_data The bitpattern for the UDC (5 bytes)
+ * @return none
+ */
+ void setUDC(unsigned char udc_idx, UDCData_t udc_data);
+
+ /** Set Icon
+ *
+ * @param int row The row of the icon (0..(rows-1))
+ * @param int column The column of the icon (0..(cols-1))
+ * @return none
+ */
+ void setIcon(int row, int column);
+
+ /** Clr Icon
+ *
+ * @param int row The row of the icon (0..(rows-1))
+ * @param int column The column of the icon (0..(cols-1))
+ * @return none
+ */
+ void clrIcon(int row, int column);
+
+ /** Locate cursor to a screen row, column
+ *
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return none
+ */
+ void locate(int row, int column);
+
+ /** Clear the screen and locate to (0,0)
+ *
+ * @param bool clrAll Clear Icons also (default = true)
+ */
+ void cls(bool clrAll = true);
+
+ /** Refresh screen and show data in local mirrors on the display
+ *
+ * @param bool copyAll Copy Icons in Adat local mirror also (default = true)
+ * @return none
+ */
+ void refresh(bool copyAll = true);
+
+
+ /** Number of screen columns
+ *
+ * @param none
+ * @return columns
+ */
+ int columns();
+
+ /** Number of screen rows
+ *
+ * @param none
+ * @return rows
+ */
+ int rows();
+
+ /** Write Data to local mirror
+ *
+ * @param char data The databyte
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return none
+ */
+ void setData(char data, int row, int column);
+
+ /** Read Data from local mirror
+ *
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return char The databyte
+ */
+ char getData(int row, int column);
+
+ /** Write AData to local mirror
+ *
+ * @param char data The symbol databyte
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return none
+ */
+ void setAData(char data, int row, int column);
+
+ /** Read AData from local mirror
+ *
+ * @param row The vertical position from the top, indexed from 0
+ * @param column The horizontal position from the left, indexed from 0
+ * @return char The symbol databyte
+ */
+ char getAData(int row, int column);
+
+
+ protected:
+
+ /** Write Command byte to PT6301
+ *
+ * @param char cmd Command byte
+ * @return none
+ */
+ void _writeCmd(char cmd);
+
+ /** Write Command and Data byte to PT6301
+ *
+ * @param char cmd Command byte
+ * @param char data Parameter for Command byte
+ * @return none
+ */
+ void _writeCmd(char cmd, char data);
+
+
+ /** Helper to reverse all command or databits. The PT6301 expects LSB first, whereas SPI is MSB first
+ *
+ * @param char data
+ * @return bitreversed data
+ */
+ char _flip(char data);
+
+/** Helper to reverse row idx depending on VFD layout
+ *
+ * @param int row_idx
+ * @return adjusted row_idx
+ */
+int _row_flip(int row_idx);
+
+
+#if DOXYGEN_ONLY
+ /** Write a character to the Display
+ *
+ * @param c The character to write to the display RAM
+ * @return char written
+ */
+ int putc(int c);
+
+ /** Write a formatted string to the Display
+ *
+ * @param format A printf-style format string, followed by the
+ * variables to use in formatting the string.
+ */
+ int printf(const char* format, ...);
+#endif
+
+ // Stream implementation functions
+ virtual int _putc(int value);
+ virtual int _getc();
+
+
+ private:
+ SPI _spi;
+ DigitalOut _cs;
+ DigitalOut _rst;
+ Mode _mode; // Number of Grids
+ bool _inverted_rows; // Mapping of Rows to VFD layout
+
+ int _column; // Current cursor location
+ int _columns; // Max number of columns
+ int _row; // Current cursor location
+ int _rows; // Max number of rows
+
+ DisplayData_t _displaybuffer; // Local mirror for all chars
+ DisplayAdd_t _addbuffer; // Local mirror for all icons
+
+ /** Init the SPI interface and the controller
+ *
+ * @param none
+ * @return none
+ */
+ void _init();
+
+};
+
+
+#if (SMTG7400_TEST == 1)
+// Derived class for SMTG7400 display unit
+// Grids 1-16, 1 row of 16 matrix characters (5x7 segments), 4 Additional segments in use.
+//
+
+//SMTG7400 Display data
+#define SMTG7400_NR_GRIDS 16
+#define SMTG7400_NR_COLS 16
+#define SMTG7400_NR_ROWS 1
+
+//#define SMTG7400_NR_UDC 16
+
+//SMTG7400 Icon data,
+//#defines encode the row and position in the row for each icon
+#define SMTG7400_ICON_ROW_SHFT 8
+#define SMTG7400_ICON_ROW_0 (0x00 << SMTG7400_ICON_ROW_SHFT)
+#define SMTG7400_ICON_ROW_1 (0x01 << SMTG7400_ICON_ROW_SHFT)
+#define SMTG7400_ICON_COL_MSK (0x00FF)
+//
+#define SMTG7400_ICON_OFFLINE (SMTG7400_ICON_ROW_0 | 1)
+#define SMTG7400_ICON_WIFI (SMTG7400_ICON_ROW_0 | 2)
+#define SMTG7400_ICON_PHONE (SMTG7400_ICON_ROW_0 | 3)
+#define SMTG7400_ICON_REC (SMTG7400_ICON_ROW_0 | 8)
+
+/** Constructor for class for driving Princeton PT6301 VFD controller as used in SMTG7400
+ *
+ * @brief Supports 16 Grids of 5x7 Segments with 4 additional Segments in use.
+ *
+ * @param PinName mosi, sclk, cs SPI bus pins
+ * @param PinName rst reset pin
+ */
+class PT6301_SMTG7400 : public PT6301{
+ public:
+
+/** Constructor for class for driving Princeton PT6301 VFD controller as used in SMTG7400
+ *
+ * @brief Supports 16 Grids of 5x7 Segments with 4 additional Segments in use.
+ *
+ * @param PinName mosi, sclk, cs SPI bus pins
+ * @param PinName rst reset pin
+ */
+ PT6301_SMTG7400(PinName mosi, PinName sclk, PinName cs, PinName rst);
+
+ /** Set Icon
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+ void setIcon(int icon);
+
+ /** Clr Icon
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+ void clrIcon(int icon);
+
+protected:
+
+private:
+
+};
+#endif
+
+#if (SMTC7140_TEST == 1)
+// Derived class for SMTC7140 display unit
+// Grids 1-12, with 2 rows of 12 matrix characters (35 segments), no Additional segments.
+// Grid 13 is used for icons displayed as a UDC symbol.
+//
+
+//SMTC7140 Display data
+#define SMTC7140_NR_GRIDS 13
+#define SMTC7140_NR_COLS 12
+#define SMTC7140_NR_ROWS 2
+
+//#define SMTC7140_NR_UDC 16
+#define SMTC7140_ICON_DOLBY (1)
+#define SMTC7140_ICON_PLUS (2)
+#define SMTC7140_ICON_HD (3)
+#define SMTC7140_ICON_CLOCK (4)
+#define SMTC7140_ICON_REC (5)
+#define SMTC7140_ICON_MAIL (6)
+
+const char SMTC7140_ICONS[][5] = {{0x7F, 0x7F, 0x7F, 0x7F, 0x7F}, // All On
+ {0x00, 0x00, 0x08, 0x00, 0x00}, // Dolby
+ {0x00, 0x04, 0x00, 0x00, 0x00}, // +
+ {0x00, 0x00, 0x00, 0x08, 0x00}, // HD
+ {0x00, 0x00, 0x00, 0x00, 0x10}, // Clock
+ {0x20, 0x00, 0x00, 0x00, 0x00}, // Rec
+ {0x00, 0x00, 0x00, 0x00, 0x40}, // Mail
+ {0x00, 0x00, 0x00, 0x00, 0x00}, //
+ };
+
+/** Constructor for class for driving Princeton PT6301 VFD controller as used in SMTC7140
+ *
+ * @brief Supports 12 Grids of 5x7 Segments without additional Icon Segments, for 2 Rows.
+ * Grid13 is used for icons displayed by a UDC symbol.
+ *
+ * @param PinName mosi, sclk, cs SPI bus pins
+ * @param PinName rst reset pin
+ */
+class PT6301_SMTC7140 : public PT6301 {
+ public:
+
+/** Constructor for class for driving Princeton PT6301 VFD controller as used in SMTC7140
+ *
+ * @brief Supports 12 Grids with 2 rows of 12 matrix characters (35 Segments), without additional Segments.
+ * Grid 13 is used for icons displayed by a UDC symbol.
+ *
+ * @param PinName mosi, sclk, cs SPI bus pins
+ * @param PinName rst reset pin
+ */
+ PT6301_SMTC7140(PinName mosi, PinName sclk, PinName cs, PinName rst);
+
+
+/** Set VFD VGen
+ *
+ * @param bool on
+ * @return none
+ */
+ void setVGen (bool on = true);
+
+/** Set IconGrid13
+ * Icons are shown on Grid13 using the UDC at index=0. The UDC char=0 is stored in _displaybuffer[0][12] at reset.
+ * This method will set the correct segment in the UDC for each icon.
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+ void setIconGrid13(int icon);
+
+/** Clr IconGrid13
+ * Icons are shown on Grid13 using the UDC at index=0. The UDC char=0 is stored in _displaybuffer[0][12] at reset.
+ * This method will clr the correct segment in the UDC for each icon.
+ *
+ * @param int icon The icon ID
+ * @return none
+ */
+ void clrIconGrid13(int icon);
+
+protected:
+
+private:
+ UDCData_t _icon_data; // Icon data is stored as UDC_idx=0 and displayed on position (0, 12)
+
+};
+#endif
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PT6301_Config.h Sun Jun 13 13:14:12 2021 +0000 @@ -0,0 +1,36 @@ +/* mbed PT6301 Library, for Princeton PT6301 VFD controller + * The controller is used by Futaba 'Chip In Glass' (CIG) VFD tubes. + * + * Copyright (c) 2021, v01: WH, Initial version + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef PT6301_CONFIG_H +#define PT6301_CONFIG_H + +// Select one of the testboards for Princeton PT6301 VFD controller +#define PT6301_TEST 0 +#define SMTC7140_TEST 1 +#define SMTG7400_TEST 0 + +// Select if you want to include some UDC patterns +#define PT6301_UDC 1 + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PT6301_UDC.h Sun Jun 13 13:14:12 2021 +0000 @@ -0,0 +1,62 @@ +/* mbed PT6301 UDC Library, for Princeton PT6301 VFD controller + * The controller is used by Futaba 'Chip In Glass' (CIG) VFD tubes. + * + * Copyright (c) 2021, v01: WH, Initial version + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MBED_PT6301_UDC_H +#define MBED_PT6301_UDC_H + +#include "PT6301_Config.h" + +#if(PT6301_UDC == 1) +// User Defined Characters (UDCs) consist of 5x7 dots and are defined by a 5 byte bitpattern. +// The C0..C34 form the character pattern. +// D7 D6 D5 D4 D3 D2 D1 D0 +// 0 x C30 C25 C20 ...... C0 +// 1 x C31 C24 ........... C1 +// . ............. +// 4 x C34 C29 ........... C4 +// +// +// The UDC matrix will show on the VFD as +// 0 C0 C1 C2 C3 C4 +// 1 C5 C6 ..... C9 +// . ............. +// . ............. +// . ............. +// 6 C30 C31 ... C34 +// + + +// Some sample User Defined Chars 5x7 dots */ +//extern const char udc_Bat_Hi[]; // Battery Full +//extern const char udc_Bat_Ha[]; // Battery Half +//extern const char udc_Bat_Lo[]; // Battery Low +//extern const char udc_checker[]; + +//extern const char udc_PO[]; //Padlock Open +//extern const char udc_PC[]; //Padlock Closed + +extern const char udc_LAR[]; // Left Arrow +extern const char udc_RAR[]; // Right Arrow +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PT6301_UDC.inc Sun Jun 13 13:14:12 2021 +0000
@@ -0,0 +1,63 @@
+/* mbed PT6301 UDC Library, for Princeton PT6301 VFD controller
+ * The controller is used by Futaba 'Chip In Glass' (CIG) VFD tubes.
+ *
+ * Copyright (c) 2021, v01: WH, Initial version
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "PT6301_Config.h"
+
+#if(PT6301_UDC == 1)
+
+// User Defined Characters (UDCs) are defined by a 5 byte bitpattern.
+// The C0..C34 form the character pattern.
+// D7 D6 D5 D4 D3 D2 D1 D0
+// 0 x C30 C25 C20 ...... C0
+// 1 x C31 C24 ........... C1
+// . .............
+// 4 x C34 C29 ........... C4
+//
+//
+// The UDC matrix will show on the VFD as
+// 0 C0 C1 C2 C3 C4
+// 1 C5 C6 ..... C9
+// . .............
+// . .............
+// . .............
+// 6 C30 C31 ... C34
+//
+//
+// Some sample User Defined Chars 5x7 dots
+// Note that these are mirrored vertically (ie upside down) due to LSB first bitswapping of data by this lib.
+const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F}; // Battery Full
+const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F}; // Battery Half
+const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11}; // Battery Low
+const char udc_checker[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA};
+
+//const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B}; //Padlock Open
+//const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B}; //Padlock Closed
+
+const char udc_LAR[] = {0x07, 0x03, 0x05, 0x78, 0x00}; // Left Arrow
+const char udc_RAR[] = {0x00, 0x78, 0x05, 0x03, 0x07}; // Right Arrow
+
+//const char udc_LF[] = {0x08, 0x1C, 0x3E, 0x00, 0x3E}; // Left
+//const char udc_RT[] = {0x3E, 0x00, 0x3E, 0x1C, 0x08}; // Right
+//const char udc_UP[] = {0x28, 0x2C, 0x2E, 0x2C, 0x28}; // Up
+//const char udc_DW[] = {0x0A, 0x1A, 0x2A, 0x1A, 0x0A}; // Down
+#endif
--- a/PT6302.cpp Sun Dec 03 18:02:15 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,406 +0,0 @@
-/* mbed PT6302 Library, for Princeton LC7571X VFD controller
- * Note the PT6302 is identical to the OKI ML9208
- *
- * Copyright (c) 2017, v01: WH, Initial version
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "mbed.h"
-#include "PT6302.h"
-#include "PT6302_UDC.inc"
-
-
- /** Constructor for class for driving Princeton PT6302 VFD controller
- *
- * @brief Supports upto 16 Grids of 35 matrix segments.
- * Also supports 2 additional segments and 2 port pins.
- * SPI bus interface device.
- * @param PinName mosi, sclk, cs SPI bus pins
- * @param Mode selects number of Grids and Segments (default 16 Grids, 2 additional segments)
- */
-PT6302::PT6302(PinName mosi, PinName sclk, PinName cs, Mode mode) : _spi(mosi,NC,sclk), _cs(cs), _mode(mode) {
-
- _init();
-}
-
-/** Init the PT6302 interface and the controller
- *
- * @param none
- * @return none
- */
-void PT6302::_init(){
-
-//init SPI
- _cs=1;
- _spi.format(8,3); //PT6302 uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge)
- _spi.frequency(100000);
-// _spi.frequency(250000);
-
-//init controller
- //setPort(0x0); // Port Off (default at Reset)
-
- // Set number of Grids
- _writeCmd((PT6302_GRID_REG | _mode)); // Command register & value
-
- setBrightness(PT6302_BRT_DEF); // Default Brightness
-
- // Clear the DCRAM and ADRAM (undefined at Reset)
- cls();
-
- // Clear the UDC RAM (undefined at Reset)
- const char udc_none[] = {0x00,0x00,0x00,0x00,0x00};
- for (int idx=0; idx < PT6302_NR_UDC; idx++) {
- setUDC(idx, (char *)udc_none);
- }
-
- setDisplay(true); // Display On
-}
-
-
-/** Clear the screen
- *
- * @param none
- * @return none
- */
-void PT6302::cls() {
-
- for (int cnt=0; cnt<PT6302_DSP_MEM; cnt++) {
- writeData(char (' '), cnt); // data
-// writeData(0x00, cnt); // data
- }
-
- for (int cnt=0; cnt<PT6302_ADD_MEM; cnt++) {
- writeAData(0x00, cnt); // adata
- }
-}
-
-
-/** Set Brightness
- *
- * @param char brightness (3 significant bits, valid range 0..7)
- * @return none
- */
-void PT6302::setBrightness(char brightness){
-
-//Sanity check
- brightness = brightness & PT6302_BRT_MSK; // mask invalid bits
-
- _writeCmd((PT6302_BRT_REG | brightness)); // Command register & value
-}
-
-/** Set the Display mode On/off
- *
- * @param bool display mode
- * @return none
- */
-void PT6302::setDisplay(bool on) {
- char display;
-
- if (on) {
- display = PT6302_DSPL_NRM; // normal mode, show Display RAM content
- }
- else {
- display = PT6302_DSPL_OFF; // all segments off
- }
-
- _writeCmd((PT6302_DSPL_REG | display)); // Command register & value
-}
-
-/** Set Port
- *
- * @param char port (2 least significant bits)
- * @return none
- */
-void PT6302::setPort (char port){
-
-//Sanity check
- _port = port & PT6302_PDAT_MSK; // Mask invalid bits
-
- _writeCmd((PT6302_PDAT_REG | _port)); // Command register & value
- _writeCmd((PT6302_PDAT_REG | _port)); // Command register & value (Dummy cmd to show on Latched LEDs)
-}
-
-
-/** Set User Defined Characters (UDC)
- *
- * @param unsigned char udc_idx The Index of the UDC (0..7)
- * @param UDCData_t udc_data The bitpattern for the UDC (5 bytes)
- * @return none
- */
-void PT6302::setUDC(unsigned char udc_idx, UDCData_t udc_data) {
-
-//Sanity check
- udc_idx = udc_idx & PT6302_UADR_MSK; // mask invalid bits
-
- _cs=0; // Send Command & Params
- wait_us(1);
- _spi.write(_flip(PT6302_UDC_REG | udc_idx)); // Command register & address
- wait_us(PT6302_CMD_DLY); // Command Delay
-
- _spi.write(_flip(udc_data[0] & PT6302_UDC_MSK)); // CD30 CD25 ...... CD0
- _spi.write(_flip(udc_data[1] & PT6302_UDC_MSK)); // CD31 CD26 ...... CD1
- _spi.write(_flip(udc_data[2] & PT6302_UDC_MSK)); // CD32 CD27 ...... CD2
- _spi.write(_flip(udc_data[3] & PT6302_UDC_MSK)); // CD33 CD28 ...... CD3
- _spi.write(_flip(udc_data[4] & PT6302_UDC_MSK)); // CD34 CD29 ...... CD4
-
- wait_us(PT6302_CS_DLY); // CS Hold Delay
- _cs=1; // Latch Command & Params
-
- wait_us(PT6302_CMD_DLY); // Command Delay
-}
-
-
-/** Write Data to PT6302
- *
- * @param char data Character code
- * @param char address Parameter for data
- * @return none
- */
-void PT6302::writeData(char data, char address){
-
-//Sanity check
- address = address & PT6302_DADR_MSK; // mask invalid bits
-
- _writeCmd((PT6302_DATA_REG | address), // Command register & address
- data); // Character code
-}
-
-/** Write Additional Data to PT6302
- *
- * @param char adata Additional code (annunciator)
- * @param char address Parameter for data
- * @return none
- */
-void PT6302::writeAData(char adata, char address){
-
-//Sanity check
- address = address & PT6302_AADR_MSK; // mask invalid bits
-
- _writeCmd((PT6302_ADAT_REG | address), // Command register & ADRAM address
- adata); // ADATA
-}
-
-/** Write command and data to PT6302
- *
- * @param char cmd Command byte
- * @param char data Parameter for command
- * @return none
- */
-void PT6302::_writeCmd(char cmd, char data){
-
- _cs=0; // Prepare to send Command and data
- wait_us(1);
-
- _spi.write(_flip(cmd)); // Command register & value
-
- wait_us(PT6302_CMD_DLY); // Command Delay
-
- _spi.write(_flip(data)); // data
-
- wait_us(PT6302_CS_DLY); // CS Hold Delay
- _cs=1; // Latch Command and data
-
- wait_us(PT6302_CMD_DLY); // Command Delay
-}
-
-/** Write command to PT6302
- *
- * @param char cmd Command byte
- * @return none
- */
-void PT6302::_writeCmd(char cmd){
-
- _cs=0; // Prepare to send Command
- wait_us(1);
-
- _spi.write(_flip(cmd)); // Command register & value
-
- wait_us(PT6302_CS_DLY); // CS Hold Delay
- _cs=1; // Latch Command
-
- wait_us(PT6302_CMD_DLY); // Command Delay
-}
-
-
-
-/** Helper to reverse all command or databits. The PT6302 expects LSB first, whereas SPI is MSB first
- *
- * @param char data
- * @return bitreversed data
- */
-char PT6302::_flip(char data) {
- char value=0;
-
- if (data & 0x01) {value |= 0x80;} ;
- if (data & 0x02) {value |= 0x40;} ;
- if (data & 0x04) {value |= 0x20;} ;
- if (data & 0x08) {value |= 0x10;} ;
- if (data & 0x10) {value |= 0x08;} ;
- if (data & 0x20) {value |= 0x04;} ;
- if (data & 0x40) {value |= 0x02;} ;
- if (data & 0x80) {value |= 0x01;} ;
- return value;
-}
-
-
-#if (HANNSTAR_TEST == 1)
-
-/** Constructor for class for Princeton PT6302 VFD controller as used in HANNSTAR
- *
- * @brief Supports 16 Grids of 35 Segments without additional Segments.
- *
- * @param PinName mosi, miso, sclk, cs SPI bus pins
- */
-PT6302_HANNSTAR::PT6302_HANNSTAR(PinName mosi, PinName sclk, PinName cs) : PT6302(mosi, sclk, cs, Grid16_Add2) {
- _column = 0;
- _columns = HANNSTAR_NR_DIGITS;
-
- //Enable VGen for VFD Power Supply
- setVGen(true);
-}
-
-/** Locate cursor to a screen column
- *
- * @param column The horizontal position from the left, indexed from 0
- * @return none
- */
-void PT6302_HANNSTAR::locate(int column) {
- //sanity check
- if (column < 0) {column = 0;}
- if (column > (_columns - 1)) {column = _columns - 1;}
-
- _column = column;
-}
-
-
-/** Number of screen columns
- *
- * @param none
- * @return columns
- */
-int PT6302_HANNSTAR::columns() {
- return _columns;
-}
-
-
-/** Clear the screen and locate to 0
- *
- * @param bool clrAll Clear Icons also (default = false)
- * @return none
- */
-void PT6302_HANNSTAR::cls(bool clrAll) {
-
- for (int cnt=0; cnt<HANNSTAR_NR_DIGITS; cnt++) {
- writeData(char (' '), cnt); // data
- }
-
- if (clrAll) {
- //Clear Icons
- for (int cnt=0; cnt<HANNSTAR_NR_DIGITS; cnt++) {
- writeAData(0x00, cnt); // adata
- }
- }
-
- _column = 0;
-}
-
-
-/** Set Port
- *
- * @param char port (Only Bit 1 is used)
- * @return none
- */
-void PT6302_HANNSTAR::setPort (char port){
-
-//Sanity check
- _port &= ~PT6302_HANN_PDAT_MSK; // Clear valid bits
- _port |= (port & PT6302_HANN_PDAT_MSK); // Mask invalid bits
-
- _writeCmd((PT6302_PDAT_REG | _port)); // Command register & value
- _writeCmd((PT6302_PDAT_REG | _port)); // Command register & value (Dummy cmd to show on Latched LEDs)
-}
-
-
-/** Set VFD VGen
- *
- * @param bool on
- * @return none
- */
-void PT6302_HANNSTAR::setVGen(bool on){
-
- if (on) {
- _port = _port | PT6302_HANN_VGEN; // VGen On
- }
- else {
- _port = _port & ~PT6302_HANN_VGEN; // VGen Off
- }
-
- _writeCmd((PT6302_PDAT_REG | _port)); // Command register & value
- _writeCmd((PT6302_PDAT_REG | _port)); // Command register & value (Dummy cmd to show on Latched LEDs)
-}
-
-
-/** Write a single character (Stream implementation)
- *
- * @param value char to print
- * @return value;
- */
-int PT6302_HANNSTAR::_putc(int value) {
- int addr;
-
- if ((value == '\n') || (value == '\r')) {
- //No character to write
-
- //Update Cursor
- _column = 0;
- }
- else if ((value >= 0) && (value < 256)) {
- //Character to write
-
- //Translate between _column and displaybuffer entries
- //Note that the HANNSTAR has 1 digit/grid.
- //_column == 0 => Grid15 => addr = 15
- //_column == 1 => Grid14 => addr = 14
- // ....
- //_column == 15 => Grid1 => addr = 0
- addr = (15 - _column); // 1 Byte for every Grid;
-
- writeData(value, addr);
-
- //Update Cursor
- _column++;
- if (_column > (HANNSTAR_NR_DIGITS - 1)) {
- _column = 0;
- }
-
- } // if validChar
-
- return value;
-}
-
-/** Get a single character (Stream implementation)
- *
- * @param none
- * @return -1
- */
-int PT6302_HANNSTAR::_getc() {
- return -1;
-}
-#endif
--- a/PT6302.h Sun Dec 03 18:02:15 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,461 +0,0 @@
-/* mbed PT6302 Library, for Princeton PT6302 VFD controller
- * Note the PT6302 is identical to the OKI ML9208
- *
- * Copyright (c) 2017, v01: WH, Initial version
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef PT6302_H
-#define PT6302_H
-
-// Select one of the testboards for Princeton PT6302 VFD controller
-#include "PT6302_Config.h"
-#include "PT6302_UDC.h"
-
-/** An interface for driving Princeton PT6302 VFD controller
- *
- * @code
- *
- * #if (PT6302_TEST == 1)
- * // Direct driving of PT6302 Test
- *
- * #include "mbed.h"
- * #include "PT6302.h"
- *
- * DigitalOut myled(LED1);
- * Serial pc(USBTX, USBRX);
- *
- * // PT6302 declaration, Default setting 16 Grids @ 35 Segments
- * PT6302 PT6302(p5, p7, p8); // DI, CLK, CS
- *
- * int main() {
- * pc.printf("Hello World: PT6302 test\n\r");
- *
- * PT6302.cls();
- *
- * PT6302.writeData((char)'H', 9);
- * PT6302.writeData((char)'e', 8);
- * PT6302.writeData((char)'l', 7);
- * PT6302.writeData((char)'l', 6);
- * PT6302.writeData((char)'o', 5);
- * wait(2);
- * PT6302.setBrightness(PT6302_BRT0);
- * wait(2);
- * PT6302.setBrightness(PT6302_BRT3);
- *
- * while(1) {
- * myled = !myled;
- * wait(1);
- * }
- * }
- * #endif
- *
- * @endcode
- */
-
-
-//PT6302 Display and Annunciator data
-#define PT6302_MAX_NR_GRIDS 16
-#define PT6302_BYTES_PER_GRID 1
-
-//Memory size in bytes for Display and Annunciators
-#define PT6302_DSP_MEM 16
-#define PT6302_ADD_MEM 16
-//#define PT6302_UDC_MEM 8
-
-//SPI Serial control data consists of an 8-bit command and one or more data bytes.
-//Command and data are sent LSB first and latched on rising edge of CLK. Idle CLK is high.
-//Data address is auto incremented.
-//The commands and data are transmitted during CE low and latched on rising CE edge.
-//Multiple PT6302 devices on the same bus can only be distinguised by the CE control.
-
-//Command delay
-#define PT6302_CMD_DLY 8
-#define PT6302_CS_DLY 16
-
-//
-//Set Char data command (DCRAM)
-// 0 0 0 1 DA3 DA2 DA1 DA0
-#define PT6302_DATA_REG 0x10
-
-//DA3..DA0 DCRAM Address
-#define PT6302_DADR_MSK 0x0F
-
-//Char data (2nd byte, 3rd byte ...)
-//DA7..DA0 Character Data
-#define PT6302_DATA_MSK 0xFF
-
-
-//
-//Set UDC data command (CGRAM)
-// 0 0 1 0 * UA2 UA1 UA0
-#define PT6302_UDC_REG 0x20
-
-//UA2..UA0 CGRAM Address (UDC RAM address)
-#define PT6302_UADR_MSK 0x07
-#define PT6302_NR_UDC 8
-
-//User Defined Characters (UDCs) consist of 5x7 dots and are defined by a 5 byte bitpattern.
-//UDC data (2nd byte .. 6th byte)
-// D7 D6 D5 D4.. D1 D0
-// 0 * CD30 CD25 ...... CD0
-// 1 * CD31 CD26 ...... CD1
-// 2 * CD32 CD27 ...... CD2
-// 3 * CD33 CD28 ...... CD3
-// 4 * CD34 CD29 ...... CD4
-//
-#define PT6302_UDC_MSK 0x7F
-
-//CD34..CD0 UDC Data
-//UDC is a 5x7 Matrix pattern that will show on the VFD as
-// 0 C0 C1 C2 C3 C4
-// 1 C5 C6 ..... C9
-// . .............
-// . .............
-// . .............
-// 6 C30 C31 ... C34
-//
-
-//UDCs are defined by a 5x7 matrix and stored as 5 bytes
-typedef char UDCData_t[5];
-
-
-//
-//Set Additional data command (ADRAM), Used for annunciators etc
-// 0 0 1 1 AA3 AA2 AA1 AA0
-#define PT6302_ADAT_REG 0x30
-
-//AA3..AA0 ADRAM Address (Additional data)
-#define PT6302_AADR_MSK 0x0F
-
-//* * * * * * AD1 AD0 Additional Data (2nd byte, 3rd byte, ..)
-#define PT6302_ADAT_MSK 0x03
-
-
-//
-//Set Port data command (General output)
-// 0 1 0 0 * * P1 P0
-#define PT6302_PDAT_REG 0x40
-
-//P1 P0 Port data
-#define PT6302_PDAT_MSK 0x03
-
-
-
-//
-//Set Brightness command
-// 0 1 0 1 * DC2 DC1 DC0
-#define PT6302_BRT_REG 0x50
-#define PT6302_BRT_MSK 0x07
-
-//DC2..DC0 Brightness Level (0..7)
-//Note Brightness relationship between the number of active Grids (period) and the BRT value (duty cycle)
-#define PT6302_BRT_0 0x00 //Duty 8/16 (Default)
-#define PT6302_BRT_1 0x01
-#define PT6302_BRT_2 0x02
-#define PT6302_BRT_3 0x03
-#define PT6302_BRT_4 0x04
-#define PT6302_BRT_5 0x05
-#define PT6302_BRT_6 0x06
-#define PT6302_BRT_7 0x07 //Duty 15/16
-
-#define PT6302_BRT_DEF (PT6302_BRT_2)
-
-
-//
-//Grid control command
-// 0 1 1 0 * GN2 GN1 GN0
-#define PT6302_GRID_REG 0x60
-#define PT6302_GRID_MSK 0x07
-
-//Grids
-//
-// GN2 GN1 GN0
-// 0 0 0 G1 to G16 // Default
-// 0 0 1 G1 to G9
-// 0 1 0 G1 to G10
-// 0 1 1 G1 to G11
-// 1 0 0 G1 to G12
-// 1 0 1 G1 to G13
-// 1 1 0 G1 to G14
-// 1 1 1 G1 to G15
-#define PT6302_GR1_GR9 0x01
-#define PT6302_GR1_GR10 0x02
-#define PT6302_GR1_GR11 0x03
-#define PT6302_GR1_GR12 0x04
-#define PT6302_GR1_GR13 0x05
-#define PT6302_GR1_GR14 0x06
-#define PT6302_GR1_GR15 0x07
-#define PT6302_GR1_GR16 0x00
-
-
-//
-//Display On/Off command
-// 0 1 1 1 * * H L
-#define PT6302_DSPL_REG 0x70
-#define PT6302_DSPL_MSK 0x03
-
-//Display Mode
-// H L Display operating state
-// 0 0 Normal (default)
-// 0 1 Off
-// 1 0 All Segments and Additional Segments On
-// 1 1 All Segments and Additional Segments On
-#define PT6302_DSPL_NRM 0x00
-#define PT6302_DSPL_OFF 0x01
-#define PT6302_DSPL_ON 0x02
-
-
-/** A class for driving Princeton PT6302 VFD controller
- *
- * @brief Supports upto 16 Grids of 35 matrix segments.
- * Also supports 2 additional segments and 2 port pins.
- * SPI bus interface device.
- */
-class PT6302 {
- public:
-
- /** Enums for display mode */
- enum Mode {
- Grid9_Add2 = PT6302_GR1_GR9,
- Grid10_Add2 = PT6302_GR1_GR10,
- Grid11_Add2 = PT6302_GR1_GR11,
- Grid12_Add2 = PT6302_GR1_GR12,
- Grid13_Add2 = PT6302_GR1_GR13,
- Grid14_Add2 = PT6302_GR1_GR14,
- Grid15_Add2 = PT6302_GR1_GR15,
- Grid16_Add2 = PT6302_GR1_GR16
- };
-
- /** Datatypes for display data */
-// typedef char DisplayData_t[PT6302_DISPLAY_MEM];
-// typedef char DisplayAdd_t[PT6302_ADD_MEM];
-
- /** Constructor for class for driving Princeton PT6302 VFD controller
- *
- * @brief Supports upto 16 Grids of 35 matrix segments.
- * Also supports 2 additional segments and 2 port pins.
- * SPI bus interface device.
- * @param PinName mosi, sclk, cs SPI bus pins
- * @param Mode selects number of Grids and Segments (default 16 Grids, 2 additional segments)
- */
- PT6302(PinName mosi, PinName sclk, PinName cs, Mode mode = Grid16_Add2);
-
- /** Clear the screen
- *
- * @param none
- * @return none
- */
- void cls();
-
- /** Set Brightness
- *
- * @param char brightness (3 significant bits, valid range 0..7 (dutycycle linked to number of grids)
- * @return none
- */
- void setBrightness(char brightness = PT6302_BRT_DEF);
-
- /** Set the Display mode On/off
- *
- * @param bool display mode
- * @return none
- */
- void setDisplay(bool on);
-
-
- /** Set Port
- *
- * @param char port (2 least significant bits)
- * @return none
- */
- void setPort (char port = 0);
-
- /** Set User Defined Characters (UDC)
- *
- * @param unsigned char udc_idx The Index of the UDC (0..7)
- * @param UDCData_t udc_data The bitpattern for the UDC (5 bytes)
- * @return none
- */
- void setUDC(unsigned char udc_idx, UDCData_t udc_data);
-
-
- /** Write Data to PT6302
- *
- * @param char data Character code
- * @param char address Parameter for data
- * @return none
- */
- void writeData(char data, char address);
-
- /** Write Additional Data to PT6302
- *
- * @param char adata Additional code (annunciator)
- * @param char address Parameter for data
- * @return none
- */
- void writeAData(char adata, char address);
-
- protected:
- /** Write command and parameters to PT6302
- *
- * @param char cmd Command byte
- * @param char data Parameter for command
- * @return none
- */
- void _writeCmd(char cmd, char data);
-
- /** Write command to PT6302
- *
- * @param char cmd Command byte
- * @return none
- */
- void _writeCmd(char cmd);
-
- char _port;
-
- private:
- SPI _spi;
- DigitalOut _cs;
- Mode _mode;
-
- /** Init the SPI interface and the controller
- *
- * @param none
- * @return none
- */
- void _init();
-
- /** Helper to reverse all command or databits. The PT6302 expects LSB first, whereas SPI is MSB first
- *
- * @param char data
- * @return bitreversed data
- */
- char _flip(char data);
-
-};
-
-
-#if (HANNSTAR_TEST == 1)
-// Derived class for HANNSTAR display unit
-// Grids 1-16 all display 35 segment matrix characters and no Additional segments.
-//
-
-//HANNSTAR Display data
-#define HANNSTAR_NR_GRIDS 16
-#define HANNSTAR_NR_DIGITS 16
-//#define HANNSTAR_NR_UDC 8
-
-//HANNSTAR Memory size in bytes for Display
-//#define HANNSTAR_DISPLAY_MEM (HANNSTAR_NR_GRIDS * PT6302_BYTES_PER_GRID)
-
-
-//
-//Set Port data command (General output)
-// 0 1 0 0 * * P1 P0
-
-//P0 P1 Port data, P0 is used for VGen control
-#define PT6302_HANN_PDAT_MSK 0x02
-
-//P0 is used to control the VFD Voltage generator (-24V and Filament)
-#define PT6302_HANN_VGEN 0x01
-
-
-
-/** Constructor for class for driving Princeton PT6302 VFD controller as used in HANNSTAR
- *
- * @brief Supports 16 Grids of 35 Segments without additional Segments.
- *
- * @param PinName mosi, sclk, cs SPI bus pins
- */
-class PT6302_HANNSTAR : public PT6302, public Stream {
- public:
-
-/** Constructor for class for driving Princeton PT6302 VFD controller as used in HANNSTAR
- *
- * @brief Supports 16 Grids of 35 Segments without additional Segments.
- *
- * @param PinName mosi, sclk, cs SPI bus pins
- */
- PT6302_HANNSTAR(PinName mosi, PinName sclk, PinName cs);
-
-#if DOXYGEN_ONLY
- /** Write a character to the Display
- *
- * @param c The character to write to the display
- * @return char written
- */
- int putc(int c);
-
- /** Write a formatted string to the Display
- *
- * @param format A printf-style format string, followed by the
- * variables to use in formatting the string.
- */
- int printf(const char* format, ...);
-#endif
-
- /** Locate cursor to a screen column
- *
- * @param column The horizontal position from the left, indexed from 0
- * @return none
- */
- void locate(int column);
-
- /** Clear the screen and locate to 0
- *
- * @param bool clrAll Clear Icons also (default = false)
- */
- void cls(bool clrAll = false);
-
- /** Number of screen columns
- *
- * @param none
- * @return columns
- */
- int columns();
-
- /** Set Port
- *
- * @param char port (Only Bit 1 is used)
- * @return none
- */
- void setPort (char port = 0);
-
- /** Set VFD VGen
- *
- * @param bool on
- * @return none
- */
- void setVGen (bool on = true);
-
-protected:
- // Stream implementation functions
- virtual int _putc(int value);
- virtual int _getc();
-
-private:
- int _column; // Current cursor location
- int _columns; // Max number of columns
-
-// DisplayData_t _displaybuffer; // Local mirror for all chars and icons
-};
-#endif
-
-#endif
\ No newline at end of file
--- a/PT6302_Config.h Sun Dec 03 18:02:15 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* mbed PT6302 Library, for Princeton PT6302 VFD controller - * Note the PT6302 is identical to the OKI ML9208 - * - * Copyright (c) 2017, v01: WH, Initial version - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef PT6302_CONFIG_H -#define PT6302_CONFIG_H - -// Select one of the testboards for Princeton PT6302 VFD controller -#define PT6302_TEST 0 -#define HANNSTAR_TEST 1 - -// Select if you want to include some UDC patterns -#define PT6302_UDC 1 - -#endif \ No newline at end of file
--- a/PT6302_UDC.h Sun Dec 03 18:02:15 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* mbed PT6302 UDC Library, for Princeton PT6302 VFD controller - * Note the PT6302 is identical to the OKI ML9208 - * - * Copyright (c) 2017, v01: WH, Initial version - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MBED_PT6302_UDC_H -#define MBED_PT6302_UDC_H - -#include "PT6302_Config.h" - -#if(PT6302_UDC == 1) -// User Defined Characters (UDCs) consist of 5x7 dots and are defined by a 5 byte bitpattern. -// The C0..C34 form the character pattern. -// D7 D6 D5 D4 D3 D2 D1 D0 -// 0 x C30 C25 C20 ...... C0 -// 1 x C31 C24 ........... C1 -// . ............. -// 4 x C34 C29 ........... C4 -// -// -// The UDC matrix will show on the VFD as -// 0 C0 C1 C2 C3 C4 -// 1 C5 C6 ..... C9 -// . ............. -// . ............. -// . ............. -// 6 C30 C31 ... C34 -// - - -// Some sample User Defined Chars 5x7 dots */ -//extern const char udc_Bat_Hi[]; // Battery Full -//extern const char udc_Bat_Ha[]; // Battery Half -//extern const char udc_Bat_Lo[]; // Battery Low -//extern const char udc_checker[]; - -//extern const char udc_PO[]; //Padlock Open -//extern const char udc_PC[]; //Padlock Closed - -extern const char udc_LAR[]; // Left Arrow -extern const char udc_RAR[]; // Right Arrow -#endif - -#endif
--- a/PT6302_UDC.inc Sun Dec 03 18:02:15 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/* mbed PT6302 UDC Library, for Princeton PT6302 VFD controller
- * Note the PT6302 is identical to the OKI ML9208
- *
- * Copyright (c) 2017, v01: WH, Initial version
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-#include "PT6302_Config.h"
-
-#if(PT6302_UDC == 1)
-
-// User Defined Characters (UDCs) are defined by a 5 byte bitpattern.
-// The C0..C34 form the character pattern.
-// D7 D6 D5 D4 D3 D2 D1 D0
-// 0 x C30 C25 C20 ...... C0
-// 1 x C31 C24 ........... C1
-// . .............
-// 4 x C34 C29 ........... C4
-//
-//
-// The UDC matrix will show on the VFD as
-// 0 C0 C1 C2 C3 C4
-// 1 C5 C6 ..... C9
-// . .............
-// . .............
-// . .............
-// 6 C30 C31 ... C34
-//
-//
-// Some sample User Defined Chars 5x7 dots */
-const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F}; // Battery Full
-const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F}; // Battery Half
-const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11}; // Battery Low
-const char udc_checker[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA};
-
-//const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B}; //Padlock Open
-//const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B}; //Padlock Closed
-
-const char udc_LAR[] = {0x07, 0x03, 0x05, 0x78, 0x00}; // Left Arrow
-const char udc_RAR[] = {0x00, 0x78, 0x05, 0x03, 0x07}; // Right Arrow
-#endif