Fix Codec initialization (add initial reset)

This commit is contained in:
Vincent Barrilliot 2023-11-12 13:32:00 +01:00
parent cc183e6509
commit 961a42a1d1
2 changed files with 27 additions and 20 deletions

File diff suppressed because one or more lines are too long

View file

@ -14,20 +14,21 @@ void codec_wait() {
} }
void init_codec() { void init_codec() {
*CODEC = 0x1A00; // R13 - Turn On Headphones const uint16_t codec_init_data[] = {
codec_wait(); 0x2e00, // Master reset
*CODEC = 0x2A1F; // R21 - Enable All the Analog In 0x1a00, // R13 - Turn On Headphones
codec_wait(); 0x2a1f, // R21 - Enable All the Analog In
*CODEC = 0x2301; // R17 0x2301, // R17 - Auto-level control: WM8776_R17_ADC_ANALOG_AUTO_LEVEL_CONTROL | LCEN_ENABLED | HLD_MASK,
codec_wait(); 0x2c07, // R22 - Enable all output sources
*CODEC = 0x2C07; // R22 - Enable all output sources 0x1402, // R10 - DAC interface control
codec_wait(); 0x1602, // R11 - ADC inteface control
*CODEC = 0x1402; // R10 0x1845 // R12 - ADC rate 768, DAC rate 512
codec_wait(); };
*CODEC = 0x1602; // R11
codec_wait(); for (int i = 0; i<sizeof(codec_init_data)/sizeof(uint16_t); i++) {
*CODEC = 0x1845; // R12
codec_wait(); codec_wait();
*CODEC = codec_init_data[i];
}
codec_set_volume(0xff); codec_set_volume(0xff);
} }
@ -41,11 +42,11 @@ void init_codec() {
void codec_set_volume(unsigned char vol) { void codec_set_volume(unsigned char vol) {
volume = vol; volume = vol;
codec_wait();
*CODEC = 0x0A00 | (0xFF - vol); *CODEC = 0x0A00 | (0xFF - vol);
codec_wait();
*CODEC = 0x0400 | (vol >> 1);
codec_wait(); codec_wait();
*CODEC = 0x0400 | (vol >> 1);
} }
/* /*