From b07a16ed5cfde7123221b7fb59df8de492066619 Mon Sep 17 00:00:00 2001 From: Daniel Kao Date: Sat, 14 May 2022 22:14:45 -0700 Subject: [PATCH] Add a limit to do-while loops in Cirque driver Duration for these operations undocumented (does somebody know?) At least let them terminate rather than freeze up the keyboard when trackpad is disconnected. TODO: Do early return based on touch_init as well, or instead of this. --- drivers/sensors/cirque_pinnacle.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/sensors/cirque_pinnacle.c b/drivers/sensors/cirque_pinnacle.c index fb01572af5e5..93b0b3e8339f 100644 --- a/drivers/sensors/cirque_pinnacle.c +++ b/drivers/sensors/cirque_pinnacle.c @@ -137,6 +137,7 @@ void cirque_pinnacle_enable_feed(bool feedEnable) { // stores values in <*data> void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) { uint8_t ERAControlValue = 0xFF; + uint16_t retry = 0; cirque_pinnacle_enable_feed(false); // Disable feed @@ -149,7 +150,7 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) { // Wait for status register 0x1E to clear do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); - } while (ERAControlValue != 0x00); + } while ((ERAControlValue != 0x00) && (++retry != 0)); RAP_ReadBytes(ERA_VALUE, data + i, 1); @@ -160,6 +161,7 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) { // Writes a byte, , to an extended register at
(16-bit address) void ERA_WriteByte(uint16_t address, uint8_t data) { uint8_t ERAControlValue = 0xFF; + uint16_t retry = 0; cirque_pinnacle_enable_feed(false); // Disable feed @@ -173,7 +175,7 @@ void ERA_WriteByte(uint16_t address, uint8_t data) { // Wait for status register 0x1E to clear do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); - } while (ERAControlValue != 0x00); + } while ((ERAControlValue != 0x00) && (++retry != 0)); cirque_pinnacle_clear_flags(); } @@ -204,6 +206,7 @@ void cirque_pinnacle_tune_edge_sensitivity(void) { // Perform calibration void cirque_pinnacle_calibrate(void) { uint8_t calconfig; + uint16_t retry = 0; RAP_ReadBytes(CALIBRATION_CONFIG_1, &calconfig, 1); calconfig |= 0x01; @@ -211,7 +214,7 @@ void cirque_pinnacle_calibrate(void) { do { RAP_ReadBytes(CALIBRATION_CONFIG_1, &calconfig, 1); - } while (calconfig & 0x01); + } while ((calconfig & 0x01) && (++retry != 0)); cirque_pinnacle_clear_flags(); }