Skip to content

Commit ba1803f

Browse files
authored
Add Get Chip Version and Stream Mode activation support (#79)
- added a support enabling stream mode and reading the chip version - adjusted documentation - fixed a problem of `.plg` extension (using a correct `.h`), which should fix a problem while loading default patches.
1 parent 3f5464b commit ba1803f

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ Then initialize the player and use as in following example:
5151

5252
```
5353
player.begin();
54-
player.loadDefaultVs1053Patches();
54+
if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
55+
player.loadDefaultVs1053Patches();
56+
}
5557
player.setVolume(VOLUME);
5658
player.switchToMp3Mode();
5759
player.playChunk(sampleMp3, sizeof(sampleMp3));
5860
```
5961

6062
For complete code please check [examples](https://github.com/baldram/ESP_VS1053_Library/tree/master/examples) folder.
61-
The example plays the sound like this [(click to listen to the sound)](https://drive.google.com/open?id=1Mm4dc-sM7KjZcKmv5g1nwhe3-qtm7yUl) every three minutes.
63+
The example plays the sound like this [(click to listen to the sound)](https://drive.google.com/open?id=1Mm4dc-sM7KjZcKmv5g1nwhe3-qtm7yUl) every three seconds.
6264

6365
Please note that `player.switchToMp3Mode()` is an optional switch. Some of VS1053 modules will start up in MIDI mode. The result is no audio when playing MP3.
6466
You can modify the board, but there is a more elegant way without soldering. For more details please read a discussion here: [http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773](http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773).
@@ -75,6 +77,9 @@ This is a lightweight method to check if VS1053 is correctly wired up (power sup
7577

7678
For additional information please see [this issue](https://github.com/baldram/ESP_VS1053_Library/issues/24).
7779

80+
##### Get chip version via `SCI_STATUS`
81+
A lot of the VS1003 and VS1053 devices completely look the same. They are even both labeled with "VS1003/1053 MP3 CODEC". To check which chip you are using use the `player.getChipVersion()`. It should return 4 for VS1053 and 3 for VS1003. This is also a lightweight method to check whether your VS10xx device is wired up correctly.
82+
7883
##### Check and reset decoding time by `SCI_DECODE_TIME`
7984

8085
`uint16_t seconds = player.getDecodedTime(); `

examples/Mp3PlayerDemo/Mp3PlayerDemo.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ void setup() {
7777
Serial.println("Hello VS1053!\n");
7878
// initialize a player
7979
player.begin();
80-
player.loadDefaultVs1053Patches();
80+
if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
81+
player.loadDefaultVs1053Patches();
82+
}
8183
player.switchToMp3Mode(); // optional, some boards require this
8284
player.setVolume(VOLUME);
8385
}

examples/WebRadioDemo/WebRadioDemo.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ void setup() {
101101
SPI.begin();
102102

103103
player.begin();
104-
player.loadDefaultVs1053Patches();
104+
if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
105+
player.loadDefaultVs1053Patches();
106+
}
105107
player.switchToMp3Mode();
106108
player.setVolume(VOLUME);
107109

src/VS1053.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@ void VS1053::softReset() {
271271
await_data_request();
272272
}
273273

274+
/**
275+
* VLSI datasheet: "SM_STREAM activates VS1053b’s stream mode. In this mode, data should be sent with as
276+
* even intervals as possible and preferable in blocks of less than 512 bytes, and VS1053b makes
277+
* every attempt to keep its input buffer half full by changing its playback speed up to 5%. For best
278+
* quality sound, the average speed error should be within 0.5%, the bitrate should not exceed
279+
* 160 kbit/s and VBR should not be used. For details, see Application Notes for VS10XX. This
280+
* mode only works with MP3 and WAV files."
281+
*/
282+
283+
void VS1053::streamModeOn() {
284+
LOG("Performing streamModeOn\n");
285+
writeRegister(SCI_MODE, _BV(SM_SDINEW) | _BV(SM_STREAM));
286+
delay(10);
287+
await_data_request();
288+
}
289+
290+
void VS1053::streamModeOff() {
291+
LOG("Performing streamModeOff\n");
292+
writeRegister(SCI_MODE, _BV(SM_SDINEW));
293+
delay(10);
294+
await_data_request();
295+
}
296+
274297
void VS1053::printDetails(const char *header) {
275298
uint16_t regbuf[16];
276299
uint8_t i;
@@ -314,6 +337,17 @@ bool VS1053::isChipConnected() {
314337
return !(status == 0 || status == 0xFFFF);
315338
}
316339

340+
/**
341+
* get the Version Number for the VLSI chip
342+
* VLSI datasheet: 0 for VS1001, 1 for VS1011, 2 for VS1002, 3 for VS1003, 4 for VS1053 and VS8053,
343+
* 5 for VS1033, 7 for VS1103, and 6 for VS1063.
344+
*/
345+
uint16_t VS1053::getChipVersion() {
346+
uint16_t status = read_register(SCI_STATUS);
347+
348+
return ( (status & 0x00F0) >> 4);
349+
}
350+
317351
/**
318352
* Provides current decoded time in full seconds (from SCI_DECODE_TIME register value)
319353
*

src/VS1053.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <SPI.h>
3939
#include "ConsoleLogger.h"
4040

41-
#include "patches/vs1053b-patches.plg"
41+
#include "patches/vs1053b-patches.h"
4242

4343
class VS1053 {
4444
private:
@@ -69,6 +69,7 @@ class VS1053 {
6969
const uint8_t SM_CANCEL = 3; // Bitnumber in SCI_MODE cancel song
7070
const uint8_t SM_TESTS = 5; // Bitnumber in SCI_MODE for tests
7171
const uint8_t SM_LINE1 = 14; // Bitnumber in SCI_MODE for Line input
72+
const uint8_t SM_STREAM = 6; // Bitnumber in SCI_MODE for Streaming Mode
7273
SPISettings VS1053_SPI; // SPI settings for this slave
7374
uint8_t endFillByte; // Byte to send when stopping song
7475
protected:
@@ -157,12 +158,21 @@ class VS1053 {
157158
// Fine tune the data rate
158159
void adjustRate(long ppm2);
159160

161+
// Streaming Mode On
162+
void streamModeOn();
163+
164+
// Default: Streaming Mode Off
165+
void streamModeOff();
166+
160167
// An optional switch preventing the module starting up in MIDI mode
161168
void switchToMp3Mode();
162169

163170
// Checks whether the VS1053 chip is connected and is able to exchange data to the ESP
164171
bool isChipConnected();
165172

173+
// gets Version of the VLSI chip being used
174+
uint16_t getChipVersion();
175+
166176
// Provides SCI_DECODE_TIME register value
167177
uint16_t getDecodedTime();
168178

File renamed without changes.

0 commit comments

Comments
 (0)