sensorium / Mozzi

sound synthesis library for Arduino

Home Page:https://sensorium.github.io/Mozzi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hardware support for the PicoADK RP2040 DSP Board

DatanoiseTV opened this issue · comments

The PicoADK is a board which is focused on building standalone synthesizers, oscillators etc.
By default, it uses the PicoADK-Firmware-Template, which is based on the Pico SDK.

It has a 32-bit Audio DAC and a 8 channel ADC128S102 12-bit 3.3V/5V ADC with up to 1 Megasample/s.
The audio output is very low noise, due to a dedicated LDO for the Audio Codec Analog Supply.

Would be cool to see Mozzi support for it to make it also useful for Arduino IDE users.
https://github.com/DatanoiseTV/PicoADK-Hardware
https://github.com/DatanoiseTV/PicoADK-Firmware-Template

Discord: https://discord.gg/BsHUEdStMt

Hi,

I actually wonder if this should not be working already, probably with minor configuration:

  • the DAC is I2S, which has been ported #163
  • the ADC is SPI which is compatible with Mozzi (probably with a restriction that Audio input should be on one of the bare chip ADC pins and not the external ADC).

Have you tried :) ?

I didn't figure out yet where to start. Is Mozzi able to handle 16-bit/32-bit I2S output?

Yup. First step I think would be to adapt "AudioConfigRP2040.h" to the hardware:

  • the specific pins used for the DAC:
  • the number of bits used.
  • this DAC seems to accept both left justified and standard I2S, so as long as you set its config pin correctly you can choose any mode.

Then I would just try to run one of the examples

@tomcombriat #169
I've also added random seed support using the ROSC of the RP2040. This is the way
recommended by Raspberry. Now I need some help on implementing the ADC handling.

The code for reading the ADC (example):

spi_init(spi1, 16000000);
spi_set_format(spi1, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
spi_set_slave(spi1, false);

....
uint16_t adc128_read(uint8_t chan)
{
        if (chan > 7)
                return 0;
        gpio_put(13, 0);
        uint8_t data[2] = {(chan << 3), 0};
        uint8_t rxData[2];
        spi_write_read_blocking(spi1, data, rxData, 2);
        gpio_put(13, 1);
        uint16_t result = (rxData[0] << 8) | rxData[1];

        return result;
}

I made a few review on your PR.
For the DAC I do not have one to test this but is this code working? As I said in the review I do not think this level of details should go in Mozzi but probably more in your sketches (or any higher level api that goes with the board).
Let's see what the others say.

I will review it. Yes, I've tested using all the examples and it works.
The reason for adding the PicoADK specific mute pin control is that the user won't need to modify sketches in order to use them with an PicoADK board.

In the config we can define an EXTERNAL_AUDIO_OUTPUT. I think it would be cool to have the same on the input side as well, so that we could add any custom audio input in the sketch itself.

This would also help e.g. for the ESP32 where the getADCReading() is not implemented. This way we could even support the audio input from an ESP32 AudioKit.