Skip to content

Commit 5eb4548

Browse files
committed
fix: avoid spurious interrupts by disabling interrupts, re-enabling after processing. fixes #13
1 parent a63a481 commit 5eb4548

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

VoodooI2CGoodix/VoodooI2CGoodixTouchDriver.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ void VoodooI2CGoodixTouchDriver::interrupt_occurred(OSObject* owner, IOInterrupt
216216
return;
217217
if (!awake)
218218
return;
219+
interrupt_source->disable();
219220
read_in_progress = true;
220221
thread_t new_thread;
221222
kern_return_t ret = kernel_thread_start(OSMemberFunctionCast(thread_continue_t, this, &VoodooI2CGoodixTouchDriver::handle_input_threaded), this, &new_thread);
222223
if (ret != KERN_SUCCESS) {
223224
read_in_progress = false;
225+
interrupt_source->enable();
224226
IOLog("%s::Thread error while attemping to get input report: %d\n", getName(), ret);
225227
} else {
226228
thread_deallocate(new_thread);
@@ -237,15 +239,25 @@ void VoodooI2CGoodixTouchDriver::handle_input_threaded() {
237239
return;
238240
}
239241
command_gate->attemptAction(OSMemberFunctionCast(IOCommandGate::Action, this, &VoodooI2CGoodixTouchDriver::goodix_process_events));
242+
goodix_end_cmd();
243+
interrupt_source->enable();
240244
read_in_progress = false;
241245
}
242246

247+
IOReturn VoodooI2CGoodixTouchDriver::goodix_end_cmd() {
248+
IOReturn retVal = goodix_write_reg(GOODIX_READ_COOR_ADDR, 0);
249+
if (retVal != kIOReturnSuccess) {
250+
IOLog("%s::I2C write end_cmd 0 error: %d\n", getName(), retVal);
251+
}
252+
return retVal;
253+
}
254+
243255
/* Ported from goodix.c */
244256
IOReturn VoodooI2CGoodixTouchDriver::goodix_process_events() {
245257
UInt8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
246258

247259
numTouches = goodix_ts_read_input_report(point_data);
248-
if (numTouches < 0) {
260+
if (numTouches <= 0) {
249261
return kIOReturnSuccess;
250262
}
251263

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

262-
IOReturn retVal = goodix_write_reg(GOODIX_READ_COOR_ADDR, 0);
263-
if (retVal != kIOReturnSuccess) {
264-
IOLog("%s::I2C write end_cmd error: %d\n", getName(), retVal);
265-
return retVal;
266-
}
267-
268274
if (numTouches > 0) {
269275
// send the event into the event driver
270276
event_driver->reportTouches(touches, numTouches);

VoodooI2CGoodix/VoodooI2CGoodixTouchDriver.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ class VoodooI2CGoodixTouchDriver : public IOService {
116116

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

119+
/* Send the interrupt end command
120+
*/
121+
IOReturn goodix_end_cmd();
122+
119123
int goodix_ts_read_input_report(UInt8 *data);
120124
};
121125

0 commit comments

Comments
 (0)