done

Dependents:   AwesomeAlarm_BLE

Committer:
yungsung
Date:
Thu Jan 09 19:19:04 2020 +0000
Revision:
2:4d982132b42d
Parent:
1:f63d87466f55
done

Who changed what in which revision?

UserRevisionLine numberNew 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
yungsung 2:4d982132b42d 152
wim 0:dc8789a6e21f 153 /** A class for driving TM1637 LED controller
wim 0:dc8789a6e21f 154 *
wim 1:f63d87466f55 155 * @brief Supports 6 Grids @ 8 Segments and 16 Keys.
wim 0:dc8789a6e21f 156 * Serial bus interface device.
wim 0:dc8789a6e21f 157 */
wim 0:dc8789a6e21f 158 class TM1637 {
wim 0:dc8789a6e21f 159 public:
wim 0:dc8789a6e21f 160
wim 0:dc8789a6e21f 161 /** Datatype for displaydata */
wim 0:dc8789a6e21f 162 typedef char DisplayData_t[TM1637_DISPLAY_MEM];
wim 0:dc8789a6e21f 163
wim 0:dc8789a6e21f 164 /** Datatypes for keymatrix data */
wim 0:dc8789a6e21f 165 typedef char KeyData_t;
wim 1:f63d87466f55 166
wim 1:f63d87466f55 167 #if(SPI==1)
wim 0:dc8789a6e21f 168 /** Constructor for class for driving TM1637 LED controller
wim 0:dc8789a6e21f 169 *
wim 1:f63d87466f55 170 * @brief Supports 6 Grids @ 8 segments and 16 Keys.
wim 1:f63d87466f55 171 * Serial bus interface device.
wim 1:f63d87466f55 172 * DEPRECATED version
wim 1:f63d87466f55 173 *
wim 1:f63d87466f55 174 * @param PinName mosi_nc Serial bus NC pin
wim 1:f63d87466f55 175 * @param PinName miso_dio Serial bus DIO pin
wim 1:f63d87466f55 176 * @param PinName sclk_clk Serial bus CLK pin
wim 1:f63d87466f55 177 */
wim 1:f63d87466f55 178 TM1637(PinName mosi_nc, PinName miso_dio, PinName sclk_clk);
wim 1:f63d87466f55 179 #endif
wim 1:f63d87466f55 180
wim 1:f63d87466f55 181 /** Constructor for class for driving TM1637 LED controller
wim 1:f63d87466f55 182 *
wim 1:f63d87466f55 183 * @brief Supports 6 Grids @ 8 segments and 16 Keys.
wim 0:dc8789a6e21f 184 * Serial bus interface device.
wim 0:dc8789a6e21f 185 *
wim 1:f63d87466f55 186 * @param PinName dio Serial bus DIO pin
wim 1:f63d87466f55 187 * @param PinName sck Serial bus CLK pin
wim 0:dc8789a6e21f 188 */
wim 1:f63d87466f55 189 TM1637(PinName dio, PinName clk);
wim 1:f63d87466f55 190
wim 1:f63d87466f55 191
wim 0:dc8789a6e21f 192 /** Clear the screen and locate to 0
wim 0:dc8789a6e21f 193 */
wim 0:dc8789a6e21f 194 void cls();
wim 0:dc8789a6e21f 195
wim 0:dc8789a6e21f 196 /** Write databyte to TM1637
wim 0:dc8789a6e21f 197 * @param char data byte written at given address
wim 0:dc8789a6e21f 198 * @param int address display memory location to write byte
wim 0:dc8789a6e21f 199 * @return none
wim 0:dc8789a6e21f 200 */
wim 0:dc8789a6e21f 201 void writeData(char data, int address);
wim 0:dc8789a6e21f 202
wim 0:dc8789a6e21f 203 /** Write Display datablock to TM1637
wim 0:dc8789a6e21f 204 * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=6) bytes for displaydata
wim 0:dc8789a6e21f 205 * @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 206 * @param int address display memory location to write bytes (default = 0)
wim 0:dc8789a6e21f 207 * @return none
wim 0:dc8789a6e21f 208 */
wim 0:dc8789a6e21f 209 void writeData(DisplayData_t data, int length = (TM1637_MAX_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0);
wim 0:dc8789a6e21f 210
wim 0:dc8789a6e21f 211 /** Read keydata block from TM1637
wim 0:dc8789a6e21f 212 * @param *keydata Ptr to bytes for keydata
wim 0:dc8789a6e21f 213 * @return bool keypress True when at least one key was pressed
wim 0:dc8789a6e21f 214 *
wim 0:dc8789a6e21f 215 */
wim 0:dc8789a6e21f 216 bool getKeys(KeyData_t *keydata);
wim 0:dc8789a6e21f 217
wim 0:dc8789a6e21f 218 /** Set Brightness
wim 0:dc8789a6e21f 219 *
wim 0:dc8789a6e21f 220 * @param char brightness (3 significant bits, valid range 0..7 (1/16 .. 14/16 dutycycle)
wim 0:dc8789a6e21f 221 * @return none
wim 0:dc8789a6e21f 222 */
wim 0:dc8789a6e21f 223 void setBrightness(char brightness = TM1637_BRT_DEF);
wim 0:dc8789a6e21f 224
wim 0:dc8789a6e21f 225 /** Set the Display mode On/off
wim 0:dc8789a6e21f 226 *
wim 0:dc8789a6e21f 227 * @param bool display mode
wim 0:dc8789a6e21f 228 */
wim 0:dc8789a6e21f 229 void setDisplay(bool on);
wim 0:dc8789a6e21f 230
wim 1:f63d87466f55 231 private:
wim 1:f63d87466f55 232 #if(SPI==1)
wim 1:f63d87466f55 233 DigitalIn _mosi_nc; //Dummy to avoid breaking deprecated constructor
wim 1:f63d87466f55 234 #endif
wim 1:f63d87466f55 235 DigitalInOut _dio;
wim 1:f63d87466f55 236 DigitalOut _clk;
wim 1:f63d87466f55 237
wim 0:dc8789a6e21f 238 char _display;
wim 0:dc8789a6e21f 239 char _bright;
wim 0:dc8789a6e21f 240
wim 0:dc8789a6e21f 241 /** Init the Serial interface and the controller
wim 0:dc8789a6e21f 242 * @param none
wim 0:dc8789a6e21f 243 * @return none
wim 0:dc8789a6e21f 244 */
wim 0:dc8789a6e21f 245 void _init();
wim 0:dc8789a6e21f 246
wim 0:dc8789a6e21f 247
wim 0:dc8789a6e21f 248 /** Generate Start condition for TM1637
wim 0:dc8789a6e21f 249 * @param none
wim 0:dc8789a6e21f 250 * @return none
wim 0:dc8789a6e21f 251 */
wim 0:dc8789a6e21f 252 void _start();
wim 0:dc8789a6e21f 253
wim 0:dc8789a6e21f 254 /** Generate Stop condition for TM1637
wim 0:dc8789a6e21f 255 * @param none
wim 0:dc8789a6e21f 256 * @return none
wim 0:dc8789a6e21f 257 */
wim 0:dc8789a6e21f 258 void _stop();
wim 0:dc8789a6e21f 259
wim 0:dc8789a6e21f 260 /** Send byte to TM1637
wim 0:dc8789a6e21f 261 * @param int data
wim 0:dc8789a6e21f 262 * @return none
wim 0:dc8789a6e21f 263 */
wim 0:dc8789a6e21f 264 void _write(int data);
wim 0:dc8789a6e21f 265
wim 0:dc8789a6e21f 266 /** Read byte from TM1637
wim 0:dc8789a6e21f 267 * @return read byte
wim 0:dc8789a6e21f 268 */
wim 1:f63d87466f55 269 char _read();
wim 0:dc8789a6e21f 270
wim 0:dc8789a6e21f 271 /** Write command and parameter to TM1637
wim 0:dc8789a6e21f 272 * @param int cmd Command byte
wim 0:dc8789a6e21f 273 * &Param int data Parameters for command
wim 0:dc8789a6e21f 274 * @return none
wim 0:dc8789a6e21f 275 */
wim 0:dc8789a6e21f 276 void _writeCmd(int cmd, int data);
wim 0:dc8789a6e21f 277 };
wim 0:dc8789a6e21f 278
wim 0:dc8789a6e21f 279 #if (CATALEX_TEST == 1)
wim 1:f63d87466f55 280 // Derived class for TM1637 used in CATALEX display unit with 4 Digits
wim 0:dc8789a6e21f 281 //
wim 0:dc8789a6e21f 282
wim 0:dc8789a6e21f 283 #include "Font_7Seg.h"
wim 0:dc8789a6e21f 284
wim 0:dc8789a6e21f 285 #define CATALEX_NR_GRIDS 4
wim 0:dc8789a6e21f 286 #define CATALEX_NR_DIGITS 4
wim 0:dc8789a6e21f 287 #define CATALEX_NR_UDC 8
wim 0:dc8789a6e21f 288
wim 0:dc8789a6e21f 289
wim 0:dc8789a6e21f 290 /** Constructor for class for driving TM1637 controller as used in CATALEX
wim 0:dc8789a6e21f 291 *
wim 1:f63d87466f55 292 * @brief Supports 4 Digits of 7 Segments + DP (or Colon for Digit2 on some models).
wim 1:f63d87466f55 293 * Also Supports up to 16 Keys. Serial bus interface device.
wim 0:dc8789a6e21f 294 *
wim 0:dc8789a6e21f 295 * @param PinName mosi Serial bus MOSI pin
wim 0:dc8789a6e21f 296 * @param PinName miso Serial bus MISO pin
wim 0:dc8789a6e21f 297 * @param PinName sclk Serial bus SCLK pin
wim 0:dc8789a6e21f 298 */
wim 0:dc8789a6e21f 299 class TM1637_CATALEX : public TM1637, public Stream {
wim 0:dc8789a6e21f 300 public:
wim 0:dc8789a6e21f 301
wim 0:dc8789a6e21f 302 /** Enums for Icons */
wim 0:dc8789a6e21f 303 // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 0:dc8789a6e21f 304 enum Icon {
wim 1:f63d87466f55 305 DP1 = ( 1<<24) | S7_DP1, /**< Digit 1 */
wim 1:f63d87466f55 306 DP2 = ( 2<<24) | S7_DP2, /**< Digit 2 */
wim 1:f63d87466f55 307 DP3 = ( 3<<24) | S7_DP3, /**< Digit 3 */
wim 1:f63d87466f55 308 DP4 = ( 4<<24) | S7_DP4, /**< Digit 4 */
wim 1:f63d87466f55 309
wim 0:dc8789a6e21f 310 COL2 = ( 2<<24) | S7_DP2, /**< Column 2 */
wim 0:dc8789a6e21f 311 };
wim 0:dc8789a6e21f 312
wim 0:dc8789a6e21f 313 typedef char UDCData_t[CATALEX_NR_UDC];
wim 1:f63d87466f55 314
wim 1:f63d87466f55 315 #if (SPI==1)
wim 0:dc8789a6e21f 316 /** Constructor for class for driving TM1637 LED controller as used in CATALEX
wim 1:f63d87466f55 317 *
wim 1:f63d87466f55 318 * @brief Supports 4 Digits of 7 Segments + DP (or Colon for Digit2 on some models).
wim 1:f63d87466f55 319 * Also Supports up to 16 Keys. Serial bus interface device.
wim 1:f63d87466f55 320 * DEPRECATED version
wim 1:f63d87466f55 321 *
wim 1:f63d87466f55 322 * @param PinName mosi_nc Serial bus NC pin
wim 1:f63d87466f55 323 * @param PinName miso_dio Serial bus DIO pin
wim 1:f63d87466f55 324 * @param PinName sclk_clk Serial bus CLK pin
wim 0:dc8789a6e21f 325 */
wim 1:f63d87466f55 326 TM1637_CATALEX(PinName mosi_nc, PinName miso_dio, PinName sclk_clk);
wim 1:f63d87466f55 327 #endif
wim 0:dc8789a6e21f 328
wim 1:f63d87466f55 329 /** Constructor for class for driving TM1637 LED controller
wim 1:f63d87466f55 330 *
wim 1:f63d87466f55 331 * @brief Supports 4 Digits of 7 Segments + DP (or Colon for Digit2 on some models).
wim 1:f63d87466f55 332 * Also Supports up to 16 Keys. Serial bus interface device.
wim 1:f63d87466f55 333 *
wim 1:f63d87466f55 334 * @param PinName dio Serial bus DIO pin
wim 1:f63d87466f55 335 * @param PinName sck Serial bus CLK pin
wim 1:f63d87466f55 336 */
wim 1:f63d87466f55 337 TM1637_CATALEX(PinName dio, PinName clk);
wim 1:f63d87466f55 338
wim 1:f63d87466f55 339
wim 0:dc8789a6e21f 340 #if DOXYGEN_ONLY
wim 0:dc8789a6e21f 341 /** Write a character to the Display
wim 0:dc8789a6e21f 342 *
wim 0:dc8789a6e21f 343 * @param c The character to write to the display
wim 0:dc8789a6e21f 344 */
wim 0:dc8789a6e21f 345 int putc(int c);
wim 0:dc8789a6e21f 346
wim 0:dc8789a6e21f 347 /** Write a formatted string to the Display
wim 0:dc8789a6e21f 348 *
wim 0:dc8789a6e21f 349 * @param format A printf-style format string, followed by the
wim 0:dc8789a6e21f 350 * variables to use in formatting the string.
wim 0:dc8789a6e21f 351 */
wim 0:dc8789a6e21f 352 int printf(const char* format, ...);
wim 0:dc8789a6e21f 353 #endif
wim 0:dc8789a6e21f 354
wim 0:dc8789a6e21f 355 /** Locate cursor to a screen column
wim 0:dc8789a6e21f 356 *
wim 0:dc8789a6e21f 357 * @param column The horizontal position from the left, indexed from 0
wim 0:dc8789a6e21f 358 */
wim 0:dc8789a6e21f 359 void locate(int column);
wim 0:dc8789a6e21f 360
wim 0:dc8789a6e21f 361 /** Clear the screen and locate to 0
wim 0:dc8789a6e21f 362 * @param bool clrAll Clear Icons also (default = false)
wim 0:dc8789a6e21f 363 */
wim 0:dc8789a6e21f 364 void cls(bool clrAll = false);
wim 0:dc8789a6e21f 365
wim 0:dc8789a6e21f 366 /** Set Icon
wim 0:dc8789a6e21f 367 *
wim 0:dc8789a6e21f 368 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 0:dc8789a6e21f 369 * @return none
wim 0:dc8789a6e21f 370 */
wim 0:dc8789a6e21f 371 void setIcon(Icon icon);
wim 0:dc8789a6e21f 372
wim 0:dc8789a6e21f 373 /** Clr Icon
wim 0:dc8789a6e21f 374 *
wim 0:dc8789a6e21f 375 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 0:dc8789a6e21f 376 * @return none
wim 0:dc8789a6e21f 377 */
wim 0:dc8789a6e21f 378 void clrIcon(Icon icon);
wim 0:dc8789a6e21f 379
wim 0:dc8789a6e21f 380 /** Set User Defined Characters (UDC)
wim 0:dc8789a6e21f 381 *
wim 0:dc8789a6e21f 382 * @param unsigned char udc_idx The Index of the UDC (0..7)
wim 0:dc8789a6e21f 383 * @param int udc_data The bitpattern for the UDC (16 bits)
wim 0:dc8789a6e21f 384 */
wim 0:dc8789a6e21f 385 void setUDC(unsigned char udc_idx, int udc_data);
wim 0:dc8789a6e21f 386
wim 0:dc8789a6e21f 387
wim 0:dc8789a6e21f 388 /** Number of screen columns
wim 0:dc8789a6e21f 389 *
wim 0:dc8789a6e21f 390 * @param none
wim 0:dc8789a6e21f 391 * @return columns
wim 0:dc8789a6e21f 392 */
wim 0:dc8789a6e21f 393 int columns();
wim 0:dc8789a6e21f 394
wim 0:dc8789a6e21f 395 /** Write databyte to TM1637
wim 0:dc8789a6e21f 396 * @param char data byte written at given address
wim 0:dc8789a6e21f 397 * @param int address display memory location to write byte
wim 0:dc8789a6e21f 398 * @return none
wim 0:dc8789a6e21f 399 */
wim 0:dc8789a6e21f 400 void writeData(char data, int address){
wim 0:dc8789a6e21f 401 TM1637::writeData(data, address);
wim 0:dc8789a6e21f 402 }
wim 0:dc8789a6e21f 403
wim 0:dc8789a6e21f 404 /** Write Display datablock to TM1637
wim 0:dc8789a6e21f 405 * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=4) bytes for displaydata
wim 0:dc8789a6e21f 406 * @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 407 * @param int address display memory location to write bytes (default = 0)
wim 0:dc8789a6e21f 408 * @return none
wim 0:dc8789a6e21f 409 */
wim 0:dc8789a6e21f 410 void writeData(DisplayData_t data, int length = (CATALEX_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0) {
wim 0:dc8789a6e21f 411 TM1637::writeData(data, length, address);
wim 0:dc8789a6e21f 412 }
wim 0:dc8789a6e21f 413
wim 0:dc8789a6e21f 414 protected:
wim 0:dc8789a6e21f 415 // Stream implementation functions
wim 0:dc8789a6e21f 416 virtual int _putc(int value);
wim 0:dc8789a6e21f 417 virtual int _getc();
wim 0:dc8789a6e21f 418
wim 0:dc8789a6e21f 419 private:
wim 0:dc8789a6e21f 420 int _column;
wim 0:dc8789a6e21f 421 int _columns;
wim 0:dc8789a6e21f 422
wim 0:dc8789a6e21f 423 DisplayData_t _displaybuffer;
wim 0:dc8789a6e21f 424 UDCData_t _UDC_7S;
wim 0:dc8789a6e21f 425 };
wim 0:dc8789a6e21f 426 #endif
wim 0:dc8789a6e21f 427
wim 1:f63d87466f55 428 #if (ROBOTDYN_TEST == 1)
wim 1:f63d87466f55 429 // Derived class for TM1637 used in ROBOTDYN 6 Digit display unit
wim 1:f63d87466f55 430 //
wim 1:f63d87466f55 431
wim 1:f63d87466f55 432 #include "Font_7Seg.h"
wim 1:f63d87466f55 433
wim 1:f63d87466f55 434 #define ROBOTDYN_NR_GRIDS 6
wim 1:f63d87466f55 435 #define ROBOTDYN_NR_DIGITS 6
wim 1:f63d87466f55 436 #define ROBOTDYN_NR_UDC 8
wim 1:f63d87466f55 437
wim 1:f63d87466f55 438
wim 1:f63d87466f55 439 /** Constructor for class for driving TM1637 controller as used in ROBOTDYN
wim 1:f63d87466f55 440 *
wim 1:f63d87466f55 441 * @brief Supports 6 Digits of 7 Segments + DP.
wim 1:f63d87466f55 442 *
wim 1:f63d87466f55 443 * @param PinName dio Serial bus DIO pin
wim 1:f63d87466f55 444 * @param PinName clk Serial bus CLK pin
wim 1:f63d87466f55 445 */
wim 1:f63d87466f55 446 class TM1637_ROBOTDYN : public TM1637, public Stream {
wim 1:f63d87466f55 447 public:
wim 1:f63d87466f55 448
wim 1:f63d87466f55 449 /** Enums for Icons */
wim 1:f63d87466f55 450 // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 1:f63d87466f55 451 // Note that Digits 1,3 and 4,6 are swapped!
wim 1:f63d87466f55 452 enum Icon {
wim 1:f63d87466f55 453 DP1 = ( 3<<24) | S7_DP1, /**< Digit 1 */
wim 1:f63d87466f55 454 DP2 = ( 2<<24) | S7_DP2, /**< Digit 2 */
wim 1:f63d87466f55 455 DP3 = ( 1<<24) | S7_DP3, /**< Digit 3 */
wim 1:f63d87466f55 456 DP4 = ( 6<<24) | S7_DP4, /**< Digit 4 */
wim 1:f63d87466f55 457 DP5 = ( 5<<24) | S7_DP5, /**< Digit 5 */
wim 1:f63d87466f55 458 DP6 = ( 4<<24) | S7_DP6, /**< Digit 6 */
wim 1:f63d87466f55 459 };
wim 1:f63d87466f55 460
wim 1:f63d87466f55 461 typedef char UDCData_t[ROBOTDYN_NR_UDC];
wim 1:f63d87466f55 462
wim 1:f63d87466f55 463 /** Constructor for class for driving TM1637 LED controller as used in ROBOTDYN
wim 1:f63d87466f55 464 *
wim 1:f63d87466f55 465 * @brief Supports 6 Digits of 7 Segments + DP. Also supports up to 16 Keys.
wim 1:f63d87466f55 466 *
wim 1:f63d87466f55 467 * @param PinName dio Serial bus DIO pin
wim 1:f63d87466f55 468 * @param PinName clk Serial bus CLK pin
wim 1:f63d87466f55 469 */
wim 1:f63d87466f55 470 TM1637_ROBOTDYN(PinName dio, PinName clk);
wim 1:f63d87466f55 471
wim 1:f63d87466f55 472
wim 1:f63d87466f55 473 #if DOXYGEN_ONLY
wim 1:f63d87466f55 474 /** Write a character to the Display
wim 1:f63d87466f55 475 *
wim 1:f63d87466f55 476 * @param c The character to write to the display
wim 1:f63d87466f55 477 */
wim 1:f63d87466f55 478 int putc(int c);
wim 1:f63d87466f55 479
wim 1:f63d87466f55 480 /** Write a formatted string to the Display
wim 1:f63d87466f55 481 *
wim 1:f63d87466f55 482 * @param format A printf-style format string, followed by the
wim 1:f63d87466f55 483 * variables to use in formatting the string.
wim 1:f63d87466f55 484 */
wim 1:f63d87466f55 485 int printf(const char* format, ...);
wim 1:f63d87466f55 486 #endif
wim 1:f63d87466f55 487
wim 1:f63d87466f55 488 /** Locate cursor to a screen column
wim 1:f63d87466f55 489 *
wim 1:f63d87466f55 490 * @param column The horizontal position from the left, indexed from 0
wim 1:f63d87466f55 491 */
wim 1:f63d87466f55 492 void locate(int column);
wim 1:f63d87466f55 493
wim 1:f63d87466f55 494 /** Clear the screen and locate to 0
wim 1:f63d87466f55 495 * @param bool clrAll Clear Icons also (default = false)
wim 1:f63d87466f55 496 */
wim 1:f63d87466f55 497 void cls(bool clrAll = false);
wim 1:f63d87466f55 498
wim 1:f63d87466f55 499 /** Set Icon
wim 1:f63d87466f55 500 *
wim 1:f63d87466f55 501 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 1:f63d87466f55 502 * @return none
wim 1:f63d87466f55 503 */
wim 1:f63d87466f55 504 void setIcon(Icon icon);
wim 1:f63d87466f55 505
wim 1:f63d87466f55 506 /** Clr Icon
wim 1:f63d87466f55 507 *
wim 1:f63d87466f55 508 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 1:f63d87466f55 509 * @return none
wim 1:f63d87466f55 510 */
wim 1:f63d87466f55 511 void clrIcon(Icon icon);
wim 1:f63d87466f55 512
wim 1:f63d87466f55 513 /** Set User Defined Characters (UDC)
wim 1:f63d87466f55 514 *
wim 1:f63d87466f55 515 * @param unsigned char udc_idx The Index of the UDC (0..7)
wim 1:f63d87466f55 516 * @param int udc_data The bitpattern for the UDC (16 bits)
wim 1:f63d87466f55 517 */
wim 1:f63d87466f55 518 void setUDC(unsigned char udc_idx, int udc_data);
wim 1:f63d87466f55 519
wim 1:f63d87466f55 520
wim 1:f63d87466f55 521 /** Number of screen columns
wim 1:f63d87466f55 522 *
wim 1:f63d87466f55 523 * @param none
wim 1:f63d87466f55 524 * @return columns
wim 1:f63d87466f55 525 */
wim 1:f63d87466f55 526 int columns();
wim 1:f63d87466f55 527
wim 1:f63d87466f55 528 /** Write databyte to TM1637
wim 1:f63d87466f55 529 * @param char data byte written at given address
wim 1:f63d87466f55 530 * @param int address display memory location to write byte
wim 1:f63d87466f55 531 * @return none
wim 1:f63d87466f55 532 */
wim 1:f63d87466f55 533 void writeData(char data, int address){
wim 1:f63d87466f55 534 TM1637::writeData(data, address);
wim 1:f63d87466f55 535 }
wim 1:f63d87466f55 536
wim 1:f63d87466f55 537 /** Write Display datablock to TM1637
wim 1:f63d87466f55 538 * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=6) bytes for displaydata
wim 1:f63d87466f55 539 * @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 540 * @param int address display memory location to write bytes (default = 0)
wim 1:f63d87466f55 541 * @return none
wim 1:f63d87466f55 542 */
wim 1:f63d87466f55 543 void writeData(DisplayData_t data, int length = (ROBOTDYN_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0) {
wim 1:f63d87466f55 544 TM1637::writeData(data, length, address);
wim 1:f63d87466f55 545 }
wim 1:f63d87466f55 546
wim 1:f63d87466f55 547 protected:
wim 1:f63d87466f55 548 // Stream implementation functions
wim 1:f63d87466f55 549 virtual int _putc(int value);
wim 1:f63d87466f55 550 virtual int _getc();
wim 1:f63d87466f55 551
wim 1:f63d87466f55 552 private:
wim 1:f63d87466f55 553 int _column;
wim 1:f63d87466f55 554 int _columns;
wim 1:f63d87466f55 555
wim 1:f63d87466f55 556 DisplayData_t _displaybuffer;
wim 1:f63d87466f55 557 UDCData_t _UDC_7S;
wim 1:f63d87466f55 558 };
wim 1:f63d87466f55 559 #endif
wim 1:f63d87466f55 560
wim 1:f63d87466f55 561
wim 1:f63d87466f55 562 #if (EYEWINK_TEST == 1)
wim 1:f63d87466f55 563 // Derived class for TM1637 used in EYEWINK 6 Digit + 6 Keys display unit
wim 1:f63d87466f55 564 //
wim 1:f63d87466f55 565
wim 1:f63d87466f55 566 #include "Font_7Seg.h"
wim 1:f63d87466f55 567
wim 1:f63d87466f55 568 #define EYEWINK_NR_GRIDS 6
wim 1:f63d87466f55 569 #define EYEWINK_NR_DIGITS 6
wim 1:f63d87466f55 570 #define EYEWINK_NR_UDC 8
wim 1:f63d87466f55 571
wim 1:f63d87466f55 572
wim 1:f63d87466f55 573 /** Constructor for class for driving TM1637 controller as used in EYEWINK
wim 1:f63d87466f55 574 *
wim 1:f63d87466f55 575 * @brief Supports 6 Digits of 7 Segments + DP and 6 Keys.
wim 1:f63d87466f55 576 *
wim 1:f63d87466f55 577 * @param PinName dio Serial bus DIO pin
wim 1:f63d87466f55 578 * @param PinName clk Serial bus CLK pin
wim 1:f63d87466f55 579 */
wim 1:f63d87466f55 580 class TM1637_EYEWINK : public TM1637, public Stream {
wim 1:f63d87466f55 581 public:
wim 1:f63d87466f55 582
wim 1:f63d87466f55 583 /** Enums for Icons */
wim 1:f63d87466f55 584 // Grid encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 1:f63d87466f55 585 enum Icon {
wim 1:f63d87466f55 586 DP1 = ( 1<<24) | S7_DP1, /**< Digit 1 */
wim 1:f63d87466f55 587 DP2 = ( 2<<24) | S7_DP2, /**< Digit 2 */
wim 1:f63d87466f55 588 DP3 = ( 3<<24) | S7_DP3, /**< Digit 3 */
wim 1:f63d87466f55 589 DP4 = ( 4<<24) | S7_DP4, /**< Digit 4 */
wim 1:f63d87466f55 590 DP5 = ( 5<<24) | S7_DP5, /**< Digit 5 */
wim 1:f63d87466f55 591 DP6 = ( 6<<24) | S7_DP6, /**< Digit 6 */
wim 1:f63d87466f55 592 };
wim 1:f63d87466f55 593
wim 1:f63d87466f55 594 typedef char UDCData_t[EYEWINK_NR_UDC];
wim 1:f63d87466f55 595
wim 1:f63d87466f55 596 /** Constructor for class for driving TM1637 LED controller as used in EYEWINK
wim 1:f63d87466f55 597 *
wim 1:f63d87466f55 598 * @brief Supports 6 Digits of 7 Segments + DP.
wim 1:f63d87466f55 599 *
wim 1:f63d87466f55 600 * @param PinName dio Serial bus DIO pin
wim 1:f63d87466f55 601 * @param PinName clk Serial bus CLK pin
wim 1:f63d87466f55 602 */
wim 1:f63d87466f55 603 TM1637_EYEWINK(PinName dio, PinName clk);
wim 1:f63d87466f55 604
wim 1:f63d87466f55 605
wim 1:f63d87466f55 606 #if DOXYGEN_ONLY
wim 1:f63d87466f55 607 /** Write a character to the Display
wim 1:f63d87466f55 608 *
wim 1:f63d87466f55 609 * @param c The character to write to the display
wim 1:f63d87466f55 610 */
wim 1:f63d87466f55 611 int putc(int c);
wim 1:f63d87466f55 612
wim 1:f63d87466f55 613 /** Write a formatted string to the Display
wim 1:f63d87466f55 614 *
wim 1:f63d87466f55 615 * @param format A printf-style format string, followed by the
wim 1:f63d87466f55 616 * variables to use in formatting the string.
wim 1:f63d87466f55 617 */
wim 1:f63d87466f55 618 int printf(const char* format, ...);
wim 1:f63d87466f55 619 #endif
wim 1:f63d87466f55 620
wim 1:f63d87466f55 621 /** Locate cursor to a screen column
wim 1:f63d87466f55 622 *
wim 1:f63d87466f55 623 * @param column The horizontal position from the left, indexed from 0
wim 1:f63d87466f55 624 */
wim 1:f63d87466f55 625 void locate(int column);
wim 1:f63d87466f55 626
wim 1:f63d87466f55 627 /** Clear the screen and locate to 0
wim 1:f63d87466f55 628 * @param bool clrAll Clear Icons also (default = false)
wim 1:f63d87466f55 629 */
wim 1:f63d87466f55 630 void cls(bool clrAll = false);
wim 1:f63d87466f55 631
wim 1:f63d87466f55 632 /** Set Icon
wim 1:f63d87466f55 633 *
wim 1:f63d87466f55 634 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 1:f63d87466f55 635 * @return none
wim 1:f63d87466f55 636 */
wim 1:f63d87466f55 637 void setIcon(Icon icon);
wim 1:f63d87466f55 638
wim 1:f63d87466f55 639 /** Clr Icon
wim 1:f63d87466f55 640 *
wim 1:f63d87466f55 641 * @param Icon icon Enums Icon has Grid position encoded in 8 MSBs, Icon pattern encoded in 16 LSBs
wim 1:f63d87466f55 642 * @return none
wim 1:f63d87466f55 643 */
wim 1:f63d87466f55 644 void clrIcon(Icon icon);
wim 1:f63d87466f55 645
wim 1:f63d87466f55 646 /** Set User Defined Characters (UDC)
wim 1:f63d87466f55 647 *
wim 1:f63d87466f55 648 * @param unsigned char udc_idx The Index of the UDC (0..7)
wim 1:f63d87466f55 649 * @param int udc_data The bitpattern for the UDC (16 bits)
wim 1:f63d87466f55 650 */
wim 1:f63d87466f55 651 void setUDC(unsigned char udc_idx, int udc_data);
wim 1:f63d87466f55 652
wim 1:f63d87466f55 653
wim 1:f63d87466f55 654 /** Number of screen columns
wim 1:f63d87466f55 655 *
wim 1:f63d87466f55 656 * @param none
wim 1:f63d87466f55 657 * @return columns
wim 1:f63d87466f55 658 */
wim 1:f63d87466f55 659 int columns();
wim 1:f63d87466f55 660
wim 1:f63d87466f55 661 /** Write databyte to TM1637
wim 1:f63d87466f55 662 * @param char data byte written at given address
wim 1:f63d87466f55 663 * @param int address display memory location to write byte
wim 1:f63d87466f55 664 * @return none
wim 1:f63d87466f55 665 */
wim 1:f63d87466f55 666 void writeData(char data, int address){
wim 1:f63d87466f55 667 TM1637::writeData(data, address);
wim 1:f63d87466f55 668 }
wim 1:f63d87466f55 669
wim 1:f63d87466f55 670 /** Write Display datablock to TM1637
wim 1:f63d87466f55 671 * @param DisplayData_t data Array of TM1637_DISPLAY_MEM (=6) bytes for displaydata
wim 1:f63d87466f55 672 * @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 673 * @param int address display memory location to write bytes (default = 0)
wim 1:f63d87466f55 674 * @return none
wim 1:f63d87466f55 675 */
wim 1:f63d87466f55 676 void writeData(DisplayData_t data, int length = (EYEWINK_NR_GRIDS * TM1637_BYTES_PER_GRID), int address = 0) {
wim 1:f63d87466f55 677 TM1637::writeData(data, length, address);
wim 1:f63d87466f55 678 }
wim 1:f63d87466f55 679
wim 1:f63d87466f55 680 protected:
wim 1:f63d87466f55 681 // Stream implementation functions
wim 1:f63d87466f55 682 virtual int _putc(int value);
wim 1:f63d87466f55 683 virtual int _getc();
wim 1:f63d87466f55 684
wim 1:f63d87466f55 685 private:
wim 1:f63d87466f55 686 int _column;
wim 1:f63d87466f55 687 int _columns;
wim 1:f63d87466f55 688
wim 1:f63d87466f55 689 DisplayData_t _displaybuffer;
wim 1:f63d87466f55 690 UDCData_t _UDC_7S;
wim 1:f63d87466f55 691 };
wim 1:f63d87466f55 692 #endif
wim 1:f63d87466f55 693
wim 0:dc8789a6e21f 694 #endif