arduino-audio-driver
Loading...
Searching...
No Matches
WM8960.h
Go to the documentation of this file.
1/***********************************************************************************************/
25#pragma once
26
27
33#include <stdbool.h>
34#include <stdint.h>
35#include <stdio.h>
36#include <string.h>
37
38#include "DriverCommon.h"
39#include "Platforms/API_I2C.h"
40
41#ifdef ARDUINO
42#include <Arduino.h>
43#include <Wire.h>
44#endif
45
46
47namespace audio_driver {
48
49static constexpr int WM8960_I2C_ADDRESS = 0x1A;
50static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_IPVU = 0x100u;
51static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_INMUTE = 0x080u;
52static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_IZC_ZC = 0x040u;
53static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_INVOL_0dB = 0x017u;
54static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_INVOL_30dB = 0x03Fu;
55static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_OUT1VU = 0x100u;
56static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_O1ZC_ZC = 0x080u;
57static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_OUT1VOL_0dB = 0x079u;
58static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_OUT1VOL_6dB = 0x07Fu;
59static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_1 = 0x000u;
60static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_1_5 = 0x040u;
61static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_2 = 0x080u;
62static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_3 = 0x0C0u;
63static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_4 = 0x100u;
64static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_5_5 = 0x140u;
65static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_6 = 0x180u;
66static constexpr uint16_t WM8960_CLK1_DACDIV_BY_1 = 0x000u;
67static constexpr uint16_t WM8960_CLK1_DACDIV_BY_1_5 = 0x008u;
68static constexpr uint16_t WM8960_CLK1_DACDIV_BY_2 = 0x010u;
69static constexpr uint16_t WM8960_CLK1_DACDIV_BY_3 = 0x018u;
70static constexpr uint16_t WM8960_CLK1_DACDIV_BY_4 = 0x020u;
71static constexpr uint16_t WM8960_CLK1_DACDIV_BY_5_5 = 0x028u;
72static constexpr uint16_t WM8960_CLK1_DACDIV_BY_6 = 0x030u;
73static constexpr uint16_t WM8960_CLK1_SYSCLKDIV_BY_1 = 0x000u;
74static constexpr uint16_t WM8960_CLK1_SYSCLKDIV_BY_2 = 0x004u;
75static constexpr uint16_t WM8960_CLK1_CLKSEL_MCLK = 0x000u;
76static constexpr uint16_t WM8960_CLK1_CLKSEL_PLL = 0x001u;
77static constexpr uint16_t WM8960_CTR1_DACDIV2_6B_EN = 0x080u;
78static constexpr uint16_t WM8960_CTR1_ADCPOL_LR_INV = 0x060u;
79static constexpr uint16_t WM8960_CTR1_ADCPOL_L_INV = 0x040u;
80static constexpr uint16_t WM8960_CTR1_ADCPOL_R_INV = 0x020u;
81static constexpr uint16_t WM8960_CTR1_DACMU_NO = 0x000u;
82static constexpr uint16_t WM8960_CTR1_DACMU_MUTE = 0x008u;
83static constexpr uint16_t WM8960_CTR1_DEEMPH_48_KHZ = 0x006u;
84static constexpr uint16_t WM8960_CTR1_DEEMPH_44_1_KHZ = 0x004u;
85static constexpr uint16_t WM8960_CTR1_DEEMPH_32_KHZ = 0x002u;
86static constexpr uint16_t WM8960_CTR1_ADCHPD_DIS = 0x001u;
87static constexpr uint16_t WM8960_CTR2_DACPOL_LR_INV = 0x060u;
88static constexpr uint16_t WM8960_CTR2_DACPOL_L_INV = 0x040u;
89static constexpr uint16_t WM8960_CTR2_DACPOL_R_INV = 0x020u;
90static constexpr uint16_t WM8960_CTR2_DACSMM_GRAD = 0x008u;
91static constexpr uint16_t WM8960_CTR2_DACMR_SLOW_RMP = 0x004u;
92static constexpr uint16_t WM8960_CTR2_DACSLOPE_SS = 0x002u;
93static constexpr uint16_t WM8960_AUDIO_INTF0_ALRSWAP = 0x100u;
94static constexpr uint16_t WM8960_AUDIO_INTF0_BCLKINV = 0x080u;
95static constexpr uint16_t WM8960_AUDIO_INTF0_MS_MASTER = 0x040u;
96static constexpr uint16_t WM8960_AUDIO_INTF0_MS_SLAVE = 0x000u;
97static constexpr uint16_t WM8960_AUDIO_INTF0_DLRSWAP = 0x020u;
98static constexpr uint16_t WM8960_AUDIO_INTF0_LRP_INV = 0x010u;
99static constexpr uint16_t WM8960_AUDIO_INTF0_WL_16BITS = 0x000u;
100static constexpr uint16_t WM8960_AUDIO_INTF0_WL_20BITS = 0x004u;
101static constexpr uint16_t WM8960_AUDIO_INTF0_WL_24BITS = 0x008u;
102static constexpr uint16_t WM8960_AUDIO_INTF0_WL_32BITS = 0x00Cu;
103static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_R_JUSTIF = 0x000u;
104static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_L_JUSTIF = 0x001u;
105static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_I2S_MODE = 0x002u;
106static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_DSP_MODE = 0x003u;
107static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_2 = 0x040u;
108static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_3 = 0x080u;
109static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_4 = 0x0C0u;
110static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_6 = 0x100u;
111static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_8 = 0x140u;
112static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_12 = 0x180u;
113static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_16 = 0x1C0u;
114static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_1_5 = 0x001u;
115static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_2 = 0x002u;
116static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_3 = 0x003u;
117static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_4 = 0x004u;
118static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_5_5 = 0x005u;
119static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_6 = 0x006u;
120static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_8 = 0x007u;
121static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_11 = 0x008u;
122static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_12 = 0x009u;
123static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_16 = 0x00Au;
124static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_22 = 0x00Bu;
125static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_24 = 0x00Cu;
126static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_32 = 0x00Du;
127static constexpr uint16_t WM8960_AUDIO_INTF1_ALRCGPIO_GPIO = 0x040u;
128static constexpr uint16_t WM8960_AUDIO_INTF1_WL8_8BIT = 0x020u;
129static constexpr uint16_t WM8960_AUDIO_INTF1_DACCOMP_ALAW = 0x010u;
130static constexpr uint16_t WM8960_AUDIO_INTF1_DACCOMP_ULAW = 0x018u;
131static constexpr uint16_t WM8960_AUDIO_INTF1_ADCCOMP_ULAW = 0x004u;
132static constexpr uint16_t WM8960_AUDIO_INTF1_ADCCOMP_ALAW = 0x006u;
133static constexpr uint16_t WM8960_AUDIO_INTF1_LOOPBACK_EN = 0x001u;
134static constexpr uint16_t WM8960_LEFT_RIGHT_DAC_VOL_DACVU_UP = 0x100u;
135static constexpr uint16_t WM8960_LEFT_RIGHT_DAC_VOL_0dB = 0x0FFu;
136static constexpr uint16_t WM8960_LEFT_RIGHT_DAC_VOL_127dB = 0x001u;
137static constexpr uint16_t WM8960_3D_CTR_3DUC_LOW = 0x040u;
138static constexpr uint16_t WM8960_3D_CTR_3DUC_HIGH = 0x000u;
139static constexpr uint16_t WM8960_3D_CTR_3DLC_LOW = 0x000u;
140static constexpr uint16_t WM8960_3D_CTR_3DLC_HIGH = 0x020u;
141static constexpr uint16_t WM8960_3D_CTR_3DDEPTH_100 = 0x01Eu;
142static constexpr uint16_t WM8960_3D_CTR_3DEN = 0x001u;
143static constexpr uint16_t WM8960_LEFT_RIGHT_ADC_VOL_ADCVU_UP = 0x100u;
144static constexpr uint16_t WM8960_LEFT_RIGHT_ADC_VOL_ADCVOL_0dB = 0x0C3u;
145static constexpr uint16_t WM8960_LEFT_RIGHT_ADC_VOL_ADCVOL_30dB = 0x0FFu;
146static constexpr uint16_t WM8960_PWR_MGMT1_VMIDSEL_50K = 0x080u;
147static constexpr uint16_t WM8960_PWR_MGMT1_VMIDSEL_250K = 0x100u;
148static constexpr uint16_t WM8960_PWR_MGMT1_VMIDSEL_5K = 0x180u;
149static constexpr uint16_t WM8960_PWR_MGMT1_VREF_UP = 0x040u;
150static constexpr uint16_t WM8960_PWR_MGMT1_AINL_UP = 0x020u;
151static constexpr uint16_t WM8960_PWR_MGMT1_AINR_UP = 0x010u;
152static constexpr uint16_t WM8960_PWR_MGMT1_ADCL_UP = 0x008u;
153static constexpr uint16_t WM8960_PWR_MGMT1_ADCR_UP = 0x004u;
154static constexpr uint16_t WM8960_PWR_MGMT1_MICB_UP = 0x002u;
155static constexpr uint16_t WM8960_PWR_MGMT1_DIGENB_DI = 0x001u;
156static constexpr uint16_t WM8960_PWR_MGMT2_DACL_UP = 0x100u;
157static constexpr uint16_t WM8960_PWR_MGMT2_DACR_UP = 0x080u;
158static constexpr uint16_t WM8960_PWR_MGMT2_LOUT1_UP = 0x040u;
159static constexpr uint16_t WM8960_PWR_MGMT2_ROUT1_UP = 0x020u;
160static constexpr uint16_t WM8960_PWR_MGMT2_SPKL_UP = 0x010u;
161static constexpr uint16_t WM8960_PWR_MGMT2_SPKR_UP = 0x008u;
162static constexpr uint16_t WM8960_PWR_MGMT2_OUT3_UP = 0x002u;
163static constexpr uint16_t WM8960_PWR_MGMT2_PLL_EN_UP = 0x001u;
164static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MN1_CON = 0x100u;
165static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MP3_CON = 0x080u;
166static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MP2_CON = 0x040u;
167static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_0dB = 0x000u;
168static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_13dB = 0x010u;
169static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_20dB = 0x020u;
170static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_29dB = 0x030u;
171static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MIC2B_CON = 0x008u;
172static constexpr uint16_t WM8960_LEFT_OUT_MIX_LD2LO_EN = 0x100u;
173static constexpr uint16_t WM8960_LEFT_OUT_MIX_LI2LO_EN = 0x080u;
174static constexpr uint16_t WM8960_RIGHT_OUT_MIX_RD2RO_EN = 0x100u;
175static constexpr uint16_t WM8960_RIGHT_OUT_MIX_RI2RO_EN = 0x080u;
176static constexpr uint16_t WM8960_MONO_OUT_MIX1_MIX2_2MO_DI = 0x000u;
177static constexpr uint16_t WM8960_MONO_OUT_MIX1_MIX2_2MO_EN = 0x080u;
178static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKVU = 0x100u;
179static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKRZC = 0x080u;
180static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKRVOL_0dB = 0x079u;
181static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKRVOL_6dB = 0x07Fu;
182static constexpr uint16_t WM8960_PWR_MGMT3_LMIC_UP = 0x020u;
183static constexpr uint16_t WM8960_PWR_MGMT3_RMIC_UP = 0x010u;
184static constexpr uint16_t WM8960_PWR_MGMT3_LOMIX_UP = 0x008u;
185static constexpr uint16_t WM8960_PWR_MGMT3_ROMIX_UP = 0x004u;
186static constexpr uint16_t WM8960_PLL_N_PLLPRESCALE_DI = 0x000u;
187static constexpr uint16_t WM8960_PLL_N_PLLPRESCALE_EN = 0x010u;
188static constexpr uint16_t WM8960_PLL_N_SDM_INT = 0x000u;
189static constexpr uint16_t WM8960_PLL_N_SDM_FRAC = 0x020u;
190static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_1 = 0x000u;
191static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_2 = 0x040u;
192static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_3 = 0x080u;
193static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_4 = 0x0C0u;
194static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_5_5 = 0x100u;
195static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_6 = 0x140u;
196static constexpr bool MTB_RSLT_WM8960_BAD_ARG = false;
197static constexpr uint32_t WM8960_TIMEOUT_MS = 100u;
198static constexpr uint32_t REGISTER_MAP_SIZE = 56u;
199
222 WM8960_REG_RSVD0, /* 0x0C: Reserved */
223 WM8960_REG_RSVD1, /* 0x0D: Reserved */
224 WM8960_REG_RSVD2, /* 0x0E: Reserved */
240 WM8960_REG_RSVD3, /* 0x1E: Reserved */
241 WM8960_REG_RSVD4, /* 0x1F: Reserved */
245 WM8960_REG_RSVD5, /* 0x23: Reserved */
246 WM8960_REG_RSVD6, /* 0x24: Reserved */
260 WM8960_REG_RSVD7, /* 0x32: Reserved */
267
283
284static constexpr uint8_t WM8960_FEATURE_MICROPHONES =
286
303
314
322
323/*------------------------------------------------------------------------------
324 Internal types (from implementation)
325------------------------------------------------------------------------------*/
330
336
342class WM8960 {
343 public:
344 WM8960() = default;
345
347 void setWire(i2c_bus_handle_t handle) { i2c_handle = handle; }
348
350 void setAddress(int addr) {
351 if (addr > 0) i2c_addr = addr;
352 }
353
362 void setWriteRetryCount(uint32_t count) { write_retry_count = count; }
363
401 bool init(uint8_t features) {
402 AD_LOGD("init");
403 bool result = write(WM8960_REG_RESET, 0);
404 if (!result) {
405 return false;
406 }
407 if (features != WM8960_FEATURE_NONE) {
408 result = configDefault(features);
409 if (!result) {
410 AD_LOGD("configDefault ERROR");
411 return result;
412 }
413 }
414 return true;
415 }
416
421 void deinit() {
422 AD_LOGD("deinit");
423 i2c_handle = nullptr;
424 pll_enabled = false;
426 }
427
438 bool read(wm8960_reg_t reg, uint16_t* data) {
439 if (reg >= REGISTER_MAP_SIZE) {
440 return false;
441 }
442 *data = register_map[reg];
443 return true;
444 }
445
455 bool write(wm8960_reg_t enum_reg, uint16_t value) {
456 char msg[80];
457 snprintf(msg, 80, "write 0x%x = 0x%x", enum_reg, value);
458 AD_LOGD("%s", msg);
459 bool result = false;
460 uint32_t count = 0;
461 while (!result) {
462 result = writeEx(enum_reg, value);
463 if (result) break;
464 if (++count > write_retry_count) {
465 break;
466 }
467 }
468 return result;
469 }
470
480 bool set(wm8960_reg_t reg, uint16_t mask) {
481 bool result;
482 uint16_t data;
483 result = read(reg, &data);
484 if (result) {
485 result = write((wm8960_reg_t)reg, data | mask);
486 }
487 return result;
488 }
489
499 bool clear(wm8960_reg_t reg, uint16_t mask) {
500 bool result;
501 uint16_t data;
502 result = read(reg, &data);
503 if (result) {
504 result = write(reg, data & ~mask);
505 }
506 return result;
507 }
508
519 bool adjustInputVolume(uint8_t volume) {
520 AD_LOGD("adjustInputVolume");
522 return false;
523 }
524 return adjustVolume(
527 }
528
540 bool adjustHeadphoneOutputVolume(uint8_t volume) {
541 AD_LOGD("adjustHeadphoneOutputVolume");
543 return false;
544 }
545 return adjustVolume(
548 }
549
561 bool adjustSpeakerOutputVolume(uint8_t volume) {
562 AD_LOGD("adjustSpeakerOutputVolume");
564 return false;
565 }
566 return adjustVolume(
569 }
570
582 bool setOutputVolume(uint8_t volume) {
583 bool result = true;
585 result = result && adjustSpeakerOutputVolume(volume);
588 result = result && adjustHeadphoneOutputVolume(volume);
589 return result;
590 }
591
603 bool activate(void) {
604 AD_LOGD("activate");
605 bool result;
606 uint16_t value;
607
608 /******************** PWR_MGMT1 *******************/
609 result = read(WM8960_REG_PWR_MGMT1, &value);
610 if (!result) return result;
611 value &= ~WM8960_PWR_MGMT1_VMIDSEL_5K;
619 }
620 result = write(WM8960_REG_PWR_MGMT1, value);
621 if (!result) return result;
622
623 /******************** PWR_MGMT2 *******************/
624 value = 0;
625 if (pll_enabled) {
627 }
632 }
637 }
638 result = set(WM8960_REG_PWR_MGMT2, value);
639 if (!result) return result;
640
641 /******************** PWR_MGMT3 *******************/
642 value = 0;
646 }
651 }
652 result = set(WM8960_REG_PWR_MGMT3, value);
653 return result;
654 }
655
666 bool deactivate(void) {
667 AD_LOGD("deactivate");
668 bool result;
669 uint16_t value = 0;
670
671 /******************** PWR_MGMT3 *******************/
675 }
680 }
681 result = clear(WM8960_REG_PWR_MGMT3, value);
682 if (!result) return result;
683
684 /******************** PWR_MGMT2 *******************/
685 result = read(WM8960_REG_PWR_MGMT2, &value);
686 if (!result) return result;
687 if (pll_enabled) {
688 value &= ~(WM8960_PWR_MGMT2_PLL_EN_UP);
689 }
694 }
699 }
700 result = write(WM8960_REG_PWR_MGMT2, value);
701 if (!result) return result;
702
703 /******************** PWR_MGMT1 *******************/
704 result = read(WM8960_REG_PWR_MGMT1, &value);
705 if (!result) return result;
706 value &= ~WM8960_PWR_MGMT1_VMIDSEL_5K;
714 }
715 result = write(WM8960_REG_PWR_MGMT1, value);
716 return result;
717 }
718
732 bool configureClocking(uint32_t mclk_hz, bool enable_pll,
734 wm8960_word_length_t word_length,
735 wm8960_mode_t mode) {
736 AD_LOGD("configureClocking");
737 bool result;
738 uint16_t dac_div_mask;
739 uint16_t adc_div_mask;
740 uint16_t clk_sel_mask = WM8960_CLK1_CLKSEL_MCLK;
741 uint16_t sysclk_div_mask = WM8960_CLK1_SYSCLKDIV_BY_1;
742
743 if (!enable_pll && (mclk_hz != _WM8960_SYSCLK_FREQ_12288000_HZ) &&
744 (mclk_hz != _WM8960_SYSCLK_FREQ_11289600_HZ)) {
745 return false;
746 }
747
748 if (enable_pll) {
749 result = setupPll(mclk_hz, sample_rate);
750 if (!result) return result;
751 clk_sel_mask = WM8960_CLK1_CLKSEL_PLL;
752 sysclk_div_mask = WM8960_CLK1_SYSCLKDIV_BY_2;
753 }
754
755 switch (sample_rate) {
758 dac_div_mask = WM8960_CLK1_DACDIV_BY_1;
759 adc_div_mask = WM8960_CLK1_ADCDIV_BY_1;
760 break;
762 dac_div_mask = WM8960_CLK1_DACDIV_BY_1_5;
763 adc_div_mask = WM8960_CLK1_ADCDIV_BY_1_5;
764 break;
767 dac_div_mask = WM8960_CLK1_DACDIV_BY_2;
768 adc_div_mask = WM8960_CLK1_ADCDIV_BY_2;
769 break;
771 dac_div_mask = WM8960_CLK1_DACDIV_BY_3;
772 adc_div_mask = WM8960_CLK1_ADCDIV_BY_3;
773 break;
776 dac_div_mask = WM8960_CLK1_DACDIV_BY_4;
777 adc_div_mask = WM8960_CLK1_ADCDIV_BY_4;
778 break;
780 dac_div_mask = WM8960_CLK1_DACDIV_BY_5_5;
781 adc_div_mask = WM8960_CLK1_ADCDIV_BY_5_5;
782 break;
784 dac_div_mask = WM8960_CLK1_DACDIV_BY_6;
785 adc_div_mask = WM8960_CLK1_ADCDIV_BY_6;
786 break;
787 default:
788 dac_div_mask = WM8960_CLK1_DACDIV_BY_1;
789 adc_div_mask = WM8960_CLK1_ADCDIV_BY_1;
790 break;
791 }
792
793 pll_enabled = enable_pll;
794
795 result = write(WM8960_REG_CLK1, adc_div_mask | dac_div_mask |
796 sysclk_div_mask | clk_sel_mask);
797 if (!result) return result;
798
800 (uint16_t)mode | (uint16_t)word_length |
802 return result;
803 }
804
811 bool dump() {
812 AD_LOGD("dump");
813 char msg[80];
814 for (int j = 0x1; j <= 0x37; j++) {
815 uint16_t data;
816 if (!read((wm8960_reg_t)j, &data)) {
817 AD_LOGD("dump ERROR");
818 return false;
819 }
820 snprintf(msg, 80, "%x: %x", j, data);
821 AD_LOGD("%s", msg);
822 }
823 return true;
824 }
829 bool i2cWrite(uint8_t address, uint8_t data[2]) {
830 return i2c_bus_write_bytes(i2c_handle, address, data, 2, nullptr, 0) ==
831 RESULT_OK;
832 }
833
834 /* Internal write with register-map cache update. */
835 bool writeEx(wm8960_reg_t enum_reg, uint16_t value) {
836 uint8_t reg = enum_reg;
837 uint8_t data[2];
838 data[0] = (reg << 1) | ((uint8_t)((value >> 8) & 0x0001)); // RegAddr
839 data[1] = (uint8_t)(value & 0x00FF); // RegValue
840 bool result = i2cWrite(i2c_addr, data);
841
842 if (result) {
843 if (reg == WM8960_REG_RESET) {
844 static const uint16_t default_register_map[REGISTER_MAP_SIZE] = {
845 0x0097, 0x0097, 0x0000, 0x0000,
846 0x0000, 0x0008, 0x0000, 0x000a, // R0~R7
847 0x01c0, 0x0000, 0x00ff, 0x00ff,
848 0x0000, 0x0000, 0x0000, 0x0000, // R8~R15
849 0x0000, 0x007b, 0x0100, 0x0032,
850 0x0000, 0x00c3, 0x00c3, 0x01c0, // R16~R23
851 0x0000, 0x0000, 0x0000, 0x0000,
852 0x0000, 0x0000, 0x0000, 0x0000, // R24~R31
853 0x0100, 0x0100, 0x0050, 0x0050,
854 0x0050, 0x0050, 0x0000, 0x0000, // R32~R39
855 0x0000, 0x0000, 0x0040, 0x0000,
856 0x0000, 0x0050, 0x0050, 0x0000, // R40~R47
857 0x0000, 0x0037, 0x004d, 0x0080,
858 0x0008, 0x0031, 0x0026, 0x00e9, // R48~R55
859 };
860 memcpy(&register_map, &default_register_map, sizeof(register_map));
861 } else {
862 register_map[reg] = value;
863 }
864 }
865 return result;
866 }
867
868 bool configDefault(uint8_t features) {
869 bool result;
870 uint16_t value;
871
872 /* Enable VREF and set VMID=50K */
874 if (features & WM8960_FEATURE_MICROPHONE1 ||
875 features & WM8960_FEATURE_MICROPHONE2 ||
876 features & WM8960_FEATURE_MICROPHONE3) {
877 /* AINL, AINR, ADCL, ADCR and MICB */
881 }
882 result = write(WM8960_REG_PWR_MGMT1, value);
883 if (!result) {
884 AD_LOGD("Enable VREF and set VMID=50K");
885 return result;
886 }
887
888 /* Enable DACL, DACR, LOUT1 and ROUT1 */
889 if (features & WM8960_FEATURE_HEADPHONE ||
890 features & WM8960_FEATURE_SPEAKER) {
891 value = 0;
892 if (features & WM8960_FEATURE_HEADPHONE) {
895 }
896 if (features & WM8960_FEATURE_SPEAKER) {
899 }
900 result = write(WM8960_REG_PWR_MGMT2, value);
901 if (!result) {
902 AD_LOGD("Enable DACL, DACR, LOUT1 and ROUT1");
903 return result;
904 }
905 }
906
907 /* Enable Class D Speaker Outputs */
908 if (features & WM8960_FEATURE_SPEAKER) {
909 // R49 Class D Control 011110111 - Enable Class D Speaker Outputs
910 result = write(WM8960_REG_CLASS_D_CTL1, 0xF7);
911 if (!result) {
912 AD_LOGD("Enable Class D");
913 return result;
914 }
915 }
916
917 uint16_t pwr_mgmt3 = 0;
918 /* Enable left output mixer and right output mixer */
919 if (features & WM8960_FEATURE_HEADPHONE ||
920 features & WM8960_FEATURE_SPEAKER) {
922 }
923 /* Enable left and right channel input PGA */
924 uint16_t mic_sig_path = WM8960_ADCL_ADCR_SIG_PTH_MIC2B_CON;
925 if (features & WM8960_FEATURE_MICROPHONE1 ||
926 features & WM8960_FEATURE_MICROPHONE2 ||
927 features & WM8960_FEATURE_MICROPHONE3) {
929 if (features & WM8960_FEATURE_MICROPHONE1) {
930 mic_sig_path |= WM8960_ADCL_ADCR_SIG_PTH_MN1_CON;
931 }
932 if (features & WM8960_FEATURE_MICROPHONE2) {
933 mic_sig_path |= WM8960_ADCL_ADCR_SIG_PTH_MP2_CON;
934 }
935 if (features & WM8960_FEATURE_MICROPHONE3) {
936 mic_sig_path |= WM8960_ADCL_ADCR_SIG_PTH_MP3_CON;
937 }
938 }
939 result = write(WM8960_REG_PWR_MGMT3, pwr_mgmt3);
940 if (!result) {
941 AD_LOGD("WM8960_REG_PWR_MGMT3");
942 return result;
943 }
944
945 static const _wm8960_operation_t operations[] = {
946 /* LINPUT1 to PGA (LMN1), Connect left input PGA to left input boost
947 (LMIC2B), Left PGA Boost = 0dB */
950 .value = mic_sig_path},
951 /* RINPUT1 to PGA (RMN1), Connect right input PGA to right input
952 boost (RMIC2B), Right PGA Boost = 0dB */
953 {.features = WM8960_FEATURE_MICROPHONES,
955 .value = mic_sig_path},
956 /* Unmute left input PGA (LINMUTE), Left Input PGA Vol = 0dB, Volume
957 Update */
958 {.features = WM8960_FEATURE_MICROPHONES,
962 /* Unmute right input PGA (RINMUTE), Right Input PGA Vol = 0dB, Volume
963 Update */
964 {.features = WM8960_FEATURE_MICROPHONES,
968 /* Left ADC Vol = 0dB, Volume Update */
969 {.features = WM8960_FEATURE_MICROPHONES,
973 /* Right ADC Vol = 0dB, Volume Update */
974 {.features = WM8960_FEATURE_MICROPHONES,
978
979 /* Left DAC to left output mixed enabled (LD2LO), 0dB */
980 {.features = WM8960_FEATURE_HEADPHONE,
983 /* Right DAC to right output mixed enabled (RD2RO), 0dB */
984 {.features = WM8960_FEATURE_HEADPHONE,
987 /* LOUT1 Volume = 0dB, volume updated */
988 {.features = WM8960_FEATURE_HEADPHONE,
992 /* ROUT1 Volume = 0dB, volume updated */
993 {.features = WM8960_FEATURE_HEADPHONE,
997 /* Unmute DAC digital soft mute */
998 {.features = WM8960_FEATURE_HEADPHONE,
999 .reg = WM8960_REG_CTR1,
1000 .value = WM8960_CTR1_DACMU_NO},
1001
1002 /* Left DAC to left output mixed enabled (LD2LO), 0dB */
1003 {.features = WM8960_FEATURE_SPEAKER,
1006 /* Right DAC to right output mixed enabled (RD2RO), 0dB */
1007 {.features = WM8960_FEATURE_SPEAKER,
1010 /* LOUT2 Volume = 0dB, volume updated */
1011 {.features = WM8960_FEATURE_SPEAKER,
1012 .reg = WM8960_REG_LOUT2_VOL,
1015 /* ROUT2 Volume = 0dB, volume updated */
1016 {.features = WM8960_FEATURE_SPEAKER,
1017 .reg = WM8960_REG_ROUT2_VOL,
1020 /* Unmute DAC digital soft mute */
1021 {.features = WM8960_FEATURE_SPEAKER,
1022 .reg = WM8960_REG_CTR1,
1023 .value = WM8960_CTR1_DACMU_NO},
1024 };
1025
1026 for (uint32_t i = 0; i < sizeof(operations) / sizeof(_wm8960_operation_t);
1027 i++) {
1028 _wm8960_operation_t operation = operations[i];
1029 if ((features & operation.features) == operation.features) {
1030 result = write(operation.reg, operation.value);
1031 if (!result) {
1032 AD_LOGD("operation");
1033 return result;
1034 }
1035 }
1036 }
1037
1038 enabled_features = features;
1039 return result;
1040 }
1041
1042 bool setupPll(uint32_t mclk_hz, wm8960_adc_dac_sample_rate_t sample_rate) {
1043 AD_LOGD("setupPll");
1044 bool result;
1045 uint8_t pll_n;
1046 uint32_t pll_k;
1047 bool use_prescale = false;
1048 uint32_t sys_clk_hz;
1049
1050 switch (sample_rate) {
1057 default:
1059 break;
1065 break;
1066 }
1067
1068 uint32_t f2 = (4 * 2 * sys_clk_hz);
1069 uint32_t f1 = mclk_hz;
1070 float R = (float)f2 / (float)f1;
1071 if ((R <= 5) || ((R * 2 - 8) < (8 - R))) {
1072 use_prescale = true;
1073 R *= (float)2;
1074 }
1075 if ((R <= 5) || (R >= 13)) {
1076 return false;
1077 }
1078
1079 pll_n = (uint8_t)R;
1080 pll_k = (uint32_t)((float)0x1000000 * (R - (float)pll_n));
1081 uint16_t prescale_mask = (use_prescale) ? WM8960_PLL_N_PLLPRESCALE_EN
1083
1084 result = write(WM8960_REG_PLL_N,
1085 pll_n | prescale_mask | WM8960_PLL_N_SDM_FRAC);
1086 if (!result) return result;
1087
1088 result = write(WM8960_REG_PLL_K1, pll_k >> 16 & 0xFF);
1089 if (!result) return result;
1090
1091 result = write(WM8960_REG_PLL_K2, pll_k >> 8 & 0xFF);
1092 if (!result) return result;
1093
1094 result = write(WM8960_REG_PLL_K3, pll_k & 0xFF);
1095 if (!result) return result;
1096
1098 return result;
1099 }
1100
1101 bool adjustVolume(uint8_t volume, wm8960_reg_t left_vol_reg,
1102 wm8960_reg_t right_vol_reg, uint16_t update_bit,
1103 uint16_t volume_bits_mask) {
1104 AD_LOGD("adjustVolume");
1105 bool result;
1106 uint16_t data;
1107
1108 result = read(left_vol_reg, &data);
1109 if (!result) return result;
1110
1111 data &= (~update_bit & ~volume_bits_mask);
1112 data |= volume;
1113 result = write(left_vol_reg, data);
1114 if (!result) return result;
1115
1116 result = read(right_vol_reg, &data);
1117 if (!result) return result;
1118
1119 data &= ~volume_bits_mask;
1120 data |= (volume | update_bit);
1121 result = write(right_vol_reg, data);
1122 return result;
1123 }
1124
1125 protected:
1129 bool pll_enabled = false;
1130 uint32_t write_retry_count = 1;
1131
1132 /* The WM8960 audio codec does not allow reading registers from the device
1133 * so we store a cached copy with default of the register map in the driver
1134 * and is updated on every write.
1135 */
1137};
1138
1139} // namespace audio_driver
1140
#define RESULT_OK
Definition DriverCommon.h:74
#define AD_LOGD(...)
Definition Logger.h:12
Header-only driver class for the WM8960 audio codec chip.
Definition WM8960.h:342
bool clear(wm8960_reg_t reg, uint16_t mask)
This function clears bits in a register.
Definition WM8960.h:499
bool writeEx(wm8960_reg_t enum_reg, uint16_t value)
Definition WM8960.h:835
bool i2cWrite(uint8_t address, uint8_t data[2])
Definition WM8960.h:829
bool adjustHeadphoneOutputVolume(uint8_t volume)
This function updates the volume of both the left and right channels of the headphone output.
Definition WM8960.h:540
uint32_t write_retry_count
Definition WM8960.h:1130
void setAddress(int addr)
Defines the I2C device address.
Definition WM8960.h:350
uint8_t enabled_features
Definition WM8960.h:1128
bool deactivate(void)
This function powers down the modules the required for the features enabled using init.
Definition WM8960.h:666
bool setOutputVolume(uint8_t volume)
This function updates the volume of both the left and right channels of the speaker and headphones.
Definition WM8960.h:582
int i2c_addr
Definition WM8960.h:1127
bool adjustInputVolume(uint8_t volume)
This function updates the volume of both the left and right channels of the microphone input.
Definition WM8960.h:519
bool pll_enabled
Definition WM8960.h:1129
void setWriteRetryCount(uint32_t count)
Defines the number of times we retry to update a register value via I2C. This might help if you have ...
Definition WM8960.h:362
bool adjustVolume(uint8_t volume, wm8960_reg_t left_vol_reg, wm8960_reg_t right_vol_reg, uint16_t update_bit, uint16_t volume_bits_mask)
Definition WM8960.h:1101
bool setupPll(uint32_t mclk_hz, wm8960_adc_dac_sample_rate_t sample_rate)
Definition WM8960.h:1042
bool read(wm8960_reg_t reg, uint16_t *data)
This function reads value of an audio codec register.
Definition WM8960.h:438
void setWire(i2c_bus_handle_t handle)
Defines the I2C bus instance to be used.
Definition WM8960.h:347
void deinit()
Frees up any resources allocated by the driver as part of init().
Definition WM8960.h:421
bool activate(void)
This function powers up the modules the required for the features enabled using init....
Definition WM8960.h:603
i2c_bus_handle_t i2c_handle
Definition WM8960.h:1126
bool init(uint8_t features)
Initialize the I2C communication with the audio codec, reset the codec and apply default configuratio...
Definition WM8960.h:401
bool adjustSpeakerOutputVolume(uint8_t volume)
This function updates the volume of both the left and right channels of the speaker output.
Definition WM8960.h:561
bool write(wm8960_reg_t enum_reg, uint16_t value)
This function writes data to an audio codec register.
Definition WM8960.h:455
uint16_t register_map[REGISTER_MAP_SIZE]
Definition WM8960.h:1136
bool dump()
This function dumps the actual register values.
Definition WM8960.h:811
bool configureClocking(uint32_t mclk_hz, bool enable_pll, wm8960_adc_dac_sample_rate_t sample_rate, wm8960_word_length_t word_length, wm8960_mode_t mode)
This function configures the master clock and the digital interface for the audio codec.
Definition WM8960.h:732
bool configDefault(uint8_t features)
Definition WM8960.h:868
bool set(wm8960_reg_t reg, uint16_t mask)
This function sets bits in a register.
Definition WM8960.h:480
Namespace for audio driver components.
Definition AudioBoard.h:5
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_29dB
Definition WM8960.h:170
static constexpr uint16_t WM8960_LEFT_OUT_MIX_LI2LO_EN
Definition WM8960.h:173
static constexpr uint16_t WM8960_CTR2_DACSLOPE_SS
Definition WM8960.h:92
static constexpr uint16_t WM8960_CTR1_ADCPOL_L_INV
Definition WM8960.h:79
static constexpr uint16_t WM8960_CTR2_DACPOL_LR_INV
Definition WM8960.h:87
static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_OUT1VOL_0dB
Definition WM8960.h:57
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_3
Definition WM8960.h:116
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_3
Definition WM8960.h:108
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_1_5
Definition WM8960.h:114
static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_OUT1VU
Definition WM8960.h:55
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_32
Definition WM8960.h:126
wm8960_word_length_t
Definition WM8960.h:308
@ WM8960_WL_32BITS
Definition WM8960.h:312
@ WM8960_WL_24BITS
Definition WM8960.h:311
@ WM8960_WL_16BITS
Definition WM8960.h:309
@ WM8960_WL_20BITS
Definition WM8960.h:310
static constexpr uint16_t WM8960_PLL_N_SDM_INT
Definition WM8960.h:188
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_6
Definition WM8960.h:72
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_3
Definition WM8960.h:62
static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKRVOL_0dB
Definition WM8960.h:180
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_2
Definition WM8960.h:61
static constexpr uint16_t WM8960_PWR_MGMT2_DACL_UP
Definition WM8960.h:156
static constexpr uint16_t WM8960_LEFT_RIGHT_ADC_VOL_ADCVOL_30dB
Definition WM8960.h:145
static constexpr uint16_t WM8960_3D_CTR_3DUC_LOW
Definition WM8960.h:137
static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_INMUTE
Definition WM8960.h:51
static constexpr uint16_t WM8960_AUDIO_INTF0_BCLKINV
Definition WM8960.h:94
static constexpr uint16_t WM8960_CTR2_DACPOL_R_INV
Definition WM8960.h:89
static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_INVOL_30dB
Definition WM8960.h:54
static constexpr uint16_t WM8960_CTR1_DACMU_NO
Definition WM8960.h:81
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MP2_CON
Definition WM8960.h:166
static constexpr uint16_t WM8960_PWR_MGMT2_LOUT1_UP
Definition WM8960.h:158
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_16
Definition WM8960.h:123
static constexpr uint16_t WM8960_PWR_MGMT1_ADCR_UP
Definition WM8960.h:153
static constexpr uint16_t WM8960_AUDIO_INTF1_WL8_8BIT
Definition WM8960.h:128
static constexpr uint16_t WM8960_CTR1_DEEMPH_32_KHZ
Definition WM8960.h:85
static constexpr uint16_t WM8960_CTR1_DACMU_MUTE
Definition WM8960.h:82
wm8960_reg_t
Definition WM8960.h:209
@ WM8960_REG_CTR2
Definition WM8960.h:216
@ WM8960_REG_RESET
Definition WM8960.h:225
@ WM8960_REG_ADD_CTL2
Definition WM8960.h:234
@ WM8960_REG_CLK2
Definition WM8960.h:218
@ WM8960_REG_LOUT2_VOL
Definition WM8960.h:250
@ WM8960_REG_RIGHT_ADC_VOL
Definition WM8960.h:232
@ WM8960_REG_PLL_K2
Definition WM8960.h:264
@ WM8960_REG_LOUT1_VOL
Definition WM8960.h:212
@ WM8960_REG_RSVD5
Definition WM8960.h:245
@ WM8960_REG_ADD_CTL4
Definition WM8960.h:258
@ WM8960_REG_PLL_K3
Definition WM8960.h:265
@ WM8960_REG_CLASS_D_CTL3
Definition WM8960.h:261
@ WM8960_REG_NOISE_GATE
Definition WM8960.h:230
@ WM8960_REG_BYPASS2
Definition WM8960.h:256
@ WM8960_REG_ALC1
Definition WM8960.h:227
@ WM8960_REG_ADCR_SIG_PTH
Definition WM8960.h:243
@ WM8960_REG_IN_BOOST_MIX1
Definition WM8960.h:253
@ WM8960_REG_RSVD6
Definition WM8960.h:246
@ WM8960_REG_LEFT_DAC_VOL
Definition WM8960.h:220
@ WM8960_REG_RSVD2
Definition WM8960.h:224
@ WM8960_REG_AUDIO_INTF0
Definition WM8960.h:217
@ WM8960_REG_PWR_MGMT3
Definition WM8960.h:257
@ WM8960_REG_ADD_CTL1
Definition WM8960.h:233
@ WM8960_REG_RIGHT_IN_VOL
Definition WM8960.h:211
@ WM8960_REG_ADCL_SIG_PTH
Definition WM8960.h:242
@ WM8960_REG_BYPASS1
Definition WM8960.h:255
@ WM8960_REG_AUDIO_INTF1
Definition WM8960.h:219
@ WM8960_REG_ALC2
Definition WM8960.h:228
@ WM8960_REG_MONO_OUT_MIX2
Definition WM8960.h:249
@ WM8960_REG_MONO_OUT_VOL
Definition WM8960.h:252
@ WM8960_REG_LEFT_IN_VOL
Definition WM8960.h:210
@ WM8960_REG_RSVD3
Definition WM8960.h:240
@ WM8960_REG_ADD_CTL3
Definition WM8960.h:237
@ WM8960_REG_IN_BOOST_MIX2
Definition WM8960.h:254
@ WM8960_REG_ANTI_POP2
Definition WM8960.h:239
@ WM8960_REG_PWR_MGMT2
Definition WM8960.h:236
@ WM8960_REG_RIGHT_OUT_MIX
Definition WM8960.h:247
@ WM8960_REG_CLK1
Definition WM8960.h:214
@ WM8960_REG_PLL_N
Definition WM8960.h:262
@ WM8960_REG_RSVD0
Definition WM8960.h:222
@ WM8960_REG_PLL_K1
Definition WM8960.h:263
@ WM8960_REG_ROUT1_VOL
Definition WM8960.h:213
@ WM8960_REG_LEFT_ADC_VOL
Definition WM8960.h:231
@ WM8960_REG_CTR1
Definition WM8960.h:215
@ WM8960_REG_LEFT_OUT_MIX
Definition WM8960.h:244
@ WM8960_REG_RSVD4
Definition WM8960.h:241
@ WM8960_REG_RSVD1
Definition WM8960.h:223
@ WM8960_REG_MONO_OUT_MIX1
Definition WM8960.h:248
@ WM8960_REG_ALC3
Definition WM8960.h:229
@ WM8960_REG_RIGHT_DAC_VOL
Definition WM8960.h:221
@ WM8960_REG_RSVD7
Definition WM8960.h:260
@ WM8960_REG_CLASS_D_CTL1
Definition WM8960.h:259
@ WM8960_REG_3D_CTR
Definition WM8960.h:226
@ WM8960_REG_ROUT2_VOL
Definition WM8960.h:251
@ WM8960_REG_ANTI_POP1
Definition WM8960.h:238
@ WM8960_REG_PWR_MGMT1
Definition WM8960.h:235
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_6
Definition WM8960.h:119
static constexpr uint16_t WM8960_CLK1_SYSCLKDIV_BY_2
Definition WM8960.h:74
static constexpr uint16_t WM8960_PWR_MGMT2_ROUT1_UP
Definition WM8960.h:159
static constexpr uint16_t WM8960_AUDIO_INTF0_MS_SLAVE
Definition WM8960.h:96
static constexpr uint16_t WM8960_AUDIO_INTF0_WL_32BITS
Definition WM8960.h:102
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_5_5
Definition WM8960.h:64
static constexpr uint16_t WM8960_AUDIO_INTF0_MS_MASTER
Definition WM8960.h:95
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_4
Definition WM8960.h:70
static constexpr uint16_t WM8960_PLL_N_PLLPRESCALE_DI
Definition WM8960.h:186
static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_R_JUSTIF
Definition WM8960.h:103
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_2
Definition WM8960.h:115
static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_6
Definition WM8960.h:195
static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKRZC
Definition WM8960.h:179
static constexpr uint16_t WM8960_CTR2_DACMR_SLOW_RMP
Definition WM8960.h:91
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_20dB
Definition WM8960.h:169
static constexpr uint16_t WM8960_PWR_MGMT1_MICB_UP
Definition WM8960.h:154
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_12
Definition WM8960.h:112
wm8960_adc_dac_sample_rate_t
Definition WM8960.h:291
@ WM8960_ADC_DAC_SAMPLE_RATE_11_025_KHZ
Definition WM8960.h:299
@ WM8960_ADC_DAC_SAMPLE_RATE_8_KHZ
Definition WM8960.h:301
@ WM8960_ADC_DAC_SAMPLE_RATE_16_KHZ
Definition WM8960.h:297
@ WM8960_ADC_DAC_SAMPLE_RATE_32_KHZ
Definition WM8960.h:294
@ WM8960_ADC_DAC_SAMPLE_RATE_8_018_KHZ
Definition WM8960.h:300
@ WM8960_ADC_DAC_SAMPLE_RATE_24_KHZ
Definition WM8960.h:295
@ WM8960_ADC_DAC_SAMPLE_RATE_48_KHZ
Definition WM8960.h:292
@ WM8960_ADC_DAC_SAMPLE_RATE_22_05_KHZ
Definition WM8960.h:296
@ WM8960_ADC_DAC_SAMPLE_RATE_12_KHZ
Definition WM8960.h:298
@ WM8960_ADC_DAC_SAMPLE_RATE_44_1_KHZ
Definition WM8960.h:293
static constexpr uint16_t WM8960_AUDIO_INTF1_ADCCOMP_ULAW
Definition WM8960.h:131
static constexpr uint16_t WM8960_AUDIO_INTF1_ADCCOMP_ALAW
Definition WM8960.h:132
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_6
Definition WM8960.h:110
static constexpr uint16_t WM8960_AUDIO_INTF0_ALRSWAP
Definition WM8960.h:93
static constexpr uint16_t WM8960_3D_CTR_3DEN
Definition WM8960.h:142
static constexpr uint16_t WM8960_RIGHT_OUT_MIX_RD2RO_EN
Definition WM8960.h:174
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_12
Definition WM8960.h:122
static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKVU
Definition WM8960.h:178
static constexpr uint16_t WM8960_AUDIO_INTF1_DACCOMP_ULAW
Definition WM8960.h:130
static constexpr uint16_t WM8960_3D_CTR_3DLC_LOW
Definition WM8960.h:139
static constexpr uint16_t WM8960_MONO_OUT_MIX1_MIX2_2MO_EN
Definition WM8960.h:177
static constexpr uint16_t WM8960_3D_CTR_3DLC_HIGH
Definition WM8960.h:140
static constexpr uint16_t WM8960_AUDIO_INTF0_WL_20BITS
Definition WM8960.h:100
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_4
Definition WM8960.h:63
static constexpr uint16_t WM8960_PWR_MGMT1_VREF_UP
Definition WM8960.h:149
static constexpr uint16_t WM8960_PLL_N_PLLPRESCALE_EN
Definition WM8960.h:187
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MN1_CON
Definition WM8960.h:164
static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_O1ZC_ZC
Definition WM8960.h:56
static constexpr uint16_t WM8960_LOUT2_ROUT2_VOL_SPKRVOL_6dB
Definition WM8960.h:181
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_1_5
Definition WM8960.h:60
static constexpr uint16_t WM8960_PWR_MGMT3_RMIC_UP
Definition WM8960.h:183
static constexpr uint16_t WM8960_MONO_OUT_MIX1_MIX2_2MO_DI
Definition WM8960.h:176
static constexpr uint16_t WM8960_PWR_MGMT1_VMIDSEL_50K
Definition WM8960.h:146
static constexpr uint16_t WM8960_RIGHT_OUT_MIX_RI2RO_EN
Definition WM8960.h:175
static constexpr uint16_t WM8960_CLK1_CLKSEL_MCLK
Definition WM8960.h:75
static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_I2S_MODE
Definition WM8960.h:105
static constexpr int WM8960_I2C_ADDRESS
Definition WM8960.h:49
static constexpr uint16_t WM8960_PWR_MGMT3_LMIC_UP
Definition WM8960.h:182
static constexpr uint16_t WM8960_AUDIO_INTF0_LRP_INV
Definition WM8960.h:98
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_4
Definition WM8960.h:109
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MP3_CON
Definition WM8960.h:165
static constexpr uint16_t WM8960_PWR_MGMT3_LOMIX_UP
Definition WM8960.h:184
static constexpr uint16_t WM8960_3D_CTR_3DDEPTH_100
Definition WM8960.h:141
static constexpr uint16_t WM8960_CTR1_DEEMPH_44_1_KHZ
Definition WM8960.h:84
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_2
Definition WM8960.h:107
static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_3
Definition WM8960.h:192
static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_DSP_MODE
Definition WM8960.h:106
static constexpr uint16_t WM8960_PWR_MGMT3_ROMIX_UP
Definition WM8960.h:185
static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_IZC_ZC
Definition WM8960.h:52
static constexpr uint16_t WM8960_PWR_MGMT2_SPKR_UP
Definition WM8960.h:161
static constexpr uint16_t WM8960_PWR_MGMT1_VMIDSEL_5K
Definition WM8960.h:148
wm8960_mode_t
Definition WM8960.h:318
@ WM8960_MODE_MASTER
Definition WM8960.h:319
@ WM8960_MODE_SLAVE
Definition WM8960.h:320
static constexpr uint16_t WM8960_AUDIO_INTF1_ALRCGPIO_GPIO
Definition WM8960.h:127
static constexpr uint16_t WM8960_PWR_MGMT1_VMIDSEL_250K
Definition WM8960.h:147
static constexpr uint16_t WM8960_PWR_MGMT2_OUT3_UP
Definition WM8960.h:162
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_3
Definition WM8960.h:69
static constexpr uint16_t WM8960_AUDIO_INTF1_LOOPBACK_EN
Definition WM8960.h:133
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_22
Definition WM8960.h:124
_wm8960_sysclk_freq_t
Definition WM8960.h:326
@ _WM8960_SYSCLK_FREQ_11289600_HZ
Definition WM8960.h:328
@ _WM8960_SYSCLK_FREQ_12288000_HZ
Definition WM8960.h:327
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_24
Definition WM8960.h:125
static constexpr uint16_t WM8960_LOUT1_ROUT1_VOL_OUT1VOL_6dB
Definition WM8960.h:58
static constexpr uint16_t WM8960_AUDIO_INTF1_DACCOMP_ALAW
Definition WM8960.h:129
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_6
Definition WM8960.h:65
static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_4
Definition WM8960.h:193
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_2
Definition WM8960.h:68
static constexpr uint16_t WM8960_LEFT_RIGHT_DAC_VOL_DACVU_UP
Definition WM8960.h:134
static constexpr uint32_t WM8960_TIMEOUT_MS
Definition WM8960.h:197
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_16
Definition WM8960.h:113
static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_5_5
Definition WM8960.h:194
static constexpr uint16_t WM8960_CTR1_ADCPOL_R_INV
Definition WM8960.h:80
static constexpr uint16_t WM8960_AUDIO_INTF0_WL_24BITS
Definition WM8960.h:101
static constexpr uint16_t WM8960_LEFT_OUT_MIX_LD2LO_EN
Definition WM8960.h:172
static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_IPVU
Definition WM8960.h:50
static constexpr uint16_t WM8960_AUDIO_INTF0_FORMAT_L_JUSTIF
Definition WM8960.h:104
static constexpr uint16_t WM8960_PWR_MGMT1_ADCL_UP
Definition WM8960.h:152
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_5_5
Definition WM8960.h:71
static constexpr uint16_t WM8960_CTR1_DACDIV2_6B_EN
Definition WM8960.h:77
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_5_5
Definition WM8960.h:118
static constexpr uint16_t WM8960_LEFT_RIGHT_DAC_VOL_127dB
Definition WM8960.h:136
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_13dB
Definition WM8960.h:168
static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_1
Definition WM8960.h:190
static constexpr uint16_t WM8960_3D_CTR_3DUC_HIGH
Definition WM8960.h:138
static constexpr uint16_t WM8960_PWR_MGMT2_DACR_UP
Definition WM8960.h:157
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_1_5
Definition WM8960.h:67
static constexpr uint16_t WM8960_CLK1_SYSCLKDIV_BY_1
Definition WM8960.h:73
static constexpr uint16_t WM8960_LEFT_RIGHT_DAC_VOL_0dB
Definition WM8960.h:135
static constexpr uint16_t WM8960_LEFT_RIGHT_IN_VOL_INVOL_0dB
Definition WM8960.h:53
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MICBOOST_0dB
Definition WM8960.h:167
static constexpr uint16_t WM8960_CTR2_DACSMM_GRAD
Definition WM8960.h:90
static constexpr uint16_t WM8960_PLL_N_SDM_FRAC
Definition WM8960.h:189
static constexpr uint16_t WM8960_AUDIO_INTF0_DLRSWAP
Definition WM8960.h:97
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_11
Definition WM8960.h:121
static constexpr uint16_t WM8960_PWR_MGMT2_PLL_EN_UP
Definition WM8960.h:163
wm8960_features_t
Definition WM8960.h:275
@ WM8960_FEATURE_HEADPHONE
Definition WM8960.h:280
@ WM8960_FEATURE_MICROPHONE1
Definition WM8960.h:277
@ WM8960_FEATURE_SPEAKER
Definition WM8960.h:281
@ WM8960_FEATURE_MICROPHONE2
Definition WM8960.h:278
@ WM8960_FEATURE_MICROPHONE3
Definition WM8960.h:279
@ WM8960_FEATURE_NONE
Definition WM8960.h:276
static constexpr uint16_t WM8960_CLK1_DACDIV_BY_1
Definition WM8960.h:66
static constexpr uint16_t WM8960_CTR1_DEEMPH_48_KHZ
Definition WM8960.h:83
static constexpr uint16_t WM8960_CTR1_ADCPOL_LR_INV
Definition WM8960.h:78
static constexpr uint8_t WM8960_FEATURE_MICROPHONES
Definition WM8960.h:284
static constexpr uint16_t WM8960_CTR1_ADCHPD_DIS
Definition WM8960.h:86
static constexpr uint16_t WM8960_AUDIO_INTF0_WL_16BITS
Definition WM8960.h:99
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_4
Definition WM8960.h:117
static constexpr uint32_t REGISTER_MAP_SIZE
Definition WM8960.h:198
static constexpr uint16_t WM8960_LEFT_RIGHT_ADC_VOL_ADCVU_UP
Definition WM8960.h:143
static constexpr uint16_t WM8960_PLL_N_OPCLKDIV_BY_2
Definition WM8960.h:191
static constexpr uint16_t WM8960_ADCL_ADCR_SIG_PTH_MIC2B_CON
Definition WM8960.h:171
static constexpr uint16_t WM8960_CLK1_ADCDIV_BY_1
Definition WM8960.h:59
static constexpr uint16_t WM8960_CLK2_DCLKDIV_BY_8
Definition WM8960.h:111
static constexpr uint16_t WM8960_PWR_MGMT1_AINL_UP
Definition WM8960.h:150
static constexpr uint16_t WM8960_PWR_MGMT2_SPKL_UP
Definition WM8960.h:160
static constexpr uint16_t WM8960_CTR2_DACPOL_L_INV
Definition WM8960.h:88
static constexpr bool MTB_RSLT_WM8960_BAD_ARG
Definition WM8960.h:196
static constexpr uint16_t WM8960_CLK2_BCLKDIV_BY_8
Definition WM8960.h:120
static constexpr uint16_t WM8960_LEFT_RIGHT_ADC_VOL_ADCVOL_0dB
Definition WM8960.h:144
void * i2c_bus_handle_t
Definition DriverCommon.h:155
static constexpr uint16_t WM8960_CLK1_CLKSEL_PLL
Definition WM8960.h:76
static constexpr uint16_t WM8960_PWR_MGMT1_DIGENB_DI
Definition WM8960.h:155
static constexpr uint16_t WM8960_PWR_MGMT1_AINR_UP
Definition WM8960.h:151
Definition WM8960.h:331
wm8960_reg_t reg
Definition WM8960.h:333
uint16_t value
Definition WM8960.h:334
uint8_t features
Definition WM8960.h:332