• 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 	{ m_hasDebug = false; }
~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 ToggleInterruptMask(bool enable) = 0;
50 	virtual int WaitForAttention(struct timeval * timeout = NULL,
51 			unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0;
GetAttentionReport(struct timeval * timeout,unsigned int source_mask,unsigned char * buf,unsigned int * len)52 	virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
53 					unsigned char *buf, unsigned int *len)
54 	{ return -1; /* Unsupported */ }
55 	virtual void Close();
Cancel()56 	virtual void Cancel() { m_bCancel = true; }
57 	virtual void RebindDriver() = 0;
58 	virtual bool CheckABSEvent() = 0;
59 
GetFirmwareID()60 	unsigned long GetFirmwareID() { return m_buildID; }
GetConfigID()61 	unsigned long GetConfigID() { return m_configID; }
GetFirmwareVersionMajor()62 	int GetFirmwareVersionMajor() { return m_firmwareVersionMajor; }
GetFirmwareVersionMinor()63 	int GetFirmwareVersionMinor() { return m_firmwareVersionMinor; }
64 	virtual int QueryBasicProperties();
GetProductID()65 	char *GetProductID() { return (char *)m_productID; }
66 
67 	int SetRMIPage(unsigned char page);
68 
69 	int ScanPDT(int endFunc = 0, int endPage = -1);
70 	void PrintProperties();
71 	virtual void PrintDeviceInfo() = 0;
72 	int Reset();
73 
74 	bool InBootloader();
75 
76 	bool GetFunction(RMIFunction &func, int functionNumber);
77 	void PrintFunctions();
78 
SetBytesPerReadRequest(int bytes)79 	void SetBytesPerReadRequest(int bytes) { m_bytesPerReadRequest = bytes; }
80 
GetNumInterruptRegs()81 	unsigned int GetNumInterruptRegs() { return m_numInterruptRegs; }
82 
83 	virtual bool FindDevice(enum RMIDeviceType type = RMI_DEVICE_TYPE_ANY) = 0;
GetDeviceType()84 	enum RMIDeviceType GetDeviceType() { return m_deviceType; }
85 
86 	bool m_hasDebug;
87 
88 protected:
89 	std::vector<RMIFunction> m_functionList;
90 	unsigned char m_manufacturerID;
91 	bool m_hasLTS;
92 	bool m_hasSensorID;
93 	bool m_hasAdjustableDoze;
94 	bool m_hasAdjustableDozeHoldoff;
95 	bool m_hasQuery42;
96 	char m_dom[11];
97 	unsigned char m_productID[RMI_PRODUCT_ID_LENGTH + 1];
98 	unsigned short m_packageID;
99 	unsigned short m_packageRev;
100 	unsigned long m_buildID;
101 	unsigned long m_configID;
102 	unsigned char m_sensorID;
103 	unsigned long m_boardID;
104 
105 	int m_firmwareVersionMajor;
106 	int m_firmwareVersionMinor;
107 
108 	bool m_hasDS4Queries;
109 	bool m_hasMultiPhysical;
110 
111 	unsigned char m_ds4QueryLength;
112 
113 	bool m_hasPackageIDQuery;
114 	bool m_hasBuildIDQuery;
115 
116 	bool m_bCancel;
117 	int m_bytesPerReadRequest;
118 	int m_page;
119 
120 	unsigned int m_numInterruptRegs;
121 
122 	enum RMIDeviceType m_deviceType;
123 };
124 
125 /* Utility Functions */
126 long long diff_time(struct timespec *start, struct timespec *end);
127 int Sleep(int ms);
128 void print_buffer(const unsigned char *buf, unsigned int len);
129 unsigned long extract_long(const unsigned char *data);
130 unsigned short extract_short(const unsigned char *data);
131 const char * StripPath(const char * path, ssize_t size);
132 #endif /* _RMIDEVICE_H_ */
133