Skip to content

Commit c8dd35a

Browse files
authored
Add support for reading and clearing decoded time by SCI_DECODE_TIME #41 (#42)
* Add support for check and reset decoding time by SCI_DECODE_TIME Implemented handling for SCI_DECODE_TIME register according to VS1053b Datasheet specification (v1.20). When decoding correct data, current decoded time is shown in this register in full seconds. Extended API with two methods. One provides estimation of decoding time using SCI_DECODE_TIME. The other one allows to clear the value of mentioned register. Update documentation and bumped version for release.
1 parent aa80f2b commit c8dd35a

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ Please note that `player.switchToMp3Mode()` is an optional switch. Some of VS105
6363
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).
6464
<br />No side effects for boards which do not need this switch, so you can call it just in case.
6565

66+
#### Additionall functionality
67+
68+
Below briefly described. For detailed information please see [VS1053b Datasheet specification](http://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf).
69+
70+
##### Test VS1053 chip via `SCI_STATUS`
71+
To check if the VS1053 chip is connected and able to exchange data to the microcontroller use the `player.isChipConnected()`.
72+
73+
This is a lightweight method to check if VS1053 is correctly wired up (power supply and connection to SPI interface).
74+
75+
For additional information please see [this issue](https://github.com/baldram/ESP_VS1053_Library/issues/24).
76+
77+
##### Check and reset decoding time by `SCI_DECODE_TIME`
78+
79+
`uint16_t seconds = player.getDecodedTime(); `
80+
81+
Above example and self-explanatory method name tells everything. It simply provides current decoded time in full seconds (from `SCI_DECODE_TIME` register value).
82+
83+
Optionally available is also `player.clearDecodedTime()` which clears decoded time (sets `SCI_DECODE_TIME` register to `0x00`).
84+
6685
#### Logging / debugging
6786

6887
The library uses ESP Arduino framework built in logger (Arduino core for [ESP32](https://github.com/espressif/arduino-esp32/issues/893#issuecomment-348069135) and [ESP8266](https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst#debug-level)).<br />

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP_VS1053_Library",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"keywords": "vs1053, esp8266, esp32, nodemcu, codec, mp3",
55
"description": "This is a driver library for VS1053 MP3 Codec Breakout adapted for Espressif ESP8266 and ESP32 boards",
66
"authors": [

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=VS1053 Library for ESP8266/ESP32
2-
version=1.1.1
2+
version=1.1.2
33
author=Baldram
44
maintainer=Baldram <[email protected]>
55
sentence=This is a driver library for VS1053 MP3 Codec Breakout adapted for Espressif ESP8266 and ESP32 boards

src/VS1053.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,40 @@ bool VS1053::isChipConnected() {
289289

290290
return !(status == 0 || status == 0xFFFF);
291291
}
292+
293+
/**
294+
* Provides current decoded time in full seconds (from SCI_DECODE_TIME register value)
295+
*
296+
* When decoding correct data, current decoded time is shown in SCI_DECODE_TIME
297+
* register in full seconds. The user may change the value of this register.
298+
* In that case the new value should be written twice to make absolutely certain
299+
* that the change is not overwritten by the firmware. A write to SCI_DECODE_TIME
300+
* also resets the byteRate calculation.
301+
*
302+
* SCI_DECODE_TIME is reset at every hardware and software reset. It is no longer
303+
* cleared when decoding of a file ends to allow the decode time to proceed
304+
* automatically with looped files and with seamless playback of multiple files.
305+
* With fast playback (see the playSpeed extra parameter) the decode time also
306+
* counts faster. Some codecs (WMA and Ogg Vorbis) can also indicate the absolute
307+
* play position, see the positionMsec extra parameter in section 10.11.
308+
*
309+
* @see VS1053b Datasheet (1.31) / 9.6.5 SCI_DECODE_TIME (RW)
310+
*
311+
* @return current decoded time in full seconds
312+
*/
313+
uint16_t VS1053::getDecodedTime() {
314+
return read_register(SCI_DECODE_TIME);
315+
}
316+
317+
/**
318+
* Clears decoded time (sets SCI_DECODE_TIME register to 0x00)
319+
*
320+
* The user may change the value of this register. In that case the new value
321+
* should be written twice to make absolutely certain that the change is not
322+
* overwritten by the firmware. A write to SCI_DECODE_TIME also resets the
323+
* byteRate calculation.
324+
*/
325+
void VS1053::clearDecodedTime() {
326+
write_register(SCI_DECODE_TIME, 0x00);
327+
write_register(SCI_DECODE_TIME, 0x00);
328+
}

src/VS1053.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class VS1053 {
5050
const uint8_t SCI_STATUS = 0x1;
5151
const uint8_t SCI_BASS = 0x2;
5252
const uint8_t SCI_CLOCKF = 0x3;
53+
const uint8_t SCI_DECODE_TIME = 0x4; // current decoded time in full seconds
5354
const uint8_t SCI_AUDATA = 0x5;
5455
const uint8_t SCI_WRAM = 0x6;
5556
const uint8_t SCI_WRAMADDR = 0x7;
@@ -135,6 +136,10 @@ class VS1053 {
135136
void switchToMp3Mode();
136137

137138
bool isChipConnected();
139+
140+
uint16_t getDecodedTime(); // Provides SCI_DECODE_TIME register value
141+
142+
void clearDecodedTime(); // Clears SCI_DECODE_TIME register (sets 0x00)
138143
};
139144

140145
#endif

0 commit comments

Comments
 (0)