LibDriver WT588E02B
Loading...
Searching...
No Matches
driver_wt588e02b.c
Go to the documentation of this file.
1
36
37#include "driver_wt588e02b.h"
38
42#define CHIP_NAME "Waytronic Electronic WT588E02B"
43#define MANUFACTURER_NAME "Waytronic Electronic"
44#define SUPPLY_VOLTAGE_MIN 2.0f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 16.0f
47#define TEMPERATURE_MIN -20.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define WT588E02B_COMMAND_PLAY 0xF0
55#define WT588E02B_COMMAND_VOL 0xF1
56#define WT588E02B_COMMAND_PLAY_LOOP 0xF2
57#define WT588E02B_COMMAND_PLAY_LIST 0xF3
58#define WT588E02B_COMMAND_STOP 0xFF
59#define WT588E02B_COMMAND_UPDATE_ADDR 0xE0
60#define WT588E02B_COMMAND_UPDATE_ALL 0xE1
61#define WT588E02B_COMMAND_UPDATE_STATUS 0xDF
62#define WT588E02B_COMMAND_UPDATE_END 0xEF
63
73static uint8_t a_wt588e02b_check_busy(wt588e02b_handle_t *handle, uint8_t *busy)
74{
75 uint8_t res;
76 uint8_t miso;
77
78 res = handle->miso_gpio_read(&miso); /* read data */
79 if (res != 0) /* check result */
80 {
81 return 1; /* return error */
82 }
83 if (miso != 0) /* check busy */
84 {
85 *busy = 0; /* no busy */
86 }
87 else
88 {
89 *busy = 1; /* busy */
90 }
91
92 return 0; /* return error */
93}
94
105static uint8_t a_wt588e02b_write_with_no_cs(wt588e02b_handle_t *handle, uint32_t us, uint8_t data)
106{
107 uint8_t res;
108 uint8_t mosi;
109 uint8_t i;
110
111 for (i = 0; i < 8; i++) /* loop 8 bits */
112 {
113 mosi = (data >> (7 - i)) & 0x01; /* get output bit */
114
115 res = handle->mosi_gpio_write(mosi); /* write one bit */
116 if (res != 0) /* check result */
117 {
118 return 1; /* return error */
119 }
120 res = handle->sclk_gpio_write(1); /* set sclk high */
121 if (res != 0) /* check result */
122 {
123 return 1; /* return error */
124 }
125 handle->delay_us(us); /* delay us */
126 res = handle->sclk_gpio_write(0); /* set sclk low */
127 if (res != 0) /* check result */
128 {
129 return 1; /* return error */
130 }
131 handle->delay_us(us); /* delay us */
132 }
133
134 return 0; /* return error */
135}
136
147static uint8_t a_wt588e02b_read_with_no_cs(wt588e02b_handle_t *handle, uint32_t us, uint8_t *data)
148{
149 uint8_t res;
150 uint8_t miso;
151 uint8_t i;
152
153 res = handle->mosi_gpio_write(0); /* set low */
154 if (res != 0) /* check result */
155 {
156 return 1; /* return error */
157 }
158 *data = 0; /* init 0 */
159 for (i = 0; i < 8; i++) /* loop 8 bits */
160 {
161 res = handle->sclk_gpio_write(1); /* set sclk high */
162 if (res != 0) /* check result */
163 {
164 return 1; /* return error */
165 }
166 handle->delay_us(us); /* delay us */
167 res = handle->sclk_gpio_write(0); /* set sclk low */
168 if (res != 0) /* check result */
169 {
170 return 1; /* return error */
171 }
172 res = handle->miso_gpio_read(&miso); /* read data */
173 if (res != 0) /* check result */
174 {
175 return 1; /* return error */
176 }
177 if (miso != 0) /* check 1 */
178 {
179 *data |= 1 << (7 - i); /* set bit */
180 }
181 handle->delay_us(us); /* delay us */
182 }
183
184 return 0; /* return error */
185}
186
196static uint8_t a_update_get_status(wt588e02b_handle_t *handle, uint16_t *sum)
197{
198 uint8_t res;
199 uint8_t data1;
200 uint8_t data2;
201
202 *sum = 0; /* init 0 */
203 res = handle->sclk_gpio_write(0); /* set sclk low */
204 if (res != 0) /* check result */
205 {
206 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
207
208 return 1; /* return error */
209 }
210 res = handle->cs_gpio_write(0); /* set cs low */
211 if (res != 0) /* check result */
212 {
213 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
214
215 return 1; /* return error */
216 }
217 handle->delay_ms(5); /* delay 5ms */
218 res = a_wt588e02b_write_with_no_cs(handle, 20, WT588E02B_COMMAND_UPDATE_STATUS); /* write command */
219 if (res != 0) /* check result */
220 {
221 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
222
223 return 1; /* return error */
224 }
225 handle->delay_us(20); /* delay 20us */
226 res = a_wt588e02b_read_with_no_cs(handle, 20, &data1); /* read one byte */
227 if (res != 0) /* check result */
228 {
229 handle->debug_print("wt588e02b: read with no cs failed.\n"); /* read with no cs failed */
230
231 return 1; /* return error */
232 }
233 handle->delay_us(20); /* delay 20us */
234 res = a_wt588e02b_read_with_no_cs(handle, 20, &data2); /* read one byte */
235 if (res != 0) /* check result */
236 {
237 handle->debug_print("wt588e02b: read2 with no cs failed.\n"); /* read with no cs failed */
238
239 return 1; /* return error */
240 }
241 *sum = (uint16_t)((uint16_t)(data2) << 8) | data1; /* get sum */
242 res = handle->cs_gpio_write(1); /* set cs high */
243 if (res != 0) /* check result */
244 {
245 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
246
247 return 1; /* return error */
248 }
249
250 return 0; /* success return 0 */
251}
252
262static uint8_t a_update(wt588e02b_handle_t *handle, uint8_t addr)
263{
264 uint8_t res;
265
266 handle->sum = 0; /* init 0 */
267 res = handle->sclk_gpio_write(0); /* set sclk low */
268 if (res != 0) /* check result */
269 {
270 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
271
272 return 1; /* return error */
273 }
274 res = handle->cs_gpio_write(0); /* set cs low */
275 if (res != 0) /* check result */
276 {
277 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
278
279 return 1; /* return error */
280 }
281 handle->delay_ms(5); /* delay 5ms */
282 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_UPDATE_ADDR); /* write command */
283 if (res != 0) /* check result */
284 {
285 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
286
287 return 1; /* return error */
288 }
289 handle->sum += WT588E02B_COMMAND_UPDATE_ADDR; /* add sum */
290 handle->delay_us(20); /* delay 20us */
291 res = a_wt588e02b_write_with_no_cs(handle, 100, addr); /* write command */
292 if (res != 0) /* check result */
293 {
294 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
295
296 return 1; /* return error */
297 }
298 handle->sum += addr; /* add sum */
299 res = handle->cs_gpio_write(1); /* set cs high */
300 if (res != 0) /* check result */
301 {
302 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
303
304 return 1; /* return error */
305 }
306
307 return 0; /* success return 0 */
308}
309
318static uint8_t a_update_all(wt588e02b_handle_t *handle)
319{
320 uint8_t res;
321
322 handle->sum = 0; /* init 0 */
323 res = handle->sclk_gpio_write(0); /* set sclk low */
324 if (res != 0) /* check result */
325 {
326 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
327
328 return 1; /* return error */
329 }
330 res = handle->cs_gpio_write(0); /* set cs low */
331 if (res != 0) /* check result */
332 {
333 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
334
335 return 1; /* return error */
336 }
337 handle->delay_ms(5); /* delay 5ms */
338 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_UPDATE_ALL); /* write command */
339 if (res != 0) /* check result */
340 {
341 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
342
343 return 1; /* return error */
344 }
345 handle->sum += WT588E02B_COMMAND_UPDATE_ALL; /* add sum */
346 handle->delay_us(20); /* delay 20us */
347 res = a_wt588e02b_write_with_no_cs(handle, 100, 0xFF); /* write command */
348 if (res != 0) /* check result */
349 {
350 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
351
352 return 1; /* return error */
353 }
354 handle->sum += 0xFF; /* add sum */
355 res = handle->cs_gpio_write(1); /* set cs high */
356 if (res != 0) /* check result */
357 {
358 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
359
360 return 1; /* return error */
361 }
362
363 return 0; /* success return 0 */
364}
365
374static uint8_t a_update_end(wt588e02b_handle_t *handle)
375{
376 uint8_t res;
377
378 res = handle->sclk_gpio_write(0); /* set sclk low */
379 if (res != 0) /* check result */
380 {
381 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
382
383 return 1; /* return error */
384 }
385 res = handle->cs_gpio_write(0); /* set cs low */
386 if (res != 0) /* check result */
387 {
388 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
389
390 return 1; /* return error */
391 }
392 handle->delay_ms(5); /* delay 5ms */
393 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_UPDATE_END); /* write command */
394 if (res != 0) /* check result */
395 {
396 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
397
398 return 1; /* return error */
399 }
400 res = handle->cs_gpio_write(1); /* set cs high */
401 if (res != 0) /* check result */
402 {
403 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
404
405 return 1; /* return error */
406 }
407
408 return 0; /* success return 0 */
409}
410
421static uint8_t a_update_send_pack(wt588e02b_handle_t *handle, uint8_t *buf, uint16_t len)
422{
423 uint8_t res;
424 uint16_t check;
425 uint16_t i;
426
427 handle->sum = 0; /* init 0 */
428 res = handle->sclk_gpio_write(0); /* set sclk low */
429 if (res != 0) /* check result */
430 {
431 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
432
433 return 1; /* return error */
434 }
435 res = handle->cs_gpio_write(0); /* set cs low */
436 if (res != 0) /* check result */
437 {
438 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
439
440 return 1; /* return error */
441 }
442 for (i = 0; i < len; i++) /* loop all */
443 {
444 handle->delay_us(20);
445 res = a_wt588e02b_write_with_no_cs(handle, 2, buf[i]); /* write command */
446 if (res != 0) /* check result */
447 {
448 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
449
450 return 1; /* return error */
451 }
452 if ((i % 2) != 0) /* the second */
453 {
454 check = check | ((uint16_t)(buf[i]) << 8); /* set sum */
455 handle->sum += check; /* add sum */
456 }
457 else
458 {
459 check = buf[i]; /* set sum */
460 }
461 }
462 res = handle->cs_gpio_write(1); /* set cs high */
463 if (res != 0) /* check result */
464 {
465 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
466
467 return 1; /* return error */
468 }
469
470 return 0; /* success return 0 */
471}
472
486uint8_t wt588e02b_play(wt588e02b_handle_t *handle, uint8_t ind)
487{
488 uint8_t res;
489 uint8_t busy;
490
491 if (handle == NULL) /* check handle */
492 {
493 return 2; /* return error */
494 }
495 if (handle->inited != 1) /* check handle initialization */
496 {
497 return 3; /* return error */
498 }
499 if (ind > 0xDF) /* check result */
500 {
501 handle->debug_print("wt588e02b: ind > 0xDF.\n"); /* ind > 0xDF */
502
503 return 4; /* return error */
504 }
505 res = a_wt588e02b_check_busy(handle, &busy); /* read busy */
506 if (res != 0) /* check result */
507 {
508 handle->debug_print("wt588e02b: check busy failed.\n"); /* check busy failed */
509
510 return 1; /* return error */
511 }
512 if (busy != 0) /* check busy */
513 {
514 handle->debug_print("wt588e02b: chip is busy.\n"); /* chip is busy */
515
516 return 5; /* return error */
517 }
518
519 res = handle->sclk_gpio_write(0); /* set sclk low */
520 if (res != 0) /* check result */
521 {
522 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
523
524 return 1; /* return error */
525 }
526 res = handle->cs_gpio_write(0); /* set cs low */
527 if (res != 0) /* check result */
528 {
529 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
530
531 return 1; /* return error */
532 }
533 handle->delay_ms(5); /* delay 5ms */
534 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_PLAY); /* write command */
535 if (res != 0) /* check result */
536 {
537 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
538
539 return 1; /* return error */
540 }
541 res = a_wt588e02b_write_with_no_cs(handle, 100, ind); /* write command */
542 if (res != 0) /* check result */
543 {
544 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
545
546 return 1; /* return error */
547 }
548 res = handle->cs_gpio_write(1); /* set cs high */
549 if (res != 0) /* check result */
550 {
551 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
552
553 return 1; /* return error */
554 }
555
556 return 0; /* success return 0 */
557}
558
571uint8_t wt588e02b_set_vol(wt588e02b_handle_t *handle, uint8_t vol)
572{
573 uint8_t res;
574
575 if (handle == NULL) /* check handle */
576 {
577 return 2; /* return error */
578 }
579 if (handle->inited != 1) /* check handle initialization */
580 {
581 return 3; /* return error */
582 }
583 if (vol > 0x3F) /* check result */
584 {
585 handle->debug_print("wt588e02b: vol > 0x3F.\n"); /* vol > 0x3F */
586
587 return 4; /* return error */
588 }
589
590 res = handle->sclk_gpio_write(0); /* set sclk low */
591 if (res != 0) /* check result */
592 {
593 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
594
595 return 1; /* return error */
596 }
597 res = handle->cs_gpio_write(0); /* set cs low */
598 if (res != 0) /* check result */
599 {
600 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
601
602 return 1; /* return error */
603 }
604 handle->delay_ms(5); /* delay 5ms */
605 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_VOL); /* write command */
606 if (res != 0) /* check result */
607 {
608 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
609
610 return 1; /* return error */
611 }
612 res = a_wt588e02b_write_with_no_cs(handle, 100, vol); /* write command */
613 if (res != 0) /* check result */
614 {
615 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
616
617 return 1; /* return error */
618 }
619 res = handle->cs_gpio_write(1); /* set cs high */
620 if (res != 0) /* check result */
621 {
622 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
623
624 return 1; /* return error */
625 }
626
627 return 0; /* success return 0 */
628}
629
641{
642 uint8_t res;
643
644 if (handle == NULL) /* check handle */
645 {
646 return 2; /* return error */
647 }
648 if (handle->inited != 1) /* check handle initialization */
649 {
650 return 3; /* return error */
651 }
652
653 res = handle->sclk_gpio_write(0); /* set sclk low */
654 if (res != 0) /* check result */
655 {
656 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
657
658 return 1; /* return error */
659 }
660 res = handle->cs_gpio_write(0); /* set cs low */
661 if (res != 0) /* check result */
662 {
663 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
664
665 return 1; /* return error */
666 }
667 handle->delay_ms(5); /* delay 5ms */
668 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_STOP); /* write command */
669 if (res != 0) /* check result */
670 {
671 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
672
673 return 1; /* return error */
674 }
675 res = a_wt588e02b_write_with_no_cs(handle, 100, 0xEF); /* write command */
676 if (res != 0) /* check result */
677 {
678 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
679
680 return 1; /* return error */
681 }
682 res = handle->cs_gpio_write(1); /* set cs high */
683 if (res != 0) /* check result */
684 {
685 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
686
687 return 1; /* return error */
688 }
689
690 return 0; /* success return 0 */
691}
692
709uint8_t wt588e02b_play_list(wt588e02b_handle_t *handle, uint8_t *list, uint8_t len)
710{
711 uint8_t i;
712 uint8_t res;
713 uint8_t busy;
714
715 if (handle == NULL) /* check handle */
716 {
717 return 2; /* return error */
718 }
719 if (handle->inited != 1) /* check handle initialization */
720 {
721 return 3; /* return error */
722 }
723 if (len > 40) /* check length */
724 {
725 handle->debug_print("wt588e02b: len > 40.\n"); /* len > 40 */
726
727 return 4; /* return error */
728 }
729 for (i = 0; i < len; i++) /* check all */
730 {
731 if (list[i] > 0xDF) /* check range */
732 {
733 handle->debug_print("wt588e02b: list[%d] > 0xDF.\n", i); /* list > 0xDF */
734
735 return 5; /* return error */
736 }
737 }
738 res = a_wt588e02b_check_busy(handle, &busy); /* read busy */
739 if (res != 0) /* check result */
740 {
741 handle->debug_print("wt588e02b: check busy failed.\n"); /* check busy failed */
742
743 return 1; /* return error */
744 }
745 if (busy != 0) /* check busy */
746 {
747 handle->debug_print("wt588e02b: chip is busy.\n"); /* chip is busy */
748
749 return 6; /* return error */
750 }
751
752 res = handle->sclk_gpio_write(0); /* set sclk low */
753 if (res != 0) /* check result */
754 {
755 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
756
757 return 1; /* return error */
758 }
759 res = handle->cs_gpio_write(0); /* set cs low */
760 if (res != 0) /* check result */
761 {
762 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
763
764 return 1; /* return error */
765 }
766 handle->delay_ms(5); /* delay 5ms */
767 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_PLAY_LIST); /* write command */
768 if (res != 0) /* check result */
769 {
770 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
771
772 return 1; /* return error */
773 }
774 for (i = 0; i < len; i ++) /* write all */
775 {
776 res = a_wt588e02b_write_with_no_cs(handle, 100, list[i]); /* write command */
777 if (res != 0) /* check result */
778 {
779 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
780
781 return 1; /* return error */
782 }
783 }
784 res = handle->cs_gpio_write(1); /* set cs high */
785 if (res != 0) /* check result */
786 {
787 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
788
789 return 1; /* return error */
790 }
791
792 return 0; /* success return 0 */
793}
794
808uint8_t wt588e02b_play_loop(wt588e02b_handle_t *handle, uint8_t ind)
809{
810 uint8_t res;
811 uint8_t busy;
812
813 if (handle == NULL) /* check handle */
814 {
815 return 2; /* return error */
816 }
817 if (handle->inited != 1) /* check handle initialization */
818 {
819 return 3; /* return error */
820 }
821 if (ind > 0xDF) /* check result */
822 {
823 handle->debug_print("wt588e02b: ind > 0xDF.\n"); /* ind > 0xDF */
824
825 return 4; /* return error */
826 }
827
828 res = a_wt588e02b_check_busy(handle, &busy); /* read busy */
829 if (res != 0) /* check result */
830 {
831 handle->debug_print("wt588e02b: check busy failed.\n"); /* check busy failed */
832
833 return 1; /* return error */
834 }
835 if (busy != 0) /* check busy */
836 {
837 handle->debug_print("wt588e02b: chip is busy.\n"); /* chip is busy */
838
839 return 5; /* return error */
840 }
841
842 res = handle->sclk_gpio_write(0); /* set sclk low */
843 if (res != 0) /* check result */
844 {
845 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
846
847 return 1; /* return error */
848 }
849 res = handle->cs_gpio_write(0); /* set cs low */
850 if (res != 0) /* check result */
851 {
852 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
853
854 return 1; /* return error */
855 }
856 handle->delay_ms(5); /* delay 5ms */
857 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_PLAY_LOOP); /* write command */
858 if (res != 0) /* check result */
859 {
860 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
861
862 return 1; /* return error */
863 }
864 res = a_wt588e02b_write_with_no_cs(handle, 100, 0x02); /* write command */
865 if (res != 0) /* check result */
866 {
867 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
868
869 return 1; /* return error */
870 }
871 res = a_wt588e02b_write_with_no_cs(handle, 100, ind); /* write command */
872 if (res != 0) /* check result */
873 {
874 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
875
876 return 1; /* return error */
877 }
878 res = handle->cs_gpio_write(1); /* set cs high */
879 if (res != 0) /* check result */
880 {
881 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
882
883 return 1; /* return error */
884 }
885
886 return 0; /* success return 0 */
887}
888
903{
904 uint8_t res;
905 uint8_t busy;
906
907 if (handle == NULL) /* check handle */
908 {
909 return 2; /* return error */
910 }
911 if (handle->inited != 1) /* check handle initialization */
912 {
913 return 3; /* return error */
914 }
915 if (ind > 0xDF) /* check result */
916 {
917 handle->debug_print("wt588e02b: ind > 0xDF.\n"); /* ind > 0xDF */
918
919 return 4; /* return error */
920 }
921
922 res = a_wt588e02b_check_busy(handle, &busy); /* read busy */
923 if (res != 0) /* check result */
924 {
925 handle->debug_print("wt588e02b: check busy failed.\n"); /* check busy failed */
926
927 return 1; /* return error */
928 }
929 if (busy != 0) /* check busy */
930 {
931 handle->debug_print("wt588e02b: chip is busy.\n"); /* chip is busy */
932
933 return 5; /* return error */
934 }
935
936 res = handle->sclk_gpio_write(0); /* set sclk low */
937 if (res != 0) /* check result */
938 {
939 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
940
941 return 1; /* return error */
942 }
943 res = handle->cs_gpio_write(0); /* set cs low */
944 if (res != 0) /* check result */
945 {
946 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
947
948 return 1; /* return error */
949 }
950 handle->delay_ms(5); /* delay 5ms */
951 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_PLAY_LOOP); /* write command */
952 if (res != 0) /* check result */
953 {
954 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
955
956 return 1; /* return error */
957 }
958 res = a_wt588e02b_write_with_no_cs(handle, 100, 0x01); /* write command */
959 if (res != 0) /* check result */
960 {
961 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
962
963 return 1; /* return error */
964 }
965 res = a_wt588e02b_write_with_no_cs(handle, 100, ind); /* write command */
966 if (res != 0) /* check result */
967 {
968 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
969
970 return 1; /* return error */
971 }
972 res = handle->cs_gpio_write(1); /* set cs high */
973 if (res != 0) /* check result */
974 {
975 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
976
977 return 1; /* return error */
978 }
979
980 return 0; /* success return 0 */
981}
982
995{
996 uint8_t res;
997 uint8_t busy;
998
999 if (handle == NULL) /* check handle */
1000 {
1001 return 2; /* return error */
1002 }
1003 if (handle->inited != 1) /* check handle initialization */
1004 {
1005 return 3; /* return error */
1006 }
1007
1008 res = a_wt588e02b_check_busy(handle, &busy); /* read busy */
1009 if (res != 0) /* check result */
1010 {
1011 handle->debug_print("wt588e02b: check busy failed.\n"); /* check busy failed */
1012
1013 return 1; /* return error */
1014 }
1015 if (busy != 0) /* check busy */
1016 {
1017 handle->debug_print("wt588e02b: chip is busy.\n"); /* chip is busy */
1018
1019 return 4; /* return error */
1020 }
1021
1022 res = handle->sclk_gpio_write(0); /* set sclk low */
1023 if (res != 0) /* check result */
1024 {
1025 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
1026
1027 return 1; /* return error */
1028 }
1029 res = handle->cs_gpio_write(0); /* set cs low */
1030 if (res != 0) /* check result */
1031 {
1032 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
1033
1034 return 1; /* return error */
1035 }
1036 handle->delay_ms(5); /* delay 5ms */
1037 res = a_wt588e02b_write_with_no_cs(handle, 100, WT588E02B_COMMAND_PLAY_LOOP); /* write command */
1038 if (res != 0) /* check result */
1039 {
1040 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
1041
1042 return 1; /* return error */
1043 }
1044 res = a_wt588e02b_write_with_no_cs(handle, 100, 0x03); /* write command */
1045 if (res != 0) /* check result */
1046 {
1047 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
1048
1049 return 1; /* return error */
1050 }
1051 res = handle->cs_gpio_write(1); /* set cs high */
1052 if (res != 0) /* check result */
1053 {
1054 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
1055
1056 return 1; /* return error */
1057 }
1058
1059 return 0; /* success return 0 */
1060}
1061
1076uint8_t wt588e02b_update(wt588e02b_handle_t *handle, uint8_t ind, char *path)
1077{
1078 uint8_t res;
1079 uint16_t sum;
1080 uint32_t size;
1081 uint32_t i;
1082 uint32_t m;
1083 uint32_t n;
1084 uint32_t addr;
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 if (ind > 0xDF) /* check result */
1095 {
1096 handle->debug_print("wt588e02b: ind > 0xDF.\n"); /* ind > 0xDF */
1097
1098 return 5; /* return error */
1099 }
1100
1101 res = handle->bin_read_init(path, &size); /* bin read init */
1102 if (res != 0) /* check result */
1103 {
1104 handle->debug_print("wt588e02b: bin read init failed.\n"); /* bin read init failed */
1105
1106 return 4; /* return error */
1107 }
1108
1109 m = size / 512; /* get package number */
1110 n = size - m * 512; /* get package remain */
1111 res = a_update(handle, ind); /* update */
1112 if (res != 0) /* check result */
1113 {
1114 handle->debug_print("wt588e02b: update failed.\n"); /* update failed */
1115 (void)handle->bin_read_deinit(); /* bin read deinit */
1116
1117 return 1; /* return error */
1118 }
1119 handle->delay_ms(30); /* delay 30ms */
1120 addr = 0; /* init 0 */
1121 for (i = 0; i < m; i++) /* loop all */
1122 {
1123 handle->delay_ms(16); /* delay 16ms */
1124 res = handle->bin_read(addr, 512, handle->buf); /* bin read */
1125 if (res != 0) /* check result */
1126 {
1127 handle->debug_print("wt588e02b: bin read failed.\n"); /* bin read failed */
1128 (void)handle->bin_read_deinit(); /* bin read deinit */
1129
1130 return 1; /* return error */
1131 }
1132 addr += 512; /* add 512 */
1133 res = a_update_get_status(handle, &sum); /* get status */
1134 if (res != 0) /* check result */
1135 {
1136 handle->debug_print("wt588e02b: update get status failed.\n"); /* update get status failed */
1137 (void)handle->bin_read_deinit(); /* bin read deinit */
1138
1139 return 1; /* return error */
1140 }
1141 if (handle->sum != sum) /* check sum */
1142 {
1143 handle->debug_print("wt588e02b: sum check error.\n"); /* sum check error */
1144 (void)handle->bin_read_deinit(); /* bin read deinit */
1145
1146 return 1; /* return error */
1147 }
1148 handle->delay_ms(1); /* delay 1ms */
1149 res = a_update_send_pack(handle, handle->buf, 512); /* send pack */
1150 if (res != 0) /* check sum */
1151 {
1152 handle->debug_print("wt588e02b: update send pack failed.\n"); /* update send pack failed */
1153 (void)handle->bin_read_deinit(); /* bin read deinit */
1154
1155 return 1; /* return error */
1156 }
1157 }
1158 if (n != 0) /* check remain */
1159 {
1160 handle->delay_ms(16); /* delay 16ms */
1161 memset(handle->buf, 0, sizeof(uint8_t) * 512); /* init 0 */
1162 res = handle->bin_read(addr, n, handle->buf); /* bin read */
1163 if (res != 0) /* check result */
1164 {
1165 handle->debug_print("wt588e02b: bin read failed.\n"); /* bin read failed */
1166 (void)handle->bin_read_deinit(); /* bin read deinit */
1167
1168 return 1; /* return error */
1169 }
1170 addr += n; /* add n */
1171 res = a_update_get_status(handle, &sum); /* get status */
1172 if (res != 0) /* check result */
1173 {
1174 handle->debug_print("wt588e02b: update get status failed.\n"); /* update get status failed */
1175 (void)handle->bin_read_deinit(); /* bin read deinit */
1176
1177 return 1; /* return error */
1178 }
1179 if (handle->sum != sum) /* check sum */
1180 {
1181 handle->debug_print("wt588e02b: sum check error.\n"); /* sum check error */
1182 (void)handle->bin_read_deinit(); /* bin read deinit */
1183
1184 return 1; /* return error */
1185 }
1186 handle->delay_ms(1); /* delay 1ms */
1187 res = a_update_send_pack(handle, handle->buf, 512); /* send pack */
1188 if (res != 0) /* check sum */
1189 {
1190 handle->debug_print("wt588e02b: update send pack failed.\n"); /* update send pack failed */
1191 (void)handle->bin_read_deinit(); /* bin read deinit */
1192
1193 return 1; /* return error */
1194 }
1195 }
1196 res = a_update_end(handle); /* update end */
1197 if (res != 0) /* check result */
1198 {
1199 handle->debug_print("wt588e02b: update end failed.\n"); /* update end failed */
1200 (void)handle->bin_read_deinit(); /* bin read deinit */
1201
1202 return 1; /* return error */
1203 }
1204 res = handle->bin_read_deinit(); /* bin read deinit */
1205 if (res != 0) /* check result */
1206 {
1207 handle->debug_print("wt588e02b: bin read deinit failed.\n"); /* bin read deinit failed */
1208
1209 return 1; /* return error */
1210 }
1211
1212 return 0; /* success return 0 */
1213}
1214
1228uint8_t wt588e02b_update_all(wt588e02b_handle_t *handle, char *path)
1229{
1230 uint8_t res;
1231 uint16_t sum;
1232 uint32_t size;
1233 uint32_t i;
1234 uint32_t m;
1235 uint32_t addr;
1236
1237 if (handle == NULL) /* check handle */
1238 {
1239 return 2; /* return error */
1240 }
1241 if (handle->inited != 1) /* check handle initialization */
1242 {
1243 return 3; /* return error */
1244 }
1245
1246 res = handle->bin_read_init(path, &size); /* bin read init */
1247 if (res != 0) /* check result */
1248 {
1249 handle->debug_print("wt588e02b: bin read init failed.\n"); /* bin read init failed */
1250
1251 return 4; /* return error */
1252 }
1253 if ((size % 512) != 0) /* check size */
1254 {
1255 handle->debug_print("wt588e02b: bin size is invalid.\n"); /* bin size is invalid */
1256 (void)handle->bin_read_deinit(); /* bin read deinit */
1257
1258 return 5; /* return error */
1259 }
1260
1261 m = size / 512; /* get package number */
1262 res = a_update_all(handle); /* update all */
1263 if (res != 0) /* check result */
1264 {
1265 handle->debug_print("wt588e02b: update all failed.\n"); /* update all failed */
1266 (void)handle->bin_read_deinit(); /* bin read deinit */
1267
1268 return 1; /* return error */
1269 }
1270 handle->delay_ms(30); /* delay 30ms */
1271 addr = 0; /* init 0 */
1272 for (i = 0; i < m; i++) /* loop all */
1273 {
1274 handle->delay_ms(16); /* delay 16ms */
1275 res = handle->bin_read(addr, 512, handle->buf); /* bin read */
1276 if (res != 0) /* check result */
1277 {
1278 handle->debug_print("wt588e02b: bin read failed.\n"); /* bin read failed */
1279 (void)handle->bin_read_deinit(); /* bin read deinit */
1280
1281 return 1; /* return error */
1282 }
1283 addr += 512; /* add 512 */
1284 res = a_update_get_status(handle, &sum); /* get status */
1285 if (res != 0) /* check result */
1286 {
1287 handle->debug_print("wt588e02b: update get status failed.\n"); /* update get status failed */
1288 (void)handle->bin_read_deinit(); /* bin read deinit */
1289
1290 return 1; /* return error */
1291 }
1292 if (handle->sum != sum) /* check sum */
1293 {
1294 handle->debug_print("wt588e02b: sum check error.\n"); /* sum check error */
1295 (void)handle->bin_read_deinit(); /* bin read deinit */
1296
1297 return 1; /* return error */
1298 }
1299 handle->delay_ms(1); /* delay 1ms */
1300 res = a_update_send_pack(handle, handle->buf, 512); /* send pack */
1301 if (res != 0) /* check sum */
1302 {
1303 handle->debug_print("wt588e02b: update send pack failed.\n"); /* update send pack failed */
1304 (void)handle->bin_read_deinit(); /* bin read deinit */
1305
1306 return 1; /* return error */
1307 }
1308 }
1309 res = a_update_end(handle); /* update end */
1310 if (res != 0) /* check result */
1311 {
1312 handle->debug_print("wt588e02b: update end failed.\n"); /* update end failed */
1313 (void)handle->bin_read_deinit(); /* bin read deinit */
1314
1315 return 1; /* return error */
1316 }
1317 res = handle->bin_read_deinit(); /* bin read deinit */
1318 if (res != 0) /* check result */
1319 {
1320 handle->debug_print("wt588e02b: bin read deinit failed.\n"); /* bin read deinit failed */
1321
1322 return 1; /* return error */
1323 }
1324
1325 return 0; /* success return 0 */
1326}
1327
1340{
1341 uint8_t res;
1342 uint8_t busy;
1343
1344 if (handle == NULL) /* check handle */
1345 {
1346 return 2; /* return error */
1347 }
1348 if (handle->inited != 1) /* check handle initialization */
1349 {
1350 return 3; /* return error */
1351 }
1352
1353 res = a_wt588e02b_check_busy(handle, &busy); /* read busy */
1354 if (res != 0) /* check result */
1355 {
1356 handle->debug_print("wt588e02b: check busy failed.\n"); /* check busy failed */
1357
1358 return 1; /* return error */
1359 }
1360 if (busy != 0) /* check busy */
1361 {
1362 *enable = WT588E02B_BOOL_TRUE; /* set true */
1363 }
1364 else
1365 {
1366 *enable = WT588E02B_BOOL_FALSE; /* set false */
1367 }
1368
1369 return 0; /* success return 0 */
1370}
1371
1383{
1384 if (handle == NULL) /* check handle */
1385 {
1386 return 2; /* return error */
1387 }
1388 if (handle->debug_print == NULL) /* check debug_print */
1389 {
1390 return 3; /* return error */
1391 }
1392 if (handle->sclk_gpio_init == NULL) /* check sclk_gpio_init */
1393 {
1394 handle->debug_print("wt588e02b: sclk_gpio_init is null.\n"); /* sclk_gpio_init is null */
1395
1396 return 3; /* return error */
1397 }
1398 if (handle->sclk_gpio_deinit == NULL) /* check sclk_gpio_deinit */
1399 {
1400 handle->debug_print("wt588e02b: sclk_gpio_deinit is null.\n"); /* sclk_gpio_deinit is null */
1401
1402 return 3; /* return error */
1403 }
1404 if (handle->sclk_gpio_write == NULL) /* check sclk_gpio_write */
1405 {
1406 handle->debug_print("wt588e02b: sclk_gpio_write is null.\n"); /* sclk_gpio_write is null */
1407
1408 return 3; /* return error */
1409 }
1410 if (handle->mosi_gpio_init == NULL) /* check mosi_gpio_init */
1411 {
1412 handle->debug_print("wt588e02b: mosi_gpio_init is null.\n"); /* mosi_gpio_init is null */
1413
1414 return 3; /* return error */
1415 }
1416 if (handle->mosi_gpio_deinit == NULL) /* check mosi_gpio_deinit */
1417 {
1418 handle->debug_print("wt588e02b: mosi_gpio_deinit is null.\n"); /* mosi_gpio_deinit is null */
1419
1420 return 3; /* return error */
1421 }
1422 if (handle->mosi_gpio_write == NULL) /* check mosi_gpio_write */
1423 {
1424 handle->debug_print("wt588e02b: mosi_gpio_write is null.\n"); /* mosi_gpio_write is null */
1425
1426 return 3; /* return error */
1427 }
1428 if (handle->miso_gpio_init == NULL) /* check miso_gpio_init */
1429 {
1430 handle->debug_print("wt588e02b: miso_gpio_init is null.\n"); /* miso_gpio_init is null */
1431
1432 return 3; /* return error */
1433 }
1434 if (handle->miso_gpio_deinit == NULL) /* check miso_gpio_deinit */
1435 {
1436 handle->debug_print("wt588e02b: miso_gpio_deinit is null.\n"); /* miso_gpio_deinit is null */
1437
1438 return 3; /* return error */
1439 }
1440 if (handle->miso_gpio_read == NULL) /* check miso_gpio_read */
1441 {
1442 handle->debug_print("wt588e02b: miso_gpio_read is null.\n"); /* miso_gpio_read is null */
1443
1444 return 3; /* return error */
1445 }
1446 if (handle->cs_gpio_init == NULL) /* check cs_gpio_init */
1447 {
1448 handle->debug_print("wt588e02b: cs_gpio_init is null.\n"); /* cs_gpio_init is null */
1449
1450 return 3; /* return error */
1451 }
1452 if (handle->cs_gpio_deinit == NULL) /* check cs_gpio_deinit */
1453 {
1454 handle->debug_print("wt588e02b: cs_gpio_deinit is null.\n"); /* cs_gpio_deinit is null */
1455
1456 return 3; /* return error */
1457 }
1458 if (handle->cs_gpio_write == NULL) /* check cs_gpio_write */
1459 {
1460 handle->debug_print("wt588e02b: cs_gpio_write is null.\n"); /* cs_gpio_write is null */
1461
1462 return 3; /* return error */
1463 }
1464 if (handle->delay_ms == NULL) /* check delay_ms */
1465 {
1466 handle->debug_print("wt588e02b: delay_ms is null.\n"); /* delay_ms is null */
1467
1468 return 3; /* return error */
1469 }
1470 if (handle->delay_us == NULL) /* check delay_us */
1471 {
1472 handle->debug_print("wt588e02b: delay_us is null.\n"); /* delay_us is null */
1473
1474 return 3; /* return error */
1475 }
1476 if (handle->bin_read_init == NULL) /* check bin_read_init */
1477 {
1478 handle->debug_print("wt588e02b: bin_read_init is null.\n"); /* bin_read_init is null */
1479
1480 return 3; /* return error */
1481 }
1482 if (handle->bin_read == NULL) /* check bin_read */
1483 {
1484 handle->debug_print("wt588e02b: bin_read is null.\n"); /* bin_read is null */
1485
1486 return 3; /* return error */
1487 }
1488 if (handle->bin_read_deinit == NULL) /* check bin_read_deinit */
1489 {
1490 handle->debug_print("wt588e02b: bin_read_deinit is null.\n"); /* bin_read_deinit is null */
1491
1492 return 3; /* return error */
1493 }
1494
1495 if (handle->sclk_gpio_init() != 0) /* sclk gpio init */
1496 {
1497 handle->debug_print("wt588e02b: sclk gpio init failed.\n"); /* sclk gpio init failed */
1498
1499 return 1; /* return error */
1500 }
1501 if (handle->mosi_gpio_init() != 0) /* mosi gpio init */
1502 {
1503 handle->debug_print("wt588e02b: mosi gpio init failed.\n"); /* mosi gpio init failed */
1504 (void)handle->sclk_gpio_deinit(); /* sclk gpio deinit */
1505
1506 return 1; /* return error */
1507 }
1508 if (handle->miso_gpio_init() != 0) /* miso gpio init */
1509 {
1510 handle->debug_print("wt588e02b: miso gpio init failed.\n"); /* miso gpio init failed */
1511 (void)handle->sclk_gpio_deinit(); /* sclk gpio deinit */
1512 (void)handle->mosi_gpio_deinit(); /* mosi gpio deinit */
1513
1514 return 1; /* return error */
1515 }
1516 if (handle->cs_gpio_init() != 0) /* cs gpio init */
1517 {
1518 handle->debug_print("wt588e02b: cs gpio init failed.\n"); /* cs gpio init failed */
1519 (void)handle->sclk_gpio_deinit(); /* sclk gpio deinit */
1520 (void)handle->mosi_gpio_deinit(); /* mosi gpio deinit */
1521 (void)handle->miso_gpio_deinit(); /* miso gpio deinit */
1522
1523 return 1; /* return error */
1524 }
1525 handle->sum = 0; /* init 0 */
1526 handle->inited = 1; /* flag finished */
1527
1528 return 0; /* success return 0 */
1529}
1530
1542{
1543 uint8_t res;
1544
1545 if (handle == NULL) /* check handle */
1546 {
1547 return 2; /* return error */
1548 }
1549 if (handle->inited != 1) /* check handle initialization */
1550 {
1551 return 3; /* return error */
1552 }
1553
1554 res = handle->sclk_gpio_deinit(); /* sclk gpio deinit failed */
1555 if (res != 0) /* check result */
1556 {
1557 handle->debug_print("wt588e02b: sclk gpio deinit failed.\n"); /* sclk gpio deinit failed */
1558
1559 return 1; /* return error */
1560 }
1561 res = handle->mosi_gpio_deinit(); /* mosi gpio deinit failed */
1562 if (res != 0) /* check result */
1563 {
1564 handle->debug_print("wt588e02b: mosi gpio deinit failed.\n"); /* mosi gpio deinit failed */
1565
1566 return 1; /* return error */
1567 }
1568 res = handle->miso_gpio_deinit(); /* miso gpio deinit failed */
1569 if (res != 0) /* check result */
1570 {
1571 handle->debug_print("wt588e02b: miso gpio deinit failed.\n"); /* miso gpio deinit failed */
1572
1573 return 1; /* return error */
1574 }
1575 res = handle->cs_gpio_deinit(); /* cs gpio deinit failed */
1576 if (res != 0) /* check result */
1577 {
1578 handle->debug_print("wt588e02b: cs gpio deinit failed.\n"); /* cs gpio deinit failed */
1579
1580 return 1; /* return error */
1581 }
1582 handle->inited = 0; /* flag closed */
1583
1584 return 0; /* success return 0 */
1585}
1586
1600uint8_t wt588e02b_set_reg(wt588e02b_handle_t *handle, uint8_t *buf, uint16_t len, uint32_t us)
1601{
1602 uint8_t res;
1603 uint16_t i;
1604
1605 if (handle == NULL) /* check handle */
1606 {
1607 return 2; /* return error */
1608 }
1609 if (handle->inited != 1) /* check handle initialization */
1610 {
1611 return 3; /* return error */
1612 }
1613
1614 res = handle->sclk_gpio_write(0); /* set sclk low */
1615 if (res != 0) /* check result */
1616 {
1617 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
1618
1619 return 1; /* return error */
1620 }
1621 res = handle->cs_gpio_write(0); /* set cs low */
1622 if (res != 0) /* check result */
1623 {
1624 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
1625
1626 return 1; /* return error */
1627 }
1628 for (i = 0; i < len; i++) /* write all */
1629 {
1630 handle->delay_ms(5); /* delay 5ms */
1631 res = a_wt588e02b_write_with_no_cs(handle, us, buf[i]); /* write command */
1632 if (res != 0) /* check result */
1633 {
1634 handle->debug_print("wt588e02b: write with no cs failed.\n"); /* write with no cs failed */
1635
1636 return 1; /* return error */
1637 }
1638 }
1639 res = handle->cs_gpio_write(1); /* set cs high */
1640 if (res != 0) /* check result */
1641 {
1642 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
1643
1644 return 1; /* return error */
1645 }
1646
1647 return 0; /* success return 0 */
1648}
1649
1663uint8_t wt588e02b_get_reg(wt588e02b_handle_t *handle, uint8_t *buf, uint16_t len, uint32_t us)
1664{
1665 uint8_t res;
1666 uint16_t i;
1667
1668 if (handle == NULL) /* check handle */
1669 {
1670 return 2; /* return error */
1671 }
1672 if (handle->inited != 1) /* check handle initialization */
1673 {
1674 return 3; /* return error */
1675 }
1676
1677 res = handle->sclk_gpio_write(0); /* set sclk low */
1678 if (res != 0) /* check result */
1679 {
1680 handle->debug_print("wt588e02b: sclk gpio write failed.\n"); /* sclk gpio write failed */
1681
1682 return 1; /* return error */
1683 }
1684 res = handle->cs_gpio_write(0); /* set cs low */
1685 if (res != 0) /* check result */
1686 {
1687 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
1688
1689 return 1; /* return error */
1690 }
1691 for (i = 0; i < len; i++) /* write all */
1692 {
1693 handle->delay_ms(5); /* delay 5ms */
1694 res = a_wt588e02b_read_with_no_cs(handle, us, &buf[i]); /* read data */
1695 if (res != 0) /* check result */
1696 {
1697 handle->debug_print("wt588e02b: read with no cs failed.\n"); /* read with no cs failed */
1698
1699 return 1; /* return error */
1700 }
1701 }
1702 res = handle->cs_gpio_write(1); /* set cs high */
1703 if (res != 0) /* check result */
1704 {
1705 handle->debug_print("wt588e02b: cs gpio write failed.\n"); /* cs gpio write failed */
1706
1707 return 1; /* return error */
1708 }
1709
1710 return 0; /* success return 0 */
1711}
1712
1722{
1723 if (info == NULL) /* check handle */
1724 {
1725 return 2; /* return error */
1726 }
1727
1728 memset(info, 0, sizeof(wt588e02b_info_t)); /* initialize wt588e02b info structure */
1729 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1730 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1731 strncpy(info->interface, "SPI", 8); /* copy interface name */
1732 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1733 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1734 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1735 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1736 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1737 info->driver_version = DRIVER_VERSION; /* set driver version */
1738
1739 return 0; /* success return 0 */
1740}
#define WT588E02B_COMMAND_UPDATE_ADDR
#define MAX_CURRENT
#define WT588E02B_COMMAND_PLAY_LOOP
#define WT588E02B_COMMAND_PLAY_LIST
#define WT588E02B_COMMAND_PLAY
chip command definition
#define SUPPLY_VOLTAGE_MAX
#define WT588E02B_COMMAND_UPDATE_STATUS
#define WT588E02B_COMMAND_UPDATE_ALL
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define WT588E02B_COMMAND_STOP
#define WT588E02B_COMMAND_UPDATE_END
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define WT588E02B_COMMAND_VOL
driver wt588e02b header file
struct wt588e02b_info_s wt588e02b_info_t
wt588e02b information structure definition
uint8_t wt588e02b_update(wt588e02b_handle_t *handle, uint8_t ind, char *path)
update audio
struct wt588e02b_handle_s wt588e02b_handle_t
wt588e02b handle structure definition
uint8_t wt588e02b_play(wt588e02b_handle_t *handle, uint8_t ind)
play audio
uint8_t wt588e02b_play_loop(wt588e02b_handle_t *handle, uint8_t ind)
play loop
uint8_t wt588e02b_info(wt588e02b_info_t *info)
get chip's information
uint8_t wt588e02b_deinit(wt588e02b_handle_t *handle)
deinit the chip
uint8_t wt588e02b_check_busy(wt588e02b_handle_t *handle, wt588e02b_bool_t *enable)
check chip busy
uint8_t wt588e02b_play_loop_advance(wt588e02b_handle_t *handle, uint8_t ind)
play loop advance
wt588e02b_bool_t
wt588e02b bool enumeration definition
uint8_t wt588e02b_set_vol(wt588e02b_handle_t *handle, uint8_t vol)
set the volume
uint8_t wt588e02b_init(wt588e02b_handle_t *handle)
initialize the chip
uint8_t wt588e02b_play_loop_all(wt588e02b_handle_t *handle)
play loop all
uint8_t wt588e02b_play_list(wt588e02b_handle_t *handle, uint8_t *list, uint8_t len)
play list
uint8_t wt588e02b_update_all(wt588e02b_handle_t *handle, char *path)
update all audio
uint8_t wt588e02b_stop(wt588e02b_handle_t *handle)
stop audio
@ WT588E02B_BOOL_FALSE
@ WT588E02B_BOOL_TRUE
uint8_t wt588e02b_get_reg(wt588e02b_handle_t *handle, uint8_t *buf, uint16_t len, uint32_t us)
get the chip register
uint8_t wt588e02b_set_reg(wt588e02b_handle_t *handle, uint8_t *buf, uint16_t len, uint32_t us)
set the chip register
uint8_t(* mosi_gpio_write)(uint8_t data)
uint8_t(* mosi_gpio_deinit)(void)
uint8_t(* mosi_gpio_init)(void)
uint8_t(* miso_gpio_read)(uint8_t *data)
void(* delay_ms)(uint32_t ms)
uint8_t(* sclk_gpio_deinit)(void)
uint8_t(* bin_read_init)(char *name, uint32_t *size)
uint8_t(* cs_gpio_deinit)(void)
uint8_t(* cs_gpio_write)(uint8_t data)
uint8_t(* sclk_gpio_write)(uint8_t data)
void(* debug_print)(const char *const fmt,...)
uint8_t(* bin_read)(uint32_t addr, uint16_t size, uint8_t *buffer)
void(* delay_us)(uint32_t us)
uint8_t(* cs_gpio_init)(void)
uint8_t(* sclk_gpio_init)(void)
uint8_t(* miso_gpio_init)(void)
uint8_t(* bin_read_deinit)(void)
uint8_t(* miso_gpio_deinit)(void)