Skip to content

Add initial DatanoiseTV PicoADK Board Support #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
42 changes: 42 additions & 0 deletions AudioConfigRP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
#define AUDIO_BITS 16 // available values are 8, 16, 24 (LEFT ALIGN in 32 bits type!!) and 32 bits
// ****** END: These are define you may want to change. Best not to touch anything outside this range. ************/

// The arduino-pico SDK has I2S Pins predefined for some boards.
#if defined(ARDUINO_ARCH_RP2040)

#if defined(PIN_I2S_BCLK)
#define BCLK_PIN PIN_I2S_BCLK
#define WS_PIN (PIN_I2S_BCLK+)
#endif

#if defined(PIN_I2S_DOUT)
#define DOUT_PIN PIN_I2S_DOUT
#endif

#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this erasing the config for all cases? When is this test going true? I would be against putting these pins at the default values of the arduino-pico library, with no easy change if that is the case. I think that (alongside the comment on the support of ARDUINO_DATANOISETV_PICOADK) this kind of config should be given by the board designer and not be hardcoded in Mozzi.

#define BYPASS_MOZZI_OUTPUT_BUFFER true

// Configuration of the I2S port, especially DMA. Set in stone here as default of the library when this was written.
Expand All @@ -44,6 +58,34 @@
#define BUFFER_SIZE 256 // total size of the buffer, in samples
#endif

// override all definitions if the board has dedicated I2S pins
#if defined(PIN_I2S_DOUT)
// undefine to disable compiler warnings
#undef DOUT_PIN
#define DOUT_PIN PIN_I2S_DOUT
#endif

#if defined(PIN_I2S_BCLK)
// undefine to disable compiler warnings
#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 LSBJ_FORMAT false
#define AUDIO_BITS 16
#define BYPASS_MOZZI_OUTPUT_BUFFER true
#define BUFFERS 8
#define BUFFER_SIZE 128
#define RP2040_AUDIO_OUT_MODE EXTERNAL_DAC_VIA_I2S
#endif


#define AUDIO_BITS_PER_CHANNEL AUDIO_BITS

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

#if (ARDUINO_DATANOISETV_PICOADK)
// Soft mute and de-emphasis for audio codec
pinMode(25, OUTPUT);
digitalWrite(25, HIGH);
pinMode(23, OUTPUT);
digitalWrite(23, LOW);
#endif
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 it is desirable that the details of every board created are in Mozzi. Architectures yes, but if we start to "pre-config" every board that goes out this is a never ending story. Especially as what is done here can easily be done in the sketch.


#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