From 22434a33406b39ddaabd1212171f21587bd11f7c Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 14 Mar 2026 16:10:49 +0100 Subject: [PATCH 1/7] make SCI registers readable --- src/VS1053.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VS1053.h b/src/VS1053.h index 9faf7b6..5b33fe4 100644 --- a/src/VS1053.h +++ b/src/VS1053.h @@ -113,8 +113,6 @@ class VS1053 { SPI.endTransaction(); // Allow other SPI users } - uint16_t read_register(uint8_t _reg) const; - void sdi_send_buffer(uint8_t *data, size_t len); void sdi_send_fillers(size_t length); @@ -201,6 +199,8 @@ class VS1053 { // A low level method which lets users access the internals of the VS1053. void writeRegister(uint8_t _reg, uint16_t _value) const; + uint16_t read_register(uint8_t _reg) const; + // Load a patch or plugin to fix bugs and/or extend functionality. // For more info about patches see http://www.vlsi.fi/en/support/software/vs10xxpatches.html void loadUserCode(const unsigned short* plugin, unsigned short plugin_size); From b550ecc90ade20efe2febef243170ab69da830f9 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 14 Mar 2026 16:16:37 +0100 Subject: [PATCH 2/7] Make function name camelCase --- src/VS1053.cpp | 20 ++++++++++---------- src/VS1053.h | 4 +++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/VS1053.cpp b/src/VS1053.cpp index 0f17fe7..fd97b2b 100644 --- a/src/VS1053.cpp +++ b/src/VS1053.cpp @@ -36,7 +36,7 @@ VS1053::VS1053(uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin) : cs_pin(_cs_pin), dcs_pin(_dcs_pin), dreq_pin(_dreq_pin) { } -uint16_t VS1053::read_register(uint8_t _reg) const { +uint16_t VS1053::readRegister(uint8_t _reg) const { uint16_t result; control_mode_on(); @@ -103,7 +103,7 @@ void VS1053::wram_write(uint16_t address, uint16_t data) { uint16_t VS1053::wram_read(uint16_t address) { writeRegister(SCI_WRAMADDR, address); // Start reading from WRAM - return read_register(SCI_WRAM); // Read back result + return readRegister(SCI_WRAM); // Read back result } bool VS1053::testComm(const char *header) { @@ -133,8 +133,8 @@ bool VS1053::testComm(const char *header) { for (i = 0; (i < 0xFFFF) && (cnt < 20); i += delta) { writeRegister(SCI_VOL, i); // Write data to SCI_VOL - r1 = read_register(SCI_VOL); // Read back for the first time - r2 = read_register(SCI_VOL); // Read back a second time + r1 = readRegister(SCI_VOL); // Read back for the first time + r2 = readRegister(SCI_VOL); // Read back a second time if (r1 != r2 || i != r1 || i != r2) // Check for 2 equal reads { LOG("VS1053 error retry SB:%04X R1:%04X R2:%04X\n", i, r1, r2); @@ -253,7 +253,7 @@ void VS1053::stopSong() { writeRegister(SCI_MODE, _BV(SM_SDINEW) | _BV(SM_CANCEL)); for (i = 0; i < 200; i++) { sdi_send_fillers(32); - modereg = read_register(SCI_MODE); // Read status + modereg = readRegister(SCI_MODE); // Read status if ((modereg & _BV(SM_CANCEL)) == 0) { sdi_send_fillers(2052); LOG("Song stopped correctly after %d msec\n", i * 10); @@ -303,7 +303,7 @@ void VS1053::printDetails(const char *header) { LOG("REG Contents\n"); LOG("--- -----\n"); for (i = 0; i <= SCI_num_registers; i++) { - regbuf[i] = read_register(i); + regbuf[i] = readRegister(i); } for (i = 0; i <= SCI_num_registers; i++) { delay(5); @@ -365,7 +365,7 @@ void VS1053::enableI2sOut(VS1053_I2S_RATE i2sRate) { * @return true if the chip is wired up correctly */ bool VS1053::isChipConnected() { - uint16_t status = read_register(SCI_STATUS); + uint16_t status = readRegister(SCI_STATUS); return !(status == 0 || status == 0xFFFF); } @@ -376,7 +376,7 @@ bool VS1053::isChipConnected() { * 5 for VS1033, 7 for VS1103, and 6 for VS1063. */ uint16_t VS1053::getChipVersion() { - uint16_t status = read_register(SCI_STATUS); + uint16_t status = readRegister(SCI_STATUS); return ( (status & 0x00F0) >> 4); } @@ -402,7 +402,7 @@ uint16_t VS1053::getChipVersion() { * @return current decoded time in full seconds */ uint16_t VS1053::getDecodedTime() { - return read_register(SCI_DECODE_TIME); + return readRegister(SCI_DECODE_TIME); } /** @@ -429,7 +429,7 @@ void VS1053::adjustRate(long ppm2) { writeRegister(SCI_WRAMADDR, 0x5b1c); writeRegister(SCI_WRAM, 0); // Write to AUDATA or CLOCKF checks rate and recalculates adjustment. - writeRegister(SCI_AUDATA, read_register(SCI_AUDATA)); + writeRegister(SCI_AUDATA, readRegister(SCI_AUDATA)); } /** diff --git a/src/VS1053.h b/src/VS1053.h index 5b33fe4..ba167df 100644 --- a/src/VS1053.h +++ b/src/VS1053.h @@ -199,7 +199,9 @@ class VS1053 { // A low level method which lets users access the internals of the VS1053. void writeRegister(uint8_t _reg, uint16_t _value) const; - uint16_t read_register(uint8_t _reg) const; + // Reads from the VS10xx's SCI (serial command interface) SPI bus. + // A low level method which lets users access the internals of the VS1053. + uint16_t readRegister(uint8_t _reg) const; // Load a patch or plugin to fix bugs and/or extend functionality. // For more info about patches see http://www.vlsi.fi/en/support/software/vs10xxpatches.html From 75c967e7d0ef160ff972119c562598aa0d54b761 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 14 Mar 2026 16:19:53 +0100 Subject: [PATCH 3/7] Added SCI_HDAT0 and SCI_HDAT1 register definition --- src/VS1053.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/VS1053.h b/src/VS1053.h index ba167df..9794610 100644 --- a/src/VS1053.h +++ b/src/VS1053.h @@ -64,6 +64,8 @@ class VS1053 { const uint8_t SCI_AUDATA = 0x5; const uint8_t SCI_WRAM = 0x6; const uint8_t SCI_WRAMADDR = 0x7; + const uint8_t SCI_HDAT0 = 0x08; + const uint8_t SCI_HDAT1 = 0x09; const uint8_t SCI_AIADDR = 0xA; const uint8_t SCI_VOL = 0xB; const uint8_t SCI_AICTRL0 = 0xC; From de3b69246d95d2d03f25302df20d78bd5d89f009 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sun, 22 Mar 2026 10:55:08 +0100 Subject: [PATCH 4/7] * Convert .plg to .h * Rename conflicting PLUGIN_SIZE --- src/VS1053.h | 4 ++++ ...053b-patches-flac-latm.plg => vs1053b-patches-flac-latm.h} | 2 +- .../{vs1053b-patches-flac.plg => vs1053b-patches-flac.h} | 2 +- .../{vs1053b-patches-latm.plg => vs1053b-patches-latm.h} | 2 +- .../{vs1053b-patches-pitch.plg => vs1053b-patches-pitch.h} | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) rename src/patches/{vs1053b-patches-flac-latm.plg => vs1053b-patches-flac-latm.h} (99%) rename src/patches/{vs1053b-patches-flac.plg => vs1053b-patches-flac.h} (99%) rename src/patches/{vs1053b-patches-latm.plg => vs1053b-patches-latm.h} (99%) rename src/patches/{vs1053b-patches-pitch.plg => vs1053b-patches-pitch.h} (99%) diff --git a/src/VS1053.h b/src/VS1053.h index 9794610..25d0a00 100644 --- a/src/VS1053.h +++ b/src/VS1053.h @@ -39,6 +39,10 @@ #include "ConsoleLogger.h" #include "patches/vs1053b-patches.h" +#include "patches/vs1053b-patches-flac.h" +#include "patches/vs1053b-patches-flac-latm.h" +#include "patches/vs1053b-patches-latm.h" +#include "patches/vs1053b-patches-pitch.h" enum VS1053_I2S_RATE { VS1053_I2S_RATE_192_KHZ, diff --git a/src/patches/vs1053b-patches-flac-latm.plg b/src/patches/vs1053b-patches-flac-latm.h similarity index 99% rename from src/patches/vs1053b-patches-flac-latm.plg rename to src/patches/vs1053b-patches-flac-latm.h index 512cf72..fb525ed 100644 --- a/src/patches/vs1053b-patches-flac-latm.plg +++ b/src/patches/vs1053b-patches-flac-latm.h @@ -1111,7 +1111,7 @@ const unsigned short PATCHES_FLAC_LATM[] = { /* Compressed plugin */ 0x0004,0x0000,0xfffa,0xffff,0x0004,0x0000,0xffff,0xffff, 0x000a,0x0001, /*copy 1*/ 0x0050, -#define PLUGIN_SIZE 8588 +#define PATCHES_FLAC_LATM_SIZE 8588 #ifndef SKIP_PLUGIN_VARNAME }; #endif diff --git a/src/patches/vs1053b-patches-flac.plg b/src/patches/vs1053b-patches-flac.h similarity index 99% rename from src/patches/vs1053b-patches-flac.plg rename to src/patches/vs1053b-patches-flac.h index cbaebc9..8534123 100644 --- a/src/patches/vs1053b-patches-flac.plg +++ b/src/patches/vs1053b-patches-flac.h @@ -1093,7 +1093,7 @@ const unsigned short PATCHES_FLAC[] = { /* Compressed plugin */ 0x0004,0x0000,0xfffa,0xffff,0x0004,0x0000,0xffff,0xffff, 0x000a,0x0001, /*copy 1*/ 0x0050, -#define PLUGIN_SIZE 8414 +#define FLAC_SIZE 8414 #ifndef SKIP_PLUGIN_VARNAME }; #endif diff --git a/src/patches/vs1053b-patches-latm.plg b/src/patches/vs1053b-patches-latm.h similarity index 99% rename from src/patches/vs1053b-patches-latm.plg rename to src/patches/vs1053b-patches-latm.h index 8b0aefc..0e4eaa5 100644 --- a/src/patches/vs1053b-patches-latm.plg +++ b/src/patches/vs1053b-patches-latm.h @@ -731,7 +731,7 @@ const unsigned short PATCHES_LATM[] = { /* Compressed plugin */ 0x0775,0x077b, 0x000a,0x0001, /*copy 1*/ 0x0050, -#define PLUGIN_SIZE 5594 +#define LATM_SIZE 5594 #ifndef SKIP_PLUGIN_VARNAME }; #endif diff --git a/src/patches/vs1053b-patches-pitch.plg b/src/patches/vs1053b-patches-pitch.h similarity index 99% rename from src/patches/vs1053b-patches-pitch.plg rename to src/patches/vs1053b-patches-pitch.h index fe362b7..144ff5e 100644 --- a/src/patches/vs1053b-patches-pitch.plg +++ b/src/patches/vs1053b-patches-pitch.h @@ -783,7 +783,7 @@ const unsigned short PATCHES_PITCH[] = { /* Compressed plugin */ 0x0006, 0x8006, 0x0000, /*Rle(6)*/ 0x000a,0x0001, /*copy 1*/ 0x0050, -#define PLUGIN_SIZE 5964 +#define PITCH_SIZE 5964 #ifndef SKIP_PLUGIN_VARNAME }; #endif From 4db7307bfdaf93578bcf9543bf1989f8e9977dc2 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sun, 22 Mar 2026 12:54:49 +0100 Subject: [PATCH 5/7] Rename xxx_SIZE #defines --- src/patches/vs1053b-patches-flac.h | 2 +- src/patches/vs1053b-patches-latm.h | 2 +- src/patches/vs1053b-patches-pitch.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/patches/vs1053b-patches-flac.h b/src/patches/vs1053b-patches-flac.h index 8534123..09dab1b 100644 --- a/src/patches/vs1053b-patches-flac.h +++ b/src/patches/vs1053b-patches-flac.h @@ -1093,7 +1093,7 @@ const unsigned short PATCHES_FLAC[] = { /* Compressed plugin */ 0x0004,0x0000,0xfffa,0xffff,0x0004,0x0000,0xffff,0xffff, 0x000a,0x0001, /*copy 1*/ 0x0050, -#define FLAC_SIZE 8414 +#define PATCHES_FLAC_SIZE 8414 #ifndef SKIP_PLUGIN_VARNAME }; #endif diff --git a/src/patches/vs1053b-patches-latm.h b/src/patches/vs1053b-patches-latm.h index 0e4eaa5..c5755bb 100644 --- a/src/patches/vs1053b-patches-latm.h +++ b/src/patches/vs1053b-patches-latm.h @@ -731,7 +731,7 @@ const unsigned short PATCHES_LATM[] = { /* Compressed plugin */ 0x0775,0x077b, 0x000a,0x0001, /*copy 1*/ 0x0050, -#define LATM_SIZE 5594 +#define PATCHES_LATM_SIZE 5594 #ifndef SKIP_PLUGIN_VARNAME }; #endif diff --git a/src/patches/vs1053b-patches-pitch.h b/src/patches/vs1053b-patches-pitch.h index 144ff5e..feeb42b 100644 --- a/src/patches/vs1053b-patches-pitch.h +++ b/src/patches/vs1053b-patches-pitch.h @@ -783,7 +783,7 @@ const unsigned short PATCHES_PITCH[] = { /* Compressed plugin */ 0x0006, 0x8006, 0x0000, /*Rle(6)*/ 0x000a,0x0001, /*copy 1*/ 0x0050, -#define PITCH_SIZE 5964 +#define PATCHES_PITCH_SIZE 5964 #ifndef SKIP_PLUGIN_VARNAME }; #endif From c329ce13dbdb85fd80cd1517dca737d293843ef5 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sun, 22 Mar 2026 20:32:39 +0100 Subject: [PATCH 6/7] Fixed audio bleedover? --- src/VS1053.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VS1053.cpp b/src/VS1053.cpp index fd97b2b..fb9c956 100644 --- a/src/VS1053.cpp +++ b/src/VS1053.cpp @@ -237,7 +237,7 @@ int8_t VS1053::getBalance() { // Get the currenet balance setting. } void VS1053::startSong() { - sdi_send_fillers(10); + sdi_send_fillers(12288); // FLAC has a 12kB decode buffer } void VS1053::playChunk(uint8_t *data, size_t len) { From 172ad77daf735d9e8323cc7bd436099b43604cc1 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sun, 22 Mar 2026 21:21:21 +0100 Subject: [PATCH 7/7] Restore fillers in startSong() --- src/VS1053.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VS1053.cpp b/src/VS1053.cpp index fb9c956..fd97b2b 100644 --- a/src/VS1053.cpp +++ b/src/VS1053.cpp @@ -237,7 +237,7 @@ int8_t VS1053::getBalance() { // Get the currenet balance setting. } void VS1053::startSong() { - sdi_send_fillers(12288); // FLAC has a 12kB decode buffer + sdi_send_fillers(10); } void VS1053::playChunk(uint8_t *data, size_t len) {