From 367d3800fc501bfe3ec05b4b517ed195cf8d07c4 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 1 Jul 2020 14:35:25 -0700 Subject: [PATCH] Return false if we already have the lock --- ports/esp32s2/common-hal/busio/I2C.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index 74b3896fc2..57270372f1 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -163,6 +163,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { } bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { + if (self->has_lock) { + return false; + } self->has_lock = xSemaphoreTake(&self->semaphore, 0) == pdTRUE; return self->has_lock; }