Library for Princeton PT6961 LED driver. Supports 6 digits @ 12 segments or 7 digits @ 11 segments. Also supports keyboard scanning of upto 30 keys. SPI interface.

Dependents:   mbed_PT6961

This LED driver is found in frontpanel controllers of consumer electronics such as DVD players. The added features such as the matrix keyboard scanning are useful in these applications.

Additional information is available on the component page here

Revision:
1:eb4758bba68a
Parent:
0:feebe8eca523
Child:
2:c6883ede8d8b
--- a/PT6961.cpp	Sun Sep 20 13:28:46 2015 +0000
+++ b/PT6961.cpp	Thu Jan 07 20:57:00 2016 +0000
@@ -1,5 +1,6 @@
 /* mbed PT6961 Library, for Princeton PT6961 LED controller
- * Copyright (c) 2015, v01: WH, Initial version
+ * Copyright (c) 2015, v01: WH, Initial version (HR734)
+ *               2016, v02: WH, Added V56S, Added Stream support
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -23,10 +24,10 @@
 #include "PT6961.h"
 
 /** Constructor for class for driving Princeton PT6961 LED controller with SPI bus interface device. 
- *  @brief Supports 6 Digits or 12 Segments or 7 Digits of 11 Segments. Also supports a scanned keyboard of upto 30 keys.
+ *  @brief Supports 6 Grids @ 12 Segments or 7 Grids @ 11 Segments. Also supports a scanned keyboard of upto 30 keys.
  *   
  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
- *  @param  Mode selects either 6 Digits of 12 Segments or 7 Digits of 11 Segments (default) 
+ *  @param  Mode selects either 6 Grids @ 12 Segments or 7 Grids @ 11 Segments (default) 
 */
 PT6961::PT6961(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode) : _spi(mosi,miso,sclk), _cs(cs), _mode(mode) {
 
@@ -222,3 +223,415 @@
 }  
 
 
+
+#if(HR734_TEST == 1)
+// Derived class for PT6961 used in HR734 display unit
+//
+#include "Font_7Seg.h"
+
+/** Constructor for class for driving PT6961 LED controller as used in HR734
+  *
+  *  @brief Supports 5 Digits of 7 Segments + some additional segments + Icons. Also supports a scanned keyboard of 10 keys.
+  *   
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */
+PT6961_HR734::PT6961_HR734(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6961(mosi, miso, sclk, cs) {
+  _column  = 0;
+  _columns = HR734_NR_DIGITS;    
+}  
+
+#if(0)
+#if DOXYGEN_ONLY
+    /** Write a character to the Display
+     *
+     * @param c The character to write to the display
+     */
+    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
+#endif
+
+/** Locate cursor to a screen column
+  *
+  * @param column  The horizontal position from the left, indexed from 0
+  */
+void PT6961_HR734::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 PT6961_HR734::columns() {
+    return _columns;
+}
+
+    
+/** Clear the screen and locate to 0
+  * @param bool clrAll Clear Icons also (default = false)
+  */ 
+void PT6961_HR734::cls(bool clrAll) {  
+
+  if (clrAll) {
+    //clear local buffer (including Icons)
+    for (int idx=0; idx < (HR734_NR_GRIDS << 1); idx++) {
+      _displaybuffer[idx] = 0x00;  
+    }
+  }  
+  else {
+    //clear local buffer (preserving Icons)
+    for (int idx=0; idx < HR734_NR_GRIDS; idx++) {
+      _displaybuffer[(idx<<1)]     = _displaybuffer[(idx<<1)]     & MASK_ICON_GRID[idx][0];  
+      _displaybuffer[(idx<<1) + 1] = _displaybuffer[(idx<<1) + 1] & MASK_ICON_GRID[idx][1];
+    }  
+  }
+
+  writeData(_displaybuffer, (HR734_NR_GRIDS*2));
+
+  _column = 0;   
+}     
+
+/** Set Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+  * @return none
+  */
+void PT6961_HR734::setIcon(Icon icon) {
+  int addr, icn;
+
+   icn =        icon  & 0xFFFF;
+  addr = (icon >> 24) & 0xFF; 
+  addr = (addr - 1) << 1;   
+    
+  //Save char...and set bits for icon to write
+  _displaybuffer[addr]   = _displaybuffer[addr]   | LO(icn);      
+  _displaybuffer[addr+1] = _displaybuffer[addr+1] | HI(icn);      
+  writeData(_displaybuffer, (HR734_NR_GRIDS*2));
+}
+
+/** Clr Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+  * @return none
+  */
+void PT6961_HR734::clrIcon(Icon icon) {
+  int addr, icn;
+
+   icn =        icon  & 0xFFFF;
+  addr = (icon >> 24) & 0xFF; 
+  addr = (addr - 1) << 1;   
+    
+  //Save char...and clr bits for icon to write
+  _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(icn);      
+  _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~HI(icn);      
+  writeData(_displaybuffer, (HR734_NR_GRIDS*2));
+}
+
+
+/** Set User Defined Characters (UDC)
+  *
+  * @param unsigned char udc_idx  The Index of the UDC (0..7)
+  * @param int udc_data           The bitpattern for the UDC (16 bits)       
+  */
+void PT6961_HR734::setUDC(unsigned char udc_idx, int udc_data) {
+
+  //Sanity check
+  if (udc_idx > (HR734_NR_UDC-1)) {
+    return;
+  }
+  // Mask out Icon bits?
+
+  _UDC_7S[udc_idx] = udc_data;
+}
+
+
+/** Write a single character (Stream implementation)
+  */
+int PT6961_HR734::_putc(int value) {
+    int addr;
+    bool validChar = false;
+    short pattern  = 0x0000;
+    
+    if ((value == '\n') || (value == '\r')) {
+      //No character to write
+      validChar = false;
+      
+      //Update Cursor      
+      _column = 0;
+    } 
+    else if (value == '-') {
+      //No character to write
+      validChar = true;
+      pattern = C7_MIN;         
+    }
+    else if ((value >= 0) && (value < HR734_NR_UDC)) {
+      //Character to write
+      validChar = true;
+      pattern = _UDC_7S[value];
+    }  
+    else if ((value >= (int)'0') && (value <= (int) '9')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[value - (int) '0'];
+    }
+    else if ((value >= (int) 'A') && (value <= (int) 'F')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[10 + value - (int) 'A'];
+    }
+    else if ((value >= (int) 'a') && (value <= (int) 'f')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[10 + value - (int) 'a'];
+    } //else
+
+    if (validChar) {
+      //Character to write
+ 
+      //Translate between _column and displaybuffer entries
+      addr = _column << 1;
+
+      //Save icons...and set bits for character to write
+      _displaybuffer[addr]   = (_displaybuffer[addr]   & MASK_ICON_GRID[_column][0]) | LO(pattern);
+      _displaybuffer[addr+1] = (_displaybuffer[addr+1] & MASK_ICON_GRID[_column][1]) | HI(pattern);
+
+      writeData(_displaybuffer, (HR734_NR_GRIDS*2));
+                                
+      //Update Cursor
+      _column++;
+      if (_column > (HR734_NR_DIGITS - 1)) {
+        _column = 0;
+      }
+
+    } // if validChar           
+
+    return value;
+}
+
+
+// get a single character (Stream implementation)
+int PT6961_HR734::_getc() {
+    return -1;
+}
+
+#endif
+
+
+
+#if(V56S_TEST == 1)
+// Derived class for PT6961 used in V56S display unit
+//
+#include "Font_7Seg.h"
+
+/** Constructor for class for driving PT6961 LED controller as used in V56S
+  *
+  *  @brief Supports 5 Digits of 7 Segments + some additional segments + Icons. Also supports a scanned keyboard of 5 keys.
+  *   
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */
+PT6961_V56S::PT6961_V56S(PinName mosi, PinName miso, PinName sclk, PinName cs) : PT6961(mosi, miso, sclk, cs) {
+  _column  = 0;
+  _columns = V56S_NR_DIGITS;    
+}  
+
+#if(0)
+#if DOXYGEN_ONLY
+    /** Write a character to the Display
+     *
+     * @param c The character to write to the display
+     */
+    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
+#endif
+
+/** Locate cursor to a screen column
+  *
+  * @param column  The horizontal position from the left, indexed from 0
+  */
+void PT6961_V56S::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 PT6961_V56S::columns() {
+    return _columns;
+}
+
+    
+/** Clear the screen and locate to 0
+  * @param bool clrAll Clear Icons also (default = false)
+  */ 
+void PT6961_V56S::cls(bool clrAll) {  
+
+  if (clrAll) {
+    //clear local buffer (including Icons)
+    for (int idx=0; idx < (V56S_NR_GRIDS << 1); idx++) {
+      _displaybuffer[idx] = 0x00;  
+    }
+  }  
+  else {
+    //clear local buffer (preserving Icons)
+    for (int idx=0; idx < V56S_NR_GRIDS; idx++) {
+      _displaybuffer[(idx<<1)]     = _displaybuffer[(idx<<1)]     & MASK_ICON_GRID[idx][0];  
+      _displaybuffer[(idx<<1) + 1] = _displaybuffer[(idx<<1) + 1] & MASK_ICON_GRID[idx][1];
+    }  
+  }
+
+  writeData(_displaybuffer, (V56S_NR_GRIDS*2));
+
+  _column = 0;   
+}     
+
+/** Set Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+  * @return none
+  */
+void PT6961_V56S::setIcon(Icon icon) {
+  int addr, icn;
+
+   icn =        icon  & 0xFFFF;
+  addr = (icon >> 24) & 0xFF; 
+  addr = (addr - 1) << 1;   
+    
+  //Save char...and set bits for icon to write
+  _displaybuffer[addr]   = _displaybuffer[addr]   | LO(icn);      
+  _displaybuffer[addr+1] = _displaybuffer[addr+1] | HI(icn);      
+  writeData(_displaybuffer, (V56S_NR_GRIDS*2));
+}
+
+/** Clr Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+  * @return none
+  */
+void PT6961_V56S::clrIcon(Icon icon) {
+  int addr, icn;
+
+   icn =        icon  & 0xFFFF;
+  addr = (icon >> 24) & 0xFF; 
+  addr = (addr - 1) << 1;   
+    
+  //Save char...and clr bits for icon to write
+  _displaybuffer[addr]   = _displaybuffer[addr]   & ~LO(icn);      
+  _displaybuffer[addr+1] = _displaybuffer[addr+1] & ~HI(icn);      
+  writeData(_displaybuffer, (V56S_NR_GRIDS*2));
+}
+
+
+/** Set User Defined Characters (UDC)
+  *
+  * @param unsigned char udc_idx  The Index of the UDC (0..7)
+  * @param int udc_data           The bitpattern for the UDC (16 bits)       
+  */
+void PT6961_V56S::setUDC(unsigned char udc_idx, int udc_data) {
+
+  //Sanity check
+  if (udc_idx > (V56S_NR_UDC-1)) {
+    return;
+  }
+  // Mask out Icon bits?
+
+  _UDC_7S[udc_idx] = udc_data;
+}
+
+
+/** Write a single character (Stream implementation)
+  */
+int PT6961_V56S::_putc(int value) {
+    int addr;
+    bool validChar = false;
+    short pattern  = 0x0000;
+    
+    if ((value == '\n') || (value == '\r')) {
+      //No character to write
+      validChar = false;
+      
+      //Update Cursor      
+      _column = 0;
+    } 
+    else if (value == '-') {
+      //No character to write
+      validChar = true;
+      pattern = C7_MIN;         
+    }
+    else if ((value >= 0) && (value < V56S_NR_UDC)) {
+      //Character to write
+      validChar = true;
+      pattern = _UDC_7S[value];
+    }  
+    else if ((value >= (int)'0') && (value <= (int) '9')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[value - (int) '0'];
+    }
+    else if ((value >= (int) 'A') && (value <= (int) 'F')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[10 + value - (int) 'A'];
+    }
+    else if ((value >= (int) 'a') && (value <= (int) 'f')) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[10 + value - (int) 'a'];
+    } //else
+
+    if (validChar) {
+      //Character to write
+ 
+      //Translate between _column and displaybuffer entries
+      addr = _column << 1;
+
+      //Save icons...and set bits for character to write
+      _displaybuffer[addr]   = (_displaybuffer[addr]   & MASK_ICON_GRID[_column][0]) | LO(pattern);
+      _displaybuffer[addr+1] = (_displaybuffer[addr+1] & MASK_ICON_GRID[_column][1]) | HI(pattern);
+
+      writeData(_displaybuffer, (V56S_NR_GRIDS*2));
+                                
+      //Update Cursor
+      _column++;
+      if (_column > (V56S_NR_DIGITS - 1)) {
+        _column = 0;
+      }
+
+    } // if validChar           
+
+    return value;
+}
+
+
+// get a single character (Stream implementation)
+int PT6961_V56S::_getc() {
+    return -1;
+}
+
+#endif
\ No newline at end of file