arduino-audio-driver
Loading...
Searching...
No Matches
WM8962.h
Go to the documentation of this file.
1
8#pragma once
9
11
12namespace audio_driver {
13
15enum class WM8962Protocol {
16 RightJustified = 0x0,
17 LeftJustified = 0x1,
18 I2S = 0x2,
19 PCMB = 0x3 | 0x10,
20 PCMA = 0x4 - 1,
21};
22
25 Input1 = 8,
26 Input2 = 4,
27 Input3 = 2,
28 Input4 = 1,
29};
30
32enum class WM8962Channel {
37 All,
38};
39
41enum class WM8962Sequence : uint16_t {
44 ChipPowerDown = 0x9B,
45 SpeakerSleep = 0xE4,
46 SpeakerWake = 0xE8,
47};
48
60class WM8962 : public ZephyrDriverCommon {
61 public:
62 // ---- Register addresses (16 bit) ----
63 enum Reg : uint16_t {
64 REG_LINVOL = 0x00,
65 REG_RINVOL = 0x01,
66 REG_LOUT1 = 0x02,
67 REG_ROUT1 = 0x03,
68 REG_CLOCK1 = 0x04,
71 REG_IFACE0 = 0x07,
72 REG_CLOCK2 = 0x08,
73 REG_IFACE1 = 0x09,
74 REG_LDAC = 0x0A,
75 REG_RDAC = 0x0B,
76 REG_IFACE2 = 0x0E,
77 REG_RESET = 0x0F,
78 REG_3D = 0x10,
79 REG_ALC1 = 0x11,
80 REG_ALC2 = 0x12,
81 REG_ALC3 = 0x13,
82 REG_NOISEG = 0x14,
83 REG_LADC = 0x15,
84 REG_RADC = 0x16,
87 REG_POWER1 = 0x19,
88 REG_POWER2 = 0x1A,
90 REG_APOP1 = 0x1C,
91 REG_APOP2 = 0x1D,
99 REG_LOUT2 = 0x28,
100 REG_ROUT2 = 0x29,
101 REG_TEMP = 0x2F,
105 REG_CLK4 = 0x38,
121 REG_PLL2 = 0x81,
129 };
130
131 static constexpr uint16_t WSEQ_ENA = 0x20;
132 static constexpr uint16_t WSEQ_DONE_EINT_MASK = 0x80;
133
134 static constexpr uint16_t L_CH_MUTE_MASK = 2;
135 static constexpr uint16_t R_CH_MUTE_MASK = 1;
136
137 static constexpr uint16_t CLOCK2_BCLK_DIV_MASK = 0x0F;
138
139 static constexpr uint16_t IFACE0_FORMAT_MASK = 0x13;
140 static constexpr uint16_t IFACE0_WL_MASK = 0x0C;
141 static constexpr uint16_t IFACE0_WL_SHIFT = 0x02;
142 static constexpr uint16_t IFACE0_WL_16BITS = 0x00;
143 static constexpr uint16_t IFACE0_WL_20BITS = 0x01;
144 static constexpr uint16_t IFACE0_WL_24BITS = 0x02;
145 static constexpr uint16_t IFACE0_WL_32BITS = 0x03;
146
147 // ---- Output register bit masks (REG_LOUT1/ROUT1/LOUT2/ROUT2) ----
148 static constexpr uint16_t REGMASK_OUT_VU = 0b100000000;
149 static constexpr uint16_t REGMASK_OUT_ZC = 0b010000000;
150 static constexpr uint16_t REGMASK_OUT_VOL = 0b001111111;
151
152 // ---- Input register bit masks (REG_LINVOL/RINVOL) ----
153 static constexpr uint16_t REGMASK_IN_VU = 0b100000000;
154 static constexpr uint16_t REGMASK_IN_MUTE = 0b010000000;
155 static constexpr uint16_t REGMASK_IN_ZC = 0b001000000;
156 static constexpr uint16_t REGMASK_IN_VOLUME = 0b000111111;
157
158 // ---- Default volumes ----
159 static constexpr uint16_t ADC_MAX_VOLUME_VALUE = 0xFF;
160 static constexpr uint16_t DAC_MAX_VOLUME_VALUE = 0xFF;
161 static constexpr uint16_t HEADPHONE_MAX_VOLUME_VALUE = 0x7F;
162 static constexpr uint16_t HEADPHONE_MIN_VOLUME_VALUE = 0x2F;
163 static constexpr uint16_t LINEIN_MAX_VOLUME_VALUE = 0x3F;
164 static constexpr uint16_t SPEAKER_MAX_VOLUME_VALUE = 0x7F;
165 static constexpr uint16_t SPEAKER_MIN_VOLUME_VALUE = 0x2F;
166
167 static constexpr uint16_t ADC_DEFAULT_VOLUME_VALUE = 0x1C0;
168 static constexpr uint16_t DAC_DEFAULT_VOLUME_VALUE = 0x1C0;
169 static constexpr uint16_t HEADPHONE_DEFAULT_VOLUME_VALUE = 0x179;
170 static constexpr uint16_t LINEIN_DEFAULT_VOLUME_VALUE = 0x12D;
171 static constexpr uint16_t SPEAKER_DEFAULT_VOLUME_VALUE = 0x179;
172
173 WM8962() { i2c_addr = 0x1A; } // 0x34 >> 1
174
190 bool begin(uint32_t sample_rate, uint8_t bits) {
191 return begin(WM8962Protocol::I2S, sample_rate, bits);
192 }
193
198 bool begin(uint32_t sample_rate, uint8_t bits, codec_mode_t mode,
199 i2s_format_t fmt, bool is_master, uint8_t channels) override {
200 (void)is_master;
201 (void)channels;
203 switch (fmt) {
204 case I2S_LEFT:
206 break;
207 case I2S_RIGHT:
209 break;
210 case I2S_DSP:
211 protocol = WM8962Protocol::PCMA;
212 break;
213 default:
214 protocol = WM8962Protocol::I2S;
215 break;
216 }
217 return begin(protocol, sample_rate, bits, 256, mode & CODEC_MODE_DECODE,
218 mode & CODEC_MODE_ENCODE);
219 }
220
222 uint32_t sample_rate = 44100, uint8_t word_size = 16,
223 uint32_t mclk_to_fs_ratio = 256, bool playback = true,
224 bool capture = true) {
225 bool rc = true;
226
227 rc &= softReset();
228
229 /* disable internal osc/FLL2/FLL3/FLL */
230 rc &= writeRegWide(REG_PLL2, 0);
231 rc &= updateRegWide(REG_FLL_CTRL_1, 1, 0);
232 rc &= writeRegWide(REG_CLOCK2, 0x9E4);
233 rc &= writeRegWide(REG_POWER1, 0x1FE);
234 rc &= writeRegWide(REG_POWER2, 0x1E0);
235
236 /* enable system clock */
237 rc &= updateRegWide(REG_CLOCK2, 0x20, 0x20);
238
242
243 rc &= setProtocol(protocol);
244
245 /* ADC volume, 0dB */
248 /* Digital DAC volume, -15.5dB */
251 /* speaker volume 6dB */
254 /* input PGA volume */
257 /* Headphone volume */
260
261 rc &= setAudioFormat(sample_rate, word_size, mclk_to_fs_ratio);
262
263 if (playback) rc &= configureOutput();
264 if (capture) rc &= configureInput();
265
266 return rc;
267 }
268
270 bool softReset() { return writeRegWide(REG_RESET, 0x6243); }
271
274 return updateRegWide(REG_IFACE0, IFACE0_FORMAT_MASK, (uint16_t)protocol);
275 }
276
286 bool setAudioFormat(uint32_t sample_rate, uint8_t word_size = 16,
287 uint32_t mclk_to_fs_ratio = 256) {
288 bool rc = true;
289 uint16_t wl_val;
290
291 switch (word_size) {
292 case 16:
293 wl_val = IFACE0_WL_16BITS;
294 break;
295 case 20:
296 wl_val = IFACE0_WL_20BITS;
297 break;
298 case 24:
299 wl_val = IFACE0_WL_24BITS;
300 break;
301 case 32:
302 wl_val = IFACE0_WL_32BITS;
303 break;
304 default:
305 return false;
306 }
308 (uint16_t)(wl_val << IFACE0_WL_SHIFT));
309
310 uint16_t addctl3_val;
311 switch (sample_rate) {
312 case 8000:
313 addctl3_val = 0x15;
314 break;
315 case 11025:
316 addctl3_val = 0x04;
317 break;
318 case 12000:
319 addctl3_val = 0x14;
320 break;
321 case 16000:
322 addctl3_val = 0x13;
323 break;
324 case 22050:
325 addctl3_val = 0x02;
326 break;
327 case 24000:
328 addctl3_val = 0x12;
329 break;
330 case 32000:
331 addctl3_val = 0x11;
332 break;
333 case 44100:
334 addctl3_val = 0x00;
335 break;
336 case 48000:
337 addctl3_val = 0x10;
338 break;
339 case 88200:
340 addctl3_val = 0x06;
341 break;
342 case 96000:
343 addctl3_val = 0x16;
344 break;
345 default:
346 return false;
347 }
348 rc &= writeRegWide(REG_ADDCTL3, addctl3_val);
349
350 uint16_t clk4_val;
351 switch (mclk_to_fs_ratio) {
352 case 64:
353 clk4_val = 0x00;
354 break;
355 case 128:
356 clk4_val = 0x02;
357 break;
358 case 192:
359 clk4_val = 0x04;
360 break;
361 case 256:
362 clk4_val = 0x06;
363 break;
364 case 384:
365 clk4_val = 0x08;
366 break;
367 case 512:
368 clk4_val = 0x0A;
369 break;
370 case 768:
371 clk4_val = 0x0C;
372 break;
373 case 1024:
374 clk4_val = 0x0E;
375 break;
376 case 1536:
377 clk4_val = 0x12;
378 break;
379 case 3072:
380 clk4_val = 0x14;
381 break;
382 case 6144:
383 clk4_val = 0x16;
384 break;
385 default:
386 return false;
387 }
388 rc &= writeRegWide(REG_CLK4, clk4_val);
389
390 return rc;
391 }
392
394 bool setOutputVolume(uint8_t volume, WM8962Channel channel = WM8962Channel::All) {
395 if (volume > REGMASK_OUT_VOL) volume = REGMASK_OUT_VOL;
396 const uint16_t val = (uint16_t)((1U << 8U) | (volume & REGMASK_OUT_VOL));
397 const uint16_t mask = REGMASK_OUT_VU | REGMASK_OUT_ZC | REGMASK_OUT_VOL;
398 return updateOutput(channel, val, mask);
399 }
400
402 bool setOutputMute(bool mute, WM8962Channel channel = WM8962Channel::All) {
403 bool rc = true;
404 switch (channel) {
406 rc &= updateRegWide(REG_CLASSD1, L_CH_MUTE_MASK, mute ? 2 : 0);
407 break;
409 rc &= updateRegWide(REG_CLASSD1, R_CH_MUTE_MASK, mute ? 1 : 0);
410 break;
412 rc &= updateRegWide(REG_POWER2, L_CH_MUTE_MASK, mute ? 2 : 0);
413 break;
415 rc &= updateRegWide(REG_POWER2, R_CH_MUTE_MASK, mute ? 1 : 0);
416 break;
417 case WM8962Channel::All: {
418 uint16_t val = mute ? 3 : 0;
421 break;
422 }
423 default:
424 return false;
425 }
426 return rc;
427 }
428
430 bool setVolume(int volume) override {
431 volume_percent = volume < 0 ? 0 : (volume > 100 ? 100 : volume);
432 uint8_t vol = (uint8_t)((volume_percent * REGMASK_OUT_VOL) / 100);
434 }
435
437 bool setMute(bool mute) override { return setOutputMute(mute, WM8962Channel::All); }
438
441 (void)input_device;
442 this->output_device = output_device;
443 return true;
444 }
445
448 bool setActive(codec_mode_t mode) override {
451 return rc;
452 }
453
455 bool setInputVolume(uint8_t volume, WM8962Channel channel = WM8962Channel::All) {
456 if (volume > REGMASK_IN_VOLUME) volume = REGMASK_IN_VOLUME;
457 const uint16_t val = (uint16_t)(REGMASK_IN_VU | (volume & REGMASK_IN_VOLUME));
458 const uint16_t mask = (uint16_t)(REGMASK_IN_VU | REGMASK_IN_VOLUME);
459 return updateInput(channel, val, mask);
460 }
461
463 bool setInputVolume(int volume) override {
464 input_volume_percent = volume < 0 ? 0 : (volume > 100 ? 100 : volume);
465 uint8_t vol = (uint8_t)((input_volume_percent * REGMASK_IN_VOLUME) / 100);
467 }
468
469
471 bool isInputVolumeSupported() override { return true; }
472
474 bool setInputMute(bool mute, WM8962Channel channel = WM8962Channel::All) {
475 const uint16_t val =
476 (uint16_t)(REGMASK_IN_VU | ((mute ? 1U : 0U) << 7U));
477 const uint16_t mask = (uint16_t)(REGMASK_IN_VU | REGMASK_IN_MUTE);
478 return updateInput(channel, val, mask);
479 }
480
486 uint16_t reg;
487 switch (channel) {
489 reg = REG_LEFT_INPUT_PGA;
490 break;
493 break;
494 default:
495 return false;
496 }
497 return writeRegWide(reg, (uint16_t)source);
498 }
499
504 bool routeOutput(uint16_t mixer_value, WM8962Channel channel) {
505 uint16_t reg;
506 switch (channel) {
509 break;
512 break;
515 break;
518 break;
519 default:
520 return false;
521 }
522 return writeRegWide(reg, mixer_value);
523 }
524
527 bool rc = true;
530 return rc;
531 }
532
550
553 bool rc = true;
556
557 /* Input MIXER source: route input PGA to both input mixers */
558 rc &= writeRegWide(REG_INPUTMIX, ((1U & 7U) << 3U) | (1U & 7U));
559 /* Input MIXER enable */
561
564 rc &= setInputMute(false, WM8962Channel::All);
565 return rc;
566 }
567
573 uint32_t delay_remaining_ms;
574 switch (id) {
576 delay_remaining_ms = 93;
577 break;
579 delay_remaining_ms = 75;
580 break;
582 delay_remaining_ms = 32;
583 break;
586 default:
587 delay_remaining_ms = 2;
588 break;
589 }
590
591 bool rc = true;
593 rc &= writeRegWide(REG_WRITE_SEQ_CTRL_2, (uint16_t)id);
594
595 uint16_t status = 1;
596 while (delay_remaining_ms > 0) {
597 if (!readRegWide(REG_WRITE_SEQ_CTRL_3, status)) break;
598 if ((status & 1U) == 0U) break;
599 delayMs(1);
600 delay_remaining_ms--;
601 }
602 return rc && (status & 1U) == 0U;
603 }
604
605 protected:
608
611 bool writeRegWide(uint16_t reg, uint16_t value) {
612 assert(wire != nullptr);
613 uint8_t data[4] = {
614 (uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF),
615 (uint8_t)(value >> 8), (uint8_t)(value & 0xFF),
616 };
617 return i2c_bus_write_bytes(wire, i2c_addr, data, 2, data + 2, 2) == 0;
618 }
619
622 bool readRegWide(uint16_t reg, uint16_t& value) {
623 assert(wire != nullptr);
624 uint8_t reg_bytes[2] = {(uint8_t)(reg >> 8), (uint8_t)(reg & 0xFF)};
625 uint8_t data[2] = {0, 0};
626 if (i2c_bus_read_bytes(wire, i2c_addr, reg_bytes, 2, data, 2) != 0)
627 return false;
628 value = ((uint16_t)data[0] << 8) | data[1];
629 return true;
630 }
631
633 bool updateRegWide(uint16_t reg, uint16_t mask, uint16_t value) {
634 uint16_t old = 0;
635 if (!readRegWide(reg, old)) return false;
636 uint16_t updated = (old & ~mask) | (value & mask);
637 if (updated == old) return true;
638 return writeRegWide(reg, updated);
639 }
640
641 bool updateOutput(WM8962Channel channel, uint16_t val, uint16_t mask) {
642 bool rc = true;
643 switch (channel) {
645 return updateRegWide(REG_LOUT2, mask, val);
647 return updateRegWide(REG_ROUT2, mask, val);
649 return updateRegWide(REG_LOUT1, mask, val);
651 return updateRegWide(REG_ROUT1, mask, val);
653 rc &= updateRegWide(REG_LOUT1, mask, val);
654 rc &= updateRegWide(REG_ROUT1, mask, val);
655 rc &= updateRegWide(REG_LOUT2, mask, val);
656 rc &= updateRegWide(REG_ROUT2, mask, val);
657 return rc;
658 default:
659 return false;
660 }
661 }
662
663 bool updateInput(WM8962Channel channel, uint16_t val, uint16_t mask) {
664 bool rc = true;
665 switch (channel) {
667 return updateRegWide(REG_LINVOL, mask, val);
669 return updateRegWide(REG_RINVOL, mask, val);
671 rc &= updateRegWide(REG_LINVOL, mask, val);
672 rc &= updateRegWide(REG_RINVOL, mask, val);
673 return rc;
674 default:
675 return false;
676 }
677 }
678};
679
680} // namespace audio_driver
Header only C++ driver for the WM8962 audio codec.
Definition WM8962.h:60
bool updateOutput(WM8962Channel channel, uint16_t val, uint16_t mask)
Definition WM8962.h:641
Reg
Definition WM8962.h:63
@ REG_ADDCTL4
Definition WM8962.h:102
@ REG_INT_STATUS_2
Definition WM8962.h:128
@ REG_IFACE1
Definition WM8962.h:73
@ REG_FLL_CTRL_6
Definition WM8962.h:125
@ REG_DACCTL2
Definition WM8962.h:70
@ REG_FLL_CTRL_1
Definition WM8962.h:122
@ REG_LDAC
Definition WM8962.h:74
@ REG_IFACE2
Definition WM8962.h:76
@ REG_DC_SERVO_0
Definition WM8962.h:106
@ REG_CHARGE_PUMP_1
Definition WM8962.h:109
@ REG_LEFT_SPEAKER_MIXER_VOLUME
Definition WM8962.h:119
@ REG_LOUT2
Definition WM8962.h:99
@ REG_RDAC
Definition WM8962.h:75
@ REG_ALC1
Definition WM8962.h:79
@ REG_FLL_CTRL_3
Definition WM8962.h:124
@ REG_POWER1
Definition WM8962.h:87
@ REG_TEMP
Definition WM8962.h:101
@ REG_LEFT_HEADPHONE_MIXER_VOLUME
Definition WM8962.h:115
@ REG_ALC3
Definition WM8962.h:81
@ REG_LEFT_INPUT_PGA
Definition WM8962.h:96
@ REG_ADDCTL1
Definition WM8962.h:85
@ REG_LINVOL
Definition WM8962.h:64
@ REG_FLL_CTRL_8
Definition WM8962.h:127
@ REG_RADC
Definition WM8962.h:84
@ REG_LADC
Definition WM8962.h:83
@ REG_ADDCTL3
Definition WM8962.h:89
@ REG_CLASSD1
Definition WM8962.h:103
@ REG_POWER2
Definition WM8962.h:88
@ REG_MONOMIX2
Definition WM8962.h:98
@ REG_IFACE0
Definition WM8962.h:71
@ REG_RIGHT_SPEAKER_MIXER_VOLUME
Definition WM8962.h:120
@ REG_LEFT_SPEAKER_MIXER
Definition WM8962.h:117
@ REG_CLASSD3
Definition WM8962.h:104
@ REG_LOUT1
Definition WM8962.h:66
@ REG_ROUT2
Definition WM8962.h:100
@ REG_FLL_CTRL_7
Definition WM8962.h:126
@ REG_PLL2
Definition WM8962.h:121
@ REG_APOP2
Definition WM8962.h:91
@ REG_INPUTMIX
Definition WM8962.h:95
@ REG_RIGHT_INPUT_PGA
Definition WM8962.h:97
@ REG_NOISEG
Definition WM8962.h:82
@ REG_RIGHT_SPEAKER_MIXER
Definition WM8962.h:118
@ REG_RIGHT_HEADPHONE_MIXER
Definition WM8962.h:114
@ REG_RIGHT_HEADPHONE_MIXER_VOLUME
Definition WM8962.h:116
@ REG_CLOCK1
Definition WM8962.h:68
@ REG_DC_SERVO_1
Definition WM8962.h:107
@ REG_RESET
Definition WM8962.h:77
@ REG_ADDCTL2
Definition WM8962.h:86
@ REG_ALC2
Definition WM8962.h:80
@ REG_WRITE_SEQ_CTRL_3
Definition WM8962.h:112
@ REG_WRITE_SEQ_CTRL_2
Definition WM8962.h:111
@ REG_LEFT_HEADPHONE_MIXER
Definition WM8962.h:113
@ REG_ANALOG_HP_0
Definition WM8962.h:108
@ REG_WRITE_SEQ_CTRL_1
Definition WM8962.h:110
@ REG_CLOCK2
Definition WM8962.h:72
@ REG_CLK4
Definition WM8962.h:105
@ REG_DACCTL1
Definition WM8962.h:69
@ REG_3D
Definition WM8962.h:78
@ REG_APOP1
Definition WM8962.h:90
@ REG_LINPATH
Definition WM8962.h:93
@ REG_RINPATH
Definition WM8962.h:94
@ REG_RINVOL
Definition WM8962.h:65
@ REG_INPUT_MIXER_1
Definition WM8962.h:92
@ REG_FLL_CTRL_2
Definition WM8962.h:123
@ REG_ROUT1
Definition WM8962.h:67
static constexpr uint16_t LINEIN_MAX_VOLUME_VALUE
Definition WM8962.h:163
bool setDevices(input_device_t input_device, output_device_t output_device) override
Stores the output device selection for use by configureOutput()
Definition WM8962.h:440
bool begin(uint32_t sample_rate, uint8_t bits)
Initialize the codec: soft reset, power up the analog/digital blocks, run the built-in write sequence...
Definition WM8962.h:190
static constexpr uint16_t IFACE0_WL_MASK
Definition WM8962.h:140
static constexpr uint16_t HEADPHONE_MIN_VOLUME_VALUE
Definition WM8962.h:162
static constexpr uint16_t SPEAKER_MAX_VOLUME_VALUE
Definition WM8962.h:164
bool routeOutput(uint16_t mixer_value, WM8962Channel channel)
Select the output mixer source register for the given channel (the raw mixer-enable value is written ...
Definition WM8962.h:504
bool setAudioFormat(uint32_t sample_rate, uint8_t word_size=16, uint32_t mclk_to_fs_ratio=256)
Configure word size, sysclk/sample-rate divider (REG_ADDCTL3) and bit-clock divider (REG_CLK4 = syscl...
Definition WM8962.h:286
bool softReset()
Soft reset of the codec (writes 0x6243 to REG_RESET)
Definition WM8962.h:270
bool isInputVolumeSupported() override
Returns true: the input volume is supported.
Definition WM8962.h:471
static constexpr uint16_t L_CH_MUTE_MASK
Definition WM8962.h:134
bool configureInput()
Configure the default input path: route input1/input3, default volume, unmuted.
Definition WM8962.h:552
bool setMute(bool mute) override
Mutes/unmutes all outputs.
Definition WM8962.h:437
static constexpr uint16_t WSEQ_ENA
Definition WM8962.h:131
WM8962()
Definition WM8962.h:173
bool setInputMute(bool mute, WM8962Channel channel=WM8962Channel::All)
Mute / unmute the input for the given channel(s)
Definition WM8962.h:474
bool updateInput(WM8962Channel channel, uint16_t val, uint16_t mask)
Definition WM8962.h:663
static constexpr uint16_t SPEAKER_MIN_VOLUME_VALUE
Definition WM8962.h:165
output_device_t output_device
Output device selection set via setDevices(), used by configureOutput()
Definition WM8962.h:607
static constexpr uint16_t DAC_MAX_VOLUME_VALUE
Definition WM8962.h:160
bool configureOutput()
Definition WM8962.h:536
static constexpr uint16_t REGMASK_IN_ZC
Definition WM8962.h:155
static constexpr uint16_t REGMASK_IN_VOLUME
Definition WM8962.h:156
static constexpr uint16_t REGMASK_OUT_VU
Definition WM8962.h:148
static constexpr uint16_t REGMASK_OUT_ZC
Definition WM8962.h:149
static constexpr uint16_t DAC_DEFAULT_VOLUME_VALUE
Definition WM8962.h:168
bool setOutputMute(bool mute, WM8962Channel channel=WM8962Channel::All)
Mute / unmute the output for the given channel(s)
Definition WM8962.h:402
static constexpr uint16_t IFACE0_WL_16BITS
Definition WM8962.h:142
static constexpr uint16_t WSEQ_DONE_EINT_MASK
Definition WM8962.h:132
static constexpr uint16_t REGMASK_OUT_VOL
Definition WM8962.h:150
static constexpr uint16_t IFACE0_WL_24BITS
Definition WM8962.h:144
static constexpr uint16_t ADC_DEFAULT_VOLUME_VALUE
Definition WM8962.h:167
static constexpr uint16_t CLOCK2_BCLK_DIV_MASK
Definition WM8962.h:137
bool updateRegWide(uint16_t reg, uint16_t mask, uint16_t value)
Read-Modify-Write of a 16 bit register addressed via a 16 bit address.
Definition WM8962.h:633
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 WM8962.h:198
bool setOutputVolume(uint8_t volume, WM8962Channel channel=WM8962Channel::All)
Set the output volume (0..127) for the given channel(s)
Definition WM8962.h:394
bool applyProperties()
Apply pending volume changes (set VU bit for output and input)
Definition WM8962.h:526
bool begin(WM8962Protocol protocol=WM8962Protocol::I2S, uint32_t sample_rate=44100, uint8_t word_size=16, uint32_t mclk_to_fs_ratio=256, bool playback=true, bool capture=true)
Definition WM8962.h:221
static constexpr uint16_t IFACE0_WL_32BITS
Definition WM8962.h:145
static constexpr uint16_t R_CH_MUTE_MASK
Definition WM8962.h:135
bool readRegWide(uint16_t reg, uint16_t &value)
Definition WM8962.h:622
bool setActive(codec_mode_t mode) override
Definition WM8962.h:448
static constexpr uint16_t IFACE0_FORMAT_MASK
Definition WM8962.h:139
static constexpr uint16_t HEADPHONE_MAX_VOLUME_VALUE
Definition WM8962.h:161
static constexpr uint16_t IFACE0_WL_20BITS
Definition WM8962.h:143
bool setInputVolume(int volume) override
Sets the input volume in % (0...100) for all channels.
Definition WM8962.h:463
bool setInputVolume(uint8_t volume, WM8962Channel channel=WM8962Channel::All)
Set the input volume for the given channel(s) (6 bit value)
Definition WM8962.h:455
bool setVolume(int volume) override
Sets the output volume in % (0...100) for all channels.
Definition WM8962.h:430
static constexpr uint16_t REGMASK_IN_MUTE
Definition WM8962.h:154
bool routeInput(WM8962InputPgaSource source, WM8962Channel channel)
Select the input PGA source for the given channel (FrontLeft / FrontRight only).
Definition WM8962.h:485
bool writeRegWide(uint16_t reg, uint16_t value)
Definition WM8962.h:611
static constexpr uint16_t SPEAKER_DEFAULT_VOLUME_VALUE
Definition WM8962.h:171
static constexpr uint16_t LINEIN_DEFAULT_VOLUME_VALUE
Definition WM8962.h:170
bool setProtocol(WM8962Protocol protocol)
Configure the digital audio interface protocol (I2S, LJ, RJ, PCMA/B)
Definition WM8962.h:273
static constexpr uint16_t HEADPHONE_DEFAULT_VOLUME_VALUE
Definition WM8962.h:169
static constexpr uint16_t IFACE0_WL_SHIFT
Definition WM8962.h:141
static constexpr uint16_t ADC_MAX_VOLUME_VALUE
Definition WM8962.h:159
static constexpr uint16_t REGMASK_IN_VU
Definition WM8962.h:153
bool runSequence(WM8962Sequence id)
Trigger one of the codec's built-in write sequences and wait (up to the documented timeout) until it ...
Definition WM8962.h:572
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
int volume_percent
Last volume (in %) provided to setVolume()
Definition ZephyrDriverCommon.h:89
i2c_bus_handle_t wire
Definition ZephyrDriverCommon.h:86
int input_volume_percent
Last input volume (in %) provided to setInputVolume()
Definition ZephyrDriverCommon.h:91
Namespace for audio driver components.
Definition AudioBoard.h:5
WM8962Protocol
Digital audio interface protocol.
Definition WM8962.h:15
input_device_t
Definition DriverCommon.h:170
void delayMs(unsigned long ms)
Definition API_Delay.h:19
codec_mode_t
Definition DriverCommon.h:290
@ CODEC_MODE_ENCODE
Definition DriverCommon.h:293
@ CODEC_MODE_DECODE
Definition DriverCommon.h:294
WM8962Channel
Logical audio channels.
Definition WM8962.h:32
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
WM8962Sequence
Write sequencer sequence ids.
Definition WM8962.h:41
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
WM8962InputPgaSource
Input PGA source (used for routeInput)
Definition WM8962.h:24