|
arduino-audio-driver
|
Header only C++ driver for the WM8962 audio codec. More...
#include <WM8962.h>
Public Member Functions | |
| WM8962 () | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| bool | applyProperties () |
| Apply pending volume changes (set VU bit for output and input) | |
| 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 sequences, configure the digital audio interface protocol, sample rate / word size and (optionally) enable the playback and/or capture path. | |
| bool | begin (uint32_t sample_rate, uint8_t bits, codec_mode_t mode, i2s_format_t fmt, bool is_master, uint8_t channels) override |
| 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) |
| bool | configureInput () |
| Configure the default input path: route input1/input3, default volume, unmuted. | |
| bool | configureOutput () |
| virtual int | getInputVolume () |
| virtual int | getVolume () |
| Provides the output volume in % (0...100) that was set with setVolume() | |
| i2c_bus_handle_t | getWire () |
| Provides the actual I2C communication object. | |
| bool | isInputVolumeSupported () override |
| Returns true: the input volume is supported. | |
| bool | routeInput (WM8962InputPgaSource source, WM8962Channel channel) |
| Select the input PGA source for the given channel (FrontLeft / FrontRight only). | |
| 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 as-is). | |
| bool | runSequence (WM8962Sequence id) |
| Trigger one of the codec's built-in write sequences and wait (up to the documented timeout) until it has completed. | |
| bool | setActive (codec_mode_t mode) override |
| void | setAddress (uint8_t addr) |
| Defines the I2C address of the codec. | |
| 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 = sysclk/fs ratio). | |
| bool | setDevices (input_device_t input_device, output_device_t output_device) override |
| Stores the output device selection for use by configureOutput() | |
| bool | setInputMute (bool mute, WM8962Channel channel=WM8962Channel::All) |
| Mute / unmute the input for the given channel(s) | |
| bool | setInputVolume (int volume) override |
| Sets the input volume in % (0...100) for all channels. | |
| bool | setInputVolume (uint8_t volume, WM8962Channel channel=WM8962Channel::All) |
| Set the input volume for the given channel(s) (6 bit value) | |
| bool | setMute (bool mute) override |
| Mutes/unmutes all outputs. | |
| bool | setOutputMute (bool mute, WM8962Channel channel=WM8962Channel::All) |
| Mute / unmute the output for the given channel(s) | |
| bool | setOutputVolume (uint8_t volume, WM8962Channel channel=WM8962Channel::All) |
| Set the output volume (0..127) for the given channel(s) | |
| bool | setProtocol (WM8962Protocol protocol) |
| Configure the digital audio interface protocol (I2S, LJ, RJ, PCMA/B) | |
| bool | setVolume (int volume) override |
| Sets the output volume in % (0...100) for all channels. | |
| void | setWire (i2c_bus_handle_t w) |
| Defines the I2C communication object. | |
| bool | softReset () |
| Soft reset of the codec (writes 0x6243 to REG_RESET) | |
Static Public Attributes | |
| static constexpr uint16_t | ADC_DEFAULT_VOLUME_VALUE = 0x1C0 |
| static constexpr uint16_t | ADC_MAX_VOLUME_VALUE = 0xFF |
| static constexpr uint16_t | CLOCK2_BCLK_DIV_MASK = 0x0F |
| static constexpr uint16_t | DAC_DEFAULT_VOLUME_VALUE = 0x1C0 |
| static constexpr uint16_t | DAC_MAX_VOLUME_VALUE = 0xFF |
| static constexpr uint16_t | HEADPHONE_DEFAULT_VOLUME_VALUE = 0x179 |
| static constexpr uint16_t | HEADPHONE_MAX_VOLUME_VALUE = 0x7F |
| static constexpr uint16_t | HEADPHONE_MIN_VOLUME_VALUE = 0x2F |
| static constexpr uint16_t | IFACE0_FORMAT_MASK = 0x13 |
| static constexpr uint16_t | IFACE0_WL_16BITS = 0x00 |
| static constexpr uint16_t | IFACE0_WL_20BITS = 0x01 |
| static constexpr uint16_t | IFACE0_WL_24BITS = 0x02 |
| static constexpr uint16_t | IFACE0_WL_32BITS = 0x03 |
| static constexpr uint16_t | IFACE0_WL_MASK = 0x0C |
| static constexpr uint16_t | IFACE0_WL_SHIFT = 0x02 |
| static constexpr uint16_t | L_CH_MUTE_MASK = 2 |
| static constexpr uint16_t | LINEIN_DEFAULT_VOLUME_VALUE = 0x12D |
| static constexpr uint16_t | LINEIN_MAX_VOLUME_VALUE = 0x3F |
| static constexpr uint16_t | R_CH_MUTE_MASK = 1 |
| static constexpr uint16_t | REGMASK_IN_MUTE = 0b010000000 |
| static constexpr uint16_t | REGMASK_IN_VOLUME = 0b000111111 |
| static constexpr uint16_t | REGMASK_IN_VU = 0b100000000 |
| static constexpr uint16_t | REGMASK_IN_ZC = 0b001000000 |
| static constexpr uint16_t | REGMASK_OUT_VOL = 0b001111111 |
| static constexpr uint16_t | REGMASK_OUT_VU = 0b100000000 |
| static constexpr uint16_t | REGMASK_OUT_ZC = 0b010000000 |
| static constexpr uint16_t | SPEAKER_DEFAULT_VOLUME_VALUE = 0x179 |
| static constexpr uint16_t | SPEAKER_MAX_VOLUME_VALUE = 0x7F |
| static constexpr uint16_t | SPEAKER_MIN_VOLUME_VALUE = 0x2F |
| static constexpr uint16_t | WSEQ_DONE_EINT_MASK = 0x80 |
| static constexpr uint16_t | WSEQ_ENA = 0x20 |
Protected Member Functions | |
| bool | readReg (uint8_t reg, uint8_t &value) |
| Reads a single byte from an 8 bit register address. | |
| bool | readReg16 (uint8_t reg, uint16_t &value) |
| Reads a 16 bit (big endian) value from an 8 bit register address. | |
| bool | readRegWide (uint16_t reg, uint16_t &value) |
| bool | updateInput (WM8962Channel channel, uint16_t val, uint16_t mask) |
| bool | updateOutput (WM8962Channel channel, uint16_t val, uint16_t mask) |
| bool | updateReg (uint8_t reg, uint8_t mask, uint8_t value) |
| Read-Modify-Write of a single byte register. | |
| bool | updateReg16 (uint8_t reg, uint16_t mask, uint16_t value) |
| Read-Modify-Write of a 16 bit (big endian) register. | |
| 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. | |
| bool | writeReg (uint8_t reg, uint8_t value) |
| Writes a single byte to an 8 bit register address. | |
| bool | writeReg16 (uint8_t reg, uint16_t value) |
| Writes a 16 bit (big endian) value to an 8 bit register address. | |
| bool | writeRegWide (uint16_t reg, uint16_t value) |
Protected Attributes | |
| uint8_t | i2c_addr = 0 |
| int | input_volume_percent = 100 |
| Last input volume (in %) provided to setInputVolume() | |
| output_device_t | output_device = DAC_OUTPUT_ALL |
| Output device selection set via setDevices(), used by configureOutput() | |
| int | volume_percent = 100 |
| Last volume (in %) provided to setVolume() | |
| i2c_bus_handle_t | wire = nullptr |
Header only C++ driver for the WM8962 audio codec.
The WM8962 register map extends beyond a single byte, therefore both the register address and the register value are transferred as 16 bit big endian quantities (4 bytes per write, 2+2 bytes per read).
Provides a soft reset, basic playback/capture configuration, input/output routing and output/input volume & mute control, ported from the corresponding Zephyr RTOS driver.
| enum Reg : uint16_t |
|
inline |
|
inlineinherited |
Provides the actual I2C address of the codec.
|
inline |
Apply pending volume changes (set VU bit for output and input)
|
inline |
Initialize the codec: soft reset, power up the analog/digital blocks, run the built-in write sequences, configure the digital audio interface protocol, sample rate / word size and (optionally) enable the playback and/or capture path.
| protocol | Digital audio interface protocol |
| sample_rate | I2S sample rate in Hz (e.g. 44100, 48000) |
| word_size | I2S word size in bits (16, 20, 24, 32) |
| mclk_to_fs_ratio | MCLK / sample-rate ratio (e.g. 256 for sysclk = 256 * fs); used to select the SYSCLK divider |
| playback | Enable & configure the output (headphone/speaker) path |
| capture | Enable & configure the input path Initializes the codec for I2S with the given sample rate and bits per sample |
|
inlineoverridevirtual |
Initializes the codec for I2S with the given sample rate, bits per sample, enabling the playback and/or capture path depending on mode and using the given I2S data format. The is_master and channels parameters are not configurable on this chip and are ignored.
Implements ZephyrDriverCommon.
|
inline |
|
inline |
Configure the default input path: route input1/input3, default volume, unmuted.
|
inline |
Configure the default output path: default volume, headphone (LINE1) and/or speaker (LINE2) output unmuted depending on the output device selected via setDevices()
|
inlinevirtualinherited |
Provides the input volume in % (0...100) that was set with setInputVolume()
|
inlinevirtualinherited |
Provides the output volume in % (0...100) that was set with setVolume()
|
inlineinherited |
Provides the actual I2C communication object.
|
inlineoverridevirtual |
Returns true: the input volume is supported.
Reimplemented from ZephyrDriverCommon.
|
inlineprotectedinherited |
Reads a single byte from an 8 bit register address.
|
inlineprotectedinherited |
Reads a 16 bit (big endian) value from an 8 bit register address.
|
inlineprotected |
Reads a 16 bit big endian register value addressed via a 16 bit big endian register address
|
inline |
Select the input PGA source for the given channel (FrontLeft / FrontRight only).
|
inline |
Select the output mixer source register for the given channel (the raw mixer-enable value is written as-is).
|
inline |
Trigger one of the codec's built-in write sequences and wait (up to the documented timeout) until it has completed.
|
inlineoverridevirtual |
Activates/deactivates the playback and/or capture path depending on codec_mode_t by muting/unmuting the output and input independently
Reimplemented from ZephyrDriverCommon.
|
inlineinherited |
Defines the I2C address of the codec.
|
inline |
Configure word size, sysclk/sample-rate divider (REG_ADDCTL3) and bit-clock divider (REG_CLK4 = sysclk/fs ratio).
| sample_rate | sample rate in Hz |
| word_size | word size in bits (16, 20, 24, 32) |
| mclk_to_fs_ratio | ratio between sysclk and the sample rate (e.g. 256, 512, ...) used to compute REG_CLK4 |
|
inlineoverridevirtual |
Stores the output device selection for use by configureOutput()
Reimplemented from ZephyrDriverCommon.
|
inline |
Mute / unmute the input for the given channel(s)
|
inlineoverridevirtual |
Sets the input volume in % (0...100) for all channels.
Reimplemented from ZephyrDriverCommon.
|
inline |
Set the input volume for the given channel(s) (6 bit value)
|
inlineoverridevirtual |
Mutes/unmutes all outputs.
Reimplemented from ZephyrDriverCommon.
|
inline |
Mute / unmute the output for the given channel(s)
|
inline |
Set the output volume (0..127) for the given channel(s)
|
inline |
Configure the digital audio interface protocol (I2S, LJ, RJ, PCMA/B)
|
inlineoverridevirtual |
Sets the output volume in % (0...100) for all channels.
Reimplemented from ZephyrDriverCommon.
|
inlineinherited |
Defines the I2C communication object.
|
inline |
Soft reset of the codec (writes 0x6243 to REG_RESET)
|
inlineprotected |
|
inlineprotected |
|
inlineprotectedinherited |
Read-Modify-Write of a single byte register.
|
inlineprotectedinherited |
Read-Modify-Write of a 16 bit (big endian) register.
|
inlineprotected |
Read-Modify-Write of a 16 bit register addressed via a 16 bit address.
|
inlineprotectedinherited |
Writes a single byte to an 8 bit register address.
|
inlineprotectedinherited |
Writes a 16 bit (big endian) value to an 8 bit register address.
|
inlineprotected |
Writes a 16 bit big endian register address followed by a 16 bit big endian register value (4 bytes total)
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last input volume (in %) provided to setInputVolume()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protected |
Output device selection set via setDevices(), used by configureOutput()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |