ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
es8311_const.h
Go to the documentation of this file.
1#pragma once
2
3#include "es8311.h"
4
5namespace esphome::es8311 {
6
7// ES8311 register addresses
8static const uint8_t ES8311_REG00_RESET = 0x00; // Reset
9static const uint8_t ES8311_REG01_CLK_MANAGER = 0x01; // Clock Manager: select clk src for mclk, enable clock for codec
10static const uint8_t ES8311_REG02_CLK_MANAGER = 0x02; // Clock Manager: clk divider and clk multiplier
11static const uint8_t ES8311_REG03_CLK_MANAGER = 0x03; // Clock Manager: adc fsmode and osr
12static const uint8_t ES8311_REG04_CLK_MANAGER = 0x04; // Clock Manager: dac osr
13static const uint8_t ES8311_REG05_CLK_MANAGER = 0x05; // Clock Manager: clk divider for adc and dac
14static const uint8_t ES8311_REG06_CLK_MANAGER = 0x06; // Clock Manager: bclk inverter BIT(5) and divider
15static const uint8_t ES8311_REG07_CLK_MANAGER = 0x07; // Clock Manager: tri-state, lrck divider
16static const uint8_t ES8311_REG08_CLK_MANAGER = 0x08; // Clock Manager: lrck divider
17static const uint8_t ES8311_REG09_SDPIN = 0x09; // Serial Digital Port: DAC
18static const uint8_t ES8311_REG0A_SDPOUT = 0x0A; // Serial Digital Port: ADC
19static const uint8_t ES8311_REG0B_SYSTEM = 0x0B; // System
20static const uint8_t ES8311_REG0C_SYSTEM = 0x0C; // System
21static const uint8_t ES8311_REG0D_SYSTEM = 0x0D; // System: power up/down
22static const uint8_t ES8311_REG0E_SYSTEM = 0x0E; // System: power up/down
23static const uint8_t ES8311_REG0F_SYSTEM = 0x0F; // System: low power
24static const uint8_t ES8311_REG10_SYSTEM = 0x10; // System
25static const uint8_t ES8311_REG11_SYSTEM = 0x11; // System
26static const uint8_t ES8311_REG12_SYSTEM = 0x12; // System: Enable DAC
27static const uint8_t ES8311_REG13_SYSTEM = 0x13; // System
28static const uint8_t ES8311_REG14_SYSTEM = 0x14; // System: select DMIC, select analog pga gain
29static const uint8_t ES8311_REG15_ADC = 0x15; // ADC: adc ramp rate, dmic sense
30static const uint8_t ES8311_REG16_ADC = 0x16; // ADC
31static const uint8_t ES8311_REG17_ADC = 0x17; // ADC: volume
32static const uint8_t ES8311_REG18_ADC = 0x18; // ADC: alc enable and winsize
33static const uint8_t ES8311_REG19_ADC = 0x19; // ADC: alc maxlevel
34static const uint8_t ES8311_REG1A_ADC = 0x1A; // ADC: alc automute
35static const uint8_t ES8311_REG1B_ADC = 0x1B; // ADC: alc automute, adc hpf s1
36static const uint8_t ES8311_REG1C_ADC = 0x1C; // ADC: equalizer, hpf s2
37static const uint8_t ES8311_REG1D_ADCEQ = 0x1D; // ADCEQ: equalizer B0
38static const uint8_t ES8311_REG1E_ADCEQ = 0x1E; // ADCEQ: equalizer B0
39static const uint8_t ES8311_REG1F_ADCEQ = 0x1F; // ADCEQ: equalizer B0
40static const uint8_t ES8311_REG20_ADCEQ = 0x20; // ADCEQ: equalizer B0
41static const uint8_t ES8311_REG21_ADCEQ = 0x21; // ADCEQ: equalizer A1
42static const uint8_t ES8311_REG22_ADCEQ = 0x22; // ADCEQ: equalizer A1
43static const uint8_t ES8311_REG23_ADCEQ = 0x23; // ADCEQ: equalizer A1
44static const uint8_t ES8311_REG24_ADCEQ = 0x24; // ADCEQ: equalizer A1
45static const uint8_t ES8311_REG25_ADCEQ = 0x25; // ADCEQ: equalizer A2
46static const uint8_t ES8311_REG26_ADCEQ = 0x26; // ADCEQ: equalizer A2
47static const uint8_t ES8311_REG27_ADCEQ = 0x27; // ADCEQ: equalizer A2
48static const uint8_t ES8311_REG28_ADCEQ = 0x28; // ADCEQ: equalizer A2
49static const uint8_t ES8311_REG29_ADCEQ = 0x29; // ADCEQ: equalizer B1
50static const uint8_t ES8311_REG2A_ADCEQ = 0x2A; // ADCEQ: equalizer B1
51static const uint8_t ES8311_REG2B_ADCEQ = 0x2B; // ADCEQ: equalizer B1
52static const uint8_t ES8311_REG2C_ADCEQ = 0x2C; // ADCEQ: equalizer B1
53static const uint8_t ES8311_REG2D_ADCEQ = 0x2D; // ADCEQ: equalizer B2
54static const uint8_t ES8311_REG2E_ADCEQ = 0x2E; // ADCEQ: equalizer B2
55static const uint8_t ES8311_REG2F_ADCEQ = 0x2F; // ADCEQ: equalizer B2
56static const uint8_t ES8311_REG30_ADCEQ = 0x30; // ADCEQ: equalizer B2
57static const uint8_t ES8311_REG31_DAC = 0x31; // DAC: mute
58static const uint8_t ES8311_REG32_DAC = 0x32; // DAC: volume
59static const uint8_t ES8311_REG33_DAC = 0x33; // DAC: offset
60static const uint8_t ES8311_REG34_DAC = 0x34; // DAC: drc enable, drc winsize
61static const uint8_t ES8311_REG35_DAC = 0x35; // DAC: drc maxlevel, minilevel
62static const uint8_t ES8311_REG36_DAC = 0x36; // DAC
63static const uint8_t ES8311_REG37_DAC = 0x37; // DAC: ramprate
64static const uint8_t ES8311_REG38_DACEQ = 0x38; // DACEQ: equalizer B0
65static const uint8_t ES8311_REG39_DACEQ = 0x39; // DACEQ: equalizer B0
66static const uint8_t ES8311_REG3A_DACEQ = 0x3A; // DACEQ: equalizer B0
67static const uint8_t ES8311_REG3B_DACEQ = 0x3B; // DACEQ: equalizer B0
68static const uint8_t ES8311_REG3C_DACEQ = 0x3C; // DACEQ: equalizer B1
69static const uint8_t ES8311_REG3D_DACEQ = 0x3D; // DACEQ: equalizer B1
70static const uint8_t ES8311_REG3E_DACEQ = 0x3E; // DACEQ: equalizer B1
71static const uint8_t ES8311_REG3F_DACEQ = 0x3F; // DACEQ: equalizer B1
72static const uint8_t ES8311_REG40_DACEQ = 0x40; // DACEQ: equalizer A1
73static const uint8_t ES8311_REG41_DACEQ = 0x41; // DACEQ: equalizer A1
74static const uint8_t ES8311_REG42_DACEQ = 0x42; // DACEQ: equalizer A1
75static const uint8_t ES8311_REG43_DACEQ = 0x43; // DACEQ: equalizer A1
76static const uint8_t ES8311_REG44_GPIO = 0x44; // GPIO: dac2adc for test
77static const uint8_t ES8311_REG45_GP = 0x45; // GPIO: GP control
78static const uint8_t ES8311_REGFA_I2C = 0xFA; // I2C: reset registers
79static const uint8_t ES8311_REGFC_FLAG = 0xFC; // Flag
80static const uint8_t ES8311_REGFD_CHD1 = 0xFD; // Chip: ID1
81static const uint8_t ES8311_REGFE_CHD2 = 0xFE; // Chip: ID2
82static const uint8_t ES8311_REGFF_CHVER = 0xFF; // Chip: Version
83
84// ES8311 clock divider coefficients
85static const ES8311Coefficient ES8311_COEFFICIENTS[] = {
86 // clang-format off
87
88 // mclk, rate, pre_ pre_ adc_ dac_ fs_ lrck lrck bclk_ adc_ dac_
89 // div, mult, div, div, mode, _h, _l, div, osr, osr
90
91 // 8k
92 {12288000, 8000, 0x06, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
93 {18432000, 8000, 0x03, 0x02, 0x03, 0x03, 0x00, 0x05, 0xff, 0x18, 0x10, 0x20},
94 {16384000, 8000, 0x08, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
95 { 8192000, 8000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
96 { 6144000, 8000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
97 { 4096000, 8000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
98 { 3072000, 8000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
99 { 2048000, 8000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
100 { 1536000, 8000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
101 { 1024000, 8000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
102
103 // 11.025k
104 {11289600, 11025, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
105 { 5644800, 11025, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
106 { 2822400, 11025, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
107 { 1411200, 11025, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
108
109 // 12k
110 {12288000, 12000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
111 { 6144000, 12000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
112 { 3072000, 12000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
113 { 1536000, 12000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
114
115 // 16k
116 {12288000, 16000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
117 {18432000, 16000, 0x03, 0x02, 0x03, 0x03, 0x00, 0x02, 0xff, 0x0c, 0x10, 0x20},
118 {16384000, 16000, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
119 { 8192000, 16000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
120 { 6144000, 16000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
121 { 4096000, 16000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
122 { 3072000, 16000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
123 { 2048000, 16000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
124 { 1536000, 16000, 0x03, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
125 { 1024000, 16000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x20},
126
127 // 22.05k
128 {11289600, 22050, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
129 { 5644800, 22050, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
130 { 2822400, 22050, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
131 { 1411200, 22050, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
132
133 // 24k
134 {12288000, 24000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
135 {18432000, 24000, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
136 { 6144000, 24000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
137 { 3072000, 24000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
138 { 1536000, 24000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
139
140 // 32k
141 {12288000, 32000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
142 {18432000, 32000, 0x03, 0x04, 0x03, 0x03, 0x00, 0x02, 0xff, 0x0c, 0x10, 0x10},
143 {16384000, 32000, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
144 { 8192000, 32000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
145 { 6144000, 32000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
146 { 4096000, 32000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
147 { 3072000, 32000, 0x03, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
148 { 2048000, 32000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
149 { 1536000, 32000, 0x03, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
150 { 1024000, 32000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
151
152 // 44.1k
153 {11289600, 44100, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
154 { 5644800, 44100, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
155 { 2822400, 44100, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
156 { 1411200, 44100, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
157
158 // 48k
159 {12288000, 48000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
160 {18432000, 48000, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
161 { 6144000, 48000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
162 { 3072000, 48000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
163 { 1536000, 48000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
164
165 // 64k
166 {12288000, 64000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
167 {18432000, 64000, 0x03, 0x04, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
168 {16384000, 64000, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
169 { 8192000, 64000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
170 { 6144000, 64000, 0x01, 0x04, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
171 { 4096000, 64000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
172 { 3072000, 64000, 0x01, 0x08, 0x03, 0x03, 0x01, 0x01, 0x7f, 0x06, 0x10, 0x10},
173 { 2048000, 64000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
174 { 1536000, 64000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0xbf, 0x03, 0x18, 0x18},
175 { 1024000, 64000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
176
177 // 88.2k
178 {11289600, 88200, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
179 { 5644800, 88200, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
180 { 2822400, 88200, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
181 { 1411200, 88200, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
182
183 // 96k
184 {12288000, 96000, 0x01, 0x02, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
185 {18432000, 96000, 0x03, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
186 { 6144000, 96000, 0x01, 0x04, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
187 { 3072000, 96000, 0x01, 0x08, 0x01, 0x01, 0x00, 0x00, 0xff, 0x04, 0x10, 0x10},
188 { 1536000, 96000, 0x01, 0x08, 0x01, 0x01, 0x01, 0x00, 0x7f, 0x02, 0x10, 0x10},
189
190 // clang-format on
191};
192
193} // namespace esphome::es8311