Skip to content

Commit 6d6180e

Browse files
committed
native: Implement spi_xfer_block for faster reads
1 parent df7ea7e commit 6d6180e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/platforms/native/platform.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,19 @@ uint8_t platform_spi_xfer(const spi_bus_e bus, const uint8_t value)
519519
return spi_xfer(bus == SPI_BUS_EXTERNAL ? EXT_SPI : AUX_SPI, value);
520520
}
521521

522+
void platform_spi_xfer_block(
523+
const spi_bus_e bus, const uint8_t *const tx_buf, uint8_t *const rx_buf, const size_t count)
524+
{
525+
const uint32_t spi_base = bus == SPI_BUS_EXTERNAL ? EXT_SPI : AUX_SPI;
526+
527+
/* Put a byte on MOSI, wait entire transfer, grab the byte from MOSI into buffer, repeat. */
528+
for (size_t i = 0; i < count; i++) {
529+
uint8_t resp = spi_xfer(spi_base, tx_buf[i]);
530+
if (rx_buf)
531+
rx_buf[i] = resp;
532+
}
533+
}
534+
522535
void exti15_10_isr(void)
523536
{
524537
uint32_t usb_vbus_port;

0 commit comments

Comments
 (0)