Skip to content

Commit e65bb8d

Browse files
committed
spi: Added default spi_master_block_write implementation to stm targets
There is an easy default implementation of spi_master_block_write that just calls spi_master_write in a loop, so the default implementation of spi_master_block_write has been added to all targets.
1 parent e352f1b commit e65bb8d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

targets/TARGET_STM/stm_spi_api.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,21 @@ int spi_master_write(spi_t *obj, int value)
367367
}
368368
}
369369

370+
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length)
371+
{
372+
int total = (tx_length > rx_length) ? tx_length : rx_length;
373+
374+
for (int i = 0; i < total; i++) {
375+
char out = (i < tx_length) ? tx_buffer[i] : 0xff;
376+
char in = spi_master_write(obj, out);
377+
if (i < rx_length) {
378+
rx_buffer[i] = in;
379+
}
380+
}
381+
382+
return total;
383+
}
384+
370385
int spi_slave_receive(spi_t *obj)
371386
{
372387
return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);

0 commit comments

Comments
 (0)