1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-18 20:10:55 +00:00
This commit is contained in:
Keith Burzinski 2025-01-17 00:28:34 -06:00
parent 771f4007cb
commit 3b3bcb80b7
No known key found for this signature in database
GPG Key ID: 802564C5F0EEFFBE
3 changed files with 17 additions and 14 deletions

View File

@ -89,7 +89,7 @@ void ES7210::setup() {
}
bool ES7210::set_mic_gain(float mic_gain) {
this->mic_gain_ = clamp<float>(mic_gain, ES7210_MIC_GAINS[0], ES7210_MIC_GAINS[ES7210_MIC_GAIN_COUNT - 1]);
this->mic_gain_ = clamp<float>(mic_gain, ES7210_MIC_GAIN_MIN, ES7210_MIC_GAIN_MAX);
if (this->setup_complete_) {
return this->configure_mic_gain_();
}
@ -169,14 +169,18 @@ bool ES7210::configure_mic_gain_() {
}
uint8_t ES7210::es7210_gain_reg_value_(float mic_gain) {
for (uint8_t i = 0; i < ES7210_MIC_GAIN_COUNT; i++) {
if (mic_gain == ES7210_MIC_GAINS[i]) {
return i;
} else if (mic_gain < ES7210_MIC_GAINS[i]) {
return i - 1;
}
// reg: 12 - 34.5dB, 13 - 36dB, 14 - 37.5dB
mic_gain += 0.5;
if (mic_gain <= 33.0) {
return (uint8_t) mic_gain / 3;
}
return ES7210_MIC_GAIN_COUNT - 1;
if (mic_gain < 36.0) {
return 12;
}
if (mic_gain < 37.0) {
return 13;
}
return 14;
}
bool ES7210::configure_i2s_format_() {

View File

@ -33,7 +33,6 @@ class ES7210 : public audio_adc::AudioAdc, public Component, public i2c::I2CDevi
void set_sample_rate(uint32_t sample_rate) { this->sample_rate_ = sample_rate; }
float mic_gain() override { return this->mic_gain_; };
float actual_mic_gain() { return ES7210_MIC_GAINS[this->es7210_gain_reg_value_(this->mic_gain_)]; }
protected:
/// @brief Updates an I2C registry address by modifying the current state
@ -45,7 +44,7 @@ class ES7210 : public audio_adc::AudioAdc, public Component, public i2c::I2CDevi
/// @brief Convert floating point mic gain value to register value
/// @param mic_gain Gain value to convert
/// @return Corresponding register value closest to but not exceeding specified gain
/// @return Corresponding register value for specified gain
uint8_t es7210_gain_reg_value_(float mic_gain);
bool configure_i2s_format_();

View File

@ -1,5 +1,7 @@
#pragma once
#include <cinttypes>
namespace esphome {
namespace es7210 {
@ -120,10 +122,8 @@ static const ES7210Coefficient ES7210_COEFFICIENTS[] = {
{19200000, 96000, 0x01, 0x05, 0x00, 0x01, 0x28, 0x00, 0x00, 0xc8},
};
static const uint8_t ES7210_MIC_GAIN_COUNT = 15;
static const float ES7210_MIC_GAINS[ES7210_MIC_GAIN_COUNT] = {
0.0, 3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0, 27.0, 30.0, 33.0, 34.5, 36.0, 37.5,
};
static const float ES7210_MIC_GAIN_MIN = 0.0;
static const float ES7210_MIC_GAIN_MAX = 37.5;
} // namespace es7210
} // namespace esphome