Return false if we already have the lock

This commit is contained in:
Scott Shawcroft 2020-07-01 14:35:25 -07:00
parent c3d1256d76
commit 367d3800fc
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
1 changed files with 3 additions and 0 deletions

View File

@ -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;
}