Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
2 changes: 2 additions & 0 deletions src/ConsoleLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/VS1053.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down
30 changes: 30 additions & 0 deletions src/VS1053.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -119,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);
Expand Down