LibDriver VS1053B
Loading...
Searching...
No Matches
driver_vs1053b.c
Go to the documentation of this file.
1
36
37#include "driver_vs1053b.h"
38
39#if VS1053B_OGG_VENC08K1Q00 != 0
41#endif
42#if VS1053B_OGG_VENC08K1Q01 != 0
44#endif
45#if VS1053B_OGG_VENC08K1Q02 != 0
47#endif
48#if VS1053B_OGG_VENC08K1Q03 != 0
50#endif
51#if VS1053B_OGG_VENC08K1Q04 != 0
53#endif
54#if VS1053B_OGG_VENC08K1Q05 != 0
56#endif
57#if VS1053B_OGG_VENC08K1Q06 != 0
59#endif
60#if VS1053B_OGG_VENC08K1Q07 != 0
62#endif
63#if VS1053B_OGG_VENC08K1Q08 != 0
65#endif
66#if VS1053B_OGG_VENC08K1Q09 != 0
68#endif
69#if VS1053B_OGG_VENC08K1Q10 != 0
71#endif
72#if VS1053B_OGG_VENC16K1Q00 != 0
74#endif
75#if VS1053B_OGG_VENC16K1Q01 != 0
77#endif
78#if VS1053B_OGG_VENC16K1Q02 != 0
80#endif
81#if VS1053B_OGG_VENC16K1Q03 != 0
83#endif
84#if VS1053B_OGG_VENC16K1Q04 != 0
86#endif
87#if VS1053B_OGG_VENC16K1Q05 != 0
89#endif
90#if VS1053B_OGG_VENC16K1Q06 != 0
92#endif
93#if VS1053B_OGG_VENC16K1Q07 != 0
95#endif
96#if VS1053B_OGG_VENC16K1Q08 != 0
98#endif
99#if VS1053B_OGG_VENC16K1Q09 != 0
101#endif
102#if VS1053B_OGG_VENC16K1Q10 != 0
104#endif
105#if VS1053B_OGG_VENC16K2Q00 != 0
107#endif
108#if VS1053B_OGG_VENC16K2Q01 != 0
110#endif
111#if VS1053B_OGG_VENC16K2Q02 != 0
113#endif
114#if VS1053B_OGG_VENC16K2Q03 != 0
116#endif
117#if VS1053B_OGG_VENC16K2Q04 != 0
119#endif
120#if VS1053B_OGG_VENC16K2Q05 != 0
122#endif
123#if VS1053B_OGG_VENC16K2Q06 != 0
125#endif
126#if VS1053B_OGG_VENC16K2Q07 != 0
128#endif
129#if VS1053B_OGG_VENC16K2Q08 != 0
131#endif
132#if VS1053B_OGG_VENC16K2Q09 != 0
134#endif
135#if VS1053B_OGG_VENC16K2Q10 != 0
137#endif
138#if VS1053B_OGG_VENC44K1Q00 != 0
140#endif
141#if VS1053B_OGG_VENC44K1Q01 != 0
143#endif
144#if VS1053B_OGG_VENC44K1Q02 != 0
146#endif
147#if VS1053B_OGG_VENC44K1Q03 != 0
149#endif
150#if VS1053B_OGG_VENC44K1Q04 != 0
152#endif
153#if VS1053B_OGG_VENC44K1Q05 != 0
155#endif
156#if VS1053B_OGG_VENC44K2Q00 != 0
158#endif
159#if VS1053B_OGG_VENC44K2Q01 != 0
161#endif
162#if VS1053B_OGG_VENC44K2Q02 != 0
164#endif
165#if VS1053B_OGG_VENC44K2Q03 != 0
167#endif
168#if VS1053B_OGG_VENC44K2Q04 != 0
170#endif
171#if VS1053B_OGG_VENC44K2Q05 != 0
173#endif
176#include <math.h>
177
181#define CHIP_NAME "VLSI VS1053B"
182#define MANUFACTURER_NAME "VLSI"
183#define SUPPLY_VOLTAGE_MIN 2.6f
184#define SUPPLY_VOLTAGE_MAX 3.6f
185#define MAX_CURRENT 60.0f
186#define TEMPERATURE_MIN -40.0f
187#define TEMPERATURE_MAX 85.0f
188#define DRIVER_VERSION 1000
189
193#define VS1053B_COMMAND_READ 0x03
194#define VS1053B_COMMAND_WRITE 0x02
195
199#define VS1053B_REG_MODE 0x00
200#define VS1053B_REG_STATUS 0x01
201#define VS1053B_REG_BASS 0x02
202#define VS1053B_REG_CLOCKF 0x03
203#define VS1053B_REG_DECODE_TIME 0x04
204#define VS1053B_REG_AUDATA 0x05
205#define VS1053B_REG_WRAM 0x06
206#define VS1053B_REG_WRAMADDR 0x07
207#define VS1053B_REG_HDAT0 0x08
208#define VS1053B_REG_HDAT1 0x09
209#define VS1053B_REG_AIADDR 0x0A
210#define VS1053B_REG_VOL 0x0B
211#define VS1053B_REG_AICTRL0 0x0C
212#define VS1053B_REG_AICTRL1 0x0D
213#define VS1053B_REG_AICTRL2 0x0E
214#define VS1053B_REG_AICTRL3 0x0F
215
219#define VS1053B_STATUS_STOP 0x00
220#define VS1053B_STATUS_PLAY 0x01
221#define VS1053B_STATUS_RECORD 0x02
222
226#define MIN(a, b) (((a) < (b)) ? (a) : (b))
227
239static uint8_t a_vs1053b_spi_read(vs1053b_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
240{
241 if (handle->spi_cmd_read_address16(((uint16_t)(VS1053B_COMMAND_READ) << 8) | reg, buf, len) != 0) /* spi read */
242 {
243 return 1; /* return error */
244 }
245 else
246 {
247 return 0; /* success return 0 */
248 }
249}
250
262static uint8_t a_vs1053b_spi_write(vs1053b_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
263{
264 if (handle->spi_cmd_write_address16(((uint16_t)(VS1053B_COMMAND_WRITE) << 8) | reg, buf, len) != 0) /* spi write */
265 {
266 return 1; /* return error */
267 }
268 else
269 {
270 return 0; /* success return 0 */
271 }
272}
273
284static uint8_t a_vs1053b_spi_write_data(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
285{
286 if (handle->spi_dat_write_cmd(buf, len) != 0) /* spi write */
287 {
288 return 1; /* return error */
289 }
290 else
291 {
292 return 0; /* success return 0 */
293 }
294}
295
305static uint8_t a_check_busy_pin(vs1053b_handle_t *handle)
306{
307 uint16_t i;
308 uint8_t dat;
309
310 for (i = 0; i < 1000; i++) /* up to 1000ms */
311 {
312 if (handle->dreq_gpio_read(&dat) != 0) /* read failed */
313 {
314 return 2; /* return error */
315 }
316 if (dat != 0) /* if high */
317 {
318 break; /* break */
319 }
320
321 handle->delay_ms(1); /* delay 1ms */
322 }
323
324 if (i < 1000) /* check up to 1000ms */
325 {
326 return 0; /* success return 0 */
327 }
328 else
329 {
330 return 1; /* return error */
331 }
332}
333
342static uint8_t a_vs1053b_stop(vs1053b_handle_t *handle)
343{
344 uint8_t res;
345 uint8_t dat0;
346 uint8_t dat1;
347 uint8_t buf[2];
348 uint8_t buf_init[32];
349 uint16_t i;
350 uint16_t prev;
351
352 if (a_check_busy_pin(handle) != 0) /* check busy */
353 {
354 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
355
356 return 1; /* return error */
357 }
358 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
359 if (res != 0) /* check result */
360 {
361 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
362
363 return 1; /* return error */
364 }
365 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
366 prev &= ~(1 << 3); /* clear the settings */
367 prev |= 1 << 3; /* set the config */
368 buf[0] = (prev >> 8) & 0xFF; /* get msb */
369 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
370 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
371 if (res != 0) /* check result */
372 {
373 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
374
375 return 1; /* return error */
376 }
377
378 memset(buf_init, 0, sizeof(uint8_t) * 32); /* init */
379 for (i = 0; i < 64; i++) /* 64 times */
380 {
381 if (handle->spi_dat_write_cmd(buf_init, 32) != 0) /* push data */
382 {
383 handle->debug_print("vs1053b: fill buffer failed.\n"); /* fill buffer failed */
384
385 return 1; /* return error */
386 }
387 if (a_check_busy_pin(handle) != 0) /* check busy */
388 {
389 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
390
391 return 1; /* return error */
392 }
393 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
394 if (res != 0) /* check result */
395 {
396 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
397
398 return 1; /* return error */
399 }
400 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
401 if ((prev & (1 << 3)) == 0) /* check cancel bit */
402 {
403 break; /* break */
404 }
405 }
406 if (i >= 64) /* check times */
407 {
408 handle->debug_print("vs1053b: cancel bit is invalid.\n"); /* cancel bit is invalid */
409
410 return 1; /* return error */
411 }
412
413 for (i = 0; i < 65; i++) /* 65 times */
414 {
415 if (a_check_busy_pin(handle) != 0) /* check busy */
416 {
417 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
418
419 return 1; /* return error */
420 }
421 prev = 0x1E06; /* set addr */
422 buf[0] = (prev >> 8) & 0xFF; /* get msb */
423 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
424 res = a_vs1053b_spi_write(handle,
425 VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
426 if (res != 0) /* check result */
427 {
428 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
429
430 return 1; /* return error */
431 }
432 if (a_check_busy_pin(handle) != 0) /* check busy */
433 {
434 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
435
436 return 1; /* return error */
437 }
438 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
439 if (res != 0) /* check result */
440 {
441 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
442
443 return 1; /* return error */
444 }
445 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
446 memset(buf_init, prev & 0xFF, sizeof(uint8_t) * 32); /* init */
447 if (handle->spi_dat_write_cmd(buf_init, 32) != 0) /* push data */
448 {
449 handle->debug_print("vs1053b: fill buffer failed.\n"); /* fill buffer failed */
450
451 return 1; /* return error */
452 }
453 }
454
455 if (a_check_busy_pin(handle) != 0) /* check busy */
456 {
457 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
458
459 return 1; /* return error */
460 }
461 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
462 if (res != 0) /* check result */
463 {
464 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
465
466 return 1; /* return error */
467 }
468 dat0 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
469 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
470 if (res != 0) /* check result */
471 {
472 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
473
474 return 1; /* return error */
475 }
476 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
477 if ((dat0 != 0) || (dat1 != 0)) /* check dat0 */
478 {
479 handle->debug_print("vs1053b: dat0 and dat1 ara invalid.\n"); /* dat0 and dat1 ara invalid */
480
481 return 1; /* return error */
482 }
483
484 return 0; /* success return 0 */
485}
486
492static void a_period(vs1053b_handle_t *handle)
493{
494 if (handle->period_enable != 0) /* if enable */
495 {
496 uint32_t sec;
497 uint32_t us;
498 uint64_t current_time;
499
500 handle->timestamp_read(&sec, &us); /* read timestamp */
501 current_time = (((uint64_t)sec) * 1000000 + ((uint64_t)us)); /* create timestamp */
502 if (current_time - handle->timestamp >= handle->period) /* check period */
503 {
504 if (handle->receive_callback != NULL) /* if not null */
505 {
506 handle->receive_callback(VS1053B_TYPE_PERIOD, handle->cur_pos); /* run the callback */
507 }
508 handle->timestamp = current_time; /* save the current timestamp */
509 }
510 }
511}
512
522static uint8_t a_vs1053b_write_wav_header(vs1053b_handle_t *handle, vs1053b_wav_t *wav)
523{
524 uint8_t res;
525 uint8_t buf[44];
526
527 buf[0] = handle->wav.chunk_id[0]; /* R */
528 buf[1] = handle->wav.chunk_id[1]; /* I */
529 buf[2] = handle->wav.chunk_id[2]; /* F */
530 buf[3] = handle->wav.chunk_id[3]; /* F */
531 buf[4] = (handle->wav.chunk_size >> 0) & 0xFF; /* set chunk size */
532 buf[5] = (handle->wav.chunk_size >> 8) & 0xFF; /* set chunk size */
533 buf[6] = (handle->wav.chunk_size >> 16) & 0xFF; /* set chunk size */
534 buf[7] = (handle->wav.chunk_size >> 24) & 0xFF; /* set chunk size */
535 buf[8] = handle->wav.format[0]; /* W */
536 buf[9] = handle->wav.format[1]; /* A */
537 buf[10] = handle->wav.format[2]; /* V */
538 buf[11] = handle->wav.format[3]; /* E */
539 buf[12] = handle->wav.sub_chunk1_id[0]; /* f */
540 buf[13] = handle->wav.sub_chunk1_id[1]; /* m */
541 buf[14] = handle->wav.sub_chunk1_id[2]; /* t */
542 buf[15] = handle->wav.sub_chunk1_id[3]; /* 0x00 */
543 buf[16] = (handle->wav.sub_chunk1_size >> 0) & 0xFF; /* 16 bytes */
544 buf[17] = (handle->wav.sub_chunk1_size >> 8) & 0xFF; /* 16 bytes */
545 buf[18] = (handle->wav.sub_chunk1_size >> 16) & 0xFF; /* 16 bytes */
546 buf[19] = (handle->wav.sub_chunk1_size >> 24) & 0xFF; /* 16 bytes */
547 buf[20] = (handle->wav.audio_format >> 0) & 0xFF; /* pcm */
548 buf[21] = (handle->wav.audio_format >> 8) & 0xFF; /* pcm */
549 buf[22] = (handle->wav.num_channel >> 0) & 0xFF; /* 1 channel */
550 buf[23] = (handle->wav.num_channel >> 8) & 0xFF; /* 1 channel */
551 buf[24] = (handle->wav.sample_rate >> 0) & 0xFF; /* set sample rate */
552 buf[25] = (handle->wav.sample_rate >> 8) & 0xFF; /* set sample rate */
553 buf[26] = (handle->wav.sample_rate >> 16) & 0xFF; /* set sample rate */
554 buf[27] = (handle->wav.sample_rate >> 24) & 0xFF; /* set sample rate */
555 buf[28] = (handle->wav.byte_rate >> 0) & 0xFF; /* double */
556 buf[29] = (handle->wav.byte_rate >> 8) & 0xFF; /* double */
557 buf[30] = (handle->wav.byte_rate >> 16) & 0xFF; /* double */
558 buf[31] = (handle->wav.byte_rate >> 24) & 0xFF; /* double */
559 buf[32] = (handle->wav.block_align >> 0) & 0xFF; /* 2 bytes */
560 buf[33] = (handle->wav.block_align >> 8) & 0xFF; /* 2 bytes */
561 buf[34] = (handle->wav.bit_per_sample >> 0) & 0xFF; /* 16 bits */
562 buf[35] = (handle->wav.bit_per_sample >> 8) & 0xFF; /* 16 bits */
563 buf[36] = handle->wav.sub_chunk2_id[0]; /* d */
564 buf[37] = handle->wav.sub_chunk2_id[1]; /* a */
565 buf[38] = handle->wav.sub_chunk2_id[2]; /* t */
566 buf[39] = handle->wav.sub_chunk2_id[3]; /* a */
567 buf[40] = (handle->wav.sub_chunk2_size >> 0) & 0xFF; /* init 0 */
568 buf[41] = (handle->wav.sub_chunk2_size >> 8) & 0xFF; /* init 0 */
569 buf[42] = (handle->wav.sub_chunk2_size >> 16) & 0xFF; /* init 0 */
570 buf[43] = (handle->wav.sub_chunk2_size >> 24) & 0xFF; /* init 0 */
571 res = handle->audio_write(0, 44, buf); /* write buffer */
572 if (res != 0) /* check result */
573 {
574 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
575
576 return 1; /* return error */
577 }
578
579 return 0; /* success return 0 */
580}
581
594{
595 uint8_t res;
596 uint8_t buf[2];
597 uint16_t prev;
598
599 if (handle == NULL) /* check handle */
600 {
601 return 2; /* return error */
602 }
603 if (handle->inited != 1) /* check handle initialization */
604 {
605 return 3; /* return error */
606 }
607 if (a_check_busy_pin(handle) != 0) /* check busy */
608 {
609 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
610
611 return 1; /* return error */
612 }
613
614 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
615 if (res != 0) /* check result */
616 {
617 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
618
619 return 1; /* return error */
620 }
621 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
622 prev &= ~(1 << 0); /* clear the settings */
623 prev |= diff << 0; /* set the config */
624 buf[0] = (prev >> 8) & 0xFF; /* get msb */
625 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
626 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
627 if (res != 0) /* check result */
628 {
629 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
630
631 return 1; /* return error */
632 }
633
634 return 0; /* success return 0 */
635}
636
649{
650 uint8_t res;
651 uint8_t buf[2];
652 uint16_t prev;
653
654 if (handle == NULL) /* check handle */
655 {
656 return 2; /* return error */
657 }
658 if (handle->inited != 1) /* check handle initialization */
659 {
660 return 3; /* return error */
661 }
662 if (a_check_busy_pin(handle) != 0) /* check busy */
663 {
664 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
665
666 return 1; /* return error */
667 }
668
669 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
670 if (res != 0) /* check result */
671 {
672 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
673
674 return 1; /* return error */
675 }
676 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
677 *diff = (vs1053b_diff_t)((prev >> 0) & 0x01); /* get the diff */
678
679 return 0; /* success return 0 */
680}
681
694{
695 uint8_t res;
696 uint8_t buf[2];
697 uint16_t prev;
698
699 if (handle == NULL) /* check handle */
700 {
701 return 2; /* return error */
702 }
703 if (handle->inited != 1) /* check handle initialization */
704 {
705 return 3; /* return error */
706 }
707 if (a_check_busy_pin(handle) != 0) /* check busy */
708 {
709 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
710
711 return 1; /* return error */
712 }
713
714 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
715 if (res != 0) /* check result */
716 {
717 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
718
719 return 1; /* return error */
720 }
721 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
722 prev &= ~(1 << 1); /* clear the settings */
723 prev |= enable << 1; /* set the config */
724 buf[0] = (prev >> 8) & 0xFF; /* get msb */
725 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
726 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
727 if (res != 0) /* check result */
728 {
729 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
730
731 return 1; /* return error */
732 }
733
734 return 0; /* success return 0 */
735}
736
749{
750 uint8_t res;
751 uint8_t buf[2];
752 uint16_t prev;
753
754 if (handle == NULL) /* check handle */
755 {
756 return 2; /* return error */
757 }
758 if (handle->inited != 1) /* check handle initialization */
759 {
760 return 3; /* return error */
761 }
762 if (a_check_busy_pin(handle) != 0) /* check busy */
763 {
764 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
765
766 return 1; /* return error */
767 }
768
769 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
770 if (res != 0) /* check result */
771 {
772 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
773
774 return 1; /* return error */
775 }
776 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
777 *enable = (vs1053b_bool_t)((prev >> 1) & 0x01); /* get the bool */
778
779 return 0; /* success return 0 */
780}
781
794{
795 uint8_t res;
796 uint8_t buf[2];
797 uint16_t prev;
798
799 if (handle == NULL) /* check handle */
800 {
801 return 2; /* return error */
802 }
803 if (handle->inited != 1) /* check handle initialization */
804 {
805 return 3; /* return error */
806 }
807 if (a_check_busy_pin(handle) != 0) /* check busy */
808 {
809 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
810
811 return 1; /* return error */
812 }
813
814 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
815 if (res != 0) /* check result */
816 {
817 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
818
819 return 1; /* return error */
820 }
821 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
822 prev &= ~(1 << 2); /* clear the settings */
823 prev |= enable << 2; /* set the config */
824 buf[0] = (prev >> 8) & 0xFF; /* get msb */
825 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
826 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
827 if (res != 0) /* check result */
828 {
829 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
830
831 return 1; /* return error */
832 }
833 handle->delay_ms(2); /* delay 2ms */
834
835 return 0; /* success return 0 */
836}
837
850{
851 uint8_t res;
852 uint8_t buf[2];
853 uint16_t prev;
854
855 if (handle == NULL) /* check handle */
856 {
857 return 2; /* return error */
858 }
859 if (handle->inited != 1) /* check handle initialization */
860 {
861 return 3; /* return error */
862 }
863 if (a_check_busy_pin(handle) != 0) /* check busy */
864 {
865 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
866
867 return 1; /* return error */
868 }
869
870 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
871 if (res != 0) /* check result */
872 {
873 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
874
875 return 1; /* return error */
876 }
877 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
878 *enable = (vs1053b_bool_t)((prev >> 2) & 0x01); /* get the bool */
879
880 return 0; /* success return 0 */
881}
882
895{
896 uint8_t res;
897 uint8_t buf[2];
898 uint16_t prev;
899
900 if (handle == NULL) /* check handle */
901 {
902 return 2; /* return error */
903 }
904 if (handle->inited != 1) /* check handle initialization */
905 {
906 return 3; /* return error */
907 }
908 if (a_check_busy_pin(handle) != 0) /* check busy */
909 {
910 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
911
912 return 1; /* return error */
913 }
914
915 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
916 if (res != 0) /* check result */
917 {
918 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
919
920 return 1; /* return error */
921 }
922 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
923 prev &= ~(1 << 3); /* clear the settings */
924 prev |= enable << 3; /* set the config */
925 buf[0] = (prev >> 8) & 0xFF; /* get msb */
926 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
927 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
928 if (res != 0) /* check result */
929 {
930 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
931
932 return 1; /* return error */
933 }
934
935 return 0; /* success return 0 */
936}
937
950{
951 uint8_t res;
952 uint8_t buf[2];
953 uint16_t prev;
954
955 if (handle == NULL) /* check handle */
956 {
957 return 2; /* return error */
958 }
959 if (handle->inited != 1) /* check handle initialization */
960 {
961 return 3; /* return error */
962 }
963 if (a_check_busy_pin(handle) != 0) /* check busy */
964 {
965 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
966
967 return 1; /* return error */
968 }
969
970 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
971 if (res != 0) /* check result */
972 {
973 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
974
975 return 1; /* return error */
976 }
977 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
978 *enable = (vs1053b_bool_t)((prev >> 3) & 0x01); /* get the bool */
979
980 return 0; /* success return 0 */
981}
982
995{
996 uint8_t res;
997 uint8_t buf[2];
998 uint16_t prev;
999
1000 if (handle == NULL) /* check handle */
1001 {
1002 return 2; /* return error */
1003 }
1004 if (handle->inited != 1) /* check handle initialization */
1005 {
1006 return 3; /* return error */
1007 }
1008 if (a_check_busy_pin(handle) != 0) /* check busy */
1009 {
1010 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1011
1012 return 1; /* return error */
1013 }
1014
1015 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1016 if (res != 0) /* check result */
1017 {
1018 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1019
1020 return 1; /* return error */
1021 }
1022 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1023 prev &= ~(1 << 4); /* clear the settings */
1024 prev |= enable << 4; /* set the config */
1025 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1026 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1027 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1028 if (res != 0) /* check result */
1029 {
1030 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1031
1032 return 1; /* return error */
1033 }
1034
1035 return 0; /* success return 0 */
1036}
1037
1050{
1051 uint8_t res;
1052 uint8_t buf[2];
1053 uint16_t prev;
1054
1055 if (handle == NULL) /* check handle */
1056 {
1057 return 2; /* return error */
1058 }
1059 if (handle->inited != 1) /* check handle initialization */
1060 {
1061 return 3; /* return error */
1062 }
1063 if (a_check_busy_pin(handle) != 0) /* check busy */
1064 {
1065 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1066
1067 return 1; /* return error */
1068 }
1069
1070 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1071 if (res != 0) /* check result */
1072 {
1073 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1074
1075 return 1; /* return error */
1076 }
1077 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1078 *enable = (vs1053b_bool_t)((prev >> 4) & 0x01); /* get the bool */
1079
1080 return 0; /* success return 0 */
1081}
1082
1095{
1096 uint8_t res;
1097 uint8_t buf[2];
1098 uint16_t prev;
1099
1100 if (handle == NULL) /* check handle */
1101 {
1102 return 2; /* return error */
1103 }
1104 if (handle->inited != 1) /* check handle initialization */
1105 {
1106 return 3; /* return error */
1107 }
1108 if (a_check_busy_pin(handle) != 0) /* check busy */
1109 {
1110 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1111
1112 return 1; /* return error */
1113 }
1114
1115 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1116 if (res != 0) /* check result */
1117 {
1118 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1119
1120 return 1; /* return error */
1121 }
1122 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1123 prev &= ~(1 << 5); /* clear the settings */
1124 prev |= enable << 5; /* set the config */
1125 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1126 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1127 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1128 if (res != 0) /* check result */
1129 {
1130 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1131
1132 return 1; /* return error */
1133 }
1134
1135 return 0; /* success return 0 */
1136}
1137
1150{
1151 uint8_t res;
1152 uint8_t buf[2];
1153 uint16_t prev;
1154
1155 if (handle == NULL) /* check handle */
1156 {
1157 return 2; /* return error */
1158 }
1159 if (handle->inited != 1) /* check handle initialization */
1160 {
1161 return 3; /* return error */
1162 }
1163 if (a_check_busy_pin(handle) != 0) /* check busy */
1164 {
1165 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1166
1167 return 1; /* return error */
1168 }
1169
1170 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1171 if (res != 0) /* check result */
1172 {
1173 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1174
1175 return 1; /* return error */
1176 }
1177 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1178 *enable = (vs1053b_bool_t)((prev >> 5) & 0x01); /* get the bool */
1179
1180 return 0; /* success return 0 */
1181}
1182
1195{
1196 uint8_t res;
1197 uint8_t buf[2];
1198 uint16_t prev;
1199
1200 if (handle == NULL) /* check handle */
1201 {
1202 return 2; /* return error */
1203 }
1204 if (handle->inited != 1) /* check handle initialization */
1205 {
1206 return 3; /* return error */
1207 }
1208 if (a_check_busy_pin(handle) != 0) /* check busy */
1209 {
1210 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1211
1212 return 1; /* return error */
1213 }
1214
1215 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1216 if (res != 0) /* check result */
1217 {
1218 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1219
1220 return 1; /* return error */
1221 }
1222 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1223 prev &= ~(1 << 6); /* clear the settings */
1224 prev |= enable << 6; /* set the config */
1225 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1226 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1227 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1228 if (res != 0) /* check result */
1229 {
1230 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1231
1232 return 1; /* return error */
1233 }
1234
1235 return 0; /* success return 0 */
1236}
1237
1250{
1251 uint8_t res;
1252 uint8_t buf[2];
1253 uint16_t prev;
1254
1255 if (handle == NULL) /* check handle */
1256 {
1257 return 2; /* return error */
1258 }
1259 if (handle->inited != 1) /* check handle initialization */
1260 {
1261 return 3; /* return error */
1262 }
1263 if (a_check_busy_pin(handle) != 0) /* check busy */
1264 {
1265 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1266
1267 return 1; /* return error */
1268 }
1269
1270 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1271 if (res != 0) /* check result */
1272 {
1273 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1274
1275 return 1; /* return error */
1276 }
1277 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1278 *enable = (vs1053b_bool_t)((prev >> 6) & 0x01); /* get the bool */
1279
1280 return 0; /* success return 0 */
1281}
1282
1295{
1296 uint8_t res;
1297 uint8_t buf[2];
1298 uint16_t prev;
1299
1300 if (handle == NULL) /* check handle */
1301 {
1302 return 2; /* return error */
1303 }
1304 if (handle->inited != 1) /* check handle initialization */
1305 {
1306 return 3; /* return error */
1307 }
1308 if (a_check_busy_pin(handle) != 0) /* check busy */
1309 {
1310 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1311
1312 return 1; /* return error */
1313 }
1314
1315 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1316 if (res != 0) /* check result */
1317 {
1318 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1319
1320 return 1; /* return error */
1321 }
1322 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1323 prev &= ~(1 << 7); /* clear the settings */
1324 prev |= enable << 7; /* set the config */
1325 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1326 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1327 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1328 if (res != 0) /* check result */
1329 {
1330 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1331
1332 return 1; /* return error */
1333 }
1334
1335 return 0; /* success return 0 */
1336}
1337
1350{
1351 uint8_t res;
1352 uint8_t buf[2];
1353 uint16_t prev;
1354
1355 if (handle == NULL) /* check handle */
1356 {
1357 return 2; /* return error */
1358 }
1359 if (handle->inited != 1) /* check handle initialization */
1360 {
1361 return 3; /* return error */
1362 }
1363 if (a_check_busy_pin(handle) != 0) /* check busy */
1364 {
1365 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1366
1367 return 1; /* return error */
1368 }
1369
1370 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1371 if (res != 0) /* check result */
1372 {
1373 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1374
1375 return 1; /* return error */
1376 }
1377 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1378 *enable = (vs1053b_bool_t)((prev >> 7) & 0x01); /* get the bool */
1379
1380 return 0; /* success return 0 */
1381}
1382
1395{
1396 uint8_t res;
1397 uint8_t buf[2];
1398 uint16_t prev;
1399
1400 if (handle == NULL) /* check handle */
1401 {
1402 return 2; /* return error */
1403 }
1404 if (handle->inited != 1) /* check handle initialization */
1405 {
1406 return 3; /* return error */
1407 }
1408 if (a_check_busy_pin(handle) != 0) /* check busy */
1409 {
1410 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1411
1412 return 1; /* return error */
1413 }
1414
1415 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1416 if (res != 0) /* check result */
1417 {
1418 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1419
1420 return 1; /* return error */
1421 }
1422 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1423 prev &= ~(1 << 8); /* clear the settings */
1424 prev |= edge << 8; /* set the config */
1425 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1426 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1427 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1428 if (res != 0) /* check result */
1429 {
1430 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1431
1432 return 1; /* return error */
1433 }
1434
1435 return 0; /* success return 0 */
1436}
1437
1450{
1451 uint8_t res;
1452 uint8_t buf[2];
1453 uint16_t prev;
1454
1455 if (handle == NULL) /* check handle */
1456 {
1457 return 2; /* return error */
1458 }
1459 if (handle->inited != 1) /* check handle initialization */
1460 {
1461 return 3; /* return error */
1462 }
1463 if (a_check_busy_pin(handle) != 0) /* check busy */
1464 {
1465 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1466
1467 return 1; /* return error */
1468 }
1469
1470 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1471 if (res != 0) /* check result */
1472 {
1473 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1474
1475 return 1; /* return error */
1476 }
1477 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1478 *edge = (vs1053b_dclk_edge_t)((prev >> 8) & 0x01); /* get the edge */
1479
1480 return 0; /* success return 0 */
1481}
1482
1495{
1496 uint8_t res;
1497 uint8_t buf[2];
1498 uint16_t prev;
1499
1500 if (handle == NULL) /* check handle */
1501 {
1502 return 2; /* return error */
1503 }
1504 if (handle->inited != 1) /* check handle initialization */
1505 {
1506 return 3; /* return error */
1507 }
1508 if (a_check_busy_pin(handle) != 0) /* check busy */
1509 {
1510 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1511
1512 return 1; /* return error */
1513 }
1514
1515 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1516 if (res != 0) /* check result */
1517 {
1518 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1519
1520 return 1; /* return error */
1521 }
1522 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1523 prev &= ~(1 << 9); /* clear the settings */
1524 prev |= order << 9; /* set the config */
1525 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1526 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1527 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1528 if (res != 0) /* check result */
1529 {
1530 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1531
1532 return 1; /* return error */
1533 }
1534
1535 return 0; /* success return 0 */
1536}
1537
1550{
1551 uint8_t res;
1552 uint8_t buf[2];
1553 uint16_t prev;
1554
1555 if (handle == NULL) /* check handle */
1556 {
1557 return 2; /* return error */
1558 }
1559 if (handle->inited != 1) /* check handle initialization */
1560 {
1561 return 3; /* return error */
1562 }
1563 if (a_check_busy_pin(handle) != 0) /* check busy */
1564 {
1565 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1566
1567 return 1; /* return error */
1568 }
1569
1570 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1571 if (res != 0) /* check result */
1572 {
1573 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1574
1575 return 1; /* return error */
1576 }
1577 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1578 *order = (vs1053b_bit_order_t)((prev >> 9) & 0x01); /* get the order */
1579
1580 return 0; /* success return 0 */
1581}
1582
1595{
1596 uint8_t res;
1597 uint8_t buf[2];
1598 uint16_t prev;
1599
1600 if (handle == NULL) /* check handle */
1601 {
1602 return 2; /* return error */
1603 }
1604 if (handle->inited != 1) /* check handle initialization */
1605 {
1606 return 3; /* return error */
1607 }
1608 if (a_check_busy_pin(handle) != 0) /* check busy */
1609 {
1610 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1611
1612 return 1; /* return error */
1613 }
1614
1615 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1616 if (res != 0) /* check result */
1617 {
1618 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1619
1620 return 1; /* return error */
1621 }
1622 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1623 prev &= ~(1 << 10); /* clear the settings */
1624 prev |= enable << 10; /* set the config */
1625 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1626 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1627 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1628 if (res != 0) /* check result */
1629 {
1630 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1631
1632 return 1; /* return error */
1633 }
1634
1635 return 0; /* success return 0 */
1636}
1637
1650{
1651 uint8_t res;
1652 uint8_t buf[2];
1653 uint16_t prev;
1654
1655 if (handle == NULL) /* check handle */
1656 {
1657 return 2; /* return error */
1658 }
1659 if (handle->inited != 1) /* check handle initialization */
1660 {
1661 return 3; /* return error */
1662 }
1663 if (a_check_busy_pin(handle) != 0) /* check busy */
1664 {
1665 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1666
1667 return 1; /* return error */
1668 }
1669
1670 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1671 if (res != 0) /* check result */
1672 {
1673 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1674
1675 return 1; /* return error */
1676 }
1677 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1678 *enable = (vs1053b_bool_t)((prev >> 10) & 0x01); /* get the bool */
1679
1680 return 0; /* success return 0 */
1681}
1682
1695{
1696 uint8_t res;
1697 uint8_t buf[2];
1698 uint16_t prev;
1699
1700 if (handle == NULL) /* check handle */
1701 {
1702 return 2; /* return error */
1703 }
1704 if (handle->inited != 1) /* check handle initialization */
1705 {
1706 return 3; /* return error */
1707 }
1708 if (a_check_busy_pin(handle) != 0) /* check busy */
1709 {
1710 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1711
1712 return 1; /* return error */
1713 }
1714
1715 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1716 if (res != 0) /* check result */
1717 {
1718 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1719
1720 return 1; /* return error */
1721 }
1722 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1723 prev &= ~(1 << 11); /* clear the settings */
1724 prev |= enable << 11; /* set the config */
1725 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1726 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1727 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1728 if (res != 0) /* check result */
1729 {
1730 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1731
1732 return 1; /* return error */
1733 }
1734
1735 return 0; /* success return 0 */
1736}
1737
1750{
1751 uint8_t res;
1752 uint8_t buf[2];
1753 uint16_t prev;
1754
1755 if (handle == NULL) /* check handle */
1756 {
1757 return 2; /* return error */
1758 }
1759 if (handle->inited != 1) /* check handle initialization */
1760 {
1761 return 3; /* return error */
1762 }
1763 if (a_check_busy_pin(handle) != 0) /* check busy */
1764 {
1765 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1766
1767 return 1; /* return error */
1768 }
1769
1770 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1771 if (res != 0) /* check result */
1772 {
1773 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1774
1775 return 1; /* return error */
1776 }
1777 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1778 *enable = (vs1053b_bool_t)((prev >> 11) & 0x01); /* get the bool */
1779
1780 return 0; /* success return 0 */
1781}
1782
1795{
1796 uint8_t res;
1797 uint8_t buf[2];
1798 uint16_t prev;
1799
1800 if (handle == NULL) /* check handle */
1801 {
1802 return 2; /* return error */
1803 }
1804 if (handle->inited != 1) /* check handle initialization */
1805 {
1806 return 3; /* return error */
1807 }
1808 if (a_check_busy_pin(handle) != 0) /* check busy */
1809 {
1810 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1811
1812 return 1; /* return error */
1813 }
1814
1815 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1816 if (res != 0) /* check result */
1817 {
1818 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1819
1820 return 1; /* return error */
1821 }
1822 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1823 prev &= ~(1 << 12); /* clear the settings */
1824 prev |= enable << 12; /* set the config */
1825 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1826 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1827 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1828 if (res != 0) /* check result */
1829 {
1830 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1831
1832 return 1; /* return error */
1833 }
1834
1835 return 0; /* success return 0 */
1836}
1837
1850{
1851 uint8_t res;
1852 uint8_t buf[2];
1853 uint16_t prev;
1854
1855 if (handle == NULL) /* check handle */
1856 {
1857 return 2; /* return error */
1858 }
1859 if (handle->inited != 1) /* check handle initialization */
1860 {
1861 return 3; /* return error */
1862 }
1863 if (a_check_busy_pin(handle) != 0) /* check busy */
1864 {
1865 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1866
1867 return 1; /* return error */
1868 }
1869
1870 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1871 if (res != 0) /* check result */
1872 {
1873 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1874
1875 return 1; /* return error */
1876 }
1877 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1878 *enable = (vs1053b_bool_t)((prev >> 12) & 0x01); /* get the bool */
1879
1880 return 0; /* success return 0 */
1881}
1882
1895{
1896 uint8_t res;
1897 uint8_t buf[2];
1898 uint16_t prev;
1899
1900 if (handle == NULL) /* check handle */
1901 {
1902 return 2; /* return error */
1903 }
1904 if (handle->inited != 1) /* check handle initialization */
1905 {
1906 return 3; /* return error */
1907 }
1908 if (a_check_busy_pin(handle) != 0) /* check busy */
1909 {
1910 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1911
1912 return 1; /* return error */
1913 }
1914
1915 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1916 if (res != 0) /* check result */
1917 {
1918 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1919
1920 return 1; /* return error */
1921 }
1922 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1923 prev &= ~(1 << 14); /* clear the settings */
1924 prev |= selector << 14; /* set the config */
1925 buf[0] = (prev >> 8) & 0xFF; /* get msb */
1926 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
1927 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
1928 if (res != 0) /* check result */
1929 {
1930 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
1931
1932 return 1; /* return error */
1933 }
1934
1935 return 0; /* success return 0 */
1936}
1937
1950{
1951 uint8_t res;
1952 uint8_t buf[2];
1953 uint16_t prev;
1954
1955 if (handle == NULL) /* check handle */
1956 {
1957 return 2; /* return error */
1958 }
1959 if (handle->inited != 1) /* check handle initialization */
1960 {
1961 return 3; /* return error */
1962 }
1963 if (a_check_busy_pin(handle) != 0) /* check busy */
1964 {
1965 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
1966
1967 return 1; /* return error */
1968 }
1969
1970 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
1971 if (res != 0) /* check result */
1972 {
1973 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
1974
1975 return 1; /* return error */
1976 }
1977 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
1978 *selector = (vs1053b_selector_t)((prev >> 14) & 0x01); /* get the bool */
1979
1980 return 0; /* success return 0 */
1981}
1982
1995{
1996 uint8_t res;
1997 uint8_t buf[2];
1998 uint16_t prev;
1999
2000 if (handle == NULL) /* check handle */
2001 {
2002 return 2; /* return error */
2003 }
2004 if (handle->inited != 1) /* check handle initialization */
2005 {
2006 return 3; /* return error */
2007 }
2008 if (a_check_busy_pin(handle) != 0) /* check busy */
2009 {
2010 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2011
2012 return 1; /* return error */
2013 }
2014
2015 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
2016 if (res != 0) /* check result */
2017 {
2018 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
2019
2020 return 1; /* return error */
2021 }
2022 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2023 prev &= ~(1 << 15); /* clear the settings */
2024 prev |= range << 15; /* set the config */
2025 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2026 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2027 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
2028 if (res != 0) /* check result */
2029 {
2030 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
2031
2032 return 1; /* return error */
2033 }
2034
2035 return 0; /* success return 0 */
2036}
2037
2050{
2051 uint8_t res;
2052 uint8_t buf[2];
2053 uint16_t prev;
2054
2055 if (handle == NULL) /* check handle */
2056 {
2057 return 2; /* return error */
2058 }
2059 if (handle->inited != 1) /* check handle initialization */
2060 {
2061 return 3; /* return error */
2062 }
2063 if (a_check_busy_pin(handle) != 0) /* check busy */
2064 {
2065 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2066
2067 return 1; /* return error */
2068 }
2069
2070 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
2071 if (res != 0) /* check result */
2072 {
2073 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
2074
2075 return 1; /* return error */
2076 }
2077 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2078 *range = (vs1053b_clock_range_t)((prev >> 15) & 0x01); /* get the bool */
2079
2080 return 0; /* success return 0 */
2081}
2082
2095{
2096 uint8_t res;
2097 uint8_t buf[2];
2098 uint16_t prev;
2099
2100 if (handle == NULL) /* check handle */
2101 {
2102 return 2; /* return error */
2103 }
2104 if (handle->inited != 1) /* check handle initialization */
2105 {
2106 return 3; /* return error */
2107 }
2108 if (a_check_busy_pin(handle) != 0) /* check busy */
2109 {
2110 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2111
2112 return 1; /* return error */
2113 }
2114
2115 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2116 if (res != 0) /* check result */
2117 {
2118 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2119
2120 return 1; /* return error */
2121 }
2122 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2123 prev &= ~(1 << 15); /* clear the settings */
2124 prev |= enable << 15; /* set the config */
2125 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2126 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2127 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2128 if (res != 0) /* check result */
2129 {
2130 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2131
2132 return 1; /* return error */
2133 }
2134
2135 return 0; /* success return 0 */
2136}
2137
2150{
2151 uint8_t res;
2152 uint8_t buf[2];
2153 uint16_t prev;
2154
2155 if (handle == NULL) /* check handle */
2156 {
2157 return 2; /* return error */
2158 }
2159 if (handle->inited != 1) /* check handle initialization */
2160 {
2161 return 3; /* return error */
2162 }
2163 if (a_check_busy_pin(handle) != 0) /* check busy */
2164 {
2165 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2166
2167 return 1; /* return error */
2168 }
2169
2170 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2171 if (res != 0) /* check result */
2172 {
2173 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2174
2175 return 1; /* return error */
2176 }
2177 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2178 *enable = (vs1053b_bool_t)((prev >> 15) & 0x01); /* get the bool */
2179
2180 return 0; /* success return 0 */
2181}
2182
2195uint8_t vs1053b_set_swing(vs1053b_handle_t *handle, uint8_t swing)
2196{
2197 uint8_t res;
2198 uint8_t buf[2];
2199 uint16_t prev;
2200
2201 if (handle == NULL) /* check handle */
2202 {
2203 return 2; /* return error */
2204 }
2205 if (handle->inited != 1) /* check handle initialization */
2206 {
2207 return 3; /* return error */
2208 }
2209 if (swing > 7) /* check swing */
2210 {
2211 handle->debug_print("vs1053b: swing > 7.\n"); /* swing > 7 */
2212
2213 return 4; /* return error */
2214 }
2215 if (a_check_busy_pin(handle) != 0) /* check busy */
2216 {
2217 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2218
2219 return 1; /* return error */
2220 }
2221
2222 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2223 if (res != 0) /* check result */
2224 {
2225 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2226
2227 return 1; /* return error */
2228 }
2229 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2230 prev &= ~(0x07 << 12); /* clear the settings */
2231 prev |= swing << 12; /* set the config */
2232 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2233 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2234 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2235 if (res != 0) /* check result */
2236 {
2237 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2238
2239 return 1; /* return error */
2240 }
2241
2242 return 0; /* success return 0 */
2243}
2244
2256uint8_t vs1053b_get_swing(vs1053b_handle_t *handle, uint8_t *swing)
2257{
2258 uint8_t res;
2259 uint8_t buf[2];
2260 uint16_t prev;
2261
2262 if (handle == NULL) /* check handle */
2263 {
2264 return 2; /* return error */
2265 }
2266 if (handle->inited != 1) /* check handle initialization */
2267 {
2268 return 3; /* return error */
2269 }
2270 if (a_check_busy_pin(handle) != 0) /* check busy */
2271 {
2272 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2273
2274 return 1; /* return error */
2275 }
2276
2277 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2278 if (res != 0) /* check result */
2279 {
2280 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2281
2282 return 1; /* return error */
2283 }
2284 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2285 *swing = (vs1053b_bool_t)((prev >> 12) & 0x07); /* get the swing */
2286
2287 return 0; /* success return 0 */
2288}
2289
2301uint8_t vs1053b_swing_convert_to_register(vs1053b_handle_t *handle, float db, uint8_t *reg)
2302{
2303 if (handle == NULL) /* check handle */
2304 {
2305 return 2; /* return error */
2306 }
2307 if (handle->inited != 1) /* check handle initialization */
2308 {
2309 return 3; /* return error */
2310 }
2311
2312 *reg = (uint8_t)(db / 2.0f); /* convert real data to register data */
2313
2314 return 0; /* success return 0 */
2315}
2316
2328uint8_t vs1053b_swing_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, float *db)
2329{
2330 if (handle == NULL) /* check handle */
2331 {
2332 return 2; /* return error */
2333 }
2334 if (handle->inited != 1) /* check handle initialization */
2335 {
2336 return 3; /* return error */
2337 }
2338
2339 *db = (float)(reg) / 0.5f; /* convert raw data to real data */
2340
2341 return 0; /* success return 0 */
2342}
2343
2356{
2357 uint8_t res;
2358 uint8_t buf[2];
2359 uint16_t prev;
2360
2361 if (handle == NULL) /* check handle */
2362 {
2363 return 2; /* return error */
2364 }
2365 if (handle->inited != 1) /* check handle initialization */
2366 {
2367 return 3; /* return error */
2368 }
2369 if (a_check_busy_pin(handle) != 0) /* check busy */
2370 {
2371 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2372
2373 return 1; /* return error */
2374 }
2375
2376 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2377 if (res != 0) /* check result */
2378 {
2379 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2380
2381 return 1; /* return error */
2382 }
2383 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2384 prev &= ~(1 << 11); /* clear the settings */
2385 prev |= enable << 11; /* set the config */
2386 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2387 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2388 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2389 if (res != 0) /* check result */
2390 {
2391 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2392
2393 return 1; /* return error */
2394 }
2395
2396 return 0; /* success return 0 */
2397}
2398
2411{
2412 uint8_t res;
2413 uint8_t buf[2];
2414 uint16_t prev;
2415
2416 if (handle == NULL) /* check handle */
2417 {
2418 return 2; /* return error */
2419 }
2420 if (handle->inited != 1) /* check handle initialization */
2421 {
2422 return 3; /* return error */
2423 }
2424 if (a_check_busy_pin(handle) != 0) /* check busy */
2425 {
2426 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2427
2428 return 1; /* return error */
2429 }
2430
2431 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2432 if (res != 0) /* check result */
2433 {
2434 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2435
2436 return 1; /* return error */
2437 }
2438 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2439 *enable = (vs1053b_bool_t)((prev >> 11) & 0x01); /* get the bool */
2440
2441 return 0; /* success return 0 */
2442}
2443
2456{
2457 uint8_t res;
2458 uint8_t buf[2];
2459 uint16_t prev;
2460
2461 if (handle == NULL) /* check handle */
2462 {
2463 return 2; /* return error */
2464 }
2465 if (handle->inited != 1) /* check handle initialization */
2466 {
2467 return 3; /* return error */
2468 }
2469 if (a_check_busy_pin(handle) != 0) /* check busy */
2470 {
2471 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2472
2473 return 1; /* return error */
2474 }
2475
2476 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2477 if (res != 0) /* check result */
2478 {
2479 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2480
2481 return 1; /* return error */
2482 }
2483 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2484 prev &= ~(1 << 10); /* clear the settings */
2485 prev |= (!enable) << 10; /* set the config */
2486 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2487 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2488 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2489 if (res != 0) /* check result */
2490 {
2491 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2492
2493 return 1; /* return error */
2494 }
2495
2496 return 0; /* success return 0 */
2497}
2498
2511{
2512 uint8_t res;
2513 uint8_t buf[2];
2514 uint16_t prev;
2515
2516 if (handle == NULL) /* check handle */
2517 {
2518 return 2; /* return error */
2519 }
2520 if (handle->inited != 1) /* check handle initialization */
2521 {
2522 return 3; /* return error */
2523 }
2524 if (a_check_busy_pin(handle) != 0) /* check busy */
2525 {
2526 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2527
2528 return 1; /* return error */
2529 }
2530
2531 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2532 if (res != 0) /* check result */
2533 {
2534 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2535
2536 return 1; /* return error */
2537 }
2538 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2539 *enable = (vs1053b_bool_t)(!((prev >> 10) & 0x01)); /* get the bool */
2540
2541 return 0; /* success return 0 */
2542}
2543
2555uint8_t vs1053b_get_version(vs1053b_handle_t *handle, uint8_t *version)
2556{
2557 uint8_t res;
2558 uint8_t buf[2];
2559 uint16_t prev;
2560
2561 if (handle == NULL) /* check handle */
2562 {
2563 return 2; /* return error */
2564 }
2565 if (handle->inited != 1) /* check handle initialization */
2566 {
2567 return 3; /* return error */
2568 }
2569 if (a_check_busy_pin(handle) != 0) /* check busy */
2570 {
2571 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2572
2573 return 1; /* return error */
2574 }
2575
2576 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2577 if (res != 0) /* check result */
2578 {
2579 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2580
2581 return 1; /* return error */
2582 }
2583 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2584 *version = (vs1053b_bool_t)((prev >> 4) & 0x0F); /* get the swing */
2585
2586 return 0; /* success return 0 */
2587}
2588
2601{
2602 uint8_t res;
2603 uint8_t buf[2];
2604 uint16_t prev;
2605
2606 if (handle == NULL) /* check handle */
2607 {
2608 return 2; /* return error */
2609 }
2610 if (handle->inited != 1) /* check handle initialization */
2611 {
2612 return 3; /* return error */
2613 }
2614 if (a_check_busy_pin(handle) != 0) /* check busy */
2615 {
2616 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2617
2618 return 1; /* return error */
2619 }
2620
2621 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2622 if (res != 0) /* check result */
2623 {
2624 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2625
2626 return 1; /* return error */
2627 }
2628 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2629 prev &= ~(1 << 3); /* clear the settings */
2630 prev |= enable << 3; /* set the config */
2631 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2632 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2633 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2634 if (res != 0) /* check result */
2635 {
2636 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2637
2638 return 1; /* return error */
2639 }
2640
2641 return 0; /* success return 0 */
2642}
2643
2656{
2657 uint8_t res;
2658 uint8_t buf[2];
2659 uint16_t prev;
2660
2661 if (handle == NULL) /* check handle */
2662 {
2663 return 2; /* return error */
2664 }
2665 if (handle->inited != 1) /* check handle initialization */
2666 {
2667 return 3; /* return error */
2668 }
2669 if (a_check_busy_pin(handle) != 0) /* check busy */
2670 {
2671 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2672
2673 return 1; /* return error */
2674 }
2675
2676 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2677 if (res != 0) /* check result */
2678 {
2679 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2680
2681 return 1; /* return error */
2682 }
2683 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2684 *enable = (vs1053b_bool_t)((prev >> 3) & 0x01); /* get the bool */
2685
2686 return 0; /* success return 0 */
2687}
2688
2701{
2702 uint8_t res;
2703 uint8_t buf[2];
2704 uint16_t prev;
2705
2706 if (handle == NULL) /* check handle */
2707 {
2708 return 2; /* return error */
2709 }
2710 if (handle->inited != 1) /* check handle initialization */
2711 {
2712 return 3; /* return error */
2713 }
2714 if (a_check_busy_pin(handle) != 0) /* check busy */
2715 {
2716 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2717
2718 return 1; /* return error */
2719 }
2720
2721 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2722 if (res != 0) /* check result */
2723 {
2724 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2725
2726 return 1; /* return error */
2727 }
2728 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2729 prev &= ~(1 << 2); /* clear the settings */
2730 prev |= enable << 2; /* set the config */
2731 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2732 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2733 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2734 if (res != 0) /* check result */
2735 {
2736 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2737
2738 return 1; /* return error */
2739 }
2740
2741 return 0; /* success return 0 */
2742}
2743
2756{
2757 uint8_t res;
2758 uint8_t buf[2];
2759 uint16_t prev;
2760
2761 if (handle == NULL) /* check handle */
2762 {
2763 return 2; /* return error */
2764 }
2765 if (handle->inited != 1) /* check handle initialization */
2766 {
2767 return 3; /* return error */
2768 }
2769 if (a_check_busy_pin(handle) != 0) /* check busy */
2770 {
2771 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2772
2773 return 1; /* return error */
2774 }
2775
2776 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2777 if (res != 0) /* check result */
2778 {
2779 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2780
2781 return 1; /* return error */
2782 }
2783 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2784 *enable = (vs1053b_bool_t)((prev >> 2) & 0x01); /* get the bool */
2785
2786 return 0; /* success return 0 */
2787}
2788
2801{
2802 uint8_t res;
2803 uint8_t buf[2];
2804 uint16_t prev;
2805
2806 if (handle == NULL) /* check handle */
2807 {
2808 return 2; /* return error */
2809 }
2810 if (handle->inited != 1) /* check handle initialization */
2811 {
2812 return 3; /* return error */
2813 }
2814 if (a_check_busy_pin(handle) != 0) /* check busy */
2815 {
2816 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2817
2818 return 1; /* return error */
2819 }
2820
2821 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2822 if (res != 0) /* check result */
2823 {
2824 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2825
2826 return 1; /* return error */
2827 }
2828 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2829 prev &= ~(1 << 1); /* clear the settings */
2830 prev |= ad_clock << 1; /* set the config */
2831 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2832 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2833 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2834 if (res != 0) /* check result */
2835 {
2836 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2837
2838 return 1; /* return error */
2839 }
2840
2841 return 0; /* success return 0 */
2842}
2843
2856{
2857 uint8_t res;
2858 uint8_t buf[2];
2859 uint16_t prev;
2860
2861 if (handle == NULL) /* check handle */
2862 {
2863 return 2; /* return error */
2864 }
2865 if (handle->inited != 1) /* check handle initialization */
2866 {
2867 return 3; /* return error */
2868 }
2869 if (a_check_busy_pin(handle) != 0) /* check busy */
2870 {
2871 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2872
2873 return 1; /* return error */
2874 }
2875
2876 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2877 if (res != 0) /* check result */
2878 {
2879 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2880
2881 return 1; /* return error */
2882 }
2883 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2884 *ad_clock = (vs1053b_ad_clock_t)((prev >> 1) & 0x01); /* get the clock */
2885
2886 return 0; /* success return 0 */
2887}
2888
2901{
2902 uint8_t res;
2903 uint8_t buf[2];
2904 uint16_t prev;
2905
2906 if (handle == NULL) /* check handle */
2907 {
2908 return 2; /* return error */
2909 }
2910 if (handle->inited != 1) /* check handle initialization */
2911 {
2912 return 3; /* return error */
2913 }
2914 if (a_check_busy_pin(handle) != 0) /* check busy */
2915 {
2916 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2917
2918 return 1; /* return error */
2919 }
2920
2921 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2922 if (res != 0) /* check result */
2923 {
2924 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2925
2926 return 1; /* return error */
2927 }
2928 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2929 prev &= ~(1 << 0); /* clear the settings */
2930 prev |= voltage << 0; /* set the config */
2931 buf[0] = (prev >> 8) & 0xFF; /* get msb */
2932 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
2933 res = a_vs1053b_spi_write(handle, VS1053B_REG_STATUS, buf, 2); /* write the status */
2934 if (res != 0) /* check result */
2935 {
2936 handle->debug_print("vs1053b: write status failed.\n"); /* write status failed */
2937
2938 return 1; /* return error */
2939 }
2940
2941 return 0; /* success return 0 */
2942}
2943
2956{
2957 uint8_t res;
2958 uint8_t buf[2];
2959 uint16_t prev;
2960
2961 if (handle == NULL) /* check handle */
2962 {
2963 return 2; /* return error */
2964 }
2965 if (handle->inited != 1) /* check handle initialization */
2966 {
2967 return 3; /* return error */
2968 }
2969 if (a_check_busy_pin(handle) != 0) /* check busy */
2970 {
2971 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
2972
2973 return 1; /* return error */
2974 }
2975
2976 res = a_vs1053b_spi_read(handle, VS1053B_REG_STATUS, buf, 2); /* read the status */
2977 if (res != 0) /* check result */
2978 {
2979 handle->debug_print("vs1053b: read status failed.\n"); /* read status failed */
2980
2981 return 1; /* return error */
2982 }
2983 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
2984 *voltage = (vs1053b_reference_voltage_t)((prev >> 0) & 0x01); /* get the voltage */
2985
2986 return 0; /* success return 0 */
2987}
2988
3002{
3003 uint8_t res;
3004 uint8_t buf[2];
3005 uint16_t prev;
3006
3007 if (handle == NULL) /* check handle */
3008 {
3009 return 2; /* return error */
3010 }
3011 if (handle->inited != 1) /* check handle initialization */
3012 {
3013 return 3; /* return error */
3014 }
3015 if (db > 15) /* check db */
3016 {
3017 handle->debug_print("vs1053b: db > 15.\n"); /* db > 15 */
3018
3019 return 4; /* return error */
3020 }
3021 if (a_check_busy_pin(handle) != 0) /* check busy */
3022 {
3023 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3024
3025 return 1; /* return error */
3026 }
3027
3028 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3029 if (res != 0) /* check result */
3030 {
3031 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3032
3033 return 1; /* return error */
3034 }
3035 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3036 prev &= ~(0xF << 12); /* clear the settings */
3037 prev |= db << 12; /* set the config */
3038 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3039 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3040 res = a_vs1053b_spi_write(handle, VS1053B_REG_BASS, buf, 2); /* write the bass */
3041 if (res != 0) /* check result */
3042 {
3043 handle->debug_print("vs1053b: write bass failed.\n"); /* write bass failed */
3044
3045 return 1; /* return error */
3046 }
3047
3048 return 0; /* success return 0 */
3049}
3050
3063{
3064 uint8_t res;
3065 uint8_t buf[2];
3066 uint16_t prev;
3067
3068 if (handle == NULL) /* check handle */
3069 {
3070 return 2; /* return error */
3071 }
3072 if (handle->inited != 1) /* check handle initialization */
3073 {
3074 return 3; /* return error */
3075 }
3076 if (a_check_busy_pin(handle) != 0) /* check busy */
3077 {
3078 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3079
3080 return 1; /* return error */
3081 }
3082
3083 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3084 if (res != 0) /* check result */
3085 {
3086 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3087
3088 return 1; /* return error */
3089 }
3090 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3091 *db = ((prev >> 12) & 0x0F); /* get the control */
3092
3093 return 0; /* success return 0 */
3094}
3095
3107uint8_t vs1053b_treble_control_convert_to_register(vs1053b_handle_t *handle, float db, uint8_t *reg)
3108{
3109 if (handle == NULL) /* check handle */
3110 {
3111 return 2; /* return error */
3112 }
3113 if (handle->inited != 1) /* check handle initialization */
3114 {
3115 return 3; /* return error */
3116 }
3117
3118 *reg = (uint8_t)(db / 1.5f); /* convert real data to register data */
3119
3120 return 0; /* success return 0 */
3121}
3122
3134uint8_t vs1053b_treble_control_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, float *db)
3135{
3136 if (handle == NULL) /* check handle */
3137 {
3138 return 2; /* return error */
3139 }
3140 if (handle->inited != 1) /* check handle initialization */
3141 {
3142 return 3; /* return error */
3143 }
3144
3145 *db = (float)(reg) * 1.5f; /* convert raw data to real data */
3146
3147 return 0; /* success return 0 */
3148}
3149
3163{
3164 uint8_t res;
3165 uint8_t buf[2];
3166 uint16_t prev;
3167
3168 if (handle == NULL) /* check handle */
3169 {
3170 return 2; /* return error */
3171 }
3172 if (handle->inited != 1) /* check handle initialization */
3173 {
3174 return 3; /* return error */
3175 }
3176 if (step > 15) /* check step */
3177 {
3178 handle->debug_print("vs1053b: step > 15.\n"); /* step > 15 */
3179
3180 return 4; /* return error */
3181 }
3182 if (a_check_busy_pin(handle) != 0) /* check busy */
3183 {
3184 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3185
3186 return 1; /* return error */
3187 }
3188
3189 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3190 if (res != 0) /* check result */
3191 {
3192 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3193
3194 return 1; /* return error */
3195 }
3196 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3197 prev &= ~(0xF << 8); /* clear the settings */
3198 prev |= step << 8; /* set the config */
3199 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3200 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3201 res = a_vs1053b_spi_write(handle, VS1053B_REG_BASS, buf, 2); /* write the bass */
3202 if (res != 0) /* check result */
3203 {
3204 handle->debug_print("vs1053b: write bass failed.\n"); /* write bass failed */
3205
3206 return 1; /* return error */
3207 }
3208
3209 return 0; /* success return 0 */
3210}
3211
3224{
3225 uint8_t res;
3226 uint8_t buf[2];
3227 uint16_t prev;
3228
3229 if (handle == NULL) /* check handle */
3230 {
3231 return 2; /* return error */
3232 }
3233 if (handle->inited != 1) /* check handle initialization */
3234 {
3235 return 3; /* return error */
3236 }
3237 if (a_check_busy_pin(handle) != 0) /* check busy */
3238 {
3239 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3240
3241 return 1; /* return error */
3242 }
3243
3244 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3245 if (res != 0) /* check result */
3246 {
3247 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3248
3249 return 1; /* return error */
3250 }
3251 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3252 *step = ((prev >> 8) & 0x0F); /* get the freq */
3253
3254 return 0; /* success return 0 */
3255}
3256
3269{
3270 if (handle == NULL) /* check handle */
3271 {
3272 return 2; /* return error */
3273 }
3274 if (handle->inited != 1) /* check handle initialization */
3275 {
3276 return 3; /* return error */
3277 }
3278
3279 *reg = (uint8_t)(hz / 1000); /* convert real data to register data */
3280
3281 return 0; /* success return 0 */
3282}
3283
3296{
3297 if (handle == NULL) /* check handle */
3298 {
3299 return 2; /* return error */
3300 }
3301 if (handle->inited != 1) /* check handle initialization */
3302 {
3303 return 3; /* return error */
3304 }
3305
3306 *hz = (uint32_t)(reg) * 1000; /* convert raw data to real data */
3307
3308 return 0; /* success return 0 */
3309}
3310
3324{
3325 uint8_t res;
3326 uint8_t buf[2];
3327 uint16_t prev;
3328
3329 if (handle == NULL) /* check handle */
3330 {
3331 return 2; /* return error */
3332 }
3333 if (handle->inited != 1) /* check handle initialization */
3334 {
3335 return 3; /* return error */
3336 }
3337 if (db > 15) /* check db */
3338 {
3339 handle->debug_print("vs1053b: db > 15.\n"); /* db > 15 */
3340
3341 return 4; /* return error */
3342 }
3343 if (a_check_busy_pin(handle) != 0) /* check busy */
3344 {
3345 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3346
3347 return 1; /* return error */
3348 }
3349
3350 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3351 if (res != 0) /* check result */
3352 {
3353 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3354
3355 return 1; /* return error */
3356 }
3357 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3358 prev &= ~(0xF << 4); /* clear the settings */
3359 prev |= db << 4; /* set the config */
3360 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3361 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3362 res = a_vs1053b_spi_write(handle, VS1053B_REG_BASS, buf, 2); /* write the bass */
3363 if (res != 0) /* check result */
3364 {
3365 handle->debug_print("vs1053b: write bass failed.\n"); /* write bass failed */
3366
3367 return 1; /* return error */
3368 }
3369
3370 return 0; /* success return 0 */
3371}
3372
3385{
3386 uint8_t res;
3387 uint8_t buf[2];
3388 uint16_t prev;
3389
3390 if (handle == NULL) /* check handle */
3391 {
3392 return 2; /* return error */
3393 }
3394 if (handle->inited != 1) /* check handle initialization */
3395 {
3396 return 3; /* return error */
3397 }
3398 if (a_check_busy_pin(handle) != 0) /* check busy */
3399 {
3400 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3401
3402 return 1; /* return error */
3403 }
3404
3405 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3406 if (res != 0) /* check result */
3407 {
3408 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3409
3410 return 1; /* return error */
3411 }
3412 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3413 *db = ((prev >> 4) & 0x0F); /* get the enhancement */
3414
3415 return 0; /* success return 0 */
3416}
3417
3431{
3432 uint8_t res;
3433 uint8_t buf[2];
3434 uint16_t prev;
3435
3436 if (handle == NULL) /* check handle */
3437 {
3438 return 2; /* return error */
3439 }
3440 if (handle->inited != 1) /* check handle initialization */
3441 {
3442 return 3; /* return error */
3443 }
3444 if (step > 15) /* check step */
3445 {
3446 handle->debug_print("vs1053b: step > 15.\n"); /* step > 15 */
3447
3448 return 4; /* return error */
3449 }
3450 if (a_check_busy_pin(handle) != 0) /* check busy */
3451 {
3452 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3453
3454 return 1; /* return error */
3455 }
3456
3457 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3458 if (res != 0) /* check result */
3459 {
3460 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3461
3462 return 1; /* return error */
3463 }
3464 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3465 prev &= ~(0xF << 0); /* clear the settings */
3466 prev |= step << 0; /* set the config */
3467 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3468 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3469 res = a_vs1053b_spi_write(handle, VS1053B_REG_BASS, buf, 2); /* write the bass */
3470 if (res != 0) /* check result */
3471 {
3472 handle->debug_print("vs1053b: write bass failed.\n"); /* write bass failed */
3473
3474 return 1; /* return error */
3475 }
3476
3477 return 0; /* success return 0 */
3478}
3479
3492{
3493 uint8_t res;
3494 uint8_t buf[2];
3495 uint16_t prev;
3496
3497 if (handle == NULL) /* check handle */
3498 {
3499 return 2; /* return error */
3500 }
3501 if (handle->inited != 1) /* check handle initialization */
3502 {
3503 return 3; /* return error */
3504 }
3505 if (a_check_busy_pin(handle) != 0) /* check busy */
3506 {
3507 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3508
3509 return 1; /* return error */
3510 }
3511
3512 res = a_vs1053b_spi_read(handle, VS1053B_REG_BASS, buf, 2); /* read the bass */
3513 if (res != 0) /* check result */
3514 {
3515 handle->debug_print("vs1053b: read bass failed.\n"); /* read bass failed */
3516
3517 return 1; /* return error */
3518 }
3519 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3520 *step = ((prev >> 0) & 0x0F); /* get the freq */
3521
3522 return 0; /* success return 0 */
3523}
3524
3537{
3538 if (handle == NULL) /* check handle */
3539 {
3540 return 2; /* return error */
3541 }
3542 if (handle->inited != 1) /* check handle initialization */
3543 {
3544 return 3; /* return error */
3545 }
3546
3547 *reg = (uint8_t)(hz / 10); /* convert real data to register data */
3548
3549 return 0; /* success return 0 */
3550}
3551
3564{
3565 if (handle == NULL) /* check handle */
3566 {
3567 return 2; /* return error */
3568 }
3569 if (handle->inited != 1) /* check handle initialization */
3570 {
3571 return 3; /* return error */
3572 }
3573
3574 *hz = (uint32_t)(reg) * 10; /* convert raw data to real data */
3575
3576 return 0; /* success return 0 */
3577}
3578
3591{
3592 uint8_t res;
3593 uint8_t buf[2];
3594 uint16_t prev;
3595
3596 if (handle == NULL) /* check handle */
3597 {
3598 return 2; /* return error */
3599 }
3600 if (handle->inited != 1) /* check handle initialization */
3601 {
3602 return 3; /* return error */
3603 }
3604 if (a_check_busy_pin(handle) != 0) /* check busy */
3605 {
3606 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3607
3608 return 1; /* return error */
3609 }
3610
3611 res = a_vs1053b_spi_read(handle, VS1053B_REG_CLOCKF, buf, 2); /* read the clock */
3612 if (res != 0) /* check result */
3613 {
3614 handle->debug_print("vs1053b: read clock failed.\n"); /* read clock failed */
3615
3616 return 1; /* return error */
3617 }
3618 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3619 prev &= ~(0x7 << 13); /* clear the settings */
3620 prev |= multiplier << 13; /* set the config */
3621 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3622 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3623 res = a_vs1053b_spi_write(handle, VS1053B_REG_CLOCKF, buf, 2); /* write the clock */
3624 if (res != 0) /* check result */
3625 {
3626 handle->debug_print("vs1053b: write clock failed.\n"); /* write clock failed */
3627
3628 return 1; /* return error */
3629 }
3630
3631 return 0; /* success return 0 */
3632}
3633
3646{
3647 uint8_t res;
3648 uint8_t buf[2];
3649 uint16_t prev;
3650
3651 if (handle == NULL) /* check handle */
3652 {
3653 return 2; /* return error */
3654 }
3655 if (handle->inited != 1) /* check handle initialization */
3656 {
3657 return 3; /* return error */
3658 }
3659 if (a_check_busy_pin(handle) != 0) /* check busy */
3660 {
3661 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3662
3663 return 1; /* return error */
3664 }
3665
3666 res = a_vs1053b_spi_read(handle, VS1053B_REG_CLOCKF, buf, 2); /* read the clock */
3667 if (res != 0) /* check result */
3668 {
3669 handle->debug_print("vs1053b: read clock failed.\n"); /* read clock failed */
3670
3671 return 1; /* return error */
3672 }
3673 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3674 *multiplier = (vs1053b_clock_multiplier_t)((prev >> 13) & 0x07); /* get the multiplier */
3675
3676 return 0; /* success return 0 */
3677}
3678
3691{
3692 uint8_t res;
3693 uint8_t buf[2];
3694 uint16_t prev;
3695
3696 if (handle == NULL) /* check handle */
3697 {
3698 return 2; /* return error */
3699 }
3700 if (handle->inited != 1) /* check handle initialization */
3701 {
3702 return 3; /* return error */
3703 }
3704 if (a_check_busy_pin(handle) != 0) /* check busy */
3705 {
3706 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3707
3708 return 1; /* return error */
3709 }
3710
3711 res = a_vs1053b_spi_read(handle, VS1053B_REG_CLOCKF, buf, 2); /* read the clock */
3712 if (res != 0) /* check result */
3713 {
3714 handle->debug_print("vs1053b: read clock failed.\n"); /* read clock failed */
3715
3716 return 1; /* return error */
3717 }
3718 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3719 prev &= ~(0x3 << 11); /* clear the settings */
3720 prev |= addition << 11; /* set the config */
3721 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3722 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3723 res = a_vs1053b_spi_write(handle, VS1053B_REG_CLOCKF, buf, 2); /* write the clock */
3724 if (res != 0) /* check result */
3725 {
3726 handle->debug_print("vs1053b: write clock failed.\n"); /* write clock failed */
3727
3728 return 1; /* return error */
3729 }
3730
3731 return 0; /* success return 0 */
3732}
3733
3746{
3747 uint8_t res;
3748 uint8_t buf[2];
3749 uint16_t prev;
3750
3751 if (handle == NULL) /* check handle */
3752 {
3753 return 2; /* return error */
3754 }
3755 if (handle->inited != 1) /* check handle initialization */
3756 {
3757 return 3; /* return error */
3758 }
3759 if (a_check_busy_pin(handle) != 0) /* check busy */
3760 {
3761 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3762
3763 return 1; /* return error */
3764 }
3765
3766 res = a_vs1053b_spi_read(handle, VS1053B_REG_CLOCKF, buf, 2); /* read the clock */
3767 if (res != 0) /* check result */
3768 {
3769 handle->debug_print("vs1053b: read clock failed.\n"); /* read clock failed */
3770
3771 return 1; /* return error */
3772 }
3773 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3774 *addition = (vs1053b_allowed_multiplier_addition_t)((prev >> 11) & 0x03); /* get the addition */
3775
3776 return 0; /* success return 0 */
3777}
3778
3791uint8_t vs1053b_set_clock_frequency(vs1053b_handle_t *handle, uint16_t clk)
3792{
3793 uint8_t res;
3794 uint8_t buf[2];
3795 uint16_t prev;
3796
3797 if (handle == NULL) /* check handle */
3798 {
3799 return 2; /* return error */
3800 }
3801 if (handle->inited != 1) /* check handle initialization */
3802 {
3803 return 3; /* return error */
3804 }
3805 if (clk > 0x3FF) /* check clock */
3806 {
3807 handle->debug_print("vs1053b: clk > 0x3FF.\n"); /* clk > 0x3FF */
3808
3809 return 4; /* return error */
3810 }
3811 if (a_check_busy_pin(handle) != 0) /* check busy */
3812 {
3813 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3814
3815 return 1; /* return error */
3816 }
3817
3818 res = a_vs1053b_spi_read(handle, VS1053B_REG_CLOCKF, buf, 2); /* read the clock */
3819 if (res != 0) /* check result */
3820 {
3821 handle->debug_print("vs1053b: read clock failed.\n"); /* read clock failed */
3822
3823 return 1; /* return error */
3824 }
3825 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3826 prev &= ~(0x3FF << 0); /* clear the settings */
3827 prev |= clk << 0; /* set the config */
3828 buf[0] = (prev >> 8) & 0xFF; /* get msb */
3829 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
3830 res = a_vs1053b_spi_write(handle, VS1053B_REG_CLOCKF, buf, 2); /* write the clock */
3831 if (res != 0) /* check result */
3832 {
3833 handle->debug_print("vs1053b: write clock failed.\n"); /* write clock failed */
3834
3835 return 1; /* return error */
3836 }
3837
3838 return 0; /* success return 0 */
3839}
3840
3852uint8_t vs1053b_get_clock_frequency(vs1053b_handle_t *handle, uint16_t *clk)
3853{
3854 uint8_t res;
3855 uint8_t buf[2];
3856 uint16_t prev;
3857
3858 if (handle == NULL) /* check handle */
3859 {
3860 return 2; /* return error */
3861 }
3862 if (handle->inited != 1) /* check handle initialization */
3863 {
3864 return 3; /* return error */
3865 }
3866 if (a_check_busy_pin(handle) != 0) /* check busy */
3867 {
3868 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3869
3870 return 1; /* return error */
3871 }
3872
3873 res = a_vs1053b_spi_read(handle, VS1053B_REG_CLOCKF, buf, 2); /* read the clock */
3874 if (res != 0) /* check result */
3875 {
3876 handle->debug_print("vs1053b: read clock failed.\n"); /* read clock failed */
3877
3878 return 1; /* return error */
3879 }
3880 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
3881 *clk = ((prev >> 0) & 0x3FF); /* get the freq */
3882
3883 return 0; /* success return 0 */
3884}
3885
3897uint8_t vs1053b_clock_frequency_convert_to_register(vs1053b_handle_t *handle, float hz, uint16_t *reg)
3898{
3899 if (handle == NULL) /* check handle */
3900 {
3901 return 2; /* return error */
3902 }
3903 if (handle->inited != 1) /* check handle initialization */
3904 {
3905 return 3; /* return error */
3906 }
3907
3908 *reg = (uint16_t)((hz - 8000000.0f) / 4000.0f); /* convert real data to register data */
3909
3910 return 0; /* success return 0 */
3911}
3912
3924uint8_t vs1053b_clock_frequency_convert_to_data(vs1053b_handle_t *handle, uint16_t reg, float *hz)
3925{
3926 if (handle == NULL) /* check handle */
3927 {
3928 return 2; /* return error */
3929 }
3930 if (handle->inited != 1) /* check handle initialization */
3931 {
3932 return 3; /* return error */
3933 }
3934
3935 *hz = (float)((float)reg * 4000.0f + 8000000.0f); /* convert raw data to real data */
3936
3937 return 0; /* success return 0 */
3938}
3939
3951uint8_t vs1053b_set_decode_time(vs1053b_handle_t *handle, uint16_t decode_time)
3952{
3953 uint8_t res;
3954 uint8_t buf[2];
3955
3956 if (handle == NULL) /* check handle */
3957 {
3958 return 2; /* return error */
3959 }
3960 if (handle->inited != 1) /* check handle initialization */
3961 {
3962 return 3; /* return error */
3963 }
3964 if (a_check_busy_pin(handle) != 0) /* check busy */
3965 {
3966 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3967
3968 return 1; /* return error */
3969 }
3970
3971 buf[0] = (decode_time >> 8) & 0xFF; /* get msb */
3972 buf[1] = (decode_time >> 0) & 0xFF; /* get lsb */
3973 res = a_vs1053b_spi_write(handle, VS1053B_REG_DECODE_TIME, buf, 2); /* write the decode time */
3974 if (res != 0) /* check result */
3975 {
3976 handle->debug_print("vs1053b: write decode time failed.\n"); /* write decode time failed */
3977
3978 return 1; /* return error */
3979 }
3980 if (a_check_busy_pin(handle) != 0) /* check busy */
3981 {
3982 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
3983
3984 return 1; /* return error */
3985 }
3986 res = a_vs1053b_spi_write(handle, VS1053B_REG_DECODE_TIME, buf, 2); /* write the decode time */
3987 if (res != 0) /* check result */
3988 {
3989 handle->debug_print("vs1053b: write decode time failed.\n"); /* write decode time failed */
3990
3991 return 1; /* return error */
3992 }
3993
3994 return 0; /* success return 0 */
3995}
3996
4008uint8_t vs1053b_get_decode_time(vs1053b_handle_t *handle, uint16_t *decode_time)
4009{
4010 uint8_t res;
4011 uint8_t buf[2];
4012
4013 if (handle == NULL) /* check handle */
4014 {
4015 return 2; /* return error */
4016 }
4017 if (handle->inited != 1) /* check handle initialization */
4018 {
4019 return 3; /* return error */
4020 }
4021 if (a_check_busy_pin(handle) != 0) /* check busy */
4022 {
4023 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4024
4025 return 1; /* return error */
4026 }
4027
4028 res = a_vs1053b_spi_read(handle, VS1053B_REG_DECODE_TIME, buf, 2); /* read the decode time */
4029 if (res != 0) /* check result */
4030 {
4031 handle->debug_print("vs1053b: read decode time failed.\n"); /* read decode time failed */
4032
4033 return 1; /* return error */
4034 }
4035 *decode_time = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4036
4037 return 0; /* success return 0 */
4038}
4039
4052uint8_t vs1053b_set_sample_rate(vs1053b_handle_t *handle, uint16_t rate, vs1053b_channel_t channel)
4053{
4054 uint8_t res;
4055 uint8_t buf[2];
4056 uint16_t prev;
4057
4058 if (handle == NULL) /* check handle */
4059 {
4060 return 2; /* return error */
4061 }
4062 if (handle->inited != 1) /* check handle initialization */
4063 {
4064 return 3; /* return error */
4065 }
4066 if (a_check_busy_pin(handle) != 0) /* check busy */
4067 {
4068 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4069
4070 return 1; /* return error */
4071 }
4072
4073 prev = rate | channel; /* set channel */
4074 buf[0] = (prev >> 8) & 0xFF; /* get msb */
4075 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
4076 res = a_vs1053b_spi_write(handle, VS1053B_REG_AUDATA, buf, 2); /* write the audata */
4077 if (res != 0) /* check result */
4078 {
4079 handle->debug_print("vs1053b: write audata failed.\n"); /* write audata failed */
4080
4081 return 1; /* return error */
4082 }
4083
4084 return 0; /* success return 0 */
4085}
4086
4099uint8_t vs1053b_get_sample_rate(vs1053b_handle_t *handle, uint16_t *rate, vs1053b_channel_t *channel)
4100{
4101 uint8_t res;
4102 uint8_t buf[2];
4103 uint16_t prev;
4104
4105 if (handle == NULL) /* check handle */
4106 {
4107 return 2; /* return error */
4108 }
4109 if (handle->inited != 1) /* check handle initialization */
4110 {
4111 return 3; /* return error */
4112 }
4113 if (a_check_busy_pin(handle) != 0) /* check busy */
4114 {
4115 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4116
4117 return 1; /* return error */
4118 }
4119
4120 res = a_vs1053b_spi_read(handle, VS1053B_REG_AUDATA, buf, 2); /* read the audata */
4121 if (res != 0) /* check result */
4122 {
4123 handle->debug_print("vs1053b: read audata failed.\n"); /* read audata failed */
4124
4125 return 1; /* return error */
4126 }
4127 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4128 *rate = prev & (~(1 << 0)); /* get the rate */
4129 *channel = (vs1053b_channel_t)(prev & 0x01); /* get the channel */
4130
4131 return 0; /* success return 0 */
4132}
4133
4146uint8_t vs1053b_write_ram(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
4147{
4148 uint8_t res;
4149
4150 if (handle == NULL) /* check handle */
4151 {
4152 return 2; /* return error */
4153 }
4154 if (handle->inited != 1) /* check handle initialization */
4155 {
4156 return 3; /* return error */
4157 }
4158 if (a_check_busy_pin(handle) != 0) /* check busy */
4159 {
4160 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4161
4162 return 1; /* return error */
4163 }
4164
4165 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, len); /* write the ram */
4166 if (res != 0) /* check result */
4167 {
4168 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
4169
4170 return 1; /* return error */
4171 }
4172
4173 return 0; /* success return 0 */
4174}
4175
4188uint8_t vs1053b_read_ram(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
4189{
4190 uint8_t res;
4191
4192 if (handle == NULL) /* check handle */
4193 {
4194 return 2; /* return error */
4195 }
4196 if (handle->inited != 1) /* check handle initialization */
4197 {
4198 return 3; /* return error */
4199 }
4200 if (a_check_busy_pin(handle) != 0) /* check busy */
4201 {
4202 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4203
4204 return 1; /* return error */
4205 }
4206
4207 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, len); /* read the ram */
4208 if (res != 0) /* check result */
4209 {
4210 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
4211
4212 return 1; /* return error */
4213 }
4214
4215 return 0; /* success return 0 */
4216}
4217
4229uint8_t vs1053b_set_ram_address(vs1053b_handle_t *handle, uint16_t addr)
4230{
4231 uint8_t res;
4232 uint8_t buf[2];
4233
4234 if (handle == NULL) /* check handle */
4235 {
4236 return 2; /* return error */
4237 }
4238 if (handle->inited != 1) /* check handle initialization */
4239 {
4240 return 3; /* return error */
4241 }
4242 if (a_check_busy_pin(handle) != 0) /* check busy */
4243 {
4244 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4245
4246 return 1; /* return error */
4247 }
4248
4249 buf[0] = (addr >> 8) & 0xFF; /* get msb */
4250 buf[1] = (addr >> 0) & 0xFF; /* get lsb */
4251 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
4252 if (res != 0) /* check result */
4253 {
4254 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
4255
4256 return 1; /* return error */
4257 }
4258
4259 return 0; /* success return 0 */
4260}
4261
4274uint8_t vs1053b_get_hdata(vs1053b_handle_t *handle, uint16_t *dat0, uint16_t *dat1)
4275{
4276 uint8_t res;
4277 uint8_t buf[2];
4278
4279 if (handle == NULL) /* check handle */
4280 {
4281 return 2; /* return error */
4282 }
4283 if (handle->inited != 1) /* check handle initialization */
4284 {
4285 return 3; /* return error */
4286 }
4287 if (a_check_busy_pin(handle) != 0) /* check busy */
4288 {
4289 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4290
4291 return 1; /* return error */
4292 }
4293
4294 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
4295 if (res != 0) /* check result */
4296 {
4297 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
4298
4299 return 1; /* return error */
4300 }
4301 *dat0 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4302 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
4303 if (res != 0) /* check result */
4304 {
4305 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
4306
4307 return 1; /* return error */
4308 }
4309 *dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4310
4311 return 0; /* success return 0 */
4312}
4313
4325uint8_t vs1053b_get_hdata0(vs1053b_handle_t *handle, uint16_t *dat0)
4326{
4327 uint8_t res;
4328 uint8_t buf[2];
4329
4330 if (handle == NULL) /* check handle */
4331 {
4332 return 2; /* return error */
4333 }
4334 if (handle->inited != 1) /* check handle initialization */
4335 {
4336 return 3; /* return error */
4337 }
4338 if (a_check_busy_pin(handle) != 0) /* check busy */
4339 {
4340 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4341
4342 return 1; /* return error */
4343 }
4344
4345 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
4346 if (res != 0) /* check result */
4347 {
4348 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
4349
4350 return 1; /* return error */
4351 }
4352 *dat0 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4353
4354 return 0; /* success return 0 */
4355}
4356
4368uint8_t vs1053b_get_hdata1(vs1053b_handle_t *handle, uint16_t *dat1)
4369{
4370 uint8_t res;
4371 uint8_t buf[2];
4372
4373 if (handle == NULL) /* check handle */
4374 {
4375 return 2; /* return error */
4376 }
4377 if (handle->inited != 1) /* check handle initialization */
4378 {
4379 return 3; /* return error */
4380 }
4381 if (a_check_busy_pin(handle) != 0) /* check busy */
4382 {
4383 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4384
4385 return 1; /* return error */
4386 }
4387
4388 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
4389 if (res != 0) /* check result */
4390 {
4391 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
4392
4393 return 1; /* return error */
4394 }
4395 *dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4396
4397 return 0; /* success return 0 */
4398}
4399
4411uint8_t vs1053b_set_start_address(vs1053b_handle_t *handle, uint16_t addr)
4412{
4413 uint8_t res;
4414 uint8_t buf[2];
4415
4416 if (handle == NULL) /* check handle */
4417 {
4418 return 2; /* return error */
4419 }
4420 if (handle->inited != 1) /* check handle initialization */
4421 {
4422 return 3; /* return error */
4423 }
4424 if (a_check_busy_pin(handle) != 0) /* check busy */
4425 {
4426 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4427
4428 return 1; /* return error */
4429 }
4430
4431 buf[0] = (addr >> 8) & 0xFF; /* get msb */
4432 buf[1] = (addr >> 0) & 0xFF; /* get lsb */
4433 res = a_vs1053b_spi_write(handle, VS1053B_REG_AIADDR, buf, 2); /* write aiaddr */
4434 if (res != 0) /* check result */
4435 {
4436 handle->debug_print("vs1053b: write aiaddr failed.\n"); /* write aiaddr failed */
4437
4438 return 1; /* return error */
4439 }
4440
4441 return 0; /* success return 0 */
4442}
4443
4455uint8_t vs1053b_get_start_address(vs1053b_handle_t *handle, uint16_t *addr)
4456{
4457 uint8_t res;
4458 uint8_t buf[2];
4459
4460 if (handle == NULL) /* check handle */
4461 {
4462 return 2; /* return error */
4463 }
4464 if (handle->inited != 1) /* check handle initialization */
4465 {
4466 return 3; /* return error */
4467 }
4468 if (a_check_busy_pin(handle) != 0) /* check busy */
4469 {
4470 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4471
4472 return 1; /* return error */
4473 }
4474
4475 res = a_vs1053b_spi_read(handle, VS1053B_REG_AIADDR, buf, 2); /* read the aiaddr */
4476 if (res != 0) /* check result */
4477 {
4478 handle->debug_print("vs1053b: read aiaddr failed.\n"); /* read aiaddr failed */
4479
4480 return 1; /* return error */
4481 }
4482 *addr = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4483
4484 return 0; /* success return 0 */
4485}
4486
4499uint8_t vs1053b_set_vol(vs1053b_handle_t *handle, uint8_t left, uint8_t right)
4500{
4501 uint8_t res;
4502 uint8_t buf[2];
4503 uint16_t prev;
4504
4505 if (handle == NULL) /* check handle */
4506 {
4507 return 2; /* return error */
4508 }
4509 if (handle->inited != 1) /* check handle initialization */
4510 {
4511 return 3; /* return error */
4512 }
4513 if (a_check_busy_pin(handle) != 0) /* check busy */
4514 {
4515 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4516
4517 return 1; /* return error */
4518 }
4519
4520 prev = (uint16_t)left << 8 | right; /* set vol */
4521 buf[0] = (prev >> 8) & 0xFF; /* get msb */
4522 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
4523 res = a_vs1053b_spi_write(handle, VS1053B_REG_VOL, buf, 2); /* write vol */
4524 if (res != 0) /* check result */
4525 {
4526 handle->debug_print("vs1053b: write vol failed.\n"); /* write vol failed */
4527
4528 return 1; /* return error */
4529 }
4530
4531 return 0; /* success return 0 */
4532}
4533
4546uint8_t vs1053b_get_vol(vs1053b_handle_t *handle, uint8_t *left, uint8_t *right)
4547{
4548 uint8_t res;
4549 uint8_t buf[2];
4550
4551 if (handle == NULL) /* check handle */
4552 {
4553 return 2; /* return error */
4554 }
4555 if (handle->inited != 1) /* check handle initialization */
4556 {
4557 return 3; /* return error */
4558 }
4559 if (a_check_busy_pin(handle) != 0) /* check busy */
4560 {
4561 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4562
4563 return 1; /* return error */
4564 }
4565
4566 res = a_vs1053b_spi_read(handle, VS1053B_REG_VOL, buf, 2); /* read the vol */
4567 if (res != 0) /* check result */
4568 {
4569 handle->debug_print("vs1053b: read vol failed.\n"); /* read vol failed */
4570
4571 return 1; /* return error */
4572 }
4573 *left = buf[0]; /* get the left */
4574 *right = buf[1]; /* get the right */
4575
4576 return 0; /* success return 0 */
4577}
4578
4590uint8_t vs1053b_vol_convert_to_register(vs1053b_handle_t *handle, float db, uint8_t *reg)
4591{
4592 if (handle == NULL) /* check handle */
4593 {
4594 return 2; /* return error */
4595 }
4596 if (handle->inited != 1) /* check handle initialization */
4597 {
4598 return 3; /* return error */
4599 }
4600
4601 *reg = (uint8_t)(fabsf(db) / 0.5f); /* convert real data to register data */
4602
4603 return 0; /* success return 0 */
4604}
4605
4617uint8_t vs1053b_vol_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, float *db)
4618{
4619 if (handle == NULL) /* check handle */
4620 {
4621 return 2; /* return error */
4622 }
4623 if (handle->inited != 1) /* check handle initialization */
4624 {
4625 return 3; /* return error */
4626 }
4627
4628 *db = (float)(reg * 0.5f); /* convert raw data to real data */
4629
4630 return 0; /* success return 0 */
4631}
4632
4646uint8_t vs1053b_write_application(vs1053b_handle_t *handle, vs1053b_application_t num, uint8_t *buf, uint16_t len)
4647{
4648 uint8_t res;
4649
4650 if (handle == NULL) /* check handle */
4651 {
4652 return 2; /* return error */
4653 }
4654 if (handle->inited != 1) /* check handle initialization */
4655 {
4656 return 3; /* return error */
4657 }
4658 if (a_check_busy_pin(handle) != 0) /* check busy */
4659 {
4660 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4661
4662 return 1; /* return error */
4663 }
4664
4665 if (num == VS1053B_APPLICATION_0) /* app0 */
4666 {
4667 res = a_vs1053b_spi_write(handle, VS1053B_REG_AICTRL0, buf, len); /* write the aictrl0 */
4668 if (res != 0) /* check result */
4669 {
4670 handle->debug_print("vs1053b: write aictrl0 failed.\n"); /* write aictrl0 failed */
4671
4672 return 1; /* return error */
4673 }
4674 }
4675 else if (num == VS1053B_APPLICATION_1) /* app1 */
4676 {
4677 res = a_vs1053b_spi_write(handle, VS1053B_REG_AICTRL1, buf, len); /* write the aictrl1 */
4678 if (res != 0) /* check result */
4679 {
4680 handle->debug_print("vs1053b: write aictrl1 failed.\n"); /* write aictrl1 failed */
4681
4682 return 1; /* return error */
4683 }
4684 }
4685 else if (num == VS1053B_APPLICATION_2) /* app2 */
4686 {
4687 res = a_vs1053b_spi_write(handle, VS1053B_REG_AICTRL2, buf, len); /* write the aictrl2 */
4688 if (res != 0) /* check result */
4689 {
4690 handle->debug_print("vs1053b: write aictrl2 failed.\n"); /* write aictrl2 failed */
4691
4692 return 1; /* return error */
4693 }
4694 }
4695 else /* app3 */
4696 {
4697 res = a_vs1053b_spi_write(handle, VS1053B_REG_AICTRL3, buf, len); /* write the aictrl3 */
4698 if (res != 0) /* check result */
4699 {
4700 handle->debug_print("vs1053b: write aictrl3 failed.\n"); /* write aictrl3 failed */
4701
4702 return 1; /* return error */
4703 }
4704 }
4705
4706 return 0; /* success return 0 */
4707}
4708
4722uint8_t vs1053b_read_application(vs1053b_handle_t *handle, vs1053b_application_t num, uint8_t *buf, uint16_t len)
4723{
4724 uint8_t res;
4725
4726 if (handle == NULL) /* check handle */
4727 {
4728 return 2; /* return error */
4729 }
4730 if (handle->inited != 1) /* check handle initialization */
4731 {
4732 return 3; /* return error */
4733 }
4734 if (a_check_busy_pin(handle) != 0) /* check busy */
4735 {
4736 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4737
4738 return 1; /* return error */
4739 }
4740
4741 if (num == VS1053B_APPLICATION_0) /* app0 */
4742 {
4743 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL0, buf, len); /* read the aictrl0 */
4744 if (res != 0) /* check result */
4745 {
4746 handle->debug_print("vs1053b: read aictrl0 failed.\n"); /* read aictrl0 failed */
4747
4748 return 1; /* return error */
4749 }
4750 }
4751 else if (num == VS1053B_APPLICATION_1) /* app1 */
4752 {
4753 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL1, buf, len); /* read the aictrl1 */
4754 if (res != 0) /* check result */
4755 {
4756 handle->debug_print("vs1053b: read aictrl1 failed.\n"); /* read aictrl1 failed */
4757
4758 return 1; /* return error */
4759 }
4760 }
4761 else if (num == VS1053B_APPLICATION_2) /* app2 */
4762 {
4763 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL2, buf, len); /* read the aictrl2 */
4764 if (res != 0) /* check result */
4765 {
4766 handle->debug_print("vs1053b: write aictrl2 failed.\n"); /* read aictrl2 failed */
4767
4768 return 1; /* return error */
4769 }
4770 }
4771 else /* app3 */
4772 {
4773 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL3, buf, len); /* read the aictrl3 */
4774 if (res != 0) /* check result */
4775 {
4776 handle->debug_print("vs1053b: write aictrl3 failed.\n"); /* read aictrl3 failed */
4777
4778 return 1; /* return error */
4779 }
4780 }
4781
4782 return 0; /* success return 0 */
4783}
4784
4797{
4798 uint8_t res;
4799 uint8_t buf[2];
4800 uint16_t prev;
4801
4802 if (handle == NULL) /* check handle */
4803 {
4804 return 2; /* return error */
4805 }
4806 if (handle->inited != 1) /* check handle initialization */
4807 {
4808 return 3; /* return error */
4809 }
4810
4811 if (a_check_busy_pin(handle) != 0) /* check busy */
4812 {
4813 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4814
4815 return 1; /* return error */
4816 }
4817 prev = 0x1E04; /* set addr */
4818 buf[0] = (prev >> 8) & 0xFF; /* get msb */
4819 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
4820 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
4821 if (res != 0) /* check result */
4822 {
4823 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
4824
4825 return 1; /* return error */
4826 }
4827
4828 if (a_check_busy_pin(handle) != 0) /* check busy */
4829 {
4830 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4831
4832 return 1; /* return error */
4833 }
4834 prev = speed; /* set play speed */
4835 buf[0] = (prev >> 8) & 0xFF; /* get msb */
4836 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
4837 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, 2); /* write the ram */
4838 if (res != 0) /* check result */
4839 {
4840 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
4841
4842 return 1; /* return error */
4843 }
4844
4845 return 0; /* success return 0 */
4846}
4847
4860{
4861 uint8_t res;
4862 uint8_t buf[2];
4863 uint16_t prev;
4864
4865 if (handle == NULL) /* check handle */
4866 {
4867 return 2; /* return error */
4868 }
4869 if (handle->inited != 1) /* check handle initialization */
4870 {
4871 return 3; /* return error */
4872 }
4873
4874 if (a_check_busy_pin(handle) != 0) /* check busy */
4875 {
4876 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4877
4878 return 1; /* return error */
4879 }
4880 prev = 0x1E04; /* set addr */
4881 buf[0] = (prev >> 8) & 0xFF; /* get msb */
4882 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
4883 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
4884 if (res != 0) /* check result */
4885 {
4886 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
4887
4888 return 1; /* return error */
4889 }
4890
4891 if (a_check_busy_pin(handle) != 0) /* check busy */
4892 {
4893 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4894
4895 return 1; /* return error */
4896 }
4897 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
4898 if (res != 0) /* check result */
4899 {
4900 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
4901
4902 return 1; /* return error */
4903 }
4904 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
4905 *speed = (vs1053b_play_speed_t)(prev & 0x03); /* get speed */
4906
4907 return 0; /* success return 0 */
4908}
4909
4921uint8_t vs1053b_get_byte_rate(vs1053b_handle_t *handle, uint16_t *rate)
4922{
4923 uint8_t res;
4924 uint8_t buf[2];
4925 uint16_t prev;
4926
4927 if (handle == NULL) /* check handle */
4928 {
4929 return 2; /* return error */
4930 }
4931 if (handle->inited != 1) /* check handle initialization */
4932 {
4933 return 3; /* return error */
4934 }
4935
4936 if (a_check_busy_pin(handle) != 0) /* check busy */
4937 {
4938 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4939
4940 return 1; /* return error */
4941 }
4942 prev = 0x1E05; /* set addr */
4943 buf[0] = (prev >> 8) & 0xFF; /* get msb */
4944 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
4945 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
4946 if (res != 0) /* check result */
4947 {
4948 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
4949
4950 return 1; /* return error */
4951 }
4952
4953 if (a_check_busy_pin(handle) != 0) /* check busy */
4954 {
4955 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
4956
4957 return 1; /* return error */
4958 }
4959 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
4960 if (res != 0) /* check result */
4961 {
4962 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
4963
4964 return 1; /* return error */
4965 }
4966 *rate = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
4967
4968 return 0; /* success return 0 */
4969}
4970
4982uint8_t vs1053b_get_end_fill_byte(vs1053b_handle_t *handle, uint16_t *byte)
4983{
4984 uint8_t res;
4985 uint8_t buf[2];
4986 uint16_t prev;
4987
4988 if (handle == NULL) /* check handle */
4989 {
4990 return 2; /* return error */
4991 }
4992 if (handle->inited != 1) /* check handle initialization */
4993 {
4994 return 3; /* return error */
4995 }
4996
4997 if (a_check_busy_pin(handle) != 0) /* check busy */
4998 {
4999 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5000
5001 return 1; /* return error */
5002 }
5003 prev = 0x1E06; /* set addr */
5004 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5005 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5006 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5007 if (res != 0) /* check result */
5008 {
5009 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5010
5011 return 1; /* return error */
5012 }
5013
5014 if (a_check_busy_pin(handle) != 0) /* check busy */
5015 {
5016 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5017
5018 return 1; /* return error */
5019 }
5020 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5021 if (res != 0) /* check result */
5022 {
5023 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5024
5025 return 1; /* return error */
5026 }
5027 *byte = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5028
5029 return 0; /* success return 0 */
5030}
5031
5044{
5045 uint8_t res;
5046 uint8_t buf[2];
5047 uint16_t prev;
5048 uint16_t prev2;
5049
5050 if (handle == NULL) /* check handle */
5051 {
5052 return 2; /* return error */
5053 }
5054 if (handle->inited != 1) /* check handle initialization */
5055 {
5056 return 3; /* return error */
5057 }
5058
5059 if (a_check_busy_pin(handle) != 0) /* check busy */
5060 {
5061 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5062
5063 return 1; /* return error */
5064 }
5065 prev = 0xC040; /* set addr */
5066 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5067 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5068 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5069 if (res != 0) /* check result */
5070 {
5071 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5072
5073 return 1; /* return error */
5074 }
5075
5076 if (a_check_busy_pin(handle) != 0) /* check busy */
5077 {
5078 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5079
5080 return 1; /* return error */
5081 }
5082 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5083 if (res != 0) /* check result */
5084 {
5085 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5086
5087 return 1; /* return error */
5088 }
5089 prev2 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5090
5091 if (a_check_busy_pin(handle) != 0) /* check busy */
5092 {
5093 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5094
5095 return 1; /* return error */
5096 }
5097 prev = 0xC040; /* set addr */
5098 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5099 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5100 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5101 if (res != 0) /* check result */
5102 {
5103 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5104
5105 return 1; /* return error */
5106 }
5107
5108 if (a_check_busy_pin(handle) != 0) /* check busy */
5109 {
5110 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5111
5112 return 1; /* return error */
5113 }
5114 prev2 &= ~(1 << 3); /* clear settings */
5115 prev2 |= enable << 3; /* set bool */
5116 buf[0] = (prev2 >> 8) & 0xFF; /* get msb */
5117 buf[1] = (prev2 >> 0) & 0xFF; /* get lsb */
5118 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, 2); /* write the ram */
5119 if (res != 0) /* check result */
5120 {
5121 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
5122
5123 return 1; /* return error */
5124 }
5125
5126 return 0; /* success return 0 */
5127}
5128
5141{
5142 uint8_t res;
5143 uint8_t buf[2];
5144 uint16_t prev;
5145
5146 if (handle == NULL) /* check handle */
5147 {
5148 return 2; /* return error */
5149 }
5150 if (handle->inited != 1) /* check handle initialization */
5151 {
5152 return 3; /* return error */
5153 }
5154
5155 if (a_check_busy_pin(handle) != 0) /* check busy */
5156 {
5157 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5158
5159 return 1; /* return error */
5160 }
5161 prev = 0xC040; /* set addr */
5162 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5163 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5164 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5165 if (res != 0) /* check result */
5166 {
5167 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5168
5169 return 1; /* return error */
5170 }
5171
5172 if (a_check_busy_pin(handle) != 0) /* check busy */
5173 {
5174 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5175
5176 return 1; /* return error */
5177 }
5178 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5179 if (res != 0) /* check result */
5180 {
5181 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5182
5183 return 1; /* return error */
5184 }
5185 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5186 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5187 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5188 *enable = (vs1053b_bool_t)((prev >> 3) & 0x01); /* get bool */
5189
5190 return 0; /* success return 0 */
5191}
5192
5205{
5206 uint8_t res;
5207 uint8_t buf[2];
5208 uint16_t prev;
5209 uint16_t prev2;
5210
5211 if (handle == NULL) /* check handle */
5212 {
5213 return 2; /* return error */
5214 }
5215 if (handle->inited != 1) /* check handle initialization */
5216 {
5217 return 3; /* return error */
5218 }
5219
5220 if (a_check_busy_pin(handle) != 0) /* check busy */
5221 {
5222 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5223
5224 return 1; /* return error */
5225 }
5226 prev = 0xC040; /* set addr */
5227 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5228 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5229 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5230 if (res != 0) /* check result */
5231 {
5232 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5233
5234 return 1; /* return error */
5235 }
5236
5237 if (a_check_busy_pin(handle) != 0) /* check busy */
5238 {
5239 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5240
5241 return 1; /* return error */
5242 }
5243 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5244 if (res != 0) /* check result */
5245 {
5246 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5247
5248 return 1; /* return error */
5249 }
5250 prev2 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5251
5252 if (a_check_busy_pin(handle) != 0) /* check busy */
5253 {
5254 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5255
5256 return 1; /* return error */
5257 }
5258 prev = 0xC040; /* set addr */
5259 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5260 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5261 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5262 if (res != 0) /* check result */
5263 {
5264 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5265
5266 return 1; /* return error */
5267 }
5268
5269 if (a_check_busy_pin(handle) != 0) /* check busy */
5270 {
5271 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5272
5273 return 1; /* return error */
5274 }
5275 prev2 &= ~(1 << 2); /* clear settings */
5276 prev2 |= enable << 2; /* set bool */
5277 buf[0] = (prev2 >> 8) & 0xFF; /* get msb */
5278 buf[1] = (prev2 >> 0) & 0xFF; /* get lsb */
5279 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, 2); /* write the ram */
5280 if (res != 0) /* check result */
5281 {
5282 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
5283
5284 return 1; /* return error */
5285 }
5286
5287 return 0; /* success return 0 */
5288}
5289
5302{
5303 uint8_t res;
5304 uint8_t buf[2];
5305 uint16_t prev;
5306
5307 if (handle == NULL) /* check handle */
5308 {
5309 return 2; /* return error */
5310 }
5311 if (handle->inited != 1) /* check handle initialization */
5312 {
5313 return 3; /* return error */
5314 }
5315
5316 if (a_check_busy_pin(handle) != 0) /* check busy */
5317 {
5318 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5319
5320 return 1; /* return error */
5321 }
5322 prev = 0xC040; /* set addr */
5323 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5324 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5325 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5326 if (res != 0) /* check result */
5327 {
5328 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5329
5330 return 1; /* return error */
5331 }
5332
5333 if (a_check_busy_pin(handle) != 0) /* check busy */
5334 {
5335 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5336
5337 return 1; /* return error */
5338 }
5339 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5340 if (res != 0) /* check result */
5341 {
5342 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5343
5344 return 1; /* return error */
5345 }
5346 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5347 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5348 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5349 *enable = (vs1053b_bool_t)((prev >> 2) & 0x01); /* get bool */
5350
5351 return 0; /* success return 0 */
5352}
5353
5366{
5367 uint8_t res;
5368 uint8_t buf[2];
5369 uint16_t prev;
5370 uint16_t prev2;
5371
5372 if (handle == NULL) /* check handle */
5373 {
5374 return 2; /* return error */
5375 }
5376 if (handle->inited != 1) /* check handle initialization */
5377 {
5378 return 3; /* return error */
5379 }
5380
5381 if (a_check_busy_pin(handle) != 0) /* check busy */
5382 {
5383 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5384
5385 return 1; /* return error */
5386 }
5387 prev = 0xC040; /* set addr */
5388 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5389 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5390 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5391 if (res != 0) /* check result */
5392 {
5393 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5394
5395 return 1; /* return error */
5396 }
5397
5398 if (a_check_busy_pin(handle) != 0) /* check busy */
5399 {
5400 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5401
5402 return 1; /* return error */
5403 }
5404 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5405 if (res != 0) /* check result */
5406 {
5407 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5408
5409 return 1; /* return error */
5410 }
5411 prev2 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5412
5413 if (a_check_busy_pin(handle) != 0) /* check busy */
5414 {
5415 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5416
5417 return 1; /* return error */
5418 }
5419 prev = 0xC040; /* set addr */
5420 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5421 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5422 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5423 if (res != 0) /* check result */
5424 {
5425 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5426
5427 return 1; /* return error */
5428 }
5429
5430 if (a_check_busy_pin(handle) != 0) /* check busy */
5431 {
5432 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5433
5434 return 1; /* return error */
5435 }
5436 prev2 &= ~(3 << 0); /* clear settings */
5437 prev2 |= iis_rate << 0; /* set iis rate */
5438 buf[0] = (prev2 >> 8) & 0xFF; /* get msb */
5439 buf[1] = (prev2 >> 0) & 0xFF; /* get lsb */
5440 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, 2); /* write the ram */
5441 if (res != 0) /* check result */
5442 {
5443 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
5444
5445 return 1; /* return error */
5446 }
5447
5448 return 0; /* success return 0 */
5449}
5450
5463{
5464 uint8_t res;
5465 uint8_t buf[2];
5466 uint16_t prev;
5467
5468 if (handle == NULL) /* check handle */
5469 {
5470 return 2; /* return error */
5471 }
5472 if (handle->inited != 1) /* check handle initialization */
5473 {
5474 return 3; /* return error */
5475 }
5476
5477 if (a_check_busy_pin(handle) != 0) /* check busy */
5478 {
5479 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5480
5481 return 1; /* return error */
5482 }
5483 prev = 0xC040; /* set addr */
5484 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5485 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5486 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5487 if (res != 0) /* check result */
5488 {
5489 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5490
5491 return 1; /* return error */
5492 }
5493
5494 if (a_check_busy_pin(handle) != 0) /* check busy */
5495 {
5496 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5497
5498 return 1; /* return error */
5499 }
5500 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5501 if (res != 0) /* check result */
5502 {
5503 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5504
5505 return 1; /* return error */
5506 }
5507 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5508 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5509 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5510 *iis_rate= (vs1053b_iis_rate_t)((prev >> 0) & 0x03); /* get iis rate */
5511
5512 return 0; /* success return 0 */
5513}
5514
5526uint8_t vs1053b_set_gpio_direction(vs1053b_handle_t *handle, uint16_t mask)
5527{
5528 uint8_t res;
5529 uint8_t buf[2];
5530 uint16_t prev;
5531 uint16_t prev2;
5532
5533 if (handle == NULL) /* check handle */
5534 {
5535 return 2; /* return error */
5536 }
5537 if (handle->inited != 1) /* check handle initialization */
5538 {
5539 return 3; /* return error */
5540 }
5541
5542 if (a_check_busy_pin(handle) != 0) /* check busy */
5543 {
5544 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5545
5546 return 1; /* return error */
5547 }
5548 prev = 0xC017; /* set addr */
5549 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5550 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5551 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5552 if (res != 0) /* check result */
5553 {
5554 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5555
5556 return 1; /* return error */
5557 }
5558
5559 if (a_check_busy_pin(handle) != 0) /* check busy */
5560 {
5561 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5562
5563 return 1; /* return error */
5564 }
5565 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5566 if (res != 0) /* check result */
5567 {
5568 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5569
5570 return 1; /* return error */
5571 }
5572 prev2 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5573
5574 if (a_check_busy_pin(handle) != 0) /* check busy */
5575 {
5576 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5577
5578 return 1; /* return error */
5579 }
5580 prev = 0xC017; /* set addr */
5581 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5582 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5583 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5584 if (res != 0) /* check result */
5585 {
5586 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5587
5588 return 1; /* return error */
5589 }
5590
5591 if (a_check_busy_pin(handle) != 0) /* check busy */
5592 {
5593 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5594
5595 return 1; /* return error */
5596 }
5597 prev2 &= ~(0x3FF); /* clear settings */
5598 prev2 |= mask; /* set mask */
5599 buf[0] = (prev2 >> 8) & 0xFF; /* get msb */
5600 buf[1] = (prev2 >> 0) & 0xFF; /* get lsb */
5601 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, 2); /* write the ram */
5602 if (res != 0) /* check result */
5603 {
5604 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
5605
5606 return 1; /* return error */
5607 }
5608
5609 return 0; /* success return 0 */
5610}
5611
5623uint8_t vs1053b_get_gpio_direction(vs1053b_handle_t *handle, uint16_t *mask)
5624{
5625 uint8_t res;
5626 uint8_t buf[2];
5627 uint16_t prev;
5628
5629 if (handle == NULL) /* check handle */
5630 {
5631 return 2; /* return error */
5632 }
5633 if (handle->inited != 1) /* check handle initialization */
5634 {
5635 return 3; /* return error */
5636 }
5637
5638 if (a_check_busy_pin(handle) != 0) /* check busy */
5639 {
5640 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5641
5642 return 1; /* return error */
5643 }
5644 prev = 0xC017; /* set addr */
5645 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5646 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5647 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5648 if (res != 0) /* check result */
5649 {
5650 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5651
5652 return 1; /* return error */
5653 }
5654
5655 if (a_check_busy_pin(handle) != 0) /* check busy */
5656 {
5657 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5658
5659 return 1; /* return error */
5660 }
5661 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5662 if (res != 0) /* check result */
5663 {
5664 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5665
5666 return 1; /* return error */
5667 }
5668 *mask = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5669
5670 return 0; /* success return 0 */
5671}
5672
5684uint8_t vs1053b_get_gpio_input(vs1053b_handle_t *handle, uint16_t *data)
5685{
5686 uint8_t res;
5687 uint8_t buf[2];
5688 uint16_t prev;
5689
5690 if (handle == NULL) /* check handle */
5691 {
5692 return 2; /* return error */
5693 }
5694 if (handle->inited != 1) /* check handle initialization */
5695 {
5696 return 3; /* return error */
5697 }
5698
5699 if (a_check_busy_pin(handle) != 0) /* check busy */
5700 {
5701 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5702
5703 return 1; /* return error */
5704 }
5705 prev = 0xC018; /* set addr */
5706 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5707 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5708 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5709 if (res != 0) /* check result */
5710 {
5711 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5712
5713 return 1; /* return error */
5714 }
5715
5716 if (a_check_busy_pin(handle) != 0) /* check busy */
5717 {
5718 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5719
5720 return 1; /* return error */
5721 }
5722 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5723 if (res != 0) /* check result */
5724 {
5725 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5726
5727 return 1; /* return error */
5728 }
5729 *data = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5730
5731 return 0; /* success return 0 */
5732}
5733
5745uint8_t vs1053b_set_gpio_output(vs1053b_handle_t *handle, uint16_t data)
5746{
5747 uint8_t res;
5748 uint8_t buf[2];
5749 uint16_t prev;
5750 uint16_t prev2;
5751
5752 if (handle == NULL) /* check handle */
5753 {
5754 return 2; /* return error */
5755 }
5756 if (handle->inited != 1) /* check handle initialization */
5757 {
5758 return 3; /* return error */
5759 }
5760
5761 if (a_check_busy_pin(handle) != 0) /* check busy */
5762 {
5763 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5764
5765 return 1; /* return error */
5766 }
5767 prev = 0xC019; /* set addr */
5768 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5769 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5770 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5771 if (res != 0) /* check result */
5772 {
5773 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5774
5775 return 1; /* return error */
5776 }
5777
5778 if (a_check_busy_pin(handle) != 0) /* check busy */
5779 {
5780 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5781
5782 return 1; /* return error */
5783 }
5784 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5785 if (res != 0) /* check result */
5786 {
5787 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5788
5789 return 1; /* return error */
5790 }
5791 prev2 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5792
5793 if (a_check_busy_pin(handle) != 0) /* check busy */
5794 {
5795 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5796
5797 return 1; /* return error */
5798 }
5799 prev = 0xC019; /* set addr */
5800 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5801 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5802 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5803 if (res != 0) /* check result */
5804 {
5805 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5806
5807 return 1; /* return error */
5808 }
5809
5810 if (a_check_busy_pin(handle) != 0) /* check busy */
5811 {
5812 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5813
5814 return 1; /* return error */
5815 }
5816 prev2 &= ~(0x1FF); /* clear settings */
5817 prev2 |= data; /* set data */
5818 buf[0] = (prev2 >> 8) & 0xFF; /* get msb */
5819 buf[1] = (prev2 >> 0) & 0xFF; /* get lsb */
5820 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAM, buf, 2); /* write the ram */
5821 if (res != 0) /* check result */
5822 {
5823 handle->debug_print("vs1053b: write ram failed.\n"); /* write ram failed */
5824
5825 return 1; /* return error */
5826 }
5827
5828 return 0; /* success return 0 */
5829}
5830
5842uint8_t vs1053b_get_gpio_output(vs1053b_handle_t *handle, uint16_t *data)
5843{
5844 uint8_t res;
5845 uint8_t buf[2];
5846 uint16_t prev;
5847
5848 if (handle == NULL) /* check handle */
5849 {
5850 return 2; /* return error */
5851 }
5852 if (handle->inited != 1) /* check handle initialization */
5853 {
5854 return 3; /* return error */
5855 }
5856
5857 if (a_check_busy_pin(handle) != 0) /* check busy */
5858 {
5859 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5860
5861 return 1; /* return error */
5862 }
5863 prev = 0xC019; /* set addr */
5864 buf[0] = (prev >> 8) & 0xFF; /* get msb */
5865 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
5866 res = a_vs1053b_spi_write(handle, VS1053B_REG_WRAMADDR, buf, 2); /* write the ram addr */
5867 if (res != 0) /* check result */
5868 {
5869 handle->debug_print("vs1053b: write ram addr failed.\n"); /* write ram addr failed */
5870
5871 return 1; /* return error */
5872 }
5873
5874 if (a_check_busy_pin(handle) != 0) /* check busy */
5875 {
5876 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
5877
5878 return 1; /* return error */
5879 }
5880 res = a_vs1053b_spi_read(handle, VS1053B_REG_WRAM, buf, 2); /* read the ram */
5881 if (res != 0) /* check result */
5882 {
5883 handle->debug_print("vs1053b: read ram failed.\n"); /* read ram failed */
5884
5885 return 1; /* return error */
5886 }
5887 *data = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine data */
5888
5889 return 0; /* success return 0 */
5890}
5891
5903{
5904 if (handle == NULL) /* check handle */
5905 {
5906 return 2; /* return error */
5907 }
5908 if (handle->inited != 1) /* check handle initialization */
5909 {
5910 return 3; /* return error */
5911 }
5912
5913 handle->record_type = (uint8_t)(format); /* set record format */
5914
5915 return 0; /* success return 0 */
5916}
5917
5929{
5930 if (handle == NULL) /* check handle */
5931 {
5932 return 2; /* return error */
5933 }
5934 if (handle->inited != 1) /* check handle initialization */
5935 {
5936 return 3; /* return error */
5937 }
5938
5939 *format = (vs1053b_record_format_t)(handle->record_type); /* get record format */
5940
5941 return 0; /* success return 0 */
5942}
5943
5957{
5958 uint8_t res;
5959 uint8_t buf[2];
5960 uint16_t prev;
5961 uint16_t timeout;
5962
5963 if (handle == NULL) /* check handle */
5964 {
5965 return 2; /* return error */
5966 }
5967 if (handle->debug_print == NULL) /* check debug_print */
5968 {
5969 return 3; /* return error */
5970 }
5971 if (handle->spi_cmd_init == NULL) /* check spi_cmd_init */
5972 {
5973 handle->debug_print("vs1053b: spi_cmd_init is null.\n"); /* spi_cmd_init is null */
5974
5975 return 3; /* return error */
5976 }
5977 if (handle->spi_cmd_deinit == NULL) /* check spi_cmd_deinit */
5978 {
5979 handle->debug_print("vs1053b: spi_cmd_deinit is null.\n"); /* spi_cmd_deinit is null */
5980
5981 return 3; /* return error */
5982 }
5983 if (handle->spi_cmd_write_address16 == NULL) /* check spi_cmd_write_address16 */
5984 {
5985 handle->debug_print("vs1053b: spi_cmd_write_address16 is null.\n"); /* spi_cmd_write_address16 is null */
5986
5987 return 3; /* return error */
5988 }
5989 if (handle->spi_cmd_read_address16 == NULL) /* check spi_cmd_read_address16 */
5990 {
5991 handle->debug_print("vs1053b: spi_cmd_read_address16 is null.\n"); /* spi_cmd_read_address16 is null */
5992
5993 return 3; /* return error */
5994 }
5995 if (handle->spi_dat_init == NULL) /* check spi_dat_init */
5996 {
5997 handle->debug_print("vs1053b: spi_dat_init is null.\n"); /* spi_dat_init is null */
5998
5999 return 3; /* return error */
6000 }
6001 if (handle->spi_dat_deinit == NULL) /* check spi_dat_deinit */
6002 {
6003 handle->debug_print("vs1053b: spi_dat_deinit is null.\n"); /* spi_dat_deinit is null */
6004
6005 return 3; /* return error */
6006 }
6007 if (handle->spi_dat_write_cmd == NULL) /* check spi_dat_write_cmd */
6008 {
6009 handle->debug_print("vs1053b: spi_dat_write_cmd is null.\n"); /* spi_dat_write_cmd is null */
6010
6011 return 3; /* return error */
6012 }
6013 if (handle->reset_gpio_init == NULL) /* check reset_gpio_init */
6014 {
6015 handle->debug_print("vs1053b: reset_gpio_init is null.\n"); /* reset_gpio_init is null */
6016
6017 return 3; /* return error */
6018 }
6019 if (handle->reset_gpio_deinit == NULL) /* check reset_gpio_deinit */
6020 {
6021 handle->debug_print("vs1053b: reset_gpio_deinit is null.\n"); /* reset_gpio_deinit is null */
6022
6023 return 3; /* return error */
6024 }
6025 if (handle->reset_gpio_write == NULL) /* check reset_gpio_write */
6026 {
6027 handle->debug_print("vs1053b: reset_gpio_write is null.\n"); /* reset_gpio_write is null */
6028
6029 return 3; /* return error */
6030 }
6031 if (handle->dreq_gpio_init == NULL) /* check dreq_gpio_init */
6032 {
6033 handle->debug_print("vs1053b: dreq_gpio_init is null.\n"); /* dreq_gpio_init is null */
6034
6035 return 3; /* return error */
6036 }
6037 if (handle->dreq_gpio_deinit == NULL) /* check dreq_gpio_deinit */
6038 {
6039 handle->debug_print("vs1053b: dreq_gpio_deinit is null.\n"); /* dreq_gpio_deinit is null */
6040
6041 return 3; /* return error */
6042 }
6043 if (handle->dreq_gpio_read == NULL) /* check dreq_gpio_read */
6044 {
6045 handle->debug_print("vs1053b: dreq_gpio_read is null.\n"); /* dreq_gpio_read is null */
6046
6047 return 3; /* return error */
6048 }
6049 if (handle->audio_init == NULL) /* check audio_init */
6050 {
6051 handle->debug_print("vs1053b: audio_init is null.\n"); /* audio_init is null */
6052
6053 return 3; /* return error */
6054 }
6055 if (handle->audio_deinit == NULL) /* check audio_deinit */
6056 {
6057 handle->debug_print("vs1053b: audio_deinit is null.\n"); /* audio_deinit is null */
6058
6059 return 3; /* return error */
6060 }
6061 if (handle->audio_read == NULL) /* check audio_read */
6062 {
6063 handle->debug_print("vs1053b: audio_read is null.\n"); /* audio_read is null */
6064
6065 return 3; /* return error */
6066 }
6067 if (handle->audio_write == NULL) /* check audio_write */
6068 {
6069 handle->debug_print("vs1053b: audio_write is null.\n"); /* audio_write is null */
6070
6071 return 3; /* return error */
6072 }
6073 if (handle->timestamp_read == NULL) /* check timestamp_read */
6074 {
6075 handle->debug_print("vs1053b: timestamp_read is null.\n"); /* timestamp_read is null */
6076
6077 return 3; /* return error */
6078 }
6079 if (handle->delay_ms == NULL) /* check delay_ms */
6080 {
6081 handle->debug_print("vs1053b: delay_ms is null.\n"); /* delay_ms is null */
6082
6083 return 3; /* return error */
6084 }
6085 if (handle->receive_callback == NULL) /* check receive_callback */
6086 {
6087 handle->debug_print("vs1053b: receive_callback is null.\n"); /* receive_callback is null */
6088
6089 return 3; /* return error */
6090 }
6091
6092 if (handle->reset_gpio_init() != 0) /* reset gpio init */
6093 {
6094 handle->debug_print("vs1053b: reset gpio init failed.\n"); /* reset gpio init failed */
6095
6096 return 4; /* return error */
6097 }
6098 if (handle->dreq_gpio_init() != 0) /* dreq gpio init */
6099 {
6100 handle->debug_print("vs1053b: dreq gpio init failed.\n"); /* dreq gpio init failed */
6101 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6102
6103 return 4; /* return error */
6104 }
6105 if (handle->spi_cmd_init() != 0) /* spi cmd init */
6106 {
6107 handle->debug_print("vs1053b: spi cmd init failed.\n"); /* spi cmd init failed */
6108 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6109 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6110
6111 return 1; /* return error */
6112 }
6113 if (handle->spi_dat_init() != 0) /* spi dat init failed */
6114 {
6115 handle->debug_print("vs1053b: spi dat init failed.\n"); /* spi dat init failed */
6116 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6117 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6118 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6119
6120 return 1; /* return error */
6121 }
6122
6123 res = handle->reset_gpio_write(0); /* set low */
6124 if (res != 0) /* check result */
6125 {
6126 handle->debug_print("vs1053b: reset gpio write failed.\n"); /* reset gpio write failed */
6127 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6128 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6129 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6130 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6131
6132 return 5; /* return error */
6133 }
6134 handle->delay_ms(20); /* delay 20ms */
6135 res = handle->reset_gpio_write(1); /* set high */
6136 if (res != 0) /* check result */
6137 {
6138 handle->debug_print("vs1053b: reset gpio write failed.\n"); /* reset gpio write failed */
6139 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6140 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6141 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6142 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6143
6144 return 5; /* return error */
6145 }
6146
6147 if (a_check_busy_pin(handle) != 0) /* check busy */
6148 {
6149 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6150 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6151 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6152 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6153 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6154
6155 return 5; /* return error */
6156 }
6157 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
6158 if (res != 0) /* check result */
6159 {
6160 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
6161 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6162 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6163 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6164 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6165
6166 return 5; /* return error */
6167 }
6168 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6169 prev &= ~(1 << 2); /* clear the settings */
6170 prev |= 1 << 2; /* set the config */
6171 buf[0] = (prev >> 8) & 0xFF; /* get msb */
6172 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
6173 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
6174 if (res != 0) /* check result */
6175 {
6176 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
6177 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6178 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6179 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6180 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6181
6182 return 5; /* return error */
6183 }
6184
6185 if (a_check_busy_pin(handle) != 0) /* check busy */
6186 {
6187 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6188 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6189 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6190 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6191 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6192
6193 return 5; /* return error */
6194 }
6195 timeout = 1000; /* timeout 1000ms */
6196 while (timeout != 0) /* check timeout */
6197 {
6198 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
6199 if (res != 0) /* check result */
6200 {
6201 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
6202 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6203 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6204 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6205 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6206
6207 return 5; /* return error */
6208 }
6209 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6210 if (((prev >> 2) & 0x01) == 0) /* check flag */
6211 {
6212 break; /* break */
6213 }
6214 timeout--; /* timeout */
6215 handle->delay_ms(1); /* delay 1ms */
6216 }
6217 if (timeout == 0) /* check timeout */
6218 {
6219 handle->debug_print("vs1053b: reset failed.\n"); /* chip is busy */
6220 (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
6221 (void)handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6222 (void)handle->spi_cmd_deinit(); /* spi cmd deinit */
6223 (void)handle->spi_dat_deinit(); /* spi dat deinit */
6224
6225 return 5; /* return error */
6226 }
6227 handle->period = 0; /* init 0 */
6228 handle->period_enable = 0; /* init 0 */
6229 handle->timestamp = 0; /* init 0 */
6230 handle->status = VS1053B_STATUS_STOP; /* no working */
6231 handle->pause = 0; /* no pause */
6232 handle->cur_pos = 0; /* current position */
6233 handle->buf_pos = 0; /* buffer position */
6234 handle->size = 0; /* total size */
6235 handle->record_type = 0; /* init record type */
6236 handle->plugin_patch_type = 0; /* plugin patch type */
6237 handle->inited = 1; /* flag finish initialization */
6238
6239 return 0; /* success return 0 */
6240}
6241
6254{
6255 uint8_t res;
6256
6257 if (handle == NULL) /* check handle */
6258 {
6259 return 2; /* return error */
6260 }
6261 if (handle->inited != 1) /* check handle initialization */
6262 {
6263 return 3; /* return error */
6264 }
6265
6266 res = handle->reset_gpio_write(0); /* set low */
6267 if (res != 0) /* check result */
6268 {
6269 handle->debug_print("vs1053b: reset gpio write failed.\n"); /* reset gpio write failed */
6270
6271 return 4; /* return error */
6272 }
6273 handle->delay_ms(20); /* delay 20ms */
6274 res = handle->reset_gpio_write(1); /* set high */
6275 if (res != 0) /* check result */
6276 {
6277 handle->debug_print("vs1053b: reset gpio write failed.\n"); /* reset gpio write failed */
6278
6279 return 4; /* return error */
6280 }
6281
6282 res = handle->spi_cmd_deinit(); /* spi cmd deinit */
6283 if (res != 0) /* check result */
6284 {
6285 handle->debug_print("vs1053b: spi cmd deinit failed.\n"); /* spi cmd deinit failed */
6286
6287 return 1; /* return error */
6288 }
6289 res = handle->spi_dat_deinit(); /* spi dat deinit */
6290 if (res != 0) /* check result */
6291 {
6292 handle->debug_print("vs1053b: spi dat deinit failed.\n"); /* spi dat deinit failed */
6293
6294 return 1; /* return error */
6295 }
6296 res = handle->dreq_gpio_deinit(); /* dreq gpio deinit */
6297 if (res != 0) /* check result */
6298 {
6299 handle->debug_print("vs1053b: dreq gpio deinit failed.\n"); /* dreq gpio deinit failed */
6300
6301 return 1; /* return error */
6302 }
6303 res = handle->reset_gpio_deinit(); /* reset gpio deinit */
6304 if (res != 0) /* check result */
6305 {
6306 handle->debug_print("vs1053b: reset gpio deinit failed.\n"); /* reset gpio deinit failed */
6307
6308 return 1; /* return error */
6309 }
6310 handle->inited = 0; /* flag close */
6311
6312 return 0; /* success return 0 */
6313}
6314
6328{
6329 uint8_t res;
6330 uint8_t buf[2];
6331
6332 if (handle == NULL) /* check handle */
6333 {
6334 return 2; /* return error */
6335 }
6336 if (handle->inited != 1) /* check handle initialization */
6337 {
6338 return 3; /* return error */
6339 }
6340
6341 if (handle->status == VS1053B_STATUS_STOP) /* check status */
6342 {
6343 return 4; /* not working */
6344 }
6345 else if (handle->status == VS1053B_STATUS_PLAY) /* play */
6346 {
6347 a_period(handle); /* run period callback */
6348 if ((handle->pause != 0) || (handle->status == VS1053B_STATUS_STOP)) /* if pause and return */
6349 {
6350 return 0; /* success return 0 */
6351 }
6352 if (a_check_busy_pin(handle) == 0) /* if not busy */
6353 {
6354 if (handle->cur_pos >= handle->buf_pos) /* check buffer */
6355 {
6356 res = handle->audio_read(handle->cur_pos,
6357 VS1053B_BUFFER_SIZE, handle->buf); /* read buffer */
6358 if (res != 0) /* check result */
6359 {
6360 handle->debug_print("vs1053b: audio read failed.\n"); /* audio read failed */
6361
6362 return 1; /* return error */
6363 }
6364 handle->buf_pos += VS1053B_BUFFER_SIZE; /* add pos */
6365 if (handle->receive_callback != NULL) /* check not null */
6366 {
6368 handle->cur_pos); /* run callback */
6369 }
6370 }
6371 if (handle->spi_dat_write_cmd(handle->buf +
6372 (handle->cur_pos %
6373 VS1053B_BUFFER_SIZE), 32) != 0) /* push data */
6374 {
6375 handle->debug_print("vs1053b: fill buffer failed.\n"); /* fill buffer failed */
6376
6377 return 1; /* return error */
6378 }
6379 handle->cur_pos += 32; /* current position +32 */
6380 if (handle->receive_callback != NULL) /* check not null */
6381 {
6383 handle->cur_pos); /* run callback */
6384 }
6385 if (handle->cur_pos >= handle->size) /* check end */
6386 {
6387 if (a_vs1053b_stop(handle) != 0) /* stop audio */
6388 {
6389 return 1; /* return error */
6390 }
6391 if (handle->audio_deinit() != 0) /* audio deinit */
6392 {
6393 handle->debug_print("vs1053b: audio deinit failed.\n"); /* audio deinit failed */
6394
6395 return 1; /* return error */
6396 }
6397 handle->status = VS1053B_STATUS_STOP; /* set not working */
6398 if (handle->receive_callback != NULL) /* check not null */
6399 {
6401 handle->cur_pos); /* run callback */
6402 }
6403 }
6404 }
6405
6406 return 0; /* success return 0 */
6407 }
6408 else if (handle->status == VS1053B_STATUS_RECORD) /* record */
6409 {
6410 if (handle->record_type != 0) /* ogg */
6411 {
6412 uint8_t b[2];
6413 uint16_t i;
6414 uint16_t j;
6415 uint16_t l;
6416 uint16_t dat1;
6417
6418 a_period(handle); /* run period callback */
6419 if ((handle->pause != 0) || (handle->status == VS1053B_STATUS_STOP)) /* if pause and return */
6420 {
6421 return 0; /* success return 0 */
6422 }
6423
6424 if (a_check_busy_pin(handle) != 0) /* check busy */
6425 {
6426 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6427
6428 return 1; /* return error */
6429 }
6430 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
6431 if (res != 0) /* check result */
6432 {
6433 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6434
6435 return 1; /* return error */
6436 }
6437 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6438 while (dat1 >= 256) /* check length */
6439 {
6440 l = MIN(dat1, 256); /* get min */
6441 dat1 -= l; /* dat1 - length */
6442 i = 0; /* init 0 */
6443 for (j = 0; j < l; j++) /* loop all */
6444 {
6445 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
6446 if (res != 0) /* check result */
6447 {
6448 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
6449
6450 return 1; /* return error */
6451 }
6452 handle->buf[i++] = buf[0]; /* save low part */
6453 handle->buf[i++] = buf[1]; /* save high part */
6454 }
6455 if (handle->receive_callback != NULL) /* check not null */
6456 {
6458 handle->cur_pos); /* run callback */
6459 }
6460 res = handle->audio_write(handle->cur_pos, l * 2, handle->buf); /* write buffer */
6461 if (res != 0) /* check result */
6462 {
6463 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
6464
6465 return 1; /* return error */
6466 }
6467 handle->cur_pos += l * 2; /* add bytes */
6468 if (handle->receive_callback != NULL) /* check not null */
6469 {
6471 handle->cur_pos); /* run callback */
6472 }
6473 if (l < 256) /* check 256 */
6474 {
6475 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, b, 2); /* read the hdat0 */
6476 if (res != 0) /* check result */
6477 {
6478 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
6479
6480 return 1; /* return error */
6481 }
6482 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL3, buf, 2); /* read the aictrl3 */
6483 if (res != 0) /* check result */
6484 {
6485 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6486
6487 return 1; /* return error */
6488 }
6489 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL3, buf, 2); /* read the aictrl3 */
6490 if (res != 0) /* check result */
6491 {
6492 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6493
6494 return 1; /* return error */
6495 }
6496 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6497 if (!(dat1 & (1 << 2)))
6498 {
6499 res = handle->audio_write(handle->cur_pos, 2, b); /* write buffer */
6500 if (res != 0) /* check result */
6501 {
6502 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
6503
6504 return 1; /* return error */
6505 }
6506 handle->cur_pos += 2; /* add bytes */
6507 }
6508 else
6509 {
6510 res = handle->audio_write(handle->cur_pos, 1, b); /* write buffer */
6511 if (res != 0) /* check result */
6512 {
6513 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
6514
6515 return 1; /* return error */
6516 }
6517 handle->cur_pos += 1; /* add bytes */
6518 }
6519 }
6520 }
6521
6522 return 0; /* success return 0 */
6523 }
6524 else /* wav */
6525 {
6526 uint16_t i;
6527 uint16_t dat1;
6528
6529 a_period(handle); /* run period callback */
6530 if ((handle->pause != 0) || (handle->status == VS1053B_STATUS_STOP)) /* if pause and return */
6531 {
6532 return 0; /* success return 0 */
6533 }
6534
6535 if (a_check_busy_pin(handle) != 0) /* check busy */
6536 {
6537 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6538
6539 return 1; /* return error */
6540 }
6541 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
6542 if (res != 0) /* check result */
6543 {
6544 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6545
6546 return 1; /* return error */
6547 }
6548 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6549 if ((dat1 >= 256) && (dat1 < 896)) /* check range */
6550 {
6551 i = 0; /* init 0 */
6552 while (i < 512) /* 512 bytes */
6553 {
6554 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
6555 if (res != 0) /* check result */
6556 {
6557 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
6558
6559 return 1; /* return error */
6560 }
6561 handle->buf[i++] = buf[1]; /* save low part */
6562 handle->buf[i++] = buf[0]; /* save high part */
6563 }
6564 if (handle->receive_callback != NULL) /* check not null */
6565 {
6567 handle->cur_pos); /* run callback */
6568 }
6569 res = handle->audio_write(handle->cur_pos, 512, handle->buf); /* write buffer */
6570 if (res != 0) /* check result */
6571 {
6572 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
6573
6574 return 1; /* return error */
6575 }
6576 handle->cur_pos += 512; /* add 512 bytes */
6577 if (handle->receive_callback != NULL) /* check not null */
6578 {
6580 handle->cur_pos); /* run callback */
6581 }
6582 }
6583 else if (dat1 >= 896)
6584 {
6585 i = 0; /* init 0 */
6586 while (i < 512) /* 512 bytes */
6587 {
6588 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
6589 if (res != 0) /* check result */
6590 {
6591 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
6592
6593 return 1; /* return error */
6594 }
6595 handle->buf[i++] = buf[1]; /* save low part */
6596 handle->buf[i++] = buf[0]; /* save high part */
6597 }
6598 if (handle->receive_callback != NULL) /* check not null */
6599 {
6601 handle->cur_pos); /* run callback */
6602 }
6603 if (handle->receive_callback != NULL) /* check not null */
6604 {
6606 handle->cur_pos); /* run callback */
6607 }
6608 handle->debug_print("vs1053b: buffer is over.\n"); /* buffer is over */
6609 }
6610 else
6611 {
6612 /* do nothing */
6613 }
6614
6615 return 0; /* success return 0 */
6616 }
6617 }
6618 else
6619 {
6620 handle->debug_print("vs1053b: status is invalid.\n"); /* status is invalid */
6621
6622 return 5; /* return error */
6623 }
6624}
6625
6637{
6638 if (handle == NULL) /* check handle */
6639 {
6640 return 2; /* return error */
6641 }
6642 if (handle->inited != 1) /* check handle initialization */
6643 {
6644 return 3; /* return error */
6645 }
6646 if (handle->status != 0) /* check played */
6647 {
6648 handle->debug_print("vs1053b: audio working.\n"); /* audio working */
6649
6650 return 4; /* return error */
6651 }
6652
6653 handle->pause = 1; /* flag paused */
6654
6655 return 0; /* success return 0 */
6656}
6657
6670uint8_t vs1053b_play(vs1053b_handle_t *handle, char *path)
6671{
6672 uint8_t res;
6673 uint32_t sec;
6674 uint32_t us;
6675
6676 if (handle == NULL) /* check handle */
6677 {
6678 return 2; /* return error */
6679 }
6680 if (handle->inited != 1) /* check handle initialization */
6681 {
6682 return 3; /* return error */
6683 }
6684 if (handle->status != 0) /* check played */
6685 {
6686 handle->debug_print("vs1053b: audio working.\n"); /* audio working */
6687
6688 return 4; /* return error */
6689 }
6690
6691 if (handle->pause != 0) /* if pause and return */
6692 {
6693 handle->pause = 0; /* recover */
6694
6695 return 0; /* success return 0 */
6696 }
6697
6698 res = a_vs1053b_stop(handle); /* stop playing */
6699 if (res != 0) /* check result */
6700 {
6701 return 1; /* return error */
6702 }
6703 res = handle->audio_init(0, path, &handle->size); /* audio init */
6704 if (res != 0) /* check result */
6705 {
6706 handle->debug_print("vs1053b: audio init failed.\n"); /* audio init failed */
6707
6708 return 1; /* return error */
6709 }
6710 handle->timestamp_read(&sec, &us); /* read timestamp */
6711 handle->timestamp = (((uint64_t)sec) * 1000000 + ((uint64_t)us)); /* set timestamp */
6712 handle->cur_pos = 0; /* current position */
6713 handle->buf_pos = 0; /* buffer position */
6714 handle->status = VS1053B_STATUS_PLAY; /* active play */
6715
6716 return 0; /* success return 0 */
6717}
6718
6733uint8_t vs1053b_record(vs1053b_handle_t *handle, char *path, uint32_t sample_rate)
6734{
6735 uint8_t res;
6736 uint8_t buf[2];
6737 uint32_t sec;
6738 uint32_t us;
6739
6740 if (handle == NULL) /* check handle */
6741 {
6742 return 2; /* return error */
6743 }
6744 if (handle->inited != 1) /* check handle initialization */
6745 {
6746 return 3; /* return error */
6747 }
6748 if (handle->status != 0) /* check played */
6749 {
6750 handle->debug_print("vs1053b: audio working.\n"); /* audio working */
6751
6752 return 4; /* return error */
6753 }
6754
6755 if (handle->pause != 0) /* if pause and return */
6756 {
6757 handle->pause = 0; /* recover */
6758
6759 return 0; /* success return 0 */
6760 }
6761
6762 res = handle->audio_init(1, path, &handle->size); /* audio init */
6763 if (res != 0) /* check result */
6764 {
6765 handle->debug_print("vs1053b: audio init failed.\n"); /* audio init failed */
6766
6767 return 1; /* return error */
6768 }
6769 if (handle->record_type != 0) /* ogg */
6770 {
6771 if ((handle->plugin_patch_type >= 0x02) &&
6772 (handle->plugin_patch_type <= 0x0C)) /* 8000hz */
6773 {
6774 if (sample_rate != 8000) /* check sample rate */
6775 {
6776 handle->debug_print("vs1053b: sample rate "
6777 "doesn't match path.\n"); /* sample rate doesn't match patch */
6778
6779 return 5; /* return error */
6780 }
6781 }
6782 else if ((handle->plugin_patch_type >= 0x0D) &&
6783 (handle->plugin_patch_type <= 0x22)) /* 16000hz */
6784 {
6785 if (sample_rate != 16000) /* check sample rate */
6786 {
6787 handle->debug_print("vs1053b: sample rate "
6788 "doesn't match path.\n"); /* sample rate doesn't match patch */
6789
6790 return 5; /* return error */
6791 }
6792 }
6793 else if ((handle->plugin_patch_type >= 0x23) &&
6794 (handle->plugin_patch_type <= 0x2E)) /* 44100hz */
6795 {
6796 if (sample_rate != 44100) /* check sample rate */
6797 {
6798 handle->debug_print("vs1053b: sample rate "
6799 "doesn't match path.\n"); /* sample rate doesn't match patch */
6800
6801 return 5; /* return error */
6802 }
6803 }
6804 else
6805 {
6806 handle->debug_print("vs1053b: sample rate "
6807 "doesn't match path.\n"); /* sample rate doesn't match patch */
6808
6809 return 5; /* return error */
6810 }
6811
6812 if (a_check_busy_pin(handle) != 0) /* check busy */
6813 {
6814 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6815
6816 return 1; /* return error */
6817 }
6818 buf[0] = 0x00; /* set msb */
6819 buf[1] = 0x34; /* set lsb */
6820 res = a_vs1053b_spi_write(handle, VS1053B_REG_AIADDR, buf, 2); /* write aiaddr */
6821 if (res != 0) /* check result */
6822 {
6823 handle->debug_print("vs1053b: write aiaddr failed.\n"); /* write aiaddr failed */
6824
6825 return 1; /* return error */
6826 }
6827 handle->cur_pos = 0; /* current position */
6828 }
6829 else /* wav */
6830 {
6831 handle->wav.chunk_id[0] = 'R'; /* R */
6832 handle->wav.chunk_id[1] = 'I'; /* I */
6833 handle->wav.chunk_id[2] = 'F'; /* F */
6834 handle->wav.chunk_id[3] = 'F'; /* F */
6835 handle->wav.chunk_size = 0x00000000; /* init 0 */
6836 handle->wav.format[0] = 'W'; /* W */
6837 handle->wav.format[1] = 'A'; /* A */
6838 handle->wav.format[2] = 'V'; /* V */
6839 handle->wav.format[3] = 'E'; /* E */
6840 handle->wav.sub_chunk1_id[0] = 'f'; /* f */
6841 handle->wav.sub_chunk1_id[1] = 'm'; /* m */
6842 handle->wav.sub_chunk1_id[2] = 't'; /* t */
6843 handle->wav.sub_chunk1_id[3] = 0x20; /* 0x20 */
6844 handle->wav.sub_chunk1_size = 16; /* 16 bytes */
6845 handle->wav.audio_format = 0x01; /* pcm */
6846 handle->wav.num_channel = 1; /* 1 channel */
6847 handle->wav.sample_rate = sample_rate; /* set sample rate */
6848 handle->wav.byte_rate = handle->wav.sample_rate * 2; /* double */
6849 handle->wav.block_align = 2; /* 2 bytes */
6850 handle->wav.bit_per_sample = 16; /* 16 bits */
6851 handle->wav.sub_chunk2_id[0] = 'd'; /* d */
6852 handle->wav.sub_chunk2_id[1] = 'a'; /* a */
6853 handle->wav.sub_chunk2_id[2] = 't'; /* t */
6854 handle->wav.sub_chunk2_id[3] = 'a'; /* a */
6855 handle->wav.sub_chunk2_size = 0x00000000; /* init 0 */
6856 if (a_vs1053b_write_wav_header(handle, &handle->wav) != 0) /* write wav header */
6857 {
6858 return 1; /* return error */
6859 }
6860 handle->cur_pos = 44; /* current position */
6861 }
6862 handle->timestamp_read(&sec, &us); /* read timestamp */
6863 handle->timestamp = (((uint64_t)sec) * 1000000 + ((uint64_t)us)); /* set timestamp */
6864 handle->buf_pos = 0; /* buffer position */
6865 handle->status = VS1053B_STATUS_RECORD; /* active record */
6866
6867 return 0; /* success return 0 */
6868}
6869
6883{
6884 uint8_t res;
6885 uint8_t buf[2];
6886 uint16_t prev;
6887
6888 if (handle == NULL) /* check handle */
6889 {
6890 return 2; /* return error */
6891 }
6892 if (handle->inited != 1) /* check handle initialization */
6893 {
6894 return 3; /* return error */
6895 }
6896 if (handle->status == 0) /* check played */
6897 {
6898 handle->debug_print("vs1053b: audio not working.\n"); /* audio not working */
6899
6900 return 4; /* return error */
6901 }
6902
6903 if (handle->status == 1) /* play */
6904 {
6905 if (a_vs1053b_stop(handle) != 0) /* stop audio */
6906 {
6907 return 1; /* return error */
6908 }
6909 if (handle->audio_deinit() != 0) /* audio deinit */
6910 {
6911 handle->debug_print("vs1053b: audio deinit failed.\n"); /* audio deinit failed */
6912
6913 return 1; /* return error */
6914 }
6915 handle->status = VS1053B_STATUS_STOP; /* set not working */
6916 if (handle->receive_callback != NULL) /* check not null */
6917 {
6919 handle->cur_pos); /* run callback */
6920 }
6921
6922 return 0; /* success return 0 */
6923 }
6924 else if (handle->status == 2) /* record */
6925 {
6926 if ((handle->pause != 0) || (handle->status == VS1053B_STATUS_STOP)) /* if pause and return */
6927 {
6928 return 0; /* success return 0 */
6929 }
6930
6931 if (handle->record_type != 0) /* ogg */
6932 {
6933 uint8_t b[2];
6934 uint16_t i;
6935 uint16_t j;
6936 uint16_t l;
6937 uint16_t ll;
6938 uint16_t dat1;
6939
6940 if (a_check_busy_pin(handle) != 0) /* check busy */
6941 {
6942 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6943
6944 return 1; /* return error */
6945 }
6946 buf[0] = 0x00; /* 0x00 */
6947 buf[1] = 0x01; /* 0x01 */
6948 res = a_vs1053b_spi_write(handle, VS1053B_REG_AICTRL3, buf, 2); /* read the aictrl3 */
6949 if (res != 0) /* check result */
6950 {
6951 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6952
6953 return 1; /* return error */
6954 }
6955
6956 if (a_check_busy_pin(handle) != 0) /* check busy */
6957 {
6958 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6959
6960 return 1; /* return error */
6961 }
6962 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
6963 if (res != 0) /* check result */
6964 {
6965 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6966
6967 return 1; /* return error */
6968 }
6969 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6970
6971 if (a_check_busy_pin(handle) != 0) /* check busy */
6972 {
6973 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6974
6975 return 1; /* return error */
6976 }
6977 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL3, buf, 2); /* read the aictrl3 */
6978 if (res != 0) /* check result */
6979 {
6980 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6981
6982 return 1; /* return error */
6983 }
6984 ll = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
6985 if ((ll & (1 << 1)) != 0) /* check next state*/
6986 {
6987 if (a_check_busy_pin(handle) != 0) /* check busy */
6988 {
6989 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
6990
6991 return 1; /* return error */
6992 }
6993 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT1, buf, 2); /* read the hdat1 */
6994 if (res != 0) /* check result */
6995 {
6996 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
6997
6998 return 1; /* return error */
6999 }
7000 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
7001 }
7002
7003 while (dat1 >= 256) /* check length */
7004 {
7005 l = MIN(dat1, 256); /* get min */
7006 dat1 -= l; /* dat1 - length */
7007 if (((ll & (1 << 1)) != 0) && (!dat1)) /* check data */
7008 {
7009 l--; /* length-- */
7010 }
7011 i = 0; /* init 0 */
7012 for (j = 0; j < l; j++) /* loop all */
7013 {
7014 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, buf, 2); /* read the hdat0 */
7015 if (res != 0) /* check result */
7016 {
7017 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
7018
7019 return 1; /* return error */
7020 }
7021 handle->buf[i++] = buf[0]; /* save low part */
7022 handle->buf[i++] = buf[1]; /* save high part */
7023 }
7024 if (handle->receive_callback != NULL) /* check not null */
7025 {
7027 handle->cur_pos); /* run callback */
7028 }
7029 res = handle->audio_write(handle->cur_pos, l * 2, handle->buf); /* write buffer */
7030 if (res != 0) /* check result */
7031 {
7032 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
7033
7034 return 1; /* return error */
7035 }
7036 handle->cur_pos += l * 2; /* add bytes */
7037 if (handle->receive_callback != NULL) /* check not null */
7038 {
7040 handle->cur_pos); /* run callback */
7041 }
7042 if (l < 256) /* check 256 */
7043 {
7044 res = a_vs1053b_spi_read(handle, VS1053B_REG_HDAT0, b, 2); /* read the hdat0 */
7045 if (res != 0) /* check result */
7046 {
7047 handle->debug_print("vs1053b: read hdat0 failed.\n"); /* read hdat0 failed */
7048
7049 return 1; /* return error */
7050 }
7051 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL3, buf, 2); /* read the aictrl3 */
7052 if (res != 0) /* check result */
7053 {
7054 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
7055
7056 return 1; /* return error */
7057 }
7058 res = a_vs1053b_spi_read(handle, VS1053B_REG_AICTRL3, buf, 2); /* read the aictrl3 */
7059 if (res != 0) /* check result */
7060 {
7061 handle->debug_print("vs1053b: read hdat1 failed.\n"); /* read hdat1 failed */
7062
7063 return 1; /* return error */
7064 }
7065 dat1 = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
7066 if (!(dat1 & (1 << 2)))
7067 {
7068 res = handle->audio_write(handle->cur_pos, 2, b); /* write buffer */
7069 if (res != 0) /* check result */
7070 {
7071 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
7072
7073 return 1; /* return error */
7074 }
7075 handle->cur_pos += 2; /* add bytes */
7076 }
7077 else
7078 {
7079 res = handle->audio_write(handle->cur_pos, 1, b); /* write buffer */
7080 if (res != 0) /* check result */
7081 {
7082 handle->debug_print("vs1053b: audio write failed.\n"); /* audio write failed */
7083
7084 return 1; /* return error */
7085 }
7086 handle->cur_pos += 1; /* add bytes */
7087 }
7088 }
7089 }
7090 }
7091 else /* wav */
7092 {
7093 if (a_check_busy_pin(handle) != 0) /* check busy */
7094 {
7095 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
7096
7097 return 1; /* return error */
7098 }
7099
7100 res = a_vs1053b_spi_read(handle, VS1053B_REG_MODE, buf, 2); /* read the mode */
7101 if (res != 0) /* check result */
7102 {
7103 handle->debug_print("vs1053b: read mode failed.\n"); /* read mode failed */
7104
7105 return 1; /* return error */
7106 }
7107 prev = ((uint16_t)(buf[0]) << 8) | buf[1]; /* combine the config */
7108 prev &= ~(1 << 12); /* clear the settings */
7109 prev |= 0 << 12; /* set the config */
7110 buf[0] = (prev >> 8) & 0xFF; /* get msb */
7111 buf[1] = (prev >> 0) & 0xFF; /* get lsb */
7112 res = a_vs1053b_spi_write(handle, VS1053B_REG_MODE, buf, 2); /* write the mode */
7113 if (res != 0) /* check result */
7114 {
7115 handle->debug_print("vs1053b: write mode failed.\n"); /* write mode failed */
7116
7117 return 1; /* return error */
7118 }
7119 handle->wav.chunk_size = handle->cur_pos - 44 + 36; /* set chunk size */
7120 handle->wav.sub_chunk2_size = handle->cur_pos - 44; /* set sub chunk2 size */
7121 if (a_vs1053b_write_wav_header(handle, &handle->wav) != 0) /* write wav header */
7122 {
7123 return 1; /* return error */
7124 }
7125 }
7126 if (handle->audio_deinit() != 0) /* audio deinit */
7127 {
7128 handle->debug_print("vs1053b: audio deinit failed.\n"); /* audio deinit failed */
7129
7130 return 1; /* return error */
7131 }
7132 handle->status = VS1053B_STATUS_STOP; /* set not working */
7133 if (handle->receive_callback != NULL) /* check not null */
7134 {
7135 handle->receive_callback(VS1053B_TYPE_RECORD_END, handle->cur_pos); /* run callback */
7136 }
7137
7138 return 0; /* success return 0 */
7139 }
7140 else
7141 {
7142 handle->debug_print("vs1053b: status is invalid.\n"); /* status is invalid */
7143
7144 return 5; /* return error */
7145 }
7146}
7147
7159{
7160 uint8_t res;
7161
7162 if (handle == NULL) /* check handle */
7163 {
7164 return 2; /* return error */
7165 }
7166 if (handle->inited != 1) /* check handle initialization */
7167 {
7168 return 3; /* return error */
7169 }
7170
7171 res = handle->reset_gpio_write(0); /* set low */
7172 if (res != 0) /* check result */
7173 {
7174 handle->debug_print("vs1053b: reset gpio write failed.\n"); /* reset gpio write failed */
7175
7176 return 5; /* return error */
7177 }
7178 handle->delay_ms(20); /* delay 20ms */
7179 res = handle->reset_gpio_write(1); /* set high */
7180 if (res != 0) /* check result */
7181 {
7182 handle->debug_print("vs1053b: reset gpio write failed.\n"); /* reset gpio write failed */
7183
7184 return 5; /* return error */
7185 }
7186 if (a_check_busy_pin(handle) != 0) /* check busy */
7187 {
7188 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
7189
7190 return 5; /* return error */
7191 }
7192
7193 return 0; /* success return 0 */
7194}
7195
7208uint8_t vs1053b_set_period_callback(vs1053b_handle_t *handle, uint32_t second, uint32_t microsecond, vs1053b_bool_t enable)
7209{
7210 if (handle == NULL) /* check handle */
7211 {
7212 return 2; /* return error */
7213 }
7214 if (handle->inited != 1) /* check handle initialization */
7215 {
7216 return 3; /* return error */
7217 }
7218
7219 handle->period = (((uint64_t)second) * 1000000 + ((uint64_t)microsecond)); /* set period */
7220 handle->period_enable = enable; /* set period enable */
7221
7222 return 0; /* success return 0 */
7223}
7224
7237uint8_t vs1053b_get_period_callback(vs1053b_handle_t *handle, uint32_t *second, uint32_t *microsecond, vs1053b_bool_t *enable)
7238{
7239 if (handle == NULL) /* check handle */
7240 {
7241 return 2; /* return error */
7242 }
7243 if (handle->inited != 1) /* check handle initialization */
7244 {
7245 return 3; /* return error */
7246 }
7247
7248 *second = (handle->period / 1000000) & 0xFFFFFFFF; /* get second */
7249 *microsecond = (handle->period % 1000000) & 0xFFFFFFFF; /* get microsecond */
7250 *enable = (vs1053b_bool_t)(handle->period_enable); /* get period enable */
7251
7252 return 0; /* success return 0 */
7253}
7254
7267uint8_t vs1053b_parse_info(vs1053b_handle_t *handle, uint16_t dat0, uint16_t dat1, vs1053b_audio_info_t *info)
7268{
7269 const float bitrate[2][16]= {{0.0f, 8.0f, 16.0f, 24.0f, 32.0f, 40.0f, 48.0f, 56.0f, 64.0f,
7270 80.0f, 96.0f, 112.0f, 128.0f, 144.0f, 160.0f, 0.0f},
7271 {0.0f, 32.0f, 40.0f, 48.0f, 56.0f, 64.0f, 80.0f, 96.0f, 112.0f,
7272 128.0f, 160.0f, 192.0f, 224.0f, 256.0f, 320.0f, 0.0f}};
7273
7274 if (handle == NULL) /* check handle */
7275 {
7276 return 2; /* return error */
7277 }
7278 if (handle->inited != 1) /* check handle initialization */
7279 {
7280 return 3; /* return error */
7281 }
7282
7283 switch (dat1)
7284 {
7285 case VS1053B_FORMAT_WAV : /* wav */
7286 {
7287 info->format = VS1053B_FORMAT_WAV; /* set wav format */
7288 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7289 strncpy(info->format_name, "wav", 32); /* copy name */
7290 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get wav kbps */
7291
7292 break; /* break */
7293 }
7294 case VS1053B_FORMAT_MIDI : /* midi */
7295 {
7296 info->format = VS1053B_FORMAT_MIDI; /* set midi format */
7297 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7298 strncpy(info->format_name, "midi", 32); /* copy name */
7299 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get midi kbps */
7300
7301 break; /* break */
7302 }
7303 case VS1053B_FORMAT_AAC_ADTS : /* acc adts */
7304 {
7305 info->format = VS1053B_FORMAT_AAC_ADTS; /* set acc adts format */
7306 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7307 strncpy(info->format_name, "aac_adts", 32); /* copy name */
7308 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get acc adts kbps */
7309
7310 break; /* break */
7311 }
7312 case VS1053B_FORMAT_AAC_ADIF : /* acc adif */
7313 {
7314 info->format = VS1053B_FORMAT_AAC_ADIF; /* set acc adif format */
7315 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7316 strncpy(info->format_name, "aac_adif", 32); /* copy name */
7317 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get acc adif kbps */
7318
7319 break; /* break */
7320 }
7321 case VS1053B_FORMAT_AAC_MP4 : /* acc mp4 */
7322 {
7323 info->format = VS1053B_FORMAT_AAC_MP4; /* set acc mp4 format */
7324 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7325 strncpy(info->format_name, "aac_mp4", 32); /* copy name */
7326 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get acc mp4 kbps */
7327
7328 break; /* break */
7329 }
7330 case VS1053B_FORMAT_OGG : /* ogg */
7331 {
7332 info->format = VS1053B_FORMAT_OGG; /* set ogg format */
7333 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7334 strncpy(info->format_name, "ogg", 32); /* copy name */
7335 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get ogg kbps */
7336
7337 break; /* break */
7338 }
7339 case VS1053B_FORMAT_WMA : /* wma */
7340 {
7341 info->format = VS1053B_FORMAT_WMA; /* set wma format */
7342 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7343 strncpy(info->format_name, "wma", 32); /* copy name */
7344 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get wma kbps */
7345
7346 break; /* break */
7347 }
7348 case VS1053B_FORMAT_FLAC : /* flac */
7349 {
7350 info->format = VS1053B_FORMAT_FLAC; /* set flac format */
7351 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7352 strncpy(info->format_name, "flac", 32); /* copy name */
7353 info->kbps = (float)(dat0) * 8.0f / 1000.0f; /* get flac kbps */
7354
7355 break; /* break */
7356 }
7357 default : /* mp3 */
7358 {
7359 uint16_t tmp;
7360
7361 info->format = VS1053B_FORMAT_MP3; /* set mp3 format */
7362 memset(info->format_name, 0, sizeof(char) * 32); /* init buffer */
7363 strncpy(info->format_name, "mp3", 32); /* copy name */
7364 tmp = (dat1 >> 3) & 0x03; /* get index */
7365 if (tmp == 3) /* index 1 */
7366 {
7367 info->kbps = bitrate[1][(dat0 >> 12) & 0xF]; /* get mp3 kbps */
7368 }
7369 else /* index 0 */
7370 {
7371 info->kbps = bitrate[0][(dat0 >> 12) & 0xF]; /* get mp3 kbps */
7372 }
7373 }
7374
7375 break; /* break */
7376 }
7377
7378 return 0; /* success return 0 */
7379}
7380
7393uint8_t vs1053b_get_patch(vs1053b_handle_t *handle, vs1053b_patch_t type, const uint16_t **patch_addr, uint16_t *len)
7394{
7395 if (handle == NULL) /* check handle */
7396 {
7397 return 2; /* return error */
7398 }
7399 if (handle->inited != 1) /* check handle initialization */
7400 {
7401 return 3; /* return error */
7402 }
7403
7404 if (type == VS1053B_PATCH_FLAC) /* flac */
7405 {
7406 *patch_addr = gsc_vs1053b_patch_flac_plugin; /* set flac plugin address */
7407 *len = VS1053B_PATCH_FLAC_PLUGIN_SIZE; /* set flac plugin size */
7408 }
7409#if VS1053B_OGG_VENC08K1Q00 != 0
7410 else if (type == VS1053B_PATCH_OGG_VENC08K1Q00) /* ogg venc08k1q00 */
7411 {
7412 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q00_plugin; /* set plugin address */
7413 *len = VS1053B_PATCH_OGG_VENC08K1Q00_PLUGIN_SIZE; /* set plugin size */
7414 }
7415#endif
7416#if VS1053B_OGG_VENC08K1Q01 != 0
7417 else if (type == VS1053B_PATCH_OGG_VENC08K1Q01) /* ogg venc08k1q01 */
7418 {
7419 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q01_plugin; /* set plugin address */
7420 *len = VS1053B_PATCH_OGG_VENC08K1Q01_PLUGIN_SIZE; /* set plugin size */
7421 }
7422#endif
7423#if VS1053B_OGG_VENC08K1Q02 != 0
7424 else if (type == VS1053B_PATCH_OGG_VENC08K1Q02) /* ogg venc08k1q02 */
7425 {
7426 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q02_plugin; /* set plugin address */
7427 *len = VS1053B_PATCH_OGG_VENC08K1Q02_PLUGIN_SIZE; /* set plugin size */
7428 }
7429#endif
7430#if VS1053B_OGG_VENC08K1Q03 != 0
7431 else if (type == VS1053B_PATCH_OGG_VENC08K1Q03) /* ogg venc08k1q03 */
7432 {
7433 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q03_plugin; /* set plugin address */
7434 *len = VS1053B_PATCH_OGG_VENC08K1Q03_PLUGIN_SIZE; /* set plugin size */
7435 }
7436#endif
7437#if VS1053B_OGG_VENC08K1Q04 != 0
7438 else if (type == VS1053B_PATCH_OGG_VENC08K1Q04) /* ogg venc08k1q04 */
7439 {
7440 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q04_plugin; /* set plugin address */
7441 *len = VS1053B_PATCH_OGG_VENC08K1Q04_PLUGIN_SIZE; /* set plugin size */
7442 }
7443#endif
7444#if VS1053B_OGG_VENC08K1Q05 != 0
7445 else if (type == VS1053B_PATCH_OGG_VENC08K1Q05) /* ogg venc08k1q05 */
7446 {
7447 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q05_plugin; /* set plugin address */
7448 *len = VS1053B_PATCH_OGG_VENC08K1Q05_PLUGIN_SIZE; /* set plugin size */
7449 }
7450#endif
7451#if VS1053B_OGG_VENC08K1Q06 != 0
7452 else if (type == VS1053B_PATCH_OGG_VENC08K1Q06) /* ogg venc08k1q06 */
7453 {
7454 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q06_plugin; /* set plugin address */
7455 *len = VS1053B_PATCH_OGG_VENC08K1Q06_PLUGIN_SIZE; /* set plugin size */
7456 }
7457#endif
7458#if VS1053B_OGG_VENC08K1Q07 != 0
7459 else if (type == VS1053B_PATCH_OGG_VENC08K1Q07) /* ogg venc08k1q07 */
7460 {
7461 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q07_plugin; /* set plugin address */
7462 *len = VS1053B_PATCH_OGG_VENC08K1Q07_PLUGIN_SIZE; /* set plugin size */
7463 }
7464#endif
7465#if VS1053B_OGG_VENC08K1Q08 != 0
7466 else if (type == VS1053B_PATCH_OGG_VENC08K1Q08) /* ogg venc08k1q08 */
7467 {
7468 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q08_plugin; /* set plugin address */
7469 *len = VS1053B_PATCH_OGG_VENC08K1Q08_PLUGIN_SIZE; /* set plugin size */
7470 }
7471#endif
7472#if VS1053B_OGG_VENC08K1Q09 != 0
7473 else if (type == VS1053B_PATCH_OGG_VENC08K1Q09) /* ogg venc08k1q09 */
7474 {
7475 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q09_plugin; /* set plugin address */
7476 *len = VS1053B_PATCH_OGG_VENC08K1Q09_PLUGIN_SIZE; /* set plugin size */
7477 }
7478#endif
7479#if VS1053B_OGG_VENC08K1Q10 != 0
7480 else if (type == VS1053B_PATCH_OGG_VENC08K1Q10) /* ogg venc08k1q10 */
7481 {
7482 *patch_addr = gsc_vs1053b_patch_ogg_venc08k1q10_plugin; /* set plugin address */
7483 *len = VS1053B_PATCH_OGG_VENC08K1Q10_PLUGIN_SIZE; /* set plugin size */
7484 }
7485#endif
7486#if VS1053B_OGG_VENC16K1Q00 != 0
7487 else if (type == VS1053B_PATCH_OGG_VENC16K1Q00) /* ogg venc16k1q00 */
7488 {
7489 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q00_plugin; /* set plugin address */
7490 *len = VS1053B_PATCH_OGG_VENC16K1Q00_PLUGIN_SIZE; /* set plugin size */
7491 }
7492#endif
7493#if VS1053B_OGG_VENC16K1Q01 != 0
7494 else if (type == VS1053B_PATCH_OGG_VENC16K1Q01) /* ogg venc16k1q01 */
7495 {
7496 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q01_plugin; /* set plugin address */
7497 *len = VS1053B_PATCH_OGG_VENC16K1Q01_PLUGIN_SIZE; /* set plugin size */
7498 }
7499#endif
7500#if VS1053B_OGG_VENC16K1Q02 != 0
7501 else if (type == VS1053B_PATCH_OGG_VENC16K1Q02) /* ogg venc16k1q02 */
7502 {
7503 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q02_plugin; /* set plugin address */
7504 *len = VS1053B_PATCH_OGG_VENC16K1Q02_PLUGIN_SIZE; /* set plugin size */
7505 }
7506#endif
7507#if VS1053B_OGG_VENC16K1Q03 != 0
7508 else if (type == VS1053B_PATCH_OGG_VENC16K1Q03) /* ogg venc16k1q03 */
7509 {
7510 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q03_plugin; /* set plugin address */
7511 *len = VS1053B_PATCH_OGG_VENC16K1Q03_PLUGIN_SIZE; /* set plugin size */
7512 }
7513#endif
7514#if VS1053B_OGG_VENC16K1Q04 != 0
7515 else if (type == VS1053B_PATCH_OGG_VENC16K1Q04) /* ogg venc16k1q04 */
7516 {
7517 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q04_plugin; /* set plugin address */
7518 *len = VS1053B_PATCH_OGG_VENC16K1Q04_PLUGIN_SIZE; /* set plugin size */
7519 }
7520#endif
7521#if VS1053B_OGG_VENC16K1Q05 != 0
7522 else if (type == VS1053B_PATCH_OGG_VENC16K1Q05) /* ogg venc16k1q05 */
7523 {
7524 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q05_plugin; /* set plugin address */
7525 *len = VS1053B_PATCH_OGG_VENC16K1Q05_PLUGIN_SIZE; /* set plugin size */
7526 }
7527#endif
7528#if VS1053B_OGG_VENC16K1Q06 != 0
7529 else if (type == VS1053B_PATCH_OGG_VENC16K1Q06) /* ogg venc16k1q06 */
7530 {
7531 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q06_plugin; /* set plugin address */
7532 *len = VS1053B_PATCH_OGG_VENC16K1Q06_PLUGIN_SIZE; /* set plugin size */
7533 }
7534#endif
7535#if VS1053B_OGG_VENC16K1Q07 != 0
7536 else if (type == VS1053B_PATCH_OGG_VENC16K1Q07) /* ogg venc16k1q07 */
7537 {
7538 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q07_plugin; /* set plugin address */
7539 *len = VS1053B_PATCH_OGG_VENC16K1Q07_PLUGIN_SIZE; /* set plugin size */
7540 }
7541#endif
7542#if VS1053B_OGG_VENC16K1Q08 != 0
7543 else if (type == VS1053B_PATCH_OGG_VENC16K1Q08) /* ogg venc16k1q08 */
7544 {
7545 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q08_plugin; /* set plugin address */
7546 *len = VS1053B_PATCH_OGG_VENC16K1Q08_PLUGIN_SIZE; /* set plugin size */
7547 }
7548#endif
7549#if VS1053B_OGG_VENC16K1Q09 != 0
7550 else if (type == VS1053B_PATCH_OGG_VENC16K1Q09) /* ogg venc16k1q09 */
7551 {
7552 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q09_plugin; /* set plugin address */
7553 *len = VS1053B_PATCH_OGG_VENC16K1Q09_PLUGIN_SIZE; /* set plugin size */
7554 }
7555#endif
7556#if VS1053B_OGG_VENC16K1Q10 != 0
7557 else if (type == VS1053B_PATCH_OGG_VENC16K1Q10) /* ogg venc16k1q10 */
7558 {
7559 *patch_addr = gsc_vs1053b_patch_ogg_venc16k1q10_plugin; /* set plugin address */
7560 *len = VS1053B_PATCH_OGG_VENC16K1Q10_PLUGIN_SIZE; /* set plugin size */
7561 }
7562#endif
7563#if VS1053B_OGG_VENC16K2Q00 != 0
7564 else if (type == VS1053B_PATCH_OGG_VENC16K2Q00) /* ogg venc16k2q00 */
7565 {
7566 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q00_plugin; /* set plugin address */
7567 *len = VS1053B_PATCH_OGG_VENC16K2Q00_PLUGIN_SIZE; /* set plugin size */
7568 }
7569#endif
7570#if VS1053B_OGG_VENC16K2Q01 != 0
7571 else if (type == VS1053B_PATCH_OGG_VENC16K2Q01) /* ogg venc16k2q01 */
7572 {
7573 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q01_plugin; /* set plugin address */
7574 *len = VS1053B_PATCH_OGG_VENC16K2Q01_PLUGIN_SIZE; /* set plugin size */
7575 }
7576#endif
7577#if VS1053B_OGG_VENC16K2Q02 != 0
7578 else if (type == VS1053B_PATCH_OGG_VENC16K2Q02) /* ogg venc16k2q02 */
7579 {
7580 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q02_plugin; /* set plugin address */
7581 *len = VS1053B_PATCH_OGG_VENC16K2Q02_PLUGIN_SIZE; /* set plugin size */
7582 }
7583#endif
7584#if VS1053B_OGG_VENC16K2Q03 != 0
7585 else if (type == VS1053B_PATCH_OGG_VENC16K2Q03) /* ogg venc16k2q03 */
7586 {
7587 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q03_plugin; /* set plugin address */
7588 *len = VS1053B_PATCH_OGG_VENC16K2Q03_PLUGIN_SIZE; /* set plugin size */
7589 }
7590#endif
7591#if VS1053B_OGG_VENC16K2Q04 != 0
7592 else if (type == VS1053B_PATCH_OGG_VENC16K2Q04) /* ogg venc16k2q04 */
7593 {
7594 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q04_plugin; /* set plugin address */
7595 *len = VS1053B_PATCH_OGG_VENC16K2Q04_PLUGIN_SIZE; /* set plugin size */
7596 }
7597#endif
7598#if VS1053B_OGG_VENC16K2Q05 != 0
7599 else if (type == VS1053B_PATCH_OGG_VENC16K2Q05) /* ogg venc16k2q05 */
7600 {
7601 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q05_plugin; /* set plugin address */
7602 *len = VS1053B_PATCH_OGG_VENC16K2Q05_PLUGIN_SIZE; /* set plugin size */
7603 }
7604#endif
7605#if VS1053B_OGG_VENC16K2Q06 != 0
7606 else if (type == VS1053B_PATCH_OGG_VENC16K2Q06) /* ogg venc16k2q06 */
7607 {
7608 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q06_plugin; /* set plugin address */
7609 *len = VS1053B_PATCH_OGG_VENC16K2Q06_PLUGIN_SIZE; /* set plugin size */
7610 }
7611#endif
7612#if VS1053B_OGG_VENC16K2Q07 != 0
7613 else if (type == VS1053B_PATCH_OGG_VENC16K2Q07) /* ogg venc16k2q07 */
7614 {
7615 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q07_plugin; /* set plugin address */
7616 *len = VS1053B_PATCH_OGG_VENC16K2Q07_PLUGIN_SIZE; /* set plugin size */
7617 }
7618#endif
7619#if VS1053B_OGG_VENC16K2Q08 != 0
7620 else if (type == VS1053B_PATCH_OGG_VENC16K2Q08) /* ogg venc16k2q08 */
7621 {
7622 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q08_plugin; /* set plugin address */
7623 *len = VS1053B_PATCH_OGG_VENC16K2Q08_PLUGIN_SIZE; /* set plugin size */
7624 }
7625#endif
7626#if VS1053B_OGG_VENC16K2Q09 != 0
7627 else if (type == VS1053B_PATCH_OGG_VENC16K2Q09) /* ogg venc16k2q09 */
7628 {
7629 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q09_plugin; /* set plugin address */
7630 *len = VS1053B_PATCH_OGG_VENC16K2Q09_PLUGIN_SIZE; /* set plugin size */
7631 }
7632#endif
7633#if VS1053B_OGG_VENC16K2Q10 != 0
7634 else if (type == VS1053B_PATCH_OGG_VENC16K2Q10) /* ogg venc16k2q10 */
7635 {
7636 *patch_addr = gsc_vs1053b_patch_ogg_venc16k2q10_plugin; /* set plugin address */
7637 *len = VS1053B_PATCH_OGG_VENC16K2Q10_PLUGIN_SIZE; /* set plugin size */
7638 }
7639#endif
7640#if VS1053B_OGG_VENC44K1Q00 != 0
7641 else if (type == VS1053B_PATCH_OGG_VENC44K1Q00) /* ogg venc44k1q00 */
7642 {
7643 *patch_addr = gsc_vs1053b_patch_ogg_venc44k1q00_plugin; /* set plugin address */
7644 *len = VS1053B_PATCH_OGG_VENC44K1Q00_PLUGIN_SIZE; /* set plugin size */
7645 }
7646#endif
7647#if VS1053B_OGG_VENC44K1Q01 != 0
7648 else if (type == VS1053B_PATCH_OGG_VENC44K1Q01) /* ogg venc44k1q01 */
7649 {
7650 *patch_addr = gsc_vs1053b_patch_ogg_venc44k1q01_plugin; /* set plugin address */
7651 *len = VS1053B_PATCH_OGG_VENC44K1Q01_PLUGIN_SIZE; /* set plugin size */
7652 }
7653#endif
7654#if VS1053B_OGG_VENC44K1Q02 != 0
7655 else if (type == VS1053B_PATCH_OGG_VENC44K1Q02) /* ogg venc44k1q02 */
7656 {
7657 *patch_addr = gsc_vs1053b_patch_ogg_venc44k1q02_plugin; /* set plugin address */
7658 *len = VS1053B_PATCH_OGG_VENC44K1Q02_PLUGIN_SIZE; /* set plugin size */
7659 }
7660#endif
7661#if VS1053B_OGG_VENC44K1Q03 != 0
7662 else if (type == VS1053B_PATCH_OGG_VENC44K1Q03) /* ogg venc44k1q03 */
7663 {
7664 *patch_addr = gsc_vs1053b_patch_ogg_venc44k1q03_plugin; /* set plugin address */
7665 *len = VS1053B_PATCH_OGG_VENC44K1Q03_PLUGIN_SIZE; /* set plugin size */
7666 }
7667#endif
7668#if VS1053B_OGG_VENC44K1Q04 != 0
7669 else if (type == VS1053B_PATCH_OGG_VENC44K1Q04) /* ogg venc44k1q04 */
7670 {
7671 *patch_addr = gsc_vs1053b_patch_ogg_venc44k1q04_plugin; /* set plugin address */
7672 *len = VS1053B_PATCH_OGG_VENC44K1Q04_PLUGIN_SIZE; /* set plugin size */
7673 }
7674#endif
7675#if VS1053B_OGG_VENC44K1Q05 != 0
7676 else if (type == VS1053B_PATCH_OGG_VENC44K1Q05) /* ogg venc44k1q05 */
7677 {
7678 *patch_addr = gsc_vs1053b_patch_ogg_venc44k1q05_plugin; /* set plugin address */
7679 *len = VS1053B_PATCH_OGG_VENC44K1Q05_PLUGIN_SIZE; /* set plugin size */
7680 }
7681#endif
7682#if VS1053B_OGG_VENC44K2Q00 != 0
7683 else if (type == VS1053B_PATCH_OGG_VENC44K2Q00) /* ogg venc44k2q00 */
7684 {
7685 *patch_addr = gsc_vs1053b_patch_ogg_venc44k2q00_plugin; /* set plugin address */
7686 *len = VS1053B_PATCH_OGG_VENC44K2Q00_PLUGIN_SIZE; /* set plugin size */
7687 }
7688#endif
7689#if VS1053B_OGG_VENC44K2Q01 != 0
7690 else if (type == VS1053B_PATCH_OGG_VENC44K2Q01) /* ogg venc44k2q01 */
7691 {
7692 *patch_addr = gsc_vs1053b_patch_ogg_venc44k2q01_plugin; /* set plugin address */
7693 *len = VS1053B_PATCH_OGG_VENC44K2Q01_PLUGIN_SIZE; /* set plugin size */
7694 }
7695#endif
7696#if VS1053B_OGG_VENC44K2Q02 != 0
7697 else if (type == VS1053B_PATCH_OGG_VENC44K2Q02) /* ogg venc44k2q02 */
7698 {
7699 *patch_addr = gsc_vs1053b_patch_ogg_venc44k2q02_plugin; /* set plugin address */
7700 *len = VS1053B_PATCH_OGG_VENC44K2Q02_PLUGIN_SIZE; /* set plugin size */
7701 }
7702#endif
7703#if VS1053B_OGG_VENC44K2Q03 != 0
7704 else if (type == VS1053B_PATCH_OGG_VENC44K2Q03) /* ogg venc44k2q03 */
7705 {
7706 *patch_addr = gsc_vs1053b_patch_ogg_venc44k2q03_plugin; /* set plugin address */
7707 *len = VS1053B_PATCH_OGG_VENC44K2Q03_PLUGIN_SIZE; /* set plugin size */
7708 }
7709#endif
7710#if VS1053B_OGG_VENC44K2Q04 != 0
7711 else if (type == VS1053B_PATCH_OGG_VENC44K2Q04) /* ogg venc44k2q04 */
7712 {
7713 *patch_addr = gsc_vs1053b_patch_ogg_venc44k2q04_plugin; /* set plugin address */
7714 *len = VS1053B_PATCH_OGG_VENC44K2Q04_PLUGIN_SIZE; /* set plugin size */
7715 }
7716#endif
7717#if VS1053B_OGG_VENC44K2Q05 != 0
7718 else if (type == VS1053B_PATCH_OGG_VENC44K2Q05) /* ogg venc44k2q05 */
7719 {
7720 *patch_addr = gsc_vs1053b_patch_ogg_venc44k2q05_plugin; /* set plugin address */
7721 *len = VS1053B_PATCH_OGG_VENC44K2Q05_PLUGIN_SIZE; /* set plugin size */
7722 }
7723#endif
7724 else /* wav */
7725 {
7726 *patch_addr = gsc_vs1053b_patch_wav_plugin; /* set wav plugin address */
7727 *len = VS1053B_PATCH_WAV_PLUGIN_SIZE; /* set wav plugin size */
7728 }
7729
7730 return 0; /* success return 0 */
7731}
7732
7746uint8_t vs1053b_load_patch(vs1053b_handle_t *handle, const uint16_t *patch, uint16_t len)
7747{
7748 uint8_t res;
7749 uint8_t buf[2];
7750 uint16_t i;
7751 uint16_t addr;
7752 uint16_t n;
7753 uint16_t val;
7754
7755 if (handle == NULL) /* check handle */
7756 {
7757 return 2; /* return error */
7758 }
7759 if (handle->inited != 1) /* check handle initialization */
7760 {
7761 return 3; /* return error */
7762 }
7763
7764 if (patch == gsc_vs1053b_patch_flac_plugin) /* flac */
7765 {
7766 handle->plugin_patch_type = VS1053B_PATCH_FLAC; /* save type */
7767 }
7768#if VS1053B_OGG_VENC08K1Q00 != 0
7769 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q00_plugin) /* venc08k1q00 */
7770 {
7771 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q00; /* save type */
7772 }
7773#endif
7774#if VS1053B_OGG_VENC08K1Q01 != 0
7775 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q01_plugin) /* venc08k1q01 */
7776 {
7777 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q01; /* save type */
7778 }
7779#endif
7780#if VS1053B_OGG_VENC08K1Q02 != 0
7781 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q02_plugin) /* venc08k1q02 */
7782 {
7783 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q02; /* save type */
7784 }
7785#endif
7786#if VS1053B_OGG_VENC08K1Q03 != 0
7787 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q03_plugin) /* venc08k1q03 */
7788 {
7789 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q03; /* save type */
7790 }
7791#endif
7792#if VS1053B_OGG_VENC08K1Q04 != 0
7793 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q04_plugin) /* venc08k1q04 */
7794 {
7795 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q04; /* save type */
7796 }
7797#endif
7798#if VS1053B_OGG_VENC08K1Q05 != 0
7799 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q05_plugin) /* venc08k1q05 */
7800 {
7801 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q05; /* save type */
7802 }
7803#endif
7804#if VS1053B_OGG_VENC08K1Q06 != 0
7805 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q06_plugin) /* venc08k1q06 */
7806 {
7807 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q06; /* save type */
7808 }
7809#endif
7810#if VS1053B_OGG_VENC08K1Q07 != 0
7811 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q07_plugin) /* venc08k1q07 */
7812 {
7813 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q07; /* save type */
7814 }
7815#endif
7816#if VS1053B_OGG_VENC08K1Q08 != 0
7817 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q08_plugin) /* venc08k1q08 */
7818 {
7819 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q08; /* save type */
7820 }
7821#endif
7822#if VS1053B_OGG_VENC08K1Q09 != 0
7823 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q09_plugin) /* venc08k1q09 */
7824 {
7825 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q09; /* save type */
7826 }
7827#endif
7828#if VS1053B_OGG_VENC08K1Q10 != 0
7829 else if (patch == gsc_vs1053b_patch_ogg_venc08k1q10_plugin) /* venc08k1q10 */
7830 {
7831 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC08K1Q10; /* save type */
7832 }
7833#endif
7834#if VS1053B_OGG_VENC16K1Q00 != 0
7835 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q00_plugin) /* venc16k1q00 */
7836 {
7837 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q00; /* save type */
7838 }
7839#endif
7840#if VS1053B_OGG_VENC16K1Q01 != 0
7841 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q01_plugin) /* venc16k1q01 */
7842 {
7843 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q01; /* save type */
7844 }
7845#endif
7846#if VS1053B_OGG_VENC16K1Q02 != 0
7847 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q02_plugin) /* venc16k1q02 */
7848 {
7849 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q02; /* save type */
7850 }
7851#endif
7852#if VS1053B_OGG_VENC16K1Q03 != 0
7853 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q03_plugin) /* venc16k1q03 */
7854 {
7855 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q03; /* save type */
7856 }
7857#endif
7858#if VS1053B_OGG_VENC16K1Q04 != 0
7859 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q04_plugin) /* venc16k1q04 */
7860 {
7861 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q04; /* save type */
7862 }
7863#endif
7864#if VS1053B_OGG_VENC16K1Q05 != 0
7865 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q05_plugin) /* venc16k1q05 */
7866 {
7867 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q05; /* save type */
7868 }
7869#endif
7870#if VS1053B_OGG_VENC16K1Q06 != 0
7871 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q06_plugin) /* venc16k1q06 */
7872 {
7873 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q06; /* save type */
7874 }
7875#endif
7876#if VS1053B_OGG_VENC16K1Q07 != 0
7877 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q07_plugin) /* venc16k1q07 */
7878 {
7879 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q07; /* save type */
7880 }
7881#endif
7882#if VS1053B_OGG_VENC16K1Q08 != 0
7883 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q08_plugin) /* venc16k1q08 */
7884 {
7885 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q08; /* save type */
7886 }
7887#endif
7888#if VS1053B_OGG_VENC16K1Q09 != 0
7889 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q09_plugin) /* venc16k1q09 */
7890 {
7891 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q09; /* save type */
7892 }
7893#endif
7894#if VS1053B_OGG_VENC16K1Q10 != 0
7895 else if (patch == gsc_vs1053b_patch_ogg_venc16k1q10_plugin) /* venc16k1q10 */
7896 {
7897 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K1Q10; /* save type */
7898 }
7899#endif
7900#if VS1053B_OGG_VENC16K2Q00 != 0
7901 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q00_plugin) /* venc16k2q00 */
7902 {
7903 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q00; /* save type */
7904 }
7905#endif
7906#if VS1053B_OGG_VENC16K2Q01 != 0
7907 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q01_plugin) /* venc16k2q01 */
7908 {
7909 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q01; /* save type */
7910 }
7911#endif
7912#if VS1053B_OGG_VENC16K2Q02 != 0
7913 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q02_plugin) /* venc16k2q02 */
7914 {
7915 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q02; /* save type */
7916 }
7917#endif
7918#if VS1053B_OGG_VENC16K2Q03 != 0
7919 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q03_plugin) /* venc16k2q03 */
7920 {
7921 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q03; /* save type */
7922 }
7923#endif
7924#if VS1053B_OGG_VENC16K2Q04 != 0
7925 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q04_plugin) /* venc16k2q04 */
7926 {
7927 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q04; /* save type */
7928 }
7929#endif
7930#if VS1053B_OGG_VENC16K2Q05 != 0
7931 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q05_plugin) /* venc16k2q05 */
7932 {
7933 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q05; /* save type */
7934 }
7935#endif
7936#if VS1053B_OGG_VENC16K2Q06 != 0
7937 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q06_plugin) /* venc16k2q06 */
7938 {
7939 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q06; /* save type */
7940 }
7941#endif
7942#if VS1053B_OGG_VENC16K2Q07 != 0
7943 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q07_plugin) /* venc16k2q07 */
7944 {
7945 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q07; /* save type */
7946 }
7947#endif
7948#if VS1053B_OGG_VENC16K2Q08 != 0
7949 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q08_plugin) /* venc16k2q08 */
7950 {
7951 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q08; /* save type */
7952 }
7953#endif
7954#if VS1053B_OGG_VENC16K2Q09 != 0
7955 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q09_plugin) /* venc16k2q09 */
7956 {
7957 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q09; /* save type */
7958 }
7959#endif
7960#if VS1053B_OGG_VENC16K2Q10 != 0
7961 else if (patch == gsc_vs1053b_patch_ogg_venc16k2q10_plugin) /* venc16k2q10 */
7962 {
7963 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC16K2Q10; /* save type */
7964 }
7965#endif
7966#if VS1053B_OGG_VENC44K1Q00 != 0
7967 else if (patch == gsc_vs1053b_patch_ogg_venc44k1q00_plugin) /* venc44k1q00 */
7968 {
7969 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K1Q00; /* save type */
7970 }
7971#endif
7972#if VS1053B_OGG_VENC44K1Q01 != 0
7973 else if (patch == gsc_vs1053b_patch_ogg_venc44k1q01_plugin) /* venc44k1q01 */
7974 {
7975 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K1Q01; /* save type */
7976 }
7977#endif
7978#if VS1053B_OGG_VENC44K1Q02 != 0
7979 else if (patch == gsc_vs1053b_patch_ogg_venc44k1q02_plugin) /* venc44k1q02 */
7980 {
7981 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K1Q02; /* save type */
7982 }
7983#endif
7984#if VS1053B_OGG_VENC44K1Q03 != 0
7985 else if (patch == gsc_vs1053b_patch_ogg_venc44k1q03_plugin) /* venc44k1q03 */
7986 {
7987 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K1Q03; /* save type */
7988 }
7989#endif
7990#if VS1053B_OGG_VENC44K1Q04 != 0
7991 else if (patch == gsc_vs1053b_patch_ogg_venc44k1q04_plugin) /* venc44k1q04 */
7992 {
7993 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K1Q04; /* save type */
7994 }
7995#endif
7996#if VS1053B_OGG_VENC44K1Q05 != 0
7997 else if (patch == gsc_vs1053b_patch_ogg_venc44k1q05_plugin) /* venc44k1q05 */
7998 {
7999 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K1Q05; /* save type */
8000 }
8001#endif
8002#if VS1053B_OGG_VENC44K2Q00 != 0
8003 else if (patch == gsc_vs1053b_patch_ogg_venc44k2q00_plugin) /* venc44k2q00 */
8004 {
8005 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K2Q00; /* save type */
8006 }
8007#endif
8008#if VS1053B_OGG_VENC44K2Q01 != 0
8009 else if (patch == gsc_vs1053b_patch_ogg_venc44k2q01_plugin) /* venc44k2q01 */
8010 {
8011 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K2Q01; /* save type */
8012 }
8013#endif
8014#if VS1053B_OGG_VENC44K2Q02 != 0
8015 else if (patch == gsc_vs1053b_patch_ogg_venc44k2q02_plugin) /* venc44k2q02 */
8016 {
8017 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K2Q02; /* save type */
8018 }
8019#endif
8020#if VS1053B_OGG_VENC44K2Q03 != 0
8021 else if (patch == gsc_vs1053b_patch_ogg_venc44k2q03_plugin) /* venc44k2q03 */
8022 {
8023 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K2Q03; /* save type */
8024 }
8025#endif
8026#if VS1053B_OGG_VENC44K2Q04 != 0
8027 else if (patch == gsc_vs1053b_patch_ogg_venc44k2q04_plugin) /* venc44k2q04 */
8028 {
8029 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K2Q04; /* save type */
8030 }
8031#endif
8032#if VS1053B_OGG_VENC44K2Q05 != 0
8033 else if (patch == gsc_vs1053b_patch_ogg_venc44k2q05_plugin) /* venc44k2q05 */
8034 {
8035 handle->plugin_patch_type = VS1053B_PATCH_OGG_VENC44K2Q05; /* save type */
8036 }
8037#endif
8038 else if (patch == gsc_vs1053b_patch_wav_plugin) /* wav */
8039 {
8040 handle->plugin_patch_type = VS1053B_PATCH_WAV; /* save type */
8041 }
8042 else
8043 {
8044 handle->debug_print("vs1053b: invalid path address.\n"); /* invalid path address */
8045
8046 return 4; /* return error */
8047 }
8048
8049 i = 0; /* init 0 */
8050 while (i < len) /* loop */
8051 {
8052 addr = patch[i++]; /* get addr */
8053 n = patch[i++]; /* get n */
8054 if ((n & 0x8000U) != 0) /* rle run, replicate n samples */
8055 {
8056 n &= 0x7FFFU; /* & */
8057 val = patch[i++]; /* get a val */
8058 while (n--) /* loop */
8059 {
8060 buf[0] = (val >> 8) & 0xFF; /* high part */
8061 buf[1] = (val >> 0) & 0xFF; /* low part */
8062 res = a_vs1053b_spi_write(handle, (uint8_t)addr, buf, 2); /* write patch */
8063 if (res != 0) /* check result */
8064 {
8065 handle->debug_print("vs1053b: load patch failed.\n"); /* load patch failed */
8066
8067 return 1; /* return error */
8068 }
8069 }
8070 }
8071 else /* copy run, copy n sample */
8072 {
8073 while (n--) /* loop */
8074 {
8075 val = patch[i++]; /* get a val */
8076 buf[0] = (val >> 8) & 0xFF; /* high part */
8077 buf[1] = (val >> 0) & 0xFF; /* low part */
8078 res = a_vs1053b_spi_write(handle, (uint8_t)addr, buf, 2); /* write patch */
8079 if (res != 0) /* check result */
8080 {
8081 handle->debug_print("vs1053b: load patch failed.\n"); /* load patch failed */
8082
8083 return 1; /* return error */
8084 }
8085 }
8086 }
8087 }
8088
8089 return 0; /* success return 0 */
8090}
8091
8104uint8_t vs1053b_set_data(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
8105{
8106 if (handle == NULL) /* check handle */
8107 {
8108 return 2; /* return error */
8109 }
8110 if (handle->inited != 1) /* check handle initialization */
8111 {
8112 return 3; /* return error */
8113 }
8114
8115 return a_vs1053b_spi_write_data(handle, buf, len); /* write data */
8116}
8117
8131uint8_t vs1053b_set_reg(vs1053b_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
8132{
8133 if (handle == NULL) /* check handle */
8134 {
8135 return 2; /* return error */
8136 }
8137 if (handle->inited != 1) /* check handle initialization */
8138 {
8139 return 3; /* return error */
8140 }
8141 if (a_check_busy_pin(handle) != 0) /* check busy */
8142 {
8143 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
8144
8145 return 1; /* return error */
8146 }
8147
8148 return a_vs1053b_spi_write(handle, reg, buf, len); /* write data */
8149}
8150
8164uint8_t vs1053b_get_reg(vs1053b_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
8165{
8166 if (handle == NULL) /* check handle */
8167 {
8168 return 2; /* return error */
8169 }
8170 if (handle->inited != 1) /* check handle initialization */
8171 {
8172 return 3; /* return error */
8173 }
8174 if (a_check_busy_pin(handle) != 0) /* check busy */
8175 {
8176 handle->debug_print("vs1053b: chip is busy.\n"); /* chip is busy */
8177
8178 return 1; /* return error */
8179 }
8180
8181 return a_vs1053b_spi_read(handle, reg, buf, len); /* read data */
8182}
8183
8193{
8194 if (info == NULL) /* check handle */
8195 {
8196 return 2; /* return error */
8197 }
8198
8199 memset(info, 0, sizeof(vs1053b_info_t)); /* initialize vs1053b info structure */
8200 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
8201 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
8202 strncpy(info->interface, "SPI", 8); /* copy interface name */
8203 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
8204 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
8205 info->max_current_ma = MAX_CURRENT; /* set maximum current */
8206 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
8207 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
8208 info->driver_version = DRIVER_VERSION; /* set driver version */
8209
8210 return 0; /* success return 0 */
8211}
#define VS1053B_REG_CLOCKF
#define VS1053B_REG_DECODE_TIME
#define VS1053B_REG_HDAT0
#define VS1053B_REG_WRAMADDR
#define VS1053B_REG_VOL
#define VS1053B_REG_MODE
chip register definition
#define MAX_CURRENT
#define VS1053B_REG_STATUS
#define VS1053B_STATUS_STOP
chip status definition
#define MIN(a, b)
inner function definition
#define VS1053B_REG_AICTRL2
#define VS1053B_REG_AUDATA
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define VS1053B_REG_WRAM
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define VS1053B_REG_BASS
#define SUPPLY_VOLTAGE_MIN
#define VS1053B_COMMAND_READ
chip command definition
#define VS1053B_REG_AICTRL1
#define VS1053B_REG_AICTRL0
#define VS1053B_STATUS_RECORD
#define VS1053B_REG_AICTRL3
#define VS1053B_REG_AIADDR
#define VS1053B_REG_HDAT1
#define CHIP_NAME
chip information definition
#define VS1053B_STATUS_PLAY
#define DRIVER_VERSION
#define VS1053B_COMMAND_WRITE
driver vs1053b header file
driver vs1053b patch flac header file
#define VS1053B_PATCH_FLAC_PLUGIN_SIZE
vs1053b patch flac plugin size definition
driver vs1053b patch ogg venc08k1q00 header file
#define VS1053B_PATCH_OGG_VENC08K1Q00_PLUGIN_SIZE
vs1053b patch ogg venc08k1q00 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q00_plugin[VS1053B_PATCH_OGG_VENC08K1Q00_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q00 plugin definition
driver vs1053b patch ogg venc08k1q01 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q01_plugin[VS1053B_PATCH_OGG_VENC08K1Q01_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q01 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q01_PLUGIN_SIZE
vs1053b patch ogg venc08k1q01 plugin size definition
driver vs1053b patch ogg venc08k1q02 header file
#define VS1053B_PATCH_OGG_VENC08K1Q02_PLUGIN_SIZE
vs1053b patch ogg venc08k1q02 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q02_plugin[VS1053B_PATCH_OGG_VENC08K1Q02_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q02 plugin definition
driver vs1053b patch ogg venc08k1q03 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q03_plugin[VS1053B_PATCH_OGG_VENC08K1Q03_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q03 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q03_PLUGIN_SIZE
vs1053b patch ogg venc08k1q03 plugin size definition
driver vs1053b patch ogg venc08k1q04 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q04_plugin[VS1053B_PATCH_OGG_VENC08K1Q04_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q04 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q04_PLUGIN_SIZE
vs1053b patch ogg venc08k1q04 plugin size definition
driver vs1053b patch ogg venc08k1q05 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q05_plugin[VS1053B_PATCH_OGG_VENC08K1Q05_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q05 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q05_PLUGIN_SIZE
vs1053b patch ogg venc08k1q05 plugin size definition
driver vs1053b patch ogg venc08k1q06 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q06_plugin[VS1053B_PATCH_OGG_VENC08K1Q06_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q06 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q06_PLUGIN_SIZE
vs1053b patch ogg venc08k1q06 plugin size definition
driver vs1053b patch ogg venc08k1q07 header file
#define VS1053B_PATCH_OGG_VENC08K1Q07_PLUGIN_SIZE
vs1053b patch ogg venc08k1q07 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q07_plugin[VS1053B_PATCH_OGG_VENC08K1Q07_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q07 plugin definition
driver vs1053b patch ogg venc08k1q08 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q08_plugin[VS1053B_PATCH_OGG_VENC08K1Q08_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q08 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q08_PLUGIN_SIZE
vs1053b patch ogg venc08k1q08 plugin size definition
driver vs1053b patch ogg venc08k1q09 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q09_plugin[VS1053B_PATCH_OGG_VENC08K1Q09_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q09 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q09_PLUGIN_SIZE
vs1053b patch ogg venc08k1q09 plugin size definition
driver vs1053b patch ogg venc08k1q10 header file
const uint16_t gsc_vs1053b_patch_ogg_venc08k1q10_plugin[VS1053B_PATCH_OGG_VENC08K1Q10_PLUGIN_SIZE]
vs1053b patch ogg venc08k1q10 plugin definition
#define VS1053B_PATCH_OGG_VENC08K1Q10_PLUGIN_SIZE
vs1053b patch ogg venc08k1q10 plugin size definition
driver vs1053b patch ogg venc16k1q00 header file
#define VS1053B_PATCH_OGG_VENC16K1Q00_PLUGIN_SIZE
vs1053b patch ogg venc16k1q00 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q00_plugin[VS1053B_PATCH_OGG_VENC16K1Q00_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q00 plugin definition
driver vs1053b patch ogg venc16k1q01 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q01_plugin[VS1053B_PATCH_OGG_VENC16K1Q01_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q01 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q01_PLUGIN_SIZE
vs1053b patch ogg venc16k1q01 plugin size definition
driver vs1053b patch ogg venc16k1q02 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q02_plugin[VS1053B_PATCH_OGG_VENC16K1Q02_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q02 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q02_PLUGIN_SIZE
vs1053b patch ogg venc16k1q02 plugin size definition
driver vs1053b patch ogg venc16k1q03 header file
#define VS1053B_PATCH_OGG_VENC16K1Q03_PLUGIN_SIZE
vs1053b patch ogg venc16k1q03 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q03_plugin[VS1053B_PATCH_OGG_VENC16K1Q03_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q03 plugin definition
driver vs1053b patch ogg venc16k1q04 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q04_plugin[VS1053B_PATCH_OGG_VENC16K1Q04_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q04 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q04_PLUGIN_SIZE
vs1053b patch ogg venc16k1q04 plugin size definition
driver vs1053b patch ogg venc16k1q05 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q05_plugin[VS1053B_PATCH_OGG_VENC16K1Q05_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q05 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q05_PLUGIN_SIZE
vs1053b patch ogg venc16k1q05 plugin size definition
driver vs1053b patch ogg venc16k1q06 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q06_plugin[VS1053B_PATCH_OGG_VENC16K1Q06_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q06 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q06_PLUGIN_SIZE
vs1053b patch ogg venc16k1q06 plugin size definition
driver vs1053b patch ogg venc16k1q07 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q07_plugin[VS1053B_PATCH_OGG_VENC16K1Q07_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q07 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q07_PLUGIN_SIZE
vs1053b patch ogg venc16k1q07 plugin size definition
driver vs1053b patch ogg venc16k1q08 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q08_plugin[VS1053B_PATCH_OGG_VENC16K1Q08_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q08 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q08_PLUGIN_SIZE
vs1053b patch ogg venc16k1q08 plugin size definition
driver vs1053b patch ogg venc16k1q09 header file
#define VS1053B_PATCH_OGG_VENC16K1Q09_PLUGIN_SIZE
vs1053b patch ogg venc16k1q09 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q09_plugin[VS1053B_PATCH_OGG_VENC16K1Q09_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q09 plugin definition
driver vs1053b patch ogg venc16k1q10 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k1q10_plugin[VS1053B_PATCH_OGG_VENC16K1Q10_PLUGIN_SIZE]
vs1053b patch ogg venc16k1q10 plugin definition
#define VS1053B_PATCH_OGG_VENC16K1Q10_PLUGIN_SIZE
vs1053b patch ogg venc16k1q10 plugin size definition
driver vs1053b patch ogg venc16k2q00 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q00_plugin[VS1053B_PATCH_OGG_VENC16K2Q00_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q00 plugin definition
#define VS1053B_PATCH_OGG_VENC16K2Q00_PLUGIN_SIZE
vs1053b patch ogg venc16k2q00 plugin size definition
driver vs1053b patch ogg venc16k2q01 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q01_plugin[VS1053B_PATCH_OGG_VENC16K2Q01_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q01 plugin definition
#define VS1053B_PATCH_OGG_VENC16K2Q01_PLUGIN_SIZE
vs1053b patch ogg venc16k2q01 plugin size definition
driver vs1053b patch ogg venc16k2q02 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q02_plugin[VS1053B_PATCH_OGG_VENC16K2Q02_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q02 plugin definition
#define VS1053B_PATCH_OGG_VENC16K2Q02_PLUGIN_SIZE
vs1053b patch ogg venc16k2q02 plugin size definition
driver vs1053b patch ogg venc16k2q03 header file
#define VS1053B_PATCH_OGG_VENC16K2Q03_PLUGIN_SIZE
vs1053b patch ogg venc16k2q03 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q03_plugin[VS1053B_PATCH_OGG_VENC16K2Q03_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q03 plugin definition
driver vs1053b patch ogg venc16k2q04 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q04_plugin[VS1053B_PATCH_OGG_VENC16K2Q04_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q04 plugin definition
#define VS1053B_PATCH_OGG_VENC16K2Q04_PLUGIN_SIZE
vs1053b patch ogg venc16k2q04 plugin size definition
driver vs1053b patch ogg venc16k2q05 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q05_plugin[VS1053B_PATCH_OGG_VENC16K2Q05_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q05 plugin definition
#define VS1053B_PATCH_OGG_VENC16K2Q05_PLUGIN_SIZE
vs1053b patch ogg venc16k2q05 plugin size definition
driver vs1053b patch ogg venc16k2q06 header file
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q06_plugin[VS1053B_PATCH_OGG_VENC16K2Q06_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q06 plugin definition
#define VS1053B_PATCH_OGG_VENC16K2Q06_PLUGIN_SIZE
vs1053b patch ogg venc16k2q06 plugin size definition
driver vs1053b patch ogg venc16k2q07 header file
#define VS1053B_PATCH_OGG_VENC16K2Q07_PLUGIN_SIZE
vs1053b patch ogg venc16k2q07 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q07_plugin[VS1053B_PATCH_OGG_VENC16K2Q07_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q07 plugin definition
driver vs1053b patch ogg venc16k2q08 header file
#define VS1053B_PATCH_OGG_VENC16K2Q08_PLUGIN_SIZE
vs1053b patch ogg venc16k2q08 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q08_plugin[VS1053B_PATCH_OGG_VENC16K2Q08_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q08 plugin definition
driver vs1053b patch ogg venc16k2q09 header file
#define VS1053B_PATCH_OGG_VENC16K2Q09_PLUGIN_SIZE
vs1053b patch ogg venc16k2q09 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q09_plugin[VS1053B_PATCH_OGG_VENC16K2Q09_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q09 plugin definition
driver vs1053b patch ogg venc16k2q10 header file
#define VS1053B_PATCH_OGG_VENC16K2Q10_PLUGIN_SIZE
vs1053b patch ogg venc16k2q10 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc16k2q10_plugin[VS1053B_PATCH_OGG_VENC16K2Q10_PLUGIN_SIZE]
vs1053b patch ogg venc16k2q10 plugin definition
driver vs1053b patch ogg venc44k1q00 header file
#define VS1053B_PATCH_OGG_VENC44K1Q00_PLUGIN_SIZE
vs1053b patch ogg venc44k1q00 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc44k1q00_plugin[VS1053B_PATCH_OGG_VENC44K1Q00_PLUGIN_SIZE]
vs1053b patch ogg venc44k1q00 plugin definition
driver vs1053b patch ogg venc44k1q01 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k1q01_plugin[VS1053B_PATCH_OGG_VENC44K1Q01_PLUGIN_SIZE]
vs1053b patch ogg venc44k1q01 plugin definition
#define VS1053B_PATCH_OGG_VENC44K1Q01_PLUGIN_SIZE
vs1053b patch ogg venc44k1q01 plugin size definition
driver vs1053b patch ogg venc44k1q02 header file
#define VS1053B_PATCH_OGG_VENC44K1Q02_PLUGIN_SIZE
vs1053b patch ogg venc44k1q02 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc44k1q02_plugin[VS1053B_PATCH_OGG_VENC44K1Q02_PLUGIN_SIZE]
vs1053b patch ogg venc44k1q02 plugin definition
driver vs1053b patch ogg venc44k1q03 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k1q03_plugin[VS1053B_PATCH_OGG_VENC44K1Q03_PLUGIN_SIZE]
vs1053b patch ogg venc44k1q03 plugin definition
#define VS1053B_PATCH_OGG_VENC44K1Q03_PLUGIN_SIZE
vs1053b patch ogg venc44k1q03 plugin size definition
driver vs1053b patch ogg venc44k1q04 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k1q04_plugin[VS1053B_PATCH_OGG_VENC44K1Q04_PLUGIN_SIZE]
vs1053b patch ogg venc44k1q04 plugin definition
#define VS1053B_PATCH_OGG_VENC44K1Q04_PLUGIN_SIZE
vs1053b patch ogg venc44k1q04 plugin size definition
driver vs1053b patch ogg venc44k1q05 header file
#define VS1053B_PATCH_OGG_VENC44K1Q05_PLUGIN_SIZE
vs1053b patch ogg venc44k1q05 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc44k1q05_plugin[VS1053B_PATCH_OGG_VENC44K1Q05_PLUGIN_SIZE]
vs1053b patch ogg venc44k1q05 plugin definition
driver vs1053b patch ogg venc44k2q00 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k2q00_plugin[VS1053B_PATCH_OGG_VENC44K2Q00_PLUGIN_SIZE]
vs1053b patch ogg venc44k2q00 plugin definition
#define VS1053B_PATCH_OGG_VENC44K2Q00_PLUGIN_SIZE
vs1053b patch ogg venc44k2q00 plugin size definition
driver vs1053b patch ogg venc44k2q01 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k2q01_plugin[VS1053B_PATCH_OGG_VENC44K2Q01_PLUGIN_SIZE]
vs1053b patch ogg venc44k2q01 plugin definition
#define VS1053B_PATCH_OGG_VENC44K2Q01_PLUGIN_SIZE
vs1053b patch ogg venc44k2q01 plugin size definition
driver vs1053b patch ogg venc44k2q02 header file
#define VS1053B_PATCH_OGG_VENC44K2Q02_PLUGIN_SIZE
vs1053b patch ogg venc44k2q02 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc44k2q02_plugin[VS1053B_PATCH_OGG_VENC44K2Q02_PLUGIN_SIZE]
vs1053b patch ogg venc44k2q02 plugin definition
driver vs1053b patch ogg venc44k2q03 header file
#define VS1053B_PATCH_OGG_VENC44K2Q03_PLUGIN_SIZE
vs1053b patch ogg venc44k2q03 plugin size definition
const uint16_t gsc_vs1053b_patch_ogg_venc44k2q03_plugin[VS1053B_PATCH_OGG_VENC44K2Q03_PLUGIN_SIZE]
vs1053b patch ogg venc44k2q03 plugin definition
driver vs1053b patch ogg venc44k2q04 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k2q04_plugin[VS1053B_PATCH_OGG_VENC44K2Q04_PLUGIN_SIZE]
vs1053b patch ogg venc44k2q04 plugin definition
#define VS1053B_PATCH_OGG_VENC44K2Q04_PLUGIN_SIZE
vs1053b patch ogg venc44k2q04 plugin size definition
driver vs1053b patch ogg venc44k2q05 header file
const uint16_t gsc_vs1053b_patch_ogg_venc44k2q05_plugin[VS1053B_PATCH_OGG_VENC44K2Q05_PLUGIN_SIZE]
vs1053b patch ogg venc44k2q05 plugin definition
#define VS1053B_PATCH_OGG_VENC44K2Q05_PLUGIN_SIZE
vs1053b patch ogg venc44k2q05 plugin size definition
driver vs1053b patch wav header file
#define VS1053B_PATCH_WAV_PLUGIN_SIZE
vs1053b patch wav plugin size definition
uint8_t vs1053b_get_version(vs1053b_handle_t *handle, uint8_t *version)
get version
uint8_t vs1053b_set_iis_mclk(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable iis mclk
uint8_t vs1053b_parse_info(vs1053b_handle_t *handle, uint16_t dat0, uint16_t dat1, vs1053b_audio_info_t *info)
parse info
uint8_t vs1053b_set_swing(vs1053b_handle_t *handle, uint8_t swing)
set swing
uint8_t vs1053b_get_overload_indicator(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get overload indicator status
uint8_t vs1053b_set_treble_control(vs1053b_handle_t *handle, uint8_t db)
set treble control
uint8_t vs1053b_set_ad_clock(vs1053b_handle_t *handle, vs1053b_ad_clock_t ad_clock)
set ad clock
uint8_t vs1053b_set_clock_multiplier(vs1053b_handle_t *handle, vs1053b_clock_multiplier_t multiplier)
set clock multiplier
uint8_t vs1053b_get_diff(vs1053b_handle_t *handle, vs1053b_diff_t *diff)
get the audio differential
uint8_t vs1053b_get_lower_limit_frequency_in_1000_hz(vs1053b_handle_t *handle, uint8_t *step)
get lower limit frequency in 1000 hz
uint8_t vs1053b_set_reference_voltage(vs1053b_handle_t *handle, vs1053b_reference_voltage_t voltage)
set reference voltage
uint8_t vs1053b_set_period_callback(vs1053b_handle_t *handle, uint32_t second, uint32_t microsecond, vs1053b_bool_t enable)
set period callback
uint8_t vs1053b_get_end_fill_byte(vs1053b_handle_t *handle, uint16_t *byte)
get end fill byte
uint8_t vs1053b_get_iis(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get iis status
uint8_t vs1053b_get_ear_speaker_high_setting(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get ear speaker high setting status
uint8_t vs1053b_set_analog_internal_power_down(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable analog internal power down
uint8_t vs1053b_vol_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, float *db)
convert the register raw data to vol
uint8_t vs1053b_get_allow_sdi_test(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get allow sdi test status
uint8_t vs1053b_swing_convert_to_register(vs1053b_handle_t *handle, float db, uint8_t *reg)
convert the swing to the register raw data
uint8_t vs1053b_set_lower_limit_frequency_in_10_hz(vs1053b_handle_t *handle, uint8_t step)
set lower limit frequency in 10 hz
uint8_t vs1053b_stop(vs1053b_handle_t *handle)
stop audio
uint8_t vs1053b_set_vol(vs1053b_handle_t *handle, uint8_t left, uint8_t right)
set vol
uint8_t vs1053b_lower_limit_frequency_in_1000_hz_convert_to_register(vs1053b_handle_t *handle, uint32_t hz, uint8_t *reg)
convert the lower limit frequency in 1000 hz to the register raw data
uint8_t vs1053b_get_lower_limit_frequency_in_10_hz(vs1053b_handle_t *handle, uint8_t *step)
get lower limit frequency in 10 hz
uint8_t vs1053b_read_ram(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
read ram
uint8_t vs1053b_get_play_speed(vs1053b_handle_t *handle, vs1053b_play_speed_t *speed)
get play speed
uint8_t vs1053b_process(vs1053b_handle_t *handle)
audio process
uint8_t vs1053b_set_selector(vs1053b_handle_t *handle, vs1053b_selector_t selector)
set selector
uint8_t vs1053b_clock_frequency_convert_to_register(vs1053b_handle_t *handle, float hz, uint16_t *reg)
convert the clock frequency to the register raw data
uint8_t vs1053b_get_gpio_output(vs1053b_handle_t *handle, uint16_t *data)
get gpio output
uint8_t vs1053b_get_pcm_adpcm_recording_active(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get pcm adpcm recording active status
uint8_t vs1053b_set_do_not_jump(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable do not jump
uint8_t vs1053b_get_stream_mode(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get stream mode status
vs1053b_ad_clock_t
vs1053b ad clock enumeration definition
uint8_t vs1053b_get_mpeg_layer_i_and_ii(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get mpeg layer i and ii status
uint8_t vs1053b_get_bass_enhancement(vs1053b_handle_t *handle, uint8_t *db)
get bass enhancement
uint8_t vs1053b_get_clock_frequency(vs1053b_handle_t *handle, uint16_t *clk)
get clock frequency
uint8_t vs1053b_get_period_callback(vs1053b_handle_t *handle, uint32_t *second, uint32_t *microsecond, vs1053b_bool_t *enable)
get period callback
vs1053b_reference_voltage_t
vs1053b reference voltage enumeration definition
vs1053b_bit_order_t
vs1053b bit order enumeration definition
vs1053b_allowed_multiplier_addition_t
vs1053b allowed multiplier addition enumeration definition
uint8_t vs1053b_get_clock_multiplier(vs1053b_handle_t *handle, vs1053b_clock_multiplier_t *multiplier)
get clock multiplier
vs1053b_diff_t
vs1053b diff enumeration definition
uint8_t vs1053b_get_gpio_direction(vs1053b_handle_t *handle, uint16_t *mask)
get gpio direction
uint8_t vs1053b_set_sample_rate(vs1053b_handle_t *handle, uint16_t rate, vs1053b_channel_t channel)
set sample rate
vs1053b_bool_t
vs1053b bool enumeration definition
uint8_t vs1053b_set_decode_time(vs1053b_handle_t *handle, uint16_t decode_time)
set decode time
uint8_t vs1053b_get_hdata0(vs1053b_handle_t *handle, uint16_t *dat0)
get hdata0
vs1053b_selector_t
vs1053b selector enumeration definition
uint8_t vs1053b_set_gpio_direction(vs1053b_handle_t *handle, uint16_t mask)
set gpio direction
uint8_t vs1053b_get_gpio_input(vs1053b_handle_t *handle, uint16_t *data)
get gpio input
uint8_t vs1053b_get_share_spi_chip_select(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get share spi chip select status
uint8_t vs1053b_get_soft_reset(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get soft reset status
uint8_t vs1053b_set_native_spi_modes(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable native spi modes
uint8_t vs1053b_get_selector(vs1053b_handle_t *handle, vs1053b_selector_t *selector)
get selector
uint8_t vs1053b_init(vs1053b_handle_t *handle)
initialize the chip
uint8_t vs1053b_set_cancel_decoding_current_file(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable cancel decoding current file
vs1053b_patch_t
vs1053b patch enumeration definition
uint8_t vs1053b_set_start_address(vs1053b_handle_t *handle, uint16_t addr)
set start address
uint8_t vs1053b_get_swing(vs1053b_handle_t *handle, uint8_t *swing)
get swing
vs1053b_dclk_edge_t
vs1053b dclk edge enumeration definition
uint8_t vs1053b_set_stream_mode(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable stream mode
uint8_t vs1053b_get_allowed_multiplier_addition(vs1053b_handle_t *handle, vs1053b_allowed_multiplier_addition_t *addition)
get allowed multiplier addition
uint8_t vs1053b_get_decode_time(vs1053b_handle_t *handle, uint16_t *decode_time)
get decode time
uint8_t vs1053b_get_treble_control(vs1053b_handle_t *handle, uint8_t *db)
get treble control
uint8_t vs1053b_set_iis_rate(vs1053b_handle_t *handle, vs1053b_iis_rate_t iis_rate)
set iis rate
uint8_t vs1053b_read_application(vs1053b_handle_t *handle, vs1053b_application_t num, uint8_t *buf, uint16_t len)
read application
uint8_t vs1053b_write_application(vs1053b_handle_t *handle, vs1053b_application_t num, uint8_t *buf, uint16_t len)
write application
#define VS1053B_BUFFER_SIZE
vs1053b buffer size definition
uint8_t vs1053b_set_dclk_edge(vs1053b_handle_t *handle, vs1053b_dclk_edge_t edge)
set dclk edge
uint8_t vs1053b_get_dclk_edge(vs1053b_handle_t *handle, vs1053b_dclk_edge_t *edge)
get dclk edge
uint8_t vs1053b_set_analog_driver_power_down(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable analog driver power down
uint8_t vs1053b_set_play_speed(vs1053b_handle_t *handle, vs1053b_play_speed_t speed)
set play speed
uint8_t vs1053b_set_pcm_adpcm_recording_active(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable pcm adpcm recording active
uint8_t vs1053b_set_clock_frequency(vs1053b_handle_t *handle, uint16_t clk)
set clock frequency
uint8_t vs1053b_lower_limit_frequency_in_1000_hz_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, uint32_t *hz)
convert the register raw data to the lower limit frequency in 1000 hz
uint8_t vs1053b_hard_reset(vs1053b_handle_t *handle)
hard reset
uint8_t vs1053b_get_iis_mclk(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get iis mclk status
uint8_t vs1053b_get_analog_internal_power_down(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get analog internal power down status
vs1053b_clock_range_t
vs1053b clock range enumeration definition
uint8_t vs1053b_set_ear_speaker_low_setting(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable ear speaker low setting
uint8_t vs1053b_clock_frequency_convert_to_data(vs1053b_handle_t *handle, uint16_t reg, float *hz)
convert the register raw data to the clock frequency
uint8_t vs1053b_set_record_format(vs1053b_handle_t *handle, vs1053b_record_format_t format)
set record format
uint8_t vs1053b_set_clock_range(vs1053b_handle_t *handle, vs1053b_clock_range_t range)
set clock range
uint8_t vs1053b_get_patch(vs1053b_handle_t *handle, vs1053b_patch_t type, const uint16_t **patch_addr, uint16_t *len)
get patch info
uint8_t vs1053b_set_diff(vs1053b_handle_t *handle, vs1053b_diff_t diff)
set the audio differential
uint8_t vs1053b_get_do_not_jump(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get do not jump status
uint8_t vs1053b_get_cancel_decoding_current_file(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get cancel decoding current file status
uint8_t vs1053b_get_overload_detection(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get overload detection status
uint8_t vs1053b_get_record_format(vs1053b_handle_t *handle, vs1053b_record_format_t *format)
get record format
uint8_t vs1053b_set_ear_speaker_high_setting(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable ear speaker high setting
uint8_t vs1053b_treble_control_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, float *db)
convert the register raw data to the treble control
uint8_t vs1053b_set_share_spi_chip_select(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable share spi chip select
uint8_t vs1053b_vol_convert_to_register(vs1053b_handle_t *handle, float db, uint8_t *reg)
convert vol to the register raw data
uint8_t vs1053b_set_soft_reset(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable soft reset
vs1053b_application_t
vs1053b application enumeration definition
uint8_t vs1053b_get_reference_voltage(vs1053b_handle_t *handle, vs1053b_reference_voltage_t *voltage)
get reference voltage
uint8_t vs1053b_lower_limit_frequency_in_10_hz_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, uint32_t *hz)
convert the register raw data to the lower limit frequency in 10 hz
uint8_t vs1053b_get_analog_driver_power_down(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get analog driver power down status
uint8_t vs1053b_set_ram_address(vs1053b_handle_t *handle, uint16_t addr)
set ram address
vs1053b_record_format_t
vs1053b record format enumeration definition
uint8_t vs1053b_set_overload_indicator(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable overload indicator
struct vs1053b_handle_s vs1053b_handle_t
vs1053b handle structure definition
vs1053b_play_speed_t
vs1053b play speed enumeration definition
uint8_t vs1053b_set_allow_sdi_test(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable allow sdi test
uint8_t vs1053b_get_sdi_bit_order(vs1053b_handle_t *handle, vs1053b_bit_order_t *order)
get sdi bit order
uint8_t vs1053b_set_overload_detection(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable overload detection
uint8_t vs1053b_treble_control_convert_to_register(vs1053b_handle_t *handle, float db, uint8_t *reg)
convert the treble control to the register raw data
struct vs1053b_audio_info_s vs1053b_audio_info_t
vs1053b audio info structure definition
uint8_t vs1053b_deinit(vs1053b_handle_t *handle)
deinit the chip
vs1053b_iis_rate_t
vs1053b iis rate enumeration definition
uint8_t vs1053b_set_iis(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable iis
struct vs1053b_wav_s vs1053b_wav_t
vs1053b wav structure definition
uint8_t vs1053b_set_allowed_multiplier_addition(vs1053b_handle_t *handle, vs1053b_allowed_multiplier_addition_t addition)
set allowed multiplier addition
uint8_t vs1053b_set_sdi_bit_order(vs1053b_handle_t *handle, vs1053b_bit_order_t order)
set sdi bit order
uint8_t vs1053b_get_start_address(vs1053b_handle_t *handle, uint16_t *addr)
get start address
struct vs1053b_info_s vs1053b_info_t
vs1053b information structure definition
uint8_t vs1053b_set_gpio_output(vs1053b_handle_t *handle, uint16_t data)
set gpio output
uint8_t vs1053b_get_vol(vs1053b_handle_t *handle, uint8_t *left, uint8_t *right)
get vol
vs1053b_clock_multiplier_t
vs1053b clock multiplier enumeration definition
uint8_t vs1053b_get_iis_rate(vs1053b_handle_t *handle, vs1053b_iis_rate_t *iis_rate)
get iis rate
uint8_t vs1053b_get_ad_clock(vs1053b_handle_t *handle, vs1053b_ad_clock_t *ad_clock)
get ad clock
uint8_t vs1053b_info(vs1053b_info_t *info)
get chip's information
uint8_t vs1053b_get_byte_rate(vs1053b_handle_t *handle, uint16_t *rate)
get byte rate
uint8_t vs1053b_get_hdata(vs1053b_handle_t *handle, uint16_t *dat0, uint16_t *dat1)
get hdata
uint8_t vs1053b_record(vs1053b_handle_t *handle, char *path, uint32_t sample_rate)
record audio
uint8_t vs1053b_play(vs1053b_handle_t *handle, char *path)
play audio
uint8_t vs1053b_load_patch(vs1053b_handle_t *handle, const uint16_t *patch, uint16_t len)
load patch
uint8_t vs1053b_pause(vs1053b_handle_t *handle)
pause audio
uint8_t vs1053b_write_ram(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
write ram
uint8_t vs1053b_get_hdata1(vs1053b_handle_t *handle, uint16_t *dat1)
get hdata1
vs1053b_channel_t
vs1053b channel enumeration definition
uint8_t vs1053b_get_native_spi_modes(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get native spi modes status
uint8_t vs1053b_set_bass_enhancement(vs1053b_handle_t *handle, uint8_t db)
set bass enhancement
uint8_t vs1053b_set_lower_limit_frequency_in_1000_hz(vs1053b_handle_t *handle, uint8_t step)
set lower limit frequency in 1000 hz
uint8_t vs1053b_get_sample_rate(vs1053b_handle_t *handle, uint16_t *rate, vs1053b_channel_t *channel)
get sample rate
uint8_t vs1053b_swing_convert_to_data(vs1053b_handle_t *handle, uint8_t reg, float *db)
convert the register raw data to the swing
uint8_t vs1053b_set_mpeg_layer_i_and_ii(vs1053b_handle_t *handle, vs1053b_bool_t enable)
enable or disable mpeg layer i and ii
uint8_t vs1053b_get_ear_speaker_low_setting(vs1053b_handle_t *handle, vs1053b_bool_t *enable)
get ear speaker low setting status
uint8_t vs1053b_get_clock_range(vs1053b_handle_t *handle, vs1053b_clock_range_t *range)
get clock range
uint8_t vs1053b_lower_limit_frequency_in_10_hz_convert_to_register(vs1053b_handle_t *handle, uint32_t hz, uint8_t *reg)
convert the lower limit frequency in 10 hz to the register raw data
@ VS1053B_TYPE_PERIOD
@ VS1053B_TYPE_PLAY_END
@ VS1053B_TYPE_PLAY_WRITE
@ VS1053B_TYPE_RECORD_END
@ VS1053B_TYPE_RECORD_READ
@ VS1053B_TYPE_RECORD_WRITE
@ VS1053B_TYPE_RECORD_OVER
@ VS1053B_TYPE_PLAY_READ
@ VS1053B_FORMAT_AAC_MP4
@ VS1053B_FORMAT_WAV
@ VS1053B_FORMAT_MP3
@ VS1053B_FORMAT_AAC_ADTS
@ VS1053B_FORMAT_WMA
@ VS1053B_FORMAT_FLAC
@ VS1053B_FORMAT_OGG
@ VS1053B_FORMAT_MIDI
@ VS1053B_FORMAT_AAC_ADIF
@ VS1053B_PATCH_OGG_VENC16K1Q07
@ VS1053B_PATCH_OGG_VENC16K2Q09
@ VS1053B_PATCH_OGG_VENC44K1Q03
@ VS1053B_PATCH_OGG_VENC16K1Q04
@ VS1053B_PATCH_OGG_VENC44K1Q05
@ VS1053B_PATCH_OGG_VENC16K2Q05
@ VS1053B_PATCH_OGG_VENC16K2Q07
@ VS1053B_PATCH_OGG_VENC16K1Q09
@ VS1053B_PATCH_OGG_VENC44K2Q04
@ VS1053B_PATCH_OGG_VENC16K1Q06
@ VS1053B_PATCH_OGG_VENC08K1Q10
@ VS1053B_PATCH_OGG_VENC08K1Q03
@ VS1053B_PATCH_OGG_VENC44K2Q01
@ VS1053B_PATCH_OGG_VENC16K1Q02
@ VS1053B_PATCH_OGG_VENC16K1Q05
@ VS1053B_PATCH_OGG_VENC44K2Q03
@ VS1053B_PATCH_OGG_VENC08K1Q05
@ VS1053B_PATCH_OGG_VENC16K2Q02
@ VS1053B_PATCH_OGG_VENC08K1Q01
@ VS1053B_PATCH_FLAC
@ VS1053B_PATCH_OGG_VENC16K1Q08
@ VS1053B_PATCH_OGG_VENC44K2Q02
@ VS1053B_PATCH_OGG_VENC16K2Q10
@ VS1053B_PATCH_OGG_VENC44K2Q05
@ VS1053B_PATCH_OGG_VENC08K1Q09
@ VS1053B_PATCH_OGG_VENC44K1Q04
@ VS1053B_PATCH_OGG_VENC16K2Q04
@ VS1053B_PATCH_OGG_VENC44K1Q02
@ VS1053B_PATCH_OGG_VENC44K1Q01
@ VS1053B_PATCH_OGG_VENC16K2Q08
@ VS1053B_PATCH_OGG_VENC08K1Q07
@ VS1053B_PATCH_OGG_VENC16K1Q00
@ VS1053B_PATCH_WAV
@ VS1053B_PATCH_OGG_VENC16K2Q00
@ VS1053B_PATCH_OGG_VENC08K1Q08
@ VS1053B_PATCH_OGG_VENC44K2Q00
@ VS1053B_PATCH_OGG_VENC16K1Q10
@ VS1053B_PATCH_OGG_VENC16K2Q01
@ VS1053B_PATCH_OGG_VENC08K1Q00
@ VS1053B_PATCH_OGG_VENC16K1Q01
@ VS1053B_PATCH_OGG_VENC44K1Q00
@ VS1053B_PATCH_OGG_VENC08K1Q02
@ VS1053B_PATCH_OGG_VENC08K1Q06
@ VS1053B_PATCH_OGG_VENC08K1Q04
@ VS1053B_PATCH_OGG_VENC16K1Q03
@ VS1053B_PATCH_OGG_VENC16K2Q06
@ VS1053B_PATCH_OGG_VENC16K2Q03
@ VS1053B_APPLICATION_2
@ VS1053B_APPLICATION_0
@ VS1053B_APPLICATION_1
uint8_t vs1053b_set_data(vs1053b_handle_t *handle, uint8_t *buf, uint16_t len)
set chip data
uint8_t vs1053b_get_reg(vs1053b_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t vs1053b_set_reg(vs1053b_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
vs1053b_format_t format
vs1053b_wav_t wav
uint8_t(* spi_dat_deinit)(void)
void(* timestamp_read)(uint32_t *sec, uint32_t *us)
uint8_t(* spi_cmd_write_address16)(uint16_t addr, uint8_t *buf, uint16_t len)
uint8_t(* dreq_gpio_init)(void)
uint8_t(* spi_dat_write_cmd)(uint8_t *buf, uint16_t len)
uint8_t(* spi_cmd_deinit)(void)
uint8_t buf[VS1053B_BUFFER_SIZE]
uint8_t(* spi_cmd_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_cmd_read_address16)(uint16_t addr, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type, uint32_t cur_pos)
uint8_t(* reset_gpio_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* audio_init)(uint8_t type, char *name, uint32_t *size)
uint8_t(* audio_read)(uint32_t addr, uint16_t size, uint8_t *buffer)
uint8_t(* reset_gpio_init)(void)
uint8_t(* spi_dat_init)(void)
uint8_t(* dreq_gpio_deinit)(void)
uint8_t(* dreq_gpio_read)(uint8_t *data)
uint8_t(* reset_gpio_write)(uint8_t data)
uint8_t(* audio_deinit)(void)
uint8_t(* audio_write)(uint32_t addr, uint16_t size, uint8_t *buffer)
uint32_t driver_version
char manufacturer_name[32]
uint32_t sub_chunk1_size
uint32_t sample_rate
uint32_t sub_chunk2_size
char sub_chunk2_id[4]
uint16_t num_channel
char sub_chunk1_id[4]
uint16_t block_align
uint32_t chunk_size
uint16_t bit_per_sample
uint16_t audio_format