Library for Siemens SDA5708 8 digit LED matrix display. The control interface is SPI.

Dependents:   mbed_SDA5708

Committer:
wim
Date:
Tue Sep 30 17:48:48 2014 +0000
Revision:
3:7f65944fee37
Parent:
2:966fca76e5aa
Child:
4:7713c496717b
Doxygen test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 2:966fca76e5aa 1 /**
wim 2:966fca76e5aa 2 * @file SDA5708.h
wim 2:966fca76e5aa 3 * @brief mbed SDA5708 LED matrix display Library.
wim 2:966fca76e5aa 4 * @author WH
wim 2:966fca76e5aa 5 * @date Copyright (c) 2014
wim 2:966fca76e5aa 6 * v01: WH, Initial release
wim 2:966fca76e5aa 7 * v02: WH, Added setMode() and UDC support
wim 0:5265413226e5 8 *
wim 0:5265413226e5 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:5265413226e5 10 * of this software and associated documentation files (the "Software"), to deal
wim 0:5265413226e5 11 * in the Software without restriction, including without limitation the rights
wim 0:5265413226e5 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:5265413226e5 13 * copies of the Software, and to permit persons to whom the Software is
wim 0:5265413226e5 14 * furnished to do so, subject to the following conditions:
wim 0:5265413226e5 15 *
wim 0:5265413226e5 16 * The above copyright notice and this permission notice shall be included in
wim 0:5265413226e5 17 * all copies or substantial portions of the Software.
wim 0:5265413226e5 18 *
wim 0:5265413226e5 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:5265413226e5 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:5265413226e5 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:5265413226e5 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:5265413226e5 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:5265413226e5 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:5265413226e5 25 * THE SOFTWARE.
wim 0:5265413226e5 26 */
wim 0:5265413226e5 27 #ifndef _SDA5708_H
wim 0:5265413226e5 28 #define _SDA5708_H
wim 0:5265413226e5 29
wim 0:5265413226e5 30 #include "mbed.h"
wim 0:5265413226e5 31
wim 0:5265413226e5 32 //Enable Stream printf or minimalistic printf
wim 0:5265413226e5 33 #define SDA5708_PRINTF 1
wim 0:5265413226e5 34
wim 0:5265413226e5 35 // display brightness definitions, indicating percentage brightness
wim 0:5265413226e5 36 #define SDA5708_BRIGHT_100 0x00
wim 0:5265413226e5 37 #define SDA5708_BRIGHT_53 0x01
wim 0:5265413226e5 38 #define SDA5708_BRIGHT_40 0x02
wim 0:5265413226e5 39 #define SDA5708_BRIGHT_27 0x03
wim 0:5265413226e5 40 #define SDA5708_BRIGHT_20 0x04
wim 0:5265413226e5 41 #define SDA5708_BRIGHT_13 0x05
wim 0:5265413226e5 42 #define SDA5708_BRIGHT_6_6 0x06
wim 0:5265413226e5 43 #define SDA5708_BRIGHT_0 0x07
wim 0:5265413226e5 44
wim 0:5265413226e5 45 #define SDA5708_MAX_PEAK 0x00
wim 0:5265413226e5 46 #define SDA5708_12_5_PEAK 0x08
wim 0:5265413226e5 47
wim 0:5265413226e5 48 // default display brightness
wim 0:5265413226e5 49 #define SDA5708_DEF_BRIGHT SDA5708_BRIGHT_27
wim 0:5265413226e5 50
wim 0:5265413226e5 51 //Commands
wim 0:5265413226e5 52 //Clear display. D2..D0 select brightness. D3 selects max peak current
wim 0:5265413226e5 53 #define SDA5708_CMD_CLR 0xC0
wim 0:5265413226e5 54 //Normal display. D2..D0 select brightness. D3 selects max peak current
wim 0:5265413226e5 55 #define SDA5708_CMD_NORMAL 0xE0
wim 0:5265413226e5 56 //Select Digit Address. D2..D0 select digit. Digit 0 is leftmost, Digit 7 is rightmost.
wim 0:5265413226e5 57 #define SDA5708_CMD_DIG_ADDR 0xA0
wim 0:5265413226e5 58 //Write Digit row data as 8 sequential bytes.
wim 0:5265413226e5 59 // First byte defines top row. D7..D5 are always 0, D4..D0 define bitpattern. D4 is leftmost, D0 is rightmost pixel.
wim 0:5265413226e5 60 //
wim 0:5265413226e5 61
wim 3:7f65944fee37 62 extern const char udc_0[]; /* |> */
wim 3:7f65944fee37 63 extern const char udc_1[]; /* <| */
wim 3:7f65944fee37 64 extern const char udc_2[]; /* | */
wim 3:7f65944fee37 65 extern const char udc_3[]; /* || */
wim 3:7f65944fee37 66 extern const char udc_4[]; /* ||| */
wim 3:7f65944fee37 67 extern const char udc_5[]; /* = */
wim 3:7f65944fee37 68 extern const char udc_6[]; /* checkerboard */
wim 3:7f65944fee37 69 extern const char udc_7[]; /* \ */
wim 1:d8a07b8468f6 70
wim 3:7f65944fee37 71 extern const char udc_Bat_Hi[]; /* Battery Full */
wim 3:7f65944fee37 72 extern const char udc_Bat_Ha[]; /* Battery Half */
wim 3:7f65944fee37 73 extern const char udc_Bat_Lo[]; /* Battery Low */
wim 3:7f65944fee37 74 extern const char udc_AC[]; /* AC Power */
wim 3:7f65944fee37 75 extern const char udc_smiley[]; /* Smiley */
wim 1:d8a07b8468f6 76
wim 0:5265413226e5 77 /** A library for driving SDA5708 LED matrix displays
wim 0:5265413226e5 78 *
wim 0:5265413226e5 79 * @code
wim 0:5265413226e5 80 * #include "mbed.h"
wim 0:5265413226e5 81 * #include "SDA5708.h"
wim 0:5265413226e5 82 *
wim 0:5265413226e5 83 * // SPI Communication
wim 0:5265413226e5 84 * SPI spi_led(p5, NC, p7); // MOSI, MISO, SCLK
wim 0:5265413226e5 85 *
wim 0:5265413226e5 86 * //Display
wim 0:5265413226e5 87 * SDA5708 led(&spi_led, p8, p9); // SPI bus, CS pin, RST pin
wim 0:5265413226e5 88 *
wim 0:5265413226e5 89 * int main() {
wim 0:5265413226e5 90 * int cnt;
wim 0:5265413226e5 91 *
wim 0:5265413226e5 92 * led.locate(0, 0);
wim 0:5265413226e5 93 *
wim 0:5265413226e5 94 * // 12345678
wim 0:5265413226e5 95 * led.printf("Hi mbed ");
wim 0:5265413226e5 96 * wait(2);
wim 0:5265413226e5 97 *
wim 0:5265413226e5 98 * cnt=0x20;
wim 0:5265413226e5 99 * while(1) {
wim 0:5265413226e5 100 * wait(0.5);
wim 0:5265413226e5 101 *
wim 0:5265413226e5 102 * led.putc(cnt);
wim 0:5265413226e5 103 * cnt++;
wim 0:5265413226e5 104 * if (cnt == 0x80) cnt=0x20;
wim 0:5265413226e5 105 * }
wim 0:5265413226e5 106 * }
wim 0:5265413226e5 107 * @endcode
wim 0:5265413226e5 108 */
wim 0:5265413226e5 109
wim 1:d8a07b8468f6 110
wim 1:d8a07b8468f6 111 #if(SDA5708_PRINTF == 1)
wim 0:5265413226e5 112 /** Create an SDA5708 Display object connected to the proper pins
wim 0:5265413226e5 113 *
wim 0:5265413226e5 114 * @param *spi SPI port
wim 0:5265413226e5 115 * @param cs PinName for Chip Select (active low)
wim 0:5265413226e5 116 * @param rst PinName for Reset (active low)
wim 0:5265413226e5 117 */
wim 0:5265413226e5 118 class SDA5708 : public Stream {
wim 0:5265413226e5 119 #else
wim 1:d8a07b8468f6 120 /** Create an SDA5708 Display object connected to the proper pins
wim 1:d8a07b8468f6 121 *
wim 1:d8a07b8468f6 122 * @param *spi SPI port
wim 1:d8a07b8468f6 123 * @param cs PinName for Chip Select (active low)
wim 1:d8a07b8468f6 124 * @param rst PinName for Reset (active low)
wim 1:d8a07b8468f6 125 */
wim 0:5265413226e5 126 class SDA5708 {
wim 0:5265413226e5 127 #endif
wim 0:5265413226e5 128
wim 0:5265413226e5 129 public:
wim 1:d8a07b8468f6 130
wim 1:d8a07b8468f6 131 /** Display control */
wim 1:d8a07b8468f6 132 enum DisplayMode {
wim 1:d8a07b8468f6 133 DispOff, /**< Display Off */
wim 1:d8a07b8468f6 134 DispOn /**< Display On */
wim 1:d8a07b8468f6 135 };
wim 1:d8a07b8468f6 136
wim 1:d8a07b8468f6 137
wim 0:5265413226e5 138 /** Create an SDA5708 Display object connected to the proper pins
wim 0:5265413226e5 139 *
wim 0:5265413226e5 140 * @param *spi SPI port
wim 0:5265413226e5 141 * @param cs PinName for Chip Select (active low)
wim 0:5265413226e5 142 * @param rst PinName for Reset (active low)
wim 0:5265413226e5 143 */
wim 0:5265413226e5 144 SDA5708(SPI *spi, PinName cs, PinName rst);
wim 0:5265413226e5 145
wim 0:5265413226e5 146 #if(SDA5708_PRINTF != 1)
wim 0:5265413226e5 147 /** Write a character to the LCD
wim 0:5265413226e5 148 *
wim 0:5265413226e5 149 * @param c The character to write to the display
wim 0:5265413226e5 150 */
wim 0:5265413226e5 151 int putc(int c);
wim 0:5265413226e5 152
wim 0:5265413226e5 153 /** Write a raw string to the LCD
wim 0:5265413226e5 154 *
wim 0:5265413226e5 155 * @param string text, may be followed by variables to emulate formatting the string.
wim 0:5265413226e5 156 * However, printf formatting is NOT supported and variables will be ignored!
wim 0:5265413226e5 157 */
wim 0:5265413226e5 158 int printf(const char* text, ...);
wim 0:5265413226e5 159 #else
wim 0:5265413226e5 160 #if DOXYGEN_ONLY
wim 0:5265413226e5 161 /** Write a character to the LCD
wim 0:5265413226e5 162 *
wim 0:5265413226e5 163 * @param c The character to write to the display
wim 0:5265413226e5 164 */
wim 0:5265413226e5 165 int putc(int c);
wim 0:5265413226e5 166
wim 0:5265413226e5 167 /** Write a formatted string to the LCD
wim 0:5265413226e5 168 *
wim 0:5265413226e5 169 * @param format A printf-style format string, followed by the
wim 0:5265413226e5 170 * variables to use in formatting the string.
wim 0:5265413226e5 171 */
wim 0:5265413226e5 172 int printf(const char* format, ...);
wim 0:5265413226e5 173 #endif
wim 0:5265413226e5 174
wim 0:5265413226e5 175 #endif
wim 0:5265413226e5 176
wim 0:5265413226e5 177 /** Clear the screen and locate to 0,0
wim 0:5265413226e5 178 */
wim 0:5265413226e5 179 void cls();
wim 0:5265413226e5 180
wim 0:5265413226e5 181 /** Locate cursor to a screen column and row
wim 0:5265413226e5 182 *
wim 0:5265413226e5 183 * @param column The horizontal position from the left, indexed from 0
wim 0:5265413226e5 184 * @param row The vertical position from the top, indexed from 0
wim 0:5265413226e5 185 */
wim 0:5265413226e5 186 void locate(int column=0, int row=0);
wim 0:5265413226e5 187
wim 1:d8a07b8468f6 188 /** Set the Displaymode
wim 1:d8a07b8468f6 189 *
wim 1:d8a07b8468f6 190 * @param displayMode The Display mode (DispOff, DispOn)
wim 1:d8a07b8468f6 191 */
wim 1:d8a07b8468f6 192 void setMode(DisplayMode displayMode);
wim 1:d8a07b8468f6 193
wim 0:5265413226e5 194 /** Set Brightness
wim 0:5265413226e5 195 *
wim 0:5265413226e5 196 * @param brightness The brightness level (valid range 0..7)
wim 0:5265413226e5 197 */
wim 0:5265413226e5 198 void set_brightness(uint8_t brightness);
wim 0:5265413226e5 199
wim 1:d8a07b8468f6 200 /** Set User Defined Characters (UDC)
wim 1:d8a07b8468f6 201 *
wim 1:d8a07b8468f6 202 * @param unsigned char c The Index of the UDC (0..7)
wim 1:d8a07b8468f6 203 * @param char *udc_data The bitpatterns for the UDC (7 bytes of 5 significant bits for bitpattern)
wim 1:d8a07b8468f6 204 */
wim 1:d8a07b8468f6 205 void setUDC(unsigned char c, char *udc_data);
wim 1:d8a07b8468f6 206
wim 0:5265413226e5 207 protected:
wim 0:5265413226e5 208 /** Low level Reset method for controller
wim 0:5265413226e5 209 */
wim 0:5265413226e5 210 void _reset();
wim 0:5265413226e5 211
wim 0:5265413226e5 212 /** Low level Init method for LCD controller
wim 0:5265413226e5 213 */
wim 0:5265413226e5 214 void _init();
wim 0:5265413226e5 215
wim 0:5265413226e5 216 /** Low level command byte write operation.
wim 0:5265413226e5 217 */
wim 0:5265413226e5 218 void _write(uint8_t data);
wim 0:5265413226e5 219
wim 0:5265413226e5 220 // Stream implementation functions
wim 0:5265413226e5 221 virtual int _putc(int value);
wim 0:5265413226e5 222 virtual int _getc();
wim 0:5265413226e5 223
wim 0:5265413226e5 224 // int _row;
wim 0:5265413226e5 225 int _column;
wim 0:5265413226e5 226 int _peak, _brightness;
wim 0:5265413226e5 227
wim 1:d8a07b8468f6 228 // Local UDC memory
wim 1:d8a07b8468f6 229 char _udc[8][7];
wim 1:d8a07b8468f6 230
wim 1:d8a07b8468f6 231 //SPI bus
wim 0:5265413226e5 232 SPI *_spi;
wim 1:d8a07b8468f6 233 DigitalOut _cs;
wim 1:d8a07b8468f6 234
wim 1:d8a07b8468f6 235 DigitalOut _rst;
wim 0:5265413226e5 236 };
wim 0:5265413226e5 237
wim 0:5265413226e5 238
wim 0:5265413226e5 239 #endif