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

Dependents:   mbed_SDA5708

Committer:
wim
Date:
Mon Sep 29 19:39:18 2014 +0000
Revision:
0:5265413226e5
Child:
1:d8a07b8468f6
Library for Siemens SDA5708 LED matrix display. The display has 8 digits, each comprising of a 5x7 LED matrix.The control interface is SPI.

Who changed what in which revision?

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