modified for VS1033
Dependents: 11U68_MP3Player with TFTLCD 11U68_MP3Player-with-TFTLCD Mp3_1
Fork of VS1033 by
Revision 4:6e0fb5342efa, committed 2013-12-18
- Comitter:
- kayekss
- Date:
- Wed Dec 18 17:00:22 2013 +0000
- Parent:
- 3:696c8e6744b2
- Child:
- 5:cbf43dc9c947
- Commit message:
- Fixed a bug where sendDataBlock hangs up
Changed in this revision
VS1053.cpp | Show annotated file Show diff for this revision Revisions of this file |
VS1053.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/VS1053.cpp Wed Dec 04 16:58:44 2013 +0000 +++ b/VS1053.cpp Wed Dec 18 17:00:22 2013 +0000 @@ -1,4 +1,4 @@ -// ==================================================== Dec 05 2013, kayeks == +// ==================================================== Dec 18 2013, kayeks == // VS1053.cpp // =========================================================================== // Just a simple library for VLSI's mp3/midi codec chip @@ -50,15 +50,16 @@ /** Send a data block specified as a pointer to VS1053. * @return Data length successfully sent. */ -size_t VS1053::sendDataBlock(uint8_t* pData, size_t length) { - size_t sizeSent = 0; +size_t VS1053::sendDataBlock(uint8_t* data, size_t length) { + size_t sizeSent = 0, n; - if (!pData || !length) return 0; - while (length) { + if (!data || !length) return 0; + while (sizeSent < length) { + n = length - sizeSent < 32 ? length - sizeSent : 32; while (!dreq); bsync = 0; - for (uint8_t i = 0; i < 32 && length--; i++) { - spi.write(*pData++); + for (uint32_t i = 0; i < n; i++) { + spi.write(*data++); sizeSent++; } bsync = 1; @@ -70,6 +71,7 @@ void VS1053::clockUp() { // Set CLKI to 43.0-55.3 MHz writeReg(SCI_CLOCKF, 0x8800); // SC_MULT=4 (3.5x), SC_ADD=1 (+1.0x) + wait(0.01); } /** Send cancel request to VS1053. @@ -88,8 +90,8 @@ return true; } -/** Attempts a termination of playing. - * Call this repeatedly during data stream tramsission until it successes. +/** Attempt a termination of playing. + * Please call this repeatedly during data stream tramsission until it successes. * @return Zero at failure, non-zero at success. */ bool VS1053::stop() {
--- a/VS1053.h Wed Dec 04 16:58:44 2013 +0000 +++ b/VS1053.h Wed Dec 18 17:00:22 2013 +0000 @@ -1,4 +1,4 @@ -// ==================================================== Dec 05 2013, kayeks == +// ==================================================== Dec 18 2013, kayeks == // VS1053.h // =========================================================================== // Just a simple library for VLSI's mp3/midi codec chip @@ -10,10 +10,10 @@ /** Class VS1053. Drives VLSI's mp3/midi codec chip. */ class VS1053 { private: - SPI spi; + SPI spi; DigitalOut cs; DigitalOut bsync; - DigitalIn dreq; + DigitalIn dreq; DigitalOut rst; public: @@ -40,7 +40,7 @@ ~VS1053(); void hardwareReset(); void sendDataByte(uint8_t data); - size_t sendDataBlock(uint8_t* pData, size_t length); + size_t sendDataBlock(uint8_t* data, size_t length); void clockUp(); bool sendCancel(); bool stop();