Skip to content

Commit

Permalink
Remove manual DAC init, use Circle auto-detection
Browse files Browse the repository at this point in the history
Closes #273.
  • Loading branch information
dwhinham committed Jun 13, 2022
1 parent 72c517f commit 37c2567
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update to circle-stdlib v15.13/Circle Step 44.5.
- Update to libmt32emu v2.6.3.
- Update to FluidSynth v2.2.7.
- The `i2c_dac_address` and `i2c_dac_init` configuration options have been deprecated and have no longer have any effect. DACs requiring initialization are now automatically detected.

## [0.11.3] - 2022-04-13

Expand Down
2 changes: 0 additions & 2 deletions include/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ BEGIN_SECTION(audio)
CFG(output_device, TAudioOutputDevice, AudioOutputDevice, TAudioOutputDevice::PWM )
CFG(sample_rate, int, AudioSampleRate, 48000 )
CFG(chunk_size, int, AudioChunkSize, 256 )
CFG(i2c_dac_address, int, AudioI2CDACAddress, 0x4c, true )
CFG(i2c_dac_init, TAudioI2CDACInit, AudioI2CDACInit, TAudioI2CDACInit::None )
END_SECTION

BEGIN_SECTION(control)
Expand Down
6 changes: 0 additions & 6 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class CConfig
ENUM(HDMI, hdmi) \
ENUM(I2S, i2s)

#define ENUM_AUDIOI2CDACINIT(ENUM) \
ENUM(None, none) \
ENUM(PCM51xx, pcm51xx)

#define ENUM_CONTROLSCHEME(ENUM) \
ENUM(None, none) \
ENUM(SimpleButtons, simple_buttons) \
Expand Down Expand Up @@ -78,7 +74,6 @@ class CConfig

CONFIG_ENUM(TSystemDefaultSynth, ENUM_SYSTEMDEFAULTSYNTH);
CONFIG_ENUM(TAudioOutputDevice, ENUM_AUDIOOUTPUTDEVICE);
CONFIG_ENUM(TAudioI2CDACInit, ENUM_AUDIOI2CDACINIT);
CONFIG_ENUM(TControlScheme, ENUM_CONTROLSCHEME);
CONFIG_ENUM(TLCDType, ENUM_LCDTYPE);
CONFIG_ENUM(TNetworkMode, ENUM_NETWORKMODE);
Expand All @@ -105,7 +100,6 @@ class CConfig
static bool ParseOption(const char *pString, CIPAddress* pOut);
static bool ParseOption(const char* pString, TSystemDefaultSynth* pOut);
static bool ParseOption(const char* pString, TAudioOutputDevice* pOut);
static bool ParseOption(const char* pString, TAudioI2CDACInit* pOut);
static bool ParseOption(const char* pString, TMT32EmuResamplerQuality* pOut);
static bool ParseOption(const char* pString, TMT32EmuMIDIChannels* pOut);
static bool ParseOption(const char* pString, TMT32EmuROMSet* pOut);
Expand Down
2 changes: 0 additions & 2 deletions include/mt32pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ class CMT32Pi : CMultiCoreSupport, CPower, CMIDIParser, CAppleMIDIHandler, CUDPM
void LEDOn();
void LCDLog(TLCDLogType Type, const char* pFormat...);

bool InitPCM51xx(u8 nAddress);

CLogger* volatile m_pLogger;
CConfig* volatile m_pConfig;

Expand Down
18 changes: 0 additions & 18 deletions sdcard/mt32-pi.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,6 @@ sample_rate = 48000
# Values: 2-2048 (256*)
chunk_size = 256

# Set address (hexadecimal) of I2C DAC control interface.
#
# This will be used for the initialization sequence (see below) if enabled.
# You can find the address of your DAC by using the i2cdetect utility in Linux.
#
# Values: 00-80 (4c*)
i2c_dac_address = 4c

# Select an initialization sequence for the DAC.
#
# Some DACs require some initialization commands to be sent via I2C before they
# will produce any sound.
#
# Values: none*, pcm51xx
#
# pcm51xx: for DACs based on PCM5121 or similar (e.g. PCM5141, PCM5242)
i2c_dac_init = none

# -----------------------------------------------------------------------------
# Control options
# -----------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const char* FalseStrings[] = {"false", "off", "0"};
// Enum string tables
CONFIG_ENUM_STRINGS(TSystemDefaultSynth, ENUM_SYSTEMDEFAULTSYNTH);
CONFIG_ENUM_STRINGS(TAudioOutputDevice, ENUM_AUDIOOUTPUTDEVICE);
CONFIG_ENUM_STRINGS(TAudioI2CDACInit, ENUM_AUDIOI2CDACINIT);
CONFIG_ENUM_STRINGS(TMT32EmuResamplerQuality, ENUM_RESAMPLERQUALITY);
CONFIG_ENUM_STRINGS(TMT32EmuMIDIChannels, ENUM_MIDICHANNELS);
CONFIG_ENUM_STRINGS(TMT32EmuROMSet, ENUM_MT32ROMSET);
Expand Down Expand Up @@ -259,7 +258,6 @@ bool CConfig::ParseOption(const char* pString, CIPAddress* pOut)
// Define template function wrappers for parsing enums
CONFIG_ENUM_PARSER(TSystemDefaultSynth);
CONFIG_ENUM_PARSER(TAudioOutputDevice);
CONFIG_ENUM_PARSER(TAudioI2CDACInit);
CONFIG_ENUM_PARSER(TMT32EmuResamplerQuality);
CONFIG_ENUM_PARSER(TMT32EmuMIDIChannels);
CONFIG_ENUM_PARSER(TMT32EmuROMSet);
Expand Down
36 changes: 5 additions & 31 deletions src/mt32pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,12 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)

// Pisound provides clock
const bool bSlave = m_pPisound != nullptr;
m_pSound = new CI2SSoundBaseDevice(m_pInterrupt, m_pConfig->AudioSampleRate, m_pConfig->AudioChunkSize, bSlave);
Format = TSoundFormat::SoundFormatSigned24_32;

if (m_pConfig->AudioI2CDACInit == CConfig::TAudioI2CDACInit::PCM51xx)
InitPCM51xx(m_pConfig->AudioI2CDACAddress);
// Don't probe if using Pisound
CI2CMaster* const pI2CMaster = bSlave ? nullptr : m_pI2CMaster;

m_pSound = new CI2SSoundBaseDevice(m_pInterrupt, m_pConfig->AudioSampleRate, m_pConfig->AudioChunkSize, bSlave, pI2CMaster);
Format = TSoundFormat::SoundFormatSigned24_32;

break;
}
Expand Down Expand Up @@ -1224,33 +1225,6 @@ void CMT32Pi::LCDLog(TLCDLogType Type, const char* pFormat...)
m_UserInterface.ShowSystemMessage(Buffer, Type == TLCDLogType::Spinner);
}

// TODO: Generic configurable DAC init class
bool CMT32Pi::InitPCM51xx(u8 nAddress)
{
static const u8 InitBytes[][2] =
{
// Set PLL reference clock to BCK (set SREF to 001b)
{ 0x0D, 0x10 },

// Ignore clock halt detection (set IDCH to 1)
{ 0x25, 0x08 },

// Disable auto mute
{ 0x41, 0x04 }
};

for (auto& Command : InitBytes)
{
if (m_pI2CMaster->Write(nAddress, &Command, sizeof(Command)) != sizeof(Command))
{
m_pLogger->Write(MT32PiName, LogWarning, "I2C write error (DAC init sequence)");
return false;
}
}

return true;
}

const char* CMT32Pi::GetNetworkDeviceShortName() const
{
switch (m_pConfig->NetworkMode)
Expand Down

0 comments on commit 37c2567

Please sign in to comment.