|
|
|
@ -1,10 +1,13 @@ |
|
|
|
|
/*
|
|
|
|
|
* BAAudioControlWM8731.h |
|
|
|
|
/**************************************************************************//**
|
|
|
|
|
* BAAudioContromWM8731 is a class for controlling a WM8731 Codec via I2C. |
|
|
|
|
* @details The Codec power ups in a silent state, with non-optimal |
|
|
|
|
* configuration. This class will enable codec and set some initial gain levels. |
|
|
|
|
* The user can than use the API to changing settings for their specific needs. |
|
|
|
|
* |
|
|
|
|
* Created on: May 22, 2017 |
|
|
|
|
* Author: slascos |
|
|
|
|
* |
|
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
|
|
|
* @file |
|
|
|
|
* @author Steve Lascos |
|
|
|
|
* @company Blackaddr Audio |
|
|
|
|
* @copyright This program is free software: you can redistribute it and/or modify |
|
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
|
|
|
* (at your option) any later version.* |
|
|
|
@ -16,7 +19,7 @@ |
|
|
|
|
* |
|
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/ |
|
|
|
|
*****************************************************************************/ |
|
|
|
|
|
|
|
|
|
#ifndef INC_BAAUDIOCONTROLWM8731_H_ |
|
|
|
|
#define INC_BAAUDIOCONTROLWM8731_H_ |
|
|
|
@ -25,90 +28,96 @@ |
|
|
|
|
|
|
|
|
|
namespace BAGuitar { |
|
|
|
|
|
|
|
|
|
// use const instead of define for proper scoping
|
|
|
|
|
constexpr int WM8731_I2C_ADDR = 0x1A; |
|
|
|
|
constexpr int WM8731_NUM_REGS = 10; |
|
|
|
|
|
|
|
|
|
constexpr int WM8731_REG_LLINEIN = 0; |
|
|
|
|
constexpr int WM8731_REG_RLINEIN = 1; |
|
|
|
|
constexpr int WM8731_REG_LHEADOUT = 2; |
|
|
|
|
constexpr int WM8731_REG_RHEADOUT = 3; |
|
|
|
|
constexpr int WM8731_REG_ANALOG =4; |
|
|
|
|
constexpr int WM8731_REG_DIGITAL = 5; |
|
|
|
|
constexpr int WM8731_REG_POWERDOWN = 6; |
|
|
|
|
constexpr int WM8731_REG_INTERFACE = 7; |
|
|
|
|
constexpr int WM8731_REG_SAMPLING = 8; |
|
|
|
|
constexpr int WM8731_REG_ACTIVE = 9; |
|
|
|
|
constexpr int WM8731_REG_RESET = 15; |
|
|
|
|
|
|
|
|
|
// Register Masks and Shifts
|
|
|
|
|
// Register 0
|
|
|
|
|
constexpr int WM8731_LEFT_INPUT_GAIN_ADDR = 0; |
|
|
|
|
constexpr int WM8731_LEFT_INPUT_GAIN_MASK = 0x1F; |
|
|
|
|
constexpr int WM8731_LEFT_INPUT_GAIN_SHIFT = 0; |
|
|
|
|
constexpr int WM8731_LEFT_INPUT_MUTE_ADDR = 0; |
|
|
|
|
constexpr int WM8731_LEFT_INPUT_MUTE_MASK = 0x80; |
|
|
|
|
constexpr int WM8731_LEFT_INPUT_MUTE_SHIFT = 7; |
|
|
|
|
constexpr int WM8731_LINK_LEFT_RIGHT_IN_ADDR = 0; |
|
|
|
|
constexpr int WM8731_LINK_LEFT_RIGHT_IN_MASK = 0x100; |
|
|
|
|
constexpr int WM8731_LINK_LEFT_RIGHT_IN_SHIFT = 8; |
|
|
|
|
// Register 1
|
|
|
|
|
constexpr int WM8731_RIGHT_INPUT_GAIN_ADDR = 1; |
|
|
|
|
constexpr int WM8731_RIGHT_INPUT_GAIN_MASK = 0x1F; |
|
|
|
|
constexpr int WM8731_RIGHT_INPUT_GAIN_SHIFT = 0; |
|
|
|
|
constexpr int WM8731_RIGHT_INPUT_MUTE_ADDR = 1; |
|
|
|
|
constexpr int WM8731_RIGHT_INPUT_MUTE_MASK = 0x80; |
|
|
|
|
constexpr int WM8731_RIGHT_INPUT_MUTE_SHIFT = 7; |
|
|
|
|
constexpr int WM8731_LINK_RIGHT_LEFT_IN_ADDR = 1; |
|
|
|
|
constexpr int WM8731_LINK_RIGHT_LEFT_IN_MASK = 0x100; |
|
|
|
|
constexpr int WM8731_LINK_RIGHT_LEFT_IN_SHIFT = 8; |
|
|
|
|
// Register 4
|
|
|
|
|
constexpr int WM8731_ADC_BYPASS_ADDR = 4; |
|
|
|
|
constexpr int WM8731_ADC_BYPASS_MASK = 0x8; |
|
|
|
|
constexpr int WM8731_ADC_BYPASS_SHIFT = 3; |
|
|
|
|
constexpr int WM8731_DAC_SELECT_ADDR = 4; |
|
|
|
|
constexpr int WM8731_DAC_SELECT_MASK = 0x10; |
|
|
|
|
constexpr int WM8731_DAC_SELECT_SHIFT = 4; |
|
|
|
|
// Register 5
|
|
|
|
|
constexpr int WM8731_DAC_MUTE_ADDR = 5; |
|
|
|
|
constexpr int WM8731_DAC_MUTE_MASK = 0x8; |
|
|
|
|
constexpr int WM8731_DAC_MUTE_SHIFT = 3; |
|
|
|
|
constexpr int WM8731_HPF_DISABLE_ADDR = 5; |
|
|
|
|
constexpr int WM8731_HPF_DISABLE_MASK = 0x1; |
|
|
|
|
constexpr int WM8731_HPF_DISABLE_SHIFT = 0; |
|
|
|
|
|
|
|
|
|
// Register 9
|
|
|
|
|
constexpr int WM8731_ACTIVATE_ADDR = 9; |
|
|
|
|
constexpr int WM8731_ACTIVATE_MASK = 0x1; |
|
|
|
|
|
|
|
|
|
constexpr int WM8731_NUM_REGS = 10; // Number of registers in the internal shadow array
|
|
|
|
|
|
|
|
|
|
/**************************************************************************//**
|
|
|
|
|
* BAAudioControlWM8731 provides an API for configuring the internal registers |
|
|
|
|
* of the WM8731 codec. |
|
|
|
|
* @details Not every single command is provided, please ask if you need something |
|
|
|
|
* added that is not already present. You can also directly write any register |
|
|
|
|
* you wish with the writeI2C() method. |
|
|
|
|
*****************************************************************************/ |
|
|
|
|
class BAAudioControlWM8731 { |
|
|
|
|
public: |
|
|
|
|
BAAudioControlWM8731(); |
|
|
|
|
virtual ~BAAudioControlWM8731(); |
|
|
|
|
|
|
|
|
|
/// Mute and power down the codec.
|
|
|
|
|
void disable(void); |
|
|
|
|
bool enable(void); |
|
|
|
|
|
|
|
|
|
/// First disable, then cleanly power up and unmute the codec.
|
|
|
|
|
void enable(void); |
|
|
|
|
|
|
|
|
|
/// Set the input gain of the codec's PGA for the left (TRS Tip) channel.
|
|
|
|
|
/// @param val an interger value from 31 = +12dB . . 1.5dB steps down to 0 = -34.5dB
|
|
|
|
|
void setLeftInputGain(int val); |
|
|
|
|
|
|
|
|
|
/// Set the input gain of the codec's PGA for the right (TRS Ring) channel.
|
|
|
|
|
/// @param val an interger value from 31 = +12dB . . 1.5dB steps down to 0 = -34.5dB
|
|
|
|
|
void setRightInputGain(int val); |
|
|
|
|
|
|
|
|
|
/// Mute/unmute the Left (TRS Tip) channel at the ADC input.
|
|
|
|
|
/// @param val when true, channel is muted, when false, channel is unmuted
|
|
|
|
|
void setLeftInMute(bool val); |
|
|
|
|
|
|
|
|
|
/// Mute/unmute the Right (TRS Ring) channel at the ADC input.
|
|
|
|
|
/// @param val when true, channel is muted, when false, channel is unmuted
|
|
|
|
|
void setRightInMute(bool val); |
|
|
|
|
|
|
|
|
|
/// Links the Left/Right channel contols for mute and input gain.
|
|
|
|
|
/// @details when true, changing either the left or right gain/mute controls will
|
|
|
|
|
/// affect both channels.
|
|
|
|
|
/// @param val when true, channels are linked, when false, they are controlled separately
|
|
|
|
|
void setLinkLeftRightIn(bool val); |
|
|
|
|
|
|
|
|
|
/// Mute/unmute the output DAC, affects both Left and Right output channels.
|
|
|
|
|
/// @param when true, output DAC is muted, when false, unmuted.
|
|
|
|
|
void setDacMute(bool val); |
|
|
|
|
|
|
|
|
|
/// Control when the DAC is feeding the output analog circuitry.
|
|
|
|
|
/// @param val when true, the DAC output is connected to the analog output. When
|
|
|
|
|
/// false, the DAC is disconnected.
|
|
|
|
|
void setDacSelect(bool val); |
|
|
|
|
|
|
|
|
|
/// ADC Bypass control.
|
|
|
|
|
/// @details This permits the analog audio from the Codec's PGA to bypass the ADC
|
|
|
|
|
/// and go directly to the analog output of the codec, bypassing the digital domain
|
|
|
|
|
/// entirely.
|
|
|
|
|
/// @param val when true, analog ADC input is fed directly to codec analog otuput.
|
|
|
|
|
void setAdcBypass(bool val); |
|
|
|
|
void setHPFDisable(bool val); |
|
|
|
|
|
|
|
|
|
/// Digital High Pass Filter disable. RECOMMENDED ALWAYS TRUE!
|
|
|
|
|
/// @details this controls a HPF in the codec that attempts to remove the lowest
|
|
|
|
|
/// frequency (i.e. < 10 Hz) to improve headroom by dynamically measuring DC level.
|
|
|
|
|
/// In most cases, it introduces noise components by modulating the filter. This
|
|
|
|
|
/// is not suitable for applications where the audio is used for output, but might
|
|
|
|
|
/// be useful for applications like tuning, pitch detection, whre the noise components
|
|
|
|
|
/// can be tolerated.
|
|
|
|
|
/// @param val when true (recommended) the dynamic HPF is disabled, otherwise enabled.
|
|
|
|
|
void setHPFDisable(bool val); |
|
|
|
|
|
|
|
|
|
/// Activates the I2S interface on the codec.
|
|
|
|
|
/// @param val when true, I2S interface is active, when false it is disabled.
|
|
|
|
|
void setActivate(bool val); |
|
|
|
|
|
|
|
|
|
/// Soft-reset the codec.
|
|
|
|
|
/// @details This will cause the codec to reset its internal registers to default values.
|
|
|
|
|
void resetCodec(void); |
|
|
|
|
|
|
|
|
|
/// Write a custom command to the codec via I2C control interface.
|
|
|
|
|
/// @details See WM8731 datasheet for register map details.
|
|
|
|
|
/// @param addr The register address you wish to write to, range 0 to 15.
|
|
|
|
|
/// @param val the 9-bit data value you wish to write at the address specifed.
|
|
|
|
|
void writeI2C(unsigned int addr, unsigned int val); |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
// A shadow array for the registers on the codec since the interface is write-only.
|
|
|
|
|
int regArray[WM8731_NUM_REGS]; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
// low-level write command
|
|
|
|
|
bool write(unsigned int reg, unsigned int val); |
|
|
|
|
// resets the internal shadow register array
|
|
|
|
|
void resetInternalReg(void); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|