|
arduino-audio-driver
|
Header only C++ driver for the MAX98091 audio codec. More...
#include <MAX98091.h>
Public Member Functions | |
| MAX98091 () | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| bool | begin (MAX98091Protocol protocol=MAX98091Protocol::I2S, uint32_t sample_rate=44100, uint32_t mclk_freq=12000000, uint8_t word_size=16, uint8_t channels=2, bool playback=true) |
| bool | begin (uint32_t sample_rate, uint8_t bits) |
| Initialize the codec: soft reset, configure the system clock, digital audio interface protocol, sample rate and word size, and (if playback is true) configure the default output (speaker/headphone) 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 | configureOutput () |
| Configure the default playback path: route the DAC to the speaker mixers, select DAC-only source for the headphone mixer, enable the headphone and/or speaker outputs (depending on the output device selected via setDevices()) and set the default volume. | |
| 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. | |
| virtual bool | isInputVolumeSupported () |
| Returns true if the driver supports setting the input volume, false otherwise. By default we return false, but some drivers (e.g. WM8962) override this to return true. | |
| bool | readRevisionId (uint8_t &id) |
| virtual bool | setActive (codec_mode_t mode) |
| void | setAddress (uint8_t addr) |
| Defines the I2C address of the codec. | |
| bool | setAudioFormat (uint32_t sample_rate, uint8_t word_size=16, uint8_t channels=2) |
| Configure the sample rate, channel count and word size of the digital audio interface. | |
| bool | setDevices (input_device_t input_device, output_device_t output_device) override |
| Stores the output device selection for use by configureOutput() | |
| virtual bool | setInputVolume (int volume) |
| bool | setMute (bool mute) override |
| Mutes/unmutes all outputs. | |
| bool | setOutputMute (bool mute, MAX98091Channel channel=MAX98091Channel::All) |
| Mute / unmute the output for the given channel(s) | |
| bool | setOutputVolume (uint8_t volume, MAX98091Channel channel=MAX98091Channel::All) |
| bool | setProtocol (MAX98091Protocol protocol) |
| Configure the digital audio interface protocol (slave mode) | |
| bool | setSystemClock (uint32_t mclk_freq) |
| Configure the master clock pre-scaler (PSCLK) based on the MCLK frequency, and ensure the codec remains in slave mode. | |
| 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. | |
Static Public Attributes | |
| static constexpr uint8_t | BCI_MASK = (1 << 3) |
| static constexpr uint8_t | DALEN_MASK = (1 << 0) |
| static constexpr uint8_t | DAREN_MASK = (1 << 1) |
| static constexpr uint8_t | DEFAULT_VOLUME = 0x2A |
| static constexpr uint8_t | DLY_MASK = (1 << 2) |
| static constexpr uint8_t | DMONO_MASK = (1 << 3) |
| static constexpr uint8_t | HIZOFF_MASK = (1 << 2) |
| static constexpr uint8_t | HPLEN_MASK = (1 << 6) |
| static constexpr uint8_t | HPLM_MASK = (1 << 7) |
| static constexpr uint8_t | HPREN_MASK = (1 << 7) |
| static constexpr uint8_t | HPVOLL_MASK = (31 << 0) |
| static constexpr uint8_t | I2S_M_MASK = (1 << 1) |
| static constexpr uint8_t | I2S_S_MASK = (1 << 0) |
| static constexpr uint8_t | LBEN_MASK = (1 << 4) |
| static constexpr uint8_t | LJ_M_MASK = (1 << 3) |
| static constexpr uint8_t | LJ_S_MASK = (1 << 2) |
| static constexpr uint8_t | LTEN_MASK = (1 << 5) |
| static constexpr uint8_t | MAS_MASK = (1 << 7) |
| static constexpr uint8_t | MIXHPL_DACL_MASK = (1 << 0) |
| static constexpr uint8_t | MIXHPL_DACR_MASK = (1 << 1) |
| static constexpr uint8_t | MIXHPL_LINEA_MASK = (1 << 2) |
| static constexpr uint8_t | MIXHPL_LINEB_MASK = (1 << 3) |
| static constexpr uint8_t | MIXHPL_MASK = (63 << 0) |
| static constexpr uint8_t | MIXHPL_MIC1_MASK = (1 << 4) |
| static constexpr uint8_t | MIXHPL_MIC2_MASK = (1 << 5) |
| static constexpr uint8_t | MIXHPLG_MASK = (3 << 0) |
| static constexpr uint8_t | MIXHPLSEL_MASK = (1 << 4) |
| static constexpr uint8_t | MIXHPR_DACL_MASK = (1 << 0) |
| static constexpr uint8_t | MIXHPR_DACR_MASK = (1 << 1) |
| static constexpr uint8_t | MIXHPR_LINEA_MASK = (1 << 2) |
| static constexpr uint8_t | MIXHPR_LINEB_MASK = (1 << 3) |
| static constexpr uint8_t | MIXHPR_MASK = (63 << 0) |
| static constexpr uint8_t | MIXHPR_MIC1_MASK = (1 << 4) |
| static constexpr uint8_t | MIXHPR_MIC2_MASK = (1 << 5) |
| static constexpr uint8_t | MIXHPRG_MASK = (3 << 2) |
| static constexpr uint8_t | MIXHPRSEL_MASK = (1 << 5) |
| static constexpr uint8_t | MIXSPL_DACL_MASK = (1 << 0) |
| static constexpr uint8_t | MIXSPL_DACR_MASK = (1 << 1) |
| static constexpr uint8_t | MIXSPL_LINEA_MASK = (1 << 2) |
| static constexpr uint8_t | MIXSPL_LINEB_MASK = (1 << 3) |
| static constexpr uint8_t | MIXSPL_MASK = (63 << 0) |
| static constexpr uint8_t | MIXSPL_MIC1_MASK = (1 << 4) |
| static constexpr uint8_t | MIXSPL_MIC2_MASK = (1 << 5) |
| static constexpr uint8_t | MIXSPLG_MASK = (3 << 0) |
| static constexpr uint8_t | MIXSPR_DACL_MASK = (1 << 0) |
| static constexpr uint8_t | MIXSPR_DACR_MASK = (1 << 1) |
| static constexpr uint8_t | MIXSPR_LINEA_MASK = (1 << 2) |
| static constexpr uint8_t | MIXSPR_LINEB_MASK = (1 << 3) |
| static constexpr uint8_t | MIXSPR_MASK = (63 << 0) |
| static constexpr uint8_t | MIXSPR_MIC1_MASK = (1 << 4) |
| static constexpr uint8_t | MIXSPR_MIC2_MASK = (1 << 5) |
| static constexpr uint8_t | MIXSPRG_MASK = (3 << 2) |
| static constexpr uint8_t | PSCLK_DISABLED = (0 << 4) |
| static constexpr uint8_t | PSCLK_DIV1 = (1 << 4) |
| static constexpr uint8_t | PSCLK_DIV2 = (2 << 4) |
| static constexpr uint8_t | PSCLK_DIV4 = (3 << 4) |
| static constexpr uint8_t | RCVLEN_MASK = (1 << 3) |
| static constexpr uint8_t | RCVREN_MASK = (1 << 2) |
| static constexpr uint8_t | REVA = 0x50 |
| static constexpr uint8_t | RJ_M_MASK = (1 << 5) |
| static constexpr uint8_t | RJ_MASK = (1 << 5) |
| static constexpr uint8_t | RJ_S_MASK = (1 << 4) |
| static constexpr uint8_t | SDIEN_MASK = (1 << 0) |
| static constexpr uint8_t | SDOEN_MASK = (1 << 1) |
| static constexpr uint8_t | SHDNN_MASK = (1 << 7) |
| static constexpr uint8_t | SPK_SLAVE_MASK = (1 << 6) |
| static constexpr uint8_t | SPLEN_MASK = (1 << 4) |
| static constexpr uint8_t | SPLM_MASK = (1 << 7) |
| static constexpr uint8_t | SPREN_MASK = (1 << 5) |
| static constexpr uint8_t | SPVOLL_MASK = (63 << 0) |
| static constexpr uint8_t | SR_16K_MASK = (1 << 1) |
| static constexpr uint8_t | SR_32K_MASK = (1 << 4) |
| static constexpr uint8_t | SR_44K1_MASK = (1 << 2) |
| static constexpr uint8_t | SR_48K_MASK = (1 << 3) |
| static constexpr uint8_t | SR_8K_MASK = (1 << 0) |
| static constexpr uint8_t | SR_96K_MASK = (1 << 5) |
| static constexpr uint8_t | SWRESET_MASK = (1 << 7) |
| static constexpr uint8_t | WCI_MASK = (1 << 4) |
| static constexpr uint8_t | WS_16B = (0 << 0) |
| static constexpr uint8_t | WS_MASK = (3 << 0) |
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 | setVolumeOrMute (MAX98091Channel channel, uint8_t value, bool is_volume) |
| 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 MAX98091 audio codec.
Provides a soft reset, basic playback configuration (protocol, sample rate, word size, system clock) and output 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 |
|
inline |
Initialize the codec: soft reset, configure the system clock, digital audio interface protocol, sample rate and word size, and (if playback is true) configure the default output (speaker/headphone) path.
| protocol | Digital audio interface protocol (slave mode) |
| sample_rate | I2S sample rate in Hz (8000, 16000, 32000, 44100, 48000 or 96000) |
| mclk_freq | MCLK frequency in Hz (10MHz .. 60MHz) |
| word_size | I2S word size in bits (only 16 bits is supported) |
| channels | number of channels (1 = mono, 2 = stereo) |
| playback | enable & configure the output (speaker/headphone) 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 path if mode includes CODEC_MODE_DECODE, using the given I2S data format and number of channels. This chip only supports slave mode, so is_master is ignored.
Implements ZephyrDriverCommon.
|
inline |
Configure the default playback path: route the DAC to the speaker mixers, select DAC-only source for the headphone mixer, enable the headphone and/or speaker outputs (depending on the output device selected via setDevices()) and set the default volume.
|
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.
|
inlinevirtualinherited |
|
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 |
Read the device revision ID register (REG_REVISION_ID). Valid MAX98091 devices report a value in the range REVA..REVA+0x0F.
|
inlinevirtualinherited |
Activates/deactivates the playback and/or capture path at runtime (without reconfiguring the codec), based on codec_mode_t (CODEC_MODE_DECODE: playback active, CODEC_MODE_ENCODE: capture active). By default this just mutes/unmutes all outputs depending on CODEC_MODE_DECODE; chip specific subclasses that support muting the input path independently override this to also mute/unmute the capture path depending on CODEC_MODE_ENCODE.
|
inlineinherited |
Defines the I2C address of the codec.
|
inline |
Configure the sample rate, channel count and word size of the digital audio interface.
| sample_rate | sample rate in Hz (8000, 16000, 32000, 44100, 48000 or 96000) |
| word_size | word size in bits (only 16 bits is supported) |
| channels | number of channels (1 = mono, 2 = stereo) |
|
inlineoverridevirtual |
Stores the output device selection for use by configureOutput()
Reimplemented from ZephyrDriverCommon.
|
inlinevirtualinherited |
|
inlineoverridevirtual |
Mutes/unmutes all outputs.
Reimplemented from ZephyrDriverCommon.
|
inline |
Mute / unmute the output for the given channel(s)
|
inline |
Set the output volume for the given channel(s). Range 0..31 for headphone channels, 0..63 for speaker channels.
|
inline |
Configure the digital audio interface protocol (slave mode)
|
inline |
Configure the master clock pre-scaler (PSCLK) based on the MCLK frequency, and ensure the codec remains in slave mode.
| mclk_freq | MCLK frequency in Hz, in the range 10MHz .. 60MHz |
|
inlineoverridevirtual |
Sets the output volume in % (0...100) for all channels.
Reimplemented from ZephyrDriverCommon.
|
inlineprotected |
|
inlineinherited |
Defines the I2C communication object.
|
inline |
Soft reset of the codec.
|
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.
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last input volume (in %) provided to setInputVolume()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protected |
Output device selection set via setDevices(), used by configureOutput()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
staticconstexpr |
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |