• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 Andrew Duggan
3  * Copyright (C) 2014 Synaptics Inc
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _RMIDEVICE_H_
19 #define _RMIDEVICE_H_
20 
21 #include <cstddef>
22 #include <vector>
23 
24 #include "rmifunction.h"
25 
26 #define RMI_PRODUCT_ID_LENGTH		10
27 
28 #define RMI_INTERUPT_SOURCES_ALL_MASK	0xFFFFFFFF
29 
30 enum RMIDeviceType {
31 	RMI_DEVICE_TYPE_ANY             = 0,
32 	RMI_DEVICE_TYPE_TOUCHPAD,
33 	RMI_DEVICE_TYPE_TOUCHSCREEN,
34 };
35 
36 class RMIDevice
37 {
38 public:
RMIDevice()39 	RMIDevice() : m_functionList(), m_sensorID(0), m_bCancel(false), m_bytesPerReadRequest(0), m_page(-1),
40 		      m_deviceType(RMI_DEVICE_TYPE_ANY)
41 	{}
~RMIDevice()42 	virtual ~RMIDevice() {}
43 	virtual int Open(const char * filename) = 0;
44 	virtual int Read(unsigned short addr, unsigned char *data,
45 				unsigned short len) = 0;
46 	virtual int Write(unsigned short addr, const unsigned char *data,
47 				 unsigned short len) = 0;
SetMode(int mode)48 	virtual int SetMode(int mode) { return -1; /* Unsupported */ }
49 	virtual int WaitForAttention(struct timeval * timeout = NULL,
50 			unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0;
GetAttentionReport(struct timeval * timeout,unsigned int source_mask,unsigned char * buf,unsigned int * len)51 	virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
52 					unsigned char *buf, unsigned int *len)
53 	{ return -1; /* Unsupported */ }
54 	virtual void Close();
Cancel()55 	virtual void Cancel() { m_bCancel = true; }
56 	virtual void RebindDriver() = 0;
57 	virtual bool CheckABSEvent() = 0;
58 
GetFirmwareID()59 	unsigned long GetFirmwareID() { return m_buildID; }
GetConfigID()60 	unsigned long GetConfigID() { return m_configID; }
GetFirmwareVersionMajor()61 	int GetFirmwareVersionMajor() { return m_firmwareVersionMajor; }
GetFirmwareVersionMinor()62 	int GetFirmwareVersionMinor() { return m_firmwareVersionMinor; }
63 	virtual int QueryBasicProperties();
64 
65 	int SetRMIPage(unsigned char page);
66 
67 	int ScanPDT(int endFunc = 0, int endPage = -1);
68 	void PrintProperties();
69 	virtual void PrintDeviceInfo() = 0;
70 	int Reset();
71 
72 	bool InBootloader();
73 
74 	bool GetFunction(RMIFunction &func, int functionNumber);
75 	void PrintFunctions();
76 
SetBytesPerReadRequest(int bytes)77 	void SetBytesPerReadRequest(int bytes) { m_bytesPerReadRequest = bytes; }
78 
GetNumInterruptRegs()79 	unsigned int GetNumInterruptRegs() { return m_numInterruptRegs; }
80 
81 	virtual bool FindDevice(enum RMIDeviceType type = RMI_DEVICE_TYPE_ANY) = 0;
GetDeviceType()82 	enum RMIDeviceType GetDeviceType() { return m_deviceType; }
83 
84 protected:
85 	std::vector<RMIFunction> m_functionList;
86 	unsigned char m_manufacturerID;
87 	bool m_hasLTS;
88 	bool m_hasSensorID;
89 	bool m_hasAdjustableDoze;
90 	bool m_hasAdjustableDozeHoldoff;
91 	bool m_hasQuery42;
92 	char m_dom[11];
93 	unsigned char m_productID[RMI_PRODUCT_ID_LENGTH + 1];
94 	unsigned short m_packageID;
95 	unsigned short m_packageRev;
96 	unsigned long m_buildID;
97 	unsigned long m_configID;
98 	unsigned char m_sensorID;
99 	unsigned long m_boardID;
100 
101 	int m_firmwareVersionMajor;
102 	int m_firmwareVersionMinor;
103 
104 	bool m_hasDS4Queries;
105 	bool m_hasMultiPhysical;
106 
107 	unsigned char m_ds4QueryLength;
108 
109 	bool m_hasPackageIDQuery;
110 	bool m_hasBuildIDQuery;
111 
112 	bool m_bCancel;
113 	int m_bytesPerReadRequest;
114 	int m_page;
115 
116 	unsigned int m_numInterruptRegs;
117 
118 	enum RMIDeviceType m_deviceType;
119 };
120 
121 /* Utility Functions */
122 long long diff_time(struct timespec *start, struct timespec *end);
123 int Sleep(int ms);
124 void print_buffer(const unsigned char *buf, unsigned int len);
125 unsigned long extract_long(const unsigned char *data);
126 unsigned short extract_short(const unsigned char *data);
127 const char * StripPath(const char * path, ssize_t size);
128 #endif /* _RMIDEVICE_H_ */
129