Skip to content
Snippets Groups Projects

Port buttons module to new hwlock API & fix related USB mode deadlock

Merged rahix requested to merge rahix/fix-buttons into master
1 file
+ 4
8
Compare changes
  • Side-by-side
  • Inline
@@ -16,20 +16,15 @@ static const uint8_t pin_mask[] = {
uint8_t epic_buttons_read(uint8_t mask)
{
uint8_t ret = 0;
if (portexpander_detected() && (mask & 0x7)) {
if (hwlock_acquire_timeout(HWLOCK_I2C, portMAX_DELAY) < 0) {
LOG_ERR("buttons", "Can't acquire I2C bus");
return 0;
}
hwlock_acquire(HWLOCK_I2C);
if (portexpander_detected() && (mask & 0x7)) {
/*
* Not using PB_Get() here as that performs one I2C transcation
* Not using PB_Get() here as that performs one I2C transaction
* per button.
*/
uint8_t pin_status = ~portexpander_in_get(0xFF);
hwlock_release(HWLOCK_I2C);
for (uint8_t m = 1; m < 0x8; m <<= 1) {
if (mask & m && pin_status & pin_mask[m]) {
ret |= m;
@@ -41,5 +36,6 @@ uint8_t epic_buttons_read(uint8_t mask)
ret |= BUTTON_RESET;
}
hwlock_release(HWLOCK_I2C);
return ret;
}
Loading