Skip to content

Commit aa013bd

Browse files
committed
- more minor coding standard fixes
1 parent 2d0bedc commit aa013bd

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

libraries/SPI/SPI.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ void ArduinoSPI::transfer(void *buf, size_t count)
259259
}
260260
else
261261
{
262-
if (buf) {
262+
if (buf != NULL) {
263263
uint32_t *buffer32 = (uint32_t *) buf;
264264
size_t ir = 0;
265265
size_t it = 0;
266-
size_t n32 = count / 4U;
267-
count &= 3U;
266+
size_t const n32 = count / 4U;
267+
uint8_t const bytes_remaining = (uint8_t) (count & 3U);
268268

269-
if (n32) {
269+
if (n32 != 0U) {
270270
_spi_ctrl.p_regs->SPCR_b.SPE = 0; /* disable SPI unit */
271271
_spi_ctrl.p_regs->SPDCR = R_SPI0_SPDCR_SPLW_Msk; /* SPI word access */
272272
_spi_ctrl.p_regs->SPCMD_b[0].SPB = 2; /* spi bit width = 32 */
@@ -303,14 +303,13 @@ void ArduinoSPI::transfer(void *buf, size_t count)
303303
_spi_ctrl.p_regs->SPCR_b.SPE = 1; /* enable SPI unit */
304304
}
305305

306+
/* send the remaining bytes with 8-bit transfers */
306307
uint8_t *buffer = (uint8_t *) &buffer32[ir];
307308

308-
/* send the remaining bytes with 8-bit transfers */
309-
for (; count > 0U; count--) {
310-
_spi_ctrl.p_regs->SPDR_BY = buffer[0];
309+
for (uint8_t index = 0; index < bytes_remaining; index++) {
310+
_spi_ctrl.p_regs->SPDR_BY = buffer[index];
311311
while (0U == _spi_ctrl.p_regs->SPSR_b.SPRF) {}
312-
buffer[0] = _spi_ctrl.p_regs->SPDR_BY;
313-
buffer++;
312+
buffer[index] = _spi_ctrl.p_regs->SPDR_BY;
314313
}
315314
}
316315
}
@@ -335,7 +334,7 @@ void ArduinoSPI::transfer(void *buf, void *rxbuf, size_t count)
335334
}
336335
else {
337336
size_t n32 = count / 4U;
338-
if (n32) {
337+
if (n32 != 0U) {
339338
_spi_ctrl.p_regs->SPCR_b.SPE = 0; /* disable SPI unit */
340339
_spi_ctrl.p_regs->SPDCR = R_SPI0_SPDCR_SPLW_Msk; /* SPI word access */
341340
_spi_ctrl.p_regs->SPCMD_b[0].SPB = 2; /* spi bit width = 32 */
@@ -348,16 +347,16 @@ void ArduinoSPI::transfer(void *buf, void *rxbuf, size_t count)
348347

349348
while ((it < 2U) && (it < n32)) {
350349
if (_spi_ctrl.p_regs->SPSR_b.SPTEF) {
351-
_spi_ctrl.p_regs->SPDR = (buf) ? tx32[it] : 0xFFFFFFFF;
350+
_spi_ctrl.p_regs->SPDR = (buf != NULL) ? tx32[it] : 0xFFFFFFFF;
352351
it++;
353352
}
354353
}
355354

356355
while (it < n32) {
357356
if (_spi_ctrl.p_regs->SPSR_b.SPRF) {
358357
uint32_t tmp = _spi_ctrl.p_regs->SPDR;
359-
_spi_ctrl.p_regs->SPDR = (buf) ? tx32[it] : 0xFFFFFFFF;
360-
if (rxbuf) {
358+
_spi_ctrl.p_regs->SPDR = (buf != NULL) ? tx32[it] : 0xFFFFFFFF;
359+
if (rxbuf != NULL) {
361360
rx32[ir] = tmp;
362361
}
363362
ir++;
@@ -368,7 +367,7 @@ void ArduinoSPI::transfer(void *buf, void *rxbuf, size_t count)
368367
while (ir < n32) { /* collect the last word received */
369368
if (_spi_ctrl.p_regs->SPSR_b.SPRF) {
370369
uint32_t tmp = _spi_ctrl.p_regs->SPDR;
371-
if (rxbuf) {
370+
if (rxbuf != NULL) {
372371
rx32[ir] = tmp;
373372
}
374373
ir++;
@@ -386,10 +385,10 @@ void ArduinoSPI::transfer(void *buf, void *rxbuf, size_t count)
386385
uint8_t *rx = (uint8_t *) rxbuf;
387386
const uint8_t* tx = (const uint8_t *) buf;
388387
for (size_t i = 4U * n32; i < count; i++) {
389-
_spi_ctrl.p_regs->SPDR_BY = (buf) ? tx[i] : 0xFF;
388+
_spi_ctrl.p_regs->SPDR_BY = (buf != NULL) ? tx[i] : 0xFF;
390389
while (0U == _spi_ctrl.p_regs->SPSR_b.SPRF) {}
391390
uint8_t tmp = _spi_ctrl.p_regs->SPDR_BY;
392-
if (rxbuf) {
391+
if (rxbuf != NULL) {
393392
rx[i] = tmp;
394393
}
395394
}

0 commit comments

Comments
 (0)