arduino-audio-driver
Loading...
Searching...
No Matches
TLV320DAC310x.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <cstddef>
13#include <math.h>
14
16
17namespace audio_driver {
18
21 I2S = 0,
22 DSP = 1,
23 RJF = 2,
24 LJF = 3,
25};
26
29 Bits16 = 0,
30 Bits20 = 1,
31 Bits24 = 2,
32 Bits32 = 3,
33};
34
37 Headphone,
38 LineOut,
39 Auto,
40};
41
44 DecimationA = 25,
45 DecimationB = 10,
46 DecimationC = 18,
47};
48
51 Multiple8 = 8,
52 Multiple4 = 4,
53 Multiple2 = 2,
54};
55
58 V1P35 = 0,
59 V1P5 = 1,
60 V1P65 = 2,
61 V1P8 = 3,
62};
63
76 public:
77 // ---- Page 0 register addresses ----
78 static constexpr uint8_t PAGE_CONTROL_ADDR = 0;
79 static constexpr uint8_t SOFT_RESET_ADDR = 1;
80 static constexpr uint8_t NDAC_DIV_ADDR = 11;
81 static constexpr uint8_t MDAC_DIV_ADDR = 12;
82 static constexpr uint8_t OSR_MSB_ADDR = 13;
83 static constexpr uint8_t OSR_LSB_ADDR = 14;
84 static constexpr uint8_t IF_CTRL1_ADDR = 27;
85 static constexpr uint8_t BCLK_DIV_ADDR = 30;
86 static constexpr uint8_t OVF_FLAG_ADDR = 39;
87 static constexpr uint8_t PROC_BLK_SEL_ADDR = 60;
88 static constexpr uint8_t DATA_PATH_SETUP_ADDR = 63;
89 static constexpr uint8_t VOL_CTRL_ADDR = 64;
90 static constexpr uint8_t L_DIG_VOL_CTRL_ADDR = 65;
91 static constexpr uint8_t DRC_CTRL1_ADDR = 68;
92 static constexpr uint8_t L_BEEP_GEN_ADDR = 71;
93 static constexpr uint8_t R_BEEP_GEN_ADDR = 72;
94 static constexpr uint8_t BEEP_LEN_MSB_ADDR = 73;
95 static constexpr uint8_t BEEP_LEN_MID_ADDR = 74;
96 static constexpr uint8_t BEEP_LEN_LSB_ADDR = 75;
97 static constexpr uint8_t BEEP_SIN_MSB_ADDR = 76;
98 static constexpr uint8_t BEEP_SIN_LSB_ADDR = 77;
99 static constexpr uint8_t BEEP_COS_MSB_ADDR = 78;
100 static constexpr uint8_t BEEP_COS_LSB_ADDR = 79;
101 static constexpr uint8_t VOL_MICDET_ADC_CTRL_ADDR = 116;
102
103 // ---- Page 1 register addresses ----
104 static constexpr uint8_t HEADPHONE_DRV_ADDR = 31;
105 static constexpr uint8_t SPEAKER_AMP_ADDR = 32;
106 static constexpr uint8_t HP_OUT_POP_RM_ADDR = 33;
107 static constexpr uint8_t OUTPUT_ROUTING_ADDR = 35;
108 static constexpr uint8_t HPL_ANA_VOL_CTRL_ADDR = 36;
109 static constexpr uint8_t HPR_ANA_VOL_CTRL_ADDR = 37;
110 static constexpr uint8_t SPL_ANA_VOL_CTRL_ADDR = 38;
111 static constexpr uint8_t HPL_DRV_GAIN_CTRL_ADDR = 40;
112 static constexpr uint8_t HPR_DRV_GAIN_CTRL_ADDR = 41;
113 static constexpr uint8_t SPK_DRV_GAIN_CTRL_ADDR = 42;
114 static constexpr uint8_t HEADPHONE_DRV_CTRL_ADDR = 44;
115
116 // ---- Page 3 register addresses ----
117 static constexpr uint8_t TIMER_MCLK_DIV_ADDR = 16;
118
119 // ---- Bit field defines ----
120 static constexpr uint8_t SOFT_RESET_ASSERT = 1;
121
122 static constexpr uint8_t NDAC_POWER_UP = 0x80; // BIT(7)
123 static constexpr uint8_t NDAC_POWER_UP_MASK = 0x80; // BIT(7)
124 static constexpr uint8_t NDAC_DIV_MASK = 0x7F; // BIT_MASK(7)
125
126 static constexpr uint8_t MDAC_POWER_UP = 0x80;
127 static constexpr uint8_t MDAC_POWER_UP_MASK = 0x80;
128 static constexpr uint8_t MDAC_DIV_MASK = 0x7F;
129
130 static constexpr uint32_t DAC_PROC_CLK_FREQ_MAX = 49152000; // 49.152 MHz
131 static constexpr uint32_t DAC_MOD_CLK_FREQ_MIN = 2800000; // 2.8 MHz
132 static constexpr uint32_t DAC_MOD_CLK_FREQ_MAX = 6200000; // 6.2 MHz
133
134 static constexpr uint8_t OSR_MSB_MASK = 0x03; // BIT_MASK(2)
135 static constexpr uint8_t OSR_LSB_MASK = 0xFF; // BIT_MASK(8)
136
137 static constexpr uint8_t IF_CTRL_IFTYPE_MASK = 0x03; // BIT_MASK(2)
138 static constexpr uint8_t IF_CTRL_WLEN_MASK = 0x03; // BIT_MASK(2)
139 static constexpr uint8_t IF_CTRL_BCLK_OUT = 0x08; // BIT(3)
140 static constexpr uint8_t IF_CTRL_WCLK_OUT = 0x04; // BIT(2)
141
142 static constexpr uint8_t BCLK_DIV_POWER_UP = 0x80; // BIT(7)
143 static constexpr uint8_t BCLK_DIV_POWER_UP_MASK = 0x80; // BIT(7)
144 static constexpr uint8_t BCLK_DIV_MASK = 0x7F; // BIT_MASK(7)
145
146 static constexpr uint8_t PROC_BLK_SEL_MASK = 0x1F; // BIT_MASK(5)
147
148 static constexpr uint8_t DAC_LR_POWERUP_DEFAULT =
149 (0x80 | 0x40 | 0x10 | 0x04); // BIT(7)|BIT(6)|BIT(4)|BIT(2)
150 static constexpr uint8_t DAC_LR_POWERDN_DEFAULT = (0x10 | 0x04); // BIT(4)|BIT(2)
151
152 static constexpr uint8_t VOL_CTRL_UNMUTE_DEFAULT = 0;
153 static constexpr uint8_t VOL_CTRL_MUTE_DEFAULT = (0x08 | 0x04); // BIT(3)|BIT(2)
154
155 static constexpr uint8_t BEEP_GEN_EN_BEEP = 0x80; // BIT(7)
156 static constexpr uint8_t BEEP_VOL_MASK = 0x3F; // D5-D0: volume code (0=2dB .. 63=-61dB)
157
158 static constexpr uint8_t VOL_MICDET_VOL_CTRL_PIN = 0x80; // BIT(7)
159
160 static constexpr uint8_t HEADPHONE_DRV_POWERUP = (0x80 | 0x40); // BIT(7)|BIT(6)
161 static constexpr uint8_t HEADPHONE_DRV_CM_MASK = (0x03 << 3);
162 static constexpr uint8_t HEADPHONE_DRV_RESERVED = 0x04; // BIT(2)
163
164 static constexpr uint8_t SPEAKER_AMP_POWERUP = 0x80; // BIT(7)
165 static constexpr uint8_t SPEAKER_AMP_RESERVED = (0x04 | 0x02); // BIT(2)|BIT(1)
166
167 static constexpr uint8_t SPK_DRV_UNMUTE = 0x04; // BIT(2)
168
169 static constexpr uint8_t HP_OUT_POP_RM_ENABLE = 0x80; // BIT(7)
170
171 static constexpr uint8_t OUTPUT_ROUTING_HPL = (2 << 6);
172 static constexpr uint8_t OUTPUT_ROUTING_MIXERL = (1 << 6);
173 static constexpr uint8_t OUTPUT_ROUTING_HPR = (2 << 2);
174 static constexpr uint8_t OUTPUT_ROUTING_MIXERR = (1 << 2);
175
176 static constexpr uint8_t HPX_ANA_VOL_ENABLE = 0x80; // BIT(7)
177 static constexpr uint8_t HPX_ANA_VOL_MASK = 0x7F; // BIT_MASK(7)
178 static constexpr uint8_t HPX_ANA_VOL_MAX = 0;
179 static constexpr uint8_t HPX_ANA_VOL_DEFAULT = 64;
180 static constexpr uint8_t HPX_ANA_VOL_MIN = 127;
181 static constexpr uint8_t HPX_ANA_VOL_LOW_THRESH = 105;
182 static constexpr uint8_t HPX_ANA_VOL_FLOOR = 144;
183
184 static constexpr uint8_t HPX_DRV_UNMUTE = 0x04; // BIT(2)
185
186 static constexpr uint8_t HEADPHONE_DRV_LINEOUT = (0x02 | 0x04); // BIT(1)|BIT(2)
187
188 static constexpr uint8_t TIMER_MCLK_DIV_EN_EXT = 0x80; // BIT(7)
189 static constexpr uint8_t TIMER_MCLK_DIV_MASK = 0x7F; // BIT_MASK(7)
190
191 // ---- Output volume range (0.5dB steps) ----
192 static constexpr int OUTPUT_VOLUME_MAX = 0;
193 static constexpr int OUTPUT_VOLUME_MIN = (-78 * 2);
194
196
200 bool begin(uint32_t sample_rate, uint8_t bits, codec_mode_t mode,
201 i2s_format_t fmt, bool is_master, uint8_t channels) override {
202 (void)mode;
203 (void)channels;
204 return begin(sample_rate, bits, 12000000, toFormat(fmt), is_master, is_master);
205 }
206
220 bool begin(uint32_t sample_rate = 44100, uint8_t word_size = 16,
221 uint32_t mclk_freq = 12000000,
223 bool bclk_controller = false, bool wclk_controller = false) {
224 bool rc = true;
225 current_sample_rate = sample_rate;
226
227 rc &= softReset();
228 rc &= configureClocks(mclk_freq, sample_rate, bclk_controller, word_size);
229 rc &= configureDai(word_size, fmt, bclk_controller, wclk_controller);
230 rc &= configureFilters(sample_rate);
231 rc &= configureOutput();
232
233 return rc;
234 }
235
238
243 bool configureClocks(uint32_t mclk_freq, uint32_t sample_rate,
244 bool bclk_controller = false, uint8_t word_size = 16) {
245 bool rc = true;
246 uint32_t dac_clk, mod_clk;
247 uint32_t ndac, mdac, bclk_div = 0;
248 int osr, osr_min, osr_max;
249 TLV320DAC310xOsrMultiple osr_multiple = getOsrMultiple(sample_rate);
250
251 if (mclk_freq <= DAC_PROC_CLK_FREQ_MAX) {
252 ndac = 1;
253 } else {
254 ndac = mclk_freq / DAC_PROC_CLK_FREQ_MAX;
255 }
256 dac_clk = mclk_freq / ndac;
257
258 /* find mdac/osr such that mod_clk = sample_rate * osr is an integer
259 * divisor of dac_clk and DAC_MOD_CLK_FREQ_MIN <= mod_clk <=
260 * DAC_MOD_CLK_FREQ_MAX */
261 osr_min = (DAC_MOD_CLK_FREQ_MIN + sample_rate - 1) / sample_rate;
262 osr_max = DAC_MOD_CLK_FREQ_MAX / sample_rate;
263
264 int multiple = (int)osr_multiple;
265 osr_max = (osr_max / multiple) * multiple;
266 osr_min = ((osr_min + multiple - 1) / multiple) * multiple;
267
268 osr = osr_max;
269 mdac = 0;
270 while (osr >= osr_min) {
271 mod_clk = sample_rate * osr;
272 mdac = dac_clk / mod_clk;
273 if ((mdac * mod_clk) == dac_clk) {
274 break;
275 }
276 osr -= multiple;
277 }
278
279 if (osr < osr_min || mdac == 0) {
280 return false;
281 }
282
283 if (bclk_controller) {
284 uint32_t num = (uint32_t)osr * mdac;
285 uint32_t den = (uint32_t)word_size * 2U;
286 bclk_div = num / den;
287 if ((bclk_div * den) != num) {
288 return false;
289 }
291 (uint8_t)(BCLK_DIV_POWER_UP | (bclk_div & BCLK_DIV_MASK)));
292 }
293
294 /* set NDAC, then MDAC, followed by OSR */
296 (uint8_t)((ndac & NDAC_DIV_MASK) | NDAC_POWER_UP_MASK));
298 (uint8_t)((mdac & MDAC_DIV_MASK) | MDAC_POWER_UP_MASK));
299 rc &= writePagedReg(0, OSR_MSB_ADDR, (uint8_t)((osr >> 8) & OSR_MSB_MASK));
300 rc &= writePagedReg(0, OSR_LSB_ADDR, (uint8_t)(osr & OSR_LSB_MASK));
301
302 if (bclk_controller) {
304 (uint8_t)((bclk_div & BCLK_DIV_MASK) | BCLK_DIV_POWER_UP));
305 }
306
307 /* MCLK divider for the internal timer, target ~1MHz */
308 uint32_t mclk_div = (mclk_freq + 999999) / 1000000;
310 (uint8_t)(TIMER_MCLK_DIV_EN_EXT | (mclk_div & TIMER_MCLK_DIV_MASK)));
311
312 return rc;
313 }
314
316 bool configureDai(uint8_t word_size = 16,
318 bool bclk_controller = false, bool wclk_controller = false) {
319 uint8_t val = (uint8_t)(((uint8_t)fmt & IF_CTRL_IFTYPE_MASK) << 6);
320
321 if (bclk_controller) val |= IF_CTRL_BCLK_OUT;
322 if (wclk_controller) val |= IF_CTRL_WCLK_OUT;
323
325 switch (word_size) {
326 case 16:
328 break;
329 case 20:
331 break;
332 case 24:
334 break;
335 case 32:
337 break;
338 default:
339 return false;
340 }
341 val |= (uint8_t)(((uint8_t)wlen & IF_CTRL_WLEN_MASK) << 4);
342
343 return writePagedReg(0, IF_CTRL1_ADDR, val);
344 }
345
347 bool configureFilters(uint32_t sample_rate) {
348 TLV320DAC310xProcBlock proc_blk;
349 if (sample_rate >= 192000) {
351 } else if (sample_rate >= 96000) {
353 } else {
355 }
357 (uint8_t)((uint8_t)proc_blk & PROC_BLK_SEL_MASK));
358 }
359
371 bool rc = true;
372 uint8_t val = 0;
373
376
377 if (!hp && !spk) {
378 /* unroute the DACs and power down both the headphone and speaker drivers */
380 rc &= readPagedReg(1, HEADPHONE_DRV_ADDR, val);
382 (uint8_t)((val & (uint8_t)~HEADPHONE_DRV_POWERUP) |
384 rc &= readPagedReg(1, SPEAKER_AMP_ADDR, val);
386 (uint8_t)((val & (uint8_t)~SPEAKER_AMP_POWERUP) |
388 return rc;
389 }
390
391 /* set common mode voltage of the headphone driver (e.g. 1.65V = half of
392 * typical 3.3V AVDD) */
393 rc &= readPagedReg(1, HEADPHONE_DRV_ADDR, val);
394 val &= (uint8_t)~HEADPHONE_DRV_CM_MASK;
395 val |= (uint8_t)((((uint8_t)cm) << 3) & HEADPHONE_DRV_CM_MASK) | HEADPHONE_DRV_RESERVED;
396 rc &= writePagedReg(1, HEADPHONE_DRV_ADDR, val);
397
398 /* enable pop removal on power down/up */
399 rc &= readPagedReg(1, HP_OUT_POP_RM_ADDR, val);
400 rc &= writePagedReg(1, HP_OUT_POP_RM_ADDR, (uint8_t)(val | HP_OUT_POP_RM_ENABLE));
401
402 /* route DAC_L/DAC_R to the mixer amplifiers so that the analog volume
403 * controls have effect; DAC_L feeds both HPL and SPK (SPK is mono),
404 * DAC_R only feeds HPR */
405 val = 0;
406 if (hp || spk) val |= OUTPUT_ROUTING_MIXERL;
407 if (hp) val |= OUTPUT_ROUTING_MIXERR;
408 rc &= writePagedReg(1, OUTPUT_ROUTING_ADDR, val);
409
410 if (hp) {
411 /* enable volume control on headphone out */
414
415 /* set headphone driver impedance mode */
417 uint8_t drv_ctrl = (mode == TLV320DAC310xOutputMode::Headphone)
418 ? 0x00
420 rc &= writePagedReg(1, HEADPHONE_DRV_CTRL_ADDR, drv_ctrl);
421
422 /* unmute headphone drivers */
425
426 /* power up headphone drivers */
427 rc &= readPagedReg(1, HEADPHONE_DRV_ADDR, val);
430 } else {
431 /* power down headphone drivers */
432 rc &= readPagedReg(1, HEADPHONE_DRV_ADDR, val);
434 (uint8_t)((val & (uint8_t)~HEADPHONE_DRV_POWERUP) |
436 }
437
438 if (spk) {
439 /* route the left analog volume control to the Class-D speaker driver */
441
442 /* unmute the Class-D speaker driver (default gain = 6dB) */
444
445 /* power up the Class-D speaker driver */
446 rc &= readPagedReg(1, SPEAKER_AMP_ADDR, val);
448 (uint8_t)(val | SPEAKER_AMP_POWERUP | SPEAKER_AMP_RESERVED));
449 } else {
450 /* power down the Class-D speaker driver */
451 rc &= readPagedReg(1, SPEAKER_AMP_ADDR, val);
453 (uint8_t)((val & (uint8_t)~SPEAKER_AMP_POWERUP) |
455 }
456
457 return rc;
458 }
459
461 bool startOutput() {
462 bool rc = true;
465 return rc;
466 }
467
469 bool stopOutput() {
470 bool rc = true;
473 return rc;
474 }
475
478
481
483 bool setOutputMute(bool mute) { return mute ? setOutputMute() : setOutputUnmute(); }
484
491 bool setOutputVolume(int vol) {
492 static const uint8_t vol_array[] = {107, 108, 110, 113, 116, 120,
493 125, 128, 132, 138, 144};
494 if (vol > OUTPUT_VOLUME_MAX || vol < OUTPUT_VOLUME_MIN) return false;
495
496 /* remove sign: 0 = 0dB .. 156 = -78dB */
497 int v = -vol;
498 uint8_t vol_val;
499 if (v > HPX_ANA_VOL_FLOOR) {
500 vol_val = HPX_ANA_VOL_FLOOR;
501 } else if (v > HPX_ANA_VOL_LOW_THRESH) {
502 size_t idx = 0;
503 size_t n = sizeof(vol_array) / sizeof(vol_array[0]);
504 while (idx < n && vol_array[idx] < (uint8_t)v) idx++;
505 vol_val = (uint8_t)(HPX_ANA_VOL_LOW_THRESH + idx + 1);
506 } else {
507 vol_val = (uint8_t)v;
508 }
509
510 bool rc = true;
513 return rc;
514 }
515
517 bool applyProperties() { return true; }
518
536 bool enableBeep(uint32_t freq_hz, uint32_t duration_ms = 500,
537 int8_t left_db = 0, int8_t right_db = 0) {
538 bool rc = true;
539 static constexpr float kTwoPi = 6.28318530717959f;
540
541 float angle = kTwoPi * (float)freq_hz / (float)current_sample_rate;
542 int16_t sin_q15 = (int16_t)(sinf(angle) * 32767.0f);
543 int16_t cos_q15 = (int16_t)(cosf(angle) * 32767.0f);
544
545 uint32_t num_samples = (duration_ms == 0)
546 ? 0xFFFFFFu
547 : (uint32_t)((uint64_t)current_sample_rate * duration_ms / 1000);
548 if (num_samples > 0xFFFFFFu) num_samples = 0xFFFFFFu;
549
550 rc &= writePagedReg(0, BEEP_SIN_MSB_ADDR, (uint8_t)(sin_q15 >> 8));
551 rc &= writePagedReg(0, BEEP_SIN_LSB_ADDR, (uint8_t)(sin_q15 & 0xFF));
552 rc &= writePagedReg(0, BEEP_COS_MSB_ADDR, (uint8_t)(cos_q15 >> 8));
553 rc &= writePagedReg(0, BEEP_COS_LSB_ADDR, (uint8_t)(cos_q15 & 0xFF));
554
555 rc &= writePagedReg(0, BEEP_LEN_MSB_ADDR, (uint8_t)((num_samples >> 16) & 0xFF));
556 rc &= writePagedReg(0, BEEP_LEN_MID_ADDR, (uint8_t)((num_samples >> 8) & 0xFF));
557 rc &= writePagedReg(0, BEEP_LEN_LSB_ADDR, (uint8_t)(num_samples & 0xFF));
558
559 rc &= writePagedReg(0, R_BEEP_GEN_ADDR, beepVolReg(right_db));
560 /* write L register last — the enable bit starts the tone */
562 (uint8_t)(BEEP_GEN_EN_BEEP | beepVolReg(left_db)));
563 return rc;
564 }
565
567 bool disableBeep() {
568 return writePagedReg(0, L_BEEP_GEN_ADDR, 0x00);
569 }
570
574 uint8_t val = 0;
575 if (!readPagedReg(0, L_BEEP_GEN_ADDR, val)) return false;
576 return (val & BEEP_GEN_EN_BEEP) != 0;
577 }
578
581 (void)input_device;
582 this->output_device = output_device;
583 return true;
584 }
585
597 output_mode = mode;
599 uint8_t drv_ctrl = (resolved == TLV320DAC310xOutputMode::Headphone)
600 ? 0x00
602 return writePagedReg(1, HEADPHONE_DRV_CTRL_ADDR, drv_ctrl);
603 }
604
606 bool setMute(bool mute) override { return setOutputMute(mute); }
607
610 bool setVolume(int volume) override {
611 volume_percent = volume < 0 ? 0 : (volume > 100 ? 100 : volume);
612 int vol = OUTPUT_VOLUME_MIN +
614 return setOutputVolume(vol);
615 }
616
617 protected:
618 uint8_t active_page = 0xFF;
619 uint32_t current_sample_rate = 44100;
624
627 static uint8_t beepVolReg(int8_t vol_db) {
628 int8_t clamped = vol_db > 2 ? (int8_t)2 : (vol_db < -61 ? (int8_t)-61 : vol_db);
629 return (uint8_t)(2 - clamped) & BEEP_VOL_MASK;
630 }
631
638
640 static uint8_t analogVolReg(uint8_t vol) {
641 return (uint8_t)((vol & HPX_ANA_VOL_MASK) | HPX_ANA_VOL_ENABLE);
642 }
643
646 switch (fmt) {
647 case I2S_LEFT:
649 case I2S_RIGHT:
651 case I2S_DSP:
653 default:
655 }
656 }
657
658 static TLV320DAC310xOsrMultiple getOsrMultiple(uint32_t sample_rate) {
659 if (sample_rate >= 192000) return TLV320DAC310xOsrMultiple::Multiple2;
660 if (sample_rate >= 96000) return TLV320DAC310xOsrMultiple::Multiple4;
662 }
663
665 bool selectPage(uint8_t page) {
666 if (active_page == page) return true;
667 if (!writeReg(PAGE_CONTROL_ADDR, page)) return false;
668 active_page = page;
669 return true;
670 }
671
673 bool writePagedReg(uint8_t page, uint8_t reg, uint8_t value) {
674 if (!selectPage(page)) return false;
675 return writeReg(reg, value);
676 }
677
679 bool readPagedReg(uint8_t page, uint8_t reg, uint8_t& value) {
680 if (!selectPage(page)) return false;
681 return readReg(reg, value);
682 }
683
685 bool updatePagedReg(uint8_t page, uint8_t reg, uint8_t mask, uint8_t value) {
686 if (!selectPage(page)) return false;
687 return updateReg(reg, mask, value);
688 }
689};
690
692
693} // namespace audio_driver
Header only C++ driver for the TLV320DAC3100 / TLV320DAC3101 audio DAC.
Definition TLV320DAC310x.h:75
static constexpr uint8_t MDAC_POWER_UP
Definition TLV320DAC310x.h:126
static constexpr uint8_t OSR_MSB_ADDR
Definition TLV320DAC310x.h:82
bool isBeepActive()
Definition TLV320DAC310x.h:573
static constexpr uint8_t MDAC_POWER_UP_MASK
Definition TLV320DAC310x.h:127
static constexpr uint8_t NDAC_POWER_UP
Definition TLV320DAC310x.h:122
static TLV320DAC310xFormat toFormat(i2s_format_t fmt)
Map the generic I2S format to the TLV320DAC310x specific format.
Definition TLV320DAC310x.h:645
static constexpr int OUTPUT_VOLUME_MAX
Definition TLV320DAC310x.h:192
static constexpr uint8_t TIMER_MCLK_DIV_ADDR
Definition TLV320DAC310x.h:117
bool setDevices(input_device_t input_device, output_device_t output_device) override
Stores the output device selection for use by configureOutput()
Definition TLV320DAC310x.h:580
static constexpr uint8_t OSR_MSB_MASK
Definition TLV320DAC310x.h:134
static constexpr uint8_t HPX_DRV_UNMUTE
Definition TLV320DAC310x.h:184
static constexpr uint32_t DAC_MOD_CLK_FREQ_MIN
Definition TLV320DAC310x.h:131
bool readPagedReg(uint8_t page, uint8_t reg, uint8_t &value)
Read a register on the given page.
Definition TLV320DAC310x.h:679
static constexpr uint8_t SOFT_RESET_ASSERT
Definition TLV320DAC310x.h:120
uint32_t current_sample_rate
Definition TLV320DAC310x.h:619
bool begin(uint32_t sample_rate=44100, uint8_t word_size=16, uint32_t mclk_freq=12000000, TLV320DAC310xFormat fmt=TLV320DAC310xFormat::I2S, bool bclk_controller=false, bool wclk_controller=false)
Initialize the codec.
Definition TLV320DAC310x.h:220
static constexpr uint8_t IF_CTRL_IFTYPE_MASK
Definition TLV320DAC310x.h:137
static constexpr uint8_t SPL_ANA_VOL_CTRL_ADDR
Definition TLV320DAC310x.h:110
bool softReset()
Soft reset of the codec.
Definition TLV320DAC310x.h:237
static constexpr uint8_t HPX_ANA_VOL_MAX
Definition TLV320DAC310x.h:178
static constexpr uint8_t HP_OUT_POP_RM_ADDR
Definition TLV320DAC310x.h:106
bool setOutputUnmute()
Unmute the output.
Definition TLV320DAC310x.h:480
static constexpr uint8_t HPL_ANA_VOL_CTRL_ADDR
Definition TLV320DAC310x.h:108
static constexpr uint8_t HPX_ANA_VOL_LOW_THRESH
Definition TLV320DAC310x.h:181
static constexpr uint8_t OUTPUT_ROUTING_HPR
Definition TLV320DAC310x.h:173
static constexpr uint8_t L_BEEP_GEN_ADDR
Definition TLV320DAC310x.h:92
static constexpr uint8_t PROC_BLK_SEL_MASK
Definition TLV320DAC310x.h:146
static constexpr int OUTPUT_VOLUME_MIN
Definition TLV320DAC310x.h:193
bool setOutputMute()
Mute the output (DAC channel mute, output stage stays powered)
Definition TLV320DAC310x.h:477
bool enableBeep(uint32_t freq_hz, uint32_t duration_ms=500, int8_t left_db=0, int8_t right_db=0)
Start the hardware sine-wave beep generator.
Definition TLV320DAC310x.h:536
static constexpr uint8_t VOL_CTRL_ADDR
Definition TLV320DAC310x.h:89
static constexpr uint8_t HEADPHONE_DRV_ADDR
Definition TLV320DAC310x.h:104
uint8_t active_page
0xFF forces a page select on first access
Definition TLV320DAC310x.h:618
static constexpr uint8_t MDAC_DIV_MASK
Definition TLV320DAC310x.h:128
static constexpr uint8_t NDAC_DIV_MASK
Definition TLV320DAC310x.h:124
static constexpr uint8_t VOL_MICDET_VOL_CTRL_PIN
Definition TLV320DAC310x.h:158
bool setMute(bool mute) override
Mutes/unmutes the output.
Definition TLV320DAC310x.h:606
static constexpr uint8_t SPEAKER_AMP_POWERUP
Definition TLV320DAC310x.h:164
TLV320DAC310xOutputMode output_mode
HP driver impedance mode, applied by configureOutput() and setOutputImpedance()
Definition TLV320DAC310x.h:623
bool setOutputImpedance(TLV320DAC310xOutputMode mode)
Set the HP output driver impedance mode and apply it immediately to register 44.
Definition TLV320DAC310x.h:596
static constexpr uint8_t NDAC_DIV_ADDR
Definition TLV320DAC310x.h:80
static constexpr uint8_t BEEP_LEN_MID_ADDR
Definition TLV320DAC310x.h:95
static constexpr uint8_t HPX_ANA_VOL_ENABLE
Definition TLV320DAC310x.h:176
output_device_t output_device
Output device selection set via setDevices(), used by configureOutput()
Definition TLV320DAC310x.h:621
bool disableBeep()
Stop the beep generator immediately by clearing the enable bit.
Definition TLV320DAC310x.h:567
static constexpr uint8_t BEEP_COS_LSB_ADDR
Definition TLV320DAC310x.h:100
static constexpr uint8_t SOFT_RESET_ADDR
Definition TLV320DAC310x.h:79
static constexpr uint8_t BCLK_DIV_MASK
Definition TLV320DAC310x.h:144
static constexpr uint8_t SPK_DRV_GAIN_CTRL_ADDR
Definition TLV320DAC310x.h:113
static constexpr uint8_t VOL_CTRL_MUTE_DEFAULT
Definition TLV320DAC310x.h:153
static constexpr uint8_t DATA_PATH_SETUP_ADDR
Definition TLV320DAC310x.h:88
static constexpr uint8_t OUTPUT_ROUTING_MIXERL
Definition TLV320DAC310x.h:172
static constexpr uint8_t OUTPUT_ROUTING_HPL
Definition TLV320DAC310x.h:171
bool updatePagedReg(uint8_t page, uint8_t reg, uint8_t mask, uint8_t value)
Read-Modify-Write of a register on the given page.
Definition TLV320DAC310x.h:685
bool configureClocks(uint32_t mclk_freq, uint32_t sample_rate, bool bclk_controller=false, uint8_t word_size=16)
Configure NDAC/MDAC/OSR dividers (and optionally BCLK divider) to derive the DAC processing/modulator...
Definition TLV320DAC310x.h:243
static constexpr uint8_t SPK_DRV_UNMUTE
Definition TLV320DAC310x.h:167
static constexpr uint8_t BCLK_DIV_POWER_UP_MASK
Definition TLV320DAC310x.h:143
static constexpr uint8_t VOL_CTRL_UNMUTE_DEFAULT
Definition TLV320DAC310x.h:152
TLV320DAC310xOutputMode resolveOutputMode() const
Resolve Auto → Headphone when LINE1 is selected, LineOut otherwise.
Definition TLV320DAC310x.h:633
static constexpr uint8_t TIMER_MCLK_DIV_EN_EXT
Definition TLV320DAC310x.h:188
static constexpr uint8_t HP_OUT_POP_RM_ENABLE
Definition TLV320DAC310x.h:169
static constexpr uint8_t OSR_LSB_ADDR
Definition TLV320DAC310x.h:83
static constexpr uint8_t L_DIG_VOL_CTRL_ADDR
Definition TLV320DAC310x.h:90
static constexpr uint32_t DAC_MOD_CLK_FREQ_MAX
Definition TLV320DAC310x.h:132
bool startOutput()
Power up & unmute the DAC channels and start the output.
Definition TLV320DAC310x.h:461
static constexpr uint8_t VOL_MICDET_ADC_CTRL_ADDR
Definition TLV320DAC310x.h:101
TLV320DAC310x()
Definition TLV320DAC310x.h:195
bool setOutputVolume(int vol)
Set the headphone output (analog) volume.
Definition TLV320DAC310x.h:491
bool setOutputMute(bool mute)
Mute / unmute the output.
Definition TLV320DAC310x.h:483
static constexpr uint8_t BEEP_GEN_EN_BEEP
Definition TLV320DAC310x.h:155
static constexpr uint8_t SPEAKER_AMP_RESERVED
Definition TLV320DAC310x.h:165
static constexpr uint8_t BCLK_DIV_POWER_UP
Definition TLV320DAC310x.h:142
static constexpr uint8_t BEEP_SIN_MSB_ADDR
Definition TLV320DAC310x.h:97
static constexpr uint8_t BEEP_COS_MSB_ADDR
Definition TLV320DAC310x.h:99
static constexpr uint8_t SPEAKER_AMP_ADDR
Definition TLV320DAC310x.h:105
static constexpr uint8_t IF_CTRL1_ADDR
Definition TLV320DAC310x.h:84
static constexpr uint8_t HEADPHONE_DRV_CM_MASK
Definition TLV320DAC310x.h:161
static constexpr uint8_t PROC_BLK_SEL_ADDR
Definition TLV320DAC310x.h:87
static constexpr uint8_t MDAC_DIV_ADDR
Definition TLV320DAC310x.h:81
static constexpr uint8_t HEADPHONE_DRV_POWERUP
Definition TLV320DAC310x.h:160
static constexpr uint8_t IF_CTRL_BCLK_OUT
Definition TLV320DAC310x.h:139
bool begin(uint32_t sample_rate, uint8_t bits, codec_mode_t mode, i2s_format_t fmt, bool is_master, uint8_t channels) override
Definition TLV320DAC310x.h:200
static constexpr uint8_t HEADPHONE_DRV_CTRL_ADDR
Definition TLV320DAC310x.h:114
static constexpr uint8_t OSR_LSB_MASK
Definition TLV320DAC310x.h:135
static constexpr uint8_t R_BEEP_GEN_ADDR
Definition TLV320DAC310x.h:93
static constexpr uint8_t HPL_DRV_GAIN_CTRL_ADDR
Definition TLV320DAC310x.h:111
bool applyProperties()
no-op, nothing is cached that needs re-applying
Definition TLV320DAC310x.h:517
static constexpr uint8_t IF_CTRL_WLEN_MASK
Definition TLV320DAC310x.h:138
bool selectPage(uint8_t page)
Select the active register page (cached, only writes if changed)
Definition TLV320DAC310x.h:665
static constexpr uint8_t OVF_FLAG_ADDR
Definition TLV320DAC310x.h:86
static constexpr uint8_t IF_CTRL_WCLK_OUT
Definition TLV320DAC310x.h:140
static constexpr uint8_t BEEP_LEN_MSB_ADDR
Definition TLV320DAC310x.h:94
static constexpr uint8_t HPX_ANA_VOL_DEFAULT
Definition TLV320DAC310x.h:179
static constexpr uint8_t OUTPUT_ROUTING_MIXERR
Definition TLV320DAC310x.h:174
static constexpr uint32_t DAC_PROC_CLK_FREQ_MAX
Definition TLV320DAC310x.h:130
static constexpr uint8_t OUTPUT_ROUTING_ADDR
Definition TLV320DAC310x.h:107
static constexpr uint8_t TIMER_MCLK_DIV_MASK
Definition TLV320DAC310x.h:189
static constexpr uint8_t BEEP_VOL_MASK
Definition TLV320DAC310x.h:156
static constexpr uint8_t DAC_LR_POWERUP_DEFAULT
Definition TLV320DAC310x.h:148
static constexpr uint8_t BEEP_LEN_LSB_ADDR
Definition TLV320DAC310x.h:96
static constexpr uint8_t HEADPHONE_DRV_LINEOUT
Definition TLV320DAC310x.h:186
bool configureDai(uint8_t word_size=16, TLV320DAC310xFormat fmt=TLV320DAC310xFormat::I2S, bool bclk_controller=false, bool wclk_controller=false)
Configure the digital audio interface (format, word length, clock directions)
Definition TLV320DAC310x.h:316
static constexpr uint8_t HPR_ANA_VOL_CTRL_ADDR
Definition TLV320DAC310x.h:109
bool stopOutput()
Mute and power down the DAC channels.
Definition TLV320DAC310x.h:469
static constexpr uint8_t HEADPHONE_DRV_RESERVED
Definition TLV320DAC310x.h:162
bool setVolume(int volume) override
Definition TLV320DAC310x.h:610
static constexpr uint8_t DRC_CTRL1_ADDR
Definition TLV320DAC310x.h:91
static constexpr uint8_t BCLK_DIV_ADDR
Definition TLV320DAC310x.h:85
bool writePagedReg(uint8_t page, uint8_t reg, uint8_t value)
Write a register on the given page.
Definition TLV320DAC310x.h:673
static constexpr uint8_t DAC_LR_POWERDN_DEFAULT
Definition TLV320DAC310x.h:150
bool configureOutput(TLV320DAC310xCmVoltage cm=TLV320DAC310xCmVoltage::V1P65)
Configure the output path(s) selected via setDevices(): common mode voltage, pop removal,...
Definition TLV320DAC310x.h:370
static constexpr uint8_t HPX_ANA_VOL_MASK
Definition TLV320DAC310x.h:177
static constexpr uint8_t PAGE_CONTROL_ADDR
Definition TLV320DAC310x.h:78
static constexpr uint8_t HPR_DRV_GAIN_CTRL_ADDR
Definition TLV320DAC310x.h:112
static uint8_t analogVolReg(uint8_t vol)
Build the register value for the HPx analog volume control registers.
Definition TLV320DAC310x.h:640
static constexpr uint8_t HPX_ANA_VOL_MIN
Definition TLV320DAC310x.h:180
static constexpr uint8_t NDAC_POWER_UP_MASK
Definition TLV320DAC310x.h:123
static constexpr uint8_t HPX_ANA_VOL_FLOOR
Definition TLV320DAC310x.h:182
static uint8_t beepVolReg(int8_t vol_db)
Definition TLV320DAC310x.h:627
static TLV320DAC310xOsrMultiple getOsrMultiple(uint32_t sample_rate)
Definition TLV320DAC310x.h:658
static constexpr uint8_t BEEP_SIN_LSB_ADDR
Definition TLV320DAC310x.h:98
bool configureFilters(uint32_t sample_rate)
Select the decimation filter / processing block based on the sample rate.
Definition TLV320DAC310x.h:347
Common parent class for codec drivers that have been ported from the Zephyr RTOS audio driver impleme...
Definition ZephyrDriverCommon.h:22
uint8_t i2c_addr
Definition ZephyrDriverCommon.h:87
bool updateReg(uint8_t reg, uint8_t mask, uint8_t value)
Read-Modify-Write of a single byte register.
Definition ZephyrDriverCommon.h:110
int volume_percent
Last volume (in %) provided to setVolume()
Definition ZephyrDriverCommon.h:89
bool readReg(uint8_t reg, uint8_t &value, bool stopBit=true)
Reads a single byte from an 8 bit register address.
Definition ZephyrDriverCommon.h:100
bool writeReg(uint8_t reg, uint8_t value)
Writes a single byte to an 8 bit register address.
Definition ZephyrDriverCommon.h:94
Namespace for audio driver components.
Definition AudioBoard.h:5
TLV320DAC310xProcBlock
Processing block / decimation filter selection (see codec_configure_filters)
Definition TLV320DAC310x.h:43
@ DecimationB
PRB_P10, used for PCM rates >= 96kHz.
@ DecimationC
PRB_P18, used for PCM rates >= 192kHz.
@ DecimationA
PRB_P25, used for PCM rates < 96kHz.
TLV320DAC310xOsrMultiple
OSR multiple, determined from the PCM sample rate.
Definition TLV320DAC310x.h:50
input_device_t
Definition DriverCommon.h:170
TLV320DAC310xOutputMode
HP output driver impedance / bias mode (Page 1 / Register 44 D2-D1)
Definition TLV320DAC310x.h:36
@ Auto
Derive from output_device: LINE1 → Headphone, otherwise LineOut.
@ Headphone
Low-impedance headphone driver mode, optimised for 16–32 Ω loads.
@ LineOut
High-impedance line-out driver mode, optimised for ≥10 kΩ loads.
codec_mode_t
Definition DriverCommon.h:290
output_device_t
Definition DriverCommon.h:186
@ DAC_OUTPUT_LINE1
Definition DriverCommon.h:188
@ DAC_OUTPUT_ALL
Definition DriverCommon.h:190
@ DAC_OUTPUT_LINE2
Definition DriverCommon.h:189
TLV320DAC310xWordLength
Word length of the digital audio interface.
Definition TLV320DAC310x.h:28
TLV320DAC310xCmVoltage
Headphone driver common mode voltage.
Definition TLV320DAC310x.h:57
i2s_format_t
Definition DriverCommon.h:250
@ I2S_RIGHT
Definition DriverCommon.h:253
@ I2S_DSP
Definition DriverCommon.h:254
@ I2S_LEFT
Definition DriverCommon.h:252
TLV320DAC310xFormat
Digital audio interface format.
Definition TLV320DAC310x.h:20