Skip to content

Commit f501eb7

Browse files
authored
Fix load user code bug (#82)
A fix for bug in `loadUserCode`. This seems like incompatible change, as the second argument was introduced, however the previous version is buggy and it's better to get a compilation error, and adjust a code to get rid of bug (if a new loadUserCode was already used). Please also see a discussion here: #66 (comment)
1 parent fdbe2a0 commit f501eb7

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/VS1053.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,22 @@ void VS1053::adjustRate(long ppm2) {
401401

402402
/**
403403
* Load a patch or plugin
404+
*
405+
* Patches can be found on the VLSI Website http://www.vlsi.fi/en/support/software/vs10xxpatches.html
406+
*
407+
* Please note that loadUserCode only works for compressed plugins (file ending .plg).
408+
* To include them, rename them to file ending .h
409+
* Please also note that, in order to avoid multiple definitions, if you are using more than one patch,
410+
* it is necessary to rename the name of the array plugin[] and the name of PLUGIN_SIZE to names of your choice.
411+
* example: after renaming plugin[] to plugin_myname[] and PLUGIN_SIZE to PLUGIN_MYNAME_SIZE
412+
* the method is called by player.loadUserCode(plugin_myname, PLUGIN_MYNAME_SIZE)
413+
* It is also possible to just rename the array plugin[] to a name of your choice
414+
* example: after renaming plugin[] to plugin_myname[]
415+
* the method is called by player.loadUserCode(plugin_myname, sizeof(plugin_myname)/sizeof(plugin_myname[0]))
404416
*/
405-
void VS1053::loadUserCode(const unsigned short* plugin) {
417+
void VS1053::loadUserCode(const unsigned short* plugin, unsigned short plugin_size) {
406418
int i = 0;
407-
while (i<sizeof(plugin)/sizeof(plugin[0])) {
419+
while (i<plugin_size) {
408420
unsigned short addr, n, val;
409421
addr = plugin[i++];
410422
n = plugin[i++];
@@ -427,5 +439,5 @@ void VS1053::loadUserCode(const unsigned short* plugin) {
427439
* Load the latest generic firmware patch
428440
*/
429441
void VS1053::loadDefaultVs1053Patches() {
430-
loadUserCode(PATCHES);
442+
loadUserCode(PATCHES,PATCHES_SIZE);
431443
};

src/VS1053.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class VS1053 {
185185

186186
// Load a patch or plugin to fix bugs and/or extend functionality.
187187
// For more info about patches see http://www.vlsi.fi/en/support/software/vs10xxpatches.html
188-
void loadUserCode(const unsigned short* plugin);
188+
void loadUserCode(const unsigned short* plugin, unsigned short plugin_size);
189189

190190
// Loads the latest generic firmware patch.
191191
void loadDefaultVs1053Patches();

src/patches/vs1053b-patches.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ const unsigned short PATCHES[] = { /* Compressed plugin */
618618
0x2a01,0x824e,
619619
0x000a,0x0001, /*copy 1*/
620620
0x0050,
621-
#define PLUGIN_SIZE 4667
621+
#define PATCHES_SIZE 4667
622622
#ifndef SKIP_PLUGIN_VARNAME
623623
};
624624
#endif

0 commit comments

Comments
 (0)