Library for Siemens SDA5708 8 digit LED matrix display. The control interface is SPI.
Revision 1:d8a07b8468f6, committed 2014-09-30
- Comitter:
- wim
- Date:
- Tue Sep 30 17:13:47 2014 +0000
- Parent:
- 0:5265413226e5
- Child:
- 2:966fca76e5aa
- Commit message:
- Added method setMode() to switch display on/off, added support for User Defined Characters (max. 8 UDCs, occupying character codes 0..7).
Changed in this revision
SDA5708.cpp | Show annotated file Show diff for this revision Revisions of this file |
SDA5708.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SDA5708.cpp Mon Sep 29 19:39:18 2014 +0000 +++ b/SDA5708.cpp Tue Sep 30 17:13:47 2014 +0000 @@ -23,6 +23,36 @@ #include "SDA5708.h" #include "font_5x7.h" +// User Defined Characters (UDCs) are defined by a 7 byte bitpattern. The P0..P5 form the character pattern. +// P7 P6 P5 P4 P3 P2 P1 P0 +// 0 B1 B0 x 0 1 1 1 0 +// 1 B1 B0 x 1 0 0 0 1 +// . ............. +// 6 B1 B0 x 1 0 0 0 1 +// + +/** Some sample User Defined Chars 5x7 dots */ +const char udc_0[] = {0x18, 0x14, 0x12, 0x11, 0x12, 0x14, 0x18}; // |> +const char udc_1[] = {0x03, 0x05, 0x09, 0x11, 0x09, 0x05, 0x03}; // <| +const char udc_2[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}; // | +const char udc_3[] = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14}; // || +const char udc_4[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15}; // ||| +const char udc_5[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00}; // = +const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15}; // checkerboard +const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10}; // \ + +const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; // Battery Full +const char udc_Bat_Ha[] = {0x0E, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F}; // Battery Half +const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F}; // Battery Low +const char udc_AC[] = {0x0A, 0x0A, 0x1F, 0x11, 0x0E, 0x04, 0x04}; // AC Power +const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00}; // Smiley + +/** Create an SDA5708 Display object connected to the proper pins + * + * @param *spi SPI port + * @param cs PinName for Chip Select (active low) + * @param rst PinName for Reset (active low) + */ SDA5708::SDA5708(SPI *spi, PinName cs, PinName rst) : _spi(spi), _cs(cs), _rst(rst) { _init(); } @@ -102,6 +132,42 @@ _write(SDA5708_CMD_NORMAL | _peak | _brightness); } +/** Set the Displaymode + * + * @param displayMode The Display mode (DispOff, DispOn) + */ +void SDA5708::setMode(DisplayMode displayMode){ + + if (displayMode == DispOff) { + //Set brightness to Zero + _write(SDA5708_CMD_NORMAL | _peak | SDA5708_BRIGHT_0); + } + else { + //Restore brightness + _write(SDA5708_CMD_NORMAL | _peak | _brightness); + } +} + +/** Set User Defined Characters (UDC) + * + * @param unsigned char c The Index of the UDC (0..7) + * @param char *udc_data The bitpatterns for the UDC (7 bytes of 5 significant bits for bitpattern) + */ +void SDA5708::setUDC(unsigned char c, char *udc_data){ + char *udc; + int idx; + + c = c & 0x07; // mask to valid range + + udc = (char *) _udc[c]; + + // Copy UDC data to local UDC memory + for (idx=0; idx < 7; idx++) { + *udc++ = *udc_data++; + } +} + + /** Low level Reset method for controller */ void SDA5708::_reset(){ @@ -184,7 +250,11 @@ else { // Sanity check - if ((value < 0x20) || (value > 0x7F)) { + if (value < 0x08) { + //Pointer to char pattern for UDC + fnt_ptr = (char *) _udc[value]; + } + else if ((value < 0x20) || (value > 0x7F)) { //Pointer to char pattern for 'space' fnt_ptr = (char *) font_5x7[0]; }
--- a/SDA5708.h Mon Sep 29 19:39:18 2014 +0000 +++ b/SDA5708.h Tue Sep 30 17:13:47 2014 +0000 @@ -54,6 +54,21 @@ // First byte defines top row. D7..D5 are always 0, D4..D0 define bitpattern. D4 is leftmost, D0 is rightmost pixel. // +extern const char udc_0[]; // |> +extern const char udc_1[]; // <| +extern const char udc_2[]; // | +extern const char udc_3[]; // || +extern const char udc_4[]; // ||| +extern const char udc_5[]; // = +extern const char udc_6[]; // checkerboard +extern const char udc_7[]; // \ + +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_AC[]; // AC Power +extern const char udc_smiley[]; // Smiley + /** A library for driving SDA5708 LED matrix displays * * @code @@ -87,19 +102,34 @@ * @endcode */ + +#if(SDA5708_PRINTF == 1) /** Create an SDA5708 Display object connected to the proper pins * * @param *spi SPI port * @param cs PinName for Chip Select (active low) * @param rst PinName for Reset (active low) */ -#if(SDA5708_PRINTF == 1) class SDA5708 : public Stream { #else +/** Create an SDA5708 Display object connected to the proper pins + * + * @param *spi SPI port + * @param cs PinName for Chip Select (active low) + * @param rst PinName for Reset (active low) +*/ class SDA5708 { #endif public: + + /** Display control */ + enum DisplayMode { + DispOff, /**< Display Off */ + DispOn /**< Display On */ + }; + + /** Create an SDA5708 Display object connected to the proper pins * * @param *spi SPI port @@ -150,14 +180,26 @@ */ void locate(int column=0, int row=0); + /** Set the Displaymode + * + * @param displayMode The Display mode (DispOff, DispOn) + */ + void setMode(DisplayMode displayMode); + /** Set Brightness * * @param brightness The brightness level (valid range 0..7) */ void set_brightness(uint8_t brightness); + /** Set User Defined Characters (UDC) + * + * @param unsigned char c The Index of the UDC (0..7) + * @param char *udc_data The bitpatterns for the UDC (7 bytes of 5 significant bits for bitpattern) + */ + void setUDC(unsigned char c, char *udc_data); + protected: - /** Low level Reset method for controller */ void _reset(); @@ -178,8 +220,14 @@ int _column; int _peak, _brightness; + // Local UDC memory + char _udc[8][7]; + + //SPI bus SPI *_spi; - DigitalOut _cs, _rst; + DigitalOut _cs; + + DigitalOut _rst; };