Skip to content

Commit 2b64318

Browse files
committed
Update all implementations of common_hal_busio_spi_read to honor write_value
(nrf, rp2040, and cxd56) .. as well as a misleading comment that said that read always output zeros. Closes: #3447
1 parent 5b0009c commit 2b64318

File tree

4 files changed

+7
-16
lines changed
  • ports
    • cxd56/common-hal/busio
    • nrf/common-hal/busio
    • raspberrypi/common-hal/busio
  • shared-bindings/busio

4 files changed

+7
-16
lines changed

ports/cxd56/common-hal/busio/SPI.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, const uint8_t *data, size
132132
}
133133

134134
bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size_t len, uint8_t write_value) {
135-
SPI_EXCHANGE(self->spi_dev, NULL, data, len);
135+
memset(data, write_value, len);
136+
SPI_EXCHANGE(self->spi_dev, data, data, len);
136137

137138
return true;
138139
}

ports/nrf/common-hal/busio/SPI.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,8 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, const uint8_t *data, size
269269
}
270270

271271
bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size_t len, uint8_t write_value) {
272-
uint8_t *next_chunk = data;
273-
274-
while (len > 0) {
275-
size_t chunk_size = MIN(len, self->spim_peripheral->max_xfer_size);
276-
const nrfx_spim_xfer_desc_t xfer = NRFX_SPIM_XFER_RX(next_chunk, chunk_size);
277-
if (nrfx_spim_xfer(&self->spim_peripheral->spim, &xfer, 0) != NRFX_SUCCESS) {
278-
return false;
279-
}
280-
next_chunk += chunk_size;
281-
len -= chunk_size;
282-
}
283-
return true;
272+
memset(data, write_value, len);
273+
return common_hal_busio_spi_transfer(self, data, data, len);
284274
}
285275

286276
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) {

ports/raspberrypi/common-hal/busio/SPI.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
263263

264264
bool common_hal_busio_spi_read(busio_spi_obj_t *self,
265265
uint8_t *data, size_t len, uint8_t write_value) {
266-
uint32_t data_out = write_value << 24 | write_value << 16 | write_value << 8 | write_value;
267-
return _transfer(self, (const uint8_t *)&data_out, MIN(4, len), data, len);
266+
memset(data, write_value, len);
267+
return _transfer(self, data, len, data, len);
268268
}
269269

270270
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) {

shared-bindings/busio/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern void common_hal_busio_spi_unlock(busio_spi_obj_t *self);
5252
// Writes out the given data.
5353
extern bool common_hal_busio_spi_write(busio_spi_obj_t *self, const uint8_t *data, size_t len);
5454

55-
// Reads in len bytes while outputting zeroes.
55+
// Reads in len bytes while outputting the byte write_value.
5656
extern bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size_t len, uint8_t write_value);
5757

5858
// Reads and write len bytes simultaneously.

0 commit comments

Comments
 (0)