Skip to content

Commit d5dea4f

Browse files
authored
AudioOutputI2SNoDAC not working for RP2040 due to constructor differences with AudioOutputI2S (parent class) (earlephilhower#477)
Updated code to correctly call the parent classes constructor for the RP2040. Changed the code for the RP2040 to correctly call the parent classes constructor.
1 parent 7a82ba2 commit d5dea4f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/AudioOutputI2SNoDAC.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@
2929
#include "AudioOutputI2SNoDAC.h"
3030

3131

32+
#if defined(ARDUINO_ARCH_RP2040)
33+
//
34+
// Create an alternate constructor for the RP2040. The AudioOutputI2S has an alternate
35+
// constructor for the RP2040, so the code was passing port to the sampleRate and false to sck.
36+
//
37+
// AudioOutputI2S(long sampleRate = 44100, pin_size_t sck = 26, pin_size_t data = 28);
38+
//
39+
// So this new constructor adds the ability to pass both port and sck to the underlying class, but
40+
// uses the same defaults in the AudioOutputI2S constructor.
41+
//
42+
AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port, int sck) : AudioOutputI2S(44100, sck, port)
43+
{
44+
SetOversampling(32);
45+
lastSamp = 0;
46+
cumErr = 0;
47+
}
48+
49+
#else
50+
3251
AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port) : AudioOutputI2S(port, false)
3352
{
3453
SetOversampling(32);
@@ -38,7 +57,10 @@ AudioOutputI2SNoDAC::AudioOutputI2SNoDAC(int port) : AudioOutputI2S(port, false)
3857
WRITE_PERI_REG(PERIPHS_IO_MUX_MTDO_U, orig_bck);
3958
WRITE_PERI_REG(PERIPHS_IO_MUX_GPIO2_U, orig_ws);
4059
#endif
60+
4161
}
62+
#endif
63+
4264

4365
AudioOutputI2SNoDAC::~AudioOutputI2SNoDAC()
4466
{

src/AudioOutputI2SNoDAC.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
class AudioOutputI2SNoDAC : public AudioOutputI2S
2626
{
2727
public:
28+
//
29+
// Define a different constructor for the RP2040, as this class calls the constructor
30+
// of the AudioOutputI2S which has an alternate constructor for the RP2040
31+
//
32+
#if defined(ARDUINO_ARCH_RP2040)
33+
AudioOutputI2SNoDAC(int port = 28,int sck = 26);
34+
#else
2835
AudioOutputI2SNoDAC(int port = 0);
36+
#endif
37+
2938
virtual ~AudioOutputI2SNoDAC() override;
3039
virtual bool begin() override { return AudioOutputI2S::begin(false); }
3140
virtual bool ConsumeSample(int16_t sample[2]) override;

0 commit comments

Comments
 (0)