-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtm1637.h
120 lines (104 loc) · 3.66 KB
/
tm1637.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* @file TM1637
* @author Nima Askari
* @version 2.0.0
* @license See the LICENSE file in the root folder.
*
* @github https://www.github.com/nimaltd
* @linkedin https://www.linkedin.com/in/nimaltd
* @youtube https://www.youtube.com/@nimaltd
* @instagram https://instagram.com/github.nimaltd
*
* Copyright (C) 2025 Nima Askari - NimaLTD. All rights reserved.
*
*/
/*
* TM1637 7-Segment Display Driver Help
*
* Pin Connections:
* Display Segment | TM1637 Pin
* ----------------|-----------
* A | SEG1
* B | SEG2
* C | SEG3
* D | SEG4
* E | SEG5
* F | SEG6
* G | SEG7
* . | SEG8
*
* STM32CubeMX Configuration:
* Set CLK (Clock) and DIO (Data I/O) pins as:
* - Mode: Output Open Drain
* - Select High level initialization
*
* Usage:
* 1. Declare a display instance:
* one instance per display
* tm1637_t seg =
* {
* .seg_cnt = 4,
* .gpio_clk = GPIOA,
* .gpio_dat = GPIOA,
* .pin_clk = GPIO_PIN_1,
* .pin_data = GPIO_PIN_2,
* };
*
* 2. Initialize with GPIO settings:
* tm1637_init(&display);
*
* 3. Use display functions.
*
* Notes:
* - Always initialize with tm1637_init() before other functions
* - Ensure proper pull-up resistors on both CLK and DIO lines
* - Maximum 6-digit 7-segment displays are supported
*/
#ifndef _TM1637_H_
#define _TM1637_H_
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************************************************/
/** Includes **/
/*************************************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include "main.h"
/*************************************************************************************************/
/** Macros and Definitions **/
/*************************************************************************************************/
typedef enum
{
TM1637_ERR_NONE = 0, /* No error */
TM1637_ERR_ERROR, /* Acknowledge error */
} tm1637_err_t;
/*************************************************************************************************/
/** Strucs and Enums **/
/*************************************************************************************************/
typedef struct
{
GPIO_TypeDef *gpio_clk;
GPIO_TypeDef *gpio_dat;
uint16_t pin_clk;
uint16_t pin_dat;
uint8_t seg_cnt;
} tm1637_t;
/*************************************************************************************************/
/** Function Declarations **/
/*************************************************************************************************/
tm1637_err_t tm1637_init(tm1637_t *handle);
tm1637_err_t tm1637_brightness(tm1637_t *handle, uint8_t brightness_0_8);
void tm1637_seg(tm1637_t *handle, uint8_t seg_1_6);
tm1637_err_t tm1637_disp_raw(tm1637_t *handle, const uint8_t *data);
tm1637_err_t tm1637_disp_str(tm1637_t *handle, const char *str);
tm1637_err_t tm1637_disp_printf(tm1637_t *handle, const char *format, ...);
tm1637_err_t tm1637_disp_clear(tm1637_t *handle);
/*************************************************************************************************/
/** End of File **/
/*************************************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _TM1637_H_ */