Skip to content

Commit

Permalink
Add Get Chip Version and Stream Mode activation support (#79)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Dr-Dawg committed Sep 2, 2021
1 parent 3f5464b commit ba1803f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ Then initialize the player and use as in following example:

```
player.begin();
player.loadDefaultVs1053Patches();
if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
player.loadDefaultVs1053Patches();
}
player.setVolume(VOLUME);
player.switchToMp3Mode();
player.playChunk(sampleMp3, sizeof(sampleMp3));
```

For complete code please check [examples](https://github.com/baldram/ESP_VS1053_Library/tree/master/examples) folder.
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.
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.

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.
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).
Expand All @@ -75,6 +77,9 @@ This is a lightweight method to check if VS1053 is correctly wired up (power sup

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

##### Get chip version via `SCI_STATUS`
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.

##### Check and reset decoding time by `SCI_DECODE_TIME`

`uint16_t seconds = player.getDecodedTime(); `
Expand Down
4 changes: 3 additions & 1 deletion examples/Mp3PlayerDemo/Mp3PlayerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ void setup() {
Serial.println("Hello VS1053!\n");
// initialize a player
player.begin();
player.loadDefaultVs1053Patches();
if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
player.loadDefaultVs1053Patches();
}
player.switchToMp3Mode(); // optional, some boards require this
player.setVolume(VOLUME);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/WebRadioDemo/WebRadioDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ void setup() {
SPI.begin();

player.begin();
player.loadDefaultVs1053Patches();
if (player.getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003
player.loadDefaultVs1053Patches();
}
player.switchToMp3Mode();
player.setVolume(VOLUME);

Expand Down
34 changes: 34 additions & 0 deletions src/VS1053.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,29 @@ void VS1053::softReset() {
await_data_request();
}

/**
* VLSI datasheet: "SM_STREAM activates VS1053b’s stream mode. In this mode, data should be sent with as
* even intervals as possible and preferable in blocks of less than 512 bytes, and VS1053b makes
* every attempt to keep its input buffer half full by changing its playback speed up to 5%. For best
* quality sound, the average speed error should be within 0.5%, the bitrate should not exceed
* 160 kbit/s and VBR should not be used. For details, see Application Notes for VS10XX. This
* mode only works with MP3 and WAV files."
*/

void VS1053::streamModeOn() {
LOG("Performing streamModeOn\n");
writeRegister(SCI_MODE, _BV(SM_SDINEW) | _BV(SM_STREAM));
delay(10);
await_data_request();
}

void VS1053::streamModeOff() {
LOG("Performing streamModeOff\n");
writeRegister(SCI_MODE, _BV(SM_SDINEW));
delay(10);
await_data_request();
}

void VS1053::printDetails(const char *header) {
uint16_t regbuf[16];
uint8_t i;
Expand Down Expand Up @@ -314,6 +337,17 @@ bool VS1053::isChipConnected() {
return !(status == 0 || status == 0xFFFF);
}

/**
* get the Version Number for the VLSI chip
* VLSI datasheet: 0 for VS1001, 1 for VS1011, 2 for VS1002, 3 for VS1003, 4 for VS1053 and VS8053,
* 5 for VS1033, 7 for VS1103, and 6 for VS1063.
*/
uint16_t VS1053::getChipVersion() {
uint16_t status = read_register(SCI_STATUS);

return ( (status & 0x00F0) >> 4);
}

/**
* Provides current decoded time in full seconds (from SCI_DECODE_TIME register value)
*
Expand Down
12 changes: 11 additions & 1 deletion src/VS1053.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <SPI.h>
#include "ConsoleLogger.h"

#include "patches/vs1053b-patches.plg"
#include "patches/vs1053b-patches.h"

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

// Streaming Mode On
void streamModeOn();

// Default: Streaming Mode Off
void streamModeOff();

// An optional switch preventing the module starting up in MIDI mode
void switchToMp3Mode();

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

// gets Version of the VLSI chip being used
uint16_t getChipVersion();

// Provides SCI_DECODE_TIME register value
uint16_t getDecodedTime();

Expand Down
File renamed without changes.

0 comments on commit ba1803f

Please sign in to comment.