• 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 class RMIDevice
31 {
32 public:
RMIDevice()33 	RMIDevice() : m_functionList(), m_sensorID(0), m_bCancel(false), m_bytesPerReadRequest(0), m_page(-1)
34 	{}
~RMIDevice()35 	virtual ~RMIDevice() {}
36 	virtual int Open(const char * filename) = 0;
37 	virtual int Read(unsigned short addr, unsigned char *data,
38 				unsigned short len) = 0;
39 	virtual int Write(unsigned short addr, const unsigned char *data,
40 				 unsigned short len) = 0;
SetMode(int mode)41 	virtual int SetMode(int mode) { return -1; /* Unsupported */ }
42 	virtual int WaitForAttention(struct timeval * timeout = NULL,
43 			unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0;
GetAttentionReport(struct timeval * timeout,unsigned int source_mask,unsigned char * buf,unsigned int * len)44 	virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
45 					unsigned char *buf, unsigned int *len)
46 	{ return -1; /* Unsupported */ }
47 	virtual void Close() = 0;
Cancel()48 	virtual void Cancel() { m_bCancel = true; }
49 	virtual void RebindDriver() = 0;
50 
GetFirmwareID()51 	unsigned long GetFirmwareID() { return m_buildID; }
GetFirmwareVersionMajor()52 	int GetFirmwareVersionMajor() { return m_firmwareVersionMajor; }
GetFirmwareVersionMinor()53 	int GetFirmwareVersionMinor() { return m_firmwareVersionMinor; }
54 	virtual int QueryBasicProperties();
55 
56 	int SetRMIPage(unsigned char page);
57 
58 	int ScanPDT(int endFunc = 0, int endPage = -1);
59 	void PrintProperties();
60 	virtual void PrintDeviceInfo() = 0;
61 	int Reset();
62 
63 	bool InBootloader();
64 
65 	bool GetFunction(RMIFunction &func, int functionNumber);
66 	void PrintFunctions();
67 
SetBytesPerReadRequest(int bytes)68 	void SetBytesPerReadRequest(int bytes) { m_bytesPerReadRequest = bytes; }
69 
GetNumInterruptRegs()70 	unsigned int GetNumInterruptRegs() { return m_numInterruptRegs; }
71 
72 protected:
73 	std::vector<RMIFunction> m_functionList;
74 	unsigned char m_manufacturerID;
75 	bool m_hasLTS;
76 	bool m_hasSensorID;
77 	bool m_hasAdjustableDoze;
78 	bool m_hasAdjustableDozeHoldoff;
79 	bool m_hasQuery42;
80 	char m_dom[11];
81 	unsigned char m_productID[RMI_PRODUCT_ID_LENGTH + 1];
82 	unsigned short m_packageID;
83 	unsigned short m_packageRev;
84 	unsigned long m_buildID;
85 	unsigned char m_sensorID;
86 	unsigned long m_boardID;
87 
88 	int m_firmwareVersionMajor;
89 	int m_firmwareVersionMinor;
90 
91 	bool m_hasDS4Queries;
92 	bool m_hasMultiPhysical;
93 
94 	unsigned char m_ds4QueryLength;
95 
96 	bool m_hasPackageIDQuery;
97 	bool m_hasBuildIDQuery;
98 
99 	bool m_bCancel;
100 	int m_bytesPerReadRequest;
101 	int m_page;
102 
103 	unsigned int m_numInterruptRegs;
104  };
105 
106 /* Utility Functions */
107 long long diff_time(struct timespec *start, struct timespec *end);
108 int Sleep(int ms);
109 void print_buffer(const unsigned char *buf, unsigned int len);
110 #endif /* _RMIDEVICE_H_ */
111