TM1638 LED controller. Max 80 LEDs, Max 24 Key scan. Supports LED&KEY, QYF-TM1638 and JY-LKM1638 module.
Dependents: mbed_TM1638 Otjimaniya RL0201-V1
See here for more information.
TM1638.h@1:1f2453ed85d7, 2016-01-09 (annotated)
- Committer:
- wim
- Date:
- Sat Jan 09 14:30:43 2016 +0000
- Revision:
- 1:1f2453ed85d7
- Parent:
- 0:201dfacbe0e5
- Child:
- 2:532ce15ea9ec
TM1638 LED controller, Initial version.; Supports LED&KEY module.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:201dfacbe0e5 | 1 | /* mbed TM1638 Library, for TM1638 LED controller |
wim | 0:201dfacbe0e5 | 2 | * Copyright (c) 2015, v01: WH, Initial version |
wim | 0:201dfacbe0e5 | 3 | * |
wim | 0:201dfacbe0e5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:201dfacbe0e5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:201dfacbe0e5 | 6 | * in the Software without restriction, including without limitation the rights |
wim | 0:201dfacbe0e5 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:201dfacbe0e5 | 8 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:201dfacbe0e5 | 9 | * furnished to do so, subject to the following conditions: |
wim | 0:201dfacbe0e5 | 10 | * |
wim | 0:201dfacbe0e5 | 11 | * The above copyright notice and this permission notice shall be included in |
wim | 0:201dfacbe0e5 | 12 | * all copies or substantial portions of the Software. |
wim | 0:201dfacbe0e5 | 13 | * |
wim | 0:201dfacbe0e5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:201dfacbe0e5 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:201dfacbe0e5 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:201dfacbe0e5 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:201dfacbe0e5 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:201dfacbe0e5 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:201dfacbe0e5 | 20 | * THE SOFTWARE. |
wim | 0:201dfacbe0e5 | 21 | */ |
wim | 0:201dfacbe0e5 | 22 | |
wim | 0:201dfacbe0e5 | 23 | #ifndef TM1638_H |
wim | 0:201dfacbe0e5 | 24 | #define TM1638_H |
wim | 0:201dfacbe0e5 | 25 | |
wim | 0:201dfacbe0e5 | 26 | // Select one of the testboards for TM1638 LED controller |
wim | 0:201dfacbe0e5 | 27 | #include "TM1638_Config.h" |
wim | 0:201dfacbe0e5 | 28 | |
wim | 0:201dfacbe0e5 | 29 | /** An interface for driving TM1638 LED controller |
wim | 0:201dfacbe0e5 | 30 | * |
wim | 0:201dfacbe0e5 | 31 | * @code |
wim | 0:201dfacbe0e5 | 32 | * #include "mbed.h" |
wim | 0:201dfacbe0e5 | 33 | * #include "TM1638.h" |
wim | 0:201dfacbe0e5 | 34 | * |
wim | 0:201dfacbe0e5 | 35 | * DisplayData_t size is 16 bytes (8 grids @ 10 segments) |
wim | 0:201dfacbe0e5 | 36 | * TM1638::DisplayData_t all_str = {0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F}; |
wim | 0:201dfacbe0e5 | 37 | * |
wim | 1:1f2453ed85d7 | 38 | * // KeyData_t size is 4 bytes |
wim | 0:201dfacbe0e5 | 39 | * TM1638::KeyData_t keydata; |
wim | 0:201dfacbe0e5 | 40 | * |
wim | 0:201dfacbe0e5 | 41 | * // TM1638 declaration |
wim | 0:201dfacbe0e5 | 42 | * TM1638 TM1638(p5,p6,p7, p8); |
wim | 0:201dfacbe0e5 | 43 | * |
wim | 0:201dfacbe0e5 | 44 | * int main() { |
wim | 0:201dfacbe0e5 | 45 | * TM1638.cls(); |
wim | 0:201dfacbe0e5 | 46 | * TM1638.writeData(all_str); |
wim | 0:201dfacbe0e5 | 47 | * wait(1); |
wim | 0:201dfacbe0e5 | 48 | * TM1638.setBrightness(TM1638_BRT0); |
wim | 0:201dfacbe0e5 | 49 | * wait(1); |
wim | 0:201dfacbe0e5 | 50 | * TM1638.setBrightness(TM1638_BRT3); |
wim | 0:201dfacbe0e5 | 51 | * |
wim | 0:201dfacbe0e5 | 52 | * while (1) { |
wim | 0:201dfacbe0e5 | 53 | * // Check and read keydata |
wim | 0:201dfacbe0e5 | 54 | * if (TM1638.getKeys(&keydata)) { |
wim | 0:201dfacbe0e5 | 55 | * pc.printf("Keydata 0..3 = 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3]); |
wim | 0:201dfacbe0e5 | 56 | * |
wim | 1:1f2453ed85d7 | 57 | * if (keydata[0] == 0x01) { //sw1 |
wim | 0:201dfacbe0e5 | 58 | * TM1638.cls(); |
wim | 0:201dfacbe0e5 | 59 | * TM1638.writeData(all_str); |
wim | 0:201dfacbe0e5 | 60 | * } |
wim | 0:201dfacbe0e5 | 61 | * } |
wim | 0:201dfacbe0e5 | 62 | * } |
wim | 0:201dfacbe0e5 | 63 | * } |
wim | 0:201dfacbe0e5 | 64 | * @endcode |
wim | 0:201dfacbe0e5 | 65 | */ |
wim | 0:201dfacbe0e5 | 66 | |
wim | 0:201dfacbe0e5 | 67 | //Memory size in bytes for Display and Keymatrix |
wim | 0:201dfacbe0e5 | 68 | #define TM1638_DISPLAY_MEM 16 |
wim | 0:201dfacbe0e5 | 69 | #define TM1638_KEY_MEM 4 |
wim | 0:201dfacbe0e5 | 70 | //Significant bits Keymatrix data |
wim | 0:201dfacbe0e5 | 71 | #define TM1638_KEY_BITS 6 |
wim | 0:201dfacbe0e5 | 72 | |
wim | 0:201dfacbe0e5 | 73 | //Reserved bits for commands |
wim | 0:201dfacbe0e5 | 74 | #define TM1638_CMD_MSK 0xC0 |
wim | 0:201dfacbe0e5 | 75 | |
wim | 0:201dfacbe0e5 | 76 | //Data setting commands |
wim | 0:201dfacbe0e5 | 77 | #define TM1638_DATA_SET_CMD 0x40 |
wim | 0:201dfacbe0e5 | 78 | #define TM1638_DATA_WR 0x00 |
wim | 0:201dfacbe0e5 | 79 | #define TM1638_KEY_RD 0x02 |
wim | 0:201dfacbe0e5 | 80 | #define TM1638_ADDR_INC 0x00 |
wim | 0:201dfacbe0e5 | 81 | #define TM1638_ADDR_FIXED 0x04 |
wim | 0:201dfacbe0e5 | 82 | #define TM1638_MODE_NORM 0x00 |
wim | 0:201dfacbe0e5 | 83 | #define TM1638_MODE_TEST 0x08 |
wim | 0:201dfacbe0e5 | 84 | |
wim | 0:201dfacbe0e5 | 85 | //Address setting commands |
wim | 0:201dfacbe0e5 | 86 | #define TM1638_ADDR_SET_CMD 0xC0 |
wim | 0:201dfacbe0e5 | 87 | #define TM1638_ADDR_MSK 0x0F |
wim | 0:201dfacbe0e5 | 88 | |
wim | 0:201dfacbe0e5 | 89 | //Display control commands |
wim | 0:201dfacbe0e5 | 90 | #define TM1638_DSP_CTRL_CMD 0x80 |
wim | 0:201dfacbe0e5 | 91 | #define TM1638_BRT_MSK 0x07 |
wim | 0:201dfacbe0e5 | 92 | #define TM1638_BRT0 0x00 //Pulsewidth 1/16 |
wim | 0:201dfacbe0e5 | 93 | #define TM1638_BRT1 0x01 |
wim | 0:201dfacbe0e5 | 94 | #define TM1638_BRT2 0x02 |
wim | 0:201dfacbe0e5 | 95 | #define TM1638_BRT3 0x03 |
wim | 0:201dfacbe0e5 | 96 | #define TM1638_BRT4 0x04 |
wim | 0:201dfacbe0e5 | 97 | #define TM1638_BRT5 0x05 |
wim | 0:201dfacbe0e5 | 98 | #define TM1638_BRT6 0x06 |
wim | 0:201dfacbe0e5 | 99 | #define TM1638_BRT7 0x07 //Pulsewidth 14/16 |
wim | 0:201dfacbe0e5 | 100 | |
wim | 0:201dfacbe0e5 | 101 | #define TM1638_BRT_DEF TM1638_BRT3 |
wim | 0:201dfacbe0e5 | 102 | |
wim | 0:201dfacbe0e5 | 103 | #define TM1638_DSP_OFF 0x00 |
wim | 0:201dfacbe0e5 | 104 | #define TM1638_DSP_ON 0x08 |
wim | 0:201dfacbe0e5 | 105 | |
wim | 0:201dfacbe0e5 | 106 | |
wim | 0:201dfacbe0e5 | 107 | /** A class for driving TM1638 LED controller |
wim | 0:201dfacbe0e5 | 108 | * |
wim | 0:201dfacbe0e5 | 109 | * @brief Supports 8 Grids @ 10 Segments. |
wim | 0:201dfacbe0e5 | 110 | * Also supports a scanned keyboard of upto 24 keys. |
wim | 0:201dfacbe0e5 | 111 | * SPI bus interface device. |
wim | 0:201dfacbe0e5 | 112 | */ |
wim | 0:201dfacbe0e5 | 113 | class TM1638 { |
wim | 0:201dfacbe0e5 | 114 | public: |
wim | 0:201dfacbe0e5 | 115 | |
wim | 0:201dfacbe0e5 | 116 | /** Datatypes for display and keymatrix data */ |
wim | 0:201dfacbe0e5 | 117 | typedef char DisplayData_t[TM1638_DISPLAY_MEM]; |
wim | 0:201dfacbe0e5 | 118 | typedef char KeyData_t[TM1638_KEY_MEM]; |
wim | 0:201dfacbe0e5 | 119 | |
wim | 0:201dfacbe0e5 | 120 | /** Constructor for class for driving TM1638 LED controller |
wim | 0:201dfacbe0e5 | 121 | * |
wim | 0:201dfacbe0e5 | 122 | * @brief Supports 8 Grids @ 10 segments. |
wim | 0:201dfacbe0e5 | 123 | * Also supports a scanned keyboard of upto 24 keys. |
wim | 0:201dfacbe0e5 | 124 | * SPI bus interface device. |
wim | 0:201dfacbe0e5 | 125 | * |
wim | 0:201dfacbe0e5 | 126 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:201dfacbe0e5 | 127 | */ |
wim | 0:201dfacbe0e5 | 128 | TM1638(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 0:201dfacbe0e5 | 129 | |
wim | 0:201dfacbe0e5 | 130 | /** Clear the screen and locate to 0 |
wim | 0:201dfacbe0e5 | 131 | */ |
wim | 0:201dfacbe0e5 | 132 | void cls(); |
wim | 0:201dfacbe0e5 | 133 | |
wim | 0:201dfacbe0e5 | 134 | /** Write databyte to TM1638 |
wim | 0:201dfacbe0e5 | 135 | * @param int address display memory location to write byte |
wim | 0:201dfacbe0e5 | 136 | * @param char data byte written at given address |
wim | 0:201dfacbe0e5 | 137 | * @return none |
wim | 0:201dfacbe0e5 | 138 | */ |
wim | 0:201dfacbe0e5 | 139 | void writeData(int address, char data); |
wim | 0:201dfacbe0e5 | 140 | |
wim | 0:201dfacbe0e5 | 141 | /** Write Display datablock to TM1638 |
wim | 0:201dfacbe0e5 | 142 | * @param DisplayData_t data Array of TM1638_DISPLAY_MEM (=16) bytes for displaydata (starting at address 0) |
wim | 0:201dfacbe0e5 | 143 | * @param length number bytes to write (valid range 0..TM1638_DISPLAY_MEM (=16), starting at address 0) |
wim | 0:201dfacbe0e5 | 144 | * @return none |
wim | 0:201dfacbe0e5 | 145 | */ |
wim | 0:201dfacbe0e5 | 146 | void writeData(DisplayData_t data, int length = TM1638_DISPLAY_MEM); |
wim | 0:201dfacbe0e5 | 147 | |
wim | 0:201dfacbe0e5 | 148 | /** Read keydata block from TM1638 |
wim | 0:201dfacbe0e5 | 149 | * @param *keydata Ptr to Array of TM1638_KEY_MEM (=4) bytes for keydata |
wim | 0:201dfacbe0e5 | 150 | * @return bool keypress True when at least one key was pressed |
wim | 0:201dfacbe0e5 | 151 | * |
wim | 0:201dfacbe0e5 | 152 | * Note: Due to the hardware configuration the TM1638 key matrix scanner will detect multiple keys pressed at same time, |
wim | 0:201dfacbe0e5 | 153 | * but this may result in some spurious keys also being set in keypress data array. |
wim | 0:201dfacbe0e5 | 154 | * It may be best to ignore all keys in those situations. That option is implemented in this method depending on #define setting. |
wim | 0:201dfacbe0e5 | 155 | */ |
wim | 0:201dfacbe0e5 | 156 | bool getKeys(KeyData_t *keydata); |
wim | 0:201dfacbe0e5 | 157 | |
wim | 0:201dfacbe0e5 | 158 | /** Set Brightness |
wim | 0:201dfacbe0e5 | 159 | * |
wim | 0:201dfacbe0e5 | 160 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/14 dutycycle) |
wim | 0:201dfacbe0e5 | 161 | * @return none |
wim | 0:201dfacbe0e5 | 162 | */ |
wim | 0:201dfacbe0e5 | 163 | void setBrightness(char brightness = TM1638_BRT_DEF); |
wim | 0:201dfacbe0e5 | 164 | |
wim | 0:201dfacbe0e5 | 165 | /** Set the Display mode On/off |
wim | 0:201dfacbe0e5 | 166 | * |
wim | 0:201dfacbe0e5 | 167 | * @param bool display mode |
wim | 0:201dfacbe0e5 | 168 | */ |
wim | 0:201dfacbe0e5 | 169 | void setDisplay(bool on); |
wim | 0:201dfacbe0e5 | 170 | |
wim | 0:201dfacbe0e5 | 171 | private: |
wim | 0:201dfacbe0e5 | 172 | SPI _spi; |
wim | 0:201dfacbe0e5 | 173 | DigitalOut _cs; |
wim | 0:201dfacbe0e5 | 174 | char _display; |
wim | 0:201dfacbe0e5 | 175 | char _bright; |
wim | 0:201dfacbe0e5 | 176 | |
wim | 0:201dfacbe0e5 | 177 | /** Init the SPI interface and the controller |
wim | 0:201dfacbe0e5 | 178 | * @param none |
wim | 0:201dfacbe0e5 | 179 | * @return none |
wim | 0:201dfacbe0e5 | 180 | */ |
wim | 0:201dfacbe0e5 | 181 | void _init(); |
wim | 0:201dfacbe0e5 | 182 | |
wim | 0:201dfacbe0e5 | 183 | /** Helper to reverse all command or databits. The TM1638 expects LSB first, whereas SPI is MSB first |
wim | 0:201dfacbe0e5 | 184 | * @param char data |
wim | 0:201dfacbe0e5 | 185 | * @return bitreversed data |
wim | 0:201dfacbe0e5 | 186 | */ |
wim | 0:201dfacbe0e5 | 187 | char _flip(char data); |
wim | 0:201dfacbe0e5 | 188 | |
wim | 0:201dfacbe0e5 | 189 | /** Write command and parameter to TM1638 |
wim | 0:201dfacbe0e5 | 190 | * @param int cmd Command byte |
wim | 0:201dfacbe0e5 | 191 | * &Param int data Parameters for command |
wim | 0:201dfacbe0e5 | 192 | * @return none |
wim | 0:201dfacbe0e5 | 193 | */ |
wim | 0:201dfacbe0e5 | 194 | void _writeCmd(int cmd, int data); |
wim | 0:201dfacbe0e5 | 195 | }; |
wim | 0:201dfacbe0e5 | 196 | |
wim | 0:201dfacbe0e5 | 197 | |
wim | 0:201dfacbe0e5 | 198 | #if (LEDKEY8_TEST == 1) |
wim | 0:201dfacbe0e5 | 199 | // Derived class for TM1638 used in LED&KEY display unit |
wim | 0:201dfacbe0e5 | 200 | // |
wim | 0:201dfacbe0e5 | 201 | |
wim | 0:201dfacbe0e5 | 202 | #include "Font_7Seg.h" |
wim | 0:201dfacbe0e5 | 203 | |
wim | 0:201dfacbe0e5 | 204 | #define LEDKEY8_NR_GRIDS 8 |
wim | 0:201dfacbe0e5 | 205 | #define LEDKEY8_NR_DIGITS 8 |
wim | 0:201dfacbe0e5 | 206 | #define LEDKEY8_NR_UDC 8 |
wim | 0:201dfacbe0e5 | 207 | |
wim | 1:1f2453ed85d7 | 208 | //Access to 8 Switches |
wim | 1:1f2453ed85d7 | 209 | #define LEDKEY8_SW1_IDX 0 |
wim | 1:1f2453ed85d7 | 210 | #define LEDKEY8_SW1_BIT 0x01 |
wim | 1:1f2453ed85d7 | 211 | #define LEDKEY8_SW2_IDX 1 |
wim | 1:1f2453ed85d7 | 212 | #define LEDKEY8_SW2_BIT 0x01 |
wim | 1:1f2453ed85d7 | 213 | #define LEDKEY8_SW3_IDX 2 |
wim | 1:1f2453ed85d7 | 214 | #define LEDKEY8_SW3_BIT 0x01 |
wim | 1:1f2453ed85d7 | 215 | #define LEDKEY8_SW4_IDX 3 |
wim | 1:1f2453ed85d7 | 216 | #define LEDKEY8_SW4_BIT 0x01 |
wim | 1:1f2453ed85d7 | 217 | |
wim | 1:1f2453ed85d7 | 218 | #define LEDKEY8_SW5_IDX 0 |
wim | 1:1f2453ed85d7 | 219 | #define LEDKEY8_SW5_BIT 0x10 |
wim | 1:1f2453ed85d7 | 220 | #define LEDKEY8_SW6_IDX 1 |
wim | 1:1f2453ed85d7 | 221 | #define LEDKEY8_SW6_BIT 0x10 |
wim | 1:1f2453ed85d7 | 222 | #define LEDKEY8_SW7_IDX 2 |
wim | 1:1f2453ed85d7 | 223 | #define LEDKEY8_SW7_BIT 0x10 |
wim | 1:1f2453ed85d7 | 224 | #define LEDKEY8_SW8_IDX 3 |
wim | 1:1f2453ed85d7 | 225 | #define LEDKEY8_SW8_BIT 0x10 |
wim | 1:1f2453ed85d7 | 226 | |
wim | 0:201dfacbe0e5 | 227 | /** Constructor for class for driving TM1638 controller as used in LEDKEY8 |
wim | 0:201dfacbe0e5 | 228 | * |
wim | 0:201dfacbe0e5 | 229 | * @brief Supports 8 Digits of 7 Segments + DP + LED Icons, Also supports a scanned keyboard of 8 keys. |
wim | 0:201dfacbe0e5 | 230 | * |
wim | 0:201dfacbe0e5 | 231 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:201dfacbe0e5 | 232 | */ |
wim | 0:201dfacbe0e5 | 233 | class TM1638_LEDKEY8 : public TM1638, public Stream { |
wim | 0:201dfacbe0e5 | 234 | public: |
wim | 0:201dfacbe0e5 | 235 | |
wim | 0:201dfacbe0e5 | 236 | /** Enums for Icons */ |
wim | 1:1f2453ed85d7 | 237 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:201dfacbe0e5 | 238 | enum Icon { |
wim | 0:201dfacbe0e5 | 239 | LD1 = (1<<24) | S7_LD1, |
wim | 0:201dfacbe0e5 | 240 | LD2 = (2<<24) | S7_LD2, |
wim | 0:201dfacbe0e5 | 241 | LD3 = (3<<24) | S7_LD3, |
wim | 0:201dfacbe0e5 | 242 | LD4 = (4<<24) | S7_LD4, |
wim | 0:201dfacbe0e5 | 243 | LD5 = (5<<24) | S7_LD5, |
wim | 0:201dfacbe0e5 | 244 | LD6 = (6<<24) | S7_LD6, |
wim | 0:201dfacbe0e5 | 245 | LD7 = (7<<24) | S7_LD7, |
wim | 0:201dfacbe0e5 | 246 | LD8 = (8<<24) | S7_LD8, |
wim | 0:201dfacbe0e5 | 247 | |
wim | 0:201dfacbe0e5 | 248 | DP1 = (1<<24) | S7_DP1, |
wim | 0:201dfacbe0e5 | 249 | DP2 = (2<<24) | S7_DP2, |
wim | 0:201dfacbe0e5 | 250 | DP3 = (3<<24) | S7_DP3, |
wim | 0:201dfacbe0e5 | 251 | DP4 = (4<<24) | S7_DP4, |
wim | 0:201dfacbe0e5 | 252 | DP5 = (5<<24) | S7_DP5, |
wim | 0:201dfacbe0e5 | 253 | DP6 = (6<<24) | S7_DP6, |
wim | 0:201dfacbe0e5 | 254 | DP7 = (7<<24) | S7_DP7, |
wim | 0:201dfacbe0e5 | 255 | DP8 = (8<<24) | S7_DP8 |
wim | 0:201dfacbe0e5 | 256 | }; |
wim | 0:201dfacbe0e5 | 257 | |
wim | 0:201dfacbe0e5 | 258 | typedef char UDCData_t[LEDKEY8_NR_UDC]; |
wim | 0:201dfacbe0e5 | 259 | |
wim | 0:201dfacbe0e5 | 260 | /** Constructor for class for driving TM1638 LED controller as used in LEDKEY8 |
wim | 0:201dfacbe0e5 | 261 | * |
wim | 0:201dfacbe0e5 | 262 | * @brief Supports 8 Digits of 7 Segments + DP + LED Icons. Also supports a scanned keyboard of 8 keys. |
wim | 0:201dfacbe0e5 | 263 | * |
wim | 0:201dfacbe0e5 | 264 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:201dfacbe0e5 | 265 | */ |
wim | 0:201dfacbe0e5 | 266 | TM1638_LEDKEY8(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 0:201dfacbe0e5 | 267 | |
wim | 0:201dfacbe0e5 | 268 | #if DOXYGEN_ONLY |
wim | 0:201dfacbe0e5 | 269 | /** Write a character to the Display |
wim | 0:201dfacbe0e5 | 270 | * |
wim | 0:201dfacbe0e5 | 271 | * @param c The character to write to the display |
wim | 0:201dfacbe0e5 | 272 | */ |
wim | 0:201dfacbe0e5 | 273 | int putc(int c); |
wim | 0:201dfacbe0e5 | 274 | |
wim | 0:201dfacbe0e5 | 275 | /** Write a formatted string to the Display |
wim | 0:201dfacbe0e5 | 276 | * |
wim | 0:201dfacbe0e5 | 277 | * @param format A printf-style format string, followed by the |
wim | 0:201dfacbe0e5 | 278 | * variables to use in formatting the string. |
wim | 0:201dfacbe0e5 | 279 | */ |
wim | 0:201dfacbe0e5 | 280 | int printf(const char* format, ...); |
wim | 0:201dfacbe0e5 | 281 | #endif |
wim | 0:201dfacbe0e5 | 282 | |
wim | 0:201dfacbe0e5 | 283 | /** Locate cursor to a screen column |
wim | 0:201dfacbe0e5 | 284 | * |
wim | 0:201dfacbe0e5 | 285 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:201dfacbe0e5 | 286 | */ |
wim | 0:201dfacbe0e5 | 287 | void locate(int column); |
wim | 0:201dfacbe0e5 | 288 | |
wim | 0:201dfacbe0e5 | 289 | /** Clear the screen and locate to 0 |
wim | 0:201dfacbe0e5 | 290 | * @param bool clrAll Clear Icons also (default = false) |
wim | 0:201dfacbe0e5 | 291 | */ |
wim | 0:201dfacbe0e5 | 292 | void cls(bool clrAll = false); |
wim | 0:201dfacbe0e5 | 293 | |
wim | 0:201dfacbe0e5 | 294 | /** Set Icon |
wim | 0:201dfacbe0e5 | 295 | * |
wim | 1:1f2453ed85d7 | 296 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:201dfacbe0e5 | 297 | * @return none |
wim | 0:201dfacbe0e5 | 298 | */ |
wim | 0:201dfacbe0e5 | 299 | void setIcon(Icon icon); |
wim | 0:201dfacbe0e5 | 300 | |
wim | 0:201dfacbe0e5 | 301 | /** Clr Icon |
wim | 0:201dfacbe0e5 | 302 | * |
wim | 1:1f2453ed85d7 | 303 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:201dfacbe0e5 | 304 | * @return none |
wim | 0:201dfacbe0e5 | 305 | */ |
wim | 0:201dfacbe0e5 | 306 | void clrIcon(Icon icon); |
wim | 0:201dfacbe0e5 | 307 | |
wim | 0:201dfacbe0e5 | 308 | /** Set User Defined Characters (UDC) |
wim | 0:201dfacbe0e5 | 309 | * |
wim | 0:201dfacbe0e5 | 310 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 0:201dfacbe0e5 | 311 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 0:201dfacbe0e5 | 312 | */ |
wim | 0:201dfacbe0e5 | 313 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 0:201dfacbe0e5 | 314 | |
wim | 0:201dfacbe0e5 | 315 | |
wim | 0:201dfacbe0e5 | 316 | /** Number of screen columns |
wim | 0:201dfacbe0e5 | 317 | * |
wim | 0:201dfacbe0e5 | 318 | * @param none |
wim | 0:201dfacbe0e5 | 319 | * @return columns |
wim | 0:201dfacbe0e5 | 320 | */ |
wim | 0:201dfacbe0e5 | 321 | int columns(); |
wim | 0:201dfacbe0e5 | 322 | |
wim | 0:201dfacbe0e5 | 323 | /** Write databyte to TM1638 |
wim | 0:201dfacbe0e5 | 324 | * @param int address display memory location to write byte |
wim | 0:201dfacbe0e5 | 325 | * @param char data byte written at given address |
wim | 0:201dfacbe0e5 | 326 | * @return none |
wim | 0:201dfacbe0e5 | 327 | */ |
wim | 0:201dfacbe0e5 | 328 | void writeData(int address, char data){ |
wim | 0:201dfacbe0e5 | 329 | TM1638::writeData(address, data); |
wim | 0:201dfacbe0e5 | 330 | } |
wim | 0:201dfacbe0e5 | 331 | |
wim | 0:201dfacbe0e5 | 332 | /** Write Display datablock to TM1638 |
wim | 0:201dfacbe0e5 | 333 | * @param DisplayData_t data Array of TM1638_DISPLAY_MEM (=16) bytes for displaydata (starting at address 0) |
wim | 0:201dfacbe0e5 | 334 | * @param length number bytes to write (valid range 0..(LEDKEY8_NR_GRIDS*2) (=16), starting at address 0) |
wim | 0:201dfacbe0e5 | 335 | * @return none |
wim | 0:201dfacbe0e5 | 336 | */ |
wim | 0:201dfacbe0e5 | 337 | void writeData(DisplayData_t data, int length = (LEDKEY8_NR_GRIDS*2)) { |
wim | 0:201dfacbe0e5 | 338 | TM1638::writeData(data, length); |
wim | 0:201dfacbe0e5 | 339 | } |
wim | 0:201dfacbe0e5 | 340 | |
wim | 0:201dfacbe0e5 | 341 | protected: |
wim | 0:201dfacbe0e5 | 342 | // Stream implementation functions |
wim | 0:201dfacbe0e5 | 343 | virtual int _putc(int value); |
wim | 0:201dfacbe0e5 | 344 | virtual int _getc(); |
wim | 0:201dfacbe0e5 | 345 | |
wim | 0:201dfacbe0e5 | 346 | private: |
wim | 0:201dfacbe0e5 | 347 | int _column; |
wim | 0:201dfacbe0e5 | 348 | int _columns; |
wim | 0:201dfacbe0e5 | 349 | |
wim | 0:201dfacbe0e5 | 350 | DisplayData_t _displaybuffer; |
wim | 0:201dfacbe0e5 | 351 | UDCData_t _UDC_7S; |
wim | 0:201dfacbe0e5 | 352 | }; |
wim | 0:201dfacbe0e5 | 353 | #endif |
wim | 0:201dfacbe0e5 | 354 | |
wim | 0:201dfacbe0e5 | 355 | #endif |