LED Driver, 6 digits @ 8 segm, 8 LEDs, 16 Keys. SPI Interface

Dependents:   mbed_STLED316S

See here for more information.

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sat Oct 01 15:09:51 2016 +0000
Child:
1:7a845a89625f
Commit message:
ST316LED driver lib; First Release

Changed in this revision

Font_7Seg.cpp Show annotated file Show diff for this revision Revisions of this file
Font_7Seg.h Show annotated file Show diff for this revision Revisions of this file
STLED316S.cpp Show annotated file Show diff for this revision Revisions of this file
STLED316S.h Show annotated file Show diff for this revision Revisions of this file
STLED316S_Config.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Font_7Seg.cpp	Sat Oct 01 15:09:51 2016 +0000
@@ -0,0 +1,153 @@
+/* mbed LED Font Library, for STM STLED316S controller
+ * Copyright (c) 2016, 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 "Font_7Seg.h"
+
+// ASCII Font definition table for transmission to STLED316S
+//
+//#define FONT_7S_START     0x20
+//#define FONT_7S_END       0x7F
+//#define FONT_7S_NR_CHARS (FONT_7_END - FONT_7S_START + 1)
+
+
+#if (SHOW_ASCII == 1)
+//display all ASCII characters
+const char FONT_7S[]  = { 
+                             C7_SPC, //32 0x20, Space
+                             C7_EXC,
+                             C7_QTE,
+                             C7_HSH,
+                             C7_DLR,
+                             C7_PCT,
+                             C7_AMP,
+                             C7_ACC,
+                             C7_LBR,
+                             C7_RBR,                   
+                             C7_MLT,                            
+                             C7_PLS,
+                             C7_CMA,
+                             C7_MIN,
+                             C7_DPT,                             
+                             C7_RS,
+                             C7_0,   //48 0x30
+                             C7_1,
+                             C7_2,
+                             C7_3,
+                             C7_4,                   
+                             C7_5,
+                             C7_6,
+                             C7_7,
+                             C7_8,
+                             C7_9,
+                             C7_COL, //58 0x3A
+                             C7_SCL,
+                             C7_LT,
+                             C7_EQ,
+                             C7_GT,
+                             C7_QM,                             
+                             C7_AT,  //64 0x40
+                             C7_A,   //65 0x41, A
+                             C7_B,
+                             C7_C,
+                             C7_D,
+                             C7_E,
+                             C7_F,
+                             C7_G,
+                             C7_H,
+                             C7_I,
+                             C7_J,                   
+                             C7_K,
+                             C7_L,
+                             C7_M,
+                             C7_N,
+                             C7_O,
+                             C7_P,
+                             C7_Q,
+                             C7_R,
+                             C7_S,
+                             C7_T,
+                             C7_U,
+                             C7_V,
+                             C7_W,
+                             C7_X,
+                             C7_Y,
+                             C7_Z,   //90 0x5A, Z
+                             C7_SBL, //91 0x5B
+                             C7_LS,
+                             C7_SBR,
+                             C7_PWR,
+                             C7_UDS,  
+                             C7_ACC,                             
+                             C7_A,   //97 0x61, A replacing a
+                             C7_B,
+                             C7_C,
+                             C7_D,
+                             C7_E,
+                             C7_F,
+                             C7_G,
+                             C7_H,
+                             C7_I,
+                             C7_J,                   
+                             C7_K,
+                             C7_L,
+                             C7_M,
+                             C7_N,
+                             C7_O,
+                             C7_P,
+                             C7_Q,
+                             C7_R,
+                             C7_S,
+                             C7_T,
+                             C7_U,
+                             C7_V,
+                             C7_W,
+                             C7_X,
+                             C7_Y,
+                             C7_Z,   // 122 0x7A, Z replacing z
+                             C7_CBL, // 123 0x7B
+                             C7_OR,
+                             C7_CBR,
+                             C7_TLD,
+                             C7_DEL  // 127                             
+                        };
+ 
+#else
+//display only digits and hex characters
+const short FONT_7S[] = { 
+                           C7_0, //48 0x30
+                           C7_1,
+                           C7_2,
+                           C7_3,
+                           C7_4,                   
+                           C7_5,
+                           C7_6,
+                           C7_7,
+                           C7_8,
+                           C7_9,
+                           C7_A, //65 0x41, A
+                           C7_B,
+                           C7_C,
+                           C7_D,
+                           C7_E,
+                           C7_F
+                        };// 127
+#endif
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Font_7Seg.h	Sat Oct 01 15:09:51 2016 +0000
@@ -0,0 +1,193 @@
+/* mbed LED Font Library, for STM STLED316S controller
+ * Copyright (c) 2016, 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_FONT_7SEG_H
+#define MBED_FONT_7SEG_H
+
+// Select one of the testboards for STLED316S controller
+#include "STLED316S_Config.h"
+
+#if ((STLED316S_TEST == 1) || (ST316BOARD_TEST == 1))
+// Segment bit positions for 7 Segment display using the test display mapping for STLED316S
+// Modify this table for different 'bit-to-segment' mappings. The ASCII character defines and the FONT_7S const table below 
+// will be adapted automatically according to the bit-to-segment mapping. Obviously this will only work when the segment
+// mapping is identical for every digit position. This will be the case unless the hardware designer really hates software developers.
+//
+//            A
+//          -----
+//         |     |     
+//       F |     | B    
+//         |  G  |     
+//          -----
+//         |     |     
+//       E |     | C    
+//         |     |     
+//          -----   * DP
+//            D  
+//
+#define S7_A    0x01 
+#define S7_B    0x02
+#define S7_C    0x04
+#define S7_D    0x08 
+#define S7_E    0x10
+#define S7_F    0x20
+#define S7_G    0x40
+#define S7_DP   0x80
+
+//Mask for blending out and setting 7 segments digits
+#define MASK_7S_ALL = (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F | S7_G}
+#endif
+
+
+// ASCII Font definitions for segments in each character
+//
+//32 0x20  Symbols
+#define C7_SPC  (0x0000)
+#define C7_EXC  (S7_B | S7_C) //!
+#define C7_QTE  (S7_B | S7_F) //"
+#define C7_HSH  (S7_C | S7_D | S7_E | S7_G) //#
+#define C7_DLR  (S7_A | S7_C | S7_D | S7_F | S7_G) //$
+#define C7_PCT  (S7_C | S7_F) //%
+#define C7_AMP  (S7_A | S7_C | S7_D | S7_E | S7_F | S7_G) //&
+#define C7_ACC  (S7_B) //'
+#define C7_LBR  (S7_A | S7_D | S7_E | S7_F) //(
+#define C7_RBR  (S7_A | S7_B | S7_C | S7_D) //)
+#define C7_MLT  (S7_B | S7_C | S7_E | S7_F | S7_G)  //*
+#define C7_PLS  (S7_B | S7_C | S7_G) //+
+#define C7_CMA  (S7_DP)
+#define C7_MIN  (S7_G)
+#define C7_DPT  (S7_DP)
+#define C7_RS   (S7_B | S7_E  | S7_G)  // /
+
+//48 0x30  Digits
+#define C7_0    (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F)
+#define C7_1    (S7_B | S7_C)
+#define C7_2    (S7_A | S7_B | S7_D | S7_E | S7_G)
+#define C7_3    (S7_A | S7_B | S7_C | S7_D | S7_G)
+#define C7_4    (S7_B | S7_C | S7_F | S7_G)
+#define C7_5    (S7_A | S7_C | S7_D | S7_F | S7_G)
+#define C7_6    (S7_A | S7_C | S7_D | S7_E | S7_F | S7_G)
+#define C7_7    (S7_A | S7_B | S7_C)
+#define C7_8    (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F | S7_G)
+#define C7_9    (S7_A | S7_B | S7_C | S7_D | S7_F | S7_G)
+
+//58 0x3A
+#define C7_COL  (S7_D | S7_G) // :
+#define C7_SCL  (S7_D | S7_G) // ;
+#define C7_LT   (S7_D | S7_E | S7_G)             // <
+#define C7_EQ   (S7_D | S7_G)                    // =
+#define C7_GT   (S7_C | S7_D | S7_G)             // >   
+#define C7_QM   (S7_A | S7_B | S7_E | S7_G)      // ?
+#define C7_AT   (S7_A | S7_B | S7_C | S7_D | S7_E  | S7_G)  // @
+
+//65 0x41  Upper case alphabet
+#define C7_A    (S7_A | S7_B | S7_C | S7_E | S7_F | S7_G )
+#define C7_B    (S7_C | S7_D | S7_E | S7_F | S7_G)
+#define C7_C    (S7_A | S7_D | S7_E | S7_F)
+#define C7_D    (S7_B | S7_C | S7_D | S7_E | S7_G)
+#define C7_E    (S7_A | S7_D | S7_E | S7_F | S7_G)
+#define C7_F    (S7_A | S7_E | S7_F | S7_G)
+
+#define C7_G    (S7_A | S7_C | S7_D | S7_E | S7_F)
+#define C7_H    (S7_B | S7_C | S7_E | S7_F | S7_G)
+#define C7_I    (S7_B | S7_C)
+#define C7_J    (S7_B | S7_C | S7_D | S7_E)
+#define C7_K    (S7_B | S7_C | S7_E | S7_F | S7_G)
+#define C7_L    (S7_D | S7_E | S7_F)
+#define C7_M    (S7_A | S7_C | S7_E)
+#define C7_N    (S7_A | S7_B | S7_C | S7_E | S7_F)
+#define C7_O    (S7_A | S7_B | S7_C | S7_D | S7_E | S7_F)
+#define C7_P    (S7_A | S7_B | S7_E | S7_F | S7_G)
+#define C7_Q    (S7_A | S7_B | S7_C | S7_F | S7_G)
+#define C7_R    (S7_E | S7_G )
+#define C7_S    (S7_A | S7_C | S7_D | S7_F | S7_G)
+#define C7_T    (S7_D | S7_E | S7_F | S7_G)
+#define C7_U    (S7_B | S7_C | S7_D | S7_E | S7_F)
+#define C7_V    (S7_B | S7_C | S7_D | S7_E | S7_F)
+#define C7_W    (S7_B | S7_D | S7_F)
+#define C7_X    (S7_B | S7_C | S7_E | S7_F | S7_G)
+#define C7_Y    (S7_B | S7_C | S7_D | S7_F | S7_G)
+#define C7_Z    (S7_A | S7_B | S7_D | S7_E | S7_G)
+
+//91 0x5B
+#define C7_SBL  (S7_A | S7_D | S7_E | S7_F) // [
+#define C7_LS   (S7_C | S7_F | S7_G)        // left slash
+#define C7_SBR  (S7_A | S7_B | S7_C | S7_D) // ]
+#define C7_PWR  (S7_A | S7_B | S7_F)        // ^
+#define C7_UDS  (S7_D)                      // _
+#define C7_DSH  (S7_F)                      // `  
+
+//97 0x61  Lower case alphabet
+#define C7_a     C7_A
+#define C7_b     C7_B
+#define C7_c     C7_C
+#define C7_d     C7_D
+#define C7_e     C7_E
+#define C7_f     C7_H
+
+#define C7_g     C7_G
+#define C7_h     C7_H
+#define C7_i     C7_I
+#define C7_j     C7_J
+#define C7_k     C7_K
+#define C7_l     C7_L
+#define C7_m     C7_M
+//#define C7_n     C7_N
+#define C7_n    (S7_C | S7_E | S7_G)
+//#define C7_o     C7_O
+#define C7_o    (S7_C | S7_D | S7_E | S7_G)
+#define C7_p     C7_P
+#define C7_q     C7_Q
+//#define C7_r     C7_R
+#define C7_r    (S7_E | S7_G)
+#define C7_s     C7_S
+#define C7_t     C7_T
+#define C7_u     C7_U
+#define C7_v     C7_V
+#define C7_w     C7_W
+#define C7_x     C7_X
+#define C7_y     C7_Y
+#define C7_z     C7_Z
+
+//123 0x7B
+#define C7_CBL  (S7_A | S7_D | S7_E | S7_F)        // {
+#define C7_OR   (S7_B | S7_C)                      // |
+#define C7_CBR  (S7_A | S7_B | S7_C | S7_D)        // }
+#define C7_TLD  (S7_B | S7_E | S7_G )              // ~
+#define C7_DEL  (0x0000)
+
+
+//User Defined Characters (some examples)
+#define C7_DGR   (S7_A | S7_B | S7_F | S7_G)  //Degrees
+                                                                         
+// Font data selection for transmission to TM1637 memory
+#define LO(x)  ( x & 0xFF)
+#define HI(x)  ((x >> 8) & 0xFF)
+
+
+// ASCII Font definition table
+//
+#define FONT_7S_START     0x20
+#define FONT_7S_END       0x7F
+//#define FONT_7S_NR_CHARS (FONT_7S_END - FONT_7S_START + 1)
+extern const char FONT_7S[]; 
+
+#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STLED316S.cpp	Sat Oct 01 15:09:51 2016 +0000
@@ -0,0 +1,666 @@
+/* mbed STLED316S Library, for STLED316S LED controller
+ * Copyright (c) 2016, 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 "STLED316S.h"
+#include "Font_7Seg.h"
+
+/** Constructor for class for driving STLED316S LED controller with SPI bus interface device. 
+ *  @brief Supports 1..6 digits @ 8 segments and 8 LEDs. 
+ *         Also supports a scanned keyboard of upto 16 keys.
+ *   
+ *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+ *  @param  Mode selects 1..6 Digits of 8 Segments (default 6 Digits of 8 Segments) 
+*/
+STLED316S::STLED316S(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode) : _spi(mosi,miso,sclk), _cs(cs), _mode(mode) {
+
+  _init();
+}
+
+/** Init the SPI interface and the controller
+  * @param  none
+  * @return none
+  */ 
+void STLED316S::_init(){
+  char config;  
+
+//init SPI
+  _cs=1;
+  _spi.format(8,3); //STLED316S uses mode 3 (Clock High on Idle, Data latched on second (=rising) edge)
+  _spi.frequency(500000);   
+
+//init controller  
+  _brt_mode = GlobalBright; //STLED316S_BRT_GLOB;
+//  _brt_mode = IndivBright;  //STLED316S_BRT_INDIV;  
+  _bright   = STLED316S_BRT_DEF; 
+
+  config = ((_mode << STLED316S_CONF_GRID_SHFT) & STLED316S_CONF_GRID_MSK) | 
+           ((_brt_mode << STLED316S_CONF_BRT_MODE_SHFT) & STLED316S_CONF_BRT_MODE_MSK) |
+           ((_bright << STLED316S_CONF_BRT_GLOB_SHFT) & STLED316S_CONF_BRT_GLOB_MSK);
+            
+  _writeReg(STLED316S_IDX(STLED316S_CONF_PAGE,STLED316S_CONF_ADDR), config);    // Config set command 
+//  printf("Cmd= 0x%02X, Conf= 0x%02X\r\n", STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_CONF_PAGE,STLED316S_CONF_ADDR), config); // Debug   
+   
+  _writeReg(STLED316S_IDX(STLED316S_DSP_PAGE,STLED316S_DSP_ON_ADDR));           // Display On command      
+}   
+
+                          
+/** Clear the screen and locate to 0
+ */  
+void STLED316S::cls() {
+  
+  _cs=0;
+  wait_us(1);    
+  _spi.write(_flip(STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_DIG_PAGE,STLED316S_DIG2_ADDR))); // Address set cmd, 0
+      
+  for (int cnt=0; cnt<STLED316S_DISPLAY_MEM; cnt++) {
+    _spi.write(0x00); // data 
+  }
+  
+  wait_us(1);
+  _cs=1;      
+}  
+
+/** Set Brightness for all Digits and LEDs (value is used in GlobalBright mode)
+  *
+  * @param  char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)  
+  * @return none
+  */ 
+void STLED316S::setBrightness(char brightness){
+  char config;
+  
+  _bright = brightness & STLED316S_BRT_MSK; // mask invalid bits
+  
+  config = ((_mode << STLED316S_CONF_GRID_SHFT) & STLED316S_CONF_GRID_MSK) | 
+           ((_brt_mode << STLED316S_CONF_BRT_MODE_SHFT) & STLED316S_CONF_BRT_MODE_MSK) |
+           ((_bright << STLED316S_CONF_BRT_GLOB_SHFT) & STLED316S_CONF_BRT_GLOB_MSK);
+            
+  _writeReg(STLED316S_IDX(STLED316S_CONF_PAGE,STLED316S_CONF_ADDR), config);    // Config set command 
+//  printf("Cmd= 0x%02X, Conf= 0x%02X\r\n", STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_CONF_PAGE,STLED316S_CONF_ADDR), config); // Debug   
+}
+
+
+/** Set Individual LED Brightness (value is used in IndivBright mode)
+  *
+  * @param  LedData_t leds pattern of LED data
+  * @param  char led_brt (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)  
+  * @return none
+  */
+void STLED316S::setLedBrightness(LedData_t leds, char led_brt) {
+  char brt_old;
+  
+  //Sanity check
+  led_brt &= STLED316S_BRT_MSK;  
+  
+  if (leds & STLED316S_LED_L1) { // LED_1
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED1_2_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED1_2_BRT_ADDR), (brt_old & 0xF0) | led_brt);         // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L2) { // LED_2
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED1_2_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED1_2_BRT_ADDR), (brt_old & 0x0F) | (led_brt << 4));  // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L3) { // LED_3
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED3_4_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED3_4_BRT_ADDR), (brt_old & 0xF0) | led_brt);         // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L4) { // LED_4
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED3_4_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED3_4_BRT_ADDR), (brt_old & 0x0F) | (led_brt << 4));  // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L5) { // LED_5
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED5_6_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED5_6_BRT_ADDR), (brt_old & 0xF0) | led_brt);         // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L6) { // LED_6
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED5_6_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED5_6_BRT_ADDR), (brt_old & 0x0F) | (led_brt << 4));  // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L7) { // LED_7
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED7_8_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED7_8_BRT_ADDR), (brt_old & 0xF0) | led_brt);         // LED Brt set command 
+  }
+
+  if (leds & STLED316S_LED_L8) { // LED_8
+    brt_old = _readReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED7_8_BRT_ADDR));                            // LED Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_LED_BRT_PAGE,STLED316S_LED7_8_BRT_ADDR), (brt_old & 0x0F) | (led_brt << 4));  // LED Brt set command 
+  }
+}
+
+
+/** Set Individual Digit Brightness (value is used in IndivBright mode)
+  *
+  * @param  LedData_t digits pattern of Digit data
+  * @param  char dig_brt (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)  
+  * @return none
+  */
+void STLED316S::setDigitBrightness(LedData_t digits, char dig_brt) {
+  char brt_old;
+  
+  //Sanity check
+  dig_brt &= STLED316S_BRT_MSK;  
+
+  if (digits & STLED316S_DIG_D2) { // DIGIT_2
+    brt_old = _readReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG2_3_BRT_ADDR));                            // Digit Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG2_3_BRT_ADDR), (brt_old & 0xF0) | dig_brt);         // Digit Brt set command 
+  }
+
+  if (digits & STLED316S_DIG_D3) { // DIGIT_3
+    brt_old = _readReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG2_3_BRT_ADDR));                            // Digit Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG2_3_BRT_ADDR), (brt_old & 0x0F) | (dig_brt << 4));  // Digit Brt set command 
+  }
+
+  if (digits & STLED316S_DIG_D4) { // DIGIT_4
+    brt_old = _readReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG4_5_BRT_ADDR));                            // Digit Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG4_5_BRT_ADDR), (brt_old & 0xF0) | dig_brt);         // Digit Brt set command 
+  }
+
+  if (digits & STLED316S_DIG_D5) { // DIGIT_5
+    brt_old = _readReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG4_5_BRT_ADDR));                            // Digit Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG4_5_BRT_ADDR), (brt_old & 0x0F) | (dig_brt << 4));  // Digit Brt set command 
+  }
+
+  if (digits & STLED316S_DIG_D6) { // DIGIT_6
+    brt_old = _readReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG6_7_BRT_ADDR));                            // Digit Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG6_7_BRT_ADDR), (brt_old & 0xF0) | dig_brt);         // Digit Brt set command 
+  }
+
+  if (digits & STLED316S_DIG_D7) { // DIGIT_7
+    brt_old = _readReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG6_7_BRT_ADDR));                            // Digit Brt read command 
+    _writeReg(STLED316S_IDX(STLED316S_DIG_BRT_PAGE,STLED316S_DIG6_7_BRT_ADDR), (brt_old & 0x0F) | (dig_brt << 4));  // Digit Brt set command 
+  }
+}
+
+
+/** Set the Display mode On/off
+  *
+  * @param bool display mode
+  */
+void STLED316S::setDisplay(bool on) {
+  
+  if (on) {
+    _writeReg(STLED316S_IDX(STLED316S_DSP_PAGE,STLED316S_DSP_ON_ADDR));  // Display On command       
+  }
+  else {
+   _writeReg(STLED316S_IDX(STLED316S_DSP_PAGE,STLED316S_DSP_OFF_ADDR));  // Display Off command          
+  }
+}
+
+/** Set Brightness mode 
+  *
+  * @param  BrightMode brt_mode (value is IndivBright or GlobalBright)  
+  * @return none
+  */
+void STLED316S::setBrightMode(BrightMode brt_mode) {
+  char config;
+  
+  _brt_mode = brt_mode; // mask invalid bits
+  
+  config = ((_mode << STLED316S_CONF_GRID_SHFT) & STLED316S_CONF_GRID_MSK) | 
+           ((_brt_mode << STLED316S_CONF_BRT_MODE_SHFT) & STLED316S_CONF_BRT_MODE_MSK) |
+           ((_bright << STLED316S_CONF_BRT_GLOB_SHFT) & STLED316S_CONF_BRT_GLOB_MSK);
+            
+  _writeReg(STLED316S_IDX(STLED316S_CONF_PAGE,STLED316S_CONF_ADDR), config);    // Config set command 
+//  printf("Cmd= 0x%02X, Conf= 0x%02X\r\n", STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_CONF_PAGE,STLED316S_CONF_ADDR), config); // Debug   
+}
+
+
+/** Write databyte to STLED316S
+  *  @param  int address display memory location to write byte
+  *  @param  char data byte written at given address
+  *  @return none
+  */ 
+void STLED316S::writeData(int address, char data) {
+  _cs=0;
+  wait_us(1);    
+
+  _spi.write(_flip(STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_DIG_PAGE, address))); // Address set cmd
+  _spi.write(_flip(data)); // data 
+      
+  wait_us(1);
+  _cs=1;             
+}
+
+/** Write Display datablock to STLED316S
+  *  @param  DisplayData_t data Array of STLED316S_DISPLAY_MEM (=6) bytes for displaydata (starting at address 0)
+  *  @param  length number bytes to write (valide range 0..STLED316S_DISPLAY_MEM (=6), starting at address 0)     
+  *  @return none
+  */ 
+void STLED316S::writeData(DisplayData_t data, int length) {
+  _cs=0;
+  wait_us(1);    
+
+  _spi.write(_flip(STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_DIG_PAGE, 0x00))); // Set Address at 0
+
+//  printf("Cmd= 0x%02X\r\n", STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_DIG_PAGE, 0x00)); // Debug   
+      
+// sanity check
+  if (length < 0) {length = 0;}
+  if (length > STLED316S_DISPLAY_MEM) {length = STLED316S_DISPLAY_MEM;}
+
+//  for (int idx=0; idx<STLED316S_DISPLAY_MEM; idx++) {  
+  for (int idx=0; idx<length; idx++) {    
+    _spi.write(_flip(data[idx])); // data 
+
+//    printf("Data= 0x%02X\r\n", data[idx]); // Debug       
+  }
+  
+  wait_us(1);
+  _cs=1;             
+}
+
+
+/** Write LED data to STLED316S
+  *  @param  LedData_t leds LED data
+  *  @return none
+  */   
+void STLED316S::writeLedData(LedData_t leds) {
+  _cs=0;
+  wait_us(1);    
+
+  _leds = leds;
+  
+  _spi.write(_flip(STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_DIG1_LED_PAGE, STLED316S_DIG1_LED_ADDR))); // Set Address
+//  printf("Cmd= 0x%02Xr\n", STLED316S_ADDR_WR_CMD | STLED316S_IDX(STLED316S_DIG1_LED_PAGE, STLED316S_DIG1_LED_ADDR)); // Debug          
+
+  _spi.write(_flip(leds)); // data 
+//  printf("Data 0x%02X\r\n", leds); // Debug       
+  
+  wait_us(1);
+  _cs=1;             
+}
+
+
+/** Set LED
+  *
+  * @param LedData_t leds pattern of LED data
+  * @return none
+  */
+void STLED316S::setLed(LedData_t leds){
+
+  _leds |= leds;
+  writeLedData(_leds);  
+}
+
+/** Clr LED
+  *
+  * @param LedData_t leds pattern of LED data  
+  * @return none
+  */
+void STLED316S::clrLed(LedData_t leds){
+  _leds &= ~leds;
+  writeLedData(_leds);  
+}
+
+/** Read keydata block from STLED316S
+  *  @param  *keydata Ptr to Array of STLED316S_KEY_MEM (=5) bytes for keydata
+  *  @return bool keypress True when at least one key was pressed
+  *
+  * Note: Due to the hardware configuration the STLED316S key matrix scanner will detect multiple keys pressed at same time,
+  *       but this may also result in some spurious keys being set in keypress data array.
+  *       It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting.  
+  */ 
+bool STLED316S::getKeys(KeyData_t *keydata) {
+  int keypress = 0;
+  char data;
+
+  // Read keys
+  _cs=0;
+  wait_us(1);    
+  
+  // Enable Key Read mode
+  _spi.write(_flip(STLED316S_ADDR_RD_CMD | STLED316S_IDX(STLED316S_KEY_PAGE, STLED316S_KEY1_ADDR))); // Set Address
+//  printf("Cmd= 0x%02Xr\n", STLED316S_ADDR_RD_CMD | STLED316S_IDX(STLED316S_KEY_PAGE, STLED316S_KEY1_ADDR)); // Debug          
+
+  for (int idx=0; idx < STLED316S_KEY_MEM; idx++) {
+    data = _flip(_spi.write(0xFF));    // read keys and correct bitorder
+//    printf("KeyData 0x%02X\r\n", data); // Debug       
+
+    data = data & STLED316S_KEY_MSK; // Mask valid bits
+    if (data != 0) {  // Check for any pressed key
+      for (int bit=0; bit < 8; bit++) {
+        if (data & (1 << bit)) {keypress++;} // Test all significant bits
+      }
+    }  
+
+    (*keydata)[idx] = data;            // Store keydata after correcting bitorder
+  }
+
+  wait_us(1);
+  _cs=1;    
+     
+#if(1)
+// Dismiss multiple keypresses at same time
+  return (keypress == 1);    
+#else
+// Allow multiple keypress and accept possible spurious keys
+  return (keypress > 0);
+#endif  
+}
+    
+
+/** Helper to reverse all command or databits. The STLED316S expects LSB first, whereas SPI is MSB first
+  *  @param  char data
+  *  @return bitreversed data
+  */ 
+char STLED316S::_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;       
+}
+
+
+/** Write parameter to STLED316S Register
+  *  @param  int idx Register address
+  *  @Param  int data Parameter for Register
+  *  @return none
+  */  
+void STLED316S::_writeReg(int idx, int data){
+    
+  _cs=0;
+  wait_us(1);    
+ 
+  _spi.write(_flip(STLED316S_ADDR_WR_CMD | (idx & STLED316S_IDX_MSK)));
+  _spi.write(_flip(data) );
+
+//  printf("Cmd= 0x%02X, Write= 0x%02X\r\n", STLED316S_ADDR_WR_CMD | (idx & STLED316S_IDX_MSK), data); // Debug        
+       
+  wait_us(1);
+  _cs=1;          
+}  
+
+
+/** Write merged command and parameter to STLED316S
+  *  @param  int cmd Command & Parameter byte
+  *  @return none
+  */  
+void STLED316S::_writeReg(int cmd){
+    
+  _cs=0;
+  wait_us(1);    
+  _spi.write(_flip(STLED316S_ADDR_WR_CMD | (cmd & STLED316S_IDX_MSK)));
+
+//  printf("Cmd= 0x%02X\r\n", STLED316S_ADDR_WR_CMD | (cmd & STLED316S_IDX_MSK)); // Debug        
+
+  wait_us(1);
+  _cs=1;          
+}  
+
+
+/** Read parameter from STLED316S Register
+  *  @param  int idx Register address
+  *  @return char data from Register
+  */ 
+char STLED316S::_readReg(int idx){
+  char data;
+
+  _cs=0;
+  wait_us(1);    
+  _spi.write(_flip(STLED316S_ADDR_RD_CMD | (idx & STLED316S_IDX_MSK)));
+
+  data = _flip(_spi.write(0xFF));    // read data and correct bitorder
+
+//  printf("Cmd= 0x%02X, Read= 0x%02X\r\n", STLED316S_ADDR_RD_CMD | (idx & STLED316S_IDX_MSK), data); // Debug        
+
+  wait_us(1);
+  _cs=1;          
+ 
+  return data;
+}        
+
+
+
+#if(ST316BOARD_TEST == 1)
+// Derived class for STLED316S used in test display module
+//
+//#include "Font_7Seg.h"
+
+/** Constructor for class for driving STM STLED316S controller as used in ST316S test display
+  *
+  *  @brief Supports 6 Digits of 7 Segments and 3 LEDs. Also supports a scanned keyboard of 3.
+  *   
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */
+STLED316S_BOARD::STLED316S_BOARD(PinName mosi, PinName miso, PinName sclk, PinName cs) : STLED316S(mosi, miso, sclk, cs, Grid6_Seg8) {
+  _column  = 0;
+  _columns = ST316BOARD_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 STLED316S_BOARD::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 STLED316S_BOARD::columns() {
+    return _columns;
+}
+
+
+/** Clear the screen and locate to 0
+  * @param bool clrAll Clear Icons also (default = false)
+  */ 
+void STLED316S_BOARD::cls(bool clrAll) {  
+
+  if (clrAll) {
+    //clear local buffer for LEDs/Icons 
+    setLed(0x00);    
+  }  
+
+  //clear local buffer for digits
+  for (int idx=0; idx < (ST316BOARD_NR_GRIDS * STLED316S_BYTES_PER_GRID); idx++) {
+    _displaybuffer[idx] = 0x00;  
+  }
+  writeData(_displaybuffer, (ST316BOARD_NR_GRIDS * STLED316S_BYTES_PER_GRID));
+
+  _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 STLED316S_BOARD::setIcon(Icon icon) {
+//  int addr;
+  int icn;
+
+   icn =        icon  & 0xFF;
+//  addr = (icon >> 24) & 0xFF; 
+
+  setLed(icn);
+}
+
+/** Clr Icon
+  *
+  * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+  * @return none
+  */
+void STLED316S_BOARD::clrIcon(Icon icon) {
+//  int addr;
+  int icn;
+
+   icn =        icon  & 0xFF;
+//  addr = (icon >> 24) & 0xFF; 
+
+  clrLed(icn);
+}
+
+
+/** 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 STLED316S_BOARD::setUDC(unsigned char udc_idx, int udc_data) {
+
+  //Sanity check
+  if (udc_idx > (ST316BOARD_NR_UDC-1)) {
+    return;
+  }
+  // Mask out Icon bits?
+
+  _UDC_7S[udc_idx] = udc_data;
+}
+
+
+/** Write a single character (Stream implementation)
+  */
+int STLED316S_BOARD::_putc(int value) {
+
+    int addr;
+    bool validChar = false;
+    char pattern  = 0x00;
+
+    if ((value == '\n') || (value == '\r')) {
+      //No character to write
+      validChar = false;
+      
+      //Update Cursor      
+      _column = 0;
+    }
+    else if ((value == '.') || (value == ',')) {
+      //No character to write
+      validChar = false;
+      pattern = S7_DP; // placeholder for all DPs
+      
+      // Check to see that DP can be shown for current column
+      if (_column > 0) {
+        //Translate between _column and displaybuffer entries
+        //Add DP to bitpattern of digit left of current column.
+        addr = (_column - 1);
+      
+        //Set bits for decimal point to write
+        _displaybuffer[addr] = _displaybuffer[addr] | pattern;
+        writeData(_displaybuffer, (ST316BOARD_NR_GRIDS * STLED316S_BYTES_PER_GRID));        
+        
+        //No Cursor Update
+      }
+    }
+    else if ((value >= 0) && (value < ST316BOARD_NR_UDC)) {
+      //Character to write
+      validChar = true;
+      pattern = _UDC_7S[value];
+    }  
+    
+#if (SHOW_ASCII == 1)
+    //display all ASCII characters
+    else if ((value >= FONT_7S_START) && (value <= FONT_7S_END)) {   
+      //Character to write
+      validChar = true;
+      pattern = FONT_7S[value - FONT_7S_START];
+    } // else
+#else    
+    //display only digits and hex characters      
+    else if (value == '-') {
+      //Character to write
+      validChar = true;
+      pattern = C7_MIN;         
+    }
+    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
+#endif
+
+    if (validChar) {
+      //Character to write
+ 
+      //Translate between _column and displaybuffer entries
+      //_column == 0 => Grid0 => addr = 0
+      //
+      //_column == 5 => Grid5 => addr = 5            
+      addr = _column;
+      _displaybuffer[addr]   = pattern;
+
+      writeData(_displaybuffer, (ST316BOARD_NR_GRIDS * STLED316S_BYTES_PER_GRID));
+                                
+      //Update Cursor
+      _column++;
+      if (_column > (ST316BOARD_NR_DIGITS - 1)) {
+        _column = 0;
+      }
+
+    } // if validChar           
+
+    return value;
+}
+
+// get a single character (Stream implementation)
+int STLED316S_BOARD::_getc() {
+    return -1;
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STLED316S.h	Sat Oct 01 15:09:51 2016 +0000
@@ -0,0 +1,495 @@
+/* mbed STLED316S Library, for STLED316S LED controller
+ * Copyright (c) 2016, 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 STLED316S_H
+#define STLED316S_H
+
+// Select one of the testboards for the STM STLED316S LED controller
+#include "STLED316S_Config.h"
+
+#include "Font_7Seg.h"
+
+/** An interface for driving STLED316S LED controller
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "STLED316S.h" 
+ * 
+ * DisplayData_t size is  8 bytes (4 grids @ 13 segments) OR 10 bytes (5 grids @ 12 segments) OR
+ *                       12 bytes (6 grids @ 11 segments) OR 14 bytes (7 grids @ 10 segments) 
+ * STLED316S::DisplayData_t mbed_str = {0xDA,0x00, 0x7C,0x00, 0x3C,0x01, 0xF6,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
+ * STLED316S::DisplayData_t all_str  = {0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F};  
+ *
+ * // KeyData_t size is 5 bytes  
+ * STLED316S::KeyData_t keydata; 
+ *
+ * // STLED316S declaration, Default setting 7 Grids @ 10 Segments
+ * STLED316S STLED316S(p5,p6,p7, p8);
+ *
+ * int main() {
+ *   STLED316S.cls(); 
+ *   STLED316S.writeData(all_str);
+ *   wait(4);
+ *   STLED316S.writeData(mbed_str);    
+ *   wait(1);
+ *   STLED316S.setBrightness(STLED316S_BRT0);
+ *   wait(1);
+ *   STLED316S.setBrightness(STLED316S_BRT3);
+ *
+ *   while (1) {
+ *    // Check and read keydata
+ *    if (STLED316S.getKeys(&keydata)) {
+ *      pc.printf("Keydata 0..4 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4]);
+ *
+ *      if (keydata[0] == 0x10) { //sw2   
+ *        STLED316S.cls(); 
+ *        STLED316S.writeData(all_str);
+ *      }  
+ *    } 
+ *   }   
+ * }
+ * @endcode
+ */
+
+//STLED316S Display and Keymatrix data
+#define STLED316S_MAX_NR_GRIDS    6
+#define STLED316S_BYTES_PER_GRID  1
+//Significant bits Keymatrix data
+#define STLED316S_KEY_MSK      0xFF 
+
+//Memory size in bytes for Display and Keymatrix
+#define STLED316S_DISPLAY_MEM  (STLED316S_MAX_NR_GRIDS * STLED316S_BYTES_PER_GRID)
+#define STLED316S_KEY_MEM         2
+
+//Address set commands
+#define STLED316S_CMD_MSK      0x7F
+#define STLED316S_DATA_WR      0x00
+#define STLED316S_DATA_RD      0x40
+#define STLED316S_ADDR_INC     0x00
+#define STLED316S_ADDR_FIXED   0x20
+#define STLED316S_PAGE_MSK     0x18
+#define STLED316S_PAGE_SHFT       3
+#define STLED316S_ADDR_MSK     0x07
+#define STLED316S_ADDR_SHFT       0
+#define STLED316S_IDX_MSK      (STLED316S_PAGE_MSK | STLED316S_ADDR_MSK)
+
+//Read and Write commands
+#define STLED316S_ADDR_WR_CMD  (STLED316S_DATA_WR | STLED316S_ADDR_INC) 
+#define STLED316S_ADDR_RD_CMD  (STLED316S_DATA_RD | STLED316S_ADDR_INC) 
+
+//Combined Page and Address parameters
+#define STLED316S_IDX(page, addr) ( ((page << STLED316S_PAGE_SHFT) & STLED316S_PAGE_MSK) | ((addr << STLED316S_ADDR_SHFT) & STLED316S_ADDR_MSK) )   
+
+
+//Digit Data address (Digit2..Digit7)
+#define STLED316S_DIG_PAGE        0
+#define STLED316S_DIG2_ADDR    0x00
+#define STLED316S_DIG3_ADDR    0x01
+#define STLED316S_DIG4_ADDR    0x02
+#define STLED316S_DIG5_ADDR    0x03
+#define STLED316S_DIG6_ADDR    0x04
+#define STLED316S_DIG7_ADDR    0x05
+
+//LED Data address (also Digit1 Data address)
+#define STLED316S_DIG1_LED_PAGE         1
+#define STLED316S_DIG1_LED_ADDR      0x00
+
+//LED Data used to select individual LEDs
+#define STLED316S_LED_L1       0x01
+#define STLED316S_LED_L2       0x02
+#define STLED316S_LED_L3       0x04
+#define STLED316S_LED_L4       0x08
+#define STLED316S_LED_L5       0x10
+#define STLED316S_LED_L6       0x20
+#define STLED316S_LED_L7       0x40
+#define STLED316S_LED_L8       0x80
+#define STLED316S_LED_ALL      0xFF
+
+//Digit Data used to select individual digits
+//#define STLED316S_DIG_D1       0x01
+#define STLED316S_DIG_D2       0x02
+#define STLED316S_DIG_D3       0x04
+#define STLED316S_DIG_D4       0x08
+#define STLED316S_DIG_D5       0x10
+#define STLED316S_DIG_D6       0x20
+#define STLED316S_DIG_D7       0x40
+#define STLED316S_DIG_ALL      0x7E
+
+
+//Key Data address
+#define STLED316S_KEY_PAGE        1
+#define STLED316S_KEY1_ADDR    0x01
+#define STLED316S_KEY2_ADDR    0x02
+
+//Display On_Off address
+#define STLED316S_DSP_PAGE        1
+#define STLED316S_DSP_ON_ADDR  0x05
+#define STLED316S_DSP_OFF_ADDR 0x06
+
+//Config set address
+#define STLED316S_CONF_PAGE             2
+#define STLED316S_CONF_ADDR          0x00
+
+//Config parameters
+#define STLED316S_CONF_GRID_MSK      0x07
+#define STLED316S_CONF_GRID_SHFT        0
+#define STLED316S_CONF_BRT_MODE_MSK  0x18
+#define STLED316S_CONF_BRT_MODE_SHFT    3
+#define STLED316S_CONF_BRT_GLOB_MSK  0xE0
+#define STLED316S_CONF_BRT_GLOB_SHFT    5
+
+//Grid Config parameters
+#define STLED316S_GR1_SEG8     0x00
+#define STLED316S_GR2_SEG8     0x01
+#define STLED316S_GR3_SEG8     0x02
+#define STLED316S_GR4_SEG8     0x03 //default
+#define STLED316S_GR5_SEG8     0x04
+#define STLED316S_GR6_SEG8     0x05
+
+//Brightness Mode Config parameters
+#define STLED316S_BRT_INDIV    0x00
+#define STLED316S_BRT_GLOB     0x03 //default
+
+//Digit Brightness address (used when Brightness mode is set as 'individual')
+#define STLED316S_DIG_BRT_PAGE          2
+#define STLED316S_DIG2_3_BRT_ADDR    0x01
+#define STLED316S_DIG4_5_BRT_ADDR    0x02
+#define STLED316S_DIG6_7_BRT_ADDR    0x03
+
+//LED Brightness address (used when Brightness mode is set as 'individual')
+#define STLED316S_LED_BRT_PAGE          3
+#define STLED316S_LED1_2_BRT_ADDR    0x00
+#define STLED316S_LED3_4_BRT_ADDR    0x01
+#define STLED316S_LED5_6_BRT_ADDR    0x02
+#define STLED316S_LED7_8_BRT_ADDR    0x03
+
+//Brightness control parameters (used for both Brightness modes 'global' and 'individual')
+#define STLED316S_BRT_MSK      0x07
+
+#define STLED316S_BRT0         0x00 //Pulsewidth 1/16
+#define STLED316S_BRT1         0x01
+#define STLED316S_BRT2         0x02
+#define STLED316S_BRT3         0x03
+#define STLED316S_BRT4         0x04
+#define STLED316S_BRT5         0x05
+#define STLED316S_BRT6         0x06
+#define STLED316S_BRT7         0x07 //Pulsewidth 14/16 (default)
+
+#define STLED316S_BRT_DEF      STLED316S_BRT3
+
+
+
+/** A class for driving STM STLED316S LED controller
+ *
+ * @brief Supports 1..6 Grids @ 8 Segments and 8 LEDs. 
+ *        Also supports a scanned keyboard of upto 16 keys.
+ *        SPI bus interface device. 
+ */
+class STLED316S {
+ public:
+
+  /** Enums for Display mode */
+  enum Mode {
+    Grid1_Seg8 = STLED316S_GR1_SEG8,
+    Grid2_Seg8 = STLED316S_GR2_SEG8,   
+    Grid3_Seg8 = STLED316S_GR3_SEG8,
+    Grid4_Seg8 = STLED316S_GR4_SEG8,
+    Grid5_Seg8 = STLED316S_GR5_SEG8,
+    Grid6_Seg8 = STLED316S_GR6_SEG8   
+  };
+  
+  /** Enums for Brightness mode */
+  enum BrightMode {
+    IndivBright  = STLED316S_BRT_INDIV,
+    GlobalBright = STLED316S_BRT_GLOB      
+  };
+
+  /** Datatypes for display and keymatrix data */
+  typedef char DisplayData_t[STLED316S_DISPLAY_MEM];
+  typedef char LedData_t;  
+  typedef char KeyData_t[STLED316S_KEY_MEM];
+    
+ /** Constructor for class for driving STLED316S LED controller
+  *
+  * @brief Supports 1..6 Grids @ 8 Segments and 8 LEDs. 
+  *        Also supports a scanned keyboard of upto 16 keys.
+  *        SPI bus interface device. 
+  *
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  *  @param  Mode selects either Grids/Segments (default 6 Grids @ 8 Segments)
+  */
+  STLED316S(PinName mosi, PinName miso, PinName sclk, PinName cs, Mode mode=Grid6_Seg8);
+      
+  /** Clear the screen and locate to 0
+   */ 
+  void cls();  
+
+  /** Write databyte to STLED316S
+   *  @param  int address display memory location to write byte
+   *  @param  char data byte written at given address
+   *  @return none
+   */ 
+  void writeData(int address, char data); 
+ 
+ /** Write Display datablock to STLED316S
+   *  @param  DisplayData_t data Array of STLED316S_DISPLAY_MEM (=6) bytes for displaydata (starting at address 0)
+   *  @param  length number bytes to write (valid range 0..STLED316S_DISPLAY_MEM (=6), starting at address 0)   
+   *  @return none
+   */   
+  void writeData(DisplayData_t data, int length = STLED316S_DISPLAY_MEM);
+
+ /** Write LED data to STLED316S
+   *  @param  LedData_t leds LED data   
+   *  @return none
+   */   
+  void writeLedData(LedData_t leds);
+
+  /** Set LED
+    *
+    * @param LedData_t leds pattern of LED data      
+    * @return none
+    */
+  void setLed(LedData_t leds);
+
+  /** Clr LED
+    *
+    * @param LedData_t leds pattern of LED data      
+    * @return none
+    */
+  void clrLed(LedData_t leds);
+
+
+  /** Read keydata block from STLED316S
+   *  @param  *keydata Ptr to Array of STLED316S_KEY_MEM (=2) bytes for keydata
+   *  @return bool keypress True when at least one key was pressed
+   *
+   * Note: Due to the hardware configuration the STLED316S key matrix scanner will detect multiple keys pressed at same time,
+   *       but this may result in some spurious keys also being set in keypress data array.
+   *       It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting.
+   */   
+  bool getKeys(KeyData_t *keydata);
+
+  /** Set Brightness for all Digits and LEDs (value is used in GlobalBrightness mode)
+    *
+    * @param  char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)  
+    * @return none
+    */
+  void setBrightness(char brightness = STLED316S_BRT_DEF);
+
+  /** Set Individual LED Brightness (value is used in IndivBright mode)
+    *
+    * @param  LedData_t leds pattern of LED data          
+    * @param  char led_brt (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)  
+    * @return none
+    */
+  void setLedBrightness(LedData_t leds = STLED316S_LED_ALL, char led_brt = STLED316S_BRT_DEF);
+  
+  /** Set Individual Digit Brightness (value is used in IndivBright mode)
+    *
+    * @param  LedData_t digits pattern of Digit data
+    * @param  char dig_brt (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle)  
+    * @return none
+    */    
+  void setDigitBrightness(LedData_t digits = STLED316S_DIG_ALL, char dig_brt = STLED316S_BRT_DEF);
+
+  /** Set Brightness mode 
+    *
+    * @param  BrightMode brt_mode (value is IndivBright or GlobalBright)  
+    * @return none
+    */
+  void setBrightMode(BrightMode brt_mode = GlobalBright);
+
+
+  /** Set the Display mode On/off
+    *
+    * @param bool display mode
+    */
+  void setDisplay(bool on);
+  
+ private:  
+  SPI _spi;
+  DigitalOut _cs;
+  Mode _mode;
+  BrightMode _brt_mode;
+  char _bright;
+  LedData_t _leds;
+  
+  /** Init the SPI interface and the controller
+    * @param  none
+    * @return none
+    */ 
+  void _init();
+
+  /** Helper to reverse all command or databits. The STLED316S expects LSB first, whereas SPI is MSB first
+    *  @param  char data
+    *  @return bitreversed data
+    */ 
+  char _flip(char data);
+
+  /** Write parameter to STLED316S Register
+    *  @param  int idx Register address
+    *  @param  int data Parameter for Register
+    *  @return none
+    */ 
+  void _writeReg(int idx, int data);  
+  
+/** Write merged command and parameter to STLED316S
+  *  @param  int cmd Command & Parameter byte
+  *  @return none
+  */  
+  void _writeReg(int cmd);
+
+  /** Read parameter from STLED316S Register
+    *  @param  int idx Register address
+    *  @return char data from Register
+    */ 
+  char _readReg(int idx);    
+};
+
+
+
+#if(ST316BOARD_TEST == 1)
+// Derived class for STLED316S used in test display module
+//
+#include "Font_7Seg.h"
+
+#define ST316BOARD_NR_GRIDS    6
+#define ST316BOARD_NR_DIGITS   6
+//#define ST316BOARD_DIG1_IDX    0
+#define ST316BOARD_NR_UDC      8
+
+/** Constructor for class for driving STM STLED316S controller as used in ST316S test display
+  *
+  *  @brief Supports 6 Digits of 8 Segments, 1 Grid of 3 LEDs. Also supports a scanned keyboard of 3 keys.
+  *  
+  *  @param  PinName mosi, miso, sclk, cs SPI bus pins
+  */
+class STLED316S_BOARD : public STLED316S, public Stream {
+ public:
+
+  /** Enums for LEDs */
+  //  Grid encoded in 8 MSBs, LED pattern encoded in 16 LSBs
+  enum Icon {
+    LD1  = (0<<24) | STLED316S_LED_L1,
+    LD2  = (0<<24) | STLED316S_LED_L2,
+    LD3  = (0<<24) | STLED316S_LED_L3,
+  };
+  
+  typedef short UDCData_t[ST316BOARD_NR_UDC];
+  
+ /** Constructor for class for driving STLED316S controller as used in ST316S test display
+   *
+   * @brief Supports 6 Digits of 8 Segments, 1 Grid of 3 LEDs. Also supports a scanned keyboard of 3 keys.
+   *  
+   * @param  PinName mosi, miso, sclk, cs SPI bus pins
+   */
+  STLED316S_BOARD(PinName mosi, PinName miso, PinName sclk, PinName cs);
+
+#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
+
+     /** Locate cursor to a screen column
+     *
+     * @param column  The horizontal position from the left, indexed from 0
+     */
+    void locate(int column);
+    
+    /** Clear the screen and locate to 0
+     * @param bool clrAll Clear Icons also (default = false)
+     */
+    void cls(bool clrAll = false);   
+
+    /** Set Icon
+     *
+     * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+     * @return none
+     */
+    void setIcon(Icon icon);
+
+    /** Clr Icon
+     *
+     * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
+     * @return none
+     */
+    void clrIcon(Icon icon);
+
+   /** 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 setUDC(unsigned char udc_idx, int udc_data);
+
+
+   /** Number of screen columns
+    *
+    * @param none
+    * @return columns
+    */
+    int columns();   
+
+   /** Write databyte to STLED316S
+     *  @param  int address display memory location to write byte
+     *  @param  char data byte written at given address
+     *  @return none
+     */ 
+    void writeData(int address, char data){
+      STLED316S::writeData(address, data);
+    }        
+
+   /** Write Display datablock to STLED316S
+    *  @param  DisplayData_t data Array of STLED316S_DISPLAY_MEM (=6) bytes for displaydata (starting at address 0)
+    *  @param  length number bytes to write (valid range 0..(ST316BOARD_NR_GRIDS) (=6), starting at address 0)   
+    *  @return none
+    */   
+    void writeData(DisplayData_t data, int length = (ST316BOARD_NR_GRIDS)) {
+      STLED316S::writeData(data, length);
+    }  
+
+protected:  
+    // Stream implementation functions
+    virtual int _putc(int value);
+    virtual int _getc();
+
+private:
+    int _column;
+    int _columns;   
+    
+    DisplayData_t _displaybuffer;
+    UDCData_t _UDC_7S; 
+};
+#endif
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STLED316S_Config.h	Sat Oct 01 15:09:51 2016 +0000
@@ -0,0 +1,33 @@
+/* mbed STLED316S Library, for STLED316S LEDcontroller
+ * Copyright (c) 2016, 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 STLED316S_CONFIG_H
+#define STLED316S_CONFIG_H
+
+// Select one of the testboards for the STM STLED316S LED controller
+#define STLED316S_TEST  0
+#define ST316BOARD_TEST 1 
+
+// Select the display mode: only digits and hex or ASCII
+#define SHOW_ASCII   1 
+
+#endif
\ No newline at end of file