LibDriver SYN6288  2.0.0
SYN6288 full-featured driver
driver_syn6288.c
Go to the documentation of this file.
1 
38 #include "driver_syn6288.h"
39 
43 #define CHIP_NAME "YuToneWorld SYN6288"
44 #define MANUFACTURER_NAME "YuToneWorld"
45 #define SUPPLY_VOLTAGE_MIN 2.4f
46 #define SUPPLY_VOLTAGE_MAX 5.1f
47 #define MAX_CURRENT 280.0f
48 #define TEMPERATURE_MIN -35.0f
49 #define TEMPERATURE_MAX 85.0f
50 #define DRIVER_VERSION 2000
63 {
64  if (handle == NULL) /* check handle */
65  {
66  return 2; /* return error */
67  }
68  if (handle->debug_print == NULL) /* check debug_print */
69  {
70  return 3; /* return error */
71  }
72  if (handle->uart_init == NULL) /* check uart_init */
73  {
74  handle->debug_print("syn6288: uart_init is null.\n"); /* uart_init is null */
75 
76  return 3; /* return error */
77  }
78  if (handle->uart_deinit == NULL) /* check uart_deinit */
79  {
80  handle->debug_print("syn6288: uart_deinit is null.\n"); /* uart_deinit is null */
81 
82  return 3; /* return error */
83  }
84  if (handle->uart_read == NULL) /* check uart_read */
85  {
86  handle->debug_print("syn6288: uart_read is null.\n"); /* uart_read is null */
87 
88  return 3; /* return error */
89  }
90  if (handle->uart_write == NULL) /* check uart_write */
91  {
92  handle->debug_print("syn6288: uart_write is null.\n"); /* uart_write is null */
93 
94  return 3; /* return error */
95  }
96  if (handle->uart_flush == NULL) /* check uart_flush */
97  {
98  handle->debug_print("syn6288: uart_flush is null.\n"); /* uart_flush is null */
99 
100  return 3; /* return error */
101  }
102  if (handle->delay_ms == NULL) /* check delay_ms */
103  {
104  handle->debug_print("syn6288: delay_ms is null.\n"); /* delay_ms is null */
105 
106  return 3; /* return error */
107  }
108 
109  if (handle->uart_init() != 0) /* uart init */
110  {
111  handle->debug_print("syn6288: uart init failed.\n"); /* uart init failed */
112 
113  return 1; /* return error */
114  }
115  handle->inited = 1; /* flag finish initialization */
116 
117  return 0; /* success return 0 */
118 }
119 
131 {
132  if (handle == NULL) /* check handle */
133  {
134  return 2; /* return error */
135  }
136  if (handle->inited != 1) /* check handle initialization */
137  {
138  return 3; /* return error */
139  }
140 
141  if (handle->uart_deinit() != 0) /* uart deinit */
142  {
143  handle->debug_print("syn6288: uart deinit failed.\n"); /* uart deinit failed */
144 
145  return 1; /* return error */
146  }
147  handle->inited = 0; /* flag close */
148 
149  return 0; /* success return 0 */
150 }
151 
164 {
165  uint8_t res;
166  uint8_t times = 3;
167  uint16_t len;
168  uint8_t temp[2];
169  uint8_t cmd[5];
170 
171  if (handle == NULL) /* check handle */
172  {
173  return 2; /* return error */
174  }
175  if (handle->inited != 1) /* check handle initialization */
176  {
177  return 3; /* return error */
178  }
179 
180  cmd[0] = 0xFD; /* frame header */
181  cmd[1] = 0x00; /* length msb */
182  cmd[2] = 0x02; /* length lsb */
183  cmd[3] = 0x21; /* command */
184  cmd[4] = 0xDE; /* xor */
185  while (1) /* loop */
186  {
187  res = handle->uart_flush(); /* uart flush */
188  if (res != 0) /* check result */
189  {
190  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
191 
192  return 1; /* return error */
193  }
194  res = handle->uart_write((uint8_t *)cmd, 5); /* uart write */
195  if (res != 0) /* check result */
196  {
197  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
198 
199  return 1; /* return error */
200  }
201  handle->delay_ms(100); /* delay 100 ms */
202  memset(temp, 0, sizeof(uint8_t) * 2); /* clear the buffer */
203  len = handle->uart_read((uint8_t *)temp, 2); /* uart read */
204  if (len != 2) /* check result */
205  {
206  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
207 
208  return 1; /* return error */
209  }
210  if ((temp[0] == 0x41) && (temp[1] == 0x4F)) /* check frame */
211  {
212  *status = (syn6288_status_t)(0); /* set status */
213 
214  return 0; /* success return 0 */
215  }
216  else if ((temp[0] == 0x41) && (temp[1] == 0x4E)) /* check frame */
217  {
218  *status = (syn6288_status_t)(1); /* set status */
219 
220  return 0; /* success return 0 */
221  }
222  else
223  {
224  if (times != 0) /* check times */
225  {
226  times--; /* retry times-- */
227  handle->delay_ms(100); /* delay 100 ms */
228 
229  continue; /* continue */
230  }
231  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
232 
233  return 1; /* return error */
234  }
235  }
236 }
237 
249 {
250  uint8_t res;
251  uint16_t len;
252  uint8_t temp;
253  uint8_t cmd[5];
254 
255  if (handle == NULL) /* check handle */
256  {
257  return 2; /* return error */
258  }
259  if (handle->inited != 1) /* check handle initialization */
260  {
261  return 3; /* return error */
262  }
263 
264  cmd[0] = 0xFD; /* frame header */
265  cmd[1] = 0x00; /* length msb */
266  cmd[2] = 0x02; /* length lsb */
267  cmd[3] = 0x02; /* command */
268  cmd[4] = 0xFD; /* xor */
269  res = handle->uart_flush(); /* uart flush */
270  if (res != 0) /* check result */
271  {
272  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
273 
274  return 1; /* return error */
275  }
276  res = handle->uart_write((uint8_t *)cmd, 5); /* uart write */
277  if (res != 0) /* check result */
278  {
279  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
280 
281  return 1; /* return error */
282  }
283  handle->delay_ms(100); /* delay 100 ms */
284  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
285  if (len != 1) /* check result */
286  {
287  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
288 
289  return 1; /* return error */
290  }
291  if (temp == 0x41) /* check return */
292  {
293  return 0; /* success return 0 */
294  }
295  else
296  {
297  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
298 
299  return 1; /* return error */
300  }
301 }
302 
314 {
315  uint8_t res;
316  uint16_t len;
317  uint8_t temp;
318  uint8_t cmd[5];
319 
320  if (handle == NULL) /* check handle */
321  {
322  return 2; /* return error */
323  }
324  if (handle->inited != 1) /* check handle initialization */
325  {
326  return 3; /* return error */
327  }
328 
329  cmd[0] = 0xFD; /* frame header */
330  cmd[1] = 0x00; /* length msb */
331  cmd[2] = 0x02; /* length lsb */
332  cmd[3] = 0x03; /* command */
333  cmd[4] = 0xFC; /* xor */
334  res = handle->uart_flush(); /* uart flush */
335  if (res != 0) /* check result */
336  {
337  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
338 
339  return 1; /* return error */
340  }
341  res = handle->uart_write((uint8_t *)cmd, 5); /* uart write */
342  if (res != 0) /* check result */
343  {
344  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
345 
346  return 1; /* return error */
347  }
348  handle->delay_ms(100); /* delay 100 ms */
349  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
350  if (len != 1) /* check result */
351  {
352  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
353 
354  return 1; /* return error */
355  }
356  if (temp == 0x41) /* check return */
357  {
358  return 0; /* success return 0 */
359  }
360  else
361  {
362  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
363 
364  return 1; /* return error */
365  }
366 }
367 
379 {
380  uint8_t res;
381  uint16_t len;
382  uint8_t temp;
383  uint8_t cmd[5];
384 
385  if (handle == NULL) /* check handle */
386  {
387  return 2; /* return error */
388  }
389  if (handle->inited != 1) /* check handle initialization */
390  {
391  return 3; /* return error */
392  }
393 
394  cmd[0] = 0xFD; /* frame header */
395  cmd[1] = 0x00; /* length msb */
396  cmd[2] = 0x02; /* length lsb */
397  cmd[3] = 0x04; /* command */
398  cmd[4] = 0xFB; /* xor */
399  res = handle->uart_flush(); /* uart flush */
400  if (res != 0) /* check result */
401  {
402  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
403 
404  return 1; /* return error */
405  }
406  res = handle->uart_write((uint8_t *)cmd, 5); /* uart write */
407  if (res != 0) /* check result */
408  {
409  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
410 
411  return 1; /* return error */
412  }
413  handle->delay_ms(100); /* delay 100 ms */
414  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
415  if (len != 1) /* check result */
416  {
417  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
418 
419  return 1; /* return error */
420  }
421  if (temp == 0x41) /* check return */
422  {
423  return 0; /* success return 0 */
424  }
425  else
426  {
427  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
428 
429  return 1; /* return error */
430  }
431 }
432 
444 {
445  uint8_t res;
446  uint16_t len;
447  uint8_t temp;
448  uint8_t cmd[5];
449 
450  if (handle == NULL) /* check handle */
451  {
452  return 2; /* return error */
453  }
454  if (handle->inited != 1) /* check handle initialization */
455  {
456  return 3; /* return error */
457  }
458 
459  cmd[0] = 0xFD; /* frame header */
460  cmd[1] = 0x00; /* length msb */
461  cmd[2] = 0x02; /* length lsb */
462  cmd[3] = 0x88; /* command */
463  cmd[4] = 0x77; /* xor */
464  res = handle->uart_flush(); /* uart flush */
465  if (res != 0) /* check result */
466  {
467  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
468 
469  return 1; /* return error */
470  }
471  res = handle->uart_write((uint8_t *)cmd, 5); /* uart write */
472  if (res != 0) /* check result */
473  {
474  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
475 
476  return 1; /* return error */
477  }
478  handle->delay_ms(100); /* delay 100 ms */
479  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
480  if (len != 1) /* check result */
481  {
482  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
483 
484  return 1; /* return error */
485  }
486  if (temp == 0x41) /* check return */
487  {
488  return 0; /* success return 0 */
489  }
490  else
491  {
492  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
493 
494  return 1; /* return error */
495  }
496 }
497 
510 {
511  uint8_t res;
512  uint16_t len;
513  uint8_t temp;
514  uint8_t cmd[6];
515 
516  if (handle == NULL) /* check handle */
517  {
518  return 2; /* return error */
519  }
520  if (handle->inited != 1) /* check handle initialization */
521  {
522  return 3; /* return error */
523  }
524 
525  cmd[0] = 0xFD; /* frame header */
526  cmd[1] = 0x00; /* length msb */
527  cmd[2] = 0x03; /* length lsb */
528  cmd[3] = 0x31; /* command */
529  switch (rate) /* check rate */
530  {
531  case SYN6288_BAUD_RATE_9600_BPS : /* 9600 */
532  {
533  handle->rate = rate; /* set rate */
534  cmd[4] = 0x00; /* baud rate */
535  cmd[5] = 0xCF; /* xor */
536 
537  break; /* break */
538  }
539  case SYN6288_BAUD_RATE_19200_BPS : /* 19200 */
540  {
541  handle->rate = rate; /* set rate */
542  cmd[4] = 0x01; /* baud rate */
543  cmd[5] = 0xCE; /* xor */
544 
545  break; /* break */
546  }
547  case SYN6288_BAUD_RATE_38400_BPS : /* 38400 */
548  {
549  handle->rate = rate; /* set rate */
550  cmd[4] = 0x02; /* baud rate */
551  cmd[5] = 0xCD; /* xor */
552 
553  break; /* break */
554  }
555  default :
556  {
557  handle->rate = rate; /* set rate */
558  cmd[4] = 0x00; /* baud rate */
559  cmd[5] = 0xCF; /* xor */
560 
561  break; /* break */
562  }
563  }
564  res = handle->uart_flush(); /* uart flush */
565  if (res != 0) /* check result */
566  {
567  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
568 
569  return 1; /* return error */
570  }
571  res = handle->uart_write((uint8_t *)cmd, 6); /* uart write */
572  if (res != 0) /* check result */
573  {
574  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
575 
576  return 1; /* return error */
577  }
578  handle->delay_ms(100); /* delay 100 ms */
579  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
580  if (len != 1) /* check result */
581  {
582  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
583 
584  return 1; /* return error */
585  }
586  if (temp == 0x41) /* check return */
587  {
588  return 0; /* success return 0 */
589  }
590  else
591  {
592  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
593 
594  return 1; /* return error */
595  }
596 }
597 
609 {
610  if (handle == NULL) /* check handle */
611  {
612  return 2; /* return error */
613  }
614  if (handle->inited != 1) /* check handle initialization */
615  {
616  return 3; /* return error */
617  }
618 
619  *rate = (syn6288_baud_rate_t)(handle->rate); /* get baud rate */
620 
621  return 0; /* success return 0 */
622 }
623 
635 {
636  if (handle == NULL) /* check handle */
637  {
638  return 2; /* return error */
639  }
640  if (handle->inited != 1) /* check handle initialization */
641  {
642  return 3; /* return error */
643  }
644 
645  handle->mode = (uint8_t)mode; /* set mode */
646 
647  return 0; /* success return 0 */
648 }
649 
661 {
662  if (handle == NULL) /* check handle */
663  {
664  return 2; /* return error */
665  }
666  if (handle->inited != 1) /* check handle initialization */
667  {
668  return 3; /* return error */
669  }
670 
671  *mode = (syn6288_mode_t)(handle->mode); /* get mode */
672 
673  return 0; /* success return 0 */
674 }
675 
687 {
688  if (handle == NULL) /* check handle */
689  {
690  return 2; /* return error */
691  }
692  if (handle->inited != 1) /* check handle initialization */
693  {
694  return 3; /* return error */
695  }
696 
697  handle->type = (uint8_t)type; /* set type */
698 
699  return 0; /* success return 0 */
700 }
701 
713 {
714  if (handle == NULL) /* check handle */
715  {
716  return 2; /* return error */
717  }
718  if (handle->inited != 1) /* check handle initialization */
719  {
720  return 3; /* return error */
721  }
722 
723  *type = (syn6288_type_t)(handle->type); /* get type */
724 
725  return 0; /* success return 0 */
726 }
727 
740 {
741  uint8_t res;
742  uint16_t len;
743  uint8_t temp;
744  uint8_t i;
745  uint8_t xor_cal = 0;
746  char cmd[6];
747 
748  if (handle == NULL) /* check handle */
749  {
750  return 2; /* return error */
751  }
752  if (handle->inited != 1) /* check handle initialization */
753  {
754  return 3; /* return error */
755  }
756 
757  cmd[0] = 's'; /* set 's' */
758  cmd[1] = 'o'; /* set 'o' */
759  cmd[2] = 'u'; /* set 'u' */
760  cmd[3] = 'n'; /* set 'n' */
761  cmd[4] = 'd'; /* set 'd' */
762  cmd[5] = sound; /* set sound number */
763  handle->buf[0] = 0xFD; /* frame header */
764  handle->buf[1] = (6 + 3) / 256; /* length msb */
765  handle->buf[2] = (6 + 3) % 256; /* length lsb */
766  handle->buf[3] = 0x01; /* command */
767  handle->buf[4] = 0x00; /* command param */
768  strncpy((char *)&handle->buf[5],(char *)cmd, 6); /* copy text */
769  for (i = 0; i < 6 + 5; i++)
770  {
771  xor_cal ^= handle->buf[i]; /* calculate xor */
772  }
773  handle->buf[6+5] = xor_cal; /* set xor */
774  res = handle->uart_flush(); /* uart flush */
775  if (res != 0) /* check result */
776  {
777  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
778 
779  return 1; /* return error */
780  }
781  res = handle->uart_write((uint8_t *)handle->buf, 6+6); /* uart write */
782  if (res != 0) /* check result */
783  {
784  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
785 
786  return 1; /* return error */
787  }
788  handle->delay_ms(100); /* delay 100 ms */
789  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
790  if (len != 1) /* check result */
791  {
792  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
793 
794  return 1; /* return error */
795  }
796  if (temp == 0x41) /* check return */
797  {
798  return 0; /* success return 0 */
799  }
800  else
801  {
802  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
803 
804  return 1; /* return error */
805  }
806 }
807 
820 {
821  uint8_t res;
822  uint16_t len;
823  uint8_t temp;
824  uint8_t i;
825  uint8_t xor_cal = 0;
826  char cmd[4];
827 
828  if (handle == NULL) /* check handle */
829  {
830  return 2; /* return error */
831  }
832  if (handle->inited != 1) /* check handle initialization */
833  {
834  return 3; /* return error */
835  }
836 
837  cmd[0] = 'm'; /* set 'm' */
838  cmd[1] = 's'; /* set 's' */
839  cmd[2] = 'g'; /* set 'g' */
840  cmd[3] = message; /* set message number */
841  handle->buf[0] = 0xFD; /* frame header */
842  handle->buf[1] = (4 + 3) / 256; /* length msb */
843  handle->buf[2] = (4 + 3) % 256; /* length lsb */
844  handle->buf[3] = 0x01; /* command */
845  handle->buf[4] = 0x00; /* command param */
846  strncpy((char *)&handle->buf[5], (char *)cmd, 4); /* copy text */
847  for (i = 0; i < 4 + 5; i++)
848  {
849  xor_cal ^= handle->buf[i]; /* calculate xor */
850  }
851  handle->buf[4+5] = xor_cal; /* set xor */
852  res = handle->uart_flush(); /* uart flush */
853  if (res != 0) /* check result */
854  {
855  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
856 
857  return 1; /* return error */
858  }
859  res = handle->uart_write((uint8_t *)handle->buf, 6 + 4); /* uart write */
860  if (res != 0) /* check result */
861  {
862  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
863 
864  return 1; /* return error */
865  }
866  handle->delay_ms(100); /* delay 100 ms */
867  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
868  if (len != 1) /* check result */
869  {
870  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
871 
872  return 1; /* return error */
873  }
874  if (temp == 0x41) /* check return */
875  {
876  return 0; /* success return 0 */
877  }
878  else
879  {
880  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
881 
882  return 1; /* return error */
883  }
884 }
885 
898 {
899  uint8_t res;
900  uint16_t len;
901  uint8_t temp;
902  uint8_t i;
903  uint8_t xor_cal = 0;
904  char cmd[5];
905 
906  if (handle == NULL) /* check handle */
907  {
908  return 2; /* return error */
909  }
910  if (handle->inited != 1) /* check handle initialization */
911  {
912  return 3; /* return error */
913  }
914 
915  cmd[0] = 'r'; /* set 'r' */
916  cmd[1] = 'i'; /* set 'i' */
917  cmd[2] = 'n'; /* set 'n' */
918  cmd[3] = 'g'; /* set 'g' */
919  cmd[4] = ring; /* set ring number */
920  handle->buf[0] = 0xFD; /* frame header */
921  handle->buf[1] = (5 + 3) / 256; /* length msb */
922  handle->buf[2] = (5 + 3) % 256; /* length lsb */
923  handle->buf[3] = 0x01; /* command */
924  handle->buf[4] = 0x00; /* command param */
925  strncpy((char *)&handle->buf[5],(char *)cmd, 5); /* copy text */
926  for (i = 0; i < 5 + 5; i++)
927  {
928  xor_cal ^= handle->buf[i]; /* calculate xor */
929  }
930  handle->buf[5+5] = xor_cal; /* set xor */
931  res = handle->uart_flush(); /* uart flush */
932  if (res != 0) /* check result */
933  {
934  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
935 
936  return 1; /* return error */
937  }
938  res = handle->uart_write((uint8_t *)handle->buf, 6+5); /* uart write */
939  if (res != 0) /* check result */
940  {
941  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
942 
943  return 1; /* return error */
944  }
945  handle->delay_ms(100); /* delay 100 ms */
946  len = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
947  if (len != 1) /* check result */
948  {
949  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
950 
951  return 1; /* return error */
952  }
953  if (temp == 0x41) /* check return */
954  {
955  return 0; /* success return 0 */
956  }
957  else
958  {
959  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
960 
961  return 1; /* return error */
962  }
963 }
964 
976 uint8_t syn6288_synthesis_text(syn6288_handle_t *handle, char *text)
977 {
978  uint8_t res;
979  uint16_t l;
980  uint8_t len, temp;
981  uint8_t i;
982  uint8_t xor_cal = 0;
983 
984  if (handle == NULL) /* check handle */
985  {
986  return 2; /* return error */
987  }
988  if (handle->inited != 1) /* check handle initialization */
989  {
990  return 3; /* return error */
991  }
992 
993  len = (uint8_t)strlen(text); /* get length of text */
994  if (len > 200) /* check length */
995  {
996  handle->debug_print("syn6288: text is too long.\n"); /* text is too long */
997 
998  return 1; /* return error */
999  }
1000  handle->buf[0] = 0xFD; /* frame header */
1001  handle->buf[1] = (uint8_t)((len + 3) / 256); /* length msb */
1002  handle->buf[2] = (len + 3) % 256; /* length lsb */
1003  handle->buf[3] = 0x01; /* command */
1004  handle->buf[4] = handle->mode|handle->type; /* command param */
1005  strncpy((char *)&handle->buf[5], text, len); /* copy text */
1006  for (i = 0; i < len + 5; i++)
1007  {
1008  xor_cal ^= handle->buf[i]; /* calculate xor */
1009  }
1010  handle->buf[len+5] = xor_cal; /* set xor */
1011  res = handle->uart_flush(); /* uart flush */
1012  if (res != 0) /* check result */
1013  {
1014  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
1015 
1016  return 1; /* return error */
1017  }
1018  res = handle->uart_write((uint8_t *)handle->buf, len+6); /* uart write */
1019  if (res != 0) /* check result */
1020  {
1021  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
1022 
1023  return 1; /* return error */
1024  }
1025  handle->delay_ms(100); /* delay 100 ms */
1026  l = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
1027  if (l != 1) /* check result */
1028  {
1029  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
1030 
1031  return 1; /* return error */
1032  }
1033  if (temp == 0x41) /* check return */
1034  {
1035  return 0; /* success return 0 */
1036  }
1037  else
1038  {
1039  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
1040 
1041  return 1; /* return error */
1042  }
1043 }
1044 
1056 uint8_t syn6288_set_synthesis_volume(syn6288_handle_t *handle, uint8_t volume)
1057 {
1058  char cmd[8];
1059 
1060  if (volume > 16) /* check volume */
1061  {
1062  handle->debug_print("syn6288: volume invalid.\n"); /* volume invalid */
1063 
1064  return 1; /* return error */
1065  }
1066 
1067  memset((char *)cmd, 0, sizeof(char)*8); /* memory set 0 */
1068  (void)snprintf((char *)cmd, 8, "v[%d]", (int16_t)volume); /* set command */
1069  handle->volume = volume; /* save volume */
1070 
1071  return syn6288_set_command(handle, (char *)cmd); /* write command */
1072 }
1073 
1084 uint8_t syn6288_get_synthesis_volume(syn6288_handle_t *handle, uint8_t *volume)
1085 {
1086  if (handle == NULL) /* check handle */
1087  {
1088  return 2; /* return error */
1089  }
1090  if (handle->inited != 1) /* check handle initialization */
1091  {
1092  return 3; /* return error */
1093  }
1094 
1095  *volume = handle->volume; /* get volume */
1096 
1097  return 0; /* success return 0 */
1098 }
1099 
1111 uint8_t syn6288_set_background_volume(syn6288_handle_t *handle, uint8_t volume)
1112 {
1113  char cmd[8];
1114 
1115  if (volume > 16) /* check volume */
1116  {
1117  handle->debug_print("syn6288: volume is invalid.\n"); /* volume is invalid */
1118 
1119  return 1; /* return error */
1120  }
1121 
1122  memset((char *)cmd, 0, sizeof(char)*8); /* memory set 0 */
1123  (void)snprintf((char *)cmd, 8, "m[%d]", (int16_t)volume); /* set command */
1124  handle->background_volume = volume; /* save volume */
1125 
1126  return syn6288_set_command(handle, (char *)cmd); /* write command */
1127 }
1128 
1139 uint8_t syn6288_get_background_volume(syn6288_handle_t *handle, uint8_t *volume)
1140 {
1141  if (handle == NULL) /* check handle */
1142  {
1143  return 2; /* return error */
1144  }
1145  if (handle->inited != 1) /* check handle initialization */
1146  {
1147  return 3; /* return error */
1148  }
1149 
1150  *volume = handle->background_volume; /* get volume */
1151 
1152  return 0; /* success return 0 */
1153 }
1154 
1166 uint8_t syn6288_set_synthesis_speed(syn6288_handle_t *handle, uint8_t speed)
1167 {
1168  char cmd[8];
1169 
1170  if (speed > 5) /* check speed */
1171  {
1172  handle->debug_print("syn6288: speed is invalid.\n"); /* speed is invalid */
1173 
1174  return 1; /* return error */
1175  }
1176 
1177  memset((char *)cmd, 0, sizeof(char)*8); /* memory set 0 */
1178  (void)snprintf((char *)cmd, 8, "t[%d]", (int16_t)speed); /* set command */
1179  handle->speed = speed; /* save speed */
1180 
1181  return syn6288_set_command(handle, (char *)cmd); /* write command */
1182 }
1183 
1194 uint8_t syn6288_get_synthesis_speed(syn6288_handle_t *handle, uint8_t *speed)
1195 {
1196  if (handle == NULL) /* check handle */
1197  {
1198  return 2; /* return error */
1199  }
1200  if (handle->inited != 1) /* check handle initialization */
1201  {
1202  return 3; /* return error */
1203  }
1204 
1205  *speed = handle->speed; /* get speed */
1206 
1207  return 0; /* success return 0 */
1208 }
1209 
1221 uint8_t syn6288_set_command(syn6288_handle_t *handle, char *command)
1222 {
1223  uint8_t res;
1224  uint16_t l;
1225  uint8_t len, temp;
1226  uint8_t i;
1227  uint8_t xor_cal = 0;
1228 
1229  if (handle == NULL) /* check handle */
1230  {
1231  return 2; /* return error */
1232  }
1233  if (handle->inited != 1) /* check handle initialization */
1234  {
1235  return 3; /* return error */
1236  }
1237 
1238  len = (uint8_t)strlen(command); /* get length of command */
1239  if (len > 200) /* check result */
1240  {
1241  handle->debug_print("syn6288: command is too long.\n"); /* command is too long */
1242 
1243  return 1; /* return error */
1244  }
1245  handle->buf[0] = 0xFD; /* frame header */
1246  handle->buf[1] = (uint8_t)((len + 3) / 256); /* length msb */
1247  handle->buf[2] = (len + 3) % 256; /* length lsb */
1248  handle->buf[3] = 0x01; /* command */
1249  handle->buf[4] = 0x00; /* command param */
1250  strncpy((char *)&handle->buf[5], command, len); /* copy command */
1251  for (i = 0; i < len + 5; i++)
1252  {
1253  xor_cal ^= handle->buf[i]; /* calculate xor */
1254  }
1255  handle->buf[len + 5] = xor_cal; /* set xor */
1256  res = handle->uart_flush(); /* uart flush */
1257  if (res != 0) /* check result */
1258  {
1259  handle->debug_print("syn6288: uart flush failed.\n"); /* uart flush failed */
1260 
1261  return 1; /* return error */
1262  }
1263  res = handle->uart_write((uint8_t *)handle->buf, len+6); /* uart write */
1264  if (res != 0) /* check result */
1265  {
1266  handle->debug_print("syn6288: uart write failed.\n"); /* uart write failed */
1267 
1268  return 1; /* return error */
1269  }
1270  handle->delay_ms(100); /* delay 100 ms */
1271  l = handle->uart_read((uint8_t *)&temp, 1); /* uart read */
1272  if (l != 1) /* check result */
1273  {
1274  handle->debug_print("syn6288: uart read failed.\n"); /* uart read failed */
1275 
1276  return 1; /* return error */
1277  }
1278  if (temp == 0x41) /* check return */
1279  {
1280  return 0; /* success return 0 */
1281  }
1282  else
1283  {
1284  handle->debug_print("syn6288: command receive failed.\n"); /* command receive failed */
1285 
1286  return 1; /* return error */
1287  }
1288 }
1289 
1299 {
1300  if (info == NULL) /* check handle */
1301  {
1302  return 2; /* return error */
1303  }
1304 
1305  memset(info, 0, sizeof(syn6288_info_t)); /* initialize syn6288 info structure */
1306  strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1307  strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1308  strncpy(info->interface, "UART", 8); /* copy interface name */
1309  info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1310  info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1311  info->max_current_ma = MAX_CURRENT; /* set maximum current */
1312  info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1313  info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1314  info->driver_version = DRIVER_VERSION; /* set driver version */
1315 
1316  return 0; /* success return 0 */
1317 }
#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 syn6288 header file
uint8_t syn6288_get_mode(syn6288_handle_t *handle, syn6288_mode_t *mode)
get the chip mode
uint8_t syn6288_set_background_volume(syn6288_handle_t *handle, uint8_t volume)
set the synthesis background volume
syn6288_mode_t
syn6288 mode enumeration definition
uint8_t syn6288_set_baud_rate(syn6288_handle_t *handle, syn6288_baud_rate_t rate)
set the baud rate
syn6288_baud_rate_t
syn6288 baud rate enumeration definition
uint8_t syn6288_get_background_volume(syn6288_handle_t *handle, uint8_t *volume)
get the chip synthesis background volume
uint8_t syn6288_get_synthesis_volume(syn6288_handle_t *handle, uint8_t *volume)
get the chip synthesis volume
uint8_t syn6288_set_synthesis_volume(syn6288_handle_t *handle, uint8_t volume)
set the chip synthesis volume
uint8_t syn6288_get_baud_rate(syn6288_handle_t *handle, syn6288_baud_rate_t *rate)
get the baud rate
uint8_t syn6288_set_synthesis_speed(syn6288_handle_t *handle, uint8_t speed)
set the synthesis speed
uint8_t syn6288_get_synthesis_speed(syn6288_handle_t *handle, uint8_t *speed)
get the synthesis speed
uint8_t syn6288_set_mode(syn6288_handle_t *handle, syn6288_mode_t mode)
set the chip mode
@ SYN6288_BAUD_RATE_38400_BPS
@ SYN6288_BAUD_RATE_9600_BPS
@ SYN6288_BAUD_RATE_19200_BPS
uint8_t syn6288_init(syn6288_handle_t *handle)
initialize the chip
syn6288_type_t
syn6288 type enumeration definition
uint8_t syn6288_power_down(syn6288_handle_t *handle)
power down 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_ring_t
syn6288 ring enumeration definition
syn6288_status_t
syn6288 status enumeration definition
syn6288_sound_t
syn6288 sound enumeration definition
uint8_t syn6288_get_status(syn6288_handle_t *handle, syn6288_status_t *status)
get the current status
uint8_t syn6288_get_text_type(syn6288_handle_t *handle, syn6288_type_t *type)
get the chip text type
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
syn6288_message_t
syn6288 message enumeration definition
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
uint8_t syn6288_set_command(syn6288_handle_t *handle, char *command)
send the command to the chip
syn6288 handle structure definition
uint8_t(* uart_flush)(void)
uint8_t buf[256]
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t background_volume
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* uart_init)(void)
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]