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
|
/*
* Copyright (C) 2014 Andrew Duggan
* Copyright (C) 2014 Synaptics Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _RMIDEVICE_H_
#define _RMIDEVICE_H_
#include <cstddef>
#include <vector>
#include "rmifunction.h"
#define RMI_PRODUCT_ID_LENGTH 10
#define RMI_INTERUPT_SOURCES_ALL_MASK 0xFFFFFFFF
enum RMIDeviceType {
RMI_DEVICE_TYPE_ANY = 0,
RMI_DEVICE_TYPE_TOUCHPAD,
RMI_DEVICE_TYPE_TOUCHSCREEN,
};
class RMIDevice
{
public:
RMIDevice() : m_functionList(), m_sensorID(0), m_bCancel(false), m_bytesPerReadRequest(0), m_page(-1),
m_deviceType(RMI_DEVICE_TYPE_ANY)
{}
virtual ~RMIDevice() {}
virtual int Open(const char * filename) = 0;
virtual int Read(unsigned short addr, unsigned char *data,
unsigned short len) = 0;
virtual int Write(unsigned short addr, const unsigned char *data,
unsigned short len) = 0;
virtual int SetMode(int mode) { return -1; /* Unsupported */ }
virtual int WaitForAttention(struct timeval * timeout = NULL,
unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0;
virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
unsigned char *buf, unsigned int *len)
{ return -1; /* Unsupported */ }
virtual void Close();
virtual void Cancel() { m_bCancel = true; }
virtual void RebindDriver() = 0;
virtual bool CheckABSEvent() = 0;
unsigned long GetFirmwareID() { return m_buildID; }
unsigned long GetConfigID() { return m_configID; }
int GetFirmwareVersionMajor() { return m_firmwareVersionMajor; }
int GetFirmwareVersionMinor() { return m_firmwareVersionMinor; }
virtual int QueryBasicProperties();
int SetRMIPage(unsigned char page);
int ScanPDT(int endFunc = 0, int endPage = -1);
void PrintProperties();
virtual void PrintDeviceInfo() = 0;
int Reset();
bool InBootloader();
bool GetFunction(RMIFunction &func, int functionNumber);
void PrintFunctions();
void SetBytesPerReadRequest(int bytes) { m_bytesPerReadRequest = bytes; }
unsigned int GetNumInterruptRegs() { return m_numInterruptRegs; }
virtual bool FindDevice(enum RMIDeviceType type = RMI_DEVICE_TYPE_ANY) = 0;
enum RMIDeviceType GetDeviceType() { return m_deviceType; }
protected:
std::vector<RMIFunction> m_functionList;
unsigned char m_manufacturerID;
bool m_hasLTS;
bool m_hasSensorID;
bool m_hasAdjustableDoze;
bool m_hasAdjustableDozeHoldoff;
bool m_hasQuery42;
char m_dom[11];
unsigned char m_productID[RMI_PRODUCT_ID_LENGTH + 1];
unsigned short m_packageID;
unsigned short m_packageRev;
unsigned long m_buildID;
unsigned long m_configID;
unsigned char m_sensorID;
unsigned long m_boardID;
int m_firmwareVersionMajor;
int m_firmwareVersionMinor;
bool m_hasDS4Queries;
bool m_hasMultiPhysical;
unsigned char m_ds4QueryLength;
bool m_hasPackageIDQuery;
bool m_hasBuildIDQuery;
bool m_bCancel;
int m_bytesPerReadRequest;
int m_page;
unsigned int m_numInterruptRegs;
enum RMIDeviceType m_deviceType;
};
/* Utility Functions */
long long diff_time(struct timespec *start, struct timespec *end);
int Sleep(int ms);
void print_buffer(const unsigned char *buf, unsigned int len);
unsigned long extract_long(const unsigned char *data);
unsigned short extract_short(const unsigned char *data);
const char * StripPath(const char * path, ssize_t size);
#endif /* _RMIDEVICE_H_ */
|