├── .github └── FUNDING.yml ├── LICENSE.TXT ├── NimaLTD.NimaLTD-TM1637_conf.h ├── README.md ├── tm1637.c └── tm1637.h /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [nimaltd] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: nimaltd 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: #nimaltd 10 | issuehunt: #nimaltd 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | Software License Terms 2 | 3 | This software is dual-licensed: 4 | 5 | 1. GNU General Public License v2 (GPLv2): 6 | - You may redistribute and/or modify this software under the terms of GPLv2 as published by the Free Software Foundation. 7 | - This license does not provide any warranty of any kind, including but not limited to MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | - See for details. 9 | 10 | 2. Commercial License: 11 | - The commercial license removes all GPLv2 restrictions and allows you to redistribute your closed-source products with the Library embedded. 12 | - This license includes access to software maintenance, such as updates and upgrades. Customers who purchase this license are eligible to receive updates whenever 13 | they are released. However, the software provider is not obligated to release updates on a specific schedule. 14 | - The commercial license is available in two models: 15 | - Single-Product License: Allows usage in one specific product. 16 | - Company-Wide License: Allows usage across all products of the company. 17 | - No Warranty: The software is provided "AS IS" without any warranties, express or implied, including but not limited to the implied warranties of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, or NON-INFRINGEMENT. 18 | - Liability Disclaimer: In no event shall the copyright holder or contributors be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software. 19 | 20 | By using this software under the commercial license, you agree to these terms and acknowledge that no additional guarantees or obligations are provided beyond what is explicitly stated in this document. 21 | 22 | --- 23 | 24 | Copyright © Nima Askari, 2025. All rights reserved. 25 | For inquiries, contact: nima.askari@gmail.com All rights reserved 26 | -------------------------------------------------------------------------------- /NimaLTD.NimaLTD-TM1637_conf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @author Nima Askari 4 | * @license See the LICENSE file in the root folder. 5 | * 6 | * @github https://www.github.com/nimaltd 7 | * @linkedin https://www.linkedin.com/in/nimaltd 8 | * @youtube https://www.youtube.com/@nimaltd 9 | * @instagram https://instagram.com/github.nimaltd 10 | * 11 | * Copyright (C) 2025 Nima Askari - NimaLTD. All rights reserved. 12 | * 13 | */ 14 | 15 | /* Define to prevent recursive inclusion -------------------------------------*/ 16 | #ifndef _NIMALTD_TM1637_CONF_H_ 17 | #define _NIMALTD_TM1637_CONF_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /* Includes ------------------------------------------------------------------*/ 24 | 25 | /** 26 | MiddleWare name : NimaLTD.NimaLTD-TM1637.2.0.0 27 | MiddleWare fileName : NimaLTD.NimaLTD-TM1637_conf.h 28 | MiddleWare version : 2.0.0 29 | */ 30 | /*---------- TM1637_DELAY -----------*/ 31 | #define TM1637_DELAY 10 32 | 33 | /*---------- TM1637_ENABLE_ALFABET -----------*/ 34 | #define TM1637_ENABLE_ALFABET false 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif /*_ NIMALTD_TM1637_CONF_H_ */ 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TM1637 7-Segment Display Driver 2 | 3 | ## Author & License 4 | 5 | - **Author:** Nima Askari 6 | - **Version:** 2.0.0 7 | - **License:** See the [`LICENSE`](LICENSE.TXT) file in the root folder. 8 | 9 | --- 10 | 11 | ### Connect with Me, Support Me 12 | 13 | - [![YouTube](https://img.shields.io/badge/YouTube-Subscribe-red?style=for-the-badge&logo=youtube)](https://youtube.com/@nimaltd) 14 | - [![Instagram](https://img.shields.io/badge/Instagram-Follow-blue?style=for-the-badge&logo=instagram)](https://instagram.com/github.nimaltd) 15 | - [![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-blue?style=for-the-badge&logo=linkedin)](https://linkedin.com/in/nimaltd) 16 | - [![Email](https://img.shields.io/badge/Email-Contact-red?style=for-the-badge&logo=gmail)](mailto:nima.askari@gmail.com) 17 | - [![Ko-fi](https://img.shields.io/badge/Ko--fi-Support-orange?style=for-the-badge&logo=ko-fi)](https://ko-fi.com/nimaltd) 18 | 19 | © 2025 Nima Askari - NimaLTD. All rights reserved. 20 | 21 | --- 22 | 23 | ## TM1637 7-Segment Display Driver Help 24 | 25 | ### Pin Connections 26 | 27 | | Display Segment | TM1637 Pin | 28 | |----------------|-----------| 29 | | A | SEG1 | 30 | | B | SEG2 | 31 | | C | SEG3 | 32 | | D | SEG4 | 33 | | E | SEG5 | 34 | | F | SEG6 | 35 | | G | SEG7 | 36 | | . (Dot) | SEG8 | 37 | 38 | --- 39 | 40 | ## Installation 41 | 42 | To install the package, add the following address to your STM32 package manager: 43 | 44 | ``` 45 | https://github.com/nimaltd/STM32-PACK/raw/main/NimaLTD.pidx 46 | ``` 47 | 48 | ## STM32CubeMX Configuration 49 | 50 | Set **CLK (Clock)** and **DIO (Data I/O)** pins as: 51 | - **Mode:** Output Open Drain 52 | - **Select:** High-level initialization 53 | 54 | --- 55 | 56 | ## Usage 57 | 58 | ### 1. Declare a Display Instance 59 | Create an instance for each display: 60 | 61 | ```c 62 | tm1637_t seg = 63 | { 64 | .seg_cnt = 4, 65 | .gpio_clk = GPIOA, 66 | .gpio_dat = GPIOA, 67 | .pin_clk = GPIO_PIN_1, 68 | .pin_data = GPIO_PIN_2, 69 | }; 70 | tm1637_init(&seg); 71 | tm1637_disp_str(&seg, "1234"); 72 | ``` 73 | 74 | # Watch the Video: 75 | 76 |
77 | Video 78 |
79 | -------------------------------------------------------------------------------- /tm1637.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @file TM1637 4 | * @author Nima Askari 5 | * @version 2.0.0 6 | * @license See the LICENSE file in the root folder. 7 | * 8 | * @github https://www.github.com/nimaltd 9 | * @linkedin https://www.linkedin.com/in/nimaltd 10 | * @youtube https://www.youtube.com/@nimaltd 11 | * @instagram https://instagram.com/github.nimaltd 12 | * 13 | * Copyright (C) 2025 Nima Askari - NimaLTD. All rights reserved. 14 | * 15 | */ 16 | 17 | /*************************************************************************************************/ 18 | /** Includes **/ 19 | /*************************************************************************************************/ 20 | 21 | #include "tm1637.h" 22 | #include "NimaLTD.NimaLTD-TM1637_conf.h" 23 | 24 | /*************************************************************************************************/ 25 | /** Macros and Definitions **/ 26 | /*************************************************************************************************/ 27 | 28 | #define TM1637_COMM1 0x40 29 | #define TM1637_COMM2 0xC0 30 | #define TM1637_COMM3_OFF 0x80 31 | #define TM1637_COMM3_ON 0x88 32 | #define TM1637_SEG_MAX 6 33 | 34 | /*************************************************************************************************/ 35 | /** Static Function Prototypes **/ 36 | /*************************************************************************************************/ 37 | 38 | static void tm1637_delay(void); 39 | static void tm1637_start(tm1637_t *handle); 40 | static void tm1637_stop(tm1637_t *handle); 41 | static tm1637_err_t tm1637_write(tm1637_t *handle, uint8_t data); 42 | 43 | /*************************************************************************************************/ 44 | /** Function Implementations **/ 45 | /*************************************************************************************************/ 46 | 47 | /*************************************************************************************************/ 48 | /** 49 | * @brief Initializes the TM1637 display driver. 50 | * 51 | * @param[in] handle Pointer to the TM1637 handle structure. 52 | * 53 | * @return tm1637_err_t Error code indicating success or failure. 54 | */ 55 | tm1637_err_t tm1637_init(tm1637_t *handle) 56 | { 57 | tm1637_err_t err; 58 | assert_param(handle != NULL); 59 | assert_param(handle->mode <= TM1637_MODE_RIGHT_ALIG_WITH_ZERO); 60 | assert_param(handle->max < 6); 61 | assert_param(handle->max > 0); 62 | assert_param(IS_GPIO_PIN(pin_clk)); 63 | assert_param(IS_GPIO_PIN(pin_dat)); 64 | assert_param(handle->gpio_dat != NULL); 65 | assert_param(handle->gpio_clk != NULL); 66 | handle->gpio_clk->BSRR = handle->pin_clk; 67 | handle->gpio_dat->BSRR = handle->pin_dat; 68 | tm1637_start(handle); 69 | err = tm1637_write(handle, TM1637_COMM1); 70 | tm1637_stop(handle); 71 | return err; 72 | } 73 | 74 | /*************************************************************************************************/ 75 | /** 76 | * @brief Sets the brightness level of the TM1637 display. 77 | * 78 | * @param[in] handle Pointer to the TM1637 handle structure. 79 | * @param[in] brightness_0_8 Brightness level (0-8), where 0 turns off the display. 80 | * 81 | * @return tm1637_err_t Error code indicating success or failure. 82 | */ 83 | tm1637_err_t tm1637_brightness(tm1637_t *handle, uint8_t brightness_0_8) 84 | { 85 | tm1637_err_t err; 86 | uint8_t tmp = brightness_0_8 > 8 ? 8 : brightness_0_8; 87 | tmp = (brightness_0_8 == 0) ? TM1637_COMM3_OFF : TM1637_COMM3_ON; 88 | if (brightness_0_8 > 0) 89 | { 90 | brightness_0_8--; 91 | } 92 | tm1637_start(handle); 93 | err = tm1637_write(handle, tmp | brightness_0_8); 94 | tm1637_stop(handle); 95 | return err; 96 | } 97 | 98 | /*************************************************************************************************/ 99 | /** 100 | * @brief Sets the number of 7-segment digits to be used on the TM1637 display. 101 | * 102 | * @param[in] handle Pointer to the TM1637 handle structure. 103 | * @param[in] seg_1_6 Number of segments (1-6). Values greater than 6 are capped at 6, and 0 is set to 1. 104 | */ 105 | void tm1637_seg(tm1637_t *handle, uint8_t seg_1_6) 106 | { 107 | handle->seg_cnt = (seg_1_6 > 6) ? 6 : seg_1_6; 108 | handle->seg_cnt = (handle->seg_cnt == 0) ? 1 : handle->seg_cnt; 109 | } 110 | 111 | /*************************************************************************************************/ 112 | /** 113 | * @brief Displays raw segment data on the TM1637 display. 114 | * 115 | * @param[in] handle Pointer to the TM1637 handle structure. 116 | * @param[in] data Pointer to an array containing raw segment data. 117 | * 118 | * @return tm1637_err_t Error code indicating success or failure. 119 | */ 120 | tm1637_err_t tm1637_disp_raw(tm1637_t *handle, const uint8_t *data) 121 | { 122 | tm1637_err_t err; 123 | tm1637_start(handle); 124 | err = tm1637_write(handle, TM1637_COMM2); 125 | if (err != TM1637_ERR_NONE) 126 | { 127 | return TM1637_ERR_ERROR; 128 | } 129 | for (uint8_t i = 0; i < handle->seg_cnt; i++) 130 | { 131 | err = tm1637_write(handle, data[i]); 132 | if (err != TM1637_ERR_NONE) 133 | { 134 | break; 135 | } 136 | } 137 | tm1637_stop(handle); 138 | return err; 139 | } 140 | 141 | /*************************************************************************************************/ 142 | /** 143 | * @brief Displays a string on the TM1637 7-segment display. 144 | * 145 | * @param[in] handle Pointer to the TM1637 handle structure. 146 | * @param[in] str Pointer to a null-terminated string to display. 147 | * Supports numbers (0-9), letters (if enabled), '-' and '.' for decimal points. 148 | * 149 | * @return tm1637_err_t Error code indicating success or failure. 150 | */ 151 | tm1637_err_t tm1637_disp_str(tm1637_t *handle, const char *str) 152 | { 153 | uint8_t buff[TM1637_SEG_MAX + 1] = {0}; 154 | char *str_tmp = (char*)str; 155 | for (int i = 0; i < handle->seg_cnt; i++) 156 | { 157 | switch (*str_tmp) 158 | { 159 | case '0': 160 | buff[i] = 0x3f; 161 | break; 162 | case '1': 163 | buff[i] = 0x06; 164 | break; 165 | case '2': 166 | buff[i] = 0x5b; 167 | break; 168 | case '3': 169 | buff[i] = 0x4f; 170 | break; 171 | case '4': 172 | buff[i] = 0x66; 173 | break; 174 | case '5': 175 | buff[i] = 0x6d; 176 | break; 177 | case '6': 178 | buff[i] = 0x7d; 179 | break; 180 | case '7': 181 | buff[i] = 0x07; 182 | break; 183 | case '8': 184 | buff[i] = 0x7f; 185 | break; 186 | case '9': 187 | buff[i] = 0x6f; 188 | break; 189 | case '-': 190 | buff[i] = 0x40; 191 | break; 192 | #if (TM1637_ENABLE_ALFABET == true) 193 | case 'A': 194 | case 'a': 195 | buff[i] = 0x77; 196 | break; 197 | case 'B': 198 | case 'b': 199 | buff[i] = 0x7C; 200 | break; 201 | case 'C': 202 | case 'c': 203 | buff[i] = 0x58; 204 | break; 205 | case 'D': 206 | case 'd': 207 | buff[i] = 0x5E; 208 | break; 209 | case 'E': 210 | case 'e': 211 | buff[i] = 0x79; 212 | break; 213 | case 'F': 214 | case 'f': 215 | buff[i] = 0x71; 216 | break; 217 | case 'G': 218 | case 'g': 219 | buff[i] = 0x6f; 220 | break; 221 | case 'H': 222 | case 'h': 223 | buff[i] = 0x76; 224 | break; 225 | case 'I': 226 | case 'i': 227 | buff[i] = 0x06; 228 | break; 229 | case 'J': 230 | case 'j': 231 | buff[i] = 0x0E; 232 | break; 233 | case 'L': 234 | case 'l': 235 | buff[i] = 0x38; 236 | break; 237 | case 'N': 238 | case 'n': 239 | buff[i] = 0x54; 240 | break; 241 | case 'O': 242 | case 'o': 243 | buff[i] = 0x5C; 244 | break; 245 | case 'P': 246 | case 'p': 247 | buff[i] = 0x73; 248 | break; 249 | case 'Q': 250 | case 'q': 251 | buff[i] = 0x67; 252 | break; 253 | case 'R': 254 | case 'r': 255 | buff[i] = 0x50; 256 | break; 257 | case 'S': 258 | case 's': 259 | buff[i] = 0x6D; 260 | break; 261 | case 'T': 262 | case 't': 263 | buff[i] = 0x78; 264 | break; 265 | case 'U': 266 | case 'u': 267 | buff[i] = 0x1C; 268 | break; 269 | case 'Y': 270 | case 'y': 271 | buff[i] = 0x6E; 272 | break; 273 | #endif 274 | default: 275 | buff[i] = 0; 276 | break; 277 | } 278 | if (*(str_tmp + 1) == '.') 279 | { 280 | buff[i] |= 0x80; 281 | str_tmp++; 282 | } 283 | str_tmp++; 284 | } 285 | return tm1637_disp_raw(handle, buff); 286 | } 287 | 288 | /*************************************************************************************************/ 289 | /** 290 | * @brief Displays a formatted string on the TM1637 7-segment display. 291 | * 292 | * @param[in] handle Pointer to the TM1637 handle structure. 293 | * @param[in] format Format string (printf-style) to display. 294 | * @param[in] ... Additional arguments for the formatted string. 295 | * 296 | * @return tm1637_err_t Error code indicating success or failure. 297 | */ 298 | tm1637_err_t tm1637_disp_printf(tm1637_t *handle, const char *format, ...) 299 | { 300 | char buff[TM1637_SEG_MAX + 1] = {0}; 301 | va_list args; 302 | va_start(args, format); 303 | int chars_written = vsnprintf(buff, sizeof(buff), format, args); 304 | va_end(args); 305 | if (chars_written < 0) 306 | { 307 | return TM1637_ERR_ERROR; 308 | } 309 | return tm1637_disp_str(handle, buff); 310 | } 311 | 312 | /*************************************************************************************************/ 313 | /** 314 | * @brief Clears the TM1637 display by setting all segments to off. 315 | * 316 | * @param[in] handle Pointer to the TM1637 handle structure. 317 | * 318 | * @return tm1637_err_t Error code indicating success or failure. 319 | */ 320 | tm1637_err_t tm1637_disp_clear(tm1637_t *handle) 321 | { 322 | const uint8_t buff[TM1637_SEG_MAX] = {0}; 323 | return tm1637_disp_raw(handle, buff); 324 | } 325 | 326 | /*************************************************************************************************/ 327 | /** Static Function Implementations **/ 328 | /*************************************************************************************************/ 329 | 330 | /*************************************************************************************************/ 331 | /** 332 | * @brief Provides a delay for the TM1637 display operations. 333 | * 334 | * This function uses a simple loop to generate a delay for controlling the timing 335 | * of the TM1637 display operations. 336 | * 337 | * @param[in] None 338 | * 339 | * @return None 340 | */ 341 | static void tm1637_delay(void) 342 | { 343 | for (uint32_t i = 0; i < TM1637_DELAY; i++) 344 | { 345 | __NOP(); 346 | } 347 | } 348 | 349 | /*************************************************************************************************/ 350 | /** 351 | * @brief Generates a start condition for the TM1637 communication. 352 | * 353 | * This function generates a start condition by toggling the clock and data lines. 354 | * The start condition is necessary to begin communication with the TM1637 display. 355 | * 356 | * @param[in] handle Pointer to the TM1637 handle structure. 357 | * 358 | * @return None 359 | */ 360 | static void tm1637_start(tm1637_t *handle) 361 | { 362 | handle->gpio_clk->BSRR = handle->pin_clk; 363 | handle->gpio_dat->BSRR = handle->pin_dat; 364 | tm1637_delay(); 365 | handle->gpio_dat->BSRR = handle->pin_dat << 16; 366 | tm1637_delay(); 367 | } 368 | 369 | /*************************************************************************************************/ 370 | /** 371 | * @brief Generates a stop condition for the TM1637 communication. 372 | * 373 | * This function generates a stop condition by toggling the data and clock lines. 374 | * The stop condition signals the end of communication with the TM1637 display. 375 | * 376 | * @param[in] handle Pointer to the TM1637 handle structure. 377 | * 378 | * @return None 379 | */ 380 | static void tm1637_stop(tm1637_t *handle) 381 | { 382 | handle->gpio_dat->BSRR = handle->pin_dat << 16; 383 | tm1637_delay(); 384 | handle->gpio_clk->BSRR = handle->pin_clk; 385 | tm1637_delay(); 386 | handle->gpio_dat->BSRR = handle->pin_dat; 387 | tm1637_delay(); 388 | } 389 | 390 | /*************************************************************************************************/ 391 | /** 392 | * @brief Writes a byte of data to the TM1637 display. 393 | * 394 | * This function sends a single byte of data to the TM1637 display, bit by bit, 395 | * through the data and clock lines. It also handles the acknowledgment signal 396 | * from the TM1637 after sending the data. 397 | * 398 | * @param[in] handle Pointer to the TM1637 handle structure. 399 | * @param[in] data The byte of data to send to the display. 400 | * 401 | * @return tm1637_err_t Error code indicating success or failure. 402 | */ 403 | static tm1637_err_t tm1637_write(tm1637_t *handle, uint8_t data) 404 | { 405 | uint8_t tmp = data; 406 | for (int i = 0; i < 8; i++) 407 | { 408 | handle->gpio_clk->BSRR = handle->pin_clk << 16; 409 | tm1637_delay(); 410 | handle->gpio_dat->BSRR = (tmp & 0x01) ? handle->pin_dat : (handle->pin_dat << 16); 411 | tm1637_delay(); 412 | handle->gpio_clk->BSRR = handle->pin_clk; 413 | tm1637_delay(); 414 | tmp >>= 1; 415 | } 416 | handle->gpio_clk->BSRR = handle->pin_clk << 16; 417 | handle->gpio_dat->BSRR = handle->pin_dat; 418 | tm1637_delay(); 419 | handle->gpio_clk->BSRR = handle->pin_clk; 420 | tm1637_delay(); 421 | tm1637_delay(); 422 | tmp = (handle->gpio_dat->IDR & handle->pin_dat) ? 1 : 0; 423 | handle->gpio_dat->BSRR = (tmp == 0) ? (handle->pin_dat << 16) : handle->pin_dat; 424 | tm1637_delay(); 425 | handle->gpio_clk->BSRR = handle->pin_clk << 16; 426 | tm1637_delay(); 427 | return (tm1637_err_t)tmp; 428 | } 429 | 430 | /*************************************************************************************************/ 431 | /** End of File **/ 432 | /*************************************************************************************************/ 433 | -------------------------------------------------------------------------------- /tm1637.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @file TM1637 4 | * @author Nima Askari 5 | * @version 2.0.0 6 | * @license See the LICENSE file in the root folder. 7 | * 8 | * @github https://www.github.com/nimaltd 9 | * @linkedin https://www.linkedin.com/in/nimaltd 10 | * @youtube https://www.youtube.com/@nimaltd 11 | * @instagram https://instagram.com/github.nimaltd 12 | * 13 | * Copyright (C) 2025 Nima Askari - NimaLTD. All rights reserved. 14 | * 15 | */ 16 | 17 | /* 18 | * TM1637 7-Segment Display Driver Help 19 | * 20 | * Pin Connections: 21 | * Display Segment | TM1637 Pin 22 | * ----------------|----------- 23 | * A | SEG1 24 | * B | SEG2 25 | * C | SEG3 26 | * D | SEG4 27 | * E | SEG5 28 | * F | SEG6 29 | * G | SEG7 30 | * . | SEG8 31 | * 32 | * STM32CubeMX Configuration: 33 | * Set CLK (Clock) and DIO (Data I/O) pins as: 34 | * - Mode: Output Open Drain 35 | * - Select High level initialization 36 | * 37 | * Usage: 38 | * 1. Declare a display instance: 39 | * one instance per display 40 | * tm1637_t seg = 41 | * { 42 | * .seg_cnt = 4, 43 | * .gpio_clk = GPIOA, 44 | * .gpio_dat = GPIOA, 45 | * .pin_clk = GPIO_PIN_1, 46 | * .pin_data = GPIO_PIN_2, 47 | * }; 48 | * 49 | * 2. Initialize with GPIO settings: 50 | * tm1637_init(&display); 51 | * 52 | * 3. Use display functions. 53 | * 54 | * Notes: 55 | * - Always initialize with tm1637_init() before other functions 56 | * - Ensure proper pull-up resistors on both CLK and DIO lines 57 | * - Maximum 6-digit 7-segment displays are supported 58 | */ 59 | 60 | #ifndef _TM1637_H_ 61 | #define _TM1637_H_ 62 | 63 | #ifdef __cplusplus 64 | extern "C" { 65 | #endif 66 | 67 | /*************************************************************************************************/ 68 | /** Includes **/ 69 | /*************************************************************************************************/ 70 | 71 | #include 72 | #include 73 | #include 74 | #include "main.h" 75 | 76 | /*************************************************************************************************/ 77 | /** Macros and Definitions **/ 78 | /*************************************************************************************************/ 79 | 80 | typedef enum 81 | { 82 | TM1637_ERR_NONE = 0, /* No error */ 83 | TM1637_ERR_ERROR, /* Acknowledge error */ 84 | 85 | } tm1637_err_t; 86 | 87 | /*************************************************************************************************/ 88 | /** Strucs and Enums **/ 89 | /*************************************************************************************************/ 90 | 91 | typedef struct 92 | { 93 | GPIO_TypeDef *gpio_clk; 94 | GPIO_TypeDef *gpio_dat; 95 | uint16_t pin_clk; 96 | uint16_t pin_dat; 97 | uint8_t seg_cnt; 98 | 99 | } tm1637_t; 100 | 101 | /*************************************************************************************************/ 102 | /** Function Declarations **/ 103 | /*************************************************************************************************/ 104 | 105 | tm1637_err_t tm1637_init(tm1637_t *handle); 106 | tm1637_err_t tm1637_brightness(tm1637_t *handle, uint8_t brightness_0_8); 107 | void tm1637_seg(tm1637_t *handle, uint8_t seg_1_6); 108 | tm1637_err_t tm1637_disp_raw(tm1637_t *handle, const uint8_t *data); 109 | tm1637_err_t tm1637_disp_str(tm1637_t *handle, const char *str); 110 | tm1637_err_t tm1637_disp_printf(tm1637_t *handle, const char *format, ...); 111 | tm1637_err_t tm1637_disp_clear(tm1637_t *handle); 112 | 113 | /*************************************************************************************************/ 114 | /** End of File **/ 115 | /*************************************************************************************************/ 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | #endif /* _TM1637_H_ */ 121 | --------------------------------------------------------------------------------