You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BALibrary/src/BAAudioControlWM8731.h

132 lines
5.5 KiB

/**************************************************************************//**
* @file
* @author Steve Lascos
* @company Blackaddr Audio
*
* 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.
7 years ago
*
* @copyright This program is free software: you can redistribute it and/or modify
7 years ago
* 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.*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
7 years ago
#ifndef __INC_BAAUDIOCONTROLWM8731_H
#define __INC_BAAUDIOCONTROLWM8731_H
7 years ago
namespace BAGuitar {
constexpr int WM8731_NUM_REGS = 10; // Number of registers in the internal shadow array
7 years ago
/**************************************************************************//**
* 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.
*****************************************************************************/
7 years ago
class BAAudioControlWM8731 {
public:
BAAudioControlWM8731();
virtual ~BAAudioControlWM8731();
/// Mute and power down the codec.
7 years ago
void disable(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
7 years ago
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
7 years ago
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
7 years ago
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
7 years ago
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
7 years ago
void setLinkLeftRightIn(bool val);
/// Swaps the left and right channels in the codec.
///param val when true, channels are swapped, else normal.
void setLeftRightSwap(bool val);
/// Mute/unmute the output DAC, affects both Left and Right output channels.
/// @param when true, output DAC is muted, when false, unmuted.
7 years ago
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.
7 years ago
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.
7 years ago
void setAdcBypass(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);
7 years ago
/// Activates the I2S interface on the codec.
/// @param val when true, I2S interface is active, when false it is disabled.
7 years ago
void setActivate(bool val);
/// Soft-reset the codec.
/// @details This will cause the codec to reset its internal registers to default values.
7 years ago
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.
bool writeI2C(unsigned int addr, unsigned int val);
7 years ago
protected:
// A shadow array for the registers on the codec since the interface is write-only.
7 years ago
int regArray[WM8731_NUM_REGS];
private:
// low-level write command
7 years ago
bool write(unsigned int reg, unsigned int val);
// resets the internal shadow register array
7 years ago
void resetInternalReg(void);
bool m_wireStarted = false;
7 years ago
};
} /* namespace BAGuitar */
#endif /* __INC_BAAUDIOCONTROLWM8731_H */