25
25
* THE SOFTWARE.
26
26
*/
27
27
#include <stdbool.h>
28
+ #include <string.h>
28
29
29
30
#include "shared-bindings/busio/SPI.h"
30
31
#include "py/mperrno.h"
@@ -340,7 +341,7 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
340
341
if (self -> mosi == NULL ) {
341
342
mp_raise_ValueError (translate ("No MOSI Pin" ));
342
343
}
343
- HAL_StatusTypeDef result = HAL_SPI_Transmit (& self -> handle , (uint8_t * )data , (uint16_t )len , HAL_MAX_DELAY );
344
+ HAL_StatusTypeDef result = HAL_SPI_Transmit (& self -> handle , (uint8_t * )data , (uint16_t )len , HAL_MAX_DELAY );
344
345
return result == HAL_OK ;
345
346
}
346
347
@@ -349,7 +350,13 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
349
350
if (self -> miso == NULL ) {
350
351
mp_raise_ValueError (translate ("No MISO Pin" ));
351
352
}
352
- HAL_StatusTypeDef result = HAL_SPI_Receive (& self -> handle , data , (uint16_t )len , HAL_MAX_DELAY );
353
+ HAL_StatusTypeDef result = HAL_OK ;
354
+ if (self -> mosi == NULL ) {
355
+ result = HAL_SPI_Receive (& self -> handle , data , (uint16_t )len , HAL_MAX_DELAY );
356
+ } else {
357
+ memset (data , write_value , len );
358
+ result = HAL_SPI_TransmitReceive (& self -> handle , data , data , (uint16_t )len , HAL_MAX_DELAY );
359
+ }
353
360
return result == HAL_OK ;
354
361
}
355
362
@@ -358,7 +365,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
358
365
if (self -> miso == NULL || self -> mosi == NULL ) {
359
366
mp_raise_ValueError (translate ("Missing MISO or MOSI Pin" ));
360
367
}
361
- HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (& self -> handle ,
368
+ HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (& self -> handle ,
362
369
(uint8_t * ) data_out , data_in , (uint16_t )len ,HAL_MAX_DELAY );
363
370
return result == HAL_OK ;
364
371
}
0 commit comments