Add support for Raspberry Pi Pico Arduino Core

Adds support for the RP2040 core and the PIO based I2S output device.
https://github.com/earlephilhower/arduino-pico

Poisons some ARM optimizations which don't work on modern Thumbs.
This commit is contained in:
Earle F. Philhower, III committed 2021-04-02 19:40:58 -07:00
1 parent f4d4e69332
commit b37e9d232b
21 files changed
+122 -79

No files matched your search

+60 -29
View File
@@ -21,11 +21,14 @@
#include <Arduino.h>
#ifdef ESP32
#include "driver/i2s.h"
#else
#elif defined(ESP8266)
#include <i2s.h>
#elif defined(ARDUINO_ARCH_RP2040)
#include <I2S.h>
#endif
#include "AudioOutputI2S.h"
#if defined(ESP32) || defined(ESP8266)
AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int use_apll)
{
this->portNo = port;
@@ -48,31 +51,6 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
SetGain(1.0);
}
AudioOutputI2S::~AudioOutputI2S()
{
#ifdef ESP32
if (i2sOn) {
audioLogger->printf("UNINSTALL I2S\n");
i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
}
#else
if (i2sOn)
i2s_end();
#endif
i2sOn = false;
}
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
{
bclkPin = bclk;
wclkPin = wclk;
doutPin = dout;
if (i2sOn)
return SetPinout();
return true;
}
bool AudioOutputI2S::SetPinout()
{
#ifdef ESP32
@@ -94,6 +72,45 @@ bool AudioOutputI2S::SetPinout()
#endif
}
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
{
bclkPin = bclk;
wclkPin = wclk;
doutPin = dout;
if (i2sOn)
return SetPinout();
return true;
}
#elif defined(ARDUINO_ARCH_RP2040)
AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data) {
i2sOn = false;
mono = false;
bps = 16;
channels = 2;
hertz = sampleRate;
bclkPin = sck;
doutPin = data;
SetGain(1.0);
}
#endif
AudioOutputI2S::~AudioOutputI2S()
{
#ifdef ESP32
if (i2sOn) {
audioLogger->printf("UNINSTALL I2S\n");
i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
}
#elif defined(ESP8266)
if (i2sOn)
i2s_end();
#elif defined(ARDUINO_ARCH_RP2040)
stop();
#endif
i2sOn = false;
}
bool AudioOutputI2S::SetRate(int hz)
{
// TODO - have a list of allowable rates from constructor, check them
@@ -102,8 +119,10 @@ bool AudioOutputI2S::SetRate(int hz)
{
#ifdef ESP32
i2s_set_sample_rates((i2s_port_t)portNo, AdjustI2SRate(hz));
#else
#elif defined(ESP8266)
i2s_set_rate(AdjustI2SRate(hz));
#elif defined(ARDUINO_ARCH_RP2040)
I2S.setFrequency(hz);
#endif
}
return true;
@@ -189,7 +208,7 @@ bool AudioOutputI2S::begin(bool txDAC)
}
i2s_zero_dma_buffer((i2s_port_t)portNo);
}
#else
#elif defined(ESP8266)
(void)dma_buf_count;
(void)use_apll;
if (!i2sOn)
@@ -209,6 +228,11 @@ bool AudioOutputI2S::begin(bool txDAC)
}
#endif
}
#elif defined(ARDUINO_ARCH_RP2040)
(void)txDAC;
if (!i2sOn) {
I2S.begin(hertz, bclkPin, doutPin);
}
#endif
i2sOn = true;
SetRate(hertz); // Default
@@ -246,9 +270,11 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
}
return i2s_write_bytes((i2s_port_t)portNo, (const char *)&s32, sizeof(uint32_t), 0);
#else
#elif defined(ESP8266)
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true
#elif defined(ARDUINO_ARCH_RP2040)
return !!I2S.write((void*)ms, 4);
#endif
}
@@ -265,6 +291,8 @@ void AudioOutputI2S::flush()
delay(10);
}
}
#elif defined(ARDUINO_ARCH_RP2040)
I2S.flush();
#endif
}
@@ -275,6 +303,9 @@ bool AudioOutputI2S::stop()
#ifdef ESP32
i2s_zero_dma_buffer((i2s_port_t)portNo);
#elif defined(ARDUINO_ARCH_RP2040)
I2S.end();
#endif
i2sOn = false;
return true;
}