LibDriver TM1622
Loading...
Searching...
No Matches
driver_tm1622_write_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
43static tm1622_handle_t gs_handle;
44
52uint8_t tm1622_write_test(void)
53{
54 uint8_t res;
55 uint32_t i;
56 uint32_t j;
57 const uint8_t seg_table[10] =
58 {
59 0x01,
60 0x02,
61 0x03,
62 0x04,
63 0x05,
64 0x06,
65 0x07,
66 0x08,
67 0x09,
68 0x0A,
69 };
70 tm1622_info_t info;
71
72 /* link interface function */
90
91 /* get information */
92 res = tm1622_info(&info);
93 if (res != 0)
94 {
95 tm1622_interface_debug_print("tm1622: get info failed.\n");
96
97 return 1;
98 }
99 else
100 {
101 /* print chip info */
102 tm1622_interface_debug_print("tm1622: chip is %s.\n", info.chip_name);
103 tm1622_interface_debug_print("tm1622: manufacturer is %s.\n", info.manufacturer_name);
104 tm1622_interface_debug_print("tm1622: interface is %s.\n", info.interface);
105 tm1622_interface_debug_print("tm1622: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
106 tm1622_interface_debug_print("tm1622: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
107 tm1622_interface_debug_print("tm1622: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
108 tm1622_interface_debug_print("tm1622: max current is %0.2fmA.\n", info.max_current_ma);
109 tm1622_interface_debug_print("tm1622: max temperature is %0.1fC.\n", info.temperature_max);
110 tm1622_interface_debug_print("tm1622: min temperature is %0.1fC.\n", info.temperature_min);
111 }
112
113 /* start write test */
114 tm1622_interface_debug_print("tm1622: start write test.\n");
115
116 /* tm1622 init */
117 res = tm1622_init(&gs_handle);
118 if (res != 0)
119 {
120 tm1622_interface_debug_print("tm1622: init failed.\n");
121
122 return 1;
123 }
124
125 /* set clock */
126 res = tm1622_set_clock(&gs_handle, TM1622_CLOCK_RC_32K);
127 if (res != 0)
128 {
129 tm1622_interface_debug_print("tm1622: set clock failed.\n");
130 (void)tm1622_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* enable oscillator */
136 res = tm1622_set_oscillator(&gs_handle, TM1622_BOOL_TRUE);
137 if (res != 0)
138 {
139 tm1622_interface_debug_print("tm1622: set oscillator failed.\n");
140 (void)tm1622_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* enable lcd bias */
146 res = tm1622_set_lcd_bias(&gs_handle, TM1622_BOOL_TRUE);
147 if (res != 0)
148 {
149 tm1622_interface_debug_print("tm1622: set lcd bias failed.\n");
150 (void)tm1622_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 /* set normal mode */
156 res = tm1622_set_mode(&gs_handle, TM1622_MODE_NORMAL);
157 if (res != 0)
158 {
159 tm1622_interface_debug_print("tm1622: set mode failed.\n");
160 (void)tm1622_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* set freq clock 1hz, wdt 4s */
166 res = tm1622_set_freq(&gs_handle, TM1622_FREQ_F1);
167 if (res != 0)
168 {
169 tm1622_interface_debug_print("tm1622: set freq failed.\n");
170 (void)tm1622_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* set tone freq 2k */
176 res = tm1622_set_tone_freq(&gs_handle, TM1622_TONE_FREQ_2K);
177 if (res != 0)
178 {
179 tm1622_interface_debug_print("tm1622: set tone freq failed.\n");
180 (void)tm1622_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* disable tone */
186 res = tm1622_set_tone(&gs_handle, TM1622_BOOL_FALSE);
187 if (res != 0)
188 {
189 tm1622_interface_debug_print("tm1622: set tone failed.\n");
190 (void)tm1622_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* disable timer */
196 res = tm1622_set_timer(&gs_handle, TM1622_BOOL_FALSE);
197 if (res != 0)
198 {
199 tm1622_interface_debug_print("tm1622: set timer failed.\n");
200 (void)tm1622_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* clear timer */
206 res = tm1622_clear_timer(&gs_handle);
207 if (res != 0)
208 {
209 tm1622_interface_debug_print("tm1622: clear timer failed.\n");
210 (void)tm1622_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* disable watchdog */
216 res = tm1622_set_watchdog(&gs_handle, TM1622_BOOL_FALSE);
217 if (res != 0)
218 {
219 tm1622_interface_debug_print("tm1622: set watchdog failed.\n");
220 (void)tm1622_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* clear watchdog */
226 res = tm1622_clear_watchdog(&gs_handle);
227 if (res != 0)
228 {
229 tm1622_interface_debug_print("tm1622: clear watchdog failed.\n");
230 (void)tm1622_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* disable interrupt */
236 res = tm1622_set_irq(&gs_handle, TM1622_BOOL_FALSE);
237 if (res != 0)
238 {
239 tm1622_interface_debug_print("tm1622: set irq failed.\n");
240 (void)tm1622_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* clear segment */
246 res = tm1622_clear_segment(&gs_handle);
247 if (res != 0)
248 {
249 tm1622_interface_debug_print("tm1622: clear segment failed.\n");
250 (void)tm1622_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* output */
256 tm1622_interface_debug_print("tm1622: write segment test.\n");
257
258 for (i = 0; i < 10; i++)
259 {
260 uint8_t buffer[32];
261
262 /* copy data */
263 for (j = 0; j < 32; j++)
264 {
265 buffer[j] = seg_table[i];
266 }
267
268 /* write segment */
269 res = tm1622_write_segment(&gs_handle, 0x00, buffer, 32);
270 if (res != 0)
271 {
272 tm1622_interface_debug_print("tm1622: write segment failed.\n");
273 (void)tm1622_deinit(&gs_handle);
274
275 return 1;
276 }
277
278 /* delay 1000ms */
280 }
281
282 /* output */
283 tm1622_interface_debug_print("tm1622: 2k tone test.\n");
284
285 /* set tone freq 2k */
286 res = tm1622_set_tone_freq(&gs_handle, TM1622_TONE_FREQ_2K);
287 if (res != 0)
288 {
289 tm1622_interface_debug_print("tm1622: set tone freq failed.\n");
290 (void)tm1622_deinit(&gs_handle);
291
292 return 1;
293 }
294
295 /* enable tone */
296 res = tm1622_set_tone(&gs_handle, TM1622_BOOL_TRUE);
297 if (res != 0)
298 {
299 tm1622_interface_debug_print("tm1622: set tone failed.\n");
300 (void)tm1622_deinit(&gs_handle);
301
302 return 1;
303 }
304
305 /* delay 3000ms */
307
308 /* disable tone */
309 res = tm1622_set_tone(&gs_handle, TM1622_BOOL_FALSE);
310 if (res != 0)
311 {
312 tm1622_interface_debug_print("tm1622: set tone failed.\n");
313 (void)tm1622_deinit(&gs_handle);
314
315 return 1;
316 }
317
318 /* delay 1000ms */
320
321 /* output */
322 tm1622_interface_debug_print("tm1622: 4k tone test.\n");
323
324 /* set tone freq 4k */
325 res = tm1622_set_tone_freq(&gs_handle, TM1622_TONE_FREQ_4K);
326 if (res != 0)
327 {
328 tm1622_interface_debug_print("tm1622: set tone freq failed.\n");
329 (void)tm1622_deinit(&gs_handle);
330
331 return 1;
332 }
333
334 /* enable tone */
335 res = tm1622_set_tone(&gs_handle, TM1622_BOOL_TRUE);
336 if (res != 0)
337 {
338 tm1622_interface_debug_print("tm1622: set tone failed.\n");
339 (void)tm1622_deinit(&gs_handle);
340
341 return 1;
342 }
343
344 /* delay 3000ms */
346
347 /* disable tone */
348 res = tm1622_set_tone(&gs_handle, TM1622_BOOL_FALSE);
349 if (res != 0)
350 {
351 tm1622_interface_debug_print("tm1622: set tone failed.\n");
352 (void)tm1622_deinit(&gs_handle);
353
354 return 1;
355 }
356
357 /* finish write test */
358 tm1622_interface_debug_print("tm1622: finish write test.\n");
359 (void)tm1622_deinit(&gs_handle);
360
361 return 0;
362}
driver tm1622 write test header file
uint8_t tm1622_clear_timer(tm1622_handle_t *handle)
clear timer
uint8_t tm1622_set_lcd_bias(tm1622_handle_t *handle, tm1622_bool_t enable)
enable or disable lcd bias
uint8_t tm1622_clear_segment(tm1622_handle_t *handle)
clear segment
uint8_t tm1622_write_segment(tm1622_handle_t *handle, uint8_t addr, uint8_t *data, uint8_t len)
write segment
uint8_t tm1622_clear_watchdog(tm1622_handle_t *handle)
clear watchdog
uint8_t tm1622_set_tone_freq(tm1622_handle_t *handle, tm1622_tone_freq_t freq)
set tone freq
uint8_t tm1622_set_watchdog(tm1622_handle_t *handle, tm1622_bool_t enable)
enable or disable watchdog
struct tm1622_handle_s tm1622_handle_t
tm1622 handle structure definition
uint8_t tm1622_set_timer(tm1622_handle_t *handle, tm1622_bool_t enable)
enable or disable timer
struct tm1622_info_s tm1622_info_t
tm1622 information structure definition
uint8_t tm1622_set_clock(tm1622_handle_t *handle, tm1622_clock_t clk)
set clock
uint8_t tm1622_deinit(tm1622_handle_t *handle)
close the chip
uint8_t tm1622_set_freq(tm1622_handle_t *handle, tm1622_freq_t freq)
set freq
uint8_t tm1622_init(tm1622_handle_t *handle)
initialize the chip
uint8_t tm1622_set_tone(tm1622_handle_t *handle, tm1622_bool_t enable)
enable or disable tone
uint8_t tm1622_set_oscillator(tm1622_handle_t *handle, tm1622_bool_t enable)
enable or disable oscillator
uint8_t tm1622_set_irq(tm1622_handle_t *handle, tm1622_bool_t enable)
enable or disable irq
uint8_t tm1622_set_mode(tm1622_handle_t *handle, tm1622_mode_t mode)
set mode
uint8_t tm1622_info(tm1622_info_t *info)
get chip's information
@ TM1622_CLOCK_RC_32K
@ TM1622_FREQ_F1
@ TM1622_TONE_FREQ_4K
@ TM1622_TONE_FREQ_2K
@ TM1622_MODE_NORMAL
@ TM1622_BOOL_FALSE
@ TM1622_BOOL_TRUE
uint8_t tm1622_interface_rd_gpio_init(void)
interface rd gpio init
uint8_t tm1622_interface_cs_gpio_write(uint8_t level)
interface cs gpio write
uint8_t tm1622_interface_cs_gpio_init(void)
interface cs gpio init
uint8_t tm1622_interface_cs_gpio_deinit(void)
interface cs gpio deinit
uint8_t tm1622_interface_rd_gpio_write(uint8_t level)
interface rd gpio write
uint8_t tm1622_interface_wr_gpio_write(uint8_t level)
interface wr gpio write
void tm1622_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tm1622_interface_wr_gpio_init(void)
interface wr gpio init
uint8_t tm1622_interface_wr_gpio_deinit(void)
interface wr gpio deinit
uint8_t tm1622_interface_data_gpio_init(void)
interface data gpio init
void tm1622_interface_delay_us(uint32_t us)
interface delay us
void tm1622_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tm1622_interface_data_gpio_deinit(void)
interface data gpio deinit
uint8_t tm1622_interface_data_gpio_read(uint8_t *level)
interface data gpio read
uint8_t tm1622_interface_rd_gpio_deinit(void)
interface rd gpio deinit
uint8_t tm1622_interface_data_gpio_write(uint8_t level)
interface data gpio write
uint8_t tm1622_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]