Library for Siemens SDA5708 8 digit LED matrix display. The control interface is SPI.
SDA5708.h@9:fa31d04e35a4, 2014-10-01 (annotated)
- Committer:
- wim
- Date:
- Wed Oct 01 13:19:08 2014 +0000
- Revision:
- 9:fa31d04e35a4
- Parent:
- 8:761aa4ac6719
Name change setBrightness()
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:761aa4ac6719 | 110 | |
wim | 0:5265413226e5 | 111 | /** Create an SDA5708 Display object connected to the proper pins |
wim | 0:5265413226e5 | 112 | * |
wim | 0:5265413226e5 | 113 | * @param *spi SPI port |
wim | 0:5265413226e5 | 114 | * @param cs PinName for Chip Select (active low) |
wim | 0:5265413226e5 | 115 | * @param rst PinName for Reset (active low) |
wim | 0:5265413226e5 | 116 | */ |
wim | 0:5265413226e5 | 117 | class SDA5708 : public Stream { |
wim | 8:761aa4ac6719 | 118 | //class SDA5708 { |
wim | 8:761aa4ac6719 | 119 | |
wim | 8:761aa4ac6719 | 120 | //Unfortunately this #define selection breaks Doxygen !!! |
wim | 8:761aa4ac6719 | 121 | //#if (SDA5708_PRINTF == 1) |
wim | 8:761aa4ac6719 | 122 | //class SDA5708 : public Stream { |
wim | 8:761aa4ac6719 | 123 | //#else |
wim | 8:761aa4ac6719 | 124 | //class SDA5708 { |
wim | 8:761aa4ac6719 | 125 | //#endif |
wim | 6:27200bf65974 | 126 | |
wim | 0:5265413226e5 | 127 | public: |
wim | 1:d8a07b8468f6 | 128 | |
wim | 1:d8a07b8468f6 | 129 | /** Display control */ |
wim | 1:d8a07b8468f6 | 130 | enum DisplayMode { |
wim | 1:d8a07b8468f6 | 131 | DispOff, /**< Display Off */ |
wim | 1:d8a07b8468f6 | 132 | DispOn /**< Display On */ |
wim | 1:d8a07b8468f6 | 133 | }; |
wim | 1:d8a07b8468f6 | 134 | |
wim | 0:5265413226e5 | 135 | /** Create an SDA5708 Display object connected to the proper pins |
wim | 0:5265413226e5 | 136 | * |
wim | 0:5265413226e5 | 137 | * @param *spi SPI port |
wim | 0:5265413226e5 | 138 | * @param cs PinName for Chip Select (active low) |
wim | 0:5265413226e5 | 139 | * @param rst PinName for Reset (active low) |
wim | 0:5265413226e5 | 140 | */ |
wim | 0:5265413226e5 | 141 | SDA5708(SPI *spi, PinName cs, PinName rst); |
wim | 0:5265413226e5 | 142 | |
wim | 8:761aa4ac6719 | 143 | #if (SDA5708_PRINTF != 1) |
wim | 5:c0f8118deca2 | 144 | /** Write a character to the Display |
wim | 0:5265413226e5 | 145 | * |
wim | 0:5265413226e5 | 146 | * @param c The character to write to the display |
wim | 0:5265413226e5 | 147 | */ |
wim | 0:5265413226e5 | 148 | int putc(int c); |
wim | 0:5265413226e5 | 149 | |
wim | 5:c0f8118deca2 | 150 | /** Write a raw string to the Display |
wim | 0:5265413226e5 | 151 | * |
wim | 0:5265413226e5 | 152 | * @param string text, may be followed by variables to emulate formatting the string. |
wim | 5:c0f8118deca2 | 153 | * However, when (SDA5708_PRINTF != 1) then printf formatting is NOT supported and variables will be ignored! |
wim | 0:5265413226e5 | 154 | */ |
wim | 0:5265413226e5 | 155 | int printf(const char* text, ...); |
wim | 0:5265413226e5 | 156 | #else |
wim | 0:5265413226e5 | 157 | #if DOXYGEN_ONLY |
wim | 5:c0f8118deca2 | 158 | /** Write a character to the Display |
wim | 0:5265413226e5 | 159 | * |
wim | 0:5265413226e5 | 160 | * @param c The character to write to the display |
wim | 0:5265413226e5 | 161 | */ |
wim | 0:5265413226e5 | 162 | int putc(int c); |
wim | 0:5265413226e5 | 163 | |
wim | 9:fa31d04e35a4 | 164 | /** Write a formatted string to the Display |
wim | 0:5265413226e5 | 165 | * |
wim | 0:5265413226e5 | 166 | * @param format A printf-style format string, followed by the |
wim | 0:5265413226e5 | 167 | * variables to use in formatting the string. |
wim | 0:5265413226e5 | 168 | */ |
wim | 0:5265413226e5 | 169 | int printf(const char* format, ...); |
wim | 0:5265413226e5 | 170 | #endif |
wim | 0:5265413226e5 | 171 | |
wim | 0:5265413226e5 | 172 | #endif |
wim | 0:5265413226e5 | 173 | |
wim | 0:5265413226e5 | 174 | /** Clear the screen and locate to 0,0 |
wim | 0:5265413226e5 | 175 | */ |
wim | 0:5265413226e5 | 176 | void cls(); |
wim | 0:5265413226e5 | 177 | |
wim | 0:5265413226e5 | 178 | /** Locate cursor to a screen column and row |
wim | 0:5265413226e5 | 179 | * |
wim | 0:5265413226e5 | 180 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:5265413226e5 | 181 | * @param row The vertical position from the top, indexed from 0 |
wim | 0:5265413226e5 | 182 | */ |
wim | 0:5265413226e5 | 183 | void locate(int column=0, int row=0); |
wim | 0:5265413226e5 | 184 | |
wim | 1:d8a07b8468f6 | 185 | /** Set the Displaymode |
wim | 1:d8a07b8468f6 | 186 | * |
wim | 1:d8a07b8468f6 | 187 | * @param displayMode The Display mode (DispOff, DispOn) |
wim | 1:d8a07b8468f6 | 188 | */ |
wim | 1:d8a07b8468f6 | 189 | void setMode(DisplayMode displayMode); |
wim | 1:d8a07b8468f6 | 190 | |
wim | 0:5265413226e5 | 191 | /** Set Brightness |
wim | 0:5265413226e5 | 192 | * |
wim | 0:5265413226e5 | 193 | * @param brightness The brightness level (valid range 0..7) |
wim | 0:5265413226e5 | 194 | */ |
wim | 9:fa31d04e35a4 | 195 | void setBrightness(uint8_t brightness); |
wim | 0:5265413226e5 | 196 | |
wim | 1:d8a07b8468f6 | 197 | /** Set User Defined Characters (UDC) |
wim | 1:d8a07b8468f6 | 198 | * |
wim | 1:d8a07b8468f6 | 199 | * @param unsigned char c The Index of the UDC (0..7) |
wim | 1:d8a07b8468f6 | 200 | * @param char *udc_data The bitpatterns for the UDC (7 bytes of 5 significant bits for bitpattern) |
wim | 1:d8a07b8468f6 | 201 | */ |
wim | 1:d8a07b8468f6 | 202 | void setUDC(unsigned char c, char *udc_data); |
wim | 1:d8a07b8468f6 | 203 | |
wim | 0:5265413226e5 | 204 | protected: |
wim | 0:5265413226e5 | 205 | /** Low level Reset method for controller |
wim | 0:5265413226e5 | 206 | */ |
wim | 0:5265413226e5 | 207 | void _reset(); |
wim | 0:5265413226e5 | 208 | |
wim | 0:5265413226e5 | 209 | /** Low level Init method for LCD controller |
wim | 0:5265413226e5 | 210 | */ |
wim | 0:5265413226e5 | 211 | void _init(); |
wim | 0:5265413226e5 | 212 | |
wim | 0:5265413226e5 | 213 | /** Low level command byte write operation. |
wim | 0:5265413226e5 | 214 | */ |
wim | 0:5265413226e5 | 215 | void _write(uint8_t data); |
wim | 0:5265413226e5 | 216 | |
wim | 0:5265413226e5 | 217 | // Stream implementation functions |
wim | 0:5265413226e5 | 218 | virtual int _putc(int value); |
wim | 0:5265413226e5 | 219 | virtual int _getc(); |
wim | 0:5265413226e5 | 220 | |
wim | 0:5265413226e5 | 221 | // int _row; |
wim | 0:5265413226e5 | 222 | int _column; |
wim | 0:5265413226e5 | 223 | int _peak, _brightness; |
wim | 0:5265413226e5 | 224 | |
wim | 1:d8a07b8468f6 | 225 | // Local UDC memory |
wim | 1:d8a07b8468f6 | 226 | char _udc[8][7]; |
wim | 1:d8a07b8468f6 | 227 | |
wim | 1:d8a07b8468f6 | 228 | //SPI bus |
wim | 0:5265413226e5 | 229 | SPI *_spi; |
wim | 1:d8a07b8468f6 | 230 | DigitalOut _cs; |
wim | 1:d8a07b8468f6 | 231 | |
wim | 1:d8a07b8468f6 | 232 | DigitalOut _rst; |
wim | 0:5265413226e5 | 233 | }; |
wim | 0:5265413226e5 | 234 | |
wim | 0:5265413226e5 | 235 | |
wim | 0:5265413226e5 | 236 | #endif |