LibDriver SYN6988  1.0.0
SYN6988 full-featured driver
driver_syn6988.c
Go to the documentation of this file.
1 
37 #include "driver_syn6988.h"
38 #include <stdarg.h>
39 
43 #define CHIP_NAME "Voicetx SYN6988"
44 #define MANUFACTURER_NAME "Voicetx"
45 #define SUPPLY_VOLTAGE_MIN 3.1f
46 #define SUPPLY_VOLTAGE_MAX 4.5f
47 #define MAX_CURRENT 53.0f
48 #define TEMPERATURE_MIN -40.0f
49 #define TEMPERATURE_MAX 85.0f
50 #define DRIVER_VERSION 1000
61 static uint8_t a_check_busy(syn6988_handle_t *handle, uint32_t timeout)
62 {
63  uint8_t value;
64  uint32_t i;
65 
66  for (i = 0; i < timeout; i++) /* loop all */
67  {
68  if (handle->gpio_ready_read(&value) != 0) /* read ready level */
69  {
70  return 1; /* return error */
71  }
72  if (value == 0) /* check value */
73  {
74  return 0; /* return ready */
75  }
76  handle->delay_ms(1); /* delay 1ms */
77  }
78 
79  return 1; /* return timeout */
80 }
81 
92 static uint8_t a_write(syn6988_handle_t *handle, uint8_t *buf, uint16_t len)
93 {
94  uint8_t res;
95  uint16_t i;
96 
97  if (handle->uart_spi != 0) /* spi interface */
98  {
99  for (i = 0; i < len; i++) /* write all */
100  {
101  uint8_t rx;
102 
103  res = handle->spi_transmit(&buf[i], &rx, 1); /* write one byte */
104  if (res != 0) /* check result */
105  {
106  return 1; /* return error */
107  }
108  handle->delay_ms(1); /* delay 1ms */
109  }
110  }
111  else /* uart interface */
112  {
113  res = handle->uart_flush(); /* uart flush */
114  if (res != 0) /* check result */
115  {
116  return 1; /* return error */
117  }
118  res = handle->uart_write(buf, len); /* uart write */
119  if (res != 0) /* check result */
120  {
121  return 1; /* return error */
122  }
123  }
124 
125  return 0; /* success return 0 */
126 }
127 
138 static uint16_t a_read(syn6988_handle_t *handle, uint8_t *buf, uint16_t len)
139 {
140  uint8_t res;
141  uint16_t i;
142 
143  if (handle->uart_spi != 0) /* spi interface */
144  {
145  for (i = 0; i < len; i++) /* loop all */
146  {
147  uint8_t tx = 0xFF;
148 
149  res = handle->spi_transmit(&tx, &buf[i], 1); /* read one byte */
150  if (res != 0) /* check result */
151  {
152  return 1; /* return error */
153  }
154  handle->delay_ms(1); /* delay 1ms */
155  }
156  }
157  else
158  {
159  if (handle->uart_read(buf, len) != len) /* read data */
160  {
161  return 1; /* return error */
162  }
163  }
164 
165  return len; /* success return 0 */
166 }
167 
178 {
179  if (handle == NULL) /* check handle */
180  {
181  return 2; /* return error */
182  }
183 
184  handle->uart_spi = (uint8_t)interface; /* set interface */
185 
186  return 0; /* success return 0 */
187 }
188 
199 {
200  if (handle == NULL) /* check handle */
201  {
202  return 2; /* return error */
203  }
204 
205  *interface = (syn6988_interface_t)(handle->uart_spi); /* get interface */
206 
207  return 0; /* success return 0 */
208 }
209 
222 {
223  if (handle == NULL) /* check handle */
224  {
225  return 2; /* return error */
226  }
227  if (handle->debug_print == NULL) /* check debug_print */
228  {
229  return 3; /* return error */
230  }
231  if (handle->uart_init == NULL) /* check uart_init */
232  {
233  handle->debug_print("syn6988: uart_init is null.\n"); /* uart_init is null */
234 
235  return 3; /* return error */
236  }
237  if (handle->uart_deinit == NULL) /* check uart_deinit */
238  {
239  handle->debug_print("syn6988: uart_deinit is null.\n"); /* uart_deinit is null */
240 
241  return 3; /* return error */
242  }
243  if (handle->uart_read == NULL) /* check uart_read */
244  {
245  handle->debug_print("syn6988: uart_read is null.\n"); /* uart_read is null */
246 
247  return 3; /* return error */
248  }
249  if (handle->uart_write == NULL) /* check uart_write */
250  {
251  handle->debug_print("syn6988: uart_write is null.\n"); /* uart_write is null */
252 
253  return 3; /* return error */
254  }
255  if (handle->uart_flush == NULL) /* check uart_flush */
256  {
257  handle->debug_print("syn6988: uart_flush is null.\n"); /* uart_flush is null */
258 
259  return 3; /* return error */
260  }
261  if (handle->spi_init == NULL) /* check spi_init */
262  {
263  handle->debug_print("syn6988: spi_init is null.\n"); /* spi_init is null */
264 
265  return 3; /* return error */
266  }
267  if (handle->spi_deinit == NULL) /* check spi_deinit */
268  {
269  handle->debug_print("syn6988: spi_deinit is null.\n"); /* spi_deinit is null */
270 
271  return 3; /* return error */
272  }
273  if (handle->spi_transmit == NULL) /* check spi_transmit */
274  {
275  handle->debug_print("syn6988: spi_transmit is null.\n"); /* spi_transmit is null */
276 
277  return 3; /* return error */
278  }
279  if (handle->gpio_ready_init == NULL) /* check gpio_ready_init */
280  {
281  handle->debug_print("syn6988: gpio_ready_init is null.\n"); /* gpio_ready_init is null */
282 
283  return 3; /* return error */
284  }
285  if (handle->gpio_ready_deinit == NULL) /* check gpio_ready_deinit */
286  {
287  handle->debug_print("syn6988: gpio_ready_deinit is null.\n"); /* gpio_ready_deinit is null */
288 
289  return 3; /* return error */
290  }
291  if (handle->gpio_ready_read == NULL) /* check gpio_ready_read */
292  {
293  handle->debug_print("syn6988: gpio_ready_read is null.\n"); /* gpio_ready_read is null */
294 
295  return 3; /* return error */
296  }
297  if (handle->delay_ms == NULL) /* check delay_ms */
298  {
299  handle->debug_print("syn6988: delay_ms is null.\n"); /* delay_ms is null */
300 
301  return 3; /* return error */
302  }
303 
304  if (handle->uart_spi != 0) /* spi interface */
305  {
306  if (handle->spi_init() != 0) /* spi init */
307  {
308  handle->debug_print("syn6988: spi init failed.\n"); /* spi init failed */
309 
310  return 1; /* return error */
311  }
312  }
313  else /* uart interface */
314  {
315  if (handle->uart_init() != 0) /* uart init */
316  {
317  handle->debug_print("syn6988: uart init failed.\n"); /* uart init failed */
318 
319  return 1; /* return error */
320  }
321  }
322  if (handle->gpio_ready_init() != 0) /* gpio ready init */
323  {
324  if (handle->uart_spi != 0) /* spi interface */
325  {
326  (void)handle->spi_deinit(); /* spi deinit */
327  }
328  else /* uart interface */
329  {
330  (void)handle->uart_deinit(); /* uart deinit */
331  }
332  handle->debug_print("syn6988: gpio ready init failed.\n"); /* gpio ready init failed */
333 
334  return 4; /* return error */
335  }
336  handle->inited = 1; /* flag finish initialization */
337 
338  return 0; /* success return 0 */
339 }
340 
353 {
354  if (handle == NULL) /* check handle */
355  {
356  return 2; /* return error */
357  }
358  if (handle->inited != 1) /* check handle initialization */
359  {
360  return 3; /* return error */
361  }
362 
363  if (handle->uart_spi != 0) /* spi interface */
364  {
365  if (handle->spi_deinit() != 0) /* spi deinit */
366  {
367  handle->debug_print("syn6988: spi deinit failed.\n"); /* spi deinit failed */
368 
369  return 1; /* return error */
370  }
371  }
372  else /* uart interface */
373  {
374  if (handle->uart_deinit() != 0) /* uart deinit */
375  {
376  handle->debug_print("syn6988: uart deinit failed.\n"); /* uart deinit failed */
377 
378  return 1; /* return error */
379  }
380  }
381  if (handle->gpio_ready_deinit() != 0) /* gpio ready deinit */
382  {
383  handle->debug_print("syn6988: gpio ready deinit failed.\n"); /* gpio ready deinit failed */
384 
385  return 4; /* return error */
386  }
387  handle->inited = 0; /* flag closed */
388 
389  return 0; /* success return 0 */
390 }
391 
404 {
405  uint8_t res;
406  uint8_t value;
407  uint8_t times = 3;
408  uint16_t len;
409  uint8_t temp[1];
410  uint8_t cmd[4];
411 
412  if (handle == NULL) /* check handle */
413  {
414  return 2; /* return error */
415  }
416  if (handle->inited != 1) /* check handle initialization */
417  {
418  return 3; /* return error */
419  }
420  if (handle->uart_spi != 0) /* spi interface */
421  {
422  if (handle->gpio_ready_read(&value) != 0) /* read ready level */
423  {
424  return 1; /* return error */
425  }
426  if (value != 0) /* check value */
427  {
428  *status = (syn6988_status_t)(1); /* set status */
429  }
430  else
431  {
432  *status = (syn6988_status_t)(0); /* set status */
433  }
434 
435  return 0; /* success return 0 */
436  }
437  else /* uart interface */
438  {
439  cmd[0] = 0xFD; /* frame header */
440  cmd[1] = 0x00; /* length msb */
441  cmd[2] = 0x01; /* length lsb */
442  cmd[3] = 0x21; /* command */
443  while (1) /* loop */
444  {
445  res = handle->uart_flush(); /* uart flush */
446  if (res != 0) /* check result */
447  {
448  handle->debug_print("syn6988: uart flush failed.\n"); /* uart flush failed */
449 
450  return 1; /* return error */
451  }
452  res = handle->uart_write((uint8_t *)cmd, 4); /* uart write */
453  if (res != 0) /* check result */
454  {
455  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
456 
457  return 1; /* return error */
458  }
459  handle->delay_ms(100); /* delay 100 ms */
460  memset(temp, 0, sizeof(uint8_t) * 1); /* clear the buffer */
461  len = handle->uart_read((uint8_t *)temp, 1); /* uart read */
462  if (len != 1) /* check result */
463  {
464  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
465 
466  return 1; /* return error */
467  }
468  if (temp[0] == 0x4F) /* check frame */
469  {
470  *status = (syn6988_status_t)(0); /* set status */
471 
472  return 0; /* success return 0 */
473  }
474  else if (temp[0] == 0x4E) /* check frame */
475  {
476  *status = (syn6988_status_t)(1); /* set status */
477 
478  return 0; /* success return 0 */
479  }
480  else
481  {
482  if (times != 0) /* check times */
483  {
484  times--; /* retry times-- */
485  handle->delay_ms(100); /* delay 100 ms */
486 
487  continue; /* continue */
488  }
489  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
490 
491  return 1; /* return error */
492  }
493  }
494  }
495 }
496 
509 {
510  uint8_t res;
511  uint16_t len;
512  uint8_t temp;
513  uint8_t cmd[4];
514 
515  if (handle == NULL) /* check handle */
516  {
517  return 2; /* return error */
518  }
519  if (handle->inited != 1) /* check handle initialization */
520  {
521  return 3; /* return error */
522  }
523  if (handle->uart_spi != 0) /* check interface */
524  {
525  handle->debug_print("syn6988: spi interface \
526  can't use this function.\n"); /* spi interface can't use this function */
527 
528  return 4; /* return error */
529  }
530 
531  cmd[0] = 0xFD; /* frame header */
532  cmd[1] = 0x00; /* length msb */
533  cmd[2] = 0x01; /* length lsb */
534  cmd[3] = 0x02; /* command */
535  res = a_write(handle, (uint8_t *)cmd, 4); /* write data */
536  if (res != 0) /* check result */
537  {
538  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
539 
540  return 1; /* return error */
541  }
542  handle->delay_ms(100); /* delay 100 ms */
543  len = a_read(handle, (uint8_t *)&temp, 1); /* read data */
544  if (len != 1) /* check result */
545  {
546  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
547 
548  return 1; /* return error */
549  }
550  if (temp == 0x41) /* check return */
551  {
552  return 0; /* success return 0 */
553  }
554  else
555  {
556  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
557 
558  return 1; /* return error */
559  }
560 }
561 
574 {
575  uint8_t res;
576  uint16_t len;
577  uint8_t temp;
578  uint8_t cmd[4];
579 
580  if (handle == NULL) /* check handle */
581  {
582  return 2; /* return error */
583  }
584  if (handle->inited != 1) /* check handle initialization */
585  {
586  return 3; /* return error */
587  }
588  if (handle->uart_spi != 0) /* check interface */
589  {
590  handle->debug_print("syn6988: spi interface \
591  can't use this function.\n"); /* spi interface can't use this function */
592 
593  return 4; /* return error */
594  }
595 
596  cmd[0] = 0xFD; /* frame header */
597  cmd[1] = 0x00; /* length msb */
598  cmd[2] = 0x01; /* length lsb */
599  cmd[3] = 0x03; /* command */
600  res = a_write(handle, (uint8_t *)cmd, 4); /* write data */
601  if (res != 0) /* check result */
602  {
603  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
604 
605  return 1; /* return error */
606  }
607  handle->delay_ms(100); /* delay 100 ms */
608  len = a_read(handle, (uint8_t *)&temp, 1); /* read data */
609  if (len != 1) /* check result */
610  {
611  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
612 
613  return 1; /* return error */
614  }
615  if (temp == 0x41) /* check return */
616  {
617 
618  return 0; /* success return 0 */
619  }
620  else
621  {
622  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
623 
624  return 1; /* return error */
625  }
626 }
627 
640 {
641  uint8_t res;
642  uint16_t len;
643  uint8_t temp;
644  uint8_t cmd[4];
645 
646  if (handle == NULL) /* check handle */
647  {
648  return 2; /* return error */
649  }
650  if (handle->inited != 1) /* check handle initialization */
651  {
652  return 3; /* return error */
653  }
654  if (handle->uart_spi != 0) /* check interface */
655  {
656  handle->debug_print("syn6988: spi interface \
657  can't use this function.\n"); /* spi interface can't use this function */
658 
659  return 4; /* return error */
660  }
661 
662  cmd[0] = 0xFD; /* frame header */
663  cmd[1] = 0x00; /* length msb */
664  cmd[2] = 0x01; /* length lsb */
665  cmd[3] = 0x04; /* command */
666  res = a_write(handle, (uint8_t *)cmd, 4); /* write data */
667  if (res != 0) /* check result */
668  {
669  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
670 
671  return 1; /* return error */
672  }
673  handle->delay_ms(100); /* delay 100 ms */
674  len = a_read(handle, (uint8_t *)&temp, 1); /* read data */
675  if (len != 1) /* check result */
676  {
677  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
678 
679  return 1; /* return error */
680  }
681  if (temp == 0x41) /* check return */
682  {
683  return 0; /* success return 0 */
684  }
685  else
686  {
687  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
688 
689  return 1; /* return error */
690  }
691 }
692 
705 {
706  uint8_t res;
707  uint16_t len;
708  uint8_t temp;
709  uint8_t cmd[4];
710 
711  if (handle == NULL) /* check handle */
712  {
713  return 2; /* return error */
714  }
715  if (handle->inited != 1) /* check handle initialization */
716  {
717  return 3; /* return error */
718  }
719  if (handle->uart_spi != 0) /* check interface */
720  {
721  handle->debug_print("syn6988: spi interface \
722  can't use this function.\n"); /* spi interface can't use this function */
723 
724  return 4; /* return error */
725  }
726 
727  cmd[0] = 0xFD; /* frame header */
728  cmd[1] = 0x00; /* length msb */
729  cmd[2] = 0x01; /* length lsb */
730  cmd[3] = 0x22; /* command */
731  res = a_write(handle, (uint8_t *)cmd, 4); /* write data */
732  if (res != 0) /* check result */
733  {
734  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
735 
736  return 1; /* return error */
737  }
738  handle->delay_ms(100); /* delay 100 ms */
739  len = a_read(handle, (uint8_t *)&temp, 1); /* read data */
740  if (len != 1) /* check result */
741  {
742  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
743 
744  return 1; /* return error */
745  }
746  if (temp == 0x41) /* check return */
747  {
748  return 0; /* success return 0 */
749  }
750  else
751  {
752  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
753 
754  return 1; /* return error */
755  }
756 }
757 
770 {
771  uint8_t res;
772  uint16_t len;
773  uint8_t temp;
774  uint8_t cmd[4];
775 
776  if (handle == NULL) /* check handle */
777  {
778  return 2; /* return error */
779  }
780  if (handle->inited != 1) /* check handle initialization */
781  {
782  return 3; /* return error */
783  }
784  if (handle->uart_spi != 0) /* check interface */
785  {
786  handle->debug_print("syn6988: spi interface \
787  can't use this function.\n"); /* spi interface can't use this function */
788 
789  return 4; /* return error */
790  }
791 
792  cmd[0] = 0xFD; /* frame header */
793  cmd[1] = 0x00; /* length msb */
794  cmd[2] = 0x01; /* length lsb */
795  cmd[3] = 0xFF; /* command */
796  res = a_write(handle, (uint8_t *)cmd, 4); /* write data */
797  if (res != 0) /* check result */
798  {
799  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
800 
801  return 1; /* return error */
802  }
803  handle->delay_ms(100); /* delay 100 ms */
804  res = a_write(handle, (uint8_t *)cmd, 4); /* write data */
805  if (res != 0) /* check result */
806  {
807  handle->debug_print("syn6988: uart write failed.\n"); /* uart write failed */
808 
809  return 1; /* return error */
810  }
811  handle->delay_ms(100); /* delay 100 ms */
812  len = a_read(handle, (uint8_t *)&temp, 1); /* read data */
813  if (len != 1) /* check result */
814  {
815  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
816 
817  return 1; /* return error */
818  }
819  if (temp == 0x41) /* check return */
820  {
821  return 0; /* success return 0 */
822  }
823  else
824  {
825  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
826 
827  return 1; /* return error */
828  }
829 }
830 
842 {
843  if (handle == NULL) /* check handle */
844  {
845  return 2; /* return error */
846  }
847  if (handle->inited != 1) /* check handle initialization */
848  {
849  return 3; /* return error */
850  }
851 
852  handle->type = (uint8_t)type; /* set type */
853 
854  return 0; /* success return 0 */
855 }
856 
868 {
869  if (handle == NULL) /* check handle */
870  {
871  return 2; /* return error */
872  }
873  if (handle->inited != 1) /* check handle initialization */
874  {
875  return 3; /* return error */
876  }
877 
878  *type = (syn6988_type_t)(handle->type); /* get type */
879 
880  return 0; /* success return 0 */
881 }
882 
896 uint8_t syn6988_synthesis_text(syn6988_handle_t *handle, const char *const fmt, ...)
897 {
898  va_list args;
899  uint8_t res;
900  uint8_t temp;
901  uint16_t l;
902  uint16_t len;
903  uint32_t timeout = SYN6988_BUSY_TIMEOUT;
904 
905  if (handle == NULL) /* check handle */
906  {
907  return 2; /* return error */
908  }
909  if (handle->inited != 1) /* check handle initialization */
910  {
911  return 3; /* return error */
912  }
913 
914  memset((char *)(handle->buf + 5), 0, sizeof(char) * 4091); /* clear buffer */
915  va_start(args, fmt); /* var start */
916  (void)vsnprintf((char *)(handle->buf + 5), 4091,
917  (char const *)fmt, args); /* print to buffer */
918  va_end(args); /* var end */
919  len = (uint16_t)strlen((const char *)(handle->buf + 5)); /* get length of txt */
920  handle->buf[0] = 0xFD; /* frame header */
921  handle->buf[1] = (uint8_t)((len + 2) / 256); /* length msb */
922  handle->buf[2] = (len + 2) % 256; /* length lsb */
923  handle->buf[3] = 0x01; /* command */
924  handle->buf[4] = handle->type; /* command type */
925  res = a_check_busy(handle, timeout);
926  if (res != 0) /* check result */
927  {
928  handle->debug_print("syn6988: chip is busy.\n"); /* chip is busy */
929 
930  return 4; /* return error */
931  }
932  res = a_write(handle, handle->buf, len + 5); /* write data */
933  if (res != 0) /* check result */
934  {
935  handle->debug_print("syn6988: write failed.\n"); /* write failed */
936 
937  return 1; /* return error */
938  }
939  if (handle->uart_spi == 0) /* uart interface */
940  {
941  handle->delay_ms(100); /* delay 100 ms */
942  }
943  l = a_read(handle, (uint8_t *)&temp, 1); /* read data */
944  if (l != 1) /* check result */
945  {
946  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
947 
948  return 5; /* return error */
949  }
950  if (temp == 0x41) /* check return */
951  {
952  if (handle->uart_spi != 0) /* spi interface */
953  {
954  handle->delay_ms(200); /* delay 200 ms */
955  }
956 
957  return 0; /* success return 0 */
958  }
959  else
960  {
961  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
962 
963  return 5; /* return error */
964  }
965 }
966 
979 uint8_t syn6988_set_synthesis_volume(syn6988_handle_t *handle, uint8_t volume)
980 {
981  char cmd[8];
982 
983  if (handle == NULL) /* check handle */
984  {
985  return 2; /* return error */
986  }
987  if (handle->inited != 1) /* check handle initialization */
988  {
989  return 3; /* return error */
990  }
991  if (volume > 10) /* check volume */
992  {
993  handle->debug_print("syn6988: volume is invalid.\n"); /* volume is invalid */
994 
995  return 4; /* return error */
996  }
997 
998  memset((char *)cmd, 0, sizeof(char) * 8); /* memory set 0 */
999  (void)snprintf((char *)cmd, 8, "[v%d]", (int16_t)volume); /* set command */
1000  if (syn6988_set_command_with_arg(handle, 0x01, 0x00, cmd, SYN6988_BUSY_TIMEOUT) != 0) /* write command */
1001  {
1002  return 1; /* return error */
1003  }
1004 
1005  return 0; /* success return 0 */
1006 }
1007 
1020 uint8_t syn6988_set_synthesis_speed(syn6988_handle_t *handle, uint8_t speed)
1021 {
1022  char cmd[8];
1023 
1024  if (handle == NULL) /* check handle */
1025  {
1026  return 2; /* return error */
1027  }
1028  if (handle->inited != 1) /* check handle initialization */
1029  {
1030  return 3; /* return error */
1031  }
1032  if (speed > 10) /* check volume */
1033  {
1034  handle->debug_print("syn6988: speed is invalid.\n"); /* speed is invalid */
1035 
1036  return 4; /* return error */
1037  }
1038 
1039  memset((char *)cmd, 0, sizeof(char) * 8); /* memory set 0 */
1040  (void)snprintf((char *)cmd, 8, "[s%d]", (int16_t)speed); /* set command */
1041  if (syn6988_set_command_with_arg(handle, 0x01, 0x00, cmd, SYN6988_BUSY_TIMEOUT) != 0) /* write command */
1042  {
1043  return 1; /* return error */
1044  }
1045 
1046  return 0; /* success return 0 */
1047 }
1048 
1061 {
1062  char cmd[8];
1063 
1064  if (handle == NULL) /* check handle */
1065  {
1066  return 2; /* return error */
1067  }
1068  if (handle->inited != 1) /* check handle initialization */
1069  {
1070  return 3; /* return error */
1071  }
1072 
1073  memset((char *)cmd, 0, sizeof(char) * 8); /* memory set 0 */
1074  (void)snprintf((char *)cmd, 8, "[g%d]", (int16_t)language); /* set command */
1075  if (syn6988_set_command_with_arg(handle, 0x01, 0x00, cmd, SYN6988_BUSY_TIMEOUT) != 0) /* write command */
1076  {
1077  return 1; /* return error */
1078  }
1079 
1080  return 0; /* success return 0 */
1081 }
1082 
1100 uint8_t syn6988_set_command_with_arg(syn6988_handle_t *handle, uint8_t command, uint8_t param, char *txt, uint32_t timeout)
1101 {
1102  uint8_t res;
1103  uint8_t temp;
1104  uint16_t l;
1105  uint16_t len;
1106 
1107  if (handle == NULL) /* check handle */
1108  {
1109  return 2; /* return error */
1110  }
1111  if (handle->inited != 1) /* check handle initialization */
1112  {
1113  return 3; /* return error */
1114  }
1115 
1116  len = (uint16_t)strlen(txt); /* get length of txt */
1117  if (len > 4091) /* check result */
1118  {
1119  handle->debug_print("syn6988: txt is too long.\n"); /* txt is too long */
1120 
1121  return 4; /* return error */
1122  }
1123  handle->buf[0] = 0xFD; /* frame header */
1124  handle->buf[1] = (uint8_t)((len + 2) / 256); /* length msb */
1125  handle->buf[2] = (len + 2) % 256; /* length lsb */
1126  handle->buf[3] = command; /* command */
1127  handle->buf[4] = param; /* command param */
1128  strcpy((char *)&handle->buf[5], txt); /* copy command */
1129  res = a_check_busy(handle, timeout); /* check busy */
1130  if (res != 0) /* check result */
1131  {
1132  handle->debug_print("syn6988: chip is busy.\n"); /* chip is busy */
1133 
1134  return 5; /* return error */
1135  }
1136  res = a_write(handle, handle->buf, len + 5); /* write data */
1137  if (res != 0) /* check result */
1138  {
1139  handle->debug_print("syn6988: write failed.\n"); /* write failed */
1140 
1141  return 1; /* return error */
1142  }
1143  if (handle->uart_spi == 0) /* uart interface */
1144  {
1145  handle->delay_ms(100); /* delay 100 ms */
1146  }
1147  l = a_read(handle, (uint8_t *)&temp, 1); /* read data */
1148  if (l != 1) /* check result */
1149  {
1150  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
1151 
1152  return 6; /* return error */
1153  }
1154  if (temp == 0x41) /* check return */
1155  {
1156  if (handle->uart_spi != 0) /* spi interface */
1157  {
1158  handle->delay_ms(200); /* delay 200 ms */
1159  }
1160 
1161  return 0; /* success return 0 */
1162  }
1163  else
1164  {
1165  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
1166 
1167  return 6; /* return error */
1168  }
1169 }
1170 
1185 uint8_t syn6988_set_command(syn6988_handle_t *handle, uint8_t command, uint32_t timeout)
1186 {
1187  uint8_t res;
1188  uint8_t temp;
1189  uint16_t l;
1190 
1191  if (handle == NULL) /* check handle */
1192  {
1193  return 2; /* return error */
1194  }
1195  if (handle->inited != 1) /* check handle initialization */
1196  {
1197  return 3; /* return error */
1198  }
1199 
1200  handle->buf[0] = 0xFD; /* frame header */
1201  handle->buf[1] = 0x00; /* length msb */
1202  handle->buf[2] = 0x01; /* length lsb */
1203  handle->buf[3] = command; /* command */
1204  res = a_check_busy(handle, timeout); /* check busy */
1205  if (res != 0) /* check result */
1206  {
1207  handle->debug_print("syn6988: chip is busy.\n"); /* chip is busy */
1208 
1209  return 4; /* return error */
1210  }
1211  res = a_write(handle, handle->buf, 4); /* write data */
1212  if (res != 0) /* check result */
1213  {
1214  handle->debug_print("syn6988: write failed.\n"); /* write failed */
1215 
1216  return 1; /* return error */
1217  }
1218  if (handle->uart_spi == 0) /* uart interface */
1219  {
1220  handle->delay_ms(100); /* delay 100 ms */
1221  }
1222  l = a_read(handle, (uint8_t *)&temp, 1); /* read data */
1223  if (l != 1) /* check result */
1224  {
1225  handle->debug_print("syn6988: uart read failed.\n"); /* uart read failed */
1226 
1227  return 5; /* return error */
1228  }
1229  if (temp == 0x41) /* check return */
1230  {
1231  if (handle->uart_spi != 0) /* spi interface */
1232  {
1233  handle->delay_ms(200); /* delay 200 ms */
1234  }
1235 
1236  return 0; /* success return 0 */
1237  }
1238  else
1239  {
1240  handle->debug_print("syn6988: command receive failed.\n"); /* command receive failed */
1241 
1242  return 5; /* return error */
1243  }
1244 }
1245 
1255 {
1256  if (info == NULL) /* check handle */
1257  {
1258  return 2; /* return error */
1259  }
1260 
1261  memset(info, 0, sizeof(syn6988_info_t)); /* initialize syn6988 info structure */
1262  strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1263  strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1264  strncpy(info->interface, "UART SPI", 16); /* copy interface name */
1265  info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1266  info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1267  info->max_current_ma = MAX_CURRENT; /* set maximum current */
1268  info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1269  info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1270  info->driver_version = DRIVER_VERSION; /* set driver version */
1271 
1272  return 0; /* success return 0 */
1273 }
#define MAX_CURRENT
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver syn6988 header file
#define SYN6988_BUSY_TIMEOUT
syn6988 timeout definition
syn6988_type_t
syn6988 type enumeration definition
uint8_t syn6988_stop(syn6988_handle_t *handle)
stop the chip
uint8_t syn6988_get_text_type(syn6988_handle_t *handle, syn6988_type_t *type)
get the chip text type
uint8_t syn6988_synthesis_text(syn6988_handle_t *handle, const char *const fmt,...)
synthesis the test
uint8_t syn6988_init(syn6988_handle_t *handle)
initialize the chip
syn6988_status_t
syn6988 status enumeration definition
uint8_t syn6988_set_interface(syn6988_handle_t *handle, syn6988_interface_t interface)
set the chip interface
syn6988_interface_t
syn6988 interface enumeration definition
uint8_t syn6988_set_synthesis_language(syn6988_handle_t *handle, syn6988_language_t language)
set synthesis language
uint8_t syn6988_wake_up(syn6988_handle_t *handle)
wake up the chip
uint8_t syn6988_get_interface(syn6988_handle_t *handle, syn6988_interface_t *interface)
get the chip interface
uint8_t syn6988_pause(syn6988_handle_t *handle)
pause the chip
uint8_t syn6988_info(syn6988_info_t *info)
get chip's information
uint8_t syn6988_deinit(syn6988_handle_t *handle)
close the chip
uint8_t syn6988_standby(syn6988_handle_t *handle)
set the chip to standby mode
uint8_t syn6988_get_status(syn6988_handle_t *handle, syn6988_status_t *status)
get the current status
uint8_t syn6988_set_synthesis_speed(syn6988_handle_t *handle, uint8_t speed)
set the synthesis speed
syn6988_language_t
syn6988 language enumeration definition
uint8_t syn6988_resume(syn6988_handle_t *handle)
resume the chip
uint8_t syn6988_set_synthesis_volume(syn6988_handle_t *handle, uint8_t volume)
set the chip synthesis volume
uint8_t syn6988_set_text_type(syn6988_handle_t *handle, syn6988_type_t type)
set the chip text type
uint8_t syn6988_set_command(syn6988_handle_t *handle, uint8_t command, uint32_t timeout)
send the command to the chip
uint8_t syn6988_set_command_with_arg(syn6988_handle_t *handle, uint8_t command, uint8_t param, char *txt, uint32_t timeout)
send the command with arg to the chip
syn6988 handle structure definition
uint8_t(* uart_flush)(void)
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* gpio_ready_read)(uint8_t *value)
uint8_t(* uart_deinit)(void)
uint8_t(* gpio_ready_init)(void)
uint8_t buf[4096]
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_transmit)(uint8_t *tx, uint8_t *rx, uint16_t len)
uint8_t(* spi_deinit)(void)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* gpio_ready_deinit)(void)
uint8_t(* uart_init)(void)
syn6988 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char interface[16]
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]