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