Skip to content
Open
22 changes: 22 additions & 0 deletions AudioConfigRP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@
#define BUFFER_SIZE 256 // total size of the buffer, in samples
#endif

#if defined(ARDUINO_DATANOISETV_PICOADK)
// undefined the defindes to disable compiler warnings
// about redefinition.
#undef BCLK_PIN
#undef WS_PIN
#undef LSBJ_FORMAT
#undef AUDIO_BITS
#undef BYPASS_MOZZI_OUTPUT_BUFFER
#undef BUFFERS
#undef BUFFER_SIZE
#undef RP2040_AUDIO_OUT_MODE

#define BCLK_PIN PIN_I2S_BCLK
#define WS_PIN (PIN_I2S_BCLK+1)
#define DOUT_PIN PIN_I2S_DOUT
#define LSBJ_FORMAT false
#define AUDIO_BITS 16
#define BYPASS_MOZZI_OUTPUT_BUFFER true
#define BUFFERS 8
#define BUFFER_SIZE 256
#define RP2040_AUDIO_OUT_MODE EXTERNAL_DAC_VIA_I2S
#endif

#define AUDIO_BITS_PER_CHANNEL AUDIO_BITS

Expand Down
13 changes: 13 additions & 0 deletions MozziGuts_impl_RP2040.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ static void startAudio() {
i2s.setBCLK(BCLK_PIN);
i2s.setDATA(DOUT_PIN);
i2s.setBitsPerSample(AUDIO_BITS);

// The PicoADK won't output a tone until it is unmuted.
// Move it into the Mozzi implementation so the user won't need to change mozzi code.
#if (ARDUINO_DATANOISETV_PICOADK)
// Soft mute and de-emphasis for audio codec
i2s.setBCLK(PIN_I2S_BCLK);
i2s.setDATA(PIN_I2S_DOUT);

pinMode(25, OUTPUT);
digitalWrite(25, HIGH);
pinMode(23, OUTPUT);
digitalWrite(23, LOW);
#endif

#if (AUDIO_BITS > 16)
i2s.setBuffers(BUFFERS, (size_t) (BUFFER_SIZE/BUFFERS), 0);
Expand Down
4 changes: 4 additions & 0 deletions hardware_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#define CACHED_FUNCTION_ATTR
#endif

#if IS_RP2040()
#define AUDIO_RATE_PLATFORM_DEFAULT 32768
#endif

Comment on lines +49 to +52
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is needed as the RP2040 is not AVR so the test on line 35 will be false and the AUDIO_RATE was already at 32768.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked this?

#if IS_STM32()
// This is a little silly, but with Arduino 1.8.13, including this header inside MozziGuts.cpp does not work (fails to detect the proper include path).
// Putting it here, instead, seem to work.
Expand Down
14 changes: 14 additions & 0 deletions mozzi_rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ extern STM32ADC adc;
#include <esp8266_peri.h>
#endif

#if IS_RP2040()
#include "hardware/structs/rosc.h"
#endif

// moved these out of xorshift96() so xorshift96() can be reseeded manually
static unsigned long x=132456789, y=362436069, z=521288629;
// static unsigned long x= analogRead(A0)+123456789;
Expand Down Expand Up @@ -144,6 +148,16 @@ void randSeed() {
x = RANDOM_REG32;
y = random (0xFFFFFFFF) ^ RANDOM_REG32;
z = random (0xFFFFFFFF) ^ RANDOM_REG32;
#elif IS_RP2040()
uint32_t rand_seed;
for (int i = 0; i < 32; i++)
{
bool randomBit = rosc_hw->randombit;
rand_seed = rand_seed | (randomBit << i);
}
x = random (rand_seed);
y = random (rand_seed);
z = random (rand_seed);
#else
Comment on lines +151 to 161
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested but look good to me.

#warning Automatic random seeding not implemented on this platform
#endif
Expand Down