Skip to content
Snippets Groups Projects
Verified Commit 80b2a1de authored by rahix's avatar rahix
Browse files

fix(buttons): Acquire I2C lock before accessing bus


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 921ba019
No related branches found
No related tags found
No related merge requests found
#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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment