done
TM1637.h@1:f63d87466f55, 2017-10-06 (annotated)
- Committer:
- wim
- Date:
- Fri Oct 06 16:43:56 2017 +0000
- Revision:
- 1:f63d87466f55
- Parent:
- 0:dc8789a6e21f
- Child:
- 2:4d982132b42d
Added RobotDyn 6 Digit module,; Added Eyewink 6 Digit + 5 Keys module,; Constructor adapted to 2 pins: dio, clk
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:dc8789a6e21f | 1 | /* mbed TM1637 Library, for TM1637 LED controller |
wim | 0:dc8789a6e21f | 2 | * Copyright (c) 2016, v01: WH, Initial version |
wim | 1:f63d87466f55 | 3 | * 2017, v02: WH, Added RobotDyn 6 Digit module, |
wim | 1:f63d87466f55 | 4 | * Added Eyewink 6 Digit + 6 Keys module, |
wim | 1:f63d87466f55 | 5 | * Constructor adapted to 2 pins: dio, clk |
wim | 0:dc8789a6e21f | 6 | * |
wim | 0:dc8789a6e21f | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:dc8789a6e21f | 8 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:dc8789a6e21f | 9 | * in the Software without restriction, inclumosig without limitation the rights |
wim | 0:dc8789a6e21f | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:dc8789a6e21f | 11 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:dc8789a6e21f | 12 | * furnished to do so, subject to the following conditions: |
wim | 0:dc8789a6e21f | 13 | * |
wim | 0:dc8789a6e21f | 14 | * The above copyright notice and this permission notice shall be included in |
wim | 0:dc8789a6e21f | 15 | * all copies or substantial portions of the Software. |
wim | 0:dc8789a6e21f | 16 | * |
wim | 0:dc8789a6e21f | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:dc8789a6e21f | 18 | * IMPLIED, INCLUmosiG BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:dc8789a6e21f | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:dc8789a6e21f | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:dc8789a6e21f | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:dc8789a6e21f | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:dc8789a6e21f | 23 | * THE SOFTWARE. |
wim | 0:dc8789a6e21f | 24 | */ |
wim | 0:dc8789a6e21f | 25 | |
wim | 0:dc8789a6e21f | 26 | #ifndef TM1637_H |
wim | 0:dc8789a6e21f | 27 | #define TM1637_H |
wim | 0:dc8789a6e21f | 28 | |
wim | 0:dc8789a6e21f | 29 | // Select one of the testboards for TM1637 LED controller |
wim | 0:dc8789a6e21f | 30 | #include "TM1637_Config.h" |
wim | 0:dc8789a6e21f | 31 | |
wim | 0:dc8789a6e21f | 32 | /** An interface for driving TM1637 LED controller |
wim | 0:dc8789a6e21f | 33 | * |
wim | 0:dc8789a6e21f | 34 | * @code |
wim | 0:dc8789a6e21f | 35 | * #include "mbed.h" |
wim | 0:dc8789a6e21f | 36 | * #include "TM1637.h" |
wim | 0:dc8789a6e21f | 37 | * |
wim | 1:f63d87466f55 | 38 | * Serial pc(USBTX, USBRX); |
wim | 1:f63d87466f55 | 39 | * |
wim | 0:dc8789a6e21f | 40 | * //DisplayData_t size is 6 bytes (6 grids @ 8 segments) |
wim | 0:dc8789a6e21f | 41 | * TM1637::DisplayData_t all_str = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
wim | 0:dc8789a6e21f | 42 | * |
wim | 0:dc8789a6e21f | 43 | * // KeyData_t size is 1 bytes |
wim | 0:dc8789a6e21f | 44 | * TM1637::KeyData_t keydata; |
wim | 0:dc8789a6e21f | 45 | * |
wim | 1:f63d87466f55 | 46 | * // TM1637 declaration, Select the desired type in TM1637_Config.h |
wim | 1:f63d87466f55 | 47 | * //TM1637_CATALEX CATALEX(p5,p6,p7); //LPC1768 DEPRECATED version |
wim | 1:f63d87466f55 | 48 | * TM1637_CATALEX CATALEX(p6, p7); //LPC1768 |
wim | 1:f63d87466f55 | 49 | * //TM1637_CATALEX CATALEX(D9, D10); //F401 |
wim | 0:dc8789a6e21f | 50 | * |
wim | 0:dc8789a6e21f | 51 | * int main() { |
wim | 1:f63d87466f55 | 52 | * CATALEX.cls(); |
wim | 1:f63d87466f55 | 53 | * CATALEX.writeData(all_str); |
wim | 0:dc8789a6e21f | 54 | * wait(1); |
wim | 1:f63d87466f55 | 55 | * CATALEX.setBrightness(TM1637_BRT0); |
wim | 0:dc8789a6e21f | 56 | * wait(1); |
wim | 1:f63d87466f55 | 57 | * CATALEX.setBrightness(TM1637_BRT3); |
wim | 0:dc8789a6e21f | 58 | * |
wim | 0:dc8789a6e21f | 59 | * while (1) { |
wim | 1:f63d87466f55 | 60 | * CATALEX.cls(); |
wim | 0:dc8789a6e21f | 61 | * wait(0.5); |
wim | 1:f63d87466f55 | 62 | * CATALEX.writeData(all_str); |
wim | 1:f63d87466f55 | 63 | * wait(1.0); |
wim | 1:f63d87466f55 | 64 | * CATALEX.cls(); |
wim | 1:f63d87466f55 | 65 | * CATALEX.printf(" HI "); |
wim | 1:f63d87466f55 | 66 | * wait(1.0); |
wim | 0:dc8789a6e21f | 67 | * |
wim | 0:dc8789a6e21f | 68 | * // Check and read keydata |
wim | 1:f63d87466f55 | 69 | * if (CATALEX.getKeys(&keydata)) { |
wim | 0:dc8789a6e21f | 70 | * pc.printf("Keydata = 0x%02x\r\n", keydata); |
wim | 0:dc8789a6e21f | 71 | * |
wim | 0:dc8789a6e21f | 72 | * if (keydata == TM1637_SW9_BIT) { //sw9 |
wim | 1:f63d87466f55 | 73 | * CATALEX.cls(); |
wim | 1:f63d87466f55 | 74 | * CATALEX.printf("--09"); |
wim | 0:dc8789a6e21f | 75 | * } |
wim | 0:dc8789a6e21f | 76 | * } // Check keydata |
wim | 0:dc8789a6e21f | 77 | * } // while |
wim | 0:dc8789a6e21f | 78 | * } |
wim | 0:dc8789a6e21f | 79 | * @endcode |
wim | 0:dc8789a6e21f | 80 | */ |
wim | 0:dc8789a6e21f | 81 | |
wim | 0:dc8789a6e21f | 82 | |
wim | 0:dc8789a6e21f | 83 | //TM1637 Display data |
wim | 0:dc8789a6e21f | 84 | #define TM1637_MAX_NR_GRIDS 6 |
wim | 0:dc8789a6e21f | 85 | #define TM1637_BYTES_PER_GRID 1 |
wim | 0:dc8789a6e21f | 86 | |
wim | 0:dc8789a6e21f | 87 | //Significant bits Keymatrix data |
wim | 0:dc8789a6e21f | 88 | //#define TM1638_KEY_MSK 0xFF |
wim | 0:dc8789a6e21f | 89 | |
wim | 0:dc8789a6e21f | 90 | //Memory size in bytes for Display and Keymatrix |
wim | 0:dc8789a6e21f | 91 | #define TM1637_DISPLAY_MEM (TM1637_MAX_NR_GRIDS * TM1637_BYTES_PER_GRID) |
wim | 0:dc8789a6e21f | 92 | #define TM1637_KEY_MEM 2 |
wim | 0:dc8789a6e21f | 93 | |
wim | 0:dc8789a6e21f | 94 | //Reserved bits for commands |
wim | 0:dc8789a6e21f | 95 | #define TM1637_CMD_MSK 0xC0 |
wim | 0:dc8789a6e21f | 96 | |
wim | 0:dc8789a6e21f | 97 | //Data setting commands |
wim | 0:dc8789a6e21f | 98 | #define TM1637_DATA_SET_CMD 0x40 |
wim | 0:dc8789a6e21f | 99 | #define TM1637_DATA_WR 0x00 |
wim | 0:dc8789a6e21f | 100 | #define TM1637_KEY_RD 0x02 |
wim | 0:dc8789a6e21f | 101 | #define TM1637_ADDR_INC 0x00 |
wim | 0:dc8789a6e21f | 102 | #define TM1637_ADDR_FIXED 0x04 |
wim | 0:dc8789a6e21f | 103 | #define TM1637_MODE_NORM 0x00 |
wim | 0:dc8789a6e21f | 104 | #define TM1637_MODE_TEST 0x08 |
wim | 0:dc8789a6e21f | 105 | |
wim | 0:dc8789a6e21f | 106 | //Address setting commands |
wim | 0:dc8789a6e21f | 107 | #define TM1637_ADDR_SET_CMD 0xC0 |
wim | 0:dc8789a6e21f | 108 | #define TM1637_ADDR_MSK 0x07 //0..5 |
wim | 0:dc8789a6e21f | 109 | |
wim | 0:dc8789a6e21f | 110 | //Display control commands |
wim | 0:dc8789a6e21f | 111 | #define TM1637_DSP_CTRL_CMD 0x80 |
wim | 0:dc8789a6e21f | 112 | #define TM1637_BRT_MSK 0x07 |
wim | 0:dc8789a6e21f | 113 | #define TM1637_BRT0 0x00 //Pulsewidth 1/16 |
wim | 0:dc8789a6e21f | 114 | #define TM1637_BRT1 0x01 |
wim | 0:dc8789a6e21f | 115 | #define TM1637_BRT2 0x02 |
wim | 0:dc8789a6e21f | 116 | #define TM1637_BRT3 0x03 |
wim | 0:dc8789a6e21f | 117 | #define TM1637_BRT4 0x04 |
wim | 0:dc8789a6e21f | 118 | #define TM1637_BRT5 0x05 |
wim | 0:dc8789a6e21f | 119 | #define TM1637_BRT6 0x06 |
wim | 0:dc8789a6e21f | 120 | #define TM1637_BRT7 0x07 //Pulsewidth 14/16 |
wim | 0:dc8789a6e21f | 121 | |
wim | 0:dc8789a6e21f | 122 | #define TM1637_BRT_DEF TM1637_BRT3 |
wim | 0:dc8789a6e21f | 123 | |
wim | 0:dc8789a6e21f | 124 | #define TM1637_DSP_OFF 0x00 |
wim | 0:dc8789a6e21f | 125 | #define TM1637_DSP_ON 0x08 |
wim | 0:dc8789a6e21f | 126 | |
wim | 0:dc8789a6e21f | 127 | |
wim | 0:dc8789a6e21f | 128 | //Access to 16 Switches |
wim | 1:f63d87466f55 | 129 | //S0 S1 S2 K1 K2 1 1 1 |
wim | 1:f63d87466f55 | 130 | //K1,K2 = 0 1 |
wim | 0:dc8789a6e21f | 131 | #define TM1637_SW1_BIT 0xEF |
wim | 0:dc8789a6e21f | 132 | #define TM1637_SW2_BIT 0x6F |
wim | 0:dc8789a6e21f | 133 | #define TM1637_SW3_BIT 0xAF |
wim | 0:dc8789a6e21f | 134 | #define TM1637_SW4_BIT 0x2F |
wim | 0:dc8789a6e21f | 135 | #define TM1637_SW5_BIT 0xCF |
wim | 0:dc8789a6e21f | 136 | #define TM1637_SW6_BIT 0x4F |
wim | 0:dc8789a6e21f | 137 | #define TM1637_SW7_BIT 0x8F |
wim | 0:dc8789a6e21f | 138 | #define TM1637_SW8_BIT 0x0F |
wim | 0:dc8789a6e21f | 139 | |
wim | 1:f63d87466f55 | 140 | //K1,K2 = 1 0 |
wim | 0:dc8789a6e21f | 141 | #define TM1637_SW9_BIT 0xF7 |
wim | 0:dc8789a6e21f | 142 | #define TM1637_SW10_BIT 0x77 |
wim | 0:dc8789a6e21f | 143 | #define TM1637_SW11_BIT 0xB7 |
wim | 0:dc8789a6e21f | 144 | #define TM1637_SW12_BIT 0x37 |
wim | 0:dc8789a6e21f | 145 | #define TM1637_SW13_BIT 0xD7 |
wim | 0:dc8789a6e21f | 146 | #define TM1637_SW14_BIT 0x57 |
wim | 0:dc8789a6e21f | 147 | #define TM1637_SW15_BIT 0x97 |
wim | 0:dc8789a6e21f | 148 | #define TM1637_SW16_BIT 0x17 |
wim | 0:dc8789a6e21f | 149 | |
wim | 0:dc8789a6e21f | 150 | #define TM1637_SW_NONE 0xFF |
wim | 0:dc8789a6e21f | 151 | |
wim | 0:dc8789a6e21f | 152 | /** A class for driving TM1637 LED controller |
wim | 0:dc8789a6e21f | 153 | * |
wim | 1:f63d87466f55 | 154 | * @brief Supports 6 Grids @ 8 Segments and 16 Keys. |
wim | 0:dc8789a6e21f | 155 | * Serial bus interface device. |
wim | 0:dc8789a6e21f | 156 | */ |
wim | 0:dc8789a6e21f | 157 | class TM1637 { |
wim | 0:dc8789a6e21f | 158 | public: |
wim | 0:dc8789a6e21f | 159 | |
wim | 0:dc8789a6e21f | 160 | /** Datatype for displaydata */ |
wim | 0:dc8789a6e21f | 161 | typedef char DisplayData_t[TM1637_DISPLAY_MEM]; |
wim | 0:dc8789a6e21f | 162 | |
wim | 0:dc8789a6e21f | 163 | /** Datatypes for keymatrix data */ |
wim | 0:dc8789a6e21f | 164 | typedef char KeyData_t; |
wim | 1:f63d87466f55 | 165 | |
wim | 1:f63d87466f55 | 166 | #if(SPI==1) |
wim | 0:dc8789a6e21f | 167 | /** Constructor for class for driving TM1637 LED controller |
wim | 0:dc8789a6e21f | 168 | * |
wim | 1:f63d87466f55 | 169 | * @brief Supports 6 Grids @ 8 segments and 16 Keys. |
wim | 1:f63d87466f55 | 170 | * Serial bus interface device. |
wim | 1:f63d87466f55 | 171 | * DEPRECATED version |
wim | 1:f63d87466f55 | 172 | * |
wim | 1:f63d87466f55 | 173 | * @param PinName mosi_nc Serial bus NC pin |
wim | 1:f63d87466f55 | 174 | * @param PinName miso_dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 175 | * @param PinName sclk_clk Serial bus CLK pin |
wim | 1:f63d87466f55 | 176 | */ |
wim | 1:f63d87466f55 | 177 | TM1637(PinName mosi_nc, PinName miso_dio, PinName sclk_clk); |
wim | 1:f63d87466f55 | 178 | #endif |
wim | 1:f63d87466f55 | 179 | |
wim | 1:f63d87466f55 | 180 | /** Constructor for class for driving TM1637 LED controller |
wim | 1:f63d87466f55 | 181 | * |
wim | 1:f63d87466f55 | 182 | * @brief Supports 6 Grids @ 8 segments and 16 Keys. |
wim | 0:dc8789a6e21f | 183 | * Serial bus interface device. |
wim | 0:dc8789a6e21f | 184 | * |
wim | 1:f63d87466f55 | 185 | * @param PinName dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 186 | * @param PinName sck Serial bus CLK pin |
wim | 0:dc8789a6e21f | 187 | */ |
wim | 1:f63d87466f55 | 188 | TM1637(PinName dio, PinName clk); |
wim | 1:f63d87466f55 | 189 | |
wim | 1:f63d87466f55 | 190 | |
wim | 0:dc8789a6e21f | 191 | /** Clear the screen and locate to 0 |
wim | 0:dc8789a6e21f | 192 | */ |
wim | 0:dc8789a6e21f | 193 | void cls(); |
wim | 0:dc8789a6e21f | 194 | |
wim | 0:dc8789a6e21f | 195 | /** Write databyte to TM1637 |
wim | 0:dc8789a6e21f | 196 | * @param char data byte written at given address |
wim | 0:dc8789a6e21f | 197 | * @param int address display memory location to write byte |
wim | 0:dc8789a6e21f | 198 | * @return none |
wim | 0:dc8789a6e21f | 199 | */ |
wim | 0:dc8789a6e21f | 200 | void writeData(char data, int address); |
wim | 0:dc8789a6e21f | 201 | |
wim | 0:dc8789a6e21f | 202 | /** Write Display datablock to TM1637 |
wim | 0:dc8789a6e21f | 203 | * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=6) bytes for displaydata |
wim | 0:dc8789a6e21f | 204 | * @param length number bytes to write (valid range 0..(TM1637_MAX_NR_GRIDS * TM1637_BYTES_PER_GRID) (=6), when starting at address 0) |
wim | 0:dc8789a6e21f | 205 | * @param int address display memory location to write bytes (default = 0) |
wim | 0:dc8789a6e21f | 206 | * @return none |
wim | 0:dc8789a6e21f | 207 | */ |
wim | 0:dc8789a6e21f | 208 | void writeData(DisplayData_t data, int length = (TM1637_MAX_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0); |
wim | 0:dc8789a6e21f | 209 | |
wim | 0:dc8789a6e21f | 210 | /** Read keydata block from TM1637 |
wim | 0:dc8789a6e21f | 211 | * @param *keydata Ptr to bytes for keydata |
wim | 0:dc8789a6e21f | 212 | * @return bool keypress True when at least one key was pressed |
wim | 0:dc8789a6e21f | 213 | * |
wim | 0:dc8789a6e21f | 214 | */ |
wim | 0:dc8789a6e21f | 215 | bool getKeys(KeyData_t *keydata); |
wim | 0:dc8789a6e21f | 216 | |
wim | 0:dc8789a6e21f | 217 | /** Set Brightness |
wim | 0:dc8789a6e21f | 218 | * |
wim | 0:dc8789a6e21f | 219 | * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle) |
wim | 0:dc8789a6e21f | 220 | * @return none |
wim | 0:dc8789a6e21f | 221 | */ |
wim | 0:dc8789a6e21f | 222 | void setBrightness(char brightness = TM1637_BRT_DEF); |
wim | 0:dc8789a6e21f | 223 | |
wim | 0:dc8789a6e21f | 224 | /** Set the Display mode On/off |
wim | 0:dc8789a6e21f | 225 | * |
wim | 0:dc8789a6e21f | 226 | * @param bool display mode |
wim | 0:dc8789a6e21f | 227 | */ |
wim | 0:dc8789a6e21f | 228 | void setDisplay(bool on); |
wim | 0:dc8789a6e21f | 229 | |
wim | 1:f63d87466f55 | 230 | private: |
wim | 1:f63d87466f55 | 231 | #if(SPI==1) |
wim | 1:f63d87466f55 | 232 | DigitalIn _mosi_nc; //Dummy to avoid breaking deprecated constructor |
wim | 1:f63d87466f55 | 233 | #endif |
wim | 1:f63d87466f55 | 234 | DigitalInOut _dio; |
wim | 1:f63d87466f55 | 235 | DigitalOut _clk; |
wim | 1:f63d87466f55 | 236 | |
wim | 0:dc8789a6e21f | 237 | char _display; |
wim | 0:dc8789a6e21f | 238 | char _bright; |
wim | 0:dc8789a6e21f | 239 | |
wim | 0:dc8789a6e21f | 240 | /** Init the Serial interface and the controller |
wim | 0:dc8789a6e21f | 241 | * @param none |
wim | 0:dc8789a6e21f | 242 | * @return none |
wim | 0:dc8789a6e21f | 243 | */ |
wim | 0:dc8789a6e21f | 244 | void _init(); |
wim | 0:dc8789a6e21f | 245 | |
wim | 0:dc8789a6e21f | 246 | |
wim | 0:dc8789a6e21f | 247 | /** Generate Start condition for TM1637 |
wim | 0:dc8789a6e21f | 248 | * @param none |
wim | 0:dc8789a6e21f | 249 | * @return none |
wim | 0:dc8789a6e21f | 250 | */ |
wim | 0:dc8789a6e21f | 251 | void _start(); |
wim | 0:dc8789a6e21f | 252 | |
wim | 0:dc8789a6e21f | 253 | /** Generate Stop condition for TM1637 |
wim | 0:dc8789a6e21f | 254 | * @param none |
wim | 0:dc8789a6e21f | 255 | * @return none |
wim | 0:dc8789a6e21f | 256 | */ |
wim | 0:dc8789a6e21f | 257 | void _stop(); |
wim | 0:dc8789a6e21f | 258 | |
wim | 0:dc8789a6e21f | 259 | /** Send byte to TM1637 |
wim | 0:dc8789a6e21f | 260 | * @param int data |
wim | 0:dc8789a6e21f | 261 | * @return none |
wim | 0:dc8789a6e21f | 262 | */ |
wim | 0:dc8789a6e21f | 263 | void _write(int data); |
wim | 0:dc8789a6e21f | 264 | |
wim | 0:dc8789a6e21f | 265 | /** Read byte from TM1637 |
wim | 0:dc8789a6e21f | 266 | * @return read byte |
wim | 0:dc8789a6e21f | 267 | */ |
wim | 1:f63d87466f55 | 268 | char _read(); |
wim | 0:dc8789a6e21f | 269 | |
wim | 0:dc8789a6e21f | 270 | /** Write command and parameter to TM1637 |
wim | 0:dc8789a6e21f | 271 | * @param int cmd Command byte |
wim | 0:dc8789a6e21f | 272 | * &Param int data Parameters for command |
wim | 0:dc8789a6e21f | 273 | * @return none |
wim | 0:dc8789a6e21f | 274 | */ |
wim | 0:dc8789a6e21f | 275 | void _writeCmd(int cmd, int data); |
wim | 0:dc8789a6e21f | 276 | }; |
wim | 0:dc8789a6e21f | 277 | |
wim | 0:dc8789a6e21f | 278 | #if (CATALEX_TEST == 1) |
wim | 1:f63d87466f55 | 279 | // Derived class for TM1637 used in CATALEX display unit with 4 Digits |
wim | 0:dc8789a6e21f | 280 | // |
wim | 0:dc8789a6e21f | 281 | |
wim | 0:dc8789a6e21f | 282 | #include "Font_7Seg.h" |
wim | 0:dc8789a6e21f | 283 | |
wim | 0:dc8789a6e21f | 284 | #define CATALEX_NR_GRIDS 4 |
wim | 0:dc8789a6e21f | 285 | #define CATALEX_NR_DIGITS 4 |
wim | 0:dc8789a6e21f | 286 | #define CATALEX_NR_UDC 8 |
wim | 0:dc8789a6e21f | 287 | |
wim | 0:dc8789a6e21f | 288 | |
wim | 0:dc8789a6e21f | 289 | /** Constructor for class for driving TM1637 controller as used in CATALEX |
wim | 0:dc8789a6e21f | 290 | * |
wim | 1:f63d87466f55 | 291 | * @brief Supports 4 Digits of 7 Segments + DP (or Colon for Digit2 on some models). |
wim | 1:f63d87466f55 | 292 | * Also Supports up to 16 Keys. Serial bus interface device. |
wim | 0:dc8789a6e21f | 293 | * |
wim | 0:dc8789a6e21f | 294 | * @param PinName mosi Serial bus MOSI pin |
wim | 0:dc8789a6e21f | 295 | * @param PinName miso Serial bus MISO pin |
wim | 0:dc8789a6e21f | 296 | * @param PinName sclk Serial bus SCLK pin |
wim | 0:dc8789a6e21f | 297 | */ |
wim | 0:dc8789a6e21f | 298 | class TM1637_CATALEX : public TM1637, public Stream { |
wim | 0:dc8789a6e21f | 299 | public: |
wim | 0:dc8789a6e21f | 300 | |
wim | 0:dc8789a6e21f | 301 | /** Enums for Icons */ |
wim | 0:dc8789a6e21f | 302 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:dc8789a6e21f | 303 | enum Icon { |
wim | 1:f63d87466f55 | 304 | DP1 = ( 1<<24) | S7_DP1, /**< Digit 1 */ |
wim | 1:f63d87466f55 | 305 | DP2 = ( 2<<24) | S7_DP2, /**< Digit 2 */ |
wim | 1:f63d87466f55 | 306 | DP3 = ( 3<<24) | S7_DP3, /**< Digit 3 */ |
wim | 1:f63d87466f55 | 307 | DP4 = ( 4<<24) | S7_DP4, /**< Digit 4 */ |
wim | 1:f63d87466f55 | 308 | |
wim | 0:dc8789a6e21f | 309 | COL2 = ( 2<<24) | S7_DP2, /**< Column 2 */ |
wim | 0:dc8789a6e21f | 310 | }; |
wim | 0:dc8789a6e21f | 311 | |
wim | 0:dc8789a6e21f | 312 | typedef char UDCData_t[CATALEX_NR_UDC]; |
wim | 1:f63d87466f55 | 313 | |
wim | 1:f63d87466f55 | 314 | #if (SPI==1) |
wim | 0:dc8789a6e21f | 315 | /** Constructor for class for driving TM1637 LED controller as used in CATALEX |
wim | 1:f63d87466f55 | 316 | * |
wim | 1:f63d87466f55 | 317 | * @brief Supports 4 Digits of 7 Segments + DP (or Colon for Digit2 on some models). |
wim | 1:f63d87466f55 | 318 | * Also Supports up to 16 Keys. Serial bus interface device. |
wim | 1:f63d87466f55 | 319 | * DEPRECATED version |
wim | 1:f63d87466f55 | 320 | * |
wim | 1:f63d87466f55 | 321 | * @param PinName mosi_nc Serial bus NC pin |
wim | 1:f63d87466f55 | 322 | * @param PinName miso_dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 323 | * @param PinName sclk_clk Serial bus CLK pin |
wim | 0:dc8789a6e21f | 324 | */ |
wim | 1:f63d87466f55 | 325 | TM1637_CATALEX(PinName mosi_nc, PinName miso_dio, PinName sclk_clk); |
wim | 1:f63d87466f55 | 326 | #endif |
wim | 0:dc8789a6e21f | 327 | |
wim | 1:f63d87466f55 | 328 | /** Constructor for class for driving TM1637 LED controller |
wim | 1:f63d87466f55 | 329 | * |
wim | 1:f63d87466f55 | 330 | * @brief Supports 4 Digits of 7 Segments + DP (or Colon for Digit2 on some models). |
wim | 1:f63d87466f55 | 331 | * Also Supports up to 16 Keys. Serial bus interface device. |
wim | 1:f63d87466f55 | 332 | * |
wim | 1:f63d87466f55 | 333 | * @param PinName dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 334 | * @param PinName sck Serial bus CLK pin |
wim | 1:f63d87466f55 | 335 | */ |
wim | 1:f63d87466f55 | 336 | TM1637_CATALEX(PinName dio, PinName clk); |
wim | 1:f63d87466f55 | 337 | |
wim | 1:f63d87466f55 | 338 | |
wim | 0:dc8789a6e21f | 339 | #if DOXYGEN_ONLY |
wim | 0:dc8789a6e21f | 340 | /** Write a character to the Display |
wim | 0:dc8789a6e21f | 341 | * |
wim | 0:dc8789a6e21f | 342 | * @param c The character to write to the display |
wim | 0:dc8789a6e21f | 343 | */ |
wim | 0:dc8789a6e21f | 344 | int putc(int c); |
wim | 0:dc8789a6e21f | 345 | |
wim | 0:dc8789a6e21f | 346 | /** Write a formatted string to the Display |
wim | 0:dc8789a6e21f | 347 | * |
wim | 0:dc8789a6e21f | 348 | * @param format A printf-style format string, followed by the |
wim | 0:dc8789a6e21f | 349 | * variables to use in formatting the string. |
wim | 0:dc8789a6e21f | 350 | */ |
wim | 0:dc8789a6e21f | 351 | int printf(const char* format, ...); |
wim | 0:dc8789a6e21f | 352 | #endif |
wim | 0:dc8789a6e21f | 353 | |
wim | 0:dc8789a6e21f | 354 | /** Locate cursor to a screen column |
wim | 0:dc8789a6e21f | 355 | * |
wim | 0:dc8789a6e21f | 356 | * @param column The horizontal position from the left, indexed from 0 |
wim | 0:dc8789a6e21f | 357 | */ |
wim | 0:dc8789a6e21f | 358 | void locate(int column); |
wim | 0:dc8789a6e21f | 359 | |
wim | 0:dc8789a6e21f | 360 | /** Clear the screen and locate to 0 |
wim | 0:dc8789a6e21f | 361 | * @param bool clrAll Clear Icons also (default = false) |
wim | 0:dc8789a6e21f | 362 | */ |
wim | 0:dc8789a6e21f | 363 | void cls(bool clrAll = false); |
wim | 0:dc8789a6e21f | 364 | |
wim | 0:dc8789a6e21f | 365 | /** Set Icon |
wim | 0:dc8789a6e21f | 366 | * |
wim | 0:dc8789a6e21f | 367 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:dc8789a6e21f | 368 | * @return none |
wim | 0:dc8789a6e21f | 369 | */ |
wim | 0:dc8789a6e21f | 370 | void setIcon(Icon icon); |
wim | 0:dc8789a6e21f | 371 | |
wim | 0:dc8789a6e21f | 372 | /** Clr Icon |
wim | 0:dc8789a6e21f | 373 | * |
wim | 0:dc8789a6e21f | 374 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 0:dc8789a6e21f | 375 | * @return none |
wim | 0:dc8789a6e21f | 376 | */ |
wim | 0:dc8789a6e21f | 377 | void clrIcon(Icon icon); |
wim | 0:dc8789a6e21f | 378 | |
wim | 0:dc8789a6e21f | 379 | /** Set User Defined Characters (UDC) |
wim | 0:dc8789a6e21f | 380 | * |
wim | 0:dc8789a6e21f | 381 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 0:dc8789a6e21f | 382 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 0:dc8789a6e21f | 383 | */ |
wim | 0:dc8789a6e21f | 384 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 0:dc8789a6e21f | 385 | |
wim | 0:dc8789a6e21f | 386 | |
wim | 0:dc8789a6e21f | 387 | /** Number of screen columns |
wim | 0:dc8789a6e21f | 388 | * |
wim | 0:dc8789a6e21f | 389 | * @param none |
wim | 0:dc8789a6e21f | 390 | * @return columns |
wim | 0:dc8789a6e21f | 391 | */ |
wim | 0:dc8789a6e21f | 392 | int columns(); |
wim | 0:dc8789a6e21f | 393 | |
wim | 0:dc8789a6e21f | 394 | /** Write databyte to TM1637 |
wim | 0:dc8789a6e21f | 395 | * @param char data byte written at given address |
wim | 0:dc8789a6e21f | 396 | * @param int address display memory location to write byte |
wim | 0:dc8789a6e21f | 397 | * @return none |
wim | 0:dc8789a6e21f | 398 | */ |
wim | 0:dc8789a6e21f | 399 | void writeData(char data, int address){ |
wim | 0:dc8789a6e21f | 400 | TM1637::writeData(data, address); |
wim | 0:dc8789a6e21f | 401 | } |
wim | 0:dc8789a6e21f | 402 | |
wim | 0:dc8789a6e21f | 403 | /** Write Display datablock to TM1637 |
wim | 0:dc8789a6e21f | 404 | * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=4) bytes for displaydata |
wim | 0:dc8789a6e21f | 405 | * @param length number bytes to write (valid range 0..(CATALEX_NR_GRIDS * TM1637_BYTES_PER_GRID) (=4), when starting at address 0) |
wim | 1:f63d87466f55 | 406 | * @param int address display memory location to write bytes (default = 0) |
wim | 0:dc8789a6e21f | 407 | * @return none |
wim | 0:dc8789a6e21f | 408 | */ |
wim | 0:dc8789a6e21f | 409 | void writeData(DisplayData_t data, int length = (CATALEX_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0) { |
wim | 0:dc8789a6e21f | 410 | TM1637::writeData(data, length, address); |
wim | 0:dc8789a6e21f | 411 | } |
wim | 0:dc8789a6e21f | 412 | |
wim | 0:dc8789a6e21f | 413 | protected: |
wim | 0:dc8789a6e21f | 414 | // Stream implementation functions |
wim | 0:dc8789a6e21f | 415 | virtual int _putc(int value); |
wim | 0:dc8789a6e21f | 416 | virtual int _getc(); |
wim | 0:dc8789a6e21f | 417 | |
wim | 0:dc8789a6e21f | 418 | private: |
wim | 0:dc8789a6e21f | 419 | int _column; |
wim | 0:dc8789a6e21f | 420 | int _columns; |
wim | 0:dc8789a6e21f | 421 | |
wim | 0:dc8789a6e21f | 422 | DisplayData_t _displaybuffer; |
wim | 0:dc8789a6e21f | 423 | UDCData_t _UDC_7S; |
wim | 0:dc8789a6e21f | 424 | }; |
wim | 0:dc8789a6e21f | 425 | #endif |
wim | 0:dc8789a6e21f | 426 | |
wim | 1:f63d87466f55 | 427 | #if (ROBOTDYN_TEST == 1) |
wim | 1:f63d87466f55 | 428 | // Derived class for TM1637 used in ROBOTDYN 6 Digit display unit |
wim | 1:f63d87466f55 | 429 | // |
wim | 1:f63d87466f55 | 430 | |
wim | 1:f63d87466f55 | 431 | #include "Font_7Seg.h" |
wim | 1:f63d87466f55 | 432 | |
wim | 1:f63d87466f55 | 433 | #define ROBOTDYN_NR_GRIDS 6 |
wim | 1:f63d87466f55 | 434 | #define ROBOTDYN_NR_DIGITS 6 |
wim | 1:f63d87466f55 | 435 | #define ROBOTDYN_NR_UDC 8 |
wim | 1:f63d87466f55 | 436 | |
wim | 1:f63d87466f55 | 437 | |
wim | 1:f63d87466f55 | 438 | /** Constructor for class for driving TM1637 controller as used in ROBOTDYN |
wim | 1:f63d87466f55 | 439 | * |
wim | 1:f63d87466f55 | 440 | * @brief Supports 6 Digits of 7 Segments + DP. |
wim | 1:f63d87466f55 | 441 | * |
wim | 1:f63d87466f55 | 442 | * @param PinName dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 443 | * @param PinName clk Serial bus CLK pin |
wim | 1:f63d87466f55 | 444 | */ |
wim | 1:f63d87466f55 | 445 | class TM1637_ROBOTDYN : public TM1637, public Stream { |
wim | 1:f63d87466f55 | 446 | public: |
wim | 1:f63d87466f55 | 447 | |
wim | 1:f63d87466f55 | 448 | /** Enums for Icons */ |
wim | 1:f63d87466f55 | 449 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 1:f63d87466f55 | 450 | // Note that Digits 1,3 and 4,6 are swapped! |
wim | 1:f63d87466f55 | 451 | enum Icon { |
wim | 1:f63d87466f55 | 452 | DP1 = ( 3<<24) | S7_DP1, /**< Digit 1 */ |
wim | 1:f63d87466f55 | 453 | DP2 = ( 2<<24) | S7_DP2, /**< Digit 2 */ |
wim | 1:f63d87466f55 | 454 | DP3 = ( 1<<24) | S7_DP3, /**< Digit 3 */ |
wim | 1:f63d87466f55 | 455 | DP4 = ( 6<<24) | S7_DP4, /**< Digit 4 */ |
wim | 1:f63d87466f55 | 456 | DP5 = ( 5<<24) | S7_DP5, /**< Digit 5 */ |
wim | 1:f63d87466f55 | 457 | DP6 = ( 4<<24) | S7_DP6, /**< Digit 6 */ |
wim | 1:f63d87466f55 | 458 | }; |
wim | 1:f63d87466f55 | 459 | |
wim | 1:f63d87466f55 | 460 | typedef char UDCData_t[ROBOTDYN_NR_UDC]; |
wim | 1:f63d87466f55 | 461 | |
wim | 1:f63d87466f55 | 462 | /** Constructor for class for driving TM1637 LED controller as used in ROBOTDYN |
wim | 1:f63d87466f55 | 463 | * |
wim | 1:f63d87466f55 | 464 | * @brief Supports 6 Digits of 7 Segments + DP. Also supports up to 16 Keys. |
wim | 1:f63d87466f55 | 465 | * |
wim | 1:f63d87466f55 | 466 | * @param PinName dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 467 | * @param PinName clk Serial bus CLK pin |
wim | 1:f63d87466f55 | 468 | */ |
wim | 1:f63d87466f55 | 469 | TM1637_ROBOTDYN(PinName dio, PinName clk); |
wim | 1:f63d87466f55 | 470 | |
wim | 1:f63d87466f55 | 471 | |
wim | 1:f63d87466f55 | 472 | #if DOXYGEN_ONLY |
wim | 1:f63d87466f55 | 473 | /** Write a character to the Display |
wim | 1:f63d87466f55 | 474 | * |
wim | 1:f63d87466f55 | 475 | * @param c The character to write to the display |
wim | 1:f63d87466f55 | 476 | */ |
wim | 1:f63d87466f55 | 477 | int putc(int c); |
wim | 1:f63d87466f55 | 478 | |
wim | 1:f63d87466f55 | 479 | /** Write a formatted string to the Display |
wim | 1:f63d87466f55 | 480 | * |
wim | 1:f63d87466f55 | 481 | * @param format A printf-style format string, followed by the |
wim | 1:f63d87466f55 | 482 | * variables to use in formatting the string. |
wim | 1:f63d87466f55 | 483 | */ |
wim | 1:f63d87466f55 | 484 | int printf(const char* format, ...); |
wim | 1:f63d87466f55 | 485 | #endif |
wim | 1:f63d87466f55 | 486 | |
wim | 1:f63d87466f55 | 487 | /** Locate cursor to a screen column |
wim | 1:f63d87466f55 | 488 | * |
wim | 1:f63d87466f55 | 489 | * @param column The horizontal position from the left, indexed from 0 |
wim | 1:f63d87466f55 | 490 | */ |
wim | 1:f63d87466f55 | 491 | void locate(int column); |
wim | 1:f63d87466f55 | 492 | |
wim | 1:f63d87466f55 | 493 | /** Clear the screen and locate to 0 |
wim | 1:f63d87466f55 | 494 | * @param bool clrAll Clear Icons also (default = false) |
wim | 1:f63d87466f55 | 495 | */ |
wim | 1:f63d87466f55 | 496 | void cls(bool clrAll = false); |
wim | 1:f63d87466f55 | 497 | |
wim | 1:f63d87466f55 | 498 | /** Set Icon |
wim | 1:f63d87466f55 | 499 | * |
wim | 1:f63d87466f55 | 500 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 1:f63d87466f55 | 501 | * @return none |
wim | 1:f63d87466f55 | 502 | */ |
wim | 1:f63d87466f55 | 503 | void setIcon(Icon icon); |
wim | 1:f63d87466f55 | 504 | |
wim | 1:f63d87466f55 | 505 | /** Clr Icon |
wim | 1:f63d87466f55 | 506 | * |
wim | 1:f63d87466f55 | 507 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 1:f63d87466f55 | 508 | * @return none |
wim | 1:f63d87466f55 | 509 | */ |
wim | 1:f63d87466f55 | 510 | void clrIcon(Icon icon); |
wim | 1:f63d87466f55 | 511 | |
wim | 1:f63d87466f55 | 512 | /** Set User Defined Characters (UDC) |
wim | 1:f63d87466f55 | 513 | * |
wim | 1:f63d87466f55 | 514 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 1:f63d87466f55 | 515 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 1:f63d87466f55 | 516 | */ |
wim | 1:f63d87466f55 | 517 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 1:f63d87466f55 | 518 | |
wim | 1:f63d87466f55 | 519 | |
wim | 1:f63d87466f55 | 520 | /** Number of screen columns |
wim | 1:f63d87466f55 | 521 | * |
wim | 1:f63d87466f55 | 522 | * @param none |
wim | 1:f63d87466f55 | 523 | * @return columns |
wim | 1:f63d87466f55 | 524 | */ |
wim | 1:f63d87466f55 | 525 | int columns(); |
wim | 1:f63d87466f55 | 526 | |
wim | 1:f63d87466f55 | 527 | /** Write databyte to TM1637 |
wim | 1:f63d87466f55 | 528 | * @param char data byte written at given address |
wim | 1:f63d87466f55 | 529 | * @param int address display memory location to write byte |
wim | 1:f63d87466f55 | 530 | * @return none |
wim | 1:f63d87466f55 | 531 | */ |
wim | 1:f63d87466f55 | 532 | void writeData(char data, int address){ |
wim | 1:f63d87466f55 | 533 | TM1637::writeData(data, address); |
wim | 1:f63d87466f55 | 534 | } |
wim | 1:f63d87466f55 | 535 | |
wim | 1:f63d87466f55 | 536 | /** Write Display datablock to TM1637 |
wim | 1:f63d87466f55 | 537 | * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=6) bytes for displaydata |
wim | 1:f63d87466f55 | 538 | * @param length number bytes to write (valid range 0..(ROBOTDYN_NR_GRIDS * TM1637_BYTES_PER_GRID) (=6), when starting at address 0) |
wim | 1:f63d87466f55 | 539 | * @param int address display memory location to write bytes (default = 0) |
wim | 1:f63d87466f55 | 540 | * @return none |
wim | 1:f63d87466f55 | 541 | */ |
wim | 1:f63d87466f55 | 542 | void writeData(DisplayData_t data, int length = (ROBOTDYN_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0) { |
wim | 1:f63d87466f55 | 543 | TM1637::writeData(data, length, address); |
wim | 1:f63d87466f55 | 544 | } |
wim | 1:f63d87466f55 | 545 | |
wim | 1:f63d87466f55 | 546 | protected: |
wim | 1:f63d87466f55 | 547 | // Stream implementation functions |
wim | 1:f63d87466f55 | 548 | virtual int _putc(int value); |
wim | 1:f63d87466f55 | 549 | virtual int _getc(); |
wim | 1:f63d87466f55 | 550 | |
wim | 1:f63d87466f55 | 551 | private: |
wim | 1:f63d87466f55 | 552 | int _column; |
wim | 1:f63d87466f55 | 553 | int _columns; |
wim | 1:f63d87466f55 | 554 | |
wim | 1:f63d87466f55 | 555 | DisplayData_t _displaybuffer; |
wim | 1:f63d87466f55 | 556 | UDCData_t _UDC_7S; |
wim | 1:f63d87466f55 | 557 | }; |
wim | 1:f63d87466f55 | 558 | #endif |
wim | 1:f63d87466f55 | 559 | |
wim | 1:f63d87466f55 | 560 | |
wim | 1:f63d87466f55 | 561 | #if (EYEWINK_TEST == 1) |
wim | 1:f63d87466f55 | 562 | // Derived class for TM1637 used in EYEWINK 6 Digit + 6 Keys display unit |
wim | 1:f63d87466f55 | 563 | // |
wim | 1:f63d87466f55 | 564 | |
wim | 1:f63d87466f55 | 565 | #include "Font_7Seg.h" |
wim | 1:f63d87466f55 | 566 | |
wim | 1:f63d87466f55 | 567 | #define EYEWINK_NR_GRIDS 6 |
wim | 1:f63d87466f55 | 568 | #define EYEWINK_NR_DIGITS 6 |
wim | 1:f63d87466f55 | 569 | #define EYEWINK_NR_UDC 8 |
wim | 1:f63d87466f55 | 570 | |
wim | 1:f63d87466f55 | 571 | |
wim | 1:f63d87466f55 | 572 | /** Constructor for class for driving TM1637 controller as used in EYEWINK |
wim | 1:f63d87466f55 | 573 | * |
wim | 1:f63d87466f55 | 574 | * @brief Supports 6 Digits of 7 Segments + DP and 6 Keys. |
wim | 1:f63d87466f55 | 575 | * |
wim | 1:f63d87466f55 | 576 | * @param PinName dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 577 | * @param PinName clk Serial bus CLK pin |
wim | 1:f63d87466f55 | 578 | */ |
wim | 1:f63d87466f55 | 579 | class TM1637_EYEWINK : public TM1637, public Stream { |
wim | 1:f63d87466f55 | 580 | public: |
wim | 1:f63d87466f55 | 581 | |
wim | 1:f63d87466f55 | 582 | /** Enums for Icons */ |
wim | 1:f63d87466f55 | 583 | // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 1:f63d87466f55 | 584 | enum Icon { |
wim | 1:f63d87466f55 | 585 | DP1 = ( 1<<24) | S7_DP1, /**< Digit 1 */ |
wim | 1:f63d87466f55 | 586 | DP2 = ( 2<<24) | S7_DP2, /**< Digit 2 */ |
wim | 1:f63d87466f55 | 587 | DP3 = ( 3<<24) | S7_DP3, /**< Digit 3 */ |
wim | 1:f63d87466f55 | 588 | DP4 = ( 4<<24) | S7_DP4, /**< Digit 4 */ |
wim | 1:f63d87466f55 | 589 | DP5 = ( 5<<24) | S7_DP5, /**< Digit 5 */ |
wim | 1:f63d87466f55 | 590 | DP6 = ( 6<<24) | S7_DP6, /**< Digit 6 */ |
wim | 1:f63d87466f55 | 591 | }; |
wim | 1:f63d87466f55 | 592 | |
wim | 1:f63d87466f55 | 593 | typedef char UDCData_t[EYEWINK_NR_UDC]; |
wim | 1:f63d87466f55 | 594 | |
wim | 1:f63d87466f55 | 595 | /** Constructor for class for driving TM1637 LED controller as used in EYEWINK |
wim | 1:f63d87466f55 | 596 | * |
wim | 1:f63d87466f55 | 597 | * @brief Supports 6 Digits of 7 Segments + DP. |
wim | 1:f63d87466f55 | 598 | * |
wim | 1:f63d87466f55 | 599 | * @param PinName dio Serial bus DIO pin |
wim | 1:f63d87466f55 | 600 | * @param PinName clk Serial bus CLK pin |
wim | 1:f63d87466f55 | 601 | */ |
wim | 1:f63d87466f55 | 602 | TM1637_EYEWINK(PinName dio, PinName clk); |
wim | 1:f63d87466f55 | 603 | |
wim | 1:f63d87466f55 | 604 | |
wim | 1:f63d87466f55 | 605 | #if DOXYGEN_ONLY |
wim | 1:f63d87466f55 | 606 | /** Write a character to the Display |
wim | 1:f63d87466f55 | 607 | * |
wim | 1:f63d87466f55 | 608 | * @param c The character to write to the display |
wim | 1:f63d87466f55 | 609 | */ |
wim | 1:f63d87466f55 | 610 | int putc(int c); |
wim | 1:f63d87466f55 | 611 | |
wim | 1:f63d87466f55 | 612 | /** Write a formatted string to the Display |
wim | 1:f63d87466f55 | 613 | * |
wim | 1:f63d87466f55 | 614 | * @param format A printf-style format string, followed by the |
wim | 1:f63d87466f55 | 615 | * variables to use in formatting the string. |
wim | 1:f63d87466f55 | 616 | */ |
wim | 1:f63d87466f55 | 617 | int printf(const char* format, ...); |
wim | 1:f63d87466f55 | 618 | #endif |
wim | 1:f63d87466f55 | 619 | |
wim | 1:f63d87466f55 | 620 | /** Locate cursor to a screen column |
wim | 1:f63d87466f55 | 621 | * |
wim | 1:f63d87466f55 | 622 | * @param column The horizontal position from the left, indexed from 0 |
wim | 1:f63d87466f55 | 623 | */ |
wim | 1:f63d87466f55 | 624 | void locate(int column); |
wim | 1:f63d87466f55 | 625 | |
wim | 1:f63d87466f55 | 626 | /** Clear the screen and locate to 0 |
wim | 1:f63d87466f55 | 627 | * @param bool clrAll Clear Icons also (default = false) |
wim | 1:f63d87466f55 | 628 | */ |
wim | 1:f63d87466f55 | 629 | void cls(bool clrAll = false); |
wim | 1:f63d87466f55 | 630 | |
wim | 1:f63d87466f55 | 631 | /** Set Icon |
wim | 1:f63d87466f55 | 632 | * |
wim | 1:f63d87466f55 | 633 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 1:f63d87466f55 | 634 | * @return none |
wim | 1:f63d87466f55 | 635 | */ |
wim | 1:f63d87466f55 | 636 | void setIcon(Icon icon); |
wim | 1:f63d87466f55 | 637 | |
wim | 1:f63d87466f55 | 638 | /** Clr Icon |
wim | 1:f63d87466f55 | 639 | * |
wim | 1:f63d87466f55 | 640 | * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs |
wim | 1:f63d87466f55 | 641 | * @return none |
wim | 1:f63d87466f55 | 642 | */ |
wim | 1:f63d87466f55 | 643 | void clrIcon(Icon icon); |
wim | 1:f63d87466f55 | 644 | |
wim | 1:f63d87466f55 | 645 | /** Set User Defined Characters (UDC) |
wim | 1:f63d87466f55 | 646 | * |
wim | 1:f63d87466f55 | 647 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 1:f63d87466f55 | 648 | * @param int udc_data The bitpattern for the UDC (16 bits) |
wim | 1:f63d87466f55 | 649 | */ |
wim | 1:f63d87466f55 | 650 | void setUDC(unsigned char udc_idx, int udc_data); |
wim | 1:f63d87466f55 | 651 | |
wim | 1:f63d87466f55 | 652 | |
wim | 1:f63d87466f55 | 653 | /** Number of screen columns |
wim | 1:f63d87466f55 | 654 | * |
wim | 1:f63d87466f55 | 655 | * @param none |
wim | 1:f63d87466f55 | 656 | * @return columns |
wim | 1:f63d87466f55 | 657 | */ |
wim | 1:f63d87466f55 | 658 | int columns(); |
wim | 1:f63d87466f55 | 659 | |
wim | 1:f63d87466f55 | 660 | /** Write databyte to TM1637 |
wim | 1:f63d87466f55 | 661 | * @param char data byte written at given address |
wim | 1:f63d87466f55 | 662 | * @param int address display memory location to write byte |
wim | 1:f63d87466f55 | 663 | * @return none |
wim | 1:f63d87466f55 | 664 | */ |
wim | 1:f63d87466f55 | 665 | void writeData(char data, int address){ |
wim | 1:f63d87466f55 | 666 | TM1637::writeData(data, address); |
wim | 1:f63d87466f55 | 667 | } |
wim | 1:f63d87466f55 | 668 | |
wim | 1:f63d87466f55 | 669 | /** Write Display datablock to TM1637 |
wim | 1:f63d87466f55 | 670 | * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=6) bytes for displaydata |
wim | 1:f63d87466f55 | 671 | * @param length number bytes to write (valid range 0..(EYEWINK_NR_GRIDS * TM1637_BYTES_PER_GRID) (=6), when starting at address 0) |
wim | 1:f63d87466f55 | 672 | * @param int address display memory location to write bytes (default = 0) |
wim | 1:f63d87466f55 | 673 | * @return none |
wim | 1:f63d87466f55 | 674 | */ |
wim | 1:f63d87466f55 | 675 | void writeData(DisplayData_t data, int length = (EYEWINK_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0) { |
wim | 1:f63d87466f55 | 676 | TM1637::writeData(data, length, address); |
wim | 1:f63d87466f55 | 677 | } |
wim | 1:f63d87466f55 | 678 | |
wim | 1:f63d87466f55 | 679 | protected: |
wim | 1:f63d87466f55 | 680 | // Stream implementation functions |
wim | 1:f63d87466f55 | 681 | virtual int _putc(int value); |
wim | 1:f63d87466f55 | 682 | virtual int _getc(); |
wim | 1:f63d87466f55 | 683 | |
wim | 1:f63d87466f55 | 684 | private: |
wim | 1:f63d87466f55 | 685 | int _column; |
wim | 1:f63d87466f55 | 686 | int _columns; |
wim | 1:f63d87466f55 | 687 | |
wim | 1:f63d87466f55 | 688 | DisplayData_t _displaybuffer; |
wim | 1:f63d87466f55 | 689 | UDCData_t _UDC_7S; |
wim | 1:f63d87466f55 | 690 | }; |
wim | 1:f63d87466f55 | 691 | #endif |
wim | 1:f63d87466f55 | 692 | |
wim | 0:dc8789a6e21f | 693 | #endif |