|
arduino-audio-driver
|
Header only C++ driver for the WM8904 audio codec. More...
#include <WM8904.h>
Public Member Functions | |
| WM8904 () | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| bool | applyProperties () |
| Apply the pending volume changes (set VU bit for both output channel pairs) | |
| bool | begin (uint32_t sample_rate, uint8_t bits) |
| Initialize the codec: soft reset, power up the analog/digital blocks, 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 (WM8904Protocol protocol=WM8904Protocol::I2S, uint32_t sample_rate=44100, uint8_t word_size=16, bool playback=true, bool capture=true) |
| bool | configureInput () |
| Configure the default input path: route input 2, 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 (uint32_t input, WM8904Channel channel=WM8904Channel::All) |
| Route an analog input (1..3) to the given channel's PGA. Only FrontLeft, FrontRight and All are valid channels. | |
| 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) |
| Configure the sample rate and word size of the digital audio interface. The SYSCLK / fs ratio is determined from the current REG_CLK_RATES_0 setting (assumes MCLK_DIV = 1, i.e. SYSCLK = MCLK / 2, matching the divider written in begin()). | |
| 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, WM8904Channel channel=WM8904Channel::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, WM8904Channel channel=WM8904Channel::All) |
| Set the input volume (0..31) for the given channel(s) | |
| bool | setMute (bool mute) override |
| Mutes/unmutes all outputs. | |
| bool | setOutputMute (bool mute, WM8904Channel channel=WM8904Channel::All) |
| Mute / unmute the output for the given channel(s) | |
| bool | setOutputVolume (uint8_t volume, WM8904Channel channel=WM8904Channel::All) |
| Set the output volume (0..63) for the given channel(s) | |
| bool | setProtocol (WM8904Protocol 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 0x00 to REG_RESET) | |
Static Public Attributes | |
| static constexpr uint16_t | INPUT_VOLUME_DEFAULT = 0b00101 |
| static constexpr uint16_t | INPUT_VOLUME_MAX = 0b11111 |
| static constexpr uint16_t | INPUT_VOLUME_MIN = 0b00000 |
| static constexpr uint16_t | OUTPUT_VOLUME_DEFAULT = 0b101101 |
| static constexpr uint16_t | OUTPUT_VOLUME_MAX = 0b111111 |
| static constexpr uint16_t | OUTPUT_VOLUME_MIN = 0b000000 |
| static constexpr uint8_t | REGMASK_IN_MUTE = 0b10000000 |
| static constexpr uint8_t | REGMASK_IN_VOLUME = 0b00011111 |
| static constexpr uint8_t | REGMASK_INSEL_CMENA = 0b01000000 |
| static constexpr uint8_t | REGMASK_INSEL_IP_SEL_N = 0b00110000 |
| static constexpr uint8_t | REGMASK_INSEL_IP_SEL_P = 0b00001100 |
| static constexpr uint8_t | REGMASK_INSEL_MODE = 0b00000011 |
| static constexpr uint16_t | REGMASK_OUT_MUTE = 0b100000000 |
| static constexpr uint16_t | REGMASK_OUT_VOL = 0b000111111 |
| static constexpr uint16_t | REGMASK_OUT_VU = 0b010000000 |
| static constexpr uint16_t | REGMASK_OUT_ZC = 0b001000000 |
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 | updateInput (WM8904Channel channel, uint8_t val, uint8_t mask) |
| bool | updateOutput (WM8904Channel 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 | 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. | |
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 WM8904 audio codec.
Provides a soft reset, basic playback/capture configuration, input routing and output/input volume & mute control, ported from the corresponding Zephyr RTOS driver.
| enum Reg : uint8_t |
|
inline |
|
inlineinherited |
Provides the actual I2C address of the codec.
|
inline |
Apply the pending volume changes (set VU bit for both output channel pairs)
|
inline |
Initialize the codec: soft reset, power up the analog/digital blocks, 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) |
| playback | Enable & configure the output (headphone/line) 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 input 2, default volume, unmuted.
|
inline |
Configure the default output path: default volume, headphone (LINE1) and/or line/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.
|
inline |
Route an analog input (1..3) to the given channel's PGA. Only FrontLeft, FrontRight and All are valid channels.
| input | input number 1..3 |
|
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 the sample rate and word size of the digital audio interface. The SYSCLK / fs ratio is determined from the current REG_CLK_RATES_0 setting (assumes MCLK_DIV = 1, i.e. SYSCLK = MCLK / 2, matching the divider written in begin()).
| sample_rate | sample rate in Hz |
| word_size | word size in bits (16, 20, 24, 32) |
|
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 (0..31) for the given channel(s)
|
inlineoverridevirtual |
Mutes/unmutes all outputs.
Reimplemented from ZephyrDriverCommon.
|
inline |
Mute / unmute the output for the given channel(s)
|
inline |
Set the output volume (0..63) 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 0x00 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.
|
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.
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last input volume (in %) provided to setInputVolume()
|
protected |
Output device selection set via setDevices(), used by configureOutput()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
protectedinherited |