LibDriver TM1637
Loading...
Searching...
No Matches
driver_tm1637_basic.c
Go to the documentation of this file.
1
36
37#include "driver_tm1637_basic.h"
38
39static tm1637_handle_t gs_handle;
40
48uint8_t tm1637_basic_init(void)
49{
50 uint8_t res;
51
52 /* link interface function */
60
61 /* tm1637 init */
62 res = tm1637_init(&gs_handle);
63 if (res != 0)
64 {
65 tm1637_interface_debug_print("tm1637: init failed.\n");
66
67 return 1;
68 }
69
70 /* set default address mode */
72 if (res != 0)
73 {
74 tm1637_interface_debug_print("tm1637: set address mode failed.\n");
75 (void)tm1637_deinit(&gs_handle);
76
77 return 1;
78 }
79
80 /* disable test mode */
81 res = tm1637_set_test_mode(&gs_handle, TM1637_BOOL_FALSE);
82 if (res != 0)
83 {
84 tm1637_interface_debug_print("tm1637: set test mode failed.\n");
85 (void)tm1637_deinit(&gs_handle);
86
87 return 1;
88 }
89
90 /* set default pulse width */
92 if (res != 0)
93 {
94 tm1637_interface_debug_print("tm1637: set pulse width failed.\n");
95 (void)tm1637_deinit(&gs_handle);
96
97 return 1;
98 }
99
100 /* clear segment */
101 res = tm1637_clear_segment(&gs_handle);
102 if (res != 0)
103 {
104 tm1637_interface_debug_print("tm1637: clear segment failed.\n");
105 (void)tm1637_deinit(&gs_handle);
106
107 return 1;
108 }
109
110 /* enable display */
111 res = tm1637_set_display(&gs_handle, TM1637_BOOL_TRUE);
112 if (res != 0)
113 {
114 tm1637_interface_debug_print("tm1637: set display failed.\n");
115 (void)tm1637_deinit(&gs_handle);
116
117 return 1;
118 }
119
120 return 0;
121}
122
133uint8_t tm1637_basic_write(uint8_t addr, uint8_t *data, uint8_t len)
134{
135 uint8_t res;
136
137 /* write segment */
138 res = tm1637_write_segment(&gs_handle, addr, data, len);
139 if (res != 0)
140 {
141 return 1;
142 }
143
144 return 0;
145}
146
155{
156 uint8_t res;
157
158 /* clear segment */
159 res = tm1637_clear_segment(&gs_handle);
160 if (res != 0)
161 {
162 return 1;
163 }
164
165 return 0;
166}
167
176{
177 uint8_t res;
178
179 /* display on */
180 res = tm1637_set_display(&gs_handle, TM1637_BOOL_TRUE);
181 if (res != 0)
182 {
183 return 1;
184 }
185
186 return 0;
187}
188
197{
198 uint8_t res;
199
200 /* display off */
201 res = tm1637_set_display(&gs_handle, TM1637_BOOL_FALSE);
202 if (res != 0)
203 {
204 return 1;
205 }
206
207 return 0;
208}
209
219uint8_t tm1637_basic_read(uint8_t *seg, uint8_t *k)
220{
221 uint8_t res;
222
223 /* read segment */
224 res = tm1637_read_segment(&gs_handle, seg, k);
225 if (res != 0)
226 {
227 return 1;
228 }
229
230 return 0;
231}
232
241{
242 uint8_t res;
243
244 /* deinit tm1637 */
245 res = tm1637_deinit(&gs_handle);
246 if (res != 0)
247 {
248 return 1;
249 }
250
251 return 0;
252}
driver tm1637 basic header file
uint8_t tm1637_read_segment(tm1637_handle_t *handle, uint8_t *seg, uint8_t *k)
read segment
uint8_t tm1637_set_address_mode(tm1637_handle_t *handle, tm1637_address_mode_t mode)
set address mode
uint8_t tm1637_deinit(tm1637_handle_t *handle)
close the chip
uint8_t tm1637_clear_segment(tm1637_handle_t *handle)
clear segment
uint8_t tm1637_set_test_mode(tm1637_handle_t *handle, tm1637_bool_t enable)
enable or disable test mode
struct tm1637_handle_s tm1637_handle_t
tm1637 handle structure definition
uint8_t tm1637_write_segment(tm1637_handle_t *handle, uint8_t addr, uint8_t *data, uint8_t len)
write segment
uint8_t tm1637_set_pulse_width(tm1637_handle_t *handle, tm1637_pulse_width_t width)
set pulse width
uint8_t tm1637_set_display(tm1637_handle_t *handle, tm1637_bool_t enable)
enable or disable display
uint8_t tm1637_init(tm1637_handle_t *handle)
initialize the chip
@ TM1637_BOOL_FALSE
@ TM1637_BOOL_TRUE
uint8_t tm1637_basic_read(uint8_t *seg, uint8_t *k)
basic example read
uint8_t tm1637_basic_write(uint8_t addr, uint8_t *data, uint8_t len)
basic example write
uint8_t tm1637_basic_display_on(void)
basic example display on
#define TM1637_BASIC_DEFAULT_ADDRESS_MODE
tm1637 basic example default definition
uint8_t tm1637_basic_display_off(void)
basic example display off
uint8_t tm1637_basic_init(void)
basic example init
uint8_t tm1637_basic_clear(void)
basic example clear
uint8_t tm1637_basic_deinit(void)
basic example deinit
#define TM1637_BASIC_DEFAULT_PULSE_WIDTH
void tm1637_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tm1637_interface_iic_init(void)
interface iic init
void tm1637_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tm1637_interface_iic_read_cmd_custom(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic read command custom
uint8_t tm1637_interface_iic_write_cmd_custom(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic write command custom
uint8_t tm1637_interface_iic_deinit(void)
interface iic deinit