diff options
| author | Dan Halbert <halbert@halwitz.org> | 2017-12-05 16:41:09 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-05 16:41:09 -0500 |
| commit | 78db6c32cddabe7ff363a3f934504805a027b217 (patch) | |
| tree | 8095461df869fa96ef4bd05b9d209d82736dbd38 | |
| parent | e75fd0e166375727fbb4c054478c9c8d329477c4 (diff) | |
| parent | 2900ed22e714b64c8bb7c41b0f06bb57c4d237c2 (diff) | |
Merge pull request #473 from dhalbert/2.x_esp8266_bidi_spi
add SPI.write_readinto() to esp8266 port
| -rw-r--r-- | esp8266/common-hal/busio/SPI.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/esp8266/common-hal/busio/SPI.c b/esp8266/common-hal/busio/SPI.c index fc8dd348f..3117c80e1 100644 --- a/esp8266/common-hal/busio/SPI.c +++ b/esp8266/common-hal/busio/SPI.c @@ -185,3 +185,23 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self, } return true; } + +bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) { + // Process data in chunks, let the pending tasks run in between + size_t chunk_size = 1024; // TODO this should depend on baudrate + size_t count = len / chunk_size; + size_t i = 0; + for (size_t j = 0; j < count; ++j) { + for (size_t k = 0; k < chunk_size; ++k) { + data_in[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, data_out[i], 8, 0); + ++i; + } + ets_loop_iter(); + } + while (i < len) { + data_in[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, data_out[i], 8, 0); + ++i; + } + return true; + +} |
