From d7c79b87edbb292d65d4bd0e51b63a458b36bb93 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 4 Apr 2024 11:36:23 +0200 Subject: [PATCH] Remove WM8731 TODO comment I was reading the WM8731 audio codec setup code and I got confused by a comment which suggested Daisy always uses the codec with a 48kHz sample rate. After several hours of reading data sheets I figured out what is going on here: the WM8731 has built-in sample rate conversion and the nominal "48kHz" setting disables the built-in conversion. This commit updates the comment to explain what we are actually doing here. --- src/dev/codec_wm8731.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/dev/codec_wm8731.cpp b/src/dev/codec_wm8731.cpp index 190a5aa09..ba6da4b70 100644 --- a/src/dev/codec_wm8731.cpp +++ b/src/dev/codec_wm8731.cpp @@ -77,12 +77,6 @@ enum CodecSettings CODEC_FORMAT_MASTER = 0x40, CODEC_FORMAT_SLAVE = 0x00, CODEC_FORMAT_INVERT_CLOCK = 0x80, - - CODEC_RATE_48K_48K = 0x00 << 2, - CODEC_RATE_8K_8K = 0x03 << 2, - CODEC_RATE_96K_96K = 0x07 << 2, - CODEC_RATE_32K_32K = 0x06 << 2, - CODEC_RATE_44K_44K = 0x08 << 2, }; Wm8731::Result Wm8731::Init(const Wm8731::Config &config, I2CHandle i2c) @@ -149,9 +143,14 @@ Wm8731::Result Wm8731::Init(const Wm8731::Config &config, I2CHandle i2c) if(res != Result::OK) return Result::ERR; - // samplerate - // TODO: add support for other samplerates - res = WriteControlRegister(CODEC_REG_SAMPLE_RATE, CODEC_RATE_48K_48K); + // The WM8731 is designed to run from a fixed rate master clock and it + // has its own clock rate conversion mechanisms to derive various sample + // rates from the fixed master clock. In Daisy however we use a variable + // rate master clock generated by the STM32 SAI peripheral so we do not + // want this extra rate conversion. By setting the WM8731 sample rate + // register to 0, we disable the WM8731's own internal sample rate + // conversion. + res = WriteControlRegister(CODEC_REG_SAMPLE_RATE, 0x00); if(res != Result::OK) return Result::ERR;