File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 99
1010#include <string.h>
1111
12+ #include "py/binary.h"
13+ #include "py/mperrno.h"
14+ #include "py/objproperty.h"
15+ #include "py/runtime.h"
1216#include "shared-bindings/microcontroller/Pin.h"
1317#include "shared-bindings/busio/SPI.h"
1418#include "shared-bindings/util.h"
15-
1619#include "shared/runtime/buffer_helper.h"
1720#include "shared/runtime/context_manager_helpers.h"
18- #include "py/binary.h"
19- #include "py/mperrno.h"
20- #include "py/objproperty.h"
21- #include "py/runtime.h"
21+ #include "supervisor/shared/tick.h"
2222
2323
2424//| class SPI:
@@ -494,3 +494,16 @@ MP_DEFINE_CONST_OBJ_TYPE(
494494busio_spi_obj_t * validate_obj_is_spi_bus (mp_obj_t obj , qstr arg_name ) {
495495 return mp_arg_validate_type (obj , & busio_spi_type , arg_name );
496496}
497+
498+ // Wait as long as needed for the lock. This is used by SD card access from USB.
499+ // The default implementation is to busy-wait while running the background tasks. espressif is different.
500+ bool common_hal_busio_spi_wait_for_lock (busio_spi_obj_t * self , uint32_t timeout_ms ) {
501+ uint64_t deadline = supervisor_ticks_ms64 () + timeout_ms ;
502+ while (supervisor_ticks_ms64 () < deadline ) {
503+ if (common_hal_busio_spi_try_lock (self )) {
504+ return true;
505+ }
506+ RUN_BACKGROUND_TASKS ;
507+ }
508+ return false;
509+ }
Original file line number Diff line number Diff line change @@ -54,3 +54,7 @@ uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t *self);
5454extern void common_hal_busio_spi_never_reset (busio_spi_obj_t * self );
5555
5656extern busio_spi_obj_t * validate_obj_is_spi_bus (mp_obj_t obj_in , qstr arg_name );
57+
58+ // Wait as long as needed for the lock. This is used by SD card access from USB.
59+ // For most ports, busy-wait while running the background tasks.
60+ MP_WEAK bool common_hal_busio_spi_wait_for_lock (busio_spi_obj_t * self , uint32_t timeout_ms );
You can’t perform that action at this time.
0 commit comments