Skip to content

Commit

Permalink
fix: avoid spurious interrupts by disabling interrupts, re-enabling a…
Browse files Browse the repository at this point in the history
…fter processing. fixes #13
  • Loading branch information
lazd committed Jan 15, 2020
1 parent a63a481 commit 5eb4548
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 13 additions & 7 deletions VoodooI2CGoodix/VoodooI2CGoodixTouchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ void VoodooI2CGoodixTouchDriver::interrupt_occurred(OSObject* owner, IOInterrupt
return;
if (!awake)
return;
interrupt_source->disable();
read_in_progress = true;
thread_t new_thread;
kern_return_t ret = kernel_thread_start(OSMemberFunctionCast(thread_continue_t, this, &VoodooI2CGoodixTouchDriver::handle_input_threaded), this, &new_thread);
if (ret != KERN_SUCCESS) {
read_in_progress = false;
interrupt_source->enable();
IOLog("%s::Thread error while attemping to get input report: %d\n", getName(), ret);
} else {
thread_deallocate(new_thread);
Expand All @@ -237,15 +239,25 @@ void VoodooI2CGoodixTouchDriver::handle_input_threaded() {
return;
}
command_gate->attemptAction(OSMemberFunctionCast(IOCommandGate::Action, this, &VoodooI2CGoodixTouchDriver::goodix_process_events));
goodix_end_cmd();
interrupt_source->enable();
read_in_progress = false;
}

IOReturn VoodooI2CGoodixTouchDriver::goodix_end_cmd() {
IOReturn retVal = goodix_write_reg(GOODIX_READ_COOR_ADDR, 0);
if (retVal != kIOReturnSuccess) {
IOLog("%s::I2C write end_cmd 0 error: %d\n", getName(), retVal);
}
return retVal;
}

/* Ported from goodix.c */
IOReturn VoodooI2CGoodixTouchDriver::goodix_process_events() {
UInt8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];

numTouches = goodix_ts_read_input_report(point_data);
if (numTouches < 0) {
if (numTouches <= 0) {
return kIOReturnSuccess;
}

Expand All @@ -259,12 +271,6 @@ IOReturn VoodooI2CGoodixTouchDriver::goodix_process_events() {
goodix_ts_report_touch(&point_data[1 + GOODIX_CONTACT_SIZE * i], touches);
}

IOReturn retVal = goodix_write_reg(GOODIX_READ_COOR_ADDR, 0);
if (retVal != kIOReturnSuccess) {
IOLog("%s::I2C write end_cmd error: %d\n", getName(), retVal);
return retVal;
}

if (numTouches > 0) {
// send the event into the event driver
event_driver->reportTouches(touches, numTouches);
Expand Down
4 changes: 4 additions & 0 deletions VoodooI2CGoodix/VoodooI2CGoodixTouchDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class VoodooI2CGoodixTouchDriver : public IOService {

void goodix_ts_report_touch(UInt8 *coor_data, Touch *touches);

/* Send the interrupt end command
*/
IOReturn goodix_end_cmd();

int goodix_ts_read_input_report(UInt8 *data);
};

Expand Down

0 comments on commit 5eb4548

Please sign in to comment.