Skip to content

Commit ef589f8

Browse files
authored
Remove WM8731 TODO comment (#623)
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.
1 parent faddc74 commit ef589f8

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/dev/codec_wm8731.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ enum CodecSettings
7777
CODEC_FORMAT_MASTER = 0x40,
7878
CODEC_FORMAT_SLAVE = 0x00,
7979
CODEC_FORMAT_INVERT_CLOCK = 0x80,
80-
81-
CODEC_RATE_48K_48K = 0x00 << 2,
82-
CODEC_RATE_8K_8K = 0x03 << 2,
83-
CODEC_RATE_96K_96K = 0x07 << 2,
84-
CODEC_RATE_32K_32K = 0x06 << 2,
85-
CODEC_RATE_44K_44K = 0x08 << 2,
8680
};
8781

8882
Wm8731::Result Wm8731::Init(const Wm8731::Config &config, I2CHandle i2c)
@@ -149,9 +143,14 @@ Wm8731::Result Wm8731::Init(const Wm8731::Config &config, I2CHandle i2c)
149143
if(res != Result::OK)
150144
return Result::ERR;
151145

152-
// samplerate
153-
// TODO: add support for other samplerates
154-
res = WriteControlRegister(CODEC_REG_SAMPLE_RATE, CODEC_RATE_48K_48K);
146+
// The WM8731 is designed to run from a fixed rate master clock and it
147+
// has its own clock rate conversion mechanisms to derive various sample
148+
// rates from the fixed master clock. In Daisy however we use a variable
149+
// rate master clock generated by the STM32 SAI peripheral so we do not
150+
// want this extra rate conversion. By setting the WM8731 sample rate
151+
// register to 0, we disable the WM8731's own internal sample rate
152+
// conversion.
153+
res = WriteControlRegister(CODEC_REG_SAMPLE_RATE, 0x00);
155154
if(res != Result::OK)
156155
return Result::ERR;
157156

0 commit comments

Comments
 (0)