Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions src/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class AudioDriverAC101Class : public AudioDriver {
public:
bool setMute(bool mute) { return ac101_set_voice_mute(mute); }
bool setVolume(int volume) {
return ac101_set_voice_volume(limitValue(volume));
return ac101_set_voice_volume(limitValue(volume, 0, 100));
};
int getVolume() {
int vol;
Expand Down Expand Up @@ -608,7 +608,7 @@ class AudioDriverES7210Class : public AudioDriver {
bool setMute(bool mute) { return es7210_set_mute(mute) == RESULT_OK; }
bool setVolume(int volume) {
this->volume = volume;
return es7210_adc_set_volume(limitValue(volume)) == RESULT_OK;
return es7210_adc_set_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() { return volume; }

Expand Down Expand Up @@ -639,7 +639,7 @@ class AudioDriverES7243Class : public AudioDriver {
return es7243_adc_set_voice_mute(mute) == RESULT_OK;
}
bool setVolume(int volume) {
return es7243_adc_set_voice_volume(limitValue(volume)) == RESULT_OK;
return es7243_adc_set_voice_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand Down Expand Up @@ -674,7 +674,7 @@ class AudioDriverES7243eClass : public AudioDriver {
}
bool setVolume(int volume) {
this->volume = volume;
return es7243e_adc_set_voice_volume(limitValue(volume)) == RESULT_OK;
return es7243e_adc_set_voice_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand Down Expand Up @@ -710,7 +710,7 @@ class AudioDriverES8156Class : public AudioDriver {
}
bool setVolume(int volume) {
AD_LOGD("volume %d", volume);
return es8156_codec_set_voice_volume(limitValue(volume)) == RESULT_OK;
return es8156_codec_set_voice_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand Down Expand Up @@ -742,7 +742,7 @@ class AudioDriverES8311Class : public AudioDriver {
AudioDriverES8311Class(int i2cAddr = 0) { i2c_address = i2cAddr; }
bool setMute(bool mute) { return es8311_set_voice_mute(mute) == RESULT_OK; }
bool setVolume(int volume) {
return es8311_codec_set_voice_volume(limitValue(volume)) == RESULT_OK;
return es8311_codec_set_voice_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand Down Expand Up @@ -787,7 +787,7 @@ class AudioDriverES8374Class : public AudioDriver {
bool setMute(bool mute) { return es8374_set_voice_mute(mute) == RESULT_OK; }
bool setVolume(int volume) {
AD_LOGD("volume %d", volume);
return es8374_codec_set_voice_volume(limitValue(volume)) == RESULT_OK;
return es8374_codec_set_voice_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand Down Expand Up @@ -849,7 +849,7 @@ class AudioDriverES8388Class : public AudioDriver {
}
bool setVolume(int volume) {
AD_LOGD("volume %d", volume);
return es8388_set_voice_volume(limitValue(volume)) == RESULT_OK;
return es8388_set_voice_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand All @@ -858,14 +858,36 @@ class AudioDriverES8388Class : public AudioDriver {
}

bool setInputVolume(int volume) {
// map values from 0 - 100 to 0 to 9 MIC_GAIN_MIN = -1,
// map values from 0 - 100 to 0 to 8

// es_mic_gain_t: MIC_GAIN_MIN = -1, 0,3,6,9,12,15,18,21,24 MIC_GAIN_MAX = 25

// Vol: 0, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100
// idx: 0, 1, 2, 3, 4, 5, 6, 7, 8
// dB/gain: 0, 3, 6, 9, 12, 15, 18, 21, 24
// factor: 1, 2, 4, 8, 16, 32, 63, 126, 252

// es8388 Register 9 – ADC Control 1
//dB MicL MicR
// 0 0000 0000
// 3 0001 0001
// 6 0010 0010
// 9 0011 0011
//12 0100 0100
//15 0101 0101
//18 0110 0110
//21 0111 0111
//24 1000 1000

es_mic_gain_t gains[] = {MIC_GAIN_0DB, MIC_GAIN_3DB, MIC_GAIN_6DB,
MIC_GAIN_9DB, MIC_GAIN_12DB, MIC_GAIN_15DB,
MIC_GAIN_18DB, MIC_GAIN_21DB, MIC_GAIN_24DB,
MIC_GAIN_MAX};
int idx = limitValue(volume / 10, 0, 9);
MIC_GAIN_18DB, MIC_GAIN_21DB, MIC_GAIN_24DB};

int vol = limitValue(volume, 0, 100);
int idx = map(vol, 0, 100, 0, 8);

es_mic_gain_t gain = gains[idx];
AD_LOGD("input volume: %d -> gain %d", volume, gain);
AD_LOGD("input volume: %d -> gain %d [dB] (idx: %d of 0..8)", volume, gain, idx);
return setMicrophoneGain(gain);
}

Expand Down Expand Up @@ -901,7 +923,7 @@ class AudioDriverTAS5805MClass : public AudioDriver {
bool setMute(bool mute) { return tas5805m_set_mute(mute) == RESULT_OK; }
bool setVolume(int volume) {
AD_LOGD("volume %d", volume);
return tas5805m_set_volume(limitValue(volume)) == RESULT_OK;
return tas5805m_set_volume(limitValue(volume, 0, 100)) == RESULT_OK;
}
int getVolume() {
int vol;
Expand Down
3 changes: 2 additions & 1 deletion src/Driver/es8388/es8388.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,13 @@ error_t es8388_set_voice_volume(int volume) {
else if (volume > 100)
volume = 100;
volume /= 3;
// DAC LDACVOL RDACVOL default 0 = 0DB; Default value 192 = – -96 dB
res = es_write_reg(ES8388_ADDR, ES8388_DACCONTROL4, 0);
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL5, 0);
// LOUT1 RLOUT1 volume: dataheet says only 6 bits
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL24, volume);
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL25, volume);
// DAC LDACVOL RDACVOL default 0 = 0DB; Default value 192 = – -96 dB
// LOUT2 ROUT2 volume: datasheet says only 6 bits
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL26, volume);
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL27, volume);
return res;
Expand Down
3 changes: 2 additions & 1 deletion src/DriverCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#define RESULT_OK 0 /*!< error_t value indicating success (no error) */
#define RESULT_FAIL -1 /*!< Generic error_t code indicating failure */
#define ERROR_INVALID_ARG 1
#define I2C_END true

#define I2C_END true // wether to send a stop bit at the end of the transmission

#ifdef __cplusplus
namespace audio_driver {
Expand Down
10 changes: 2 additions & 8 deletions src/Utils/I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ error_t i2c_bus_write_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
addr, reglen, datalen, reg[0], data[0]);
TwoWire *p_wire = (TwoWire *)bus;
assert(p_wire!=nullptr);
//assert(reglen == 1);
//assert(datalen == 1);

int result = RESULT_OK;
p_wire->beginTransmission(addr);
p_wire->write(reg, reglen);
p_wire->write(data, datalen);
//p_wire->write(reg[0]);
//p_wire->write(data[0]);

int rc = p_wire->endTransmission(I2C_END);
if (rc != 0) {
AD_LOGE("->p_wire->endTransmission: %d", rc);
Expand All @@ -45,7 +39,7 @@ error_t i2c_bus_check(i2c_bus_handle_t bus, int addr) {
}


/// This method is used
// this method is used !
error_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
int reglen, uint8_t *outdata, int datalen) {
AD_LOGD("i2c_bus_read_bytes: addr=%d reglen=%d datalen=%d - reg=%d", addr,
Expand All @@ -64,7 +58,7 @@ error_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
AD_LOGE("->p_wire->endTransmission: %d", rc);
}

uint8_t result_len = p_wire->requestFrom((addr), datalen, (int) true);
uint8_t result_len = p_wire->requestFrom((addr), datalen, I2C_END);
if (result_len > 0) {
result_len = p_wire->readBytes(outdata, datalen);
} else {
Expand Down