Skip to content

Commit

Permalink
Fixed dynamic coordinate refresh for ELAN v3 touchpads
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Oct 17, 2020
1 parent d367cad commit 7512e01
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ VoodooPS2 Changelog

#### v2.1.8
- Added support for receiving input form other kexts
- Fixed dynamic coordinate refresh for ELAN v3 touchpads

#### v2.1.7
- Initial MacKernelSDK and Xcode 12 compatibility
Expand Down
3 changes: 2 additions & 1 deletion VoodooPS2Controller.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
CE8DA1C3251839B2008C44E8 /* Frameworks */,
);
sourceTree = "<group>";
usesTabs = 0;
};
84167814161B55B2002C60E6 /* Products */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -487,7 +488,7 @@
84167808161B55B2002C60E6 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1140;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = Acidanthera;
};
buildConfigurationList = 8416780B161B55B2002C60E6 /* Build configuration list for PBXProject "VoodooPS2Controller" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -110,7 +110,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions VoodooPS2Controller/VoodooPS2Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ UInt8 ApplePS2Controller::readDataPort(PS2DeviceType deviceType)
//

UInt8 readByte;
UInt8 status;
UInt8 status = 0;
UInt32 timeoutCounter = 20000; // (timeoutCounter * kDataDelay = 140 ms)

while (1)
Expand Down Expand Up @@ -1375,7 +1375,7 @@ UInt8 ApplePS2Controller::readDataPort(PS2DeviceType deviceType,
bool firstByteHeld = false;
UInt8 readByte;
bool requestedStream;
UInt8 status;
UInt8 status = 0;
UInt32 timeoutCounter = 10000; // (timeoutCounter * kDataDelay = 70 ms)

while (1)
Expand Down
48 changes: 44 additions & 4 deletions VoodooPS2Trackpad/VoodooPS2Elan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,8 @@ int ApplePS2Elan::elantechSetInputParams() {
setProperty(VOODOO_INPUT_LOGICAL_MAX_X_KEY, info.x_max - info.x_min, 32);
setProperty(VOODOO_INPUT_LOGICAL_MAX_Y_KEY, info.y_max - info.y_min, 32);

setProperty(VOODOO_INPUT_PHYSICAL_MAX_X_KEY, (info.x_max + 1) * 100 / info.x_res, 32);
setProperty(VOODOO_INPUT_PHYSICAL_MAX_Y_KEY, (info.y_max + 1) * 100 / info.y_res, 32);
setProperty(VOODOO_INPUT_PHYSICAL_MAX_X_KEY, (info.x_max - info.x_min + 1) * 100 / info.x_res, 32);
setProperty(VOODOO_INPUT_PHYSICAL_MAX_Y_KEY, (info.y_max - info.y_min + 1) * 100 / info.y_res, 32);

setProperty(VOODOO_INPUT_TRANSFORM_KEY, 0ull, 32);
setProperty("VoodooInputSupported", kOSBooleanTrue);
Expand Down Expand Up @@ -1456,6 +1456,37 @@ int ApplePS2Elan::elantechPacketCheckV4() {
return PACKET_UNKNOWN;
}

void ApplePS2Elan::elantechRescale(unsigned int x, unsigned int y) {
bool needs_update = false;

if (x > info.x_max) {
info.x_max = x;
needs_update = true;
}

if (y > info.y_max) {
info.y_max = y;
needs_update = true;
}

if (needs_update) {
setProperty(VOODOO_INPUT_LOGICAL_MAX_X_KEY, info.x_max - info.x_min, 32);
setProperty(VOODOO_INPUT_LOGICAL_MAX_Y_KEY, info.y_max - info.y_min, 32);

setProperty(VOODOO_INPUT_PHYSICAL_MAX_X_KEY, (info.x_max - info.x_min + 1) * 100 / info.x_res, 32);
setProperty(VOODOO_INPUT_PHYSICAL_MAX_Y_KEY, (info.y_max - info.y_min + 1) * 100 / info.y_res, 32);

if (voodooInputInstance) {
VoodooInputDimensions dims = {
static_cast<SInt32>(info.x_min), static_cast<SInt32>(info.x_max),
static_cast<SInt32>(info.y_min), static_cast<SInt32>(info.y_max)
};

super::messageClient(kIOMessageVoodooInputUpdateDimensionsMessage, voodooInputInstance, &dims, sizeof(dims));
}
}
}

void ApplePS2Elan::elantechReportAbsoluteV1() {
unsigned char *packet = _ringBuffer.tail();
unsigned int fingers = 0, x = 0, y = 0;
Expand Down Expand Up @@ -1666,6 +1697,11 @@ void ApplePS2Elan::elantechReportAbsoluteV3(int packetType) {
// byte 0: n1 n0 . . . . R L
fingers = (packet[0] & 0xc0) >> 6;

INTERRUPT_LOG("report abs v3 type %d finger %u x %d y %d btn %d (%02x %02x %02x %02x %02x %02x)\n", packetType, fingers,
((packet[1] & 0x0f) << 8) | packet[2],
(((packet[4] & 0x0f) << 8) | packet[5]),
packet[0] & 0x03, packet[0], packet[1], packet[2], packet[3], packet[4], packet[5]);

switch (fingers) {
case 3:
case 1:
Expand All @@ -1675,7 +1711,9 @@ void ApplePS2Elan::elantechReportAbsoluteV3(int packetType) {

// byte 4: . . . . y11 y10 y9 y8
// byte 5: y7 y6 y5 y4 y3 y2 y1 y0
y1 = info.y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
y1 = (((packet[4] & 0x0f) << 8) | packet[5]);
elantechRescale(x1, y1);
y1 = info.y_max - y1;
break;

case 2:
Expand All @@ -1696,7 +1734,9 @@ void ApplePS2Elan::elantechReportAbsoluteV3(int packetType) {
x1 = etd.mt[0].x;
y1 = etd.mt[0].y;
x2 = ((packet[1] & 0x0f) << 8) | packet[2];
y2 = info.y_max - (((packet[4] & 0x0f) << 8) | packet[5]);
y2 = (((packet[4] & 0x0f) << 8) | packet[5]);
elantechRescale(x2, y2);
y2 = info.y_max - y2;
break;
}

Expand Down
1 change: 1 addition & 0 deletions VoodooPS2Trackpad/VoodooPS2Elan.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class EXPORT ApplePS2Elan : public IOHIPointing {
int elantechPacketCheckV2();
int elantechPacketCheckV3();
int elantechPacketCheckV4();
void elantechRescale(unsigned int x, unsigned int y);
void elantechReportAbsoluteV1();
void elantechReportAbsoluteV2();
void elantechReportAbsoluteV3(int packetType);
Expand Down

4 comments on commit 7512e01

@brunocurado
Copy link

@brunocurado brunocurado commented on 7512e01 Oct 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all. Sorry to disturb your amazing work. I have a question: will you consider giving support to Focaltech trackpads??
The reasons why I ask this is well: I have a Focaltech trackpad, and the only kext that works with it, is the one provided by EmlyDinesh and as we all know, that guy hasn't released a update to his kext in over three years, neither released the source code. Secondly, I have already been in touch with a couple developers, and even though they both seemed fine with porting the code from Linux into MacOS( which both of them said that it shouldn't be that hard, since the code was fairly simple), but the truth is that after one or two chats, the gave up and never had a word again from them. I'm wondering, why? Did I said something wrong? I don't think so, since I tend to be extremely polite and also I like to tinker and help debugging as much as I can. Anyway... I am not here to complain about those developers, i'm just wondering about getting support for a trackpad, and apparently something fairly easy to port...( I would even do it myself, If I knew how to code).

Now, back to debugging: the further I got, was to get a kext from one of your contributors, but that was it. After that I got a error, and the system wouldn't boot, giving me this error>

IMG_20200930_013229

I have triple checked my config.plist, redone it as well( in case I had any problem/typo on it), but everything was fine with it. After that, I went digging inside the kext, and I discovered that inside this kext, there are 4 plugins, and disabling the Trackpad.kext, the system would boot, but as expected I would not have trackpad...
So, it all points to that Plugin/Kext. At this point, any help/development would be much appreciated. I am more than happy to help any developer to debug, and to run the necessary tests.
Thank you so much in advance.
Looking forward for your reply and hopefully some updates :)

VoodooPS2Controller-2.1.7-RELEASE.zip

My specs, in case you need them:
Asus Zenbook UX303UA :
i7-6500U,
Intel HD520 ( no dGPU)
12GB of Ram,
500GB SSD,
BCM94352Z,
and Conexant CX20751/2
Booting Opencore 0.6.3

I am attaching a IOReg >>
MacBook Pro.zip

and the EFI, in case you want to have a look :
EFI.zip

@Andrey1970AppleLife
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know that this kext isn't supported by Focaltech, why you try to use him?

@brunocurado
Copy link

@brunocurado brunocurado commented on 7512e01 Oct 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, as mentioned, one of your contributors tried to give support to it, by including some references and perhaps some code to that trackpad plugin(check the attached Screenshot of the info.plist ) , but it didn't boot.
At this time, I am still using the ApplePS2SmartTouchpad.kext by EmlyDinesh. I am aware that Focaltech is not supported (yet) by Acidanthera, but who knows if in the future that would change? hence why I came to ask.
Captura de ecrã 2020-10-18, às 22 42 21

@brunocurado
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I forgot to mention that actually, this VoodooPS2Controller kext(released by Acidanthera) partially works with my Trackpad. I am able to move the pointer and click, but that's it. The rest of the gestures do not work

Please sign in to comment.