Skip to content

Commit 03b110b

Browse files
committed
Add abort check in I2C lock
1 parent 4c93db3 commit 03b110b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

shared-module/adafruit_bus_device/I2CDevice.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@
2929
#include "py/mperrno.h"
3030
#include "py/nlr.h"
3131
#include "py/runtime.h"
32+
#include "lib/utils/interrupt_char.h"
3233

3334
void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address) {
3435
self->i2c = i2c;
3536
self->device_address = device_address;
3637
}
3738

3839
void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self) {
39-
bool success = false;
40+
bool success = common_hal_busio_i2c_try_lock(self->i2c);
41+
4042
while (!success) {
43+
RUN_BACKGROUND_TASKS;
44+
if (mp_hal_is_interrupted()) {
45+
break;
46+
}
47+
4148
success = common_hal_busio_i2c_try_lock(self->i2c);
42-
//RUN_BACKGROUND_TASKS;
43-
//mp_handle_pending();
4449
}
4550
}
4651

0 commit comments

Comments
 (0)