diff --git a/epicardium/modules/buttons.c b/epicardium/modules/buttons.c index 539d6e5c87e30b51e34a8f016c39b5a549eec5c2..91f5ad02d9000e22cbf13b93c9d2170891856da6 100644 --- a/epicardium/modules/buttons.c +++ b/epicardium/modules/buttons.c @@ -1,4 +1,6 @@ #include "epicardium.h" +#include "modules/modules.h" +#include "modules/log.h" #include "portexpander.h" #include "MAX77650-Arduino-Library.h" @@ -15,12 +17,19 @@ uint8_t epic_buttons_read(uint8_t mask) { uint8_t ret = 0; if (portexpander_detected() && (mask & 0x7)) { + if (hwlock_acquire(HWLOCK_I2C, pdMS_TO_TICKS(100)) < 0) { + LOG_ERR("buttons", "Can't acquire I2C bus"); + return 0; + } + /* * Not using PB_Get() here as that performs one I2C transcation * per button. */ uint8_t pin_status = ~portexpander_get(); + hwlock_release(HWLOCK_I2C); + for (uint8_t m = 1; m < 0x8; m <<= 1) { if (mask & m && pin_status & pin_mask[m]) { ret |= m;