LibDriver SYN6288  2.0.0
SYN6288 full-featured driver
driver_syn6288_synthesis_test.c
Go to the documentation of this file.
1 
39 
40 static syn6288_handle_t gs_handle;
50 {
51  uint8_t res;
52  syn6288_info_t info;
53  syn6288_status_t status;
54  char s[32];
55  uint8_t gb2312_text[] = {0xD3, 0xEE, 0xD2, 0xF4, 0xCC, 0xEC, 0xCF, 0xC2, 0x00};
56  uint8_t gbk_text[] = {0xD3, 0xEE, 0xD2, 0xF4, 0xCC, 0xEC, 0xCF, 0xC2, 0x00};
57  uint8_t big5_text[] = {0xA6, 0x74, 0xAD, 0xB5, 0xA4, 0xD1, 0xA4, 0x55, 0x00};
58  uint8_t unicode_text[] = {0x8B, 0xED, 0x97, 0xF3, 0x59, 0x29, 0x4E, 0x0B, 0x00};
59 
60  /* link interface function */
69 
70  /* get syn6288 information */
71  res = syn6288_info(&info);
72  if (res != 0)
73  {
74  syn6288_interface_debug_print("syn6288: get info failed.\n");
75 
76  return 1;
77  }
78  else
79  {
80  /* print chip information */
81  syn6288_interface_debug_print("syn6288: chip is %s.\n", info.chip_name);
82  syn6288_interface_debug_print("syn6288: manufacturer is %s.\n", info.manufacturer_name);
83  syn6288_interface_debug_print("syn6288: interface is %s.\n", info.interface);
84  syn6288_interface_debug_print("syn6288: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
85  syn6288_interface_debug_print("syn6288: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
86  syn6288_interface_debug_print("syn6288: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
87  syn6288_interface_debug_print("syn6288: max current is %0.2fmA.\n", info.max_current_ma);
88  syn6288_interface_debug_print("syn6288: max temperature is %0.1fC.\n", info.temperature_max);
89  syn6288_interface_debug_print("syn6288: min temperature is %0.1fC.\n", info.temperature_min);
90  }
91 
92  /* syn6288 init */
93  res = syn6288_init(&gs_handle);
94  if (res != 0)
95  {
96  syn6288_interface_debug_print("syn6288: init failed.\n");
97 
98  return 1;
99  }
100 
101  /* set baud rate 9600 bps */
103  if (res != 0)
104  {
105  syn6288_interface_debug_print("syn6288: set baud rate failed.\n");
106  (void)syn6288_deinit(&gs_handle);
107 
108  return 1;
109  }
110 
111  /* set common mode */
112  res = syn6288_set_mode(&gs_handle, SYN6288_MODE_COMMON);
113  if (res != 0)
114  {
115  syn6288_interface_debug_print("syn6288: set mode failed.\n");
116  (void)syn6288_deinit(&gs_handle);
117 
118  return 1;
119  }
120 
121  /* set synthesis volume 16 */
122  res = syn6288_set_synthesis_volume(&gs_handle, 16);
123  if (res != 0)
124  {
125  syn6288_interface_debug_print("syn6288: set synthesis volume failed.\n");
126  (void)syn6288_deinit(&gs_handle);
127 
128  return 1;
129  }
130 
131  /* set background volume 16 */
132  res = syn6288_set_background_volume(&gs_handle, 0);
133  if (res != 0)
134  {
135  syn6288_interface_debug_print("syn6288: set background volume failed.\n");
136  (void)syn6288_deinit(&gs_handle);
137 
138  return 1;
139  }
140 
141  /* set synthesis speed 5 */
142  res = syn6288_set_synthesis_speed(&gs_handle, 5);
143  if (res != 0)
144  {
145  syn6288_interface_debug_print("syn6288: set synthesis speed failed.\n");
146  (void)syn6288_deinit(&gs_handle);
147 
148  return 1;
149  }
150  syn6288_interface_debug_print("syn6288: start synthesis test.\n");
151 
152  /* synthesis text test */
153  syn6288_interface_debug_print("syn6288: synthesis text test.\n");
154 
155  /* gb2312 synthesis text */
156  syn6288_interface_debug_print("syn6288: gb2312 synthesis text.\n");
157  res = syn6288_set_text_type(&gs_handle, SYN6288_TYPE_GB2312);
158  if (res != 0)
159  {
160  syn6288_interface_debug_print("syn6288: set text type failed.\n");
161  (void)syn6288_deinit(&gs_handle);
162 
163  return 1;
164  }
165 
166  /* synthesis text */
167  res = syn6288_synthesis_text(&gs_handle, (char *)gb2312_text);
168  if (res != 0)
169  {
170  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
171  (void)syn6288_deinit(&gs_handle);
172 
173  return 1;
174  }
175  status = SYN6288_STATUS_BUSY;
176  while (status == SYN6288_STATUS_BUSY)
177  {
179  res = syn6288_get_status(&gs_handle, &status);
180  if (res != 0)
181  {
182  syn6288_interface_debug_print("syn6288: get status failed.\n");
183  (void)syn6288_deinit(&gs_handle);
184 
185  return 1;
186  }
187  }
188 
189  /* gbk synthesis text */
190  syn6288_interface_debug_print("syn6288: gbk synthesis text.\n");
191  res = syn6288_set_text_type(&gs_handle, SYN6288_TYPE_GBK);
192  if (res != 0)
193  {
194  syn6288_interface_debug_print("syn6288: set text type failed.\n");
195  (void)syn6288_deinit(&gs_handle);
196 
197  return 1;
198  }
199 
200  /* synthesis text */
201  res = syn6288_synthesis_text(&gs_handle, (char *)gbk_text);
202  if (res != 0)
203  {
204  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
205  (void)syn6288_deinit(&gs_handle);
206 
207  return 1;
208  }
209  status = SYN6288_STATUS_BUSY;
210  while (status == SYN6288_STATUS_BUSY)
211  {
213  res = syn6288_get_status(&gs_handle, &status);
214  if (res != 0)
215  {
216  syn6288_interface_debug_print("syn6288: get status failed.\n");
217  (void)syn6288_deinit(&gs_handle);
218 
219  return 1;
220  }
221  }
222 
223  /* big5 synthesis text */
224  syn6288_interface_debug_print("syn6288: big5 synthesis text.\n");
225  res = syn6288_set_text_type(&gs_handle, SYN6288_TYPE_BIG5);
226  if (res != 0)
227  {
228  syn6288_interface_debug_print("syn6288: set text type failed.\n");
229  (void)syn6288_deinit(&gs_handle);
230 
231  return 1;
232  }
233 
234  /* synthesis text */
235  res = syn6288_synthesis_text(&gs_handle, (char *)big5_text);
236  if (res != 0)
237  {
238  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
239  (void)syn6288_deinit(&gs_handle);
240 
241  return 1;
242  }
243  status = SYN6288_STATUS_BUSY;
244  while (status == SYN6288_STATUS_BUSY)
245  {
247  res = syn6288_get_status(&gs_handle, &status);
248  if (res != 0)
249  {
250  syn6288_interface_debug_print("syn6288: get status failed.\n");
251  (void)syn6288_deinit(&gs_handle);
252 
253  return 1;
254  }
255  }
256 
257  /* unicode synthesis text */
258  syn6288_interface_debug_print("syn6288: unicode synthesis text.\n");
259  res = syn6288_set_text_type(&gs_handle, SYN6288_TYPE_UNICODE);
260  if (res != 0)
261  {
262  syn6288_interface_debug_print("syn6288: set text type failed.\n");
263  (void)syn6288_deinit(&gs_handle);
264 
265  return 1;
266  }
267 
268  /* synthesis text */
269  res = syn6288_synthesis_text(&gs_handle, (char *)unicode_text);
270  if (res != 0)
271  {
272  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
273  (void)syn6288_deinit(&gs_handle);
274 
275  return 1;
276  }
277  status = SYN6288_STATUS_BUSY;
278  while (status == SYN6288_STATUS_BUSY)
279  {
281  res = syn6288_get_status(&gs_handle, &status);
282  if (res != 0)
283  {
284  syn6288_interface_debug_print("syn6288: get status failed.\n");
285  (void)syn6288_deinit(&gs_handle);
286 
287  return 1;
288  }
289  }
290 
291  /* set gb2312 synthesis text */
292  res = syn6288_set_text_type(&gs_handle, SYN6288_TYPE_GB2312);
293  if (res != 0)
294  {
295  syn6288_interface_debug_print("syn6288: set text type failed.\n");
296  (void)syn6288_deinit(&gs_handle);
297 
298  return 1;
299  }
300 
301  /* synthesis sound test */
302  syn6288_interface_debug_print("syn6288: synthesis sound test.\n");
303  res = syn6288_synthesis_sound(&gs_handle, SYN6288_SOUND_A);
304  if (res != 0)
305  {
306  syn6288_interface_debug_print("syn6288: synthesis sound failed.\n");
307  (void)syn6288_deinit(&gs_handle);
308 
309  return 1;
310  }
311  status = SYN6288_STATUS_BUSY;
312  while (status == SYN6288_STATUS_BUSY)
313  {
315  res = syn6288_get_status(&gs_handle, &status);
316  if (res != 0)
317  {
318  syn6288_interface_debug_print("syn6288: get status failed.\n");
319  (void)syn6288_deinit(&gs_handle);
320 
321  return 1;
322  }
323  }
324 
325  /* synthesis message test */
326  syn6288_interface_debug_print("syn6288: synthesis message test.\n");
327  res = syn6288_synthesis_message(&gs_handle, SYN6288_MESSAGE_A);
328  if (res != 0)
329  {
330  syn6288_interface_debug_print("syn6288: synthesis message failed.\n");
331  (void)syn6288_deinit(&gs_handle);
332 
333  return 1;
334  }
335  status = SYN6288_STATUS_BUSY;
336  while (status == SYN6288_STATUS_BUSY)
337  {
339  res = syn6288_get_status(&gs_handle, &status);
340  if (res != 0)
341  {
342  syn6288_interface_debug_print("syn6288: get status failed.\n");
343  (void)syn6288_deinit(&gs_handle);
344 
345  return 1;
346  }
347  }
348 
349  /* synthesis ring test */
350  syn6288_interface_debug_print("syn6288: synthesis ring test.\n");
351  res = syn6288_synthesis_ring(&gs_handle, SYN6288_RING_E);
352  if (res != 0)
353  {
354  syn6288_interface_debug_print("syn6288: synthesis ring failed.\n");
355  (void)syn6288_deinit(&gs_handle);
356 
357  return 1;
358  }
359  status = SYN6288_STATUS_BUSY;
360  while (status == SYN6288_STATUS_BUSY)
361  {
363  res = syn6288_get_status(&gs_handle, &status);
364  if (res != 0)
365  {
366  syn6288_interface_debug_print("syn6288: get status failed.\n");
367  (void)syn6288_deinit(&gs_handle);
368 
369  return 1;
370  }
371  }
373 
374  /* synthesis control test */
375  syn6288_interface_debug_print("syn6288: synthesis control test.\n");
376  res = syn6288_synthesis_text(&gs_handle, (char *)gb2312_text);
377  if (res != 0)
378  {
379  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
380  (void)syn6288_deinit(&gs_handle);
381 
382  return 1;
383  }
385  res = syn6288_pause(&gs_handle);
386  if (res != 0)
387  {
388  syn6288_interface_debug_print("syn6288: pause failed.\n");
389  (void)syn6288_deinit(&gs_handle);
390 
391  return 1;
392  }
393  syn6288_interface_debug_print("syn6288: synthesis control pause.\n");
395  res = syn6288_resume(&gs_handle);
396  if (res != 0)
397  {
398  syn6288_interface_debug_print("syn6288: resume failed.\n");
399  (void)syn6288_deinit(&gs_handle);
400 
401  return 1;
402  }
403  syn6288_interface_debug_print("syn6288: synthesis control resume.\n");
404  status = SYN6288_STATUS_BUSY;
405  while (status == SYN6288_STATUS_BUSY)
406  {
408  res = syn6288_get_status(&gs_handle, &status);
409  if (res != 0)
410  {
411  syn6288_interface_debug_print("syn6288: get status failed.\n");
412  (void)syn6288_deinit(&gs_handle);
413 
414  return 1;
415  }
416  }
417  res = syn6288_synthesis_text(&gs_handle, (char *)gb2312_text);
418  if (res != 0)
419  {
420  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
421  (void)syn6288_deinit(&gs_handle);
422 
423  return 1;
424  }
426  res = syn6288_stop(&gs_handle);
427  if (res != 0)
428  {
429  syn6288_interface_debug_print("syn6288: stop failed.\n");
430  (void)syn6288_deinit(&gs_handle);
431 
432  return 1;
433  }
434  syn6288_interface_debug_print("syn6288: synthesis control stop.\n");
436 
437  /* synthesis volume test */
438  syn6288_interface_debug_print("syn6288: synthesis volume test.\n");
439  res = syn6288_set_synthesis_volume(&gs_handle, 5);
440  if (res != 0)
441  {
442  syn6288_interface_debug_print("syn6288: set synthesis volume failed.\n");
443  (void)syn6288_deinit(&gs_handle);
444 
445  return 1;
446  }
447  syn6288_interface_debug_print("syn6288: set synthesis volume 5.\n");
448  res = syn6288_synthesis_text(&gs_handle, (char *)gb2312_text);
449  if (res != 0)
450  {
451  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
452  (void)syn6288_deinit(&gs_handle);
453 
454  return 1;
455  }
456  status = SYN6288_STATUS_BUSY;
457  while (status == SYN6288_STATUS_BUSY)
458  {
460  res = syn6288_get_status(&gs_handle, &status);
461  if (res != 0)
462  {
463  syn6288_interface_debug_print("syn6288: get status failed.\n");
464  (void)syn6288_deinit(&gs_handle);
465 
466  return 1;
467  }
468  }
469  res = syn6288_set_synthesis_volume(&gs_handle, 16);
470  if (res != 0)
471  {
472  syn6288_interface_debug_print("syn6288: set synthesis volume failed.\n");
473  (void)syn6288_deinit(&gs_handle);
474 
475  return 1;
476  }
477 
478  /* synthesis speed test */
479  syn6288_interface_debug_print("syn6288: synthesis speed test.\n");
480  res = syn6288_set_synthesis_speed(&gs_handle, 0);
481  if (res != 0)
482  {
483  syn6288_interface_debug_print("syn6288: set synthesis speed failed.\n");
484  (void)syn6288_deinit(&gs_handle);
485 
486  return 1;
487  }
488  syn6288_interface_debug_print("syn6288: set synthesis speed 0.\n");
489  res = syn6288_synthesis_text(&gs_handle, (char *)gb2312_text);
490  if (res != 0)
491  {
492  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
493  (void)syn6288_deinit(&gs_handle);
494 
495  return 1;
496  }
497  status = SYN6288_STATUS_BUSY;
498  while (status == SYN6288_STATUS_BUSY)
499  {
501  res = syn6288_get_status(&gs_handle, &status);
502  if (res != 0)
503  {
504  syn6288_interface_debug_print("syn6288: get status failed.\n");
505  (void)syn6288_deinit(&gs_handle);
506 
507  return 1;
508  }
509  }
510  res = syn6288_set_synthesis_speed(&gs_handle, 5);
511  if (res != 0)
512  {
513  syn6288_interface_debug_print("syn6288: set synthesis speed failed.\n");
514  (void)syn6288_deinit(&gs_handle);
515 
516  return 1;
517  }
518 
519  /* synthesis mode test */
520  syn6288_interface_debug_print("syn6288: synthesis mode test.\n");
521 
522  /* background mode on */
523  syn6288_interface_debug_print("syn6288: background mode on.\n");
524  res = syn6288_set_background_volume(&gs_handle, 15);
525  if (res != 0)
526  {
527  syn6288_interface_debug_print("syn6288: set background volume failed.\n");
528  (void)syn6288_deinit(&gs_handle);
529 
530  return 1;
531  }
532  res = syn6288_set_mode(&gs_handle, SYN6288_MODE_BACKGROUND_1);
533  if (res != 0)
534  {
535  syn6288_interface_debug_print("syn6288: set mode failed.\n");
536  (void)syn6288_deinit(&gs_handle);
537 
538  return 1;
539  }
540  res = syn6288_synthesis_text(&gs_handle, (char *)gb2312_text);
541  if (res != 0)
542  {
543  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
544  (void)syn6288_deinit(&gs_handle);
545 
546  return 1;
547  }
548  status = SYN6288_STATUS_BUSY;
549  while (status == SYN6288_STATUS_BUSY)
550  {
552  res = syn6288_get_status(&gs_handle, &status);
553  if (res != 0)
554  {
555  syn6288_interface_debug_print("syn6288: get status failed.\n");
556  (void)syn6288_deinit(&gs_handle);
557 
558  return 1;
559  }
560  }
561 
562  /* command test */
563  syn6288_interface_debug_print("syn6288: command test.\n");
564  syn6288_interface_debug_print("syn6288: set command 0.\n");
565  memset(s, 0, sizeof(char) * 32);
566  strncpy(s, "[b0]", 32);
567  res = syn6288_set_command(&gs_handle, s);
568  if (res != 0)
569  {
570  syn6288_interface_debug_print("syn6288: set command failed.\n");
571  (void)syn6288_deinit(&gs_handle);
572 
573  return 1;
574  }
575  memset(s, 0, sizeof(char) * 32);
576  strncpy(s, "110,120,130", 32);
577  res = syn6288_synthesis_text(&gs_handle, s);
578  if (res != 0)
579  {
580  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
581  (void)syn6288_deinit(&gs_handle);
582 
583  return 1;
584  }
585  status = SYN6288_STATUS_BUSY;
586  while (status == SYN6288_STATUS_BUSY)
587  {
589  res = syn6288_get_status(&gs_handle, &status);
590  if (res != 0)
591  {
592  syn6288_interface_debug_print("syn6288: get status failed.\n");
593  (void)syn6288_deinit(&gs_handle);
594 
595  return 1;
596  }
597  }
598  syn6288_interface_debug_print("syn6288: set command 1.\n");
599  memset(s, 0, sizeof(char) * 32);
600  strncpy(s, "[b1]", 32);
601  res = syn6288_set_command(&gs_handle, s);
602  if (res != 0)
603  {
604  syn6288_interface_debug_print("syn6288: set command failed.\n");
605  (void)syn6288_deinit(&gs_handle);
606 
607  return 1;
608  }
609  memset(s, 0, sizeof(char) * 32);
610  strncpy(s, "110,120,130", 32);
611  res = syn6288_synthesis_text(&gs_handle, s);
612  if (res != 0)
613  {
614  syn6288_interface_debug_print("syn6288: synthesis text failed.\n");
615  (void)syn6288_deinit(&gs_handle);
616 
617  return 1;
618  }
619  status = SYN6288_STATUS_BUSY;
620  while (status == SYN6288_STATUS_BUSY)
621  {
623  res = syn6288_get_status(&gs_handle, &status);
624  if (res != 0)
625  {
626  syn6288_interface_debug_print("syn6288: get status failed.\n");
627  (void)syn6288_deinit(&gs_handle);
628 
629  return 1;
630  }
631  }
632 
633  /* finish synthesis test */
634  syn6288_interface_debug_print("syn6288: finish synthesis test.\n");
635  (void)syn6288_deinit(&gs_handle);
636 
637  return 0;
638 }
driver syn6288 synthesis test header file
uint8_t syn6288_set_background_volume(syn6288_handle_t *handle, uint8_t volume)
set the synthesis background volume
uint8_t syn6288_set_baud_rate(syn6288_handle_t *handle, syn6288_baud_rate_t rate)
set the baud rate
uint8_t syn6288_set_synthesis_volume(syn6288_handle_t *handle, uint8_t volume)
set the chip synthesis volume
uint8_t syn6288_set_synthesis_speed(syn6288_handle_t *handle, uint8_t speed)
set the synthesis speed
uint8_t syn6288_set_mode(syn6288_handle_t *handle, syn6288_mode_t mode)
set the chip mode
@ SYN6288_MODE_BACKGROUND_1
@ SYN6288_MODE_COMMON
@ SYN6288_BAUD_RATE_9600_BPS
uint8_t syn6288_init(syn6288_handle_t *handle)
initialize the chip
uint8_t syn6288_synthesis_sound(syn6288_handle_t *handle, syn6288_sound_t sound)
synthesis the sound
uint8_t syn6288_stop(syn6288_handle_t *handle)
stop the chip
syn6288_status_t
syn6288 status enumeration definition
uint8_t syn6288_get_status(syn6288_handle_t *handle, syn6288_status_t *status)
get the current status
uint8_t syn6288_set_text_type(syn6288_handle_t *handle, syn6288_type_t type)
set the chip text type
uint8_t syn6288_synthesis_message(syn6288_handle_t *handle, syn6288_message_t message)
synthesis the message
uint8_t syn6288_deinit(syn6288_handle_t *handle)
close the chip
uint8_t syn6288_synthesis_text(syn6288_handle_t *handle, char *text)
synthesis the test
uint8_t syn6288_resume(syn6288_handle_t *handle)
resume the chip
uint8_t syn6288_synthesis_ring(syn6288_handle_t *handle, syn6288_ring_t ring)
synthesis the ring
uint8_t syn6288_info(syn6288_info_t *info)
get chip's information
uint8_t syn6288_pause(syn6288_handle_t *handle)
pause the chip
@ SYN6288_TYPE_GB2312
@ SYN6288_TYPE_UNICODE
@ SYN6288_TYPE_GBK
@ SYN6288_TYPE_BIG5
@ SYN6288_RING_E
@ SYN6288_STATUS_BUSY
@ SYN6288_SOUND_A
@ SYN6288_MESSAGE_A
uint8_t syn6288_set_command(syn6288_handle_t *handle, char *command)
send the command to the chip
void syn6288_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t syn6288_interface_uart_flush(void)
interface uart flush
uint8_t syn6288_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint16_t syn6288_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t syn6288_interface_uart_deinit(void)
interface uart deinit
void syn6288_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t syn6288_interface_uart_init(void)
interface uart init
uint8_t syn6288_synthesis_test(void)
synthesis test
syn6288 handle structure definition
syn6288 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]