/
VoodooI2CGoodixEventDriver.hpp
130 lines (96 loc) · 4.2 KB
/
VoodooI2CGoodixEventDriver.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// VoodooI2CGoodixEventDriver.hpp
// VoodooI2CGoodix
//
// Created by Larry Davis on 1/5/20.
// Copyright © 2020 lazd. All rights reserved.
//
#ifndef VoodooI2CGoodixEventDriver_hpp
#define VoodooI2CGoodixEventDriver_hpp
// hack to prevent IOHIDEventDriver from loading when
// we include IOHIDEventService
#define _IOKIT_HID_IOHIDEVENTDRIVER_H
#include <libkern/OSBase.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/hidevent/IOHIDEventService.h>
#include <IOKit/hidsystem/IOHIDTypes.h>
#include "../../../Multitouch Support/VoodooI2CDigitiserStylus.hpp"
#include "../../../Multitouch Support/VoodooI2CMultitouchInterface.hpp"
#include "../../../Multitouch Support/MultitouchHelpers.hpp"
#include "../../../Dependencies/helpers.hpp"
#include "goodix.h"
/* Implements an HID Event Driver for HID devices that expose a digitiser usage page.
*
* The members of this class are responsible for parsing, processing and interpreting digitiser-related HID objects.
*/
class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
OSDeclareDefaultStructors(VoodooI2CGoodixEventDriver);
public:
/* Notification that a provider has been terminated, sent after recursing up the stack, in leaf-to-root order.
* @options The terminated provider of this object.
* @defer If there is pending I/O that requires this object to persist, and the provider is not opened by this object set defer to true and call the IOService::didTerminate() implementation when the I/O completes. Otherwise, leave defer set to its default value of false.
*
* @return *true*
*/
bool didTerminate(IOService* provider, IOOptionBits options, bool* defer) override;
const char* getProductName();
/* Called during the start routine to set up the HID Event Driver
* @provider The <IOHIDInterface> object which we have matched against.
*
* This function is reponsible for opening a client connection with the <IOHIDInterface> provider and for publishing
* a multitouch interface into the IOService plane.
*
* @return *true* on successful start, *false* otherwise
*/
bool handleStart(IOService* provider) override;
/* Publishes a <VoodooI2CMultitouchInterface> into the IOService plane
*
* @return *kIOReturnSuccess* on successful publish, *kIOReturnError* otherwise.
*/
IOReturn publishMultitouchInterface();
void initializeMultitouchInterface(int x, int y);
void unpublishMultitouchInterface();
/* Publishes some miscellaneous properties to the IOService plane
*/
void setDigitizerProperties();
/* Called by the OS in order to notify the driver that the device should change power state
* @whichState The power state the device is expected to enter represented by either
* *kIOPMPowerOn* or *kIOPMPowerOff*
* @whatDevice The power management policy maker
*
* This function exists to be overriden by inherited classes should they need it.
*
* @return *kIOPMAckImplied* on succesful state change, *kIOReturnError* otherwise
*/
virtual IOReturn setPowerState(unsigned long whichState, IOService* whatDevice) override;
/* Called during the stop routine to terminate the HID Event Driver
* @provider The <IOHIDInterface> object which we have matched against.
*
* This function is reponsible for releasing the resources allocated in <start>
*/
void handleStop(IOService* provider) override;
/* Implemented to set a certain property
* @provider The <IOHIDInterface> object which we have matched against.
*/
bool start(IOService* provider) override;
void reportTouches(struct Touch touches[], int numTouches);
protected:
const char* name;
bool awake = true;
VoodooI2CMultitouchInterface* multitouch_interface;
OSArray* transducers;
private:
IOWorkLoop *work_loop;
IOTimerEventSource *timer_source;
UInt32 buttons = 0;
IOFixed last_x = 0;
IOFixed last_y = 0;
SInt32 last_id = 0;
int click_tick = 0;
void dispatchDigitizerEvent(int logicalX, int logicalY, bool click);
void fingerLift();
void scheduleLift();
};
#endif /* VoodooI2CGoodixEventDriver_hpp */