diff options
author | Damien George <damien.p.george@gmail.com> | 2016-10-03 12:39:31 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-10-03 12:39:31 +1100 |
commit | 5bb28c7f10ebd1036302cf7ac0b24a7a233de2aa (patch) | |
tree | 6f8546bc8346bee9193251443122212f76d2af94 /stmhal/spi.c | |
parent | a0d97fe40872b46872657bedc0e47cfd704c59aa (diff) |
extmod/machine_spi: Simplify SPI xfer function to only take one buf len.
There is no need to take src_len and dest_len arguments. The case of
reading-only with a single output byte (originally src_len=1, dest_len>1)
is now handled by using the output buffer as the input buffer, and using
memset to fill the output byte into this buffer. This simplifies the
implementations of the spi_transfer protocol function.
Diffstat (limited to 'stmhal/spi.c')
-rw-r--r-- | stmhal/spi.c | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/stmhal/spi.c b/stmhal/spi.c index 85f170920..05b9b629c 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -401,15 +401,8 @@ STATIC void spi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t * } } -STATIC void spi_transfer_machine(mp_obj_base_t *self_in, size_t src_len, const uint8_t *src_buf, size_t dest_len, uint8_t *dest_buf) { - if (src_len == 1 && dest_len > 1) { - // this catches read and readinto - // copy the single output byte to the dest buffer and use that as source - memset(dest_buf, src_buf[0], dest_len); - src_len = dest_len; - src_buf = dest_buf; - } - spi_transfer(self_in, src_len, src_buf, dest_len, dest_buf, 100); +STATIC void spi_transfer_machine(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { + spi_transfer(self_in, len, src, dest == NULL ? 0 : len, dest, 100); } /******************************************************************************/ |