Skip to content

Commit

Permalink
Add a limit to do-while loops in Cirque driver
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dkao committed May 15, 2022
1 parent f6aceb7 commit b07a16e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions drivers/sensors/cirque_pinnacle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);

Expand All @@ -160,6 +161,7 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) {
// Writes a byte, <data>, to an extended register at <address> (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

Expand All @@ -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();
}
Expand Down Expand Up @@ -204,14 +206,15 @@ 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;
RAP_Write(CALIBRATION_CONFIG_1, calconfig);

do {
RAP_ReadBytes(CALIBRATION_CONFIG_1, &calconfig, 1);
} while (calconfig & 0x01);
} while ((calconfig & 0x01) && (++retry != 0));

cirque_pinnacle_clear_flags();
}
Expand Down

0 comments on commit b07a16e

Please sign in to comment.