TEST
Dependents: ADXL345Test ADXL345Test1
Fork of TM1638 by
TM1638.h@5:a4634cc2ab71, 2017-09-04 (annotated)
- Committer:
- jack__zen
- Date:
- Mon Sep 04 01:39:58 2017 +0000
- Revision:
- 5:a4634cc2ab71
- Parent:
- 4:b2bbdc58967e
TSET
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 | 2:532ce15ea9ec | 3 | * 2016, v02: WH, refactored display and keyboard defines |
wim | 4:b2bbdc58967e | 4 | * 2016, v03: WH, Added QYF-TM1638 and LKM1638, refactoring of writeData() |
wim | 0:201dfacbe0e5 | 5 | * |
wim | 0:201dfacbe0e5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:201dfacbe0e5 | 7 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:201dfacbe0e5 | 8 | * in the Software without restriction, including without limitation the rights |
wim | 0:201dfacbe0e5 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:201dfacbe0e5 | 10 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:201dfacbe0e5 | 11 | * furnished to do so, subject to the following conditions: |
wim | 0:201dfacbe0e5 | 12 | * |
wim | 0:201dfacbe0e5 | 13 | * The above copyright notice and this permission notice shall be included in |
wim | 0:201dfacbe0e5 | 14 | * all copies or substantial portions of the Software. |
wim | 0:201dfacbe0e5 | 15 | * |
wim | 0:201dfacbe0e5 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:201dfacbe0e5 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:201dfacbe0e5 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:201dfacbe0e5 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:201dfacbe0e5 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:201dfacbe0e5 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:201dfacbe0e5 | 22 | * THE SOFTWARE. |
wim | 0:201dfacbe0e5 | 23 | */ |
wim | 0:201dfacbe0e5 | 24 | |
wim | 0:201dfacbe0e5 | 25 | #ifndef TM1638_H |
wim | 0:201dfacbe0e5 | 26 | #define TM1638_H |
wim | 0:201dfacbe0e5 | 27 | |
wim | 0:201dfacbe0e5 | 28 | // Select one of the testboards for TM1638 LED controller |
wim | 0:201dfacbe0e5 | 29 | #include "TM1638_Config.h" |
wim | 0:201dfacbe0e5 | 30 | |
wim | 0:201dfacbe0e5 | 31 | /** An interface for driving TM1638 LED controller |
wim | 0:201dfacbe0e5 | 32 | * |
wim | 0:201dfacbe0e5 | 33 | * @code |
wim | 0:201dfacbe0e5 | 34 | * #include "mbed.h" |
wim | 0:201dfacbe0e5 | 35 | * #include "TM1638.h" |
wim | 0:201dfacbe0e5 | 36 | * |
wim | 0:201dfacbe0e5 | 37 | * DisplayData_t size is 16 bytes (8 grids @ 10 segments) |
wim | 0:201dfacbe0e5 | 38 | * TM1638::DisplayData_t all_str = {0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F, 0xFF,0x3F}; |
wim | 0:201dfacbe0e5 | 39 | * |
wim | 1:1f2453ed85d7 | 40 | * // KeyData_t size is 4 bytes |
wim | 0:201dfacbe0e5 | 41 | * TM1638::KeyData_t keydata; |
wim | 0:201dfacbe0e5 | 42 | * |
wim | 0:201dfacbe0e5 | 43 | * // TM1638 declaration |
wim | 0:201dfacbe0e5 | 44 | * TM1638 TM1638(p5,p6,p7, p8); |
wim | 0:201dfacbe0e5 | 45 | * |
wim | 0:201dfacbe0e5 | 46 | * int main() { |
wim | 0:201dfacbe0e5 | 47 | * TM1638.cls(); |
wim | 0:201dfacbe0e5 | 48 | * TM1638.writeData(all_str); |
wim | 0:201dfacbe0e5 | 49 | * wait(1); |
wim | 0:201dfacbe0e5 | 50 | * TM1638.setBrightness(TM1638_BRT0); |
wim | 0:201dfacbe0e5 | 51 | * wait(1); |
wim | 0:201dfacbe0e5 | 52 | * TM1638.setBrightness(TM1638_BRT3); |
wim | 0:201dfacbe0e5 | 53 | * |
wim | 0:201dfacbe0e5 | 54 | * while (1) { |
wim | 0:201dfacbe0e5 | 55 | * // Check and read keydata |
wim | 0:201dfacbe0e5 | 56 | * if (TM1638.getKeys(&keydata)) { |
wim | 0:201dfacbe0e5 | 57 | * 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 | 58 | * |
wim | 1:1f2453ed85d7 | 59 | * if (keydata[0] == 0x01) { //sw1 |
wim | 0:201dfacbe0e5 | 60 | * TM1638.cls(); |
wim | 0:201dfacbe0e5 | 61 | * TM1638.writeData(all_str); |
wim | 0:201dfacbe0e5 | 62 | * } |
wim | 0:201dfacbe0e5 | 63 | * } |
wim | 0:201dfacbe0e5 | 64 | * } |
wim | 0:201dfacbe0e5 | 65 | * } |
wim | 0:201dfacbe0e5 | 66 | * @endcode |
wim | 0:201dfacbe0e5 | 67 | */ |
wim | 0:201dfacbe0e5 | 68 | |
wim | 2:532ce15ea9ec | 69 | |
wim | 2:532ce15ea9ec | 70 | //TM1638 Display and Keymatrix data |
wim | 2:532ce15ea9ec | 71 | #define TM1638_MAX_NR_GRIDS 8 |
wim | 2:532ce15ea9ec | 72 | #define TM1638_BYTES_PER_GRID 2 |
wim | 2:532ce15ea9ec | 73 | //Significant bits Keymatrix data |
wim | 2:532ce15ea9ec | 74 | #define TM1638_KEY_MSK 0x77 |
wim | 2:532ce15ea9ec | 75 | |
wim | 0:201dfacbe0e5 | 76 | //Memory size in bytes for Display and Keymatrix |
wim | 2:532ce15ea9ec | 77 | #define TM1638_DISPLAY_MEM (TM1638_MAX_NR_GRIDS * TM1638_BYTES_PER_GRID) |
wim | 0:201dfacbe0e5 | 78 | #define TM1638_KEY_MEM 4 |
wim | 2:532ce15ea9ec | 79 | |
wim | 0:201dfacbe0e5 | 80 | |
wim | 0:201dfacbe0e5 | 81 | //Reserved bits for commands |
wim | 0:201dfacbe0e5 | 82 | #define TM1638_CMD_MSK 0xC0 |
wim | 0:201dfacbe0e5 | 83 | |
wim | 0:201dfacbe0e5 | 84 | //Data setting commands |
wim | 0:201dfacbe0e5 | 85 | #define TM1638_DATA_SET_CMD 0x40 |
wim | 0:201dfacbe0e5 | 86 | #define TM1638_DATA_WR 0x00 |
wim | 0:201dfacbe0e5 | 87 | #define TM1638_KEY_RD 0x02 |
wim | 0:201dfacbe0e5 | 88 | #define TM1638_ADDR_INC 0x00 |
wim | 0:201dfacbe0e5 | 89 | #define TM1638_ADDR_FIXED 0x04 |
wim | 0:201dfacbe0e5 | 90 | #define TM1638_MODE_NORM 0x00 |
wim | 0:201dfacbe0e5 | 91 | #define TM1638_MODE_TEST 0x08 |
wim | 0:201dfacbe0e5 | 92 | |
wim | 0:201dfacbe0e5 | 93 | //Address setting commands |
wim | 0:201dfacbe0e5 | 94 | #define TM1638_ADDR_SET_CMD 0xC0 |
wim | 0:201dfacbe0e5 | 95 | #define TM1638_ADDR_MSK 0x0F |
wim | 0:201dfacbe0e5 | 96 | |
wim | 0:201dfacbe0e5 | 97 | //Display control commands |
wim | 0:201dfacbe0e5 | 98 | #define TM1638_DSP_CTRL_CMD 0x80 |
wim | 0:201dfacbe0e5 | 99 | #define TM1638_BRT_MSK 0x07 |
wim | 0:201dfacbe0e5 | 100 | #define TM1638_BRT0 0x00 //Pulsewidth 1/16 |
wim | 0:201dfacbe0e5 | 101 | #define TM1638_BRT1 0x01 |
wim | 0:201dfacbe0e5 | 102 | #define TM1638_BRT2 0x02 |
wim | 0:201dfacbe0e5 | 103 | #define TM1638_BRT3 0x03 |
wim | 0:201dfacbe0e5 | 104 | #define TM1638_BRT4 0x04 |
wim | 0:201dfacbe0e5 | 105 | #define TM1638_BRT5 0x05 |
wim | 0:201dfacbe0e5 | 106 | #define TM1638_BRT6 0x06 |
wim | 0:201dfacbe0e5 | 107 | #define TM1638_BRT7 0x07 //Pulsewidth 14/16 |
wim | 0:201dfacbe0e5 | 108 | |
wim | 0:201dfacbe0e5 | 109 | #define TM1638_BRT_DEF TM1638_BRT3 |
wim | 0:201dfacbe0e5 | 110 | |
wim | 0:201dfacbe0e5 | 111 | #define TM1638_DSP_OFF 0x00 |
wim | 0:201dfacbe0e5 | 112 | #define TM1638_DSP_ON 0x08 |
wim | 0:201dfacbe0e5 | 113 | |
wim | 0:201dfacbe0e5 | 114 | |
wim | 0:201dfacbe0e5 | 115 | /** A class for driving TM1638 LED controller |
wim | 0:201dfacbe0e5 | 116 | * |
wim | 0:201dfacbe0e5 | 117 | * @brief Supports 8 Grids @ 10 Segments. |
wim | 0:201dfacbe0e5 | 118 | * Also supports a scanned keyboard of upto 24 keys. |
wim | 0:201dfacbe0e5 | 119 | * SPI bus interface device. |
wim | 0:201dfacbe0e5 | 120 | */ |
wim | 0:201dfacbe0e5 | 121 | class TM1638 { |
wim | 0:201dfacbe0e5 | 122 | public: |
wim | 4:b2bbdc58967e | 123 | /** Datatype for display data */ |
wim | 0:201dfacbe0e5 | 124 | typedef char DisplayData_t[TM1638_DISPLAY_MEM]; |
wim | 4:b2bbdc58967e | 125 | |
wim | 4:b2bbdc58967e | 126 | /** Datatypes for keymatrix data */ |
wim | 0:201dfacbe0e5 | 127 | typedef char KeyData_t[TM1638_KEY_MEM]; |
wim | 0:201dfacbe0e5 | 128 | |
wim | 0:201dfacbe0e5 | 129 | /** Constructor for class for driving TM1638 LED controller |
wim | 0:201dfacbe0e5 | 130 | * |
wim | 0:201dfacbe0e5 | 131 | * @brief Supports 8 Grids @ 10 segments. |
wim | 0:201dfacbe0e5 | 132 | * Also supports a scanned keyboard of upto 24 keys. |
wim | 0:201dfacbe0e5 | 133 | * SPI bus interface device. |
wim | 0:201dfacbe0e5 | 134 | * |
wim | 0:201dfacbe0e5 | 135 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:201dfacbe0e5 | 136 | */ |
wim | 0:201dfacbe0e5 | 137 | TM1638(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 0:201dfacbe0e5 | 138 | |
wim | 0:201dfacbe0e5 | 139 | /** Clear the screen and locate to 0 |
wim | 0:201dfacbe0e5 | 140 | */ |
wim | 0:201dfacbe0e5 | 141 | void cls(); |
wim | 0:201dfacbe0e5 | 142 | |
wim | 0:201dfacbe0e5 | 143 | /** Write databyte to TM1638 |
wim | 4:b2bbdc58967e | 144 | * @param char data byte written at given address |
wim | 0:201dfacbe0e5 | 145 | * @param int address display memory location to write byte |
wim | 0:201dfacbe0e5 | 146 | * @return none |
wim | 0:201dfacbe0e5 | 147 | */ |
wim | 4:b2bbdc58967e | 148 | void writeData(char data, int address); |
wim | 4:b2bbdc58967e | 149 | |
wim | 4:b2bbdc58967e | 150 | /** Write Display datablock to TM1638 |
wim | 4:b2bbdc58967e | 151 | * @param DisplayData_t data Array of TM1638_DISPLAY_MEM (=16) bytes for displaydata |
wim | 4:b2bbdc58967e | 152 | * @param length number bytes to write (valid range 0..(TM1638_MAX_NR_GRIDS * TM1638_BYTES_PER_GRID) (=16), when starting at address 0) |
wim | 4:b2bbdc58967e | 153 | * @param int address display memory location to write bytes (default = 0) |
wim | 4:b2bbdc58967e | 154 | * @return none |
wim | 4:b2bbdc58967e | 155 | */ |
wim | 4:b2bbdc58967e | 156 | void writeData(DisplayData_t data, int length = (TM1638_MAX_NR_GRIDS * TM1638_BYTES_PER_GRID), int address = 0); |
wim | 0:201dfacbe0e5 | 157 | |
wim | 0:201dfacbe0e5 | 158 | /** Read keydata block from TM1638 |
wim | 0:201dfacbe0e5 | 159 | * @param *keydata Ptr to Array of TM1638_KEY_MEM (=4) bytes for keydata |
wim | 0:201dfacbe0e5 | 160 | * @return bool keypress True when at least one key was pressed |
wim | 0:201dfacbe0e5 | 161 | * |
wim | 0:201dfacbe0e5 | 162 | * Note: Due to the hardware configuration the TM1638 key matrix scanner will detect multiple keys pressed at same time, |
wim | 0:201dfacbe0e5 | 163 | * but this may result in some spurious keys also being set in keypress data array. |
wim | 0:201dfacbe0e5 | 164 | * 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 | 165 | */ |
wim | 0:201dfacbe0e5 | 166 | bool getKeys(KeyData_t *keydata); |
wim | 0:201dfacbe0e5 | 167 | |
wim | 0:201dfacbe0e5 | 168 | /** Set Brightness |
wim | 0:201dfacbe0e5 | 169 | * |
wim | 4:b2bbdc58967e | 170 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle) |
wim | 0:201dfacbe0e5 | 171 | * @return none |
wim | 0:201dfacbe0e5 | 172 | */ |
wim | 0:201dfacbe0e5 | 173 | void setBrightness(char brightness = TM1638_BRT_DEF); |
wim | 0:201dfacbe0e5 | 174 | |
wim | 0:201dfacbe0e5 | 175 | /** Set the Display mode On/off |
wim | 0:201dfacbe0e5 | 176 | * |
wim | 0:201dfacbe0e5 | 177 | * @param bool display mode |
wim | 0:201dfacbe0e5 | 178 | */ |
wim | 0:201dfacbe0e5 | 179 | void setDisplay(bool on); |
wim | 0:201dfacbe0e5 | 180 | |
wim | 0:201dfacbe0e5 | 181 | private: |
wim | 0:201dfacbe0e5 | 182 | SPI _spi; |
wim | 0:201dfacbe0e5 | 183 | DigitalOut _cs; |
wim | 0:201dfacbe0e5 | 184 | char _display; |
wim | 0:201dfacbe0e5 | 185 | char _bright; |
wim | 0:201dfacbe0e5 | 186 | |
wim | 0:201dfacbe0e5 | 187 | /** Init the SPI interface and the controller |
wim | 0:201dfacbe0e5 | 188 | * @param none |
wim | 0:201dfacbe0e5 | 189 | * @return none |
wim | 0:201dfacbe0e5 | 190 | */ |
wim | 0:201dfacbe0e5 | 191 | void _init(); |
wim | 0:201dfacbe0e5 | 192 | |
wim | 0:201dfacbe0e5 | 193 | /** Helper to reverse all command or databits. The TM1638 expects LSB first, whereas SPI is MSB first |
wim | 0:201dfacbe0e5 | 194 | * @param char data |
wim | 0:201dfacbe0e5 | 195 | * @return bitreversed data |
wim | 0:201dfacbe0e5 | 196 | */ |
wim | 0:201dfacbe0e5 | 197 | char _flip(char data); |
wim | 0:201dfacbe0e5 | 198 | |
wim | 0:201dfacbe0e5 | 199 | /** Write command and parameter to TM1638 |
wim | 0:201dfacbe0e5 | 200 | * @param int cmd Command byte |
wim | 0:201dfacbe0e5 | 201 | * &Param int data Parameters for command |
wim | 0:201dfacbe0e5 | 202 | * @return none |
wim | 0:201dfacbe0e5 | 203 | */ |
wim | 0:201dfacbe0e5 | 204 | void _writeCmd(int cmd, int data); |
wim | 0:201dfacbe0e5 | 205 | }; |
wim | 0:201dfacbe0e5 | 206 | |
wim | 0:201dfacbe0e5 | 207 | |
wim | 0:201dfacbe0e5 | 208 | #if (LEDKEY8_TEST == 1) |
wim | 0:201dfacbe0e5 | 209 | // Derived class for TM1638 used in LED&KEY display unit |
wim | 0:201dfacbe0e5 | 210 | // |
wim | 0:201dfacbe0e5 | 211 | |
wim | 0:201dfacbe0e5 | 212 | #include "Font_7Seg.h" |
wim | 0:201dfacbe0e5 | 213 | |
wim | 0:201dfacbe0e5 | 214 | #define LEDKEY8_NR_GRIDS 8 |
wim | 0:201dfacbe0e5 | 215 | #define LEDKEY8_NR_DIGITS 8 |
wim | 0:201dfacbe0e5 | 216 | #define LEDKEY8_NR_UDC 8 |
wim | 0:201dfacbe0e5 | 217 | |
wim | 1:1f2453ed85d7 | 218 | //Access to 8 Switches |
wim | 1:1f2453ed85d7 | 219 | #define LEDKEY8_SW1_IDX 0 |
wim | 1:1f2453ed85d7 | 220 | #define LEDKEY8_SW1_BIT 0x01 |
wim | 1:1f2453ed85d7 | 221 | #define LEDKEY8_SW2_IDX 1 |
wim | 1:1f2453ed85d7 | 222 | #define LEDKEY8_SW2_BIT 0x01 |
wim | 1:1f2453ed85d7 | 223 | #define LEDKEY8_SW3_IDX 2 |
wim | 1:1f2453ed85d7 | 224 | #define LEDKEY8_SW3_BIT 0x01 |
wim | 1:1f2453ed85d7 | 225 | #define LEDKEY8_SW4_IDX 3 |
wim | 1:1f2453ed85d7 | 226 | #define LEDKEY8_SW4_BIT 0x01 |
wim | 1:1f2453ed85d7 | 227 | |
wim | 1:1f2453ed85d7 | 228 | #define LEDKEY8_SW5_IDX 0 |
wim | 1:1f2453ed85d7 | 229 | #define LEDKEY8_SW5_BIT 0x10 |
wim | 1:1f2453ed85d7 | 230 | #define LEDKEY8_SW6_IDX 1 |
wim | 1:1f2453ed85d7 | 231 | #define LEDKEY8_SW6_BIT 0x10 |
wim | 1:1f2453ed85d7 | 232 | #define LEDKEY8_SW7_IDX 2 |
wim | 1:1f2453ed85d7 | 233 | #define LEDKEY8_SW7_BIT 0x10 |
wim | 1:1f2453ed85d7 | 234 | #define LEDKEY8_SW8_IDX 3 |
wim | 1:1f2453ed85d7 | 235 | #define LEDKEY8_SW8_BIT 0x10 |
wim | 1:1f2453ed85d7 | 236 | |
wim | 0:201dfacbe0e5 | 237 | /** Constructor for class for driving TM1638 controller as used in LEDKEY8 |
wim | 0:201dfacbe0e5 | 238 | * |
wim | 0:201dfacbe0e5 | 239 | * @brief Supports 8 Digits of 7 Segments + DP + LED Icons, Also supports a scanned keyboard of 8 keys. |
wim | 0:201dfacbe0e5 | 240 | * |
wim | 0:201dfacbe0e5 | 241 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:201dfacbe0e5 | 242 | */ |
wim | 0:201dfacbe0e5 | 243 | class TM1638_LEDKEY8 : public TM1638, public Stream { |
wim | 0:201dfacbe0e5 | 244 | public: |
wim | 0:201dfacbe0e5 | 245 | |
wim | 0:201dfacbe0e5 | 246 | /** Enums for Icons */ |
wim | 1:1f2453ed85d7 | 247 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:201dfacbe0e5 | 248 | enum Icon { |
wim | 4:b2bbdc58967e | 249 | LD1 = (1<<24) | S7_LD1, /**< LED1 */ |
wim | 4:b2bbdc58967e | 250 | LD2 = (2<<24) | S7_LD2, /**< LED2 */ |
wim | 4:b2bbdc58967e | 251 | LD3 = (3<<24) | S7_LD3, /**< LED3 */ |
wim | 4:b2bbdc58967e | 252 | LD4 = (4<<24) | S7_LD4, /**< LED4 */ |
wim | 4:b2bbdc58967e | 253 | LD5 = (5<<24) | S7_LD5, /**< LED5 */ |
wim | 4:b2bbdc58967e | 254 | LD6 = (6<<24) | S7_LD6, /**< LED6 */ |
wim | 4:b2bbdc58967e | 255 | LD7 = (7<<24) | S7_LD7, /**< LED7 */ |
wim | 4:b2bbdc58967e | 256 | LD8 = (8<<24) | S7_LD8, /**< LED8 */ |
wim | 0:201dfacbe0e5 | 257 | |
wim | 4:b2bbdc58967e | 258 | DP1 = (1<<24) | S7_DP1, /**< Decimal Point 1 */ |
wim | 4:b2bbdc58967e | 259 | DP2 = (2<<24) | S7_DP2, /**< Decimal Point 2 */ |
wim | 4:b2bbdc58967e | 260 | DP3 = (3<<24) | S7_DP3, /**< Decimal Point 3 */ |
wim | 4:b2bbdc58967e | 261 | DP4 = (4<<24) | S7_DP4, /**< Decimal Point 4 */ |
wim | 4:b2bbdc58967e | 262 | DP5 = (5<<24) | S7_DP5, /**< Decimal Point 5 */ |
wim | 4:b2bbdc58967e | 263 | DP6 = (6<<24) | S7_DP6, /**< Decimal Point 6 */ |
wim | 4:b2bbdc58967e | 264 | DP7 = (7<<24) | S7_DP7, /**< Decimal Point 7 */ |
wim | 4:b2bbdc58967e | 265 | DP8 = (8<<24) | S7_DP8 /**< Decimal Point 8 */ |
wim | 0:201dfacbe0e5 | 266 | }; |
wim | 0:201dfacbe0e5 | 267 | |
wim | 0:201dfacbe0e5 | 268 | typedef char UDCData_t[LEDKEY8_NR_UDC]; |
wim | 0:201dfacbe0e5 | 269 | |
wim | 0:201dfacbe0e5 | 270 | /** Constructor for class for driving TM1638 LED controller as used in LEDKEY8 |
wim | 0:201dfacbe0e5 | 271 | * |
wim | 0:201dfacbe0e5 | 272 | * @brief Supports 8 Digits of 7 Segments + DP + LED Icons. Also supports a scanned keyboard of 8 keys. |
wim | 0:201dfacbe0e5 | 273 | * |
wim | 0:201dfacbe0e5 | 274 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:201dfacbe0e5 | 275 | */ |
wim | 0:201dfacbe0e5 | 276 | TM1638_LEDKEY8(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 0:201dfacbe0e5 | 277 | |
wim | 0:201dfacbe0e5 | 278 | #if DOXYGEN_ONLY |
wim | 0:201dfacbe0e5 | 279 | /** Write a character to the Display |
wim | 0:201dfacbe0e5 | 280 | * |
wim | 0:201dfacbe0e5 | 281 | * @param c The character to write to the display |
wim | 0:201dfacbe0e5 | 282 | */ |
wim | 0:201dfacbe0e5 | 283 | int putc(int c); |
wim | 0:201dfacbe0e5 | 284 | |
wim | 0:201dfacbe0e5 | 285 | /** Write a formatted string to the Display |
wim | 0:201dfacbe0e5 | 286 | * |
wim | 0:201dfacbe0e5 | 287 | * @param format A printf-style format string, followed by the |
wim | 0:201dfacbe0e5 | 288 | * variables to use in formatting the string. |
wim | 0:201dfacbe0e5 | 289 | */ |
wim | 0:201dfacbe0e5 | 290 | int printf(const char* format, ...); |
wim | 0:201dfacbe0e5 | 291 | #endif |
wim | 0:201dfacbe0e5 | 292 | |
wim | 0:201dfacbe0e5 | 293 | /** Locate cursor to a screen column |
wim | 0:201dfacbe0e5 | 294 | * |
wim | 0:201dfacbe0e5 | 295 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:201dfacbe0e5 | 296 | */ |
wim | 0:201dfacbe0e5 | 297 | void locate(int column); |
wim | 0:201dfacbe0e5 | 298 | |
wim | 0:201dfacbe0e5 | 299 | /** Clear the screen and locate to 0 |
wim | 0:201dfacbe0e5 | 300 | * @param bool clrAll Clear Icons also (default = false) |
wim | 0:201dfacbe0e5 | 301 | */ |
wim | 0:201dfacbe0e5 | 302 | void cls(bool clrAll = false); |
wim | 0:201dfacbe0e5 | 303 | |
wim | 0:201dfacbe0e5 | 304 | /** Set Icon |
wim | 0:201dfacbe0e5 | 305 | * |
wim | 1:1f2453ed85d7 | 306 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:201dfacbe0e5 | 307 | * @return none |
wim | 0:201dfacbe0e5 | 308 | */ |
wim | 0:201dfacbe0e5 | 309 | void setIcon(Icon icon); |
wim | 0:201dfacbe0e5 | 310 | |
wim | 0:201dfacbe0e5 | 311 | /** Clr Icon |
wim | 0:201dfacbe0e5 | 312 | * |
wim | 1:1f2453ed85d7 | 313 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:201dfacbe0e5 | 314 | * @return none |
wim | 0:201dfacbe0e5 | 315 | */ |
wim | 0:201dfacbe0e5 | 316 | void clrIcon(Icon icon); |
wim | 0:201dfacbe0e5 | 317 | |
wim | 0:201dfacbe0e5 | 318 | /** Set User Defined Characters (UDC) |
wim | 0:201dfacbe0e5 | 319 | * |
wim | 0:201dfacbe0e5 | 320 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 0:201dfacbe0e5 | 321 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 0:201dfacbe0e5 | 322 | */ |
wim | 0:201dfacbe0e5 | 323 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 0:201dfacbe0e5 | 324 | |
wim | 0:201dfacbe0e5 | 325 | |
wim | 0:201dfacbe0e5 | 326 | /** Number of screen columns |
wim | 0:201dfacbe0e5 | 327 | * |
wim | 0:201dfacbe0e5 | 328 | * @param none |
wim | 0:201dfacbe0e5 | 329 | * @return columns |
wim | 0:201dfacbe0e5 | 330 | */ |
wim | 0:201dfacbe0e5 | 331 | int columns(); |
wim | 0:201dfacbe0e5 | 332 | |
wim | 0:201dfacbe0e5 | 333 | /** Write databyte to TM1638 |
wim | 4:b2bbdc58967e | 334 | * @param char data byte written at given address |
wim | 0:201dfacbe0e5 | 335 | * @param int address display memory location to write byte |
wim | 0:201dfacbe0e5 | 336 | * @return none |
wim | 0:201dfacbe0e5 | 337 | */ |
wim | 4:b2bbdc58967e | 338 | void writeData(char data, int address){ |
wim | 4:b2bbdc58967e | 339 | TM1638::writeData(data, address); |
wim | 4:b2bbdc58967e | 340 | } |
wim | 4:b2bbdc58967e | 341 | |
wim | 4:b2bbdc58967e | 342 | /** Write Display datablock to TM1638 |
wim | 4:b2bbdc58967e | 343 | * @param DisplayData_t data Array of TM1638_DISPLAY_MEM (=16) bytes for displaydata |
wim | 4:b2bbdc58967e | 344 | * @param length number bytes to write (valid range 0..(LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID) (=16), when starting at address 0) |
wim | 4:b2bbdc58967e | 345 | * @param int address display memory location to write bytes (default = 0) |
wim | 4:b2bbdc58967e | 346 | * @return none |
wim | 4:b2bbdc58967e | 347 | */ |
wim | 4:b2bbdc58967e | 348 | void writeData(DisplayData_t data, int length = (LEDKEY8_NR_GRIDS * TM1638_BYTES_PER_GRID), int address = 0) { |
wim | 4:b2bbdc58967e | 349 | TM1638::writeData(data, length, address); |
wim | 4:b2bbdc58967e | 350 | } |
wim | 4:b2bbdc58967e | 351 | |
wim | 4:b2bbdc58967e | 352 | protected: |
wim | 4:b2bbdc58967e | 353 | // Stream implementation functions |
wim | 4:b2bbdc58967e | 354 | virtual int _putc(int value); |
wim | 4:b2bbdc58967e | 355 | virtual int _getc(); |
wim | 4:b2bbdc58967e | 356 | |
wim | 4:b2bbdc58967e | 357 | private: |
wim | 4:b2bbdc58967e | 358 | int _column; |
wim | 4:b2bbdc58967e | 359 | int _columns; |
wim | 4:b2bbdc58967e | 360 | |
wim | 4:b2bbdc58967e | 361 | DisplayData_t _displaybuffer; |
wim | 4:b2bbdc58967e | 362 | UDCData_t _UDC_7S; |
wim | 4:b2bbdc58967e | 363 | }; |
wim | 4:b2bbdc58967e | 364 | #endif |
wim | 4:b2bbdc58967e | 365 | |
wim | 4:b2bbdc58967e | 366 | |
wim | 4:b2bbdc58967e | 367 | #if (QYF_TEST == 1) |
wim | 4:b2bbdc58967e | 368 | // Derived class for TM1638 used in QYF-TM1638 display unit |
wim | 4:b2bbdc58967e | 369 | // |
wim | 4:b2bbdc58967e | 370 | |
wim | 4:b2bbdc58967e | 371 | #include "Font_7Seg.h" |
wim | 4:b2bbdc58967e | 372 | |
wim | 4:b2bbdc58967e | 373 | #define QYF_NR_GRIDS 8 |
wim | 4:b2bbdc58967e | 374 | #define QYF_NR_DIGITS 8 |
wim | 4:b2bbdc58967e | 375 | #define QYF_NR_UDC 8 |
wim | 4:b2bbdc58967e | 376 | |
wim | 4:b2bbdc58967e | 377 | //Access to 16 Switches |
wim | 4:b2bbdc58967e | 378 | #define QYF_SW1_IDX 0 |
wim | 4:b2bbdc58967e | 379 | #define QYF_SW1_BIT 0x04 |
wim | 4:b2bbdc58967e | 380 | #define QYF_SW2_IDX 0 |
wim | 4:b2bbdc58967e | 381 | #define QYF_SW2_BIT 0x40 |
wim | 4:b2bbdc58967e | 382 | #define QYF_SW3_IDX 1 |
wim | 4:b2bbdc58967e | 383 | #define QYF_SW3_BIT 0x04 |
wim | 4:b2bbdc58967e | 384 | #define QYF_SW4_IDX 1 |
wim | 4:b2bbdc58967e | 385 | #define QYF_SW4_BIT 0x40 |
wim | 4:b2bbdc58967e | 386 | |
wim | 4:b2bbdc58967e | 387 | #define QYF_SW5_IDX 2 |
wim | 4:b2bbdc58967e | 388 | #define QYF_SW5_BIT 0x04 |
wim | 4:b2bbdc58967e | 389 | #define QYF_SW6_IDX 2 |
wim | 4:b2bbdc58967e | 390 | #define QYF_SW6_BIT 0x40 |
wim | 4:b2bbdc58967e | 391 | #define QYF_SW7_IDX 3 |
wim | 4:b2bbdc58967e | 392 | #define QYF_SW7_BIT 0x04 |
wim | 4:b2bbdc58967e | 393 | #define QYF_SW8_IDX 3 |
wim | 4:b2bbdc58967e | 394 | #define QYF_SW8_BIT 0x40 |
wim | 4:b2bbdc58967e | 395 | |
wim | 4:b2bbdc58967e | 396 | #define QYF_SW9_IDX 0 |
wim | 4:b2bbdc58967e | 397 | #define QYF_SW9_BIT 0x02 |
wim | 4:b2bbdc58967e | 398 | #define QYF_SW10_IDX 0 |
wim | 4:b2bbdc58967e | 399 | #define QYF_SW10_BIT 0x20 |
wim | 4:b2bbdc58967e | 400 | #define QYF_SW11_IDX 1 |
wim | 4:b2bbdc58967e | 401 | #define QYF_SW11_BIT 0x02 |
wim | 4:b2bbdc58967e | 402 | #define QYF_SW12_IDX 1 |
wim | 4:b2bbdc58967e | 403 | #define QYF_SW12_BIT 0x20 |
wim | 4:b2bbdc58967e | 404 | |
wim | 4:b2bbdc58967e | 405 | #define QYF_SW13_IDX 2 |
wim | 4:b2bbdc58967e | 406 | #define QYF_SW13_BIT 0x02 |
wim | 4:b2bbdc58967e | 407 | #define QYF_SW14_IDX 2 |
wim | 4:b2bbdc58967e | 408 | #define QYF_SW14_BIT 0x20 |
wim | 4:b2bbdc58967e | 409 | #define QYF_SW15_IDX 3 |
wim | 4:b2bbdc58967e | 410 | #define QYF_SW15_BIT 0x02 |
wim | 4:b2bbdc58967e | 411 | #define QYF_SW16_IDX 3 |
wim | 4:b2bbdc58967e | 412 | #define QYF_SW16_BIT 0x20 |
wim | 4:b2bbdc58967e | 413 | |
wim | 4:b2bbdc58967e | 414 | /** Constructor for class for driving TM1638 controller as used in QYF |
wim | 4:b2bbdc58967e | 415 | * |
wim | 4:b2bbdc58967e | 416 | * @brief Supports 8 Digits of 7 Segments + DP, Also supports a scanned keyboard of 16 keys. |
wim | 4:b2bbdc58967e | 417 | * |
wim | 4:b2bbdc58967e | 418 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 4:b2bbdc58967e | 419 | */ |
wim | 4:b2bbdc58967e | 420 | class TM1638_QYF : public TM1638, public Stream { |
wim | 4:b2bbdc58967e | 421 | public: |
wim | 4:b2bbdc58967e | 422 | |
wim | 4:b2bbdc58967e | 423 | /** Enums for Icons */ |
wim | 4:b2bbdc58967e | 424 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 4:b2bbdc58967e | 425 | enum Icon { |
wim | 4:b2bbdc58967e | 426 | DP1 = (8<<24) | S7_DP1, /**< Decimal Point 1 */ |
wim | 4:b2bbdc58967e | 427 | DP2 = (8<<24) | S7_DP2, /**< Decimal Point 2 */ |
wim | 4:b2bbdc58967e | 428 | DP3 = (8<<24) | S7_DP3, /**< Decimal Point 3 */ |
wim | 4:b2bbdc58967e | 429 | DP4 = (8<<24) | S7_DP4, /**< Decimal Point 4 */ |
wim | 4:b2bbdc58967e | 430 | DP5 = (8<<24) | S7_DP5, /**< Decimal Point 5 */ |
wim | 4:b2bbdc58967e | 431 | DP6 = (8<<24) | S7_DP6, /**< Decimal Point 6 */ |
wim | 4:b2bbdc58967e | 432 | DP7 = (8<<24) | S7_DP7, /**< Decimal Point 7 */ |
wim | 4:b2bbdc58967e | 433 | DP8 = (8<<24) | S7_DP8 /**< Decimal Point 8 */ |
wim | 4:b2bbdc58967e | 434 | }; |
wim | 4:b2bbdc58967e | 435 | |
wim | 4:b2bbdc58967e | 436 | typedef char UDCData_t[QYF_NR_UDC]; |
wim | 4:b2bbdc58967e | 437 | |
wim | 4:b2bbdc58967e | 438 | /** Constructor for class for driving TM1638 LED controller as used in QYF |
wim | 4:b2bbdc58967e | 439 | * |
wim | 4:b2bbdc58967e | 440 | * @brief Supports 8 Digits of 7 Segments + DP Icons. Also supports a scanned keyboard of 16 keys. |
wim | 4:b2bbdc58967e | 441 | * |
wim | 4:b2bbdc58967e | 442 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 4:b2bbdc58967e | 443 | */ |
wim | 4:b2bbdc58967e | 444 | TM1638_QYF(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 4:b2bbdc58967e | 445 | |
wim | 4:b2bbdc58967e | 446 | #if DOXYGEN_ONLY |
wim | 4:b2bbdc58967e | 447 | /** Write a character to the Display |
wim | 4:b2bbdc58967e | 448 | * |
wim | 4:b2bbdc58967e | 449 | * @param c The character to write to the display |
wim | 4:b2bbdc58967e | 450 | */ |
wim | 4:b2bbdc58967e | 451 | int putc(int c); |
wim | 4:b2bbdc58967e | 452 | |
wim | 4:b2bbdc58967e | 453 | /** Write a formatted string to the Display |
wim | 4:b2bbdc58967e | 454 | * |
wim | 4:b2bbdc58967e | 455 | * @param format A printf-style format string, followed by the |
wim | 4:b2bbdc58967e | 456 | * variables to use in formatting the string. |
wim | 4:b2bbdc58967e | 457 | */ |
wim | 4:b2bbdc58967e | 458 | int printf(const char* format, ...); |
wim | 4:b2bbdc58967e | 459 | #endif |
wim | 4:b2bbdc58967e | 460 | |
wim | 4:b2bbdc58967e | 461 | /** Locate cursor to a screen column |
wim | 4:b2bbdc58967e | 462 | * |
wim | 4:b2bbdc58967e | 463 | * @param column The horizontal position from the left, indexed from 0 |
wim | 4:b2bbdc58967e | 464 | */ |
wim | 4:b2bbdc58967e | 465 | void locate(int column); |
wim | 4:b2bbdc58967e | 466 | |
wim | 4:b2bbdc58967e | 467 | /** Clear the screen and locate to 0 |
wim | 4:b2bbdc58967e | 468 | * @param bool clrAll Clear Icons also (default = false) |
wim | 4:b2bbdc58967e | 469 | */ |
wim | 4:b2bbdc58967e | 470 | void cls(bool clrAll = false); |
wim | 4:b2bbdc58967e | 471 | |
wim | 4:b2bbdc58967e | 472 | /** Set Icon |
wim | 4:b2bbdc58967e | 473 | * |
wim | 4:b2bbdc58967e | 474 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 4:b2bbdc58967e | 475 | * @return none |
wim | 4:b2bbdc58967e | 476 | */ |
wim | 4:b2bbdc58967e | 477 | void setIcon(Icon icon); |
wim | 4:b2bbdc58967e | 478 | |
wim | 4:b2bbdc58967e | 479 | /** Clr Icon |
wim | 4:b2bbdc58967e | 480 | * |
wim | 4:b2bbdc58967e | 481 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 4:b2bbdc58967e | 482 | * @return none |
wim | 4:b2bbdc58967e | 483 | */ |
wim | 4:b2bbdc58967e | 484 | void clrIcon(Icon icon); |
wim | 4:b2bbdc58967e | 485 | |
wim | 4:b2bbdc58967e | 486 | /** Set User Defined Characters (UDC) |
wim | 4:b2bbdc58967e | 487 | * |
wim | 4:b2bbdc58967e | 488 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 4:b2bbdc58967e | 489 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 4:b2bbdc58967e | 490 | */ |
wim | 4:b2bbdc58967e | 491 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 4:b2bbdc58967e | 492 | |
wim | 4:b2bbdc58967e | 493 | |
wim | 4:b2bbdc58967e | 494 | /** Number of screen columns |
wim | 4:b2bbdc58967e | 495 | * |
wim | 4:b2bbdc58967e | 496 | * @param none |
wim | 4:b2bbdc58967e | 497 | * @return columns |
wim | 4:b2bbdc58967e | 498 | */ |
wim | 4:b2bbdc58967e | 499 | int columns(); |
wim | 4:b2bbdc58967e | 500 | |
wim | 4:b2bbdc58967e | 501 | /** Write databyte to TM1638 |
wim | 4:b2bbdc58967e | 502 | * @param char data byte written at given address |
wim | 4:b2bbdc58967e | 503 | * @param int address display memory location to write byte |
wim | 4:b2bbdc58967e | 504 | * @return none |
wim | 4:b2bbdc58967e | 505 | */ |
wim | 4:b2bbdc58967e | 506 | void writeData(char data, int address){ |
wim | 4:b2bbdc58967e | 507 | TM1638::writeData(data, address); |
wim | 0:201dfacbe0e5 | 508 | } |
wim | 0:201dfacbe0e5 | 509 | |
wim | 0:201dfacbe0e5 | 510 | /** Write Display datablock to TM1638 |
wim | 4:b2bbdc58967e | 511 | * @param DisplayData_t data Array of TM1638_DISPLAY_MEM (=16) bytes for displaydata |
wim | 4:b2bbdc58967e | 512 | * @param length number bytes to write (valid range 0..(QYF_NR_GRIDS * TM1638_BYTES_PER_GRID) (=16), when starting at address 0) |
wim | 4:b2bbdc58967e | 513 | * @param int address display memory location to write bytes (default = 0) |
wim | 0:201dfacbe0e5 | 514 | * @return none |
wim | 0:201dfacbe0e5 | 515 | */ |
wim | 4:b2bbdc58967e | 516 | void writeData(DisplayData_t data, int length = (QYF_NR_GRIDS * TM1638_BYTES_PER_GRID), int address = 0) { |
wim | 4:b2bbdc58967e | 517 | TM1638::writeData(data, length, address); |
wim | 4:b2bbdc58967e | 518 | } |
wim | 4:b2bbdc58967e | 519 | |
wim | 4:b2bbdc58967e | 520 | protected: |
wim | 4:b2bbdc58967e | 521 | // Stream implementation functions |
wim | 4:b2bbdc58967e | 522 | virtual int _putc(int value); |
wim | 4:b2bbdc58967e | 523 | virtual int _getc(); |
wim | 4:b2bbdc58967e | 524 | |
wim | 4:b2bbdc58967e | 525 | private: |
wim | 4:b2bbdc58967e | 526 | int _column; |
wim | 4:b2bbdc58967e | 527 | int _columns; |
wim | 4:b2bbdc58967e | 528 | |
wim | 4:b2bbdc58967e | 529 | DisplayData_t _displaybuffer; |
wim | 4:b2bbdc58967e | 530 | UDCData_t _UDC_7S; |
wim | 4:b2bbdc58967e | 531 | }; |
wim | 4:b2bbdc58967e | 532 | #endif |
wim | 4:b2bbdc58967e | 533 | |
wim | 4:b2bbdc58967e | 534 | #if (LKM1638_TEST == 1) |
wim | 4:b2bbdc58967e | 535 | // Derived class for TM1638 used in LKM1638 TM1638 display unit |
wim | 4:b2bbdc58967e | 536 | // |
wim | 4:b2bbdc58967e | 537 | |
wim | 4:b2bbdc58967e | 538 | #include "Font_7Seg.h" |
wim | 4:b2bbdc58967e | 539 | |
wim | 4:b2bbdc58967e | 540 | #define LKM1638_NR_GRIDS 8 |
wim | 4:b2bbdc58967e | 541 | #define LKM1638_NR_DIGITS 8 |
wim | 4:b2bbdc58967e | 542 | #define LKM1638_NR_UDC 8 |
wim | 4:b2bbdc58967e | 543 | |
wim | 4:b2bbdc58967e | 544 | //Access to 8 Switches |
wim | 4:b2bbdc58967e | 545 | #define LKM1638_SW1_IDX 0 |
wim | 4:b2bbdc58967e | 546 | #define LKM1638_SW1_BIT 0x01 |
wim | 4:b2bbdc58967e | 547 | #define LKM1638_SW2_IDX 1 |
wim | 4:b2bbdc58967e | 548 | #define LKM1638_SW2_BIT 0x01 |
wim | 4:b2bbdc58967e | 549 | #define LKM1638_SW3_IDX 2 |
wim | 4:b2bbdc58967e | 550 | #define LKM1638_SW3_BIT 0x01 |
wim | 4:b2bbdc58967e | 551 | #define LKM1638_SW4_IDX 3 |
wim | 4:b2bbdc58967e | 552 | #define LKM1638_SW4_BIT 0x01 |
wim | 4:b2bbdc58967e | 553 | |
wim | 4:b2bbdc58967e | 554 | #define LKM1638_SW5_IDX 0 |
wim | 4:b2bbdc58967e | 555 | #define LKM1638_SW5_BIT 0x10 |
wim | 4:b2bbdc58967e | 556 | #define LKM1638_SW6_IDX 1 |
wim | 4:b2bbdc58967e | 557 | #define LKM1638_SW6_BIT 0x10 |
wim | 4:b2bbdc58967e | 558 | #define LKM1638_SW7_IDX 2 |
wim | 4:b2bbdc58967e | 559 | #define LKM1638_SW7_BIT 0x10 |
wim | 4:b2bbdc58967e | 560 | #define LKM1638_SW8_IDX 3 |
wim | 4:b2bbdc58967e | 561 | #define LKM1638_SW8_BIT 0x10 |
wim | 4:b2bbdc58967e | 562 | |
wim | 4:b2bbdc58967e | 563 | /** Constructor for class for driving TM1638 controller as used in LKM1638 |
wim | 4:b2bbdc58967e | 564 | * |
wim | 4:b2bbdc58967e | 565 | * @brief Supports 8 Digits of 7 Segments + DP, Also supports 8 Bi-color LEDs and a scanned keyboard of 8 keys. |
wim | 4:b2bbdc58967e | 566 | * |
wim | 4:b2bbdc58967e | 567 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 4:b2bbdc58967e | 568 | */ |
wim | 4:b2bbdc58967e | 569 | class TM1638_LKM1638 : public TM1638, public Stream { |
wim | 4:b2bbdc58967e | 570 | public: |
wim | 4:b2bbdc58967e | 571 | |
wim | 4:b2bbdc58967e | 572 | /** Enums for Icons */ |
wim | 4:b2bbdc58967e | 573 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 4:b2bbdc58967e | 574 | enum Icon { |
wim | 4:b2bbdc58967e | 575 | DP1 = (1<<24) | S7_DP1, /**< Decimal Point 1 */ |
wim | 4:b2bbdc58967e | 576 | DP2 = (2<<24) | S7_DP2, /**< Decimal Point 2 */ |
wim | 4:b2bbdc58967e | 577 | DP3 = (3<<24) | S7_DP3, /**< Decimal Point 3 */ |
wim | 4:b2bbdc58967e | 578 | DP4 = (4<<24) | S7_DP4, /**< Decimal Point 4 */ |
wim | 4:b2bbdc58967e | 579 | DP5 = (5<<24) | S7_DP5, /**< Decimal Point 5 */ |
wim | 4:b2bbdc58967e | 580 | DP6 = (6<<24) | S7_DP6, /**< Decimal Point 6 */ |
wim | 4:b2bbdc58967e | 581 | DP7 = (7<<24) | S7_DP7, /**< Decimal Point 7 */ |
wim | 4:b2bbdc58967e | 582 | DP8 = (8<<24) | S7_DP8, /**< Decimal Point 8 */ |
wim | 4:b2bbdc58967e | 583 | |
wim | 4:b2bbdc58967e | 584 | GR1 = (1<<24) | S7_GR1, /**< Green LED 1 */ |
wim | 4:b2bbdc58967e | 585 | GR2 = (2<<24) | S7_GR2, /**< Green LED 2 */ |
wim | 4:b2bbdc58967e | 586 | GR3 = (3<<24) | S7_GR3, /**< Green LED 3 */ |
wim | 4:b2bbdc58967e | 587 | GR4 = (4<<24) | S7_GR4, /**< Green LED 4 */ |
wim | 4:b2bbdc58967e | 588 | GR5 = (5<<24) | S7_GR5, /**< Green LED 5 */ |
wim | 4:b2bbdc58967e | 589 | GR6 = (6<<24) | S7_GR6, /**< Green LED 6 */ |
wim | 4:b2bbdc58967e | 590 | GR7 = (7<<24) | S7_GR7, /**< Green LED 7 */ |
wim | 4:b2bbdc58967e | 591 | GR8 = (8<<24) | S7_GR8, /**< Green LED 8 */ |
wim | 4:b2bbdc58967e | 592 | |
wim | 4:b2bbdc58967e | 593 | RD1 = (1<<24) | S7_RD1, /**< Red LED 1 */ |
wim | 4:b2bbdc58967e | 594 | RD2 = (2<<24) | S7_RD2, /**< Red LED 2 */ |
wim | 4:b2bbdc58967e | 595 | RD3 = (3<<24) | S7_RD3, /**< Red LED 3 */ |
wim | 4:b2bbdc58967e | 596 | RD4 = (4<<24) | S7_RD4, /**< Red LED 4 */ |
wim | 4:b2bbdc58967e | 597 | RD5 = (5<<24) | S7_RD5, /**< Red LED 5 */ |
wim | 4:b2bbdc58967e | 598 | RD6 = (6<<24) | S7_RD6, /**< Red LED 6 */ |
wim | 4:b2bbdc58967e | 599 | RD7 = (7<<24) | S7_RD7, /**< Red LED 7 */ |
wim | 4:b2bbdc58967e | 600 | RD8 = (8<<24) | S7_RD8, /**< Red LED 8 */ |
wim | 4:b2bbdc58967e | 601 | |
wim | 4:b2bbdc58967e | 602 | YL1 = (1<<24) | S7_YL1, /**< Yellow LED 1 */ |
wim | 4:b2bbdc58967e | 603 | YL2 = (2<<24) | S7_YL2, /**< Yellow LED 2 */ |
wim | 4:b2bbdc58967e | 604 | YL3 = (3<<24) | S7_YL3, /**< Yellow LED 3 */ |
wim | 4:b2bbdc58967e | 605 | YL4 = (4<<24) | S7_YL4, /**< Yellow LED 4 */ |
wim | 4:b2bbdc58967e | 606 | YL5 = (5<<24) | S7_YL5, /**< Yellow LED 5 */ |
wim | 4:b2bbdc58967e | 607 | YL6 = (6<<24) | S7_YL6, /**< Yellow LED 6 */ |
wim | 4:b2bbdc58967e | 608 | YL7 = (7<<24) | S7_YL7, /**< Yellow LED 7 */ |
wim | 4:b2bbdc58967e | 609 | YL8 = (8<<24) | S7_YL8 /**< Yellow LED 8 */ |
wim | 4:b2bbdc58967e | 610 | }; |
wim | 4:b2bbdc58967e | 611 | |
wim | 4:b2bbdc58967e | 612 | typedef char UDCData_t[LKM1638_NR_UDC]; |
wim | 4:b2bbdc58967e | 613 | |
wim | 4:b2bbdc58967e | 614 | /** Constructor for class for driving TM1638 LED controller as used in LKM1638 |
wim | 4:b2bbdc58967e | 615 | * |
wim | 4:b2bbdc58967e | 616 | * @brief Supports 8 Digits of 7 Segments + DP Icons. Also supports 8 Bi-Color LEDs and a scanned keyboard of 8 keys. |
wim | 4:b2bbdc58967e | 617 | * |
wim | 4:b2bbdc58967e | 618 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 4:b2bbdc58967e | 619 | */ |
wim | 4:b2bbdc58967e | 620 | TM1638_LKM1638(PinName mosi, PinName miso, PinName sclk, PinName cs); |
wim | 4:b2bbdc58967e | 621 | |
wim | 4:b2bbdc58967e | 622 | #if DOXYGEN_ONLY |
wim | 4:b2bbdc58967e | 623 | /** Write a character to the Display |
wim | 4:b2bbdc58967e | 624 | * |
wim | 4:b2bbdc58967e | 625 | * @param c The character to write to the display |
wim | 4:b2bbdc58967e | 626 | */ |
wim | 4:b2bbdc58967e | 627 | int putc(int c); |
wim | 4:b2bbdc58967e | 628 | |
wim | 4:b2bbdc58967e | 629 | /** Write a formatted string to the Display |
wim | 4:b2bbdc58967e | 630 | * |
wim | 4:b2bbdc58967e | 631 | * @param format A printf-style format string, followed by the |
wim | 4:b2bbdc58967e | 632 | * variables to use in formatting the string. |
wim | 4:b2bbdc58967e | 633 | */ |
wim | 4:b2bbdc58967e | 634 | int printf(const char* format, ...); |
wim | 4:b2bbdc58967e | 635 | #endif |
wim | 4:b2bbdc58967e | 636 | |
wim | 4:b2bbdc58967e | 637 | /** Locate cursor to a screen column |
wim | 4:b2bbdc58967e | 638 | * |
wim | 4:b2bbdc58967e | 639 | * @param column The horizontal position from the left, indexed from 0 |
wim | 4:b2bbdc58967e | 640 | */ |
wim | 4:b2bbdc58967e | 641 | void locate(int column); |
wim | 4:b2bbdc58967e | 642 | |
wim | 4:b2bbdc58967e | 643 | /** Clear the screen and locate to 0 |
wim | 4:b2bbdc58967e | 644 | * @param bool clrAll Clear Icons also (default = false) |
wim | 4:b2bbdc58967e | 645 | */ |
wim | 4:b2bbdc58967e | 646 | void cls(bool clrAll = false); |
wim | 4:b2bbdc58967e | 647 | |
wim | 4:b2bbdc58967e | 648 | /** Set Icon |
wim | 4:b2bbdc58967e | 649 | * |
wim | 4:b2bbdc58967e | 650 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 4:b2bbdc58967e | 651 | * @return none |
wim | 4:b2bbdc58967e | 652 | */ |
wim | 4:b2bbdc58967e | 653 | void setIcon(Icon icon); |
wim | 4:b2bbdc58967e | 654 | |
wim | 4:b2bbdc58967e | 655 | /** Clr Icon |
wim | 4:b2bbdc58967e | 656 | * |
wim | 4:b2bbdc58967e | 657 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 4:b2bbdc58967e | 658 | * @return none |
wim | 4:b2bbdc58967e | 659 | */ |
wim | 4:b2bbdc58967e | 660 | void clrIcon(Icon icon); |
wim | 4:b2bbdc58967e | 661 | |
wim | 4:b2bbdc58967e | 662 | /** Set User Defined Characters (UDC) |
wim | 4:b2bbdc58967e | 663 | * |
wim | 4:b2bbdc58967e | 664 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 4:b2bbdc58967e | 665 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 4:b2bbdc58967e | 666 | */ |
wim | 4:b2bbdc58967e | 667 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 4:b2bbdc58967e | 668 | |
wim | 4:b2bbdc58967e | 669 | |
wim | 4:b2bbdc58967e | 670 | /** Number of screen columns |
wim | 4:b2bbdc58967e | 671 | * |
wim | 4:b2bbdc58967e | 672 | * @param none |
wim | 4:b2bbdc58967e | 673 | * @return columns |
wim | 4:b2bbdc58967e | 674 | */ |
wim | 4:b2bbdc58967e | 675 | int columns(); |
wim | 4:b2bbdc58967e | 676 | |
wim | 4:b2bbdc58967e | 677 | /** Write databyte to TM1638 |
wim | 4:b2bbdc58967e | 678 | * @param char data byte written at given address |
wim | 4:b2bbdc58967e | 679 | * @param int address display memory location to write byte |
wim | 4:b2bbdc58967e | 680 | * @return none |
wim | 4:b2bbdc58967e | 681 | */ |
wim | 4:b2bbdc58967e | 682 | void writeData(char data, int address){ |
wim | 4:b2bbdc58967e | 683 | TM1638::writeData(data, address); |
wim | 4:b2bbdc58967e | 684 | } |
wim | 4:b2bbdc58967e | 685 | |
wim | 4:b2bbdc58967e | 686 | /** Write Display datablock to TM1638 |
wim | 4:b2bbdc58967e | 687 | * @param DisplayData_t data Array of TM1638_DISPLAY_MEM (=16) bytes for displaydata |
wim | 4:b2bbdc58967e | 688 | * @param length number bytes to write (valid range 0..(LKM1638_NR_GRIDS * TM1638_BYTES_PER_GRID) (=16), when starting at address 0) |
wim | 4:b2bbdc58967e | 689 | * @param int address display memory location to write bytes (default = 0) |
wim | 4:b2bbdc58967e | 690 | * @return none |
wim | 4:b2bbdc58967e | 691 | */ |
wim | 4:b2bbdc58967e | 692 | void writeData(DisplayData_t data, int length = (LKM1638_NR_GRIDS * TM1638_BYTES_PER_GRID), int address = 0) { |
wim | 4:b2bbdc58967e | 693 | TM1638::writeData(data, length, address); |
wim | 0:201dfacbe0e5 | 694 | } |
wim | 0:201dfacbe0e5 | 695 | |
wim | 0:201dfacbe0e5 | 696 | protected: |
wim | 0:201dfacbe0e5 | 697 | // Stream implementation functions |
wim | 0:201dfacbe0e5 | 698 | virtual int _putc(int value); |
wim | 0:201dfacbe0e5 | 699 | virtual int _getc(); |
wim | 0:201dfacbe0e5 | 700 | |
wim | 0:201dfacbe0e5 | 701 | private: |
wim | 0:201dfacbe0e5 | 702 | int _column; |
wim | 0:201dfacbe0e5 | 703 | int _columns; |
wim | 0:201dfacbe0e5 | 704 | |
wim | 0:201dfacbe0e5 | 705 | DisplayData_t _displaybuffer; |
wim | 0:201dfacbe0e5 | 706 | UDCData_t _UDC_7S; |
wim | 0:201dfacbe0e5 | 707 | }; |
wim | 0:201dfacbe0e5 | 708 | #endif |
wim | 0:201dfacbe0e5 | 709 | |
wim | 0:201dfacbe0e5 | 710 | #endif |