Skip to content

Commit 47babd2

Browse files
committed
shave off some time when sending multiple bytes through SPI
1 parent ff9d1fb commit 47babd2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Diff for: cores/esp32/esp32-hal-spi.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@ void __spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t byt
642642
uint8_t * bytesBuf = (uint8_t *) wordsBuf;
643643

644644
if(data) {
645-
for(i=0; i<bytes; i++) {
646-
bytesBuf[i] = data[i];//copy data to buffer
647-
}
645+
memcpy(bytesBuf, data, bytes);//copy data to buffer
646+
} else {
647+
memset(bytesBuf, 0xFF, bytes);
648648
}
649649

650650
while(spi->dev->cmd.usr);
@@ -662,9 +662,7 @@ void __spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t byt
662662
for(i=0; i<words; i++) {
663663
wordsBuf[i] = spi->dev->data_buf[i];//copy spi fifo to buffer
664664
}
665-
for(i=0; i<bytes; i++) {
666-
out[i] = bytesBuf[i];//copy buffer to output
667-
}
665+
memcpy(out, bytesBuf, bytes);//copy buffer to output
668666
}
669667
}
670668

0 commit comments

Comments
 (0)