68 #if !defined (VERIFY_WRITTENDATA) 107 static uint32_t outputEnabled = 0;
108 static uint32_t inputEnabled = 0;
116 static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
136 uint32_t
wm8994_Init(uint16_t DeviceAddr, uint16_t OutputInputDevice, uint8_t Volume, uint32_t AudioFreq)
138 uint32_t counter = 0;
139 uint16_t output_device = OutputInputDevice & 0xFF;
140 uint16_t input_device = OutputInputDevice & 0xFF00;
141 uint16_t power_mgnt_reg_1 = 0;
146 counter += CODEC_IO_Write(DeviceAddr, 0x102, 0x0003);
147 counter += CODEC_IO_Write(DeviceAddr, 0x817, 0x0000);
148 counter += CODEC_IO_Write(DeviceAddr, 0x102, 0x0000);
151 counter += CODEC_IO_Write(DeviceAddr, 0x39, 0x006C);
154 if (input_device > 0)
156 counter += CODEC_IO_Write(DeviceAddr, 0x01, 0x0013);
160 counter += CODEC_IO_Write(DeviceAddr, 0x01, 0x0003);
167 if (output_device > 0)
170 switch (output_device)
175 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0C0C);
178 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0000);
181 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0000);
184 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
187 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
193 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
196 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
199 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
202 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
205 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
213 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303 | 0x0C0C);
217 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0003);
221 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0003);
225 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0003);
229 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0003);
235 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303 | 0x0C0C);
238 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
241 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
244 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
247 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
255 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
258 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
261 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
264 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
267 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
277 if (input_device > 0)
280 switch (input_device)
286 counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0C30);
289 counter += CODEC_IO_Write(DeviceAddr, 0x450, 0x00DB);
292 counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x6000);
295 counter += CODEC_IO_Write(DeviceAddr, 0x608, 0x0002);
298 counter += CODEC_IO_Write(DeviceAddr, 0x609, 0x0002);
301 counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000E);
306 counter += CODEC_IO_Write(DeviceAddr, 0x28, 0x0011);
309 counter += CODEC_IO_Write(DeviceAddr, 0x29, 0x0035);
312 counter += CODEC_IO_Write(DeviceAddr, 0x2A, 0x0035);
316 counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0303);
319 counter += CODEC_IO_Write(DeviceAddr, 0x440, 0x00DB);
322 counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x6350);
325 counter += CODEC_IO_Write(DeviceAddr, 0x606, 0x0002);
328 counter += CODEC_IO_Write(DeviceAddr, 0x607, 0x0002);
331 counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000D);
338 counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x030C);
341 counter += CODEC_IO_Write(DeviceAddr, 0x440, 0x00DB);
344 counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x6350);
347 counter += CODEC_IO_Write(DeviceAddr, 0x606, 0x0002);
350 counter += CODEC_IO_Write(DeviceAddr, 0x607, 0x0002);
353 counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000D);
359 counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0F3C);
362 counter += CODEC_IO_Write(DeviceAddr, 0x450, 0x00DB);
365 counter += CODEC_IO_Write(DeviceAddr, 0x440, 0x00DB);
368 counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x63A0);
371 counter += CODEC_IO_Write(DeviceAddr, 0x606, 0x0002);
374 counter += CODEC_IO_Write(DeviceAddr, 0x607, 0x0002);
377 counter += CODEC_IO_Write(DeviceAddr, 0x608, 0x0002);
380 counter += CODEC_IO_Write(DeviceAddr, 0x609, 0x0002);
383 counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000D);
402 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0003);
407 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0033);
412 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0063);
417 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
422 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x00A3);
427 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0013);
432 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0043);
437 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0073);
442 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
449 counter += CODEC_IO_Write(DeviceAddr, 0x300, 0x4018);
455 counter += CODEC_IO_Write(DeviceAddr, 0x300, 0x4010);
460 counter += CODEC_IO_Write(DeviceAddr, 0x302, 0x0000);
463 counter += CODEC_IO_Write(DeviceAddr, 0x208, 0x000A);
466 counter += CODEC_IO_Write(DeviceAddr, 0x200, 0x0001);
468 if (output_device > 0)
473 counter += CODEC_IO_Write(DeviceAddr, 0x03, 0x0300);
476 counter += CODEC_IO_Write(DeviceAddr, 0x22, 0x0000);
480 counter += CODEC_IO_Write(DeviceAddr, 0x23, 0x0100);
481 counter += CODEC_IO_Write(DeviceAddr, 0x22, 0x0000);
483 counter += CODEC_IO_Write(DeviceAddr, 0x23, 0x0000);
488 counter += CODEC_IO_Write(DeviceAddr, 0x36, 0x0300);
491 counter += CODEC_IO_Write(DeviceAddr, 0x01, 0x3003);
498 counter += CODEC_IO_Write(DeviceAddr, 0x51, 0x0205);
503 counter += CODEC_IO_Write(DeviceAddr, 0x51, 0x0005);
508 power_mgnt_reg_1 |= 0x0303 | 0x3003;
509 counter += CODEC_IO_Write(DeviceAddr, 0x01, power_mgnt_reg_1);
512 counter += CODEC_IO_Write(DeviceAddr, 0x60, 0x0022);
515 counter += CODEC_IO_Write(DeviceAddr, 0x4C, 0x9F25);
521 counter += CODEC_IO_Write(DeviceAddr, 0x2D, 0x0001);
524 counter += CODEC_IO_Write(DeviceAddr, 0x2E, 0x0001);
528 counter += CODEC_IO_Write(DeviceAddr, 0x03, 0x0030 | 0x0300);
531 counter += CODEC_IO_Write(DeviceAddr, 0x54, 0x0033);
537 counter += CODEC_IO_Write(DeviceAddr, 0x60, 0x00EE);
542 counter += CODEC_IO_Write(DeviceAddr, 0x610, 0x00C0);
545 counter += CODEC_IO_Write(DeviceAddr, 0x611, 0x00C0);
548 counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0000);
551 counter += CODEC_IO_Write(DeviceAddr, 0x612, 0x00C0);
554 counter += CODEC_IO_Write(DeviceAddr, 0x613, 0x00C0);
557 counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0000);
563 if (input_device > 0)
568 power_mgnt_reg_1 |= 0x0013;
569 counter += CODEC_IO_Write(DeviceAddr, 0x01, power_mgnt_reg_1);
572 counter += CODEC_IO_Write(DeviceAddr, 0x620, 0x0002);
575 counter += CODEC_IO_Write(DeviceAddr, 0x411, 0x3800);
580 power_mgnt_reg_1 |= 0x0013;
581 counter += CODEC_IO_Write(DeviceAddr, 0x01, power_mgnt_reg_1);
584 counter += CODEC_IO_Write(DeviceAddr, 0x620, 0x0002);
587 counter += CODEC_IO_Write(DeviceAddr, 0x410, 0x1800);
590 counter += CODEC_IO_Write(DeviceAddr, 0x411, 0x1800);
596 counter += CODEC_IO_Write(DeviceAddr, 0x18, 0x0009);
599 counter += CODEC_IO_Write(DeviceAddr, 0x1A, 0x000B);
604 counter += CODEC_IO_Write(DeviceAddr, 0x29, 0x0020);
609 counter += CODEC_IO_Write(DeviceAddr, 0x2A, 0x0020);
612 counter += CODEC_IO_Write(DeviceAddr, 0x28, 0x0011);
615 counter += CODEC_IO_Write(DeviceAddr, 0x410, 0x1800);
654 uint32_t
wm8994_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size)
656 uint32_t counter = 0;
672 uint32_t counter = 0;
679 counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x01);
691 uint32_t counter = 0;
715 uint32_t counter = 0;
717 if (outputEnabled != 0)
729 counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0200);
732 counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0200);
735 counter += CODEC_IO_Write(DeviceAddr, 0x2D, 0x0000);
738 counter += CODEC_IO_Write(DeviceAddr, 0x2E, 0x0000);
741 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0000);
744 counter += CODEC_IO_Write(DeviceAddr, 0x0000, 0x0000);
761 uint32_t counter = 0;
765 if (outputEnabled != 0)
767 if(convertedvol > 0x3E)
773 counter += CODEC_IO_Write(DeviceAddr, 0x1C, 0x3F | 0x140);
776 counter += CODEC_IO_Write(DeviceAddr, 0x1D, 0x3F | 0x140);
779 counter += CODEC_IO_Write(DeviceAddr, 0x26, 0x3F | 0x140);
782 counter += CODEC_IO_Write(DeviceAddr, 0x27, 0x3F | 0x140);
784 else if (Volume == 0)
795 counter += CODEC_IO_Write(DeviceAddr, 0x1C, convertedvol | 0x140);
798 counter += CODEC_IO_Write(DeviceAddr, 0x1D, convertedvol | 0x140);
801 counter += CODEC_IO_Write(DeviceAddr, 0x26, convertedvol | 0x140);
804 counter += CODEC_IO_Write(DeviceAddr, 0x27, convertedvol | 0x140);
809 if (inputEnabled != 0)
814 counter += CODEC_IO_Write(DeviceAddr, 0x400, convertedvol | 0x100);
817 counter += CODEC_IO_Write(DeviceAddr, 0x401, convertedvol | 0x100);
820 counter += CODEC_IO_Write(DeviceAddr, 0x404, convertedvol | 0x100);
823 counter += CODEC_IO_Write(DeviceAddr, 0x405, convertedvol | 0x100);
837 uint32_t counter = 0;
839 if (outputEnabled != 0)
845 counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0200);
848 counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0200);
853 counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0000);
856 counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0000);
872 uint32_t counter = 0;
879 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0C0C);
882 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0000);
885 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0000);
888 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
891 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
897 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
900 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
903 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
906 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
909 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
915 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303 | 0x0C0C);
918 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
921 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
924 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
927 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
933 counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
936 counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
939 counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
942 counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
945 counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
959 uint32_t counter = 0;
966 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0003);
971 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0033);
976 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
981 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x00A3);
986 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0013);
991 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0043);
996 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0073);
1001 counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
1014 uint32_t counter = 0;
1017 counter = CODEC_IO_Write(DeviceAddr, 0x0000, 0x0000);
1031 static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
1033 uint32_t result = 0;
1037 #ifdef VERIFY_WRITTENDATA
#define VOLUME_CONVERT(Volume)
uint32_t wm8994_Play(uint16_t DeviceAddr, uint16_t *pBuffer, uint16_t Size)
Start the audio Codec play feature.
void wm8994_DeInit(void)
Deinitializes the audio codec.
#define OUTPUT_DEVICE_BOTH
void AUDIO_IO_Init(void)
Initializes Audio low level.
#define OUTPUT_DEVICE_AUTO
#define AUDIO_FREQUENCY_16K
#define OUTPUT_DEVICE_HEADPHONE
uint32_t wm8994_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq)
Sets new frequency.
#define INPUT_DEVICE_INPUT_LINE_2
void AUDIO_IO_DeInit(void)
DeInitializes Audio low level.
#define AUDIO_FREQUENCY_22K
#define AUDIO_FREQUENCY_48K
void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
Writes a single data.
#define AUDIO_FREQUENCY_11K
uint32_t wm8994_SetMute(uint16_t DeviceAddr, uint32_t Cmd)
Enables or disables the mute feature on the audio codec.
This file contains all the functions prototypes for the wm8994.c driver.
#define OUTPUT_DEVICE_SPEAKER
#define INPUT_DEVICE_DIGITAL_MICROPHONE_2
#define WM8994_CHIPID_ADDR
Device ID Register: Reading from this register will indicate device family ID 8994h.
AUDIO_DrvTypeDef wm8994_drv
uint32_t wm8994_Init(uint16_t DeviceAddr, uint16_t OutputInputDevice, uint8_t Volume, uint32_t AudioFreq)
Initializes the audio codec and the control interface.
#define AUDIO_FREQUENCY_44K
#define AUDIO_FREQUENCY_32K
uint32_t wm8994_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
Sets higher or lower the codec volume level.
#define INPUT_DEVICE_DIGITAL_MIC1_MIC2
uint32_t wm8994_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
Stops audio Codec playing. It powers down the codec.
uint8_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg)
Reads a single data.
uint32_t wm8994_Reset(uint16_t DeviceAddr)
Resets wm8994 registers.
#define INPUT_DEVICE_DIGITAL_MICROPHONE_1
uint32_t wm8994_SetOutputMode(uint16_t DeviceAddr, uint8_t Output)
Switch dynamically (while audio file is played) the output target (speaker or headphone).
void AUDIO_IO_Delay(uint32_t Delay)
AUDIO Codec delay.
uint32_t wm8994_Resume(uint16_t DeviceAddr)
Resumes playing on the audio codec.
#define INPUT_DEVICE_INPUT_LINE_1
#define AUDIO_FREQUENCY_8K
uint32_t wm8994_ReadID(uint16_t DeviceAddr)
Get the WM8994 ID.
#define VOLUME_IN_CONVERT(Volume)
#define AUDIO_FREQUENCY_96K
uint32_t wm8994_Pause(uint16_t DeviceAddr)
Pauses playing on the audio codec.