Select one of the symbols to view example projects that use it.
 
Outline
#include "wm8994.h"
wm8994_drv
outputEnabled
inputEnabled
ColdStartup
wm8994_Init(uint16_t, uint16_t, uint8_t, uint32_t)
wm8994_DeInit()
wm8994_ReadID(uint16_t)
wm8994_Play(uint16_t, uint16_t *, uint16_t)
wm8994_Pause(uint16_t)
wm8994_Resume(uint16_t)
wm8994_Stop(uint16_t, uint32_t)
wm8994_SetVolume(uint16_t, uint8_t)
wm8994_SetMute(uint16_t, uint32_t)
wm8994_SetOutputMode(uint16_t, uint8_t)
wm8994_SetFrequency(uint16_t, uint32_t)
wm8994_Reset(uint16_t)
CODEC_IO_Write(uint8_t, uint16_t, uint16_t)
Files
loading...
CodeScopeSTM32 Libraries and Sampleswm8994wm8994.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file wm8994.c * @author MCD Application Team * @brief This file provides the WM8994 Audio Codec driver. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "wm8994.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup Components * @{ *//* ... */ /** @addtogroup wm8994 * @brief This file provides a set of functions needed to drive the * WM8994 audio codec. * @{ *//* ... */ /** @defgroup WM8994_Private_Types * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup WM8994_Private_Defines * @{ *//* ... */ /* Uncomment this line to enable verifying data sent to codec after each write operation (for debug purpose) *//* ... */ #if !defined (VERIFY_WRITTENDATA) /*#define VERIFY_WRITTENDATA*/ #endif /* VERIFY_WRITTENDATA */ /** * @} *//* ... */ /** @defgroup WM8994_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup WM8994_Private_Variables * @{ *//* ... */ /* Audio codec driver structure initialization */ AUDIO_DrvTypeDef wm8994_drv = { wm8994_Init, wm8994_DeInit, wm8994_ReadID, wm8994_Play, wm8994_Pause, wm8994_Resume, wm8994_Stop, wm8994_SetFrequency, wm8994_SetVolume, wm8994_SetMute, wm8994_SetOutputMode, wm8994_Reset ...}; static uint32_t outputEnabled = 0; static uint32_t inputEnabled = 0; static uint8_t ColdStartup = 1; /** * @} *//* ... */ /** @defgroup WM8994_Function_Prototypes * @{ *//* ... */ static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value); /** * @} *//* ... */ /** @defgroup WM8994_Private_Functions * @{ *//* ... */ /** * @brief Initializes the audio codec and the control interface. * @param DeviceAddr: Device address on communication Bus. * @param OutputInputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE, * OUTPUT_DEVICE_BOTH, OUTPUT_DEVICE_AUTO, INPUT_DEVICE_DIGITAL_MICROPHONE_1, * INPUT_DEVICE_DIGITAL_MICROPHONE_2, INPUT_DEVICE_DIGITAL_MIC1_MIC2, * INPUT_DEVICE_INPUT_LINE_1 or INPUT_DEVICE_INPUT_LINE_2. * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max)) * @param AudioFreq: Audio Frequency * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_Init(uint16_t DeviceAddr, uint16_t OutputInputDevice, uint8_t Volume, uint32_t AudioFreq) { uint32_t counter = 0; uint16_t output_device = OutputInputDevice & 0xFF; uint16_t input_device = OutputInputDevice & 0xFF00; uint16_t power_mgnt_reg_1 = 0; uint16_t tmp; /* Initialize the Control interface of the Audio Codec */ AUDIO_IO_Init(); /* wm8994 Errata Work-Arounds */ tmp = 0x0003; counter += CODEC_IO_Write(DeviceAddr, 0x102, tmp); tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, 0x817, tmp); counter += CODEC_IO_Write(DeviceAddr, 0x102, tmp); /* Enable VMID soft start (fast), Start-up Bias Current Enabled */ tmp = 0x006C; counter += CODEC_IO_Write(DeviceAddr, WM8994_ANTIPOP2, tmp); /* Enable bias generator, Enable VMID */ if (input_device > 0) { tmp = 0x0013; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_1, tmp); }if (input_device > 0) { ... } else { tmp = 0x0003; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_1, tmp); }else { ... } /* Add Delay */ AUDIO_IO_Delay(50); /* Path Configurations for output */ if (output_device > 0) { outputEnabled = 1; switch (output_device) { case OUTPUT_DEVICE_SPEAKER: /* Enable DAC1 (Left), Enable DAC1 (Right), Disable DAC2 (Left), Disable DAC2 (Right)*//* ... */ tmp = 0x0C0C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break; case OUTPUT_DEVICE_SPEAKER: case OUTPUT_DEVICE_HEADPHONE: /* Disable DAC1 (Left), Disable DAC1 (Right), Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break; case OUTPUT_DEVICE_HEADPHONE: case OUTPUT_DEVICE_BOTH: if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { /* Enable DAC1 (Left), Enable DAC1 (Right), also Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303 | 0x0C0C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path Enable the AIF1 Timeslot 1 (Left) to DAC 1 (Left) mixer path *//* ... */ tmp = 0x0003; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path Enable the AIF1 Timeslot 1 (Right) to DAC 1 (Right) mixer path *//* ... */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 2 (Left) mixer path Enable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path *//* ... */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 2 (Right) mixer path Enable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path *//* ... */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); }if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { ... } else { /* Enable DAC1 (Left), Enable DAC1 (Right), also Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303 | 0x0C0C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Enable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Enable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); }else { ... } break; case OUTPUT_DEVICE_BOTH: case OUTPUT_DEVICE_AUTO : default: /* Disable DAC1 (Left), Disable DAC1 (Right), Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break;default }switch (output_device) { ... } }if (output_device > 0) { ... } else { outputEnabled = 0; }else { ... } /* Path Configurations for input */ if (input_device > 0) { inputEnabled = 1; switch (input_device) { case INPUT_DEVICE_DIGITAL_MICROPHONE_2 : /* Enable AIF1ADC2 (Left), Enable AIF1ADC2 (Right) * Enable DMICDAT2 (Left), Enable DMICDAT2 (Right) * Enable Left ADC, Enable Right ADC *//* ... */ tmp = 0x0C30; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_4, tmp); /* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC2 Left/Right Timeslot 1 */ tmp = 0x00DB; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DRC2, tmp); /* Disable IN1L, IN1R, IN2L, IN2R, Enable Thermal sensor & shutdown */ tmp = 0x6000; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_2, tmp); /* Enable the DMIC2(Left) to AIF1 Timeslot 1 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_LMR, tmp); /* Enable the DMIC2(Right) to AIF1 Timeslot 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_RMR, tmp); /* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC2 signal detect */ tmp = 0x000E; counter += CODEC_IO_Write(DeviceAddr, WM8994_GPIO1, tmp); break; case INPUT_DEVICE_DIGITAL_MICROPHONE_2 : case INPUT_DEVICE_INPUT_LINE_1 : /* IN1LN_TO_IN1L, IN1LP_TO_VMID, IN1RN_TO_IN1R, IN1RP_TO_VMID */ tmp = 0x0011; counter += CODEC_IO_Write(DeviceAddr, WM8994_INPUT_MIXER_2, tmp); /* Disable mute on IN1L_TO_MIXINL and +30dB on IN1L PGA output */ tmp = 0x0035; counter += CODEC_IO_Write(DeviceAddr, WM8994_INPUT_MIXER_3, tmp); /* Disable mute on IN1R_TO_MIXINL, Gain = +30dB */ counter += CODEC_IO_Write(DeviceAddr, WM8994_INPUT_MIXER_4, tmp); /* Enable AIF1ADC1 (Left), Enable AIF1ADC1 (Right) * Enable Left ADC, Enable Right ADC *//* ... */ tmp = 0x0303; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_4, tmp); /* Enable AIF1 DRC1 Signal Detect & DRC in AIF1ADC1 Left/Right Timeslot 0 */ tmp = 0x00DB; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DRC1, tmp); /* Enable IN1L and IN1R, Disable IN2L and IN2R, Enable Thermal sensor & shutdown */ tmp = 0x6350; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_2, tmp); /* Enable the ADCL(Left) to AIF1 Timeslot 0 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_LMR, tmp); /* Enable the ADCR(Right) to AIF1 Timeslot 0 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_RMR, tmp); /* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC1 signal detect */ tmp = 0x000D; counter += CODEC_IO_Write(DeviceAddr, WM8994_GPIO1, tmp); break; case INPUT_DEVICE_INPUT_LINE_1 : case INPUT_DEVICE_DIGITAL_MICROPHONE_1 : /* Enable AIF1ADC1 (Left), Enable AIF1ADC1 (Right) * Enable DMICDAT1 (Left), Enable DMICDAT1 (Right) * Enable Left ADC, Enable Right ADC *//* ... */ tmp = 0x030C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_4, tmp); /* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC1 Left/Right Timeslot 0 */ tmp = 0x00DB; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DRC1, tmp); /* Disable IN1L, IN1R, IN2L, IN2R, Enable Thermal sensor & shutdown */ tmp = 0x6350; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_2, tmp); /* Enable the DMIC2(Left) to AIF1 Timeslot 0 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_LMR, tmp); /* Enable the DMIC2(Right) to AIF1 Timeslot 0 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_RMR, tmp); /* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC1 signal detect */ tmp = 0x000D; counter += CODEC_IO_Write(DeviceAddr, WM8994_GPIO1, tmp); break; case INPUT_DEVICE_DIGITAL_MICROPHONE_1 : case INPUT_DEVICE_DIGITAL_MIC1_MIC2 : /* Enable AIF1ADC1 (Left), Enable AIF1ADC1 (Right) * Enable DMICDAT1 (Left), Enable DMICDAT1 (Right) * Enable Left ADC, Enable Right ADC *//* ... */ tmp = 0x0F3C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_4, tmp); /* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC2 Left/Right Timeslot 1 */ tmp = 0x00DB; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DRC2, tmp); /* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC1 Left/Right Timeslot 0 */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DRC1, tmp); /* Disable IN1L, IN1R, Enable IN2L, IN2R, Thermal sensor & shutdown */ tmp = 0x63A0; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_2, tmp); /* Enable the DMIC2(Left) to AIF1 Timeslot 0 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_LMR, tmp); /* Enable the DMIC2(Right) to AIF1 Timeslot 0 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_RMR, tmp); /* Enable the DMIC2(Left) to AIF1 Timeslot 1 (Left) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_LMR, tmp); /* Enable the DMIC2(Right) to AIF1 Timeslot 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_RMR, tmp); /* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC1 signal detect */ tmp = 0x000D; counter += CODEC_IO_Write(DeviceAddr, WM8994_GPIO1, tmp); break; case INPUT_DEVICE_DIGITAL_MIC1_MIC2 : case INPUT_DEVICE_INPUT_LINE_2 : default: /* Actually, no other input devices supported */ counter++; break;default }switch (input_device) { ... } }if (input_device > 0) { ... } else { inputEnabled = 0; }else { ... } /* Clock Configurations */ switch (AudioFreq) { case AUDIO_FREQUENCY_8K: /* AIF1 Sample Rate = 8 (KHz), ratio=256 */ tmp = 0x0003; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_8K: case AUDIO_FREQUENCY_16K: /* AIF1 Sample Rate = 16 (KHz), ratio=256 */ tmp = 0x0033; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_16K: case AUDIO_FREQUENCY_32K: /* AIF1 Sample Rate = 32 (KHz), ratio=256 */ tmp = 0x0063; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_32K: case AUDIO_FREQUENCY_48K: /* AIF1 Sample Rate = 48 (KHz), ratio=256 */ tmp = 0x0083; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_48K: case AUDIO_FREQUENCY_96K: /* AIF1 Sample Rate = 96 (KHz), ratio=256 */ tmp = 0x00A3; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_96K: case AUDIO_FREQUENCY_11K: /* AIF1 Sample Rate = 11.025 (KHz), ratio=256 */ tmp = 0x0013; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_11K: case AUDIO_FREQUENCY_22K: /* AIF1 Sample Rate = 22.050 (KHz), ratio=256 */ tmp = 0x0043; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_22K: case AUDIO_FREQUENCY_44K: /* AIF1 Sample Rate = 44.1 (KHz), ratio=256 */ tmp = 0x0073; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_44K: default: /* AIF1 Sample Rate = 48 (KHz), ratio=256 */ tmp = 0x0083; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; default }switch (AudioFreq) { ... } if(input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { /* AIF1 Word Length = 16-bits, AIF1 Format = DSP mode */ tmp = 0x4018; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_CONTROL1, tmp); }if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { ... } else { /* AIF1 Word Length = 16-bits, AIF1 Format = I2S (Default Register Value) */ tmp = 0x4010; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_CONTROL1, tmp); }else { ... } /* slave mode */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_MASTER_SLAVE, tmp); /* Enable the DSP processing clock for AIF1, Enable the core clock */ tmp = 0x000A; counter += CODEC_IO_Write(DeviceAddr, WM8994_CLOCKING1, tmp); /* Enable AIF1 Clock, AIF1 Clock Source = MCLK1 pin */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_CLOCKING1, tmp); if (output_device > 0) /* Audio output selected */ { if (output_device == OUTPUT_DEVICE_HEADPHONE) { /* Select DAC1 (Left) to Left Headphone Output PGA (HPOUT1LVOL) path */ tmp = 0x0100; counter += CODEC_IO_Write(DeviceAddr, WM8994_OUTPUT_MIXER_1, tmp); /* Select DAC1 (Right) to Right Headphone Output PGA (HPOUT1RVOL) path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_OUTPUT_MIXER_2, tmp); /* Startup sequence for Headphone */ if(ColdStartup) { tmp = 0x8100; counter += CODEC_IO_Write(DeviceAddr,WM8994_WRITE_SEQ_CTRL1, tmp); ColdStartup=0; /* Add Delay */ AUDIO_IO_Delay(300); }if (ColdStartup) { ... } else /* Headphone Warm Start-Up */ { tmp = 0x8108; counter += CODEC_IO_Write(DeviceAddr,WM8994_WRITE_SEQ_CTRL1, tmp); /* Add Delay */ AUDIO_IO_Delay(50); }else { ... } /* Soft un-Mute the AIF1 Timeslot 0 DAC1 path L&R */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_FILTER1, tmp); }if (output_device == OUTPUT_DEVICE_HEADPHONE) { ... } /* Analog Output Configuration */ /* Enable SPKRVOL PGA, Enable SPKMIXR, Enable SPKLVOL PGA, Enable SPKMIXL */ tmp = 0x0300; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_3, tmp); /* Left Speaker Mixer Volume = 0dB */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_SPKMIXL_ATT, tmp); /* Speaker output mode = Class D, Right Speaker Mixer Volume = 0dB ((0x23, 0x0100) = class AB)*/ counter += CODEC_IO_Write(DeviceAddr, WM8994_SPKMIXR_ATT, tmp); /* Unmute DAC2 (Left) to Left Speaker Mixer (SPKMIXL) path, Unmute DAC2 (Right) to Right Speaker Mixer (SPKMIXR) path *//* ... */ tmp = 0x0300; counter += CODEC_IO_Write(DeviceAddr, WM8994_SPEAKER_MIXER, tmp); /* Enable bias generator, Enable VMID, Enable SPKOUTL, Enable SPKOUTR */ tmp = 0x3003; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_1, tmp); /* Headphone/Speaker Enable */ if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { /* Enable Class W, Class W Envelope Tracking = AIF1 Timeslots 0 and 1 */ tmp = 0x0205; counter += CODEC_IO_Write(DeviceAddr, WM8994_CLASS_W, tmp); }if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { ... } else { /* Enable Class W, Class W Envelope Tracking = AIF1 Timeslot 0 */ tmp = 0x0005; counter += CODEC_IO_Write(DeviceAddr, WM8994_CLASS_W, tmp); }else { ... } /* Enable bias generator, Enable VMID, Enable HPOUT1 (Left) and Enable HPOUT1 (Right) input stages */ /* idem for Speaker */ power_mgnt_reg_1 |= 0x0303 | 0x3003; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_1, power_mgnt_reg_1); /* Enable HPOUT1 (Left) and HPOUT1 (Right) intermediate stages */ tmp = 0x0022; counter += CODEC_IO_Write(DeviceAddr, WM8994_ANALOG_HP, tmp); /* Enable Charge Pump */ tmp = 0x9F25; counter += CODEC_IO_Write(DeviceAddr, WM8994_CHARGE_PUMP1, tmp); /* Add Delay */ AUDIO_IO_Delay(15); /* Select DAC1 (Left) to Left Headphone Output PGA (HPOUT1LVOL) path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_OUTPUT_MIXER_1, tmp); /* Select DAC1 (Right) to Right Headphone Output PGA (HPOUT1RVOL) path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_OUTPUT_MIXER_2, tmp); /* Enable Left Output Mixer (MIXOUTL), Enable Right Output Mixer (MIXOUTR) */ /* idem for SPKOUTL and SPKOUTR */ tmp = 0x0030 | 0x0300; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_3, tmp); /* Enable DC Servo and trigger start-up mode on left and right channels */ tmp = 0x0033; counter += CODEC_IO_Write(DeviceAddr, WM8994_DC_SERVO1, tmp); /* Add Delay */ AUDIO_IO_Delay(257); /* Enable HPOUT1 (Left) and HPOUT1 (Right) intermediate and output stages. Remove clamps */ tmp = 0x00EE; counter += CODEC_IO_Write(DeviceAddr, WM8994_ANALOG_HP, tmp); /* Unmutes */ /* Unmute DAC 1 (Left) */ tmp = 0x00C0; counter += CODEC_IO_Write(DeviceAddr, WM8994_DAC1_LEFT_VOL, tmp); /* Unmute DAC 1 (Right) */ counter += CODEC_IO_Write(DeviceAddr, WM8994_DAC1_RIGHT_VOL, tmp); /* Unmute the AIF1 Timeslot 0 DAC path */ tmp = 0x0010; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_FILTER1, tmp); /* Unmute DAC 2 (Left) */ tmp = 0x00C0; counter += CODEC_IO_Write(DeviceAddr, WM8994_DAC2_LEFT_VOL, tmp); /* Unmute DAC 2 (Right) */ counter += CODEC_IO_Write(DeviceAddr, WM8994_DAC2_RIGHT_VOL, tmp); /* Unmute the AIF1 Timeslot 1 DAC2 path */ tmp = 0x0010; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_FILTER1, tmp); /* Volume Control */ wm8994_SetVolume(DeviceAddr, Volume); ...} if (input_device > 0) /* Audio input selected */ { if ((input_device == INPUT_DEVICE_DIGITAL_MICROPHONE_1) || (input_device == INPUT_DEVICE_DIGITAL_MICROPHONE_2)) { /* Enable Microphone bias 1 generator, Enable VMID */ power_mgnt_reg_1 |= 0x0013; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_1, power_mgnt_reg_1); /* ADC oversample enable */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_OVERSAMPLING, tmp); /* AIF ADC2 HPF enable, HPF cut = voice mode 1 fc=127Hz at fs=8kHz */ tmp = 0x3800; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_FILTERS, tmp); }if ((input_device == INPUT_DEVICE_DIGITAL_MICROPHONE_1) || (input_device == INPUT_DEVICE_DIGITAL_MICROPHONE_2)) { ... } else if(input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { /* Enable Microphone bias 1 generator, Enable VMID */ power_mgnt_reg_1 |= 0x0013; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_1, power_mgnt_reg_1); /* ADC oversample enable */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_OVERSAMPLING, tmp); /* AIF ADC1 HPF enable, HPF cut = voice mode 1 fc=127Hz at fs=8kHz */ tmp = 0x1800; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_FILTERS, tmp); /* AIF ADC2 HPF enable, HPF cut = voice mode 1 fc=127Hz at fs=8kHz */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_FILTERS, tmp); }else if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2) { ... } else if ((input_device == INPUT_DEVICE_INPUT_LINE_1) || (input_device == INPUT_DEVICE_INPUT_LINE_2)) { /* Disable mute on IN1L, IN1L Volume = +0dB */ tmp = 0x000B; counter += CODEC_IO_Write(DeviceAddr, WM8994_LEFT_LINE_IN12_VOL, tmp); /* Disable mute on IN1R, IN1R Volume = +0dB */ counter += CODEC_IO_Write(DeviceAddr, WM8994_RIGHT_LINE_IN12_VOL, tmp); /* AIF ADC1 HPF enable, HPF cut = hifi mode fc=4Hz at fs=48kHz */ tmp = 0x1800; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_FILTERS, tmp); }else if ((input_device == INPUT_DEVICE_INPUT_LINE_1) || (input_device == INPUT_DEVICE_INPUT_LINE_2)) { ... } /* Volume Control */ wm8994_SetVolume(DeviceAddr, Volume); ...} /* Return communication control value */ return counter; }{ ... } /** * @brief Deinitializes the audio codec. * @param None * @retval None *//* ... */ void wm8994_DeInit(void) { /* Deinitialize Audio Codec interface */ AUDIO_IO_DeInit(); }{ ... } /** * @brief Get the WM8994 ID. * @param DeviceAddr: Device address on communication Bus. * @retval The WM8994 ID *//* ... */ uint32_t wm8994_ReadID(uint16_t DeviceAddr) { /* Initialize the Control interface of the Audio Codec */ AUDIO_IO_Init(); return ((uint32_t)AUDIO_IO_Read(DeviceAddr, WM8994_CHIPID_ADDR)); }{ ... } /** * @brief Start the audio Codec play feature. * @note For this codec no Play options are required. * @param DeviceAddr: Device address on communication Bus. * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size) { uint32_t counter = 0; /* Resumes the audio file playing */ /* Unmute the output first */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF); return counter; }{ ... } /** * @brief Pauses playing on the audio codec. * @param DeviceAddr: Device address on communication Bus. * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_Pause(uint16_t DeviceAddr) { uint32_t counter = 0; uint16_t tmp; /* Pause the audio file playing */ /* Mute the output first */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON); /* Put the Codec in Power save mode */ tmp = 0x01; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_2, tmp); return counter; }{ ... } /** * @brief Resumes playing on the audio codec. * @param DeviceAddr: Device address on communication Bus. * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_Resume(uint16_t DeviceAddr) { uint32_t counter = 0; /* Resumes the audio file playing */ /* Unmute the output first */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF); return counter; }{ ... } /** * @brief Stops audio Codec playing. It powers down the codec. * @param DeviceAddr: Device address on communication Bus. * @param CodecPdwnMode: selects the power down mode. * - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this * mode the codec keeps the previous initialization * (no need to re-Initialize the codec registers). * - CODEC_PDWN_HW: Physically power down the codec. When resuming from this * mode, the codec is set to default configuration * (user should re-Initialize the codec in order to * play again the audio stream). * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode) { uint32_t counter = 0; uint16_t tmp; if (outputEnabled != 0) { /* Mute the output first */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON); if (CodecPdwnMode == CODEC_PDWN_SW) { /* Only output mute required*/ }if (CodecPdwnMode == CODEC_PDWN_SW) { ... } else /* CODEC_PDWN_HW */ { /* Mute the AIF1 Timeslot 0 DAC1 path */ tmp = 0x0200; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_FILTER1, tmp); /* Mute the AIF1 Timeslot 1 DAC2 path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_FILTER1, tmp); /* Disable DAC1L_TO_HPOUT1L */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_OUTPUT_MIXER_1, tmp); /* Disable DAC1R_TO_HPOUT1R */ counter += CODEC_IO_Write(DeviceAddr, WM8994_OUTPUT_MIXER_2, tmp); /* Disable DAC1 and DAC2 */ counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Reset Codec by writing in 0x0000 address register */ counter += CODEC_IO_Write(DeviceAddr, WM8994_SW_RESET, tmp); outputEnabled = 0; }else { ... } }if (outputEnabled != 0) { ... } return counter; }{ ... } /** * @brief Sets higher or lower the codec volume level. * @param DeviceAddr: Device address on communication Bus. * @param Volume: a byte value from 0 to 255 (refer to codec registers * description for more details). * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_SetVolume(uint16_t DeviceAddr, uint8_t Volume) { uint32_t counter = 0; uint8_t convertedvol = VOLUME_CONVERT(Volume); uint16_t tmp; /* Output volume */ if (outputEnabled != 0) { if(convertedvol > 0x3E) { /* Unmute audio codec */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF); /* Left Headphone Volume */ tmp = 0x3F | 0x140; counter += CODEC_IO_Write(DeviceAddr, WM8994_LEFT_OUTPUT_VOL, tmp); /* Right Headphone Volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_RIGHT_OUTPUT_VOL, tmp); /* Left Speaker Volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_SPK_LEFT_VOL, tmp); /* Right Speaker Volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_SPK_RIGHT_VOL, tmp); }if (convertedvol > 0x3E) { ... } else if (Volume == 0) { /* Mute audio codec */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON); }else if (Volume == 0) { ... } else { /* Unmute audio codec */ counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF); /* Left Headphone Volume */ tmp = convertedvol | 0x140; counter += CODEC_IO_Write(DeviceAddr, WM8994_LEFT_OUTPUT_VOL, tmp); /* Right Headphone Volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_RIGHT_OUTPUT_VOL, tmp); /* Left Speaker Volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_SPK_LEFT_VOL, tmp); /* Right Speaker Volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_SPK_RIGHT_VOL, tmp); }else { ... } }if (outputEnabled != 0) { ... } /* Input volume */ if (inputEnabled != 0) { convertedvol = VOLUME_IN_CONVERT(Volume); /* Left AIF1 ADC1 volume */ tmp = convertedvol | 0x100; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_LEFT_VOL, tmp); /* Right AIF1 ADC1 volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC1_RIGHT_VOL, tmp); /* Left AIF1 ADC2 volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_LEFT_VOL, tmp); /* Right AIF1 ADC2 volume */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_ADC2_RIGHT_VOL, tmp); }if (inputEnabled != 0) { ... } return counter; }{ ... } /** * @brief Enables or disables the mute feature on the audio codec. * @param DeviceAddr: Device address on communication Bus. * @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the * mute mode. * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_SetMute(uint16_t DeviceAddr, uint32_t Cmd) { uint32_t counter = 0; uint16_t tmp; if (outputEnabled != 0) { /* Set the Mute mode */ if(Cmd == AUDIO_MUTE_ON) { /* Soft Mute the AIF1 Timeslot 0 DAC1 path L&R */ tmp = 0x0200; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_FILTER1, tmp); /* Soft Mute the AIF1 Timeslot 1 DAC2 path L&R */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_FILTER1, tmp); }if (Cmd == AUDIO_MUTE_ON) { ... } else /* AUDIO_MUTE_OFF Disable the Mute */ { /* Unmute the AIF1 Timeslot 0 DAC1 path L&R */ tmp = 0x0010; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_FILTER1, tmp); /* Unmute the AIF1 Timeslot 1 DAC2 path L&R */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_FILTER1, tmp); }else { ... } }if (outputEnabled != 0) { ... } return counter; }{ ... } /** * @brief Switch dynamically (while audio file is played) the output target * (speaker or headphone). * @param DeviceAddr: Device address on communication Bus. * @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER, * OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_SetOutputMode(uint16_t DeviceAddr, uint8_t Output) { uint32_t counter = 0; uint16_t tmp; switch (Output) { case OUTPUT_DEVICE_SPEAKER: /* Enable DAC1 (Left), Enable DAC1 (Right), Disable DAC2 (Left), Disable DAC2 (Right)*//* ... */ tmp = 0x0C0C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break; case OUTPUT_DEVICE_SPEAKER: case OUTPUT_DEVICE_HEADPHONE: /* Disable DAC1 (Left), Disable DAC1 (Right), Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break; case OUTPUT_DEVICE_HEADPHONE: case OUTPUT_DEVICE_BOTH: /* Enable DAC1 (Left), Enable DAC1 (Right), also Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303 | 0x0C0C; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Enable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0002; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Enable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break; case OUTPUT_DEVICE_BOTH: default: /* Disable DAC1 (Left), Disable DAC1 (Right), Enable DAC2 (Left), Enable DAC2 (Right)*//* ... */ tmp = 0x0303; counter += CODEC_IO_Write(DeviceAddr, WM8994_PWR_MANAGEMENT_5, tmp); /* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */ tmp = 0x0001; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_LMR, tmp); /* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC1_RMR, tmp); /* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */ tmp = 0x0000; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_LMR, tmp); /* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */ counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_DAC2_RMR, tmp); break; default }switch (Output) { ... } return counter; }{ ... } /** * @brief Sets new frequency. * @param DeviceAddr: Device address on communication Bus. * @param AudioFreq: Audio frequency used to play the audio stream. * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq) { uint32_t counter = 0; uint16_t tmp; /* Clock Configurations */ switch (AudioFreq) { case AUDIO_FREQUENCY_8K: /* AIF1 Sample Rate = 8 (KHz), ratio=256 */ tmp = 0x0003; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_8K: case AUDIO_FREQUENCY_16K: /* AIF1 Sample Rate = 16 (KHz), ratio=256 */ tmp = 0x0033; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_16K: case AUDIO_FREQUENCY_32K: /* AIF1 Sample Rate = 32 (KHz), ratio=256 */ tmp = 0x0063; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_32K: case AUDIO_FREQUENCY_48K: /* AIF1 Sample Rate = 48 (KHz), ratio=256 */ tmp = 0x0083; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_48K: case AUDIO_FREQUENCY_96K: /* AIF1 Sample Rate = 96 (KHz), ratio=256 */ tmp = 0x00A3; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_96K: case AUDIO_FREQUENCY_11K: /* AIF1 Sample Rate = 11.025 (KHz), ratio=256 */ tmp = 0x0013; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_11K: case AUDIO_FREQUENCY_22K: /* AIF1 Sample Rate = 22.050 (KHz), ratio=256 */ tmp = 0x0043; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_22K: case AUDIO_FREQUENCY_44K: /* AIF1 Sample Rate = 44.1 (KHz), ratio=256 */ tmp = 0x0073; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; case AUDIO_FREQUENCY_44K: default: /* AIF1 Sample Rate = 48 (KHz), ratio=256 */ tmp = 0x0083; counter += CODEC_IO_Write(DeviceAddr, WM8994_AIF1_RATE, tmp); break; default }switch (AudioFreq) { ... } return counter; }{ ... } /** * @brief Resets wm8994 registers. * @param DeviceAddr: Device address on communication Bus. * @retval 0 if correct communication, else wrong communication *//* ... */ uint32_t wm8994_Reset(uint16_t DeviceAddr) { uint32_t counter = 0; uint16_t tmp; /* Reset Codec by writing in 0x0000 address register */ tmp = 0x0000; counter = CODEC_IO_Write(DeviceAddr, WM8994_SW_RESET, tmp); outputEnabled = 0; inputEnabled=0; return counter; }{ ... } /** * @brief Writes/Read a single data. * @param Addr: I2C address * @param Reg: Reg address * @param Value: Data to be written * @retval None *//* ... */ static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value) { uint32_t result = 0; AUDIO_IO_Write(Addr, Reg, Value); #ifdef VERIFY_WRITTENDATA /* Verify that the data has been correctly written */ result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1;/* ... */ #endif /* VERIFY_WRITTENDATA */ return result; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */