From fcbef103857f59d67d5899c75cee1e8f6883aed0 Mon Sep 17 00:00:00 2001 From: Philipp Serr Date: Sat, 19 Mar 2022 18:58:02 +0100 Subject: [PATCH 1/4] Define bit value (_BV) macro if not available --- src/VS1053.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/VS1053.h b/src/VS1053.h index 9faf7b6..220cfdb 100644 --- a/src/VS1053.h +++ b/src/VS1053.h @@ -40,6 +40,10 @@ #include "patches/vs1053b-patches.h" +#ifndef _BV +#define _BV(bit) (1 << (bit)) +#endif + enum VS1053_I2S_RATE { VS1053_I2S_RATE_192_KHZ, VS1053_I2S_RATE_96_KHZ, From 4d46541fc54abf5a11b7ce934254e4d8f7ccd183 Mon Sep 17 00:00:00 2001 From: Philipp Serr Date: Sat, 19 Mar 2022 19:43:32 +0100 Subject: [PATCH 2/4] Use SPI.write* only for ESP, fallback to transfer* generic arduino SPI API only knows about SPI.transfer*. SPI.write* is ESP3266 specific. --- src/VS1053.cpp | 14 +++++++------- src/VS1053.h | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/VS1053.cpp b/src/VS1053.cpp index 0f17fe7..0759462 100644 --- a/src/VS1053.cpp +++ b/src/VS1053.cpp @@ -40,8 +40,8 @@ uint16_t VS1053::read_register(uint8_t _reg) const { uint16_t result; control_mode_on(); - SPI.write(3); // Read operation - SPI.write(_reg); // Register to read (0..0xF) + spi_write(3); // Read operation + spi_write(_reg); // Register to read (0..0xF) // Note: transfer16 does not seem to work result = (SPI.transfer(0xFF) << 8) | // Read 16 bits data (SPI.transfer(0xFF)); @@ -52,9 +52,9 @@ uint16_t VS1053::read_register(uint8_t _reg) const { void VS1053::writeRegister(uint8_t _reg, uint16_t _value) const { control_mode_on(); - SPI.write(2); // Write operation - SPI.write(_reg); // Register to write (0..0xF) - SPI.write16(_value); // Send 16 bits data + spi_write(2); // Write operation + spi_write(_reg); // Register to write (0..0xF) + spi_write16(_value); // Send 16 bits data await_data_request(); control_mode_off(); } @@ -71,7 +71,7 @@ void VS1053::sdi_send_buffer(uint8_t *data, size_t len) { chunk_length = vs1053_chunk_size; } len -= chunk_length; - SPI.writeBytes(data, chunk_length); + spi_write_bytes(data, chunk_length); data += chunk_length; } data_mode_off(); @@ -90,7 +90,7 @@ void VS1053::sdi_send_fillers(size_t len) { } len -= chunk_length; while (chunk_length--) { - SPI.write(endFillByte); + spi_write(endFillByte); } } data_mode_off(); diff --git a/src/VS1053.h b/src/VS1053.h index 220cfdb..8eec1e6 100644 --- a/src/VS1053.h +++ b/src/VS1053.h @@ -123,6 +123,32 @@ class VS1053 { void sdi_send_fillers(size_t length); + inline void spi_write(uint8_t data) const { +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + SPI.write(data); +#else + (void)SPI.transfer(data); +#endif + } + + inline void spi_write16(uint16_t data) const { +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + SPI.write16(data); +#else + (void)SPI.transfer16(data); +#endif + } + + inline void spi_write_bytes(const uint8_t * data, uint32_t size) const { +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + SPI.writeBytes(data, size); +#else + for (int i = 0; i < size; ++i) { + SPI.transfer(data[i]); + } +#endif + } + void wram_write(uint16_t address, uint16_t data); uint16_t wram_read(uint16_t address); From bdec0c599ae9580824bc727eed3c7bdaef014a68 Mon Sep 17 00:00:00 2001 From: Philipp Serr Date: Sat, 19 Mar 2022 19:50:24 +0100 Subject: [PATCH 3/4] Extend logging to rp2040 --- src/ConsoleLogger.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ConsoleLogger.h b/src/ConsoleLogger.h index 773b77d..40e5b4d 100644 --- a/src/ConsoleLogger.h +++ b/src/ConsoleLogger.h @@ -22,6 +22,8 @@ #define LOG(...) ESP_LOGD("ESP_VS1053", __VA_ARGS__) #elif defined(ARDUINO_ARCH_ESP8266) && defined(DEBUG_ESP_PORT) #define LOG(...) DEBUG_ESP_PORT.printf(__VA_ARGS__) + #elif defined(ARDUINO_ARCH_RP2040) && defined(DEBUG_RP2040_PORT) && defined(DEBUG_VS1053) + #define LOG(...) DEBUG_RP2040_PORT.printf(__VA_ARGS__) #else #define LOG(...) #endif From a36d64bd7a960502447ef8eb94bc4dac42e7dc2d Mon Sep 17 00:00:00 2001 From: Philipp Serr Date: Tue, 22 Mar 2022 15:09:10 +0100 Subject: [PATCH 4/4] Extend README regarding logging on RP2040 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c189592..3706fd7 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,10 @@ To see debug messages please add build flags to your `platformio.ini` as below ( `build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG` +- for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico) + +`build_flags = -DDEBUG_RP2040_PORT=Serial -DDEBUG_VS1053=true` + The Serial Interface needs to be initialized in the `setup()`. ```c++