summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/modpybspi.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-10-03 12:39:31 +1100
committerDamien George <damien.p.george@gmail.com>2016-10-03 12:39:31 +1100
commit5bb28c7f10ebd1036302cf7ac0b24a7a233de2aa (patch)
tree6f8546bc8346bee9193251443122212f76d2af94 /esp8266/modpybspi.c
parenta0d97fe40872b46872657bedc0e47cfd704c59aa (diff)
downloadmicropython-5bb28c7f10ebd1036302cf7ac0b24a7a233de2aa.tar.gz
micropython-5bb28c7f10ebd1036302cf7ac0b24a7a233de2aa.zip
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 'esp8266/modpybspi.c')
-rw-r--r--esp8266/modpybspi.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/esp8266/modpybspi.c b/esp8266/modpybspi.c
index 4c4b843c5d..b9650954f3 100644
--- a/esp8266/modpybspi.c
+++ b/esp8266/modpybspi.c
@@ -47,17 +47,12 @@ typedef struct _pyb_spi_obj_t {
mp_hal_pin_obj_t miso;
} pyb_spi_obj_t;
-STATIC void mp_hal_spi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t *src_buf, size_t dest_len, uint8_t *dest_buf) {
+STATIC void mp_hal_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
pyb_spi_obj_t *self = (pyb_spi_obj_t*)self_in;
// only MSB transfer is implemented
uint32_t delay_half = 500000 / self->baudrate + 1;
- for (size_t i = 0; i < src_len || i < dest_len; ++i) {
- uint8_t data_out;
- if (src_len == 1) {
- data_out = src_buf[0];
- } else {
- data_out = src_buf[i];
- }
+ for (size_t i = 0; i < len; ++i) {
+ uint8_t data_out = src[i];
uint8_t data_in = 0;
for (int j = 0; j < 8; ++j, data_out <<= 1) {
mp_hal_pin_write(self->mosi, (data_out >> 7) & 1);
@@ -77,8 +72,8 @@ STATIC void mp_hal_spi_transfer(mp_obj_base_t *self_in, size_t src_len, const ui
ets_delay_us(delay_half);
}
}
- if (dest_len != 0) {
- dest_buf[i] = data_in;
+ if (dest != NULL) {
+ dest[i] = data_in;
}
// make sure pending tasks have a chance to run
ets_loop_iter();