Added software support for WM8731 Codec running in Master mode

pull/10/head
Steve Lascos 4 years ago
parent b6712dacb1
commit 9d4ac7ff74
  1. 5
      examples/BAExpansionCalibrate/BAExpansionCalibrate.ino
  2. 4
      examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino
  3. 2
      examples/Tests/TGA_PRO_MEM2_EXP/PhysicalControls.cpp
  4. 4
      examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino
  5. 1
      keywords.txt
  6. 19
      src/BAAudioControlWM8731.h
  7. 59
      src/peripherals/BAAudioControlWM8731.cpp

@ -13,9 +13,6 @@
* When prompted turn the appropriate POT in the specified direction and
* enter any character on the terminal input line and press enter to send the character.
*/
#define TGA_PRO_REVB // Specify our hardware revision
#define TGA_PRO_EXPAND_REV2 // Specify we are using the EXPANSION CONTROL BOARD REV2
#include "BALibrary.h"
using namespace BALibrary;
@ -27,6 +24,8 @@ void setup() {
delay(100);
Serial.begin(57600);
delay(500); // long delay to wait for Serial to init
TGA_PRO_EXPAND_REV2(); // Set the expansion board revision
// put your setup code here, to run once:
Serial.println("Calibrating POT1");

@ -20,9 +20,6 @@
* SW2 - Push this button to clear out the sound circulating in the delay.
*
*/
#define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using
#define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board.
#include "BALibrary.h"
#include "BAEffects.h"
@ -118,6 +115,7 @@ delay(100);
codec.disable();
AudioMemory(128);
TGA_PRO_EXPAND_REV2(); // Set the expansion board revision
SPI_MEM0_1M(); // set the Spi memory size
// Enable the codec

@ -1,5 +1,3 @@
#define TGA_PRO_EXPAND_REV2
#include "BALibrary.h"
using namespace BALibrary;

@ -42,7 +42,7 @@
*
*/
#define RUN_MIDI_TEST // Uncomment this line to run the MIDI test.
//#define RUN_MIDI_TEST // Uncomment this line to run the MIDI test.
//#define RUN_MEMO_TEST // Uncomment this line to run the MEM0 test.
//#define RUN_MEM1_TEST // (Teensy 3.5/3/6 only!) Uncomment this line to run the MEM1 test.
@ -94,6 +94,8 @@ void setup() {
codec.setHeadphoneVolume(0.8f); // Set headphone volume
configPhysicalControls(controls, codec);
TGA_PRO_EXPAND_REV2(); // Macro to declare expansion board revision
// Run the initial Midi connectivity and SPI memory tests.
#if defined(RUN_MIDI_TEST)
if (uartTest()) { Serial.println("MIDI Ports testing PASSED!"); }

@ -7,6 +7,7 @@
#######################################
BAAudioControlWM8731 KEYWORD1
BAAudioControlWM8731master KEYWORD1
BASpiMemory KEYWORD1
BAGpio KEYWORD1
BAAudioEffectDelayExternal KEYWORD1

@ -27,7 +27,7 @@
namespace BALibrary {
constexpr int WM8731_NUM_REGS = 10; // Number of registers in the internal shadow array
constexpr int WM8731_NUM_REGS = 10; ///< Number of registers in the internal shadow array
/**************************************************************************//**
* BAAudioControlWM8731 provides an API for configuring the internal registers
@ -45,7 +45,7 @@ public:
void disable(void);
/// First disable, then cleanly power up and unmute the codec.
void enable(void);
virtual 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
@ -119,8 +119,8 @@ public:
protected:
// A shadow array for the registers on the codec since the interface is write-only.
int regArray[WM8731_NUM_REGS];
bool m_wireStarted = false;
private:
// low-level write command
bool write(unsigned int reg, unsigned int val);
@ -130,8 +130,19 @@ private:
// Sets pullups, slew rate and drive strength
void setOutputStrength(void);
bool m_wireStarted = false;
};
/**************************************************************************//**
* BAAudioControlWM8731master provides an API for configuring the internal registers
* of the WM8731 codec when the codec is in master mode (Teensy is slave).
* @details The hardware from Blackaddr Audio does not populate the XTAL needed
* for CODEC master mode. Please refer to the schematic for your board for the
* necessary parts and modifications.
*****************************************************************************/
class BAAudioControlWM8731master : public BAAudioControlWM8731 {
public:
/// First disable, then cleanly power up and unmute the codec.
void enable(void) override;
};
} /* namespace BALibrary */

@ -398,4 +398,63 @@ void BAAudioControlWM8731::setOutputStrength(void)
#endif
}
// Powerup and unmute the codec
void BAAudioControlWM8731master::enable(void)
{
disable(); // disable first in case it was already powered up
//Serial.println("Enabling codec");
if (m_wireStarted == false) {
Wire.begin();
m_wireStarted = true;
}
setOutputStrength();
// Sequence from WAN0111.pdf
// Begin configuring the codec
resetCodec();
delay(100); // wait for reset
// Power up all domains except OUTPD and microphone
regArray[WM8731_REG_POWERDOWN] = 0x12;
write(WM8731_REG_POWERDOWN, regArray[WM8731_REG_POWERDOWN]);
delay(100); // wait for codec powerup
setAdcBypass(false); // causes a slight click
setDacSelect(true);
setHPFDisable(true);
setLeftInputGain(0x17); // default input gain
setRightInputGain(0x17);
setLeftInMute(false); // no input mute
setRightInMute(false);
setDacMute(false); // unmute the DAC
// link, but mute the headphone outputs
regArray[WM8731_REG_LHEADOUT] = WM8731_LEFT_HEADPHONE_LINK_MASK;
write(WM8731_REG_LHEADOUT, regArray[WM8731_REG_LHEADOUT]); // volume off
regArray[WM8731_REG_RHEADOUT] = WM8731_RIGHT_HEADPHONE_LINK_MASK;
write(WM8731_REG_RHEADOUT, regArray[WM8731_REG_RHEADOUT]);
/// Configure the audio interface
write(WM8731_REG_INTERFACE, 0x42); // I2S, 16 bit, MCLK master
regArray[WM8731_REG_INTERFACE] = 0x42;
write(WM8731_REG_SAMPLING, 0x20); // 256*Fs, 44.1 kHz, MCLK/1
regArray[WM8731_REG_SAMPLING] = 0x20;
delay(100); // wait for interface config
// Activate the audio interface
setActivate(true);
delay(100);
write(WM8731_REG_POWERDOWN, 0x02); // power up outputs
regArray[WM8731_REG_POWERDOWN] = 0x02;
delay(500); // wait for output to power up
delay(100); // wait for mute ramp
}
} /* namespace BALibrary */

Loading…
Cancel
Save