LibDriver TM1640
Loading...
Searching...
No Matches
driver_tm1640_write_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static tm1640_handle_t gs_handle;
41
49uint8_t tm1640_write_test(void)
50{
51 uint8_t res;
58 tm1640_info_t info;
59
60 /* link interface function */
71
72 /* get information */
73 res = tm1640_info(&info);
74 if (res != 0)
75 {
76 tm1640_interface_debug_print("tm1640: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print chip info */
83 tm1640_interface_debug_print("tm1640: chip is %s.\n", info.chip_name);
84 tm1640_interface_debug_print("tm1640: manufacturer is %s.\n", info.manufacturer_name);
85 tm1640_interface_debug_print("tm1640: interface is %s.\n", info.interface);
86 tm1640_interface_debug_print("tm1640: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 tm1640_interface_debug_print("tm1640: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 tm1640_interface_debug_print("tm1640: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 tm1640_interface_debug_print("tm1640: max current is %0.2fmA.\n", info.max_current_ma);
90 tm1640_interface_debug_print("tm1640: max temperature is %0.1fC.\n", info.temperature_max);
91 tm1640_interface_debug_print("tm1640: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* start write test */
95 tm1640_interface_debug_print("tm1640: start write test.\n");
96
97 /* tm1640 init */
98 res = tm1640_init(&gs_handle);
99 if (res != 0)
100 {
101 tm1640_interface_debug_print("tm1640: init failed.\n");
102
103 return 1;
104 }
105
106 /* address auto increment mode */
107 tm1640_interface_debug_print("tm1640: address auto increment mode.\n");
108
109 /* set pulse width 14/16 */
111 if (res != 0)
112 {
113 tm1640_interface_debug_print("tm1640: set pulse width failed.\n");
114 (void)tm1640_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 /* set address auto inc mode */
121 if (res != 0)
122 {
123 tm1640_interface_debug_print("tm1640: set address mode failed.\n");
124 (void)tm1640_deinit(&gs_handle);
125
126 return 1;
127 }
128
129 /* disable test mode */
130 res = tm1640_set_test_mode(&gs_handle, TM1640_BOOL_FALSE);
131 if (res != 0)
132 {
133 tm1640_interface_debug_print("tm1640: set test mode failed.\n");
134 (void)tm1640_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* clear segment */
140 res = tm1640_clear_segment(&gs_handle);
141 if (res != 0)
142 {
143 tm1640_interface_debug_print("tm1640: clear segment failed.\n");
144 (void)tm1640_deinit(&gs_handle);
145
146 return 1;
147 }
148
149 /* enable display */
150 res = tm1640_set_display(&gs_handle, TM1640_BOOL_TRUE);
151 if (res != 0)
152 {
153 tm1640_interface_debug_print("tm1640: set display failed.\n");
154 (void)tm1640_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* write segment */
160 res = tm1640_write_segment(&gs_handle, 0x00, &number[0], 16);
161 if (res != 0)
162 {
163 tm1640_interface_debug_print("tm1640: write segment failed.\n");
164 (void)tm1640_deinit(&gs_handle);
165
166 return 1;
167 }
168
169 /* delay 5000ms */
171
172 /* address fix mode */
173 tm1640_interface_debug_print("tm1640: address fix mode.\n");
174
175 /* set address fix mode */
177 if (res != 0)
178 {
179 tm1640_interface_debug_print("tm1640: set address mode failed.\n");
180 (void)tm1640_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* write segment */
186 res = tm1640_write_segment(&gs_handle, 0x00, &number[2], 16);
187 if (res != 0)
188 {
189 tm1640_interface_debug_print("tm1640: write segment failed.\n");
190 (void)tm1640_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* delay 5000ms */
197
198 /* set pulse width */
199 tm1640_interface_debug_print("tm1640: set pulse width 12.\n");
200
201 /* set pulse width 12/16 */
203 if (res != 0)
204 {
205 tm1640_interface_debug_print("tm1640: set pulse width failed.\n");
206 (void)tm1640_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* delay 3000ms */
213
214 /* set pulse width */
215 tm1640_interface_debug_print("tm1640: set pulse width 10.\n");
216
217 /* set pulse width 12/16 */
219 if (res != 0)
220 {
221 tm1640_interface_debug_print("tm1640: set pulse width failed.\n");
222 (void)tm1640_deinit(&gs_handle);
223
224 return 1;
225 }
226
227 /* delay 3000ms */
229
230 /* set pulse width */
231 tm1640_interface_debug_print("tm1640: set pulse width 2.\n");
232
233 /* set pulse width 2/16 */
235 if (res != 0)
236 {
237 tm1640_interface_debug_print("tm1640: set pulse width failed.\n");
238 (void)tm1640_deinit(&gs_handle);
239
240 return 1;
241 }
242
243 /* delay 3000ms */
245
246 /* display off */
247 tm1640_interface_debug_print("tm1640: display off.\n");
248
249 /* disable display */
250 res = tm1640_set_display(&gs_handle, TM1640_BOOL_FALSE);
251 if (res != 0)
252 {
253 tm1640_interface_debug_print("tm1640: set display failed.\n");
254 (void)tm1640_deinit(&gs_handle);
255
256 return 1;
257 }
258 /* delay 3000ms */
260
261 /* display on */
262 tm1640_interface_debug_print("tm1640: display on.\n");
263
264 /* set pulse width 14/16 */
266 if (res != 0)
267 {
268 tm1640_interface_debug_print("tm1640: set pulse width failed.\n");
269 (void)tm1640_deinit(&gs_handle);
270
271 return 1;
272 }
273
274 /* enable display */
275 res = tm1640_set_display(&gs_handle, TM1640_BOOL_TRUE);
276 if (res != 0)
277 {
278 tm1640_interface_debug_print("tm1640: set display failed.\n");
279 (void)tm1640_deinit(&gs_handle);
280
281 return 1;
282 }
283
284 /* delay 3000ms */
286
287 /* finish write test */
288 tm1640_interface_debug_print("tm1640: finish write test.\n");
289 (void)tm1640_deinit(&gs_handle);
290
291 return 0;
292}
driver tm1640 write test header file
uint8_t tm1640_deinit(tm1640_handle_t *handle)
close the chip
uint8_t tm1640_info(tm1640_info_t *info)
get chip's information
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
struct tm1640_info_s tm1640_info_t
tm1640 information structure definition
uint8_t tm1640_set_display(tm1640_handle_t *handle, tm1640_bool_t enable)
enable or disable display
@ TM1640_PULSE_WIDTH_2_DIV_16
@ TM1640_PULSE_WIDTH_10_DIV_16
@ TM1640_PULSE_WIDTH_14_DIV_16
@ TM1640_PULSE_WIDTH_12_DIV_16
@ TM1640_NUMBER_9
@ TM1640_NUMBER_3
@ TM1640_NUMBER_4
@ TM1640_NUMBER_1
@ TM1640_NUMBER_7
@ TM1640_NUMBER_5
@ TM1640_NUMBER_6
@ TM1640_NUMBER_2
@ TM1640_NUMBER_0
@ TM1640_NUMBER_8
@ TM1640_BOOL_TRUE
@ TM1640_BOOL_FALSE
@ TM1640_ADDRESS_MODE_FIX
@ TM1640_ADDRESS_MODE_INC
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
uint8_t tm1640_write_test(void)
write test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]