1
Dependents: internet_radio_leo
Fork of VS1053 by
Diff: VS1053.cpp
- Revision:
- 5:cbf43dc9c947
- Parent:
- 4:6e0fb5342efa
- Child:
- 6:1f57fbd3aeb5
diff -r 6e0fb5342efa -r cbf43dc9c947 VS1053.cpp --- a/VS1053.cpp Wed Dec 18 17:00:22 2013 +0000 +++ b/VS1053.cpp Thu Dec 19 19:14:15 2013 +0000 @@ -51,16 +51,16 @@ * @return Data length successfully sent. */ size_t VS1053::sendDataBlock(uint8_t* data, size_t length) { - size_t sizeSent = 0, n; + size_t n, sizeSent = 0; if (!data || !length) return 0; - while (sizeSent < length) { - n = length - sizeSent < 32 ? length - sizeSent : 32; + while (length) { + n = length < 32 ? length : 32; while (!dreq); bsync = 0; for (uint32_t i = 0; i < n; i++) { spi.write(*data++); - sizeSent++; + sizeSent++; length--; } bsync = 1; } @@ -96,8 +96,8 @@ */ bool VS1053::stop() { uint16_t reg; - uint8_t endFillByte; - size_t length; + uint8_t endFillByte; + size_t n, length; // If SM_CANCEL is still set, do nothing reg = readReg(SCI_MODE); @@ -113,14 +113,15 @@ endFillByte = reg & 0xff; length = 2052; while (length) { + n = length < 32 ? length : 32; while (!dreq); bsync = 0; - for (uint8_t i = 0; i < 32 && length--; i++) { + for (uint32_t i = 0; i < n; i++) { spi.write(endFillByte); + length--; } bsync = 1; } - // Check if both HDAT0 and HDAT1 are cleared return readReg(SCI_HDAT0) == 0x0000 && readReg(SCI_HDAT1) == 0x0000; }