LibDriver TM1638
Loading...
Searching...
No Matches
driver_tm1638_write_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static tm1638_handle_t gs_handle;
41
49uint8_t tm1638_write_test(void)
50{
51 uint8_t res;
52 uint16_t number[] = {TM1638_NUMBER_0, TM1638_NUMBER_1, TM1638_NUMBER_2,
55 tm1638_info_t info;
56
57 /* link interface function */
65
66 /* get information */
67 res = tm1638_info(&info);
68 if (res != 0)
69 {
70 tm1638_interface_debug_print("tm1638: get info failed.\n");
71
72 return 1;
73 }
74 else
75 {
76 /* print chip info */
77 tm1638_interface_debug_print("tm1638: chip is %s.\n", info.chip_name);
78 tm1638_interface_debug_print("tm1638: manufacturer is %s.\n", info.manufacturer_name);
79 tm1638_interface_debug_print("tm1638: interface is %s.\n", info.interface);
80 tm1638_interface_debug_print("tm1638: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
81 tm1638_interface_debug_print("tm1638: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
82 tm1638_interface_debug_print("tm1638: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
83 tm1638_interface_debug_print("tm1638: max current is %0.2fmA.\n", info.max_current_ma);
84 tm1638_interface_debug_print("tm1638: max temperature is %0.1fC.\n", info.temperature_max);
85 tm1638_interface_debug_print("tm1638: min temperature is %0.1fC.\n", info.temperature_min);
86 }
87
88 /* start write test */
89 tm1638_interface_debug_print("tm1638: start write test.\n");
90
91 /* tm1638 init */
92 res = tm1638_init(&gs_handle);
93 if (res != 0)
94 {
95 tm1638_interface_debug_print("tm1638: init failed.\n");
96
97 return 1;
98 }
99
100 /* address auto increment mode */
101 tm1638_interface_debug_print("tm1638: address auto increment mode.\n");
102
103 /* set pulse width 14/16 */
105 if (res != 0)
106 {
107 tm1638_interface_debug_print("tm1638: set pulse width failed.\n");
108 (void)tm1638_deinit(&gs_handle);
109
110 return 1;
111 }
112
113 /* set address auto inc mode */
115 if (res != 0)
116 {
117 tm1638_interface_debug_print("tm1638: set address mode failed.\n");
118 (void)tm1638_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 /* disable test mode */
124 res = tm1638_set_test_mode(&gs_handle, TM1638_BOOL_FALSE);
125 if (res != 0)
126 {
127 tm1638_interface_debug_print("tm1638: set test mode failed.\n");
128 (void)tm1638_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* clear segment */
134 res = tm1638_clear_segment(&gs_handle);
135 if (res != 0)
136 {
137 tm1638_interface_debug_print("tm1638: clear segment failed.\n");
138 (void)tm1638_deinit(&gs_handle);
139
140 return 1;
141 }
142
143 /* enable display */
144 res = tm1638_set_display(&gs_handle, TM1638_BOOL_TRUE);
145 if (res != 0)
146 {
147 tm1638_interface_debug_print("tm1638: set display failed.\n");
148 (void)tm1638_deinit(&gs_handle);
149
150 return 1;
151 }
152
153 /* write segment */
154 res = tm1638_write_segment(&gs_handle, 0x00, &number[0], 8);
155 if (res != 0)
156 {
157 tm1638_interface_debug_print("tm1638: write segment failed.\n");
158 (void)tm1638_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* delay 5000ms */
165
166 /* address fix mode */
167 tm1638_interface_debug_print("tm1638: address fix mode.\n");
168
169 /* set address fix mode */
171 if (res != 0)
172 {
173 tm1638_interface_debug_print("tm1638: set address mode failed.\n");
174 (void)tm1638_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* write segment */
180 res = tm1638_write_segment(&gs_handle, 0x00, &number[1], 8);
181 if (res != 0)
182 {
183 tm1638_interface_debug_print("tm1638: write segment failed.\n");
184 (void)tm1638_deinit(&gs_handle);
185
186 return 1;
187 }
188
189 /* delay 5000ms */
191
192 /* set pulse width */
193 tm1638_interface_debug_print("tm1638: set pulse width 12.\n");
194
195 /* set pulse width 12/16 */
197 if (res != 0)
198 {
199 tm1638_interface_debug_print("tm1638: set pulse width failed.\n");
200 (void)tm1638_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* delay 3000ms */
207
208 /* set pulse width */
209 tm1638_interface_debug_print("tm1638: set pulse width 10.\n");
210
211 /* set pulse width 12/16 */
213 if (res != 0)
214 {
215 tm1638_interface_debug_print("tm1638: set pulse width failed.\n");
216 (void)tm1638_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* delay 3000ms */
223
224 /* set pulse width */
225 tm1638_interface_debug_print("tm1638: set pulse width 2.\n");
226
227 /* set pulse width 2/16 */
229 if (res != 0)
230 {
231 tm1638_interface_debug_print("tm1638: set pulse width failed.\n");
232 (void)tm1638_deinit(&gs_handle);
233
234 return 1;
235 }
236
237 /* delay 3000ms */
239
240 /* display off */
241 tm1638_interface_debug_print("tm1638: display off.\n");
242
243 /* disable display */
244 res = tm1638_set_display(&gs_handle, TM1638_BOOL_FALSE);
245 if (res != 0)
246 {
247 tm1638_interface_debug_print("tm1638: set display failed.\n");
248 (void)tm1638_deinit(&gs_handle);
249
250 return 1;
251 }
252 /* delay 3000ms */
254
255 /* display on */
256 tm1638_interface_debug_print("tm1638: display on.\n");
257
258 /* set pulse width 14/16 */
260 if (res != 0)
261 {
262 tm1638_interface_debug_print("tm1638: set pulse width failed.\n");
263 (void)tm1638_deinit(&gs_handle);
264
265 return 1;
266 }
267
268 /* enable display */
269 res = tm1638_set_display(&gs_handle, TM1638_BOOL_TRUE);
270 if (res != 0)
271 {
272 tm1638_interface_debug_print("tm1638: set display failed.\n");
273 (void)tm1638_deinit(&gs_handle);
274
275 return 1;
276 }
277
278 /* delay 3000ms */
280
281 /* finish write test */
282 tm1638_interface_debug_print("tm1638: finish write test.\n");
283 (void)tm1638_deinit(&gs_handle);
284
285 return 0;
286}
driver tm1638 write test header file
uint8_t tm1638_write_segment(tm1638_handle_t *handle, uint8_t addr, uint16_t *data, uint8_t len)
write segment
struct tm1638_handle_s tm1638_handle_t
tm1638 handle structure definition
uint8_t tm1638_set_address_mode(tm1638_handle_t *handle, tm1638_address_mode_t mode)
set address mode
uint8_t tm1638_set_pulse_width(tm1638_handle_t *handle, tm1638_pulse_width_t width)
set pulse width
uint8_t tm1638_deinit(tm1638_handle_t *handle)
close the chip
uint8_t tm1638_clear_segment(tm1638_handle_t *handle)
clear segment
uint8_t tm1638_init(tm1638_handle_t *handle)
initialize the chip
uint8_t tm1638_set_display(tm1638_handle_t *handle, tm1638_bool_t enable)
enable or disable display
uint8_t tm1638_set_test_mode(tm1638_handle_t *handle, tm1638_bool_t enable)
enable or disable test mode
struct tm1638_info_s tm1638_info_t
tm1638 information structure definition
uint8_t tm1638_info(tm1638_info_t *info)
get chip's information
@ TM1638_BOOL_FALSE
@ TM1638_BOOL_TRUE
@ TM1638_ADDRESS_MODE_FIX
@ TM1638_ADDRESS_MODE_INC
@ TM1638_NUMBER_4
@ TM1638_NUMBER_2
@ TM1638_NUMBER_9
@ TM1638_NUMBER_3
@ TM1638_NUMBER_8
@ TM1638_NUMBER_5
@ TM1638_NUMBER_7
@ TM1638_NUMBER_6
@ TM1638_NUMBER_0
@ TM1638_NUMBER_1
@ TM1638_PULSE_WIDTH_14_DIV_16
@ TM1638_PULSE_WIDTH_12_DIV_16
@ TM1638_PULSE_WIDTH_2_DIV_16
@ TM1638_PULSE_WIDTH_10_DIV_16
uint8_t tm1638_interface_spi_read(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi read
void tm1638_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tm1638_interface_spi_deinit(void)
interface spi deinit
uint8_t tm1638_interface_spi_init(void)
interface spi init
uint8_t tm1638_interface_spi_write(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi write
void tm1638_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tm1638_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]