LibDriver ISD17XX
Loading...
Searching...
No Matches
driver_isd17xx.c
Go to the documentation of this file.
1
36
37#include "driver_isd17xx.h"
38
42#define CHIP_NAME "Nuvoton ISD17XX"
43#define MANUFACTURER_NAME "Nuvoton"
44#define SUPPLY_VOLTAGE_MIN 2.4f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 20.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define ISD17XX_COMMAND_PU 0x01
55#define ISD17XX_COMMAND_STOP 0x02
56#define ISD17XX_COMMAND_RESET 0x03
57#define ISD17XX_COMMAND_CLR_INT 0x04
58#define ISD17XX_COMMAND_RD_STATUS 0x05
59#define ISD17XX_COMMAND_RD_PLAY_PTR 0x06
60#define ISD17XX_COMMAND_PD 0x07
61#define ISD17XX_COMMAND_RD_REC_PTR 0x08
62#define ISD17XX_COMMAND_DEVID 0x09
63#define ISD17XX_COMMAND_PLAY 0x40
64#define ISD17XX_COMMAND_REC 0x41
65#define ISD17XX_COMMAND_ERASE 0x42
66#define ISD17XX_COMMAND_G_ERASE 0x43
67#define ISD17XX_COMMAND_RD_APC 0x44
68#define ISD17XX_COMMAND_WR_APC1 0x45
69#define ISD17XX_COMMAND_WR_APC2 0x65
70#define ISD17XX_COMMAND_WR_NVCFG 0x46
71#define ISD17XX_COMMAND_LD_NVCFG 0x47
72#define ISD17XX_COMMAND_FWD 0x48
73#define ISD17XX_COMMAND_CHK_MEM 0x49
74#define ISD17XX_COMMAND_EXTCLK 0x4A
75#define ISD17XX_COMMAND_SET_PLAY 0x80
76#define ISD17XX_COMMAND_SET_REC 0x81
77#define ISD17XX_COMMAND_SET_ERASE 0x82
78
85static uint8_t a_high_low_shift(uint8_t data)
86{
87 uint8_t output;
88
89 output = (data << 4) | (data >> 4); /* part 1 */
90 output = ((output << 2) & 0xCC) | ((output >> 2) & 0x33); /* part 2 */
91 output = ((output << 1) & 0xAA) | ((output >> 1) & 0x55); /* part 3 */
92
93 return output; /* return output */
94}
95
107static uint8_t a_isd17xx_spi_transmit(isd17xx_handle_t *handle, uint8_t *tx, uint8_t *rx, uint16_t len)
108{
109 uint16_t i;
110
111 for (i = 0; i < len; i++) /* loop all */
112 {
113 tx[i] = a_high_low_shift(tx[i]); /* msb to lsb */
114 }
115
116 if (handle->spi_transmit(tx, rx, len) != 0) /* spi transmit */
117 {
118 return 1; /* return error */
119 }
120
121 for (i = 0; i < len; i++) /* loop all */
122 {
123 rx[i] = a_high_low_shift(rx[i]); /* msb to lsb */
124 }
125
126 return 0; /* success return 0 */
127}
128
140static uint8_t a_isd17xx_spi_read(isd17xx_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
141{
142 uint16_t i;
143
144 if (handle->spi_read(a_high_low_shift(reg), buf, len) != 0) /* spi read */
145 {
146 return 1; /* return error */
147 }
148
149 for (i = 0; i < len; i++) /* loop all */
150 {
151 buf[i] = a_high_low_shift(buf[i]); /* msb to lsb */
152 }
153
154 return 0; /* success return 0 */
155}
156
168static uint8_t a_isd17xx_spi_write(isd17xx_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
169{
170 uint16_t i;
171
172 for (i = 0; i < len; i++) /* loop all */
173 {
174 buf[i] = a_high_low_shift(buf[i]); /* msb to lsb */
175 }
176
177 if (handle->spi_write(a_high_low_shift(reg), buf, len) != 0) /* spi write */
178 {
179 return 1; /* return error */
180 }
181
182 return 0; /* success return 0 */
183}
184
197static uint8_t a_isd17xx_check_status(isd17xx_handle_t *handle, uint32_t prev_ms, uint8_t check_status,
198 uint16_t status, uint32_t timeout_ms)
199{
200 uint8_t flag;
201 uint8_t status2;
202 uint16_t status1;
203 uint32_t timeout;
204 uint8_t buf[3];
205 uint8_t status_buf[3];
206
207 handle->delay_ms(10); /* delay 10ms */
208 buf[0] = ISD17XX_COMMAND_RD_STATUS; /* set read status command */
209 buf[1] = 0x00; /* set 0x00 */
210 buf[2] = 0x00; /* set 0x00 */
211 if (a_isd17xx_spi_transmit(handle, buf, status_buf, 3) != 0) /* read the status */
212 {
213 handle->debug_print("isd17xx: get status failed.\n"); /* get status failed */
214
215 return 1; /* return error */
216 }
217 else
218 {
219 status1 = ((uint16_t)status_buf[0]) << 8 | status_buf[1]; /* set the status1 */
220 }
221
222 if ((status1 & ISD17XX_STATUS1_CMD_ERR) != 0) /* check the command error */
223 {
224 handle->debug_print("isd17xx: command error.\n"); /* command error */
225
226 return 1; /* return error */
227 }
228
229 if (prev_ms != 0) /* if need prev delay */
230 {
231 handle->delay_ms(prev_ms); /* delay ms */
232 }
233 if (check_status != 0) /* if check the status */
234 {
235 timeout = timeout_ms / 10; /* set the timeout */
236 flag = 0; /* init 0 */
237 while (timeout != 0) /* check the timeout */
238 {
239 buf[0] = ISD17XX_COMMAND_RD_STATUS; /* set read status command */
240 buf[1] = 0x00; /* set 0x00 */
241 buf[2] = 0x00; /* set 0x00 */
242 if (a_isd17xx_spi_transmit(handle, buf, status_buf, 3) != 0) /* read the status */
243 {
244 handle->debug_print("isd17xx: get status failed.\n"); /* get status failed */
245
246 return 1; /* return error */
247 }
248 else
249 {
250 status1 = ((uint16_t)status_buf[0]) << 8 | status_buf[1]; /* set the status1 */
251 status2 = status_buf[2]; /* set the status2 */
252 }
253
254 if ((status1 & (ISD17XX_STATUS1_EOM | ISD17XX_STATUS1_INT)) != 0) /* check the eom and int */
255 {
256 buf[0] = 0x00; /* set 0x00 */
257 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_CLR_INT, buf, 1) != 0) /* set clear interrupt */
258 {
259 handle->debug_print("isd17xx: set clear interrupt failed.\n"); /* set clear interrupt failed */
260
261 return 1; /* return error */
262 }
263 flag = 1; /* set flag */
264 }
265 if ((status2 & status) != 0) /* check the status */
266 {
267 if (flag != 0)
268 { /* check the flag */
269 handle->delay_ms(10); /* delay 10ms */
270 }
271
272 break; /* break */
273 }
274 else
275 {
276 handle->delay_ms(10); /* delay 10ms */
277 timeout--; /* timeout-- */
278 if (timeout == 0) /* check the timeout */
279 {
280 handle->debug_print("isd17xx: timeout.\n"); /* timeout */
281
282 return 1; /* return error */
283 }
284 }
285 }
286 }
287
288 return 0; /* success return 0 */
289}
290
302{
303 uint8_t buf[1];
304
305 if (handle == NULL) /* check handle */
306 {
307 return 2; /* return error */
308 }
309 if (handle->inited != 1) /* check handle initialization */
310 {
311 return 3; /* return error */
312 }
313
314 buf[0] = 0x00; /* set 0x00 */
315 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_PU, buf, 1) != 0) /* set power up */
316 {
317 handle->debug_print("isd17xx: set power up failed.\n"); /* set power up failed */
318
319 return 1; /* return error */
320 }
321 else
322 {
323 return a_isd17xx_check_status(handle, 100, 1,
324 ISD17XX_STATUS2_RDY, 1000); /* check the status */
325 }
326}
327
339{
340 uint8_t buf[1];
341
342 if (handle == NULL) /* check handle */
343 {
344 return 2; /* return error */
345 }
346 if (handle->inited != 1) /* check handle initialization */
347 {
348 return 3; /* return error */
349 }
350
351 buf[0] = 0x00; /* set 0x00 */
352 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_STOP, buf, 1) != 0) /* set stop */
353 {
354 handle->debug_print("isd17xx: set stop failed.\n"); /* set stop failed */
355
356 return 1; /* return error */
357 }
358 else
359 {
360 return a_isd17xx_check_status(handle, 0, 1,
361 ISD17XX_STATUS2_RDY, 1000); /* check the status */
362 }
363}
364
376{
377 uint8_t buf[1];
378
379 if (handle == NULL) /* check handle */
380 {
381 return 2; /* return error */
382 }
383 if (handle->inited != 1) /* check handle initialization */
384 {
385 return 3; /* return error */
386 }
387
388 buf[0] = 0x00; /* set 0x00 */
389 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_RESET, buf, 1) != 0) /* set reset */
390 {
391 handle->debug_print("isd17xx: set reset failed.\n"); /* set reset failed */
392
393 return 1; /* return error */
394 }
395 else
396 {
397 return a_isd17xx_check_status(handle, 100, 0, 0, 0); /* check the status */
398 }
399}
400
412{
413 uint8_t buf[1];
414
415 if (handle == NULL) /* check handle */
416 {
417 return 2; /* return error */
418 }
419 if (handle->inited != 1) /* check handle initialization */
420 {
421 return 3; /* return error */
422 }
423
424 buf[0] = 0x00; /* set 0x00 */
425 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_CLR_INT, buf, 1) != 0) /* set clear interrupt */
426 {
427 handle->debug_print("isd17xx: set clear interrupt failed.\n"); /* set clear interrupt failed */
428
429 return 1; /* return error */
430 }
431 else
432 {
433 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
434 }
435}
436
449uint8_t isd17xx_get_status(isd17xx_handle_t *handle, uint16_t *status1, uint8_t *status2)
450{
451 uint8_t buf[3];
452 uint8_t status[3];
453
454 if (handle == NULL) /* check handle */
455 {
456 return 2; /* return error */
457 }
458 if (handle->inited != 1) /* check handle initialization */
459 {
460 return 3; /* return error */
461 }
462
463 buf[0] = ISD17XX_COMMAND_RD_STATUS; /* set read status command */
464 buf[1] = 0x00; /* set 0x00 */
465 buf[2] = 0x00; /* set 0x00 */
466 if (a_isd17xx_spi_transmit(handle, buf, status, 3) != 0) /* read the status */
467 {
468 handle->debug_print("isd17xx: get status failed.\n"); /* get status failed */
469
470 return 1; /* return error */
471 }
472 else
473 {
474 *status1 = ((uint16_t)status[0]) << 8 | status[1]; /* set the status1 */
475 *status2 = status[2]; /* set the status2 */
476
477 if ((*status1 & (ISD17XX_STATUS1_EOM | ISD17XX_STATUS1_INT)) != 0) /* check the eom and int */
478 {
479 buf[0] = 0x00; /* set 0x00 */
480 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_CLR_INT, buf, 1) != 0) /* set clear interrupt */
481 {
482 handle->debug_print("isd17xx: set clear interrupt failed.\n"); /* set clear interrupt failed */
483
484 return 1; /* return error */
485 }
486 }
487
488 return 0; /* success return 0 */
489 }
490}
491
503{
504 uint8_t buf[1];
505
506 if (handle == NULL) /* check handle */
507 {
508 return 2; /* return error */
509 }
510 if (handle->inited != 1) /* check handle initialization */
511 {
512 return 3; /* return error */
513 }
514
515 buf[0] = 0x00; /* set 0x00 */
516 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_PD, buf, 1) != 0) /* set power down */
517 {
518 handle->debug_print("isd17xx: set power down failed.\n"); /* set power down failed */
519
520 return 1; /* return error */
521 }
522 else
523 {
524 return 0; /* success return 0 */
525 }
526}
527
539uint8_t isd17xx_get_device_id(isd17xx_handle_t *handle, uint8_t *id)
540{
541 uint8_t buf[3];
542 uint8_t status[3];
543
544 if (handle == NULL) /* check handle */
545 {
546 return 2; /* return error */
547 }
548 if (handle->inited != 1) /* check handle initialization */
549 {
550 return 3; /* return error */
551 }
552
553 buf[0] = ISD17XX_COMMAND_DEVID; /* set device id command */
554 buf[1] = 0x00; /* set 0x00 */
555 buf[2] = 0x00; /* set 0x00 */
556 if (a_isd17xx_spi_transmit(handle, buf, status, 3) != 0) /* read the device id */
557 {
558 handle->debug_print("isd17xx: get device id failed.\n"); /* get device id failed */
559
560 return 1; /* return error */
561 }
562 else
563 {
564 *id = (status[2] >> 3) & 0xFF; /* set the device id */
565
566 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
567 }
568}
569
581{
582 uint8_t buf[1];
583
584 if (handle == NULL) /* check handle */
585 {
586 return 2; /* return error */
587 }
588 if (handle->inited != 1) /* check handle initialization */
589 {
590 return 3; /* return error */
591 }
592
593 buf[0] = 0x00; /* set 0x00 */
594 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_PLAY, buf, 1) != 0) /* set play */
595 {
596 handle->debug_print("isd17xx: set play failed.\n"); /* set play failed */
597
598 return 1; /* return error */
599 }
600 else
601 {
602 handle->delay_ms(500); /* delay 500ms */
603
604 return 0; /* success return 0 */
605 }
606}
607
619{
620 uint8_t buf[1];
621
622 if (handle == NULL) /* check handle */
623 {
624 return 2; /* return error */
625 }
626 if (handle->inited != 1) /* check handle initialization */
627 {
628 return 3; /* return error */
629 }
630
631 buf[0] = 0x00; /* set 0x00 */
632 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_REC, buf, 1) != 0) /* set record */
633 {
634 handle->debug_print("isd17xx: set record failed.\n"); /* set record failed */
635
636 return 1; /* return error */
637 }
638 else
639 {
640 handle->delay_ms(500); /* delay 500ms */
641
642 return 0; /* success return 0 */
643 }
644}
645
657{
658 uint8_t buf[1];
659
660 if (handle == NULL) /* check handle */
661 {
662 return 2; /* return error */
663 }
664 if (handle->inited != 1) /* check handle initialization */
665 {
666 return 3; /* return error */
667 }
668
669 buf[0] = 0x00; /* set 0x00 */
670 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_ERASE, buf, 1) != 0) /* set erase */
671 {
672 handle->debug_print("isd17xx: set erase failed.\n"); /* set erase failed */
673
674 return 1; /* return error */
675 }
676 else
677 {
678 handle->delay_ms(500); /* delay 500ms */
679
680 return 0; /* success return 0 */
681 }
682}
683
695{
696 uint8_t buf[1];
697
698 if (handle == NULL) /* check handle */
699 {
700 return 2; /* return error */
701 }
702 if (handle->inited != 1) /* check handle initialization */
703 {
704 return 3; /* return error */
705 }
706
707 buf[0] = 0x00; /* set 0x00 */
708 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_G_ERASE, buf, 1) != 0) /* set global erase */
709 {
710 handle->debug_print("isd17xx: set global erase failed.\n"); /* set global erase failed */
711
712 return 1; /* return error */
713 }
714 else
715 {
716 handle->delay_ms(500); /* delay 500ms */
717
718 return 0; /* success return 0 */
719 }
720}
721
733{
734 uint8_t buf[1];
735
736 if (handle == NULL) /* check handle */
737 {
738 return 2; /* return error */
739 }
740 if (handle->inited != 1) /* check handle initialization */
741 {
742 return 3; /* return error */
743 }
744
745 buf[0] = 0x00; /* set 0x00 */
746 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_FWD, buf, 1) != 0) /* set next */
747 {
748 handle->debug_print("isd17xx: set next failed.\n"); /* set next failed */
749
750 return 1; /* return error */
751 }
752 else
753 {
754 handle->delay_ms(500); /* delay 500ms */
755
756 return 0; /* success return 0 */
757 }
758}
759
771{
772 uint8_t buf[1];
773
774 if (handle == NULL) /* check handle */
775 {
776 return 2; /* return error */
777 }
778 if (handle->inited != 1) /* check handle initialization */
779 {
780 return 3; /* return error */
781 }
782
783 buf[0] = 0x00; /* set 0x00 */
784 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_CHK_MEM, buf, 1) != 0) /* set check memory */
785 {
786 handle->debug_print("isd17xx: set check memory failed.\n"); /* set check memory failed */
787
788 return 1; /* return error */
789 }
790 else
791 {
792 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
793 }
794}
795
807uint8_t isd17xx_read_play_point(isd17xx_handle_t *handle, uint16_t *point)
808{
809 uint8_t buf[4];
810 uint8_t data[4];
811
812 if (handle == NULL) /* check handle */
813 {
814 return 2; /* return error */
815 }
816 if (handle->inited != 1) /* check handle initialization */
817 {
818 return 3; /* return error */
819 }
820
821 buf[0] = ISD17XX_COMMAND_RD_PLAY_PTR; /* read play point command */
822 buf[1] = 0x00; /* set 0x00 */
823 buf[2] = 0x00; /* set 0x00 */
824 buf[3] = 0x00; /* set 0x00 */
825 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
826 {
827 handle->debug_print("isd17xx: read play point failed.\n"); /* read play point failed */
828
829 return 1; /* return error */
830 }
831 else
832 {
833 *point = (uint16_t)(data[3] & 0x7) << 8 | data[2]; /* set the point */
834
835 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
836 }
837}
838
850uint8_t isd17xx_read_record_point(isd17xx_handle_t *handle, uint16_t *point)
851{
852 uint8_t buf[4];
853 uint8_t data[4];
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
864 buf[0] = ISD17XX_COMMAND_RD_REC_PTR; /* read record point command */
865 buf[1] = 0x00; /* set 0x00 */
866 buf[2] = 0x00; /* set 0x00 */
867 buf[3] = 0x00; /* set 0x00 */
868 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
869 {
870 handle->debug_print("isd17xx: read record point failed.\n"); /* read record point failed */
871
872 return 1; /* return error */
873 }
874 else
875 {
876 *point = (uint16_t)(data[3] & 0x7) << 8 | data[2]; /* set the point */
877
878 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
879 }
880}
881
895uint8_t isd17xx_set_volume(isd17xx_handle_t *handle, uint8_t vol)
896{
897 uint8_t buf[4];
898 uint8_t data[4];
899 uint8_t config;
900
901 if (handle == NULL) /* check handle */
902 {
903 return 2; /* return error */
904 }
905 if (handle->inited != 1) /* check handle initialization */
906 {
907 return 3; /* return error */
908 }
909 if (vol > 0x7) /* check the vol */
910 {
911 handle->debug_print("isd17xx: vol is over 7.\n"); /* vol is over 7 */
912
913 return 4; /* return error */
914 }
915
916 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
917 buf[1] = 0x00; /* set 0x00 */
918 buf[2] = 0x00; /* set 0x00 */
919 buf[3] = 0x00; /* set 0x00 */
920 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
921 {
922 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
923
924 return 1; /* return error */
925 }
926 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
927 {
928 return 1; /* return error */
929 }
930
931 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
932 config &= ~0x7; /* clear config */
933 config |= vol; /* set the vol */
934 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
935 {
936 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
937 }
938 else /* register control */
939 {
940 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
941 }
942 buf[1] = config & 0xFF; /* set low */
943 buf[2] = ((uint16_t)config >> 8) & 0xFF; /* set high */
944 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
945 {
946 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
947
948 return 1; /* return error */
949 }
950
951 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
952}
953
965uint8_t isd17xx_get_volume(isd17xx_handle_t *handle, uint8_t *vol)
966{
967 uint8_t buf[4];
968 uint8_t data[4];
969 uint16_t config;
970
971 if (handle == NULL) /* check handle */
972 {
973 return 2; /* return error */
974 }
975 if (handle->inited != 1) /* check handle initialization */
976 {
977 return 3; /* return error */
978 }
979
980 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
981 buf[1] = 0x00; /* set 0x00 */
982 buf[2] = 0x00; /* set 0x00 */
983 buf[3] = 0x00; /* set 0x00 */
984 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
985 {
986 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
987
988 return 1; /* return error */
989 }
990 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
991 *vol = config & 0x7; /* get the volume */
992
993 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
994}
995
1008{
1009 uint8_t buf[4];
1010 uint8_t data[4];
1011 uint16_t config;
1012
1013 if (handle == NULL) /* check handle */
1014 {
1015 return 2; /* return error */
1016 }
1017 if (handle->inited != 1) /* check handle initialization */
1018 {
1019 return 3; /* return error */
1020 }
1021
1022 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1023 buf[1] = 0x00; /* set 0x00 */
1024 buf[2] = 0x00; /* set 0x00 */
1025 buf[3] = 0x00; /* set 0x00 */
1026 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1027 {
1028 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1029
1030 return 1; /* return error */
1031 }
1032 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1033 {
1034 return 1; /* return error */
1035 }
1036
1037 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1038 config &= ~(1 << 3); /* clear config */
1039 config |= enable << 3; /* set the config */
1040 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1041 {
1042 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1043 }
1044 else /* register control */
1045 {
1046 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1047 }
1048 buf[1] = config & 0xFF; /* set low */
1049 buf[2] = (config >> 8) & 0xFF; /* set high */
1050 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1051 {
1052 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1053
1054 return 1; /* return error */
1055 }
1056
1057 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1058}
1059
1072{
1073 uint8_t buf[4];
1074 uint8_t data[4];
1075 uint16_t config;
1076
1077 if (handle == NULL) /* check handle */
1078 {
1079 return 2; /* return error */
1080 }
1081 if (handle->inited != 1) /* check handle initialization */
1082 {
1083 return 3; /* return error */
1084 }
1085
1086 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1087 buf[1] = 0x00; /* set 0x00 */
1088 buf[2] = 0x00; /* set 0x00 */
1089 buf[3] = 0x00; /* set 0x00 */
1090 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1091 {
1092 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1093
1094 return 1; /* return error */
1095 }
1096 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1097 *enable = (isd17xx_bool_t)((config >> 3) & 0x01); /* get the bool */
1098
1099 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1100}
1101
1114{
1115 uint8_t buf[4];
1116 uint8_t data[4];
1117 uint16_t config;
1118
1119 if (handle == NULL) /* check handle */
1120 {
1121 return 2; /* return error */
1122 }
1123 if (handle->inited != 1) /* check handle initialization */
1124 {
1125 return 3; /* return error */
1126 }
1127
1128 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1129 buf[1] = 0x00; /* set 0x00 */
1130 buf[2] = 0x00; /* set 0x00 */
1131 buf[3] = 0x00; /* set 0x00 */
1132 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1133 {
1134 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1135
1136 return 1; /* return error */
1137 }
1138 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1139 {
1140 return 1; /* return error */
1141 }
1142
1143 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1144 config &= ~(1 << 4); /* clear config */
1145 config |= enable << 4; /* set the config */
1146 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1147 {
1148 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1149 }
1150 else /* register control */
1151 {
1152 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1153 }
1154 buf[1] = config & 0xFF; /* set low */
1155 buf[2] = (config >> 8) & 0xFF; /* set high */
1156 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1157 {
1158 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1159
1160 return 1; /* return error */
1161 }
1162
1163 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1164}
1165
1178{
1179 uint8_t buf[4];
1180 uint8_t data[4];
1181 uint16_t config;
1182
1183 if (handle == NULL) /* check handle */
1184 {
1185 return 2; /* return error */
1186 }
1187 if (handle->inited != 1) /* check handle initialization */
1188 {
1189 return 3; /* return error */
1190 }
1191
1192 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1193 buf[1] = 0x00; /* set 0x00 */
1194 buf[2] = 0x00; /* set 0x00 */
1195 buf[3] = 0x00; /* set 0x00 */
1196 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1197 {
1198 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1199
1200 return 1; /* return error */
1201 }
1202 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1203 *enable = (isd17xx_bool_t)((config >> 4) & 0x01); /* get the bool */
1204
1205 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1206}
1207
1220{
1221 uint8_t buf[4];
1222 uint8_t data[4];
1223 uint16_t config;
1224
1225 if (handle == NULL) /* check handle */
1226 {
1227 return 2; /* return error */
1228 }
1229 if (handle->inited != 1) /* check handle initialization */
1230 {
1231 return 3; /* return error */
1232 }
1233
1234 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1235 buf[1] = 0x00; /* set 0x00 */
1236 buf[2] = 0x00; /* set 0x00 */
1237 buf[3] = 0x00; /* set 0x00 */
1238 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1239 {
1240 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1241
1242 return 1; /* return error */
1243 }
1244 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1245 {
1246 return 1; /* return error */
1247 }
1248
1249 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1250 config &= ~(1 << 5); /* clear config */
1251 config |= (!enable) << 5; /* set the config */
1252 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1253 {
1254 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1255 }
1256 else /* register control */
1257 {
1258 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1259 }
1260 buf[1] = config & 0xFF; /* set low */
1261 buf[2] = (config >> 8) & 0xFF; /* set high */
1262 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1263 {
1264 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1265
1266 return 1; /* return error */
1267 }
1268
1269 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1270}
1271
1284{
1285 uint8_t buf[4];
1286 uint8_t data[4];
1287 uint16_t config;
1288
1289 if (handle == NULL) /* check handle */
1290 {
1291 return 2; /* return error */
1292 }
1293 if (handle->inited != 1) /* check handle initialization */
1294 {
1295 return 3; /* return error */
1296 }
1297
1298 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1299 buf[1] = 0x00; /* set 0x00 */
1300 buf[2] = 0x00; /* set 0x00 */
1301 buf[3] = 0x00; /* set 0x00 */
1302 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1303 {
1304 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1305
1306 return 1; /* return error */
1307 }
1308 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1309 *enable = (isd17xx_bool_t)(!((config >> 5) & 0x01)); /* get the bool */
1310
1311 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1312}
1313
1326{
1327 uint8_t buf[4];
1328 uint8_t data[4];
1329 uint16_t config;
1330
1331 if (handle == NULL) /* check handle */
1332 {
1333 return 2; /* return error */
1334 }
1335 if (handle->inited != 1) /* check handle initialization */
1336 {
1337 return 3; /* return error */
1338 }
1339
1340 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1341 buf[1] = 0x00; /* set 0x00 */
1342 buf[2] = 0x00; /* set 0x00 */
1343 buf[3] = 0x00; /* set 0x00 */
1344 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1345 {
1346 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1347
1348 return 1; /* return error */
1349 }
1350 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1351 {
1352 return 1; /* return error */
1353 }
1354
1355 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1356 config &= ~(1 << 6); /* clear config */
1357 config |= (!enable) << 6; /* set the config */
1358 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1359 {
1360 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1361 }
1362 else /* register control */
1363 {
1364 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1365 }
1366 buf[1] = config & 0xFF; /* set low */
1367 buf[2] = (config >> 8) & 0xFF; /* set high */
1368 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1369 {
1370 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1371
1372 return 1; /* return error */
1373 }
1374
1375 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1376}
1377
1390{
1391 uint8_t buf[4];
1392 uint8_t data[4];
1393 uint16_t config;
1394
1395 if (handle == NULL) /* check handle */
1396 {
1397 return 2; /* return error */
1398 }
1399 if (handle->inited != 1) /* check handle initialization */
1400 {
1401 return 3; /* return error */
1402 }
1403
1404 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1405 buf[1] = 0x00; /* set 0x00 */
1406 buf[2] = 0x00; /* set 0x00 */
1407 buf[3] = 0x00; /* set 0x00 */
1408 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1409 {
1410 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1411
1412 return 1; /* return error */
1413 }
1414 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1415 *enable = (isd17xx_bool_t)(!((config >> 6) & 0x01)); /* get the bool */
1416
1417 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1418}
1419
1432{
1433 uint8_t buf[4];
1434 uint8_t data[4];
1435 uint16_t config;
1436
1437 if (handle == NULL) /* check handle */
1438 {
1439 return 2; /* return error */
1440 }
1441 if (handle->inited != 1) /* check handle initialization */
1442 {
1443 return 3; /* return error */
1444 }
1445
1446 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1447 buf[1] = 0x00; /* set 0x00 */
1448 buf[2] = 0x00; /* set 0x00 */
1449 buf[3] = 0x00; /* set 0x00 */
1450 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1451 {
1452 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1453
1454 return 1; /* return error */
1455 }
1456 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1457 {
1458 return 1; /* return error */
1459 }
1460
1461 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1462 config &= ~(1 << 7); /* clear config */
1463 config |= output << 7; /* set the output */
1464 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1465 {
1466 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1467 }
1468 else /* register control */
1469 {
1470 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1471 }
1472 buf[1] = config & 0xFF; /* set low */
1473 buf[2] = (config >> 8) & 0xFF; /* set high */
1474 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1475 {
1476 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1477
1478 return 1; /* return error */
1479 }
1480
1481 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1482}
1483
1496{
1497 uint8_t buf[4];
1498 uint8_t data[4];
1499 uint16_t config;
1500
1501 if (handle == NULL) /* check handle */
1502 {
1503 return 2; /* return error */
1504 }
1505 if (handle->inited != 1) /* check handle initialization */
1506 {
1507 return 3; /* return error */
1508 }
1509
1510 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1511 buf[1] = 0x00; /* set 0x00 */
1512 buf[2] = 0x00; /* set 0x00 */
1513 buf[3] = 0x00; /* set 0x00 */
1514 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1515 {
1516 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1517
1518 return 1; /* return error */
1519 }
1520 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1521 *output = (isd17xx_analog_output_t)((config >> 7) & 0x01); /* get the bool */
1522
1523 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1524}
1525
1538{
1539 uint8_t buf[4];
1540 uint8_t data[4];
1541 uint16_t config;
1542
1543 if (handle == NULL) /* check handle */
1544 {
1545 return 2; /* return error */
1546 }
1547 if (handle->inited != 1) /* check handle initialization */
1548 {
1549 return 3; /* return error */
1550 }
1551
1552 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1553 buf[1] = 0x00; /* set 0x00 */
1554 buf[2] = 0x00; /* set 0x00 */
1555 buf[3] = 0x00; /* set 0x00 */
1556 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1557 {
1558 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1559
1560 return 1; /* return error */
1561 }
1562 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1563 {
1564 return 1; /* return error */
1565 }
1566
1567 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1568 config &= ~((uint16_t)1 << 8); /* clear config */
1569 config |= (!enable) << 8; /* set the config */
1570 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1571 {
1572 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1573 }
1574 else /* register control */
1575 {
1576 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1577 }
1578 buf[1] = config & 0xFF; /* set low */
1579 buf[2] = (config >> 8) & 0xFF; /* set high */
1580 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1581 {
1582 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1583
1584 return 1; /* return error */
1585 }
1586
1587 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1588}
1589
1602{
1603 uint8_t buf[4];
1604 uint8_t data[4];
1605 uint16_t config;
1606
1607 if (handle == NULL) /* check handle */
1608 {
1609 return 2; /* return error */
1610 }
1611 if (handle->inited != 1) /* check handle initialization */
1612 {
1613 return 3; /* return error */
1614 }
1615
1616 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1617 buf[1] = 0x00; /* set 0x00 */
1618 buf[2] = 0x00; /* set 0x00 */
1619 buf[3] = 0x00; /* set 0x00 */
1620 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1621 {
1622 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1623
1624 return 1; /* return error */
1625 }
1626 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1627 *enable = (isd17xx_bool_t)(!((config >> 8) & 0x01)); /* get the bool */
1628
1629 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1630}
1631
1644{
1645 uint8_t buf[4];
1646 uint8_t data[4];
1647 uint16_t config;
1648
1649 if (handle == NULL) /* check handle */
1650 {
1651 return 2; /* return error */
1652 }
1653 if (handle->inited != 1) /* check handle initialization */
1654 {
1655 return 3; /* return error */
1656 }
1657
1658 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1659 buf[1] = 0x00; /* set 0x00 */
1660 buf[2] = 0x00; /* set 0x00 */
1661 buf[3] = 0x00; /* set 0x00 */
1662 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1663 {
1664 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1665
1666 return 1; /* return error */
1667 }
1668 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1669 {
1670 return 1; /* return error */
1671 }
1672
1673 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1674 config &= ~((uint16_t)1 << 9); /* clear config */
1675 config |= (!enable) << 9; /* set the config */
1676 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1677 {
1678 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1679 }
1680 else /* register control */
1681 {
1682 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1683 }
1684 buf[1] = config & 0xFF; /* set low */
1685 buf[2] = (config >> 8) & 0xFF; /* set high */
1686 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1687 {
1688 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1689
1690 return 1; /* return error */
1691 }
1692
1693 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1694}
1695
1708{
1709 uint8_t buf[4];
1710 uint8_t data[4];
1711 uint16_t config;
1712
1713 if (handle == NULL) /* check handle */
1714 {
1715 return 2; /* return error */
1716 }
1717 if (handle->inited != 1) /* check handle initialization */
1718 {
1719 return 3; /* return error */
1720 }
1721
1722 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1723 buf[1] = 0x00; /* set 0x00 */
1724 buf[2] = 0x00; /* set 0x00 */
1725 buf[3] = 0x00; /* set 0x00 */
1726 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1727 {
1728 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1729
1730 return 1; /* return error */
1731 }
1732 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1733 *enable = (isd17xx_bool_t)(!((config >> 9) & 0x01)); /* get the bool */
1734
1735 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1736}
1737
1750{
1751 uint8_t buf[4];
1752 uint8_t data[4];
1753 uint16_t config;
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
1764 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1765 buf[1] = 0x00; /* set 0x00 */
1766 buf[2] = 0x00; /* set 0x00 */
1767 buf[3] = 0x00; /* set 0x00 */
1768 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1769 {
1770 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1771
1772 return 1; /* return error */
1773 }
1774 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1775 {
1776 return 1; /* return error */
1777 }
1778
1779 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1780 config &= ~((uint16_t)1 << 10); /* clear config */
1781 config |= (!enable) << 10; /* set the config */
1782 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1783 {
1784 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1785 }
1786 else /* register control */
1787 {
1788 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1789 }
1790 buf[1] = config & 0xFF; /* set low */
1791 buf[2] = (config >> 8) & 0xFF; /* set high */
1792 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1793 {
1794 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1795
1796 return 1; /* return error */
1797 }
1798
1799 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1800}
1801
1814{
1815 uint8_t buf[4];
1816 uint8_t data[4];
1817 uint16_t config;
1818
1819 if (handle == NULL) /* check handle */
1820 {
1821 return 2; /* return error */
1822 }
1823 if (handle->inited != 1) /* check handle initialization */
1824 {
1825 return 3; /* return error */
1826 }
1827
1828 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1829 buf[1] = 0x00; /* set 0x00 */
1830 buf[2] = 0x00; /* set 0x00 */
1831 buf[3] = 0x00; /* set 0x00 */
1832 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1833 {
1834 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1835
1836 return 1; /* return error */
1837 }
1838 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1839 *enable = (isd17xx_bool_t)(!((config >> 10) & 0x01)); /* get the bool */
1840
1841 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1842}
1843
1856{
1857 uint8_t buf[4];
1858 uint8_t data[4];
1859 uint16_t config;
1860
1861 if (handle == NULL) /* check handle */
1862 {
1863 return 2; /* return error */
1864 }
1865 if (handle->inited != 1) /* check handle initialization */
1866 {
1867 return 3; /* return error */
1868 }
1869
1870 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1871 buf[1] = 0x00; /* set 0x00 */
1872 buf[2] = 0x00; /* set 0x00 */
1873 buf[3] = 0x00; /* set 0x00 */
1874 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1875 {
1876 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1877
1878 return 1; /* return error */
1879 }
1880 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1881 {
1882 return 1; /* return error */
1883 }
1884
1885 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1886 config &= ~((uint16_t)1 << 11); /* clear config */
1887 config |= enable << 11; /* set the config */
1888 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1889 {
1890 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1891 }
1892 else /* register control */
1893 {
1894 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
1895 }
1896 buf[1] = config & 0xFF; /* set low */
1897 buf[2] = (config >> 8) & 0xFF; /* set high */
1898 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
1899 {
1900 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
1901
1902 return 1; /* return error */
1903 }
1904
1905 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1906}
1907
1920{
1921 uint8_t buf[4];
1922 uint8_t data[4];
1923 uint16_t config;
1924
1925 if (handle == NULL) /* check handle */
1926 {
1927 return 2; /* return error */
1928 }
1929 if (handle->inited != 1) /* check handle initialization */
1930 {
1931 return 3; /* return error */
1932 }
1933
1934 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1935 buf[1] = 0x00; /* set 0x00 */
1936 buf[2] = 0x00; /* set 0x00 */
1937 buf[3] = 0x00; /* set 0x00 */
1938 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1939 {
1940 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1941
1942 return 1; /* return error */
1943 }
1944 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1945 *enable = (isd17xx_bool_t)((config >> 11) & 0x01); /* get the bool */
1946
1947 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
1948}
1949
1962{
1963 uint8_t buf[4];
1964 uint8_t data[4];
1965 uint16_t config;
1966
1967 if (handle == NULL) /* check handle */
1968 {
1969 return 2; /* return error */
1970 }
1971 if (handle->inited != 1) /* check handle initialization */
1972 {
1973 return 3; /* return error */
1974 }
1975
1976 buf[0] = ISD17XX_COMMAND_RD_APC; /* read apc command */
1977 buf[1] = 0x00; /* set 0x00 */
1978 buf[2] = 0x00; /* set 0x00 */
1979 buf[3] = 0x00; /* set 0x00 */
1980 if (a_isd17xx_spi_transmit(handle, buf, data, 4) != 0) /* read the data */
1981 {
1982 handle->debug_print("isd17xx: read config failed.\n"); /* read config failed */
1983
1984 return 1; /* return error */
1985 }
1986 if (a_isd17xx_check_status(handle, 0, 0, 0, 0) != 0) /* check the status */
1987 {
1988 return 1; /* return error */
1989 }
1990
1991 config = (uint16_t)(data[3] & 0xF) << 8 | data[2]; /* get the config */
1992 handle->vol_control = control; /* set vol control */
1993 if (handle->vol_control == ISD17XX_VOL_CONTROL_BUTTON) /* button control */
1994 {
1995 buf[0] = ISD17XX_COMMAND_WR_APC1; /* write apc command */
1996 }
1997 else /* register control */
1998 {
1999 buf[0] = ISD17XX_COMMAND_WR_APC2; /* write apc command */
2000 }
2001 buf[1] = config & 0xFF; /* set low */
2002 buf[2] = (config >> 8) & 0xFF; /* set high */
2003 if (a_isd17xx_spi_transmit(handle, buf, data, 3) != 0) /* write the data */
2004 {
2005 handle->debug_print("isd17xx: write config failed.\n"); /* write config failed */
2006
2007 return 1; /* return error */
2008 }
2009
2010 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
2011}
2012
2024{
2025 if (handle == NULL) /* check handle */
2026 {
2027 return 2; /* return error */
2028 }
2029 if (handle->inited != 1) /* check handle initialization */
2030 {
2031 return 3; /* return error */
2032 }
2033
2034 *control = (isd17xx_vol_control_t)(handle->vol_control); /* get the vol control */
2035
2036 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
2037}
2038
2050{
2051 uint8_t buf[1];
2052
2053 if (handle == NULL) /* check handle */
2054 {
2055 return 2; /* return error */
2056 }
2057 if (handle->inited != 1) /* check handle initialization */
2058 {
2059 return 3; /* return error */
2060 }
2061
2062 buf[0] = 0x00; /* set 0x00 */
2063 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_WR_NVCFG, buf, 1) != 0) /* set write to nvc */
2064 {
2065 handle->debug_print("isd17xx: set write to nvc failed.\n"); /* set write to nvc failed */
2066
2067 return 1; /* return error */
2068 }
2069
2070 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
2071}
2072
2084{
2085 uint8_t buf[1];
2086
2087 if (handle == NULL) /* check handle */
2088 {
2089 return 2; /* return error */
2090 }
2091 if (handle->inited != 1) /* check handle initialization */
2092 {
2093 return 3; /* return error */
2094 }
2095
2096 buf[0] = 0x00; /* set 0x00 */
2097 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_LD_NVCFG, buf, 1) != 0) /* set load from nvc */
2098 {
2099 handle->debug_print("isd17xx: set load from nvc failed.\n"); /* set load from nvc failed */
2100
2101 return 1; /* return error */
2102 }
2103
2104 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
2105}
2106
2121uint8_t isd17xx_set_play(isd17xx_handle_t *handle, uint16_t start_addr, uint16_t end_addr)
2122{
2123 uint8_t buf[6];
2124
2125 if (handle == NULL) /* check handle */
2126 {
2127 return 2; /* return error */
2128 }
2129 if (handle->inited != 1) /* check handle initialization */
2130 {
2131 return 3; /* return error */
2132 }
2133 if (start_addr >= end_addr) /* check the address */
2134 {
2135 handle->debug_print("isd17xx: start_addr >= end_addr.\n"); /* start_addr >= end_addr */
2136
2137 return 4; /* return error */
2138 }
2139 if (end_addr > handle->end_address) /* check the address */
2140 {
2141 handle->debug_print("isd17xx: address is invalid.\n"); /* address is invalid */
2142
2143 return 5; /* return error */
2144 }
2145
2146 buf[0] = 0x00; /* set 0x00 */
2147 buf[1] = start_addr & 0xFF; /* set start address */
2148 buf[2] = (start_addr >> 8) & 0x07; /* set start address*/
2149 buf[3] = end_addr & 0xFF; /* set end address */
2150 buf[4] = (end_addr >> 8) & 0x07; /* set end address */
2151 buf[5] = 0x00; /* set 0x00 */
2152 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_SET_PLAY, buf, 6) != 0) /* set play */
2153 {
2154 handle->debug_print("isd17xx: set play failed.\n"); /* set play failed */
2155
2156 return 1; /* return error */
2157 }
2158 handle->delay_ms(500); /* delay 500ms */
2159
2160 return 0; /* success return 0 */
2161}
2162
2177uint8_t isd17xx_set_record(isd17xx_handle_t *handle, uint16_t start_addr, uint16_t end_addr)
2178{
2179 uint8_t buf[6];
2180
2181 if (handle == NULL) /* check handle */
2182 {
2183 return 2; /* return error */
2184 }
2185 if (handle->inited != 1) /* check handle initialization */
2186 {
2187 return 3; /* return error */
2188 }
2189 if (start_addr >= end_addr) /* check the address */
2190 {
2191 handle->debug_print("isd17xx: start_addr >= end_addr.\n"); /* start_addr >= end_addr */
2192
2193 return 4; /* return error */
2194 }
2195 if (end_addr > handle->end_address) /* check the address */
2196 {
2197 handle->debug_print("isd17xx: address is invalid.\n"); /* address is invalid */
2198
2199 return 5; /* return error */
2200 }
2201
2202 buf[0] = 0x00; /* set 0x00 */
2203 buf[1] = start_addr & 0xFF; /* set start address */
2204 buf[2] = (start_addr >> 8) & 0x07; /* set start address */
2205 buf[3] = end_addr & 0xFF; /* set end address */
2206 buf[4] = (end_addr >> 8) & 0x07; /* set end address */
2207 buf[5] = 0x00; /* set 0x00 */
2208 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_SET_REC, buf, 6) != 0) /* set record */
2209 {
2210 handle->debug_print("isd17xx: set record failed.\n"); /* set record failed */
2211
2212 return 1; /* return error */
2213 }
2214 handle->delay_ms(500); /* delay 500ms */
2215
2216 return 0; /* success return 0 */
2217}
2218
2233uint8_t isd17xx_set_erase(isd17xx_handle_t *handle, uint16_t start_addr, uint16_t end_addr)
2234{
2235 uint8_t buf[6];
2236
2237 if (handle == NULL) /* check handle */
2238 {
2239 return 2; /* return error */
2240 }
2241 if (handle->inited != 1) /* check handle initialization */
2242 {
2243 return 3; /* return error */
2244 }
2245 if (start_addr >= end_addr) /* check the address */
2246 {
2247 handle->debug_print("isd17xx: start_addr >= end_addr.\n"); /* start_addr >= end_addr */
2248
2249 return 4; /* return error */
2250 }
2251 if (end_addr > handle->end_address) /* check the address */
2252 {
2253 handle->debug_print("isd17xx: address is invalid.\n"); /* address is invalid */
2254
2255 return 5; /* return error */
2256 }
2257
2258 buf[0] = 0x00; /* set 0x00 */
2259 buf[1] = start_addr & 0xFF; /* set start address */
2260 buf[2] = (start_addr >> 8) & 0x07; /* set start address */
2261 buf[3] = end_addr & 0xFF; /* set end address */
2262 buf[4] = (end_addr >> 8) & 0x07; /* set end address */
2263 buf[5] = 0x00; /* set 0x00 */
2264 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_SET_ERASE, buf, 6) != 0) /* set erase */
2265 {
2266 handle->debug_print("isd17xx: set erase failed.\n"); /* set erase failed */
2267
2268 return 1; /* return error */
2269 }
2270 handle->delay_ms(500); /* delay 500ms */
2271
2272 return 0; /* success return 0 */
2273}
2274
2286{
2287 uint8_t buf[1];
2288
2289 if (handle == NULL) /* check handle */
2290 {
2291 return 2; /* return error */
2292 }
2293 if (handle->inited != 1) /* check handle initialization */
2294 {
2295 return 3; /* return error */
2296 }
2297
2298 buf[0] = 0x00; /* set 0x00 */
2299 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_EXTCLK, buf, 1) != 0) /* set toggle */
2300 {
2301 handle->debug_print("isd17xx: set toggle failed.\n"); /* set toggle failed */
2302
2303 return 1; /* return error */
2304 }
2305
2306 return a_isd17xx_check_status(handle, 0, 0, 0, 0); /* check the status */
2307}
2308
2325{
2326 uint8_t id;
2327 uint8_t type_flag;
2328 uint8_t buf[3];
2329 uint8_t status[3];
2330
2331 if (handle == NULL) /* check handle */
2332 {
2333 return 2; /* return error */
2334 }
2335 if (handle->debug_print == NULL) /* check debug_print */
2336 {
2337 return 3; /* return error */
2338 }
2339 if (handle->spi_init == NULL) /* check spi_init */
2340 {
2341 handle->debug_print("isd17xx: spi_init is null.\n"); /* spi_init is null */
2342
2343 return 3; /* return error */
2344 }
2345 if (handle->spi_deinit == NULL) /* check spi_deinit */
2346 {
2347 handle->debug_print("isd17xx: spi_deinit is null.\n"); /* spi_deinit is null */
2348
2349 return 3; /* return error */
2350 }
2351 if (handle->spi_read == NULL) /* check spi_read */
2352 {
2353 handle->debug_print("isd17xx: spi_read is null.\n"); /* spi_read is null */
2354
2355 return 3; /* return error */
2356 }
2357 if (handle->spi_write == NULL) /* check spi_write */
2358 {
2359 handle->debug_print("isd17xx: spi_write is null.\n"); /* spi_write is null */
2360
2361 return 3; /* return error */
2362 }
2363 if (handle->spi_transmit == NULL) /* check spi_transmit */
2364 {
2365 handle->debug_print("isd17xx: spi_transmit is null.\n"); /* spi_transmit is null */
2366
2367 return 3; /* return error */
2368 }
2369 if (handle->gpio_reset_init == NULL) /* check gpio_reset_init */
2370 {
2371 handle->debug_print("isd17xx: gpio_reset_init is null.\n"); /* gpio_reset_init is null */
2372
2373 return 3; /* return error */
2374 }
2375 if (handle->gpio_reset_deinit == NULL) /* check gpio_reset_deinit */
2376 {
2377 handle->debug_print("isd17xx: gpio_reset_deinit is null.\n"); /* gpio_reset_deinit is null */
2378
2379 return 3; /* return error */
2380 }
2381 if (handle->gpio_reset_write == NULL) /* check gpio_reset_write */
2382 {
2383 handle->debug_print("isd17xx: gpio_reset_write is null.\n"); /* gpio_reset_write is null */
2384
2385 return 3; /* return error */
2386 }
2387 if (handle->delay_ms == NULL) /* check delay_ms */
2388 {
2389 handle->debug_print("isd17xx: delay_ms is null.\n"); /* delay_ms is null */
2390
2391 return 3; /* return error */
2392 }
2393
2394 if (handle->spi_init() != 0) /* spi init */
2395 {
2396 handle->debug_print("isd17xx: spi init failed.\n"); /* spi init failed */
2397
2398 return 1; /* return error */
2399 }
2400 if (handle->gpio_reset_init() != 0) /* gpio init */
2401 {
2402 handle->debug_print("isd17xx: gpio init failed.\n"); /* gpio init failed */
2403 (void)handle->spi_deinit(); /* spi deinit */
2404
2405 return 1; /* return error */
2406 }
2407
2408 handle->gpio_reset_write(1); /* set high */
2409 handle->delay_ms(1); /* delay 1ms */
2410 handle->gpio_reset_write(0); /* set low */
2411 handle->delay_ms(1); /* delay 1ms */
2412
2413 buf[0] = 0x00; /* set 0x00 */
2414 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_PU,
2415 buf, 1) != 0) /* set power up */
2416 {
2417 handle->debug_print("isd17xx: set power up failed.\n"); /* set power up failed */
2418 (void)handle->spi_deinit(); /* spi deinit */
2419 (void)handle->gpio_reset_deinit(); /* gpio deinit */
2420
2421 return 7; /* return error */
2422 }
2423 if (a_isd17xx_check_status(handle, 100, 1,
2424 ISD17XX_STATUS2_RDY, 1000) != 0) /* check the status */
2425 {
2426 (void)handle->spi_deinit(); /* spi deinit */
2427 (void)handle->gpio_reset_deinit(); /* gpio deinit */
2428
2429 return 1; /* return error */
2430 }
2431
2432 buf[0] = ISD17XX_COMMAND_DEVID; /* set device id command */
2433 buf[1] = 0x00; /* set 0x00 */
2434 buf[2] = 0x00; /* set 0x00 */
2435 if (a_isd17xx_spi_transmit(handle, buf, status, 3) != 0) /* read the device id */
2436 {
2437 handle->debug_print("isd17xx: get device id failed.\n"); /* get device id failed */
2438 (void)handle->spi_deinit(); /* spi deinit */
2439 (void)handle->gpio_reset_deinit(); /* gpio deinit */
2440
2441 return 4; /* return error */
2442 }
2443 id = (status[2] >> 3) & 0xFF; /* set the device id */
2444 if (id != handle->type) /* check the type */
2445 {
2446 handle->debug_print("isd17xx: chip type is invalid.\n"); /* chip type is invalid */
2447 (void)handle->spi_deinit(); /* spi deinit */
2448 (void)handle->gpio_reset_deinit(); /* gpio deinit */
2449
2450 return 5; /* return error */
2451 }
2452 type_flag = 0; /* init 0 */
2453 switch (handle->type) /* choose the type */
2454 {
2455 case ISD1730 : /* isd1730 */
2456 {
2457 handle->end_address = 0x0FF; /* set the end address */
2458
2459 break; /* break */
2460 }
2461 case ISD1740 : /* isd1740 */
2462 {
2463 handle->end_address = 0x14F; /* set the end address */
2464
2465 break; /* break */
2466 }
2467 case ISD1750 : /* isd1750 */
2468 {
2469 handle->end_address = 0x19F; /* set the end address */
2470
2471 break; /* break */
2472 }
2473 case ISD1760 : /* isd1760 */
2474 {
2475 handle->end_address = 0x1EF; /* set the end address */
2476
2477 break; /* break */
2478 }
2479 case ISD1790 : /* isd1790 */
2480 {
2481 handle->end_address = 0x2DF; /* set the end address */
2482
2483 break; /* break */
2484 }
2485 case ISD17120 : /* isd17120 */
2486 {
2487 handle->end_address = 0x3CF; /* set the end address */
2488
2489 break; /* break */
2490 }
2491 case ISD17150 : /* isd17150 */
2492 {
2493 handle->end_address = 0x4BF; /* set the end address */
2494
2495 break; /* break */
2496 }
2497 case ISD17180 : /* isd17180 */
2498 {
2499 handle->end_address = 0x5AF; /* set the end address */
2500
2501 break; /* break */
2502 }
2503 case ISD17210 : /* isd17210 */
2504 {
2505 handle->end_address = 0x69F; /* set the end address */
2506
2507 break; /* break */
2508 }
2509 case ISD17240 : /* isd17240 */
2510 {
2511 handle->end_address = 0x78F; /* set the end address */
2512
2513 break; /* break */
2514 }
2515 default : /* default */
2516 {
2517 type_flag = 1; /* flag error */
2518
2519 break; /* break */
2520 }
2521 }
2522 if (type_flag == 1) /* check the type */
2523 {
2524 handle->debug_print("isd17xx: unknown type.\n"); /* unknown type */
2525
2526 return 6; /* return error */
2527 }
2528
2529 buf[0] = 0x00; /* set 0x00 */
2530 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_RESET,
2531 buf, 1) != 0) /* set reset */
2532 {
2533 handle->debug_print("isd17xx: set reset failed.\n"); /* set reset failed */
2534 (void)handle->spi_deinit(); /* spi deinit */
2535 (void)handle->gpio_reset_deinit(); /* gpio deinit */
2536
2537 return 8; /* return error */
2538 }
2539 if (a_isd17xx_check_status(handle, 100, 0, 0, 0) != 0) /* check the status */
2540 {
2541 (void)handle->spi_deinit(); /* spi deinit */
2542 (void)handle->gpio_reset_deinit(); /* gpio deinit */
2543
2544 return 1; /* return error */
2545 }
2546 handle->vol_control = ISD17XX_VOL_CONTROL_REG; /* register control */
2547 handle->inited = 1; /* flag finish initialization */
2548
2549 return 0; /* success return 0 */
2550}
2551
2564{
2565 uint8_t buf[1];
2566
2567 if (handle == NULL) /* check handle */
2568 {
2569 return 2; /* return error */
2570 }
2571 if (handle->inited != 1) /* check handle initialization */
2572 {
2573 return 3; /* return error */
2574 }
2575
2576 buf[0] = 0x00; /* set 0x00 */
2577 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_PD, buf, 1) != 0) /* set power down */
2578 {
2579 handle->debug_print("isd17xx: set power down failed.\n"); /* set power down failed */
2580
2581 return 4; /* return error */
2582 }
2583 if (handle->spi_deinit() != 0) /* spi deinit */
2584 {
2585 handle->debug_print("isd17xx: spi deinit failed.\n"); /* spi deinit failed */
2586
2587 return 1; /* return error */
2588 }
2589 if (handle->gpio_reset_deinit() != 0) /* gpio deinit */
2590 {
2591 handle->debug_print("isd17xx: gpio deinit failed.\n"); /* gpio deinit failed */
2592
2593 return 1; /* return error */
2594 }
2595 handle->inited = 0; /* flag close */
2596
2597 return 0; /* success return 0 */
2598}
2599
2611{
2612 if (handle == NULL) /* check handle */
2613 {
2614 return 2; /* return error */
2615 }
2616 if (handle->inited != 1) /* check handle initialization */
2617 {
2618 return 3; /* return error */
2619 }
2620
2621 handle->gpio_reset_write(1); /* set high */
2622 handle->delay_ms(1); /* delay 1ms */
2623 handle->gpio_reset_write(0); /* set low */
2624 handle->delay_ms(1); /* delay 1ms */
2625
2626 return 0; /* success return 0 */
2627}
2628
2640{
2641 uint8_t res;
2642 uint8_t status2;
2643 uint16_t status1;
2644 uint8_t buf[1];
2645
2646 if (handle == NULL) /* check handle */
2647 {
2648 return 2; /* return error */
2649 }
2650 if (handle->inited != 1) /* check handle initialization */
2651 {
2652 return 3; /* return error */
2653 }
2654
2655 res = isd17xx_get_status(handle, &status1, &status2); /* get status */
2656 if (res != 0) /* check the result */
2657 {
2658 handle->debug_print("isd17xx: get status failed.\n"); /* get status failed */
2659
2660 return 1; /* return error */
2661 }
2662 buf[0] = 0x00; /* set 0x00 */
2663 if (a_isd17xx_spi_write(handle, ISD17XX_COMMAND_CLR_INT, buf, 1) != 0) /* set clear interrupt */
2664 {
2665 handle->debug_print("isd17xx: set clear interrupt failed.\n"); /* set clear interrupt failed */
2666
2667 return 1; /* return error */
2668 }
2669 if ((status1 & ISD17XX_STATUS1_EOM) != 0) /* check the eom */
2670 {
2671 if (handle->receive_callback != NULL) /* if receive_callback not null */
2672 {
2673 handle->receive_callback(ISD17XX_STATUS1_EOM); /* run the callback */
2674 }
2675 }
2676 if ((status1 & ISD17XX_STATUS1_INT) != 0) /* check the int */
2677 {
2678 handle->done = 1; /* flag done */
2679 if (handle->receive_callback != NULL) /* if receive_callback not null */
2680 {
2681 handle->receive_callback(ISD17XX_STATUS1_INT); /* run the callback */
2682 }
2683 }
2684
2685 return 0; /* success return 0 */
2686}
2687
2698{
2699 if (handle == NULL) /* check handle */
2700 {
2701 return 2; /* return error */
2702 }
2703
2704 handle->type = type; /* set the type */
2705
2706 return 0; /* success return 0 */
2707}
2708
2719{
2720 if (handle == NULL) /* check handle */
2721 {
2722 return 2; /* return error */
2723 }
2724
2725 *type = (isd17xx_type_t)(handle->type); /* set the type */
2726
2727 return 0; /* success return 0 */
2728}
2729
2743uint8_t isd17xx_set_reg(isd17xx_handle_t *handle, uint8_t cmd, uint8_t *buf, uint16_t len)
2744{
2745 if (handle == NULL) /* check handle */
2746 {
2747 return 2; /* return error */
2748 }
2749 if (handle->inited != 1) /* check handle initialization */
2750 {
2751 return 3; /* return error */
2752 }
2753
2754 return a_isd17xx_spi_write(handle, cmd, buf, len); /* write data */
2755}
2756
2770uint8_t isd17xx_get_reg(isd17xx_handle_t *handle, uint8_t cmd, uint8_t *buf, uint16_t len)
2771{
2772 if (handle == NULL) /* check handle */
2773 {
2774 return 2; /* return error */
2775 }
2776 if (handle->inited != 1) /* check handle initialization */
2777 {
2778 return 3; /* return error */
2779 }
2780
2781 return a_isd17xx_spi_read(handle, cmd, buf, len); /* read data */
2782}
2783
2793{
2794 if (info == NULL) /* check handle */
2795 {
2796 return 2; /* return error */
2797 }
2798
2799 memset(info, 0, sizeof(isd17xx_info_t)); /* initialize isd17xx info structure */
2800 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2801 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2802 strncpy(info->interface, "SPI", 8); /* copy interface name */
2803 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2804 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2805 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2806 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2807 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2808 info->driver_version = DRIVER_VERSION; /* set driver version */
2809
2810 return 0; /* success return 0 */
2811}
#define ISD17XX_COMMAND_RD_REC_PTR
#define ISD17XX_COMMAND_G_ERASE
#define ISD17XX_COMMAND_RD_STATUS
#define ISD17XX_COMMAND_ERASE
#define ISD17XX_COMMAND_PU
chip command definition
#define ISD17XX_COMMAND_RESET
#define ISD17XX_COMMAND_WR_NVCFG
#define MAX_CURRENT
#define ISD17XX_COMMAND_RD_PLAY_PTR
#define ISD17XX_COMMAND_SET_ERASE
#define ISD17XX_COMMAND_SET_PLAY
#define SUPPLY_VOLTAGE_MAX
#define ISD17XX_COMMAND_LD_NVCFG
#define ISD17XX_COMMAND_CHK_MEM
#define ISD17XX_COMMAND_FWD
#define ISD17XX_COMMAND_DEVID
#define ISD17XX_COMMAND_CLR_INT
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define ISD17XX_COMMAND_PLAY
#define ISD17XX_COMMAND_EXTCLK
#define ISD17XX_COMMAND_PD
#define ISD17XX_COMMAND_WR_APC1
#define CHIP_NAME
chip information definition
#define ISD17XX_COMMAND_STOP
#define DRIVER_VERSION
#define ISD17XX_COMMAND_REC
#define ISD17XX_COMMAND_SET_REC
#define ISD17XX_COMMAND_RD_APC
#define ISD17XX_COMMAND_WR_APC2
driver isd17xx header file
uint8_t isd17xx_global_erase(isd17xx_handle_t *handle)
global erase
uint8_t isd17xx_reset(isd17xx_handle_t *handle)
reset
uint8_t isd17xx_set_record(isd17xx_handle_t *handle, uint16_t start_addr, uint16_t end_addr)
set the record point
uint8_t isd17xx_info(isd17xx_info_t *info)
get chip's information
isd17xx_bool_t
isd17xx bool enumeration definition
uint8_t isd17xx_toggle_extern_clock(isd17xx_handle_t *handle)
toggle the enable and disable of the external clock
uint8_t isd17xx_set_mix_input(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable the mix input
uint8_t isd17xx_set_spi_ft(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable spi ft
uint8_t isd17xx_power_up(isd17xx_handle_t *handle)
power up
uint8_t isd17xx_read_play_point(isd17xx_handle_t *handle, uint16_t *point)
read the play point
uint8_t isd17xx_irq_handler(isd17xx_handle_t *handle)
irq handler
uint8_t isd17xx_get_sound_effect_editing(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the sound effect editing status
uint8_t isd17xx_set_volume(isd17xx_handle_t *handle, uint8_t vol)
set the volume
uint8_t isd17xx_get_volume(isd17xx_handle_t *handle, uint8_t *vol)
get the volume
uint8_t isd17xx_set_type(isd17xx_handle_t *handle, isd17xx_type_t type)
set the chip type
uint8_t isd17xx_get_mix_input(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the mix input status
uint8_t isd17xx_get_power_up_analog_output(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the power up analog output status
uint8_t isd17xx_get_spi_ft(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the spi ft status
uint8_t isd17xx_set_sound_effect_editing(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable sound effect editing
uint8_t isd17xx_next(isd17xx_handle_t *handle)
next
uint8_t isd17xx_get_status(isd17xx_handle_t *handle, uint16_t *status1, uint8_t *status2)
get the status
uint8_t isd17xx_get_v_alert(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the v alert status
uint8_t isd17xx_get_type(isd17xx_handle_t *handle, isd17xx_type_t *type)
get the chip type
uint8_t isd17xx_set_erase(isd17xx_handle_t *handle, uint16_t start_addr, uint16_t end_addr)
set the erase point
uint8_t isd17xx_hardware_reset(isd17xx_handle_t *handle)
hardware reset
uint8_t isd17xx_set_play(isd17xx_handle_t *handle, uint16_t start_addr, uint16_t end_addr)
set the play point
uint8_t isd17xx_clear_interrupt(isd17xx_handle_t *handle)
clear interrupt
uint8_t isd17xx_stop(isd17xx_handle_t *handle)
stop
uint8_t isd17xx_record(isd17xx_handle_t *handle)
record
uint8_t isd17xx_power_down(isd17xx_handle_t *handle)
power down
isd17xx_vol_control_t
isd17xx vol control enumeration definition
uint8_t isd17xx_write_to_nv(isd17xx_handle_t *handle)
write config to non volatile memory
uint8_t isd17xx_set_power_up_analog_output(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable power up analog output
uint8_t isd17xx_get_analog_output(isd17xx_handle_t *handle, isd17xx_analog_output_t *output)
get the analog output type
uint8_t isd17xx_get_device_id(isd17xx_handle_t *handle, uint8_t *id)
get the device id
uint8_t isd17xx_init(isd17xx_handle_t *handle)
initialize the chip
uint8_t isd17xx_read_record_point(isd17xx_handle_t *handle, uint16_t *point)
read the record point
uint8_t isd17xx_check_memory(isd17xx_handle_t *handle)
check memory
uint8_t isd17xx_set_analog_output(isd17xx_handle_t *handle, isd17xx_analog_output_t output)
set the analog output type
struct isd17xx_info_s isd17xx_info_t
isd17xx information structure definition
uint8_t isd17xx_set_v_alert(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable v alert
uint8_t isd17xx_erase(isd17xx_handle_t *handle)
erase
uint8_t isd17xx_set_monitor_input(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable the monitor input
uint8_t isd17xx_get_pwm_speaker(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the pwm speaker status
uint8_t isd17xx_load_from_nv(isd17xx_handle_t *handle)
load config from non volatile memory
uint8_t isd17xx_get_eom(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the eom status
uint8_t isd17xx_set_pwm_speaker(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable pwm speaker
uint8_t isd17xx_get_volume_control(isd17xx_handle_t *handle, isd17xx_vol_control_t *control)
get the volume control type
struct isd17xx_handle_s isd17xx_handle_t
isd17xx handle structure definition
uint8_t isd17xx_set_eom(isd17xx_handle_t *handle, isd17xx_bool_t enable)
enable or disable eom stop playing
uint8_t isd17xx_set_volume_control(isd17xx_handle_t *handle, isd17xx_vol_control_t control)
set the volume control type
isd17xx_type_t
isd17xx type enumeration definition
uint8_t isd17xx_get_monitor_input(isd17xx_handle_t *handle, isd17xx_bool_t *enable)
get the monitor input status
isd17xx_analog_output_t
isd17xx analog output enumeration definition
uint8_t isd17xx_deinit(isd17xx_handle_t *handle)
close the chip
uint8_t isd17xx_play(isd17xx_handle_t *handle)
play
@ ISD17XX_STATUS2_RDY
@ ISD17XX_VOL_CONTROL_REG
@ ISD17XX_VOL_CONTROL_BUTTON
@ ISD17XX_STATUS1_INT
@ ISD17XX_STATUS1_CMD_ERR
@ ISD17XX_STATUS1_EOM
@ ISD17240
@ ISD1730
@ ISD17210
@ ISD1790
@ ISD1760
@ ISD1750
@ ISD17150
@ ISD17120
@ ISD17180
@ ISD1740
uint8_t isd17xx_get_reg(isd17xx_handle_t *handle, uint8_t cmd, uint8_t *buf, uint16_t len)
get the chip register
uint8_t isd17xx_set_reg(isd17xx_handle_t *handle, uint8_t cmd, uint8_t *buf, uint16_t len)
set the chip register
uint8_t(* gpio_reset_deinit)(void)
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
void(* receive_callback)(uint16_t type)
uint8_t(* spi_transmit)(uint8_t *tx, uint8_t *rx, uint16_t len)
uint8_t(* spi_deinit)(void)
uint8_t(* gpio_reset_write)(uint8_t level)
uint8_t(* gpio_reset_init)(void)
uint32_t driver_version
char manufacturer_name[32]