Alphanumeric LED display, 8 digits, 5x7 pattern. Supports 8x1, 8x2, 16x1 and 16x2 display configuration.
Alphanumeric LED display, 8 digits, 5x7 LED pattern. The device has SPI interface. The library supports multiple devices connected in a daisy chain. This provides a 8x1, 8x2, 16x1 and 16x2 display configuration.The library methods are similar to those used for the LCDText library.
These displays are from mid 80s to mid 90s and they look cool, but they are rather expensive ($100 a piece..). The lib was developed and tested with displays salvaged from some equipment. You see them mostly in HP printers, medical equipment etc.
Some info can be found here and here.
Datasheet is here
HCMS2975.cpp@1:f46d90374eb2, 2015-01-05 (annotated)
- Committer:
- wim
- Date:
- Mon Jan 05 20:37:06 2015 +0000
- Revision:
- 1:f46d90374eb2
- Parent:
- 0:a332431006fb
Fixed setBrightness() at init()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:a332431006fb | 1 | /** |
wim | 0:a332431006fb | 2 | * @file HCMS2975.cpp |
wim | 0:a332431006fb | 3 | * @brief mbed Avago/HP HCMS2975 LED matrix display Library. |
wim | 0:a332431006fb | 4 | * @author WH |
wim | 0:a332431006fb | 5 | * @date Copyright (c) 2014 |
wim | 0:a332431006fb | 6 | * v01: WH, Initial release |
wim | 0:a332431006fb | 7 | * Info available at http://playground.arduino.cc/Main/LedDisplay and http://www.pjrc.com/teensy/td_libs_LedDisplay.html |
wim | 1:f46d90374eb2 | 8 | * v02: WH, added getVersion() |
wim | 1:f46d90374eb2 | 9 | * v03: WH, fixed setBrightness at init() when there is no HW reset. |
wim | 0:a332431006fb | 10 | * |
wim | 0:a332431006fb | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:a332431006fb | 12 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:a332431006fb | 13 | * in the Software without restriction, including without limitation the rights |
wim | 0:a332431006fb | 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:a332431006fb | 15 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:a332431006fb | 16 | * furnished to do so, subject to the following conditions: |
wim | 0:a332431006fb | 17 | * |
wim | 0:a332431006fb | 18 | * The above copyright notice and this permission notice shall be included in |
wim | 0:a332431006fb | 19 | * all copies or substantial portions of the Software. |
wim | 0:a332431006fb | 20 | * |
wim | 0:a332431006fb | 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:a332431006fb | 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:a332431006fb | 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:a332431006fb | 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:a332431006fb | 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:a332431006fb | 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:a332431006fb | 27 | * THE SOFTWARE. |
wim | 0:a332431006fb | 28 | */ |
wim | 0:a332431006fb | 29 | #include "mbed.h" |
wim | 0:a332431006fb | 30 | #include "HCMS2975.h" |
wim | 0:a332431006fb | 31 | #include "font_5x7.h" // Pascal Stang's 5x7 font library |
wim | 0:a332431006fb | 32 | |
wim | 0:a332431006fb | 33 | // User Defined Characters (UDCs) are defined by a 5 byte bitpattern. The P0..P6 form the character pattern, P7 is ignored. |
wim | 0:a332431006fb | 34 | // Byte0 Byte1 Byte2 Byte3 Byte4 |
wim | 0:a332431006fb | 35 | // b0 P0 P0 P0 P0 P0 |
wim | 0:a332431006fb | 36 | // b1 P1 P1 P1 P1 P1 |
wim | 0:a332431006fb | 37 | // . ............. |
wim | 0:a332431006fb | 38 | // b6 P6 P6 P6 P6 P6 |
wim | 0:a332431006fb | 39 | // b7 x x x x x |
wim | 0:a332431006fb | 40 | |
wim | 0:a332431006fb | 41 | /** Some sample User Defined Chars 5x7 dots */ |
wim | 0:a332431006fb | 42 | const char udc_0[] = {0x7F, 0x41, 0x22, 0x14, 0x08}; /* |> */ |
wim | 0:a332431006fb | 43 | const char udc_1[] = {0x08, 0x14, 0x22, 0x41, 0x7F}; /* <| */ |
wim | 0:a332431006fb | 44 | const char udc_2[] = {0x7F, 0x00, 0x00, 0x00, 0x00}; /* | */ |
wim | 0:a332431006fb | 45 | const char udc_3[] = {0x7F, 0x00, 0x7F, 0x00, 0x00}; /* || */ |
wim | 0:a332431006fb | 46 | const char udc_4[] = {0x7F, 0x00, 0x7F, 0x00, 0x7F}; /* ||| */ |
wim | 0:a332431006fb | 47 | const char udc_5[] = {0x2A, 0x2A, 0x2A, 0x2A, 0x2A}; /* = */ |
wim | 0:a332431006fb | 48 | const char udc_6[] = {0x55, 0x2A, 0x55, 0x2A, 0x55}; /* checkerboard */ |
wim | 0:a332431006fb | 49 | const char udc_7[] = {0x01, 0x02, 0x04, 0x08, 0x10}; /* \ */ |
wim | 0:a332431006fb | 50 | |
wim | 0:a332431006fb | 51 | const char udc_Bat_Hi[] = {0x7E, 0x7F, 0x7F, 0x7F, 0x7E}; /* Battery Full */ |
wim | 0:a332431006fb | 52 | const char udc_Bat_Ha[] = {0x7E, 0x7D, 0x7D, 0x7D, 0x7E}; /* Battery Half */ |
wim | 0:a332431006fb | 53 | const char udc_Bat_Lo[] = {0x7E, 0x61, 0x61, 0x61, 0x7E}; /* Battery Low */ |
wim | 0:a332431006fb | 54 | const char udc_AC[] = {0x0C, 0x17, 0x74, 0x17, 0x0C}; /* AC Power */ |
wim | 0:a332431006fb | 55 | const char udc_smiley[] = {0x10, 0x22, 0x28, 0x22, 0x10}; /* Smiley */ |
wim | 0:a332431006fb | 56 | |
wim | 0:a332431006fb | 57 | /** Create an HCMS2975 Display object connected to the proper pins |
wim | 0:a332431006fb | 58 | * |
wim | 0:a332431006fb | 59 | * @param *spi SPI port |
wim | 0:a332431006fb | 60 | * @param cs PinName for Chip Select (active low) |
wim | 0:a332431006fb | 61 | * @param rs PinName for RS () |
wim | 0:a332431006fb | 62 | * @param rst PinName for Rst (active low, optional, default=NC) |
wim | 0:a332431006fb | 63 | * @param type Sets the panel size (default = LED8x1) |
wim | 0:a332431006fb | 64 | */ |
wim | 0:a332431006fb | 65 | HCMS2975::HCMS2975(SPI *spi, PinName cs, PinName rs, PinName rst, LEDType type) : _spi(spi), _cs(cs), _rs(rs), _type(type) { |
wim | 0:a332431006fb | 66 | |
wim | 0:a332431006fb | 67 | // Extract LCDType data |
wim | 0:a332431006fb | 68 | |
wim | 0:a332431006fb | 69 | // Columns encoded in b7..b0 |
wim | 0:a332431006fb | 70 | _nr_cols = (_type & 0xFF); |
wim | 0:a332431006fb | 71 | |
wim | 0:a332431006fb | 72 | // Rows encoded in b15..b8 |
wim | 0:a332431006fb | 73 | _nr_rows = ((_type >> 8) & 0xFF); |
wim | 0:a332431006fb | 74 | |
wim | 0:a332431006fb | 75 | _displaySize = _nr_cols * _nr_rows; |
wim | 0:a332431006fb | 76 | |
wim | 0:a332431006fb | 77 | // Number of devices encoded in b23..b16 |
wim | 0:a332431006fb | 78 | _deviceCount = ((_type >> 16) & 0xFF); |
wim | 0:a332431006fb | 79 | |
wim | 0:a332431006fb | 80 | |
wim | 0:a332431006fb | 81 | // The hardware Reset pin is optional. Test and make sure whether it exists or not to prevent illegal access. |
wim | 0:a332431006fb | 82 | if (rst != NC) { |
wim | 0:a332431006fb | 83 | _rst = new DigitalOut(rst); //Construct new pin |
wim | 0:a332431006fb | 84 | _rst->write(1); //Deactivate |
wim | 0:a332431006fb | 85 | } |
wim | 0:a332431006fb | 86 | else { |
wim | 0:a332431006fb | 87 | // No Hardware Backlight pin |
wim | 0:a332431006fb | 88 | _rst = NULL; //Construct dummy pin |
wim | 0:a332431006fb | 89 | } |
wim | 0:a332431006fb | 90 | |
wim | 0:a332431006fb | 91 | _init(); |
wim | 0:a332431006fb | 92 | } |
wim | 0:a332431006fb | 93 | |
wim | 0:a332431006fb | 94 | /** Destructor for HCMS2975 Display object |
wim | 0:a332431006fb | 95 | * |
wim | 0:a332431006fb | 96 | */ |
wim | 0:a332431006fb | 97 | HCMS2975::~HCMS2975() { |
wim | 0:a332431006fb | 98 | if (_rst != NULL) {delete _rst;} // RST pin |
wim | 0:a332431006fb | 99 | } |
wim | 0:a332431006fb | 100 | |
wim | 0:a332431006fb | 101 | #if(HCMS2975_PRINTF != 1) |
wim | 0:a332431006fb | 102 | /** Write a character to the Display |
wim | 0:a332431006fb | 103 | * |
wim | 0:a332431006fb | 104 | * @param c The character to write to the display |
wim | 0:a332431006fb | 105 | */ |
wim | 0:a332431006fb | 106 | int HCMS2975::putc(int c){ |
wim | 0:a332431006fb | 107 | return _putc(c); |
wim | 0:a332431006fb | 108 | } |
wim | 0:a332431006fb | 109 | |
wim | 0:a332431006fb | 110 | /** Write a raw string to the Display |
wim | 0:a332431006fb | 111 | * |
wim | 0:a332431006fb | 112 | * @param string text, may be followed by variables to emulate formatting the string. |
wim | 0:a332431006fb | 113 | * However, printf formatting is NOT supported and variables will be ignored! |
wim | 0:a332431006fb | 114 | */ |
wim | 0:a332431006fb | 115 | int HCMS2975::printf(const char* text, ...) { |
wim | 0:a332431006fb | 116 | |
wim | 0:a332431006fb | 117 | while (*text !=0) { |
wim | 0:a332431006fb | 118 | _putc(*text); |
wim | 0:a332431006fb | 119 | text++; |
wim | 0:a332431006fb | 120 | } |
wim | 0:a332431006fb | 121 | return 0; |
wim | 0:a332431006fb | 122 | } |
wim | 0:a332431006fb | 123 | #else |
wim | 0:a332431006fb | 124 | #if DOXYGEN_ONLY |
wim | 0:a332431006fb | 125 | /** Write a character to the Display |
wim | 0:a332431006fb | 126 | * |
wim | 0:a332431006fb | 127 | * @param c The character to write to the display |
wim | 0:a332431006fb | 128 | */ |
wim | 0:a332431006fb | 129 | int HCMS2975::putc(int c){ |
wim | 0:a332431006fb | 130 | return _putc(c); |
wim | 0:a332431006fb | 131 | } |
wim | 0:a332431006fb | 132 | |
wim | 0:a332431006fb | 133 | /** Write a formatted string to the Display |
wim | 0:a332431006fb | 134 | * |
wim | 0:a332431006fb | 135 | * @param format A printf-style format string, followed by the |
wim | 0:a332431006fb | 136 | * variables to use in formatting the string. |
wim | 0:a332431006fb | 137 | */ |
wim | 0:a332431006fb | 138 | int HCMS2975::printf(const char* format, ...){ |
wim | 0:a332431006fb | 139 | } |
wim | 0:a332431006fb | 140 | #endif |
wim | 0:a332431006fb | 141 | |
wim | 0:a332431006fb | 142 | #endif |
wim | 0:a332431006fb | 143 | |
wim | 0:a332431006fb | 144 | /** Clear the screen and locate to 0,0 |
wim | 0:a332431006fb | 145 | */ |
wim | 0:a332431006fb | 146 | void HCMS2975::cls(){ |
wim | 0:a332431006fb | 147 | |
wim | 0:a332431006fb | 148 | // fill _displayBuffer with spaces |
wim | 0:a332431006fb | 149 | for (int i=0; i < HCMS2975_BUFFER_SIZE; i++) { |
wim | 0:a332431006fb | 150 | _displayBuffer[i] = ' '; |
wim | 0:a332431006fb | 151 | } |
wim | 0:a332431006fb | 152 | |
wim | 0:a332431006fb | 153 | // display buffer |
wim | 0:a332431006fb | 154 | _pushBuffer(); |
wim | 0:a332431006fb | 155 | |
wim | 0:a332431006fb | 156 | //cursor |
wim | 0:a332431006fb | 157 | _row = 0; |
wim | 0:a332431006fb | 158 | _column = 0; |
wim | 0:a332431006fb | 159 | } |
wim | 0:a332431006fb | 160 | |
wim | 0:a332431006fb | 161 | /** Locate cursor to a screen column and row |
wim | 0:a332431006fb | 162 | * |
wim | 0:a332431006fb | 163 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:a332431006fb | 164 | * @param row The vertical position from the top, indexed from 0 |
wim | 0:a332431006fb | 165 | */ |
wim | 0:a332431006fb | 166 | void HCMS2975::locate(int column, int row){ |
wim | 0:a332431006fb | 167 | |
wim | 0:a332431006fb | 168 | // Sanity Check column |
wim | 0:a332431006fb | 169 | if (column < 0) { |
wim | 0:a332431006fb | 170 | _column = 0; |
wim | 0:a332431006fb | 171 | } |
wim | 0:a332431006fb | 172 | else { |
wim | 0:a332431006fb | 173 | if (column >= _nr_cols) { |
wim | 0:a332431006fb | 174 | _column = _nr_cols - 1; |
wim | 0:a332431006fb | 175 | } |
wim | 0:a332431006fb | 176 | else { |
wim | 0:a332431006fb | 177 | _column = column; |
wim | 0:a332431006fb | 178 | } |
wim | 0:a332431006fb | 179 | } |
wim | 0:a332431006fb | 180 | |
wim | 0:a332431006fb | 181 | // Sanity Check row |
wim | 0:a332431006fb | 182 | if (row < 0) { |
wim | 0:a332431006fb | 183 | _row = 0; |
wim | 0:a332431006fb | 184 | } |
wim | 0:a332431006fb | 185 | else { |
wim | 0:a332431006fb | 186 | if (row >= _nr_rows) { |
wim | 0:a332431006fb | 187 | _row = _nr_rows - 1; |
wim | 0:a332431006fb | 188 | } |
wim | 0:a332431006fb | 189 | else { |
wim | 0:a332431006fb | 190 | _row = row; |
wim | 0:a332431006fb | 191 | } |
wim | 0:a332431006fb | 192 | } |
wim | 0:a332431006fb | 193 | } |
wim | 0:a332431006fb | 194 | |
wim | 0:a332431006fb | 195 | /** Return the number of columns |
wim | 0:a332431006fb | 196 | * |
wim | 1:f46d90374eb2 | 197 | * @return int The number of columns |
wim | 0:a332431006fb | 198 | */ |
wim | 0:a332431006fb | 199 | int HCMS2975::columns() { |
wim | 0:a332431006fb | 200 | |
wim | 0:a332431006fb | 201 | // Columns encoded in b7..b0 |
wim | 0:a332431006fb | 202 | //return (_type & 0xFF); |
wim | 0:a332431006fb | 203 | return _nr_cols; |
wim | 0:a332431006fb | 204 | } |
wim | 0:a332431006fb | 205 | |
wim | 0:a332431006fb | 206 | /** Return the number of rows |
wim | 0:a332431006fb | 207 | * |
wim | 1:f46d90374eb2 | 208 | * @return int The number of rows |
wim | 0:a332431006fb | 209 | */ |
wim | 0:a332431006fb | 210 | int HCMS2975::rows() { |
wim | 0:a332431006fb | 211 | |
wim | 0:a332431006fb | 212 | // Rows encoded in b15..b8 |
wim | 0:a332431006fb | 213 | //return ((_type >> 8) & 0xFF); |
wim | 0:a332431006fb | 214 | return _nr_rows; |
wim | 0:a332431006fb | 215 | } |
wim | 0:a332431006fb | 216 | |
wim | 0:a332431006fb | 217 | |
wim | 0:a332431006fb | 218 | /** Set Brightness |
wim | 0:a332431006fb | 219 | * |
wim | 0:a332431006fb | 220 | * @param brightness The brightness level (valid range 0..15) |
wim | 0:a332431006fb | 221 | */ |
wim | 0:a332431006fb | 222 | void HCMS2975::setBrightness(uint8_t brightness){ |
wim | 0:a332431006fb | 223 | |
wim | 0:a332431006fb | 224 | _brightness = brightness & 0x0F; |
wim | 0:a332431006fb | 225 | |
wim | 0:a332431006fb | 226 | //Set brightness |
wim | 0:a332431006fb | 227 | //Set display to normal |
wim | 0:a332431006fb | 228 | _writeCommand(HCMS2975_CONTROL0 | HCMS2975_NORMAL | _peak | _brightness); |
wim | 0:a332431006fb | 229 | } |
wim | 0:a332431006fb | 230 | |
wim | 0:a332431006fb | 231 | /** Set the Displaymode |
wim | 0:a332431006fb | 232 | * |
wim | 0:a332431006fb | 233 | * @param displayMode The Display mode (DispOff, DispOn) |
wim | 0:a332431006fb | 234 | */ |
wim | 0:a332431006fb | 235 | void HCMS2975::setMode(DisplayMode displayMode){ |
wim | 0:a332431006fb | 236 | |
wim | 0:a332431006fb | 237 | if (displayMode == DispOff) { |
wim | 0:a332431006fb | 238 | //Set brightness to Zero |
wim | 0:a332431006fb | 239 | _writeCommand(HCMS2975_CONTROL0 | HCMS2975_NORMAL | _peak | HCMS2975_BRIGHT_0); |
wim | 0:a332431006fb | 240 | // //Set Sleep mode |
wim | 0:a332431006fb | 241 | // _writeCommand(HCMS2975_CONTROL0 | HCMS2975_SLP | _peak | _brightness); |
wim | 0:a332431006fb | 242 | } |
wim | 0:a332431006fb | 243 | else { |
wim | 0:a332431006fb | 244 | //Restore brightness |
wim | 0:a332431006fb | 245 | //Set display to normal |
wim | 0:a332431006fb | 246 | _writeCommand(HCMS2975_CONTROL0 | HCMS2975_NORMAL | _peak | _brightness); |
wim | 0:a332431006fb | 247 | } |
wim | 0:a332431006fb | 248 | } |
wim | 0:a332431006fb | 249 | |
wim | 0:a332431006fb | 250 | /** Set User Defined Characters (UDC) |
wim | 0:a332431006fb | 251 | * |
wim | 0:a332431006fb | 252 | * @param unsigned char c The Index of the UDC (0..7) |
wim | 0:a332431006fb | 253 | * @param char *udc_data The bitpatterns for the UDC (5 bytes of 7 significant bits for bitpattern) |
wim | 0:a332431006fb | 254 | */ |
wim | 0:a332431006fb | 255 | void HCMS2975::setUDC(unsigned char c, char *udc_data){ |
wim | 0:a332431006fb | 256 | char *udc; |
wim | 0:a332431006fb | 257 | int idx; |
wim | 0:a332431006fb | 258 | |
wim | 0:a332431006fb | 259 | c = c & 0x07; // mask to valid range |
wim | 0:a332431006fb | 260 | |
wim | 0:a332431006fb | 261 | udc = (char *) _udc[c]; |
wim | 0:a332431006fb | 262 | |
wim | 0:a332431006fb | 263 | // Copy UDC data to local UDC memory |
wim | 0:a332431006fb | 264 | for (idx=0; idx < 5; idx++) { |
wim | 0:a332431006fb | 265 | *udc++ = *udc_data++; |
wim | 0:a332431006fb | 266 | } |
wim | 0:a332431006fb | 267 | } |
wim | 0:a332431006fb | 268 | |
wim | 0:a332431006fb | 269 | |
wim | 0:a332431006fb | 270 | /** Low level Reset method for controller |
wim | 0:a332431006fb | 271 | */ |
wim | 0:a332431006fb | 272 | void HCMS2975::_reset(){ |
wim | 0:a332431006fb | 273 | |
wim | 0:a332431006fb | 274 | // Reset when pin defined |
wim | 0:a332431006fb | 275 | if (_rst) { |
wim | 0:a332431006fb | 276 | _rst->write(0); |
wim | 0:a332431006fb | 277 | wait_us(500); |
wim | 0:a332431006fb | 278 | _rst->write(1); |
wim | 0:a332431006fb | 279 | } |
wim | 0:a332431006fb | 280 | } |
wim | 0:a332431006fb | 281 | |
wim | 0:a332431006fb | 282 | /** Low level Init method for controller |
wim | 0:a332431006fb | 283 | */ |
wim | 0:a332431006fb | 284 | void HCMS2975::_init(){ |
wim | 0:a332431006fb | 285 | |
wim | 0:a332431006fb | 286 | // Hard Reset |
wim | 0:a332431006fb | 287 | _reset(); |
wim | 0:a332431006fb | 288 | |
wim | 0:a332431006fb | 289 | // Init CS en RS |
wim | 0:a332431006fb | 290 | _cs = 1; |
wim | 0:a332431006fb | 291 | _rs = 0; |
wim | 0:a332431006fb | 292 | |
wim | 0:a332431006fb | 293 | // Setup the spi for 8 bit data, low steady state clock, |
wim | 0:a332431006fb | 294 | // rising edge capture, with a 500KHz or 1MHz clock rate |
wim | 0:a332431006fb | 295 | _spi->format(8,0); |
wim | 0:a332431006fb | 296 | _spi->frequency(1000000); // Max SCL is 5 MHz for HCMS2975 |
wim | 0:a332431006fb | 297 | // _spi->frequency(50000); // Max SCL is 5 MHz for HCMS2975 |
wim | 1:f46d90374eb2 | 298 | |
wim | 1:f46d90374eb2 | 299 | //Set display to serial mode |
wim | 1:f46d90374eb2 | 300 | _writeCommand(HCMS2975_CONTROL1 | HCMS2975_PRE_1 | HCMS2975_SERIAL); |
wim | 0:a332431006fb | 301 | |
wim | 0:a332431006fb | 302 | // default display brightness and peak |
wim | 0:a332431006fb | 303 | _brightness = HCMS2975_DEF_BRIGHT; |
wim | 0:a332431006fb | 304 | _peak = HCMS2975_DEF_PEAK; |
wim | 0:a332431006fb | 305 | |
wim | 0:a332431006fb | 306 | //Set display to normal |
wim | 0:a332431006fb | 307 | _writeCommand(HCMS2975_CONTROL0 | HCMS2975_NORMAL | _peak | _brightness); |
wim | 0:a332431006fb | 308 | |
wim | 1:f46d90374eb2 | 309 | //Clear display |
wim | 1:f46d90374eb2 | 310 | cls(); |
wim | 0:a332431006fb | 311 | } |
wim | 0:a332431006fb | 312 | |
wim | 0:a332431006fb | 313 | |
wim | 0:a332431006fb | 314 | /** Low level command byte write operation. |
wim | 0:a332431006fb | 315 | * @param command commandbyte to write |
wim | 0:a332431006fb | 316 | */ |
wim | 0:a332431006fb | 317 | void HCMS2975::_writeCommand(uint8_t command){ |
wim | 0:a332431006fb | 318 | int cnt; |
wim | 0:a332431006fb | 319 | |
wim | 0:a332431006fb | 320 | // Set RS |
wim | 0:a332431006fb | 321 | _rs = 1; |
wim | 0:a332431006fb | 322 | wait_us(1); |
wim | 0:a332431006fb | 323 | |
wim | 0:a332431006fb | 324 | // Enable CS |
wim | 0:a332431006fb | 325 | _cs = 0; |
wim | 0:a332431006fb | 326 | wait_us(1); |
wim | 0:a332431006fb | 327 | |
wim | 0:a332431006fb | 328 | // Must write the command to all devices...! |
wim | 0:a332431006fb | 329 | // Note that internally the 8 digit display consist of 2 display devices with 4 digits each! |
wim | 0:a332431006fb | 330 | for (cnt=0; cnt < (_deviceCount << 1); cnt++) { |
wim | 0:a332431006fb | 331 | _spi->write(command); |
wim | 0:a332431006fb | 332 | // wait_us(1); // Min setup time is x ns for HCMS2975 |
wim | 0:a332431006fb | 333 | } |
wim | 0:a332431006fb | 334 | |
wim | 0:a332431006fb | 335 | // Disable CS |
wim | 0:a332431006fb | 336 | _cs = 1; |
wim | 0:a332431006fb | 337 | |
wim | 0:a332431006fb | 338 | // Reset RS |
wim | 0:a332431006fb | 339 | _rs = 0; |
wim | 0:a332431006fb | 340 | |
wim | 0:a332431006fb | 341 | } |
wim | 0:a332431006fb | 342 | |
wim | 0:a332431006fb | 343 | /** Low level _dataBuffer write operation. |
wim | 0:a332431006fb | 344 | */ |
wim | 0:a332431006fb | 345 | void HCMS2975::_pushBuffer(){ |
wim | 0:a332431006fb | 346 | char charcode; |
wim | 0:a332431006fb | 347 | char *fnt_ptr; |
wim | 0:a332431006fb | 348 | int idx, pidx; |
wim | 0:a332431006fb | 349 | |
wim | 0:a332431006fb | 350 | // Reset RS |
wim | 0:a332431006fb | 351 | _rs = 0; |
wim | 0:a332431006fb | 352 | wait_us(1); |
wim | 0:a332431006fb | 353 | |
wim | 0:a332431006fb | 354 | // Enable CS |
wim | 0:a332431006fb | 355 | _cs = 0; |
wim | 0:a332431006fb | 356 | wait_us(1); |
wim | 0:a332431006fb | 357 | |
wim | 0:a332431006fb | 358 | // Encode and push the character data to the display |
wim | 0:a332431006fb | 359 | for (idx=0; idx < _displaySize; idx++) { |
wim | 0:a332431006fb | 360 | charcode = _displayBuffer[idx]; |
wim | 0:a332431006fb | 361 | |
wim | 0:a332431006fb | 362 | //Sanity check and font pointer |
wim | 0:a332431006fb | 363 | if (charcode < 0x08) { |
wim | 0:a332431006fb | 364 | //UDC |
wim | 0:a332431006fb | 365 | fnt_ptr = (char *) _udc[charcode]; |
wim | 0:a332431006fb | 366 | } |
wim | 0:a332431006fb | 367 | else { |
wim | 0:a332431006fb | 368 | if ((charcode < 0x20) || (charcode > 0x7F)) { |
wim | 0:a332431006fb | 369 | // non-printable, show 'space' |
wim | 0:a332431006fb | 370 | fnt_ptr = (char *) font_5x7[0]; |
wim | 0:a332431006fb | 371 | } |
wim | 0:a332431006fb | 372 | else { |
wim | 0:a332431006fb | 373 | //Pointer to char pattern |
wim | 0:a332431006fb | 374 | fnt_ptr = (char *) font_5x7[charcode - 0x20]; |
wim | 0:a332431006fb | 375 | } |
wim | 0:a332431006fb | 376 | } // end sanity check |
wim | 0:a332431006fb | 377 | |
wim | 0:a332431006fb | 378 | //Write char pattern of 5 bytes |
wim | 0:a332431006fb | 379 | for (pidx=0; pidx < 5; pidx++) { |
wim | 0:a332431006fb | 380 | _spi->write(*fnt_ptr); |
wim | 0:a332431006fb | 381 | fnt_ptr++; |
wim | 0:a332431006fb | 382 | //wait_us(1); // Min setup time is x ns for HCMS2975 |
wim | 0:a332431006fb | 383 | } //for pidx |
wim | 0:a332431006fb | 384 | |
wim | 0:a332431006fb | 385 | } //for idx |
wim | 0:a332431006fb | 386 | |
wim | 0:a332431006fb | 387 | // Disable CS |
wim | 0:a332431006fb | 388 | _cs = 1; |
wim | 0:a332431006fb | 389 | |
wim | 0:a332431006fb | 390 | } |
wim | 0:a332431006fb | 391 | |
wim | 0:a332431006fb | 392 | |
wim | 0:a332431006fb | 393 | // Stream implementation functions |
wim | 0:a332431006fb | 394 | int HCMS2975::_putc(int value){ |
wim | 0:a332431006fb | 395 | |
wim | 0:a332431006fb | 396 | if ((value == '\n') || (value == '\r')) { |
wim | 0:a332431006fb | 397 | //No character to write |
wim | 0:a332431006fb | 398 | |
wim | 0:a332431006fb | 399 | //Update Cursor |
wim | 0:a332431006fb | 400 | _column = 0; |
wim | 0:a332431006fb | 401 | _row++; |
wim | 0:a332431006fb | 402 | if (_row >= _nr_rows) { |
wim | 0:a332431006fb | 403 | _row = 0; |
wim | 0:a332431006fb | 404 | } |
wim | 0:a332431006fb | 405 | |
wim | 0:a332431006fb | 406 | return 0; |
wim | 0:a332431006fb | 407 | } |
wim | 0:a332431006fb | 408 | else { |
wim | 0:a332431006fb | 409 | //Character to write |
wim | 0:a332431006fb | 410 | _displayBuffer[(_row * _nr_cols) + _column] = value; |
wim | 0:a332431006fb | 411 | |
wim | 0:a332431006fb | 412 | //Update Cursor |
wim | 0:a332431006fb | 413 | _column++; |
wim | 0:a332431006fb | 414 | if (_column >= _nr_cols) { |
wim | 0:a332431006fb | 415 | _column = 0; |
wim | 0:a332431006fb | 416 | _row++; |
wim | 0:a332431006fb | 417 | if (_row >= _nr_rows) { |
wim | 0:a332431006fb | 418 | _row = 0; |
wim | 0:a332431006fb | 419 | } |
wim | 0:a332431006fb | 420 | } |
wim | 0:a332431006fb | 421 | |
wim | 0:a332431006fb | 422 | // push new data to display |
wim | 0:a332431006fb | 423 | _pushBuffer(); |
wim | 0:a332431006fb | 424 | |
wim | 0:a332431006fb | 425 | return 0; |
wim | 0:a332431006fb | 426 | } //else |
wim | 0:a332431006fb | 427 | |
wim | 0:a332431006fb | 428 | } |
wim | 0:a332431006fb | 429 | |
wim | 0:a332431006fb | 430 | |
wim | 0:a332431006fb | 431 | // Stream implementation functions |
wim | 0:a332431006fb | 432 | int HCMS2975::_getc(){ |
wim | 0:a332431006fb | 433 | return -1; |
wim | 0:a332431006fb | 434 | } |
wim | 0:a332431006fb | 435 | |
wim | 1:f46d90374eb2 | 436 | |
wim | 0:a332431006fb | 437 | /** Returns the version number of the library |
wim | 0:a332431006fb | 438 | * @return int version number |
wim | 0:a332431006fb | 439 | */ |
wim | 0:a332431006fb | 440 | int HCMS2975::getVersion() { |
wim | 1:f46d90374eb2 | 441 | return HCMS2975_VERSION; |
wim | 0:a332431006fb | 442 | } |