Skip to content

Commit

Permalink
add ALC in voice mode
Browse files Browse the repository at this point in the history
  • Loading branch information
uncarvedblock78 committed Jan 19, 2023
1 parent 8226a98 commit e65c1ce
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
8 changes: 7 additions & 1 deletion PlatformIO/src/devices/AudioKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ void AudioKit::InitI2SSpeakerOrMic(int mode)
// ES8388Control requires MCLK output.
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
WRITE_PERI_REG(PIN_CTRL, 0xFFF0);

if (mode == MODE_MIC) {
es8388.setALCmode(VOICE);
} else {
es8388.setALCmode(DISABLE);
}
}
return;
}
Expand Down Expand Up @@ -468,4 +474,4 @@ void AudioKit::ampOutput(int ampOut)
void AudioKit::updateBrightness(int brightness)
{
indicator_light->setMaxBrightness((brightness * indicator_light->limit) / 100);
}
}
53 changes: 53 additions & 0 deletions PlatformIO/src/devices/ES8388Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,59 @@ bool ES8388Control::begin(int sda, int scl, uint32_t frequency)
return res;
}

// Recommended ALC setting from User Guide
// DISABLE -> Disable ALC
// GENERIC -> Generic Mode
// VOICE -> Voice Mode
// MUSIC -> Music Mode
bool ES8388Control::setALCmode(alcmodesel_t alc) {
bool res = true;

// generic ALC setting
uint8_t ALCSEL = 0b11; // stereo
uint8_t ALCLVL = 0b0011; //-12db
uint8_t MAXGAIN = 0b111; //+35.5db
uint8_t MINGAIN = 0b000; //-12db
uint8_t ALCHLD = 0b0000; // 0ms
uint8_t ALCDCY = 0b0101; // 13.1ms/step
uint8_t ALCATK = 0b0111; // 13.3ms/step
uint8_t ALCMODE = 0b0; // ALC
uint8_t ALCZC = 0b0; // ZC off
uint8_t TIME_OUT = 0b0; // disable
uint8_t NGAT = 0b1; // enable
uint8_t NGTH = 0b10001; //-51db
uint8_t NGG = 0b00; // hold gain
uint8_t WIN_SIZE = 0b00110; // default

if (alc == DISABLE)
ALCSEL = 0b00;
else if (alc == MUSIC) {
ALCDCY = 0b1010; // 420ms/step
ALCATK = 0b0110; // 6.66ms/step
NGTH = 0b01011; // -60db
} else if (alc == VOICE) {
ALCLVL = 0b1100; // -4.5db
MAXGAIN = 0b101; // +23.5db
MINGAIN = 0b010; // 0db
ALCDCY = 0b0001; // 820us/step
ALCATK = 0b0010; // 416us/step
NGTH = 0b11000; // -40.5db
NGG = 0b01; // mute ADC
res &= write_reg(ES8388_ADDR, ES8388_ADCCONTROL1, 0x77);
}
res &= write_reg(ES8388_ADDR, ES8388_ADCCONTROL10,
ALCSEL << 6 | MAXGAIN << 3 | MINGAIN);
res &= write_reg(ES8388_ADDR, ES8388_ADCCONTROL11,
ALCLVL << 4 | ALCHLD);
res &= write_reg(ES8388_ADDR, ES8388_ADCCONTROL12, ALCDCY << 4 | ALCATK);
res &= write_reg(ES8388_ADDR, ES8388_ADCCONTROL13,
ALCMODE << 7 | ALCZC << 6 | TIME_OUT << 5 | WIN_SIZE);
res &= write_reg(ES8388_ADDR, ES8388_ADCCONTROL14,
NGTH << 3 | NGG << 2 | NGAT);

return res;
}

/**
* @brief (un)mute one of the two outputs or main dac output of the ES8388 by switching of the output register bits.
* Does not really mute the selected output, causes an attenuation. hence should be used in conjunction with appropriate
Expand Down
9 changes: 9 additions & 0 deletions PlatformIO/src/devices/ES8388Control.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#pragma once
#include <stdint.h>

typedef enum {
DISABLE, // ALC Disabled
GENERIC, // ALC Generic Mode
VOICE, // ALC Voice Mode
MUSIC, // ALC Music Mode
} alcmodesel_t;

class ES8388Control
{

Expand All @@ -20,4 +27,6 @@ class ES8388Control

void mute(const ES8388_OUT out, const bool muted);
void volume(const ES8388_OUT out, const uint8_t vol);

bool setALCmode(alcmodesel_t alc);
};

0 comments on commit e65c1ce

Please sign in to comment.