LibDriver TM1640
Loading...
Searching...
No Matches
driver_tm1640_basic.c
Go to the documentation of this file.
1
36
37#include "driver_tm1640_basic.h"
38
39static tm1640_handle_t gs_handle;
40
48uint8_t tm1640_basic_init(void)
49{
50 uint8_t res;
51
52 /* link interface function */
63
64 /* tm1640 init */
65 res = tm1640_init(&gs_handle);
66 if (res != 0)
67 {
68 tm1640_interface_debug_print("tm1640: init failed.\n");
69
70 return 1;
71 }
72
73 /* set default address mode */
75 if (res != 0)
76 {
77 tm1640_interface_debug_print("tm1640: set address mode failed.\n");
78 (void)tm1640_deinit(&gs_handle);
79
80 return 1;
81 }
82
83 /* disable test mode */
84 res = tm1640_set_test_mode(&gs_handle, TM1640_BOOL_FALSE);
85 if (res != 0)
86 {
87 tm1640_interface_debug_print("tm1640: set test mode failed.\n");
88 (void)tm1640_deinit(&gs_handle);
89
90 return 1;
91 }
92
93 /* set default pulse width */
95 if (res != 0)
96 {
97 tm1640_interface_debug_print("tm1640: set pulse width failed.\n");
98 (void)tm1640_deinit(&gs_handle);
99
100 return 1;
101 }
102
103 /* clear segment */
104 res = tm1640_clear_segment(&gs_handle);
105 if (res != 0)
106 {
107 tm1640_interface_debug_print("tm1640: clear segment failed.\n");
108 (void)tm1640_deinit(&gs_handle);
109
110 return 1;
111 }
112
113 /* enable display */
114 res = tm1640_set_display(&gs_handle, TM1640_BOOL_TRUE);
115 if (res != 0)
116 {
117 tm1640_interface_debug_print("tm1640: set display failed.\n");
118 (void)tm1640_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 return 0;
124}
125
136uint8_t tm1640_basic_write(uint8_t addr, uint8_t *data, uint8_t len)
137{
138 uint8_t res;
139
140 /* write segment */
141 res = tm1640_write_segment(&gs_handle, addr, data, len);
142 if (res != 0)
143 {
144 return 1;
145 }
146
147 return 0;
148}
149
158{
159 uint8_t res;
160
161 /* clear segment */
162 res = tm1640_clear_segment(&gs_handle);
163 if (res != 0)
164 {
165 return 1;
166 }
167
168 return 0;
169}
170
179{
180 uint8_t res;
181
182 /* display on */
183 res = tm1640_set_display(&gs_handle, TM1640_BOOL_TRUE);
184 if (res != 0)
185 {
186 return 1;
187 }
188
189 return 0;
190}
191
200{
201 uint8_t res;
202
203 /* display off */
204 res = tm1640_set_display(&gs_handle, TM1640_BOOL_FALSE);
205 if (res != 0)
206 {
207 return 1;
208 }
209
210 return 0;
211}
212
221{
222 uint8_t res;
223
224 /* deinit tm1640 */
225 res = tm1640_deinit(&gs_handle);
226 if (res != 0)
227 {
228 return 1;
229 }
230
231 return 0;
232}
driver tm1640 basic header file
uint8_t tm1640_deinit(tm1640_handle_t *handle)
close the chip
uint8_t tm1640_init(tm1640_handle_t *handle)
initialize the chip
uint8_t tm1640_set_pulse_width(tm1640_handle_t *handle, tm1640_pulse_width_t width)
set pulse width
uint8_t tm1640_clear_segment(tm1640_handle_t *handle)
clear segment
struct tm1640_handle_s tm1640_handle_t
tm1640 handle structure definition
uint8_t tm1640_write_segment(tm1640_handle_t *handle, uint8_t addr, uint8_t *data, uint8_t len)
write segment
uint8_t tm1640_set_test_mode(tm1640_handle_t *handle, tm1640_bool_t enable)
enable or disable test mode
uint8_t tm1640_set_address_mode(tm1640_handle_t *handle, tm1640_address_mode_t mode)
set address mode
uint8_t tm1640_set_display(tm1640_handle_t *handle, tm1640_bool_t enable)
enable or disable display
@ TM1640_BOOL_TRUE
@ TM1640_BOOL_FALSE
uint8_t tm1640_basic_display_off(void)
basic example display off
uint8_t tm1640_basic_clear(void)
basic example clear
#define TM1640_BASIC_DEFAULT_PULSE_WIDTH
#define TM1640_BASIC_DEFAULT_ADDRESS_MODE
tm1640 basic example default definition
uint8_t tm1640_basic_deinit(void)
basic example deinit
uint8_t tm1640_basic_display_on(void)
basic example display on
uint8_t tm1640_basic_write(uint8_t addr, uint8_t *data, uint8_t len)
basic example write
uint8_t tm1640_basic_init(void)
basic example init
uint8_t tm1640_interface_din_gpio_write(uint8_t level)
interface din gpio write
uint8_t tm1640_interface_sclk_gpio_deinit(void)
interface sclk gpio deinit
uint8_t tm1640_interface_sclk_gpio_init(void)
interface sclk gpio init
uint8_t tm1640_interface_sclk_gpio_write(uint8_t level)
interface sclk gpio write
uint8_t tm1640_interface_din_gpio_init(void)
interface din gpio init
uint8_t tm1640_interface_din_gpio_deinit(void)
interface din gpio deinit
void tm1640_interface_debug_print(const char *const fmt,...)
interface print format data
void tm1640_interface_delay_ms(uint32_t ms)
interface delay ms
void tm1640_interface_delay_us(uint32_t us)
interface delay us