Skip to content

Commit a991f26

Browse files
jcwrenmatthijskooijman
authored andcommitted
Sd2Card.cpp: fix compiler warning
All the while() loops that check for the SPI transfer to be complete have the semi-colon immediately after the closing parenthesis. This both causes a compiler warning of "warning: suggest a space before ';' or explicit braces around empty body in 'while' statement", and is considered a less-than-ideal programming practice. This patch breaks the semi-colon on to the next line, both eliminating the compiler error and making the code more readable. In all probability the test should be moved into a macro or a inlineable sub-routine.
1 parent ece02e9 commit a991f26

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

libraries/SD/src/utility/Sd2Card.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
static void spiSend(uint8_t b) {
3131
#ifndef USE_SPI_LIB
3232
SPDR = b;
33-
while (!(SPSR & (1 << SPIF)));
33+
while (!(SPSR & (1 << SPIF)))
34+
;
3435
#else
3536
SPI.transfer(b);
3637
#endif
@@ -124,7 +125,8 @@ uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
124125
spiSend(crc);
125126

126127
// wait for response
127-
for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++);
128+
for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++)
129+
;
128130
return status_;
129131
}
130132
//------------------------------------------------------------------------------
@@ -383,18 +385,21 @@ uint8_t Sd2Card::readData(uint32_t block,
383385

384386
// skip data before offset
385387
for (;offset_ < offset; offset_++) {
386-
while (!(SPSR & (1 << SPIF)));
388+
while (!(SPSR & (1 << SPIF)))
389+
;
387390
SPDR = 0XFF;
388391
}
389392
// transfer data
390393
n = count - 1;
391394
for (uint16_t i = 0; i < n; i++) {
392-
while (!(SPSR & (1 << SPIF)));
395+
while (!(SPSR & (1 << SPIF)))
396+
;
393397
dst[i] = SPDR;
394398
SPDR = 0XFF;
395399
}
396400
// wait for last byte
397-
while (!(SPSR & (1 << SPIF)));
401+
while (!(SPSR & (1 << SPIF)))
402+
;
398403
dst[n] = SPDR;
399404

400405
#else // OPTIMIZE_HARDWARE_SPI
@@ -429,11 +434,13 @@ void Sd2Card::readEnd(void) {
429434
// optimize skip for hardware
430435
SPDR = 0XFF;
431436
while (offset_++ < 513) {
432-
while (!(SPSR & (1 << SPIF)));
437+
while (!(SPSR & (1 << SPIF)))
438+
;
433439
SPDR = 0XFF;
434440
}
435441
// wait for last crc byte
436-
while (!(SPSR & (1 << SPIF)));
442+
while (!(SPSR & (1 << SPIF)))
443+
;
437444
#else // OPTIMIZE_HARDWARE_SPI
438445
while (offset_++ < 514) spiRec();
439446
#endif // OPTIMIZE_HARDWARE_SPI
@@ -602,14 +609,17 @@ uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
602609

603610
// send two byte per iteration
604611
for (uint16_t i = 0; i < 512; i += 2) {
605-
while (!(SPSR & (1 << SPIF)));
612+
while (!(SPSR & (1 << SPIF)))
613+
;
606614
SPDR = src[i];
607-
while (!(SPSR & (1 << SPIF)));
615+
while (!(SPSR & (1 << SPIF)))
616+
;
608617
SPDR = src[i+1];
609618
}
610619

611620
// wait for last data byte
612-
while (!(SPSR & (1 << SPIF)));
621+
while (!(SPSR & (1 << SPIF)))
622+
;
613623

614624
#else // OPTIMIZE_HARDWARE_SPI
615625
spiSend(token);

0 commit comments

Comments
 (0)