From 206906057498caf34eaf61309a9c9868a361a75a Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 18 May 2022 21:03:37 -0700 Subject: [PATCH] Add RP2040 build (#530) Fix examples to build on RP2040 Clean up generator warnings No SPDIF on RP2040 (yet) Add back C sources for AAC on ARM No WiFi streaming on RP2040 No webradio on RP2040 No talking clock (NTP) on RP2040 either --- .github/workflows/pr-or-master-push.yml | 24 +++++++++++- README.md | 2 +- examples/MixerSample/MixerSample.ino | 7 +++- .../PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino | 6 +++ .../PlayMIDIFromLittleFS.ino | 9 ++++- .../PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino | 6 ++- .../PlayMODFromPROGMEMToDAC.ino | 6 ++- .../PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino | 6 +++ examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino | 5 +++ .../PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino | 6 +++ .../StreamMP3FromHTTP/StreamMP3FromHTTP.ino | 9 ++++- .../StreamMP3FromHTTPToSPDIF.ino | 8 +++- .../StreamMP3FromHTTP_SPIRAM.ino | 8 +++- examples/StreamOnHost/StreamOnHost.ino | 8 +++- examples/TalkingClockI2S/TalkingClockI2S.ino | 10 ++++- examples/WebRadio/WebRadio.ino | 8 +++- examples/WebRadio/web.cpp | 8 ++-- src/AudioGeneratorMOD.cpp | 2 +- src/libflac/stream_decoder.c | 4 +- src/libhelix-aac/sbrqmf.c | 5 ++- src/libmad/layer3.c | 1 + src/opusfile/opusfile.c | 2 +- tests/common.sh | 38 +++++++++++++++---- 23 files changed, 154 insertions(+), 34 deletions(-) diff --git a/.github/workflows/pr-or-master-push.yml b/.github/workflows/pr-or-master-push.yml index fcbd095..3bbdbb9 100644 --- a/.github/workflows/pr-or-master-push.yml +++ b/.github/workflows/pr-or-master-push.yml @@ -13,6 +13,29 @@ on: jobs: + build-rp2040: + name: Build RP2040 + runs-on: ubuntu-latest + strategy: + matrix: + chunk: [0, 1, 2, 3, 4] + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Build Sketches + env: + TRAVIS_BUILD_DIR: ${{ github.workspace }} + TRAVIS_TAG: ${{ github.ref }} + BUILD_TYPE: build_rp2040 + BUILD_MOD: 5 + BUILD_REM: ${{ matrix.chunk }} + run: | + bash ./tests/common.sh + build-esp8266: name: Build ESP8266 runs-on: ubuntu-latest @@ -36,7 +59,6 @@ jobs: run: | bash ./tests/common.sh - build-esp32: name: Build ESP-32 runs-on: ubuntu-latest diff --git a/README.md b/README.md index 229d45f..a6a29ee 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi RP2040[![Gitter](https://badges.gitter.im/ESP8266Audio/community.svg)](https://gitter.im/ESP8266Audio/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +# ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi RP2040 [![Gitter](https://badges.gitter.im/ESP8266Audio/community.svg)](https://gitter.im/ESP8266Audio/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) Arduino library for parsing and decoding MOD, WAV, MP3, FLAC, MIDI, AAC, and RTTL files and playing them on an I2S DAC or even using a software-simulated delta-sigma DAC with dynamic 32x-128x oversampling. ESP8266 is fully supported and most mature, but ESP32 is also mostly there with built-in DAC as well as external ones. diff --git a/examples/MixerSample/MixerSample.ino b/examples/MixerSample/MixerSample.ino index 7a9a1e2..ab02af0 100644 --- a/examples/MixerSample/MixerSample.ino +++ b/examples/MixerSample/MixerSample.ino @@ -1,5 +1,10 @@ #include -#ifdef ESP32 + +#if defined(ARDUINO_ARCH_RP2040) + #define WIFI_OFF + class __x { public: __x() {}; void mode() {}; }; + __x WiFi; +#elif defined(ESP32) #include #else #include diff --git a/examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino b/examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino index cf7e143..110b046 100644 --- a/examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino +++ b/examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino @@ -1,4 +1,8 @@ #include +#ifdef ARDUINO_ARCH_RP2040 +void setup() {} +void loop() {} +#else #include "AudioFileSourceSD.h" #include "AudioOutputSPDIF.h" #include "AudioGeneratorFLAC.h" @@ -66,3 +70,5 @@ void loop() { } } } +#endif + diff --git a/examples/PlayMIDIFromLittleFS/PlayMIDIFromLittleFS.ino b/examples/PlayMIDIFromLittleFS/PlayMIDIFromLittleFS.ino index b4f02e3..ed075bc 100644 --- a/examples/PlayMIDIFromLittleFS/PlayMIDIFromLittleFS.ino +++ b/examples/PlayMIDIFromLittleFS/PlayMIDIFromLittleFS.ino @@ -6,7 +6,13 @@ } void loop() {} #else -#include +#if defined(ARDUINO_ARCH_RP2040) + #define WIFI_OFF + class __x { public: __x() {}; void mode() {}; }; + __x WiFi; +#else + #include +#endif #include #include #include @@ -42,7 +48,6 @@ void loop() { if (midi->isRunning()) { if (!midi->loop()) { - uint32_t e = millis(); midi->stop(); } } else { diff --git a/examples/PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino b/examples/PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino index da9f685..76e90bb 100644 --- a/examples/PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino +++ b/examples/PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino @@ -1,4 +1,8 @@ #include +#ifdef ARDUINO_ARCH_RP2040 +void setup() {} +void loop() {} +#else #ifdef ESP32 #include #include "SPIFFS.h" @@ -53,4 +57,4 @@ void loop() } } - +#endif diff --git a/examples/PlayMODFromPROGMEMToDAC/PlayMODFromPROGMEMToDAC.ino b/examples/PlayMODFromPROGMEMToDAC/PlayMODFromPROGMEMToDAC.ino index 44aac59..07ff11c 100644 --- a/examples/PlayMODFromPROGMEMToDAC/PlayMODFromPROGMEMToDAC.ino +++ b/examples/PlayMODFromPROGMEMToDAC/PlayMODFromPROGMEMToDAC.ino @@ -2,7 +2,11 @@ #include "AudioFileSourcePROGMEM.h" #include "AudioGeneratorMOD.h" #include "AudioOutputI2S.h" -#ifdef ESP32 +#if defined(ARDUINO_ARCH_RP2040) + #define WIFI_OFF + class __x { public: __x() {}; void mode() {}; }; + __x WiFi; +#elif defined(ESP32) #include #else #include diff --git a/examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino b/examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino index 364a7a8..6d2ff65 100644 --- a/examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino +++ b/examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino @@ -1,4 +1,9 @@ #include +#if defined(ARDUINO_ARCH_RP2040) +void setup() {} +void loop() {} +#else + #ifdef ESP32 #include #include "SPIFFS.h" @@ -70,3 +75,4 @@ void loop() delay(1000); } } +#endif diff --git a/examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino b/examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino index 02dfb98..8e41036 100644 --- a/examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino +++ b/examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino @@ -1,4 +1,8 @@ #include +#ifdef ARDUINO_ARCH_RP2040 +void setup() {} +void loop() {} +#else #ifdef ESP32 #include "SPIFFS.h" #endif @@ -97,3 +101,4 @@ void loop() delay(1000); } } +#endif diff --git a/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino b/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino index 44db7c4..5b96ec9 100644 --- a/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino +++ b/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino @@ -1,4 +1,8 @@ #include +#ifdef ARDUINO_ARCH_RP2040 +void setup() {} +void loop() {} +#else #ifdef ESP32 #include #include "SPIFFS.h" @@ -39,3 +43,5 @@ void loop() delay(1000); } } + +#endif diff --git a/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino b/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino index 84d7d5b..3ac0ec0 100644 --- a/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino +++ b/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino @@ -1,6 +1,11 @@ #include -#ifdef ESP32 +#if defined(ARDUINO_ARCH_RP2040) +void setup() {} +void loop() {} + +#else +#if defined(ESP32) #include #else #include @@ -104,4 +109,4 @@ void loop() delay(1000); } } - +#endif diff --git a/examples/StreamMP3FromHTTPToSPDIF/StreamMP3FromHTTPToSPDIF.ino b/examples/StreamMP3FromHTTPToSPDIF/StreamMP3FromHTTPToSPDIF.ino index ef54290..23b8547 100644 --- a/examples/StreamMP3FromHTTPToSPDIF/StreamMP3FromHTTPToSPDIF.ino +++ b/examples/StreamMP3FromHTTPToSPDIF/StreamMP3FromHTTPToSPDIF.ino @@ -1,6 +1,10 @@ #include +#ifdef ARDUINO_ARCH_RP2040 +void setup() {} +void loop() {} +#else -#ifdef ESP32 +#if defined(ESP32) #include #else #include @@ -140,3 +144,5 @@ void loop() ESP.restart(); } } + +#endif diff --git a/examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino b/examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino index 0b9ab09..3a59b15 100644 --- a/examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino +++ b/examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino @@ -1,5 +1,9 @@ #include -#ifdef ESP32 +#if defined(ARDUINO_ARCH_RP2040) +void setup() {} +void loop() {} +#else +#if defined(ESP32) #include #else #include @@ -101,4 +105,4 @@ void loop() delay(1000); } } - +#endif diff --git a/examples/StreamOnHost/StreamOnHost.ino b/examples/StreamOnHost/StreamOnHost.ino index 876562d..4da0642 100644 --- a/examples/StreamOnHost/StreamOnHost.ino +++ b/examples/StreamOnHost/StreamOnHost.ino @@ -1,6 +1,10 @@ #include -#ifdef ESP32 +#if defined(ARDUINO_ARCH_RP2040) +void setup() {} +void loop() {} +#else +#if defined(ESP32) #include #else #include @@ -115,4 +119,4 @@ void loop() delay(1000); } } - +#endif diff --git a/examples/TalkingClockI2S/TalkingClockI2S.ino b/examples/TalkingClockI2S/TalkingClockI2S.ino index 6a2f731..61d735d 100644 --- a/examples/TalkingClockI2S/TalkingClockI2S.ino +++ b/examples/TalkingClockI2S/TalkingClockI2S.ino @@ -2,7 +2,14 @@ // https://github.com/going-digital/Talkie/blob/master/Talkie/examples/Vocab_US_Clock/Vocab_US_Clock.ino // Released under GPL v2 -#ifdef ESP32 +#include + +#if defined(ARDUINO_ARCH_RP2040) +void setup() {} +void loop() {} +#else + +#if defined(ESP32) #include #else #include @@ -183,3 +190,4 @@ void loop() sayTime(tmstruct.tm_hour, tmstruct.tm_min, talkie); delay(1000); } +#endif diff --git a/examples/WebRadio/WebRadio.ino b/examples/WebRadio/WebRadio.ino index e8a0326..7c51ed0 100644 --- a/examples/WebRadio/WebRadio.ino +++ b/examples/WebRadio/WebRadio.ino @@ -19,7 +19,12 @@ */ #include -#ifdef ESP32 +#if defined(ARDUINO_ARCH_RP2040) +void setup() {} +void loop() {} +#else + +#if defined(ESP32) #include #else #include @@ -439,3 +444,4 @@ void loop() } } +#endif diff --git a/examples/WebRadio/web.cpp b/examples/WebRadio/web.cpp index 75e6873..505b309 100644 --- a/examples/WebRadio/web.cpp +++ b/examples/WebRadio/web.cpp @@ -19,6 +19,9 @@ */ #include +#if defined(ARDUINO_ARCH_RP2040) +// Nothing here +#else #ifdef ESP32 #include #else @@ -308,7 +311,4 @@ void Read4Int(char *str, byte *p) str += ParseInt(str, &i); p[2] = i; if (*str) str++; str += ParseInt(str, &i); p[3] = i; } - - - - +#endif diff --git a/src/AudioGeneratorMOD.cpp b/src/AudioGeneratorMOD.cpp index cb828b2..2be98ca 100644 --- a/src/AudioGeneratorMOD.cpp +++ b/src/AudioGeneratorMOD.cpp @@ -791,7 +791,7 @@ void AudioGeneratorMOD::GetSample(int16_t sample[2]) Mixer.channelSampleNumber[channel] != FatBuffer.channelSampleNumber[channel]) { uint32_t toRead = Mixer.sampleEnd[Mixer.channelSampleNumber[channel]] - samplePointer + 1; - if (toRead > fatBufferSize) toRead = fatBufferSize; + if (toRead > (uint32_t)fatBufferSize) toRead = fatBufferSize; if (!file->seek(samplePointer, SEEK_SET)) { stop(); diff --git a/src/libflac/stream_decoder.c b/src/libflac/stream_decoder.c index 20ae399..bfbcc54 100644 --- a/src/libflac/stream_decoder.c +++ b/src/libflac/stream_decoder.c @@ -2783,7 +2783,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_ if(rice_parameter < pesc) { partitioned_rice_contents->raw_bits[partition] = 0; u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order; - if(!FLAC__bitreader_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter)) + if(!FLAC__bitreader_read_rice_signed_block(decoder->private_->input, (int *)(residual + sample), u, rice_parameter)) return false; /* read_callback_ sets the state for us */ sample += u; } @@ -2792,7 +2792,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_ return false; /* read_callback_ sets the state for us */ partitioned_rice_contents->raw_bits[partition] = rice_parameter; for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) { - if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i, rice_parameter)) + if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32 *)&i, rice_parameter)) return false; /* read_callback_ sets the state for us */ residual[sample] = i; } diff --git a/src/libhelix-aac/sbrqmf.c b/src/libhelix-aac/sbrqmf.c index 83cf14a..e68bbad 100644 --- a/src/libhelix-aac/sbrqmf.c +++ b/src/libhelix-aac/sbrqmf.c @@ -222,7 +222,8 @@ static void PostMultiply64(int *fft1, int nSampsOut) * Notes: this is carefully written to be efficient on ARM * use the assembly code version in sbrqmfak.s when building for ARM! **************************************************************************************/ -#if (defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__)) + //TODO - ADD IN .S SOURCES SOMEHOW +#if 0 //(defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__)) #ifdef __cplusplus extern "C" #endif @@ -395,7 +396,7 @@ int QMFAnalysis(int *inbuf, int *delay, int *XBuf, int fBitsIn, int *delayIdx, i * Notes: this is carefully written to be efficient on ARM * use the assembly code version in sbrqmfsk.s when building for ARM! **************************************************************************************/ -#if (defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__)) +#if 0 //(defined (__arm) && defined (__ARMCC_VERSION)) || (defined (_WIN32) && defined (_WIN32_WCE) && defined (ARM)) || (defined(__GNUC__) && defined(__arm__)) #ifdef __cplusplus extern "C" #endif diff --git a/src/libmad/layer3.c b/src/libmad/layer3.c index 66ed7c2..bc96433 100644 --- a/src/libmad/layer3.c +++ b/src/libmad/layer3.c @@ -20,6 +20,7 @@ */ #pragma GCC optimize ("O3") +#pragma GCC diagnostic ignored "-Wstrict-aliasing" #include # include "config.h" diff --git a/src/opusfile/opusfile.c b/src/opusfile/opusfile.c index 7ffe32f..95aab48 100644 --- a/src/opusfile/opusfile.c +++ b/src/opusfile/opusfile.c @@ -1422,7 +1422,7 @@ static int op_open_seekable2_impl(OggOpusFile *_of){ _of->end=sr[0].offset+sr[0].size; if(OP_UNLIKELY(_of->endserialnos,&_of->nserialnos,&_of->cserialnos); free(sr); return ret; diff --git a/tests/common.sh b/tests/common.sh index eaa9d6d..275cf1d 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -118,7 +118,30 @@ function install_esp8266() python3 get.py export PATH="$ide_path/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin:$PATH" popd +} +function install_rp2040() +{ + local ide_path=$1 + mkdir -p $ide_path/hardware + cd $ide_path/hardware + mkdir pico + cd pico + git clone https://github.com/earlephilhower/arduino-pico rp2040 + pushd rp2040/tools + # Set custom warnings for all builds (i.e. could add -Wextra at some point) + echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > ../platform.local.txt + echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> ../platform.local.txt + echo -e "\n----platform.local.txt----" + cat ../platform.local.txt + git submodule update --init + cd ../pico-sdk + git submodule update --init + cd ../tools + python3 get.py + export PATH="$ide_path/hardware/pico/rp2040/system/arm-none-eabi/bin:$PATH" + popd + cd rp2040 } function install_esp32() @@ -147,25 +170,19 @@ function install_esp32() function install_arduino() { # Install Arduino IDE and required libraries - echo -e "travis_fold:start:sketch_test_env_prepare" cd $TRAVIS_BUILD_DIR install_ide $HOME/arduino_ide $TRAVIS_BUILD_DIR which arduino cd $TRAVIS_BUILD_DIR install_libraries - echo -e "travis_fold:end:sketch_test_env_prepare" } function build_sketches_with_arduino() { # Compile sketches - echo -e "travis_fold:start:sketch_test" build_sketches $HOME/arduino_ide $HOME/Arduino/libraries "-l $HOME/Arduino/libraries" - echo -e "travis_fold:end:sketch_test" # Generate size report - echo -e "travis_fold:start:size_report" cat size.log - echo -e "travis_fold:end:size_report" } set -e @@ -184,11 +201,16 @@ elif [ "$BUILD_TYPE" = "build_esp32" ]; then install_arduino install_esp32 "$HOME/arduino_ide" export ide_path=$HOME/arduino_ide - export FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" + export FQBN="esp32:esp32:esp32:PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none" export GITHUB_WORKSPACE="$TRAVIS_BUILD_DIR" export GITHUB_REPOSITORY="$TRAVIS_REPO_SLUG" source $ide_path/hardware/espressif/esp32/.github/scripts/install-arduino-ide.sh source $ide_path/hardware/espressif/esp32/.github/scripts/install-arduino-core-esp32.sh build_sketches "$FQBN" "$HOME/Arduino/libraries" "$BUILD_REM" "$BUILD_MOD" +elif [ "$BUILD_TYPE" = "build_rp2040" ]; then + install_arduino + install_rp2040 "$HOME/arduino_ide" + export cache_dir=$(mktemp -d) + source "$HOME/arduino_ide/hardware/pico/rp2040/tests/common.sh" + build_sketches "$HOME/arduino_ide" "$TRAVIS_BUILD_DIR" "-l $HOME/Arduino/libraries" "$BUILD_MOD" "$BUILD_REM" fi -