Skip to content

Commit 78db6c3

Browse files
authored
Merge pull request adafruit#473 from dhalbert/2.x_esp8266_bidi_spi
add SPI.write_readinto() to esp8266 port
2 parents e75fd0e + 2900ed2 commit 78db6c3

File tree

1 file changed

+20
-0
lines changed
  • esp8266/common-hal/busio

1 file changed

+20
-0
lines changed

esp8266/common-hal/busio/SPI.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,23 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
185185
}
186186
return true;
187187
}
188+
189+
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) {
190+
// Process data in chunks, let the pending tasks run in between
191+
size_t chunk_size = 1024; // TODO this should depend on baudrate
192+
size_t count = len / chunk_size;
193+
size_t i = 0;
194+
for (size_t j = 0; j < count; ++j) {
195+
for (size_t k = 0; k < chunk_size; ++k) {
196+
data_in[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, data_out[i], 8, 0);
197+
++i;
198+
}
199+
ets_loop_iter();
200+
}
201+
while (i < len) {
202+
data_in[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, data_out[i], 8, 0);
203+
++i;
204+
}
205+
return true;
206+
207+
}

0 commit comments

Comments
 (0)