ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
es7210.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
8
9#include "es7210_const.h"
10
11namespace esphome::es7210 {
12
20
21class ES7210 final : public audio_adc::AudioAdc, public Component, public i2c::I2CDevice {
22 /* Class for configuring an ES7210 ADC for microphone input.
23 * Based on code from:
24 * - https://github.com/espressif/esp-bsp/ (accessed 20241219)
25 * - https://github.com/espressif/esp-adf/ (accessed 20241219)
26 */
27 public:
28 void setup() override;
29 void dump_config() override;
30
31 void set_bits_per_sample(ES7210BitsPerSample bits_per_sample) { this->bits_per_sample_ = bits_per_sample; }
33 bool set_mic_gain(float mic_gain) override;
35 bool set_channel_gain(uint8_t channel, float gain);
36 void set_sample_rate(uint32_t sample_rate) { this->sample_rate_ = sample_rate; }
37 void set_tdm(bool enable_tdm) { this->enable_tdm_ = enable_tdm; }
38
40 float mic_gain() override { return this->channel_gains_[0]; };
41
42 protected:
48 bool es7210_update_reg_bit_(uint8_t reg_addr, uint8_t update_bits, uint8_t data);
49
53 uint8_t es7210_gain_reg_value_(float mic_gain);
54
58
59 bool setup_complete_{false};
60 bool enable_tdm_{false};
61 std::array<float, 4> channel_gains_{{0.0f, 0.0f, 0.0f, 0.0f}};
64};
65
66} // namespace esphome::es7210
uint8_t es7210_gain_reg_value_(float mic_gain)
Convert floating point mic gain value to register value.
Definition es7210.cpp:181
void set_tdm(bool enable_tdm)
Definition es7210.h:37
float mic_gain() override
Returns the MIC1 gain; other channels may have different gains.
Definition es7210.h:40
bool es7210_update_reg_bit_(uint8_t reg_addr, uint8_t update_bits, uint8_t data)
Updates an I2C registry address by modifying the current state.
Definition es7210.cpp:230
void setup() override
Definition es7210.cpp:36
void dump_config() override
Definition es7210.cpp:26
uint32_t sample_rate_
Definition es7210.h:63
bool set_mic_gain(float mic_gain) override
Sets all four channel gains, replacing any configured per-channel gains.
Definition es7210.cpp:87
std::array< float, 4 > channel_gains_
Definition es7210.h:61
void set_bits_per_sample(ES7210BitsPerSample bits_per_sample)
Definition es7210.h:31
bool set_channel_gain(uint8_t channel, float gain)
Sets a zero-based channel gain; returns false for an invalid channel or an I2C failure.
Definition es7210.cpp:95
ES7210BitsPerSample bits_per_sample_
Definition es7210.h:62
void set_sample_rate(uint32_t sample_rate)
Definition es7210.h:36
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
AlsGain501 gain
@ ES7210_BITS_PER_SAMPLE_20
Definition es7210.h:16
@ ES7210_BITS_PER_SAMPLE_18
Definition es7210.h:15
@ ES7210_BITS_PER_SAMPLE_16
Definition es7210.h:14
@ ES7210_BITS_PER_SAMPLE_32
Definition es7210.h:18
@ ES7210_BITS_PER_SAMPLE_24
Definition es7210.h:17
static void uint32_t