Modifity Wire write to loop until success due to possible issue with T3.6 teensyduino library

master
Steve Lascos 7 years ago
parent 84f19c7172
commit db84c56e62
  1. 19
      src/BAAudioControlWM8731.cpp
  2. 4
      src/BAAudioControlWM8731.h

@ -103,7 +103,6 @@ void BAAudioControlWM8731::resetInternalReg(void) {
BAAudioControlWM8731::BAAudioControlWM8731()
{
resetInternalReg();
Wire.begin(); // start the I2C service
}
BAAudioControlWM8731::~BAAudioControlWM8731()
@ -114,6 +113,9 @@ BAAudioControlWM8731::~BAAudioControlWM8731()
void BAAudioControlWM8731::disable(void)
{
Serial.println("Disabling codec");
if (m_wireStarted == false) { Wire.begin(); m_wireStarted = true; }
// set OUTPD to '1' (powerdown), which is bit 4
regArray[WM8731_REG_POWERDOWN] |= 0x10;
write(WM8731_REG_POWERDOWN, regArray[WM8731_REG_POWERDOWN]);
@ -130,6 +132,8 @@ void BAAudioControlWM8731::disable(void)
void BAAudioControlWM8731::enable(void)
{
Serial.println("Enabling codec");
if (m_wireStarted == false) { Wire.begin(); m_wireStarted = true; }
// Sequence from WAN0111.pdf
// Begin configuring the codec
@ -173,6 +177,8 @@ void BAAudioControlWM8731::enable(void)
regArray[WM8731_REG_POWERDOWN] = 0x02;
delay(500); // wait for output to power up
Serial.println("Done codec config");
delay(100); // wait for mute ramp
@ -315,10 +321,19 @@ void BAAudioControlWM8731::writeI2C(unsigned int addr, unsigned int val)
// Low level write control for the codec via the Teensy I2C interface
bool BAAudioControlWM8731::write(unsigned int reg, unsigned int val)
{
bool done = false;
while (!done) {
Wire.beginTransmission(WM8731_I2C_ADDR);
Wire.write((reg << 1) | ((val >> 8) & 1));
Wire.write(val & 0xFF);
Wire.endTransmission();
if (byte error = Wire.endTransmission() ) {
//Serial.println(String("Wire::Error: ") + error + String(" retrying..."));
} else {
done = true;
//Serial.println("Wire::SUCCESS!");
}
}
return true;
}

@ -24,8 +24,6 @@
#ifndef INC_BAAUDIOCONTROLWM8731_H_
#define INC_BAAUDIOCONTROLWM8731_H_
#include <Audio.h>
namespace BAGuitar {
constexpr int WM8731_NUM_REGS = 10; // Number of registers in the internal shadow array
@ -123,6 +121,8 @@ private:
// resets the internal shadow register array
void resetInternalReg(void);
bool m_wireStarted = false;
};
} /* namespace BAGuitar */

Loading…
Cancel
Save