Skip to content

Commit

Permalink
Add trackpoint device from VoodooTrackpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Belyaev committed Dec 4, 2020
1 parent 0249814 commit c6f2977
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 14 deletions.
16 changes: 16 additions & 0 deletions VoodooInput.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
358914F425798FA5007A0B58 /* TrackpointDevice.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 358914F225798FA5007A0B58 /* TrackpointDevice.hpp */; };
358914F525798FA5007A0B58 /* TrackpointDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 358914F325798FA5007A0B58 /* TrackpointDevice.cpp */; };
7BBAB1FD22E3A2F800B2941A /* VoodooInput.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 7BBAB1FC22E3A2F800B2941A /* VoodooInput.hpp */; };
7BBAB1FF22E3A2F800B2941A /* VoodooInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7BBAB1FE22E3A2F800B2941A /* VoodooInput.cpp */; };
7BBAB21722E3AD0E00B2941A /* VoodooInputSimulatorDevice.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 7BBAB21122E3AD0D00B2941A /* VoodooInputSimulatorDevice.hpp */; };
Expand All @@ -17,6 +19,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
358914F225798FA5007A0B58 /* TrackpointDevice.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TrackpointDevice.hpp; sourceTree = "<group>"; };
358914F325798FA5007A0B58 /* TrackpointDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackpointDevice.cpp; sourceTree = "<group>"; };
7BBAB1F922E3A2F800B2941A /* VoodooInput.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VoodooInput.kext; sourceTree = BUILT_PRODUCTS_DIR; };
7BBAB1FC22E3A2F800B2941A /* VoodooInput.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = VoodooInput.hpp; sourceTree = "<group>"; };
7BBAB1FE22E3A2F800B2941A /* VoodooInput.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VoodooInput.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -47,6 +51,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
358914F125798FA5007A0B58 /* Trackpoint */ = {
isa = PBXGroup;
children = (
358914F225798FA5007A0B58 /* TrackpointDevice.hpp */,
358914F325798FA5007A0B58 /* TrackpointDevice.cpp */,
);
path = Trackpoint;
sourceTree = "<group>";
};
7BBAB1EF22E3A2F800B2941A = {
isa = PBXGroup;
children = (
Expand All @@ -69,6 +82,7 @@
7BBAB1FB22E3A2F800B2941A /* VoodooInput */ = {
isa = PBXGroup;
children = (
358914F125798FA5007A0B58 /* Trackpoint */,
CEC086442439FD3E00F5B701 /* VoodooInputMultitouch */,
7BBAB20F22E3AC7E00B2941A /* VoodooInputSimulator */,
7BBAB1FC22E3A2F800B2941A /* VoodooInput.hpp */,
Expand Down Expand Up @@ -127,6 +141,7 @@
buildActionMask = 2147483647;
files = (
7BBAB21722E3AD0E00B2941A /* VoodooInputSimulatorDevice.hpp in Headers */,
358914F425798FA5007A0B58 /* TrackpointDevice.hpp in Headers */,
7BBAB21B22E3AD0E00B2941A /* VoodooInputActuatorDevice.hpp in Headers */,
7BBAB1FD22E3A2F800B2941A /* VoodooInput.hpp in Headers */,
);
Expand Down Expand Up @@ -230,6 +245,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
358914F525798FA5007A0B58 /* TrackpointDevice.cpp in Sources */,
7BBAB1FF22E3A2F800B2941A /* VoodooInput.cpp in Sources */,
7BBAB21922E3AD0E00B2941A /* VoodooInputActuatorDevice.cpp in Sources */,
7BBAB21822E3AD0E00B2941A /* VoodooInputSimulatorDevice.cpp in Sources */,
Expand Down
54 changes: 54 additions & 0 deletions VoodooInput/Trackpoint/TrackpointDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* TrackpointDevice.cpp
* VoodooTrackpoint
*
* Copyright (c) 2019 Leonard Kleinhans <leo-labs>
*
*/

#include "TrackpointDevice.hpp"

OSDefineMetaClassAndStructors(TrackpointDevice, IOHIPointing);

UInt32 TrackpointDevice::deviceType() {
return NX_EVS_DEVICE_TYPE_MOUSE;
}

UInt32 TrackpointDevice::interfaceID() {
return NX_EVS_DEVICE_INTERFACE_BUS_ACE;
}

IOItemCount TrackpointDevice::buttonCount() {
return 3;
};

IOFixed TrackpointDevice::resolution() {
return (150) << 16;
};

bool TrackpointDevice::start(IOService* provider) {
if (!super::start(provider)) {
return false;
}

setProperty(kIOHIDScrollAccelerationTypeKey, kIOHIDTrackpadScrollAccelerationKey);
setProperty(kIOHIDScrollResolutionKey, 800 << 16, 32);
setProperty("HIDScrollResolutionX", 800 << 16, 32);
setProperty("HIDScrollResolutionY", 800 << 16, 32);

registerService();
return true;
}

void TrackpointDevice::stop(IOService* provider) {
super::stop(provider);
}


void TrackpointDevice::updateRelativePointer(int dx, int dy, int buttons, uint64_t timestamp) {
dispatchRelativePointerEvent(dx, dy, buttons, timestamp);
};

void TrackpointDevice::updateScrollwheel(short deltaAxis1, short deltaAxis2, short deltaAxis3, uint64_t timestamp) {
dispatchScrollWheelEvent(deltaAxis1, deltaAxis2, deltaAxis3, timestamp);
}
35 changes: 35 additions & 0 deletions VoodooInput/Trackpoint/TrackpointDevice.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* TrackpointDevice.hpp
* VoodooTrackpoint
*
* Copyright (c) 2019 Leonard Kleinhans <leo-labs>
*
*/

#ifndef TrackpointDevice_hpp
#define TrackpointDevice_hpp

#include <IOKit/hidsystem/IOHIPointing.h>
#include <IOKit/hidsystem/IOHIDParameter.h>

class TrackpointDevice : public IOHIPointing {
typedef IOHIPointing super;
OSDeclareDefaultStructors(TrackpointDevice);
protected:
virtual IOItemCount buttonCount() override;
virtual IOFixed resolution() override;


public:
bool start(IOService* provider) override;
void stop(IOService* provider) override;

virtual UInt32 deviceType() override;
virtual UInt32 interfaceID() override;

void updateRelativePointer(int dx, int dy, int buttons, uint64_t timestamp);
void updateScrollwheel(short deltaAxis1, short deltaAxis2, short deltaAxis3, uint64_t timestamp);

};

#endif /* TrackpointDevice_hpp */
68 changes: 54 additions & 14 deletions VoodooInput/VoodooInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// VoodooInput
//
// Copyright © 2019 Kishor Prins. All rights reserved.
// Copyright (c) 2020 Leonard Kleinhans <leo-labs>
//

#include "VoodooInput.hpp"
#include "VoodooInputMultitouch/VoodooInputMessages.h"
#include "VoodooInputSimulator/VoodooInputActuatorDevice.hpp"
#include "VoodooInputSimulator/VoodooInputSimulatorDevice.hpp"
#include "Trackpoint/TrackpointDevice.hpp"

#define super IOService
OSDefineMetaClassAndStructors(VoodooInput, IOService);
Expand All @@ -29,11 +31,13 @@ bool VoodooInput::start(IOService *provider) {
// Allocate the simulator and actuator devices
simulator = OSTypeAlloc(VoodooInputSimulatorDevice);
actuator = OSTypeAlloc(VoodooInputActuatorDevice);
trackpoint = OSTypeAlloc(TrackpointDevice);

if (!simulator || !actuator) {
IOLog("VoodooInput could not alloc simulator or actuator!\n");
if (!simulator || !actuator || !trackpoint) {
IOLog("VoodooInput could not alloc simulator, actuator or trackpoint!\n");
OSSafeReleaseNULL(simulator);
OSSafeReleaseNULL(actuator);
OSSafeReleaseNULL(trackpoint);
return false;
}

Expand All @@ -59,6 +63,18 @@ bool VoodooInput::start(IOService *provider) {
goto exit;
}

// Initialize trackpoint device
if (!trackpoint->init(NULL) || !trackpoint->attach(this)) {
IOLog("VoodooInput could not init or attach trackpoint!\n");
goto exit;
}
else if (!trackpoint->start(this)) {
IOLog("VoodooInput could not start trackpoint!\n");
trackpoint->detach(this);
goto exit;
}
trackpoint->registerService();

setProperty(VOODOO_INPUT_IDENTIFIER, kOSBooleanTrue);

if (!parentProvider->open(this)) {
Expand Down Expand Up @@ -93,6 +109,12 @@ void VoodooInput::stop(IOService *provider) {
OSSafeReleaseNULL(actuator);
}

if (trackpoint) {
trackpoint->stop(this);
trackpoint->detach(this);
OSSafeReleaseNULL(trackpoint);
}

super::stop(provider);
}

Expand Down Expand Up @@ -138,21 +160,39 @@ UInt32 VoodooInput::getLogicalMaxY() {
}

IOReturn VoodooInput::message(UInt32 type, IOService *provider, void *argument) {
if (type == kIOMessageVoodooInputMessage && provider == parentProvider) {
if (argument && simulator) {
simulator->constructReport(*(VoodooInputEvent*)argument);
switch (type) {
case kIOMessageVoodooInputMessage:
if (provider == parentProvider && argument && simulator)
simulator->constructReport(*(VoodooInputEvent*)argument);
break;

case kIOMessageVoodooInputUpdateDimensionsMessage:
if (provider == parentProvider && argument) {
const VoodooInputDimensions& dimensions = *(VoodooInputDimensions*)argument;
logicalMaxX = dimensions.max_x - dimensions.min_x;
logicalMaxY = dimensions.max_y - dimensions.min_y;
}
break;

case kIOMessageVoodooInputUpdatePropertiesNotification:
updateProperties();
break;

case kIOMessageVoodooTrackpointRelativePointer: {
if (trackpoint) {
const RelativePointerEvent& event = *(RelativePointerEvent*)argument;
trackpoint->updateRelativePointer(event.dx, event.dy, event.buttons, event.timestamp);
}
break;
}
}
else if (type == kIOMessageVoodooInputUpdateDimensionsMessage && provider == parentProvider) {
if (argument) {
const VoodooInputDimensions& dimensions = *(VoodooInputDimensions*)argument;
logicalMaxX = dimensions.max_x - dimensions.min_x;
logicalMaxY = dimensions.max_y - dimensions.min_y;
case kIOMessageVoodooTrackpointScrollWheel: {
if (trackpoint) {
const ScrollWheelEvent& event = *(ScrollWheelEvent*)argument;
trackpoint->updateScrollwheel(event.deltaAxis1, event.deltaAxis2, event.deltaAxis3, event.timestamp);
}
break;
}
}
else if (type == kIOMessageVoodooInputUpdatePropertiesNotification) {
updateProperties();
}

return super::message(type, provider, argument);
}
2 changes: 2 additions & 0 deletions VoodooInput/VoodooInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class VoodooInputSimulatorDevice;
class VoodooInputActuatorDevice;
class TrackpointDevice;

#ifndef EXPORT
#define EXPORT __attribute__((visibility("default")))
Expand All @@ -24,6 +25,7 @@ class EXPORT VoodooInput : public IOService {

VoodooInputSimulatorDevice* simulator;
VoodooInputActuatorDevice* actuator;
TrackpointDevice* trackpoint;

UInt8 transformKey;

Expand Down
15 changes: 15 additions & 0 deletions VoodooInput/VoodooInputMultitouch/VoodooInputEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// VooodooInput
//
// Copyright © 2019 Kishor Prins. All rights reserved.
// Copyright (c) 2020 Leonard Kleinhans <leo-labs>
//

#ifndef VOODOO_INPUT_EVENT_H
Expand All @@ -23,4 +24,18 @@ struct VoodooInputDimensions {
SInt32 max_y;
};

struct RelativePointerEvent {
uint64_t timestamp;
int dx;
int dy;
int buttons;
};

struct ScrollWheelEvent {
uint64_t timestamp;
short deltaAxis1;
short deltaAxis2;
short deltaAxis3;
};

#endif /* VoodooInputEvent_h */
3 changes: 3 additions & 0 deletions VoodooInput/VoodooInputMultitouch/VoodooInputMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#define kIOMessageVoodooInputMessage 12345
#define kIOMessageVoodooInputUpdateDimensionsMessage 12346
#define kIOMessageVoodooInputUpdatePropertiesNotification 12347
#define kIOMessageVoodooTrackpointRelativePointer iokit_vendor_specific_msg(430)
#define kIOMessageVoodooTrackpointScrollWheel iokit_vendor_specific_msg(431)


#define kVoodooInputTransducerFingerType 1
#define kVoodooInputTransducerStylusType 2
Expand Down

1 comment on commit c6f2977

@Sniki
Copy link
Contributor

@Sniki Sniki commented on c6f2977 Dec 4, 2020

Choose a reason for hiding this comment

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

@usr-sse2 is there any cleanup necessary on the VoodooPS2TrackPad needed regarding trackpoints and Thinkpad physical buttons ?
Also is this meant to fix the acidanthera/bugtracker#890 as i believe it is somewhat related

Please sign in to comment.