Just a simple library for VLSI's mp3/midi codec chip

Dependents:   IsuProject_LPC1768

Revision:
4:6e0fb5342efa
Parent:
3:696c8e6744b2
Child:
5:cbf43dc9c947
--- 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() {