blob: 05a11fa16d2106b1f9c87f7fb1002ead929f1428 [file] [log] [blame]
Andrew Duggan052556f2014-04-16 11:32:30 -07001/*
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
Andrew Duggan4e811252014-04-03 15:17:57 -070018#ifndef _HIDDEVICE_H_
19#define _HIDDEVICE_H_
20
21#include <linux/hidraw.h>
Andrew Dugganbef9c2d2015-05-06 17:45:48 -070022#include <string>
Andrew Duggan4e811252014-04-03 15:17:57 -070023#include "rmidevice.h"
24
25class HIDDevice : public RMIDevice
26{
27public:
Andrew Dugganf73fdc72014-11-09 11:02:22 -080028 HIDDevice() : RMIDevice(), m_inputReport(NULL), m_outputReport(NULL), m_attnData(NULL),
Andrew de los Reyes242ea832015-09-04 14:40:06 -070029 m_readData(NULL),
30 m_inputReportSize(0),
31 m_outputReportSize(0),
32 m_featureReportSize(0),
33 m_deviceOpen(false)
Andrew Duggan4e811252014-04-03 15:17:57 -070034 {}
35 virtual int Open(const char * filename);
36 virtual int Read(unsigned short addr, unsigned char *buf,
37 unsigned short len);
38 virtual int Write(unsigned short addr, const unsigned char *buf,
39 unsigned short len);
40 virtual int SetMode(int mode);
Andrew Dugganf73fdc72014-11-09 11:02:22 -080041 virtual int WaitForAttention(struct timeval * timeout = NULL,
42 unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK);
43 virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
44 unsigned char *buf, unsigned int *len);
Andrew Duggan4e811252014-04-03 15:17:57 -070045 virtual void Close();
Andrew Dugganbef9c2d2015-05-06 17:45:48 -070046 virtual void RebindDriver();
Andrew Duggan4e811252014-04-03 15:17:57 -070047 ~HIDDevice() { Close(); }
48
Andrew Duggan2c24adb2015-05-06 18:18:06 -070049 virtual void PrintDeviceInfo();
50
Andrew Duggan4e811252014-04-03 15:17:57 -070051private:
52 int m_fd;
53
54 struct hidraw_report_descriptor m_rptDesc;
55 struct hidraw_devinfo m_info;
56
57 unsigned char *m_inputReport;
58 unsigned char *m_outputReport;
59
Andrew Dugganf73fdc72014-11-09 11:02:22 -080060 unsigned char *m_attnData;
Andrew Duggan4e811252014-04-03 15:17:57 -070061 unsigned char *m_readData;
62 int m_dataBytesRead;
63
64 size_t m_inputReportSize;
65 size_t m_outputReportSize;
66 size_t m_featureReportSize;
67
68 bool m_deviceOpen;
Andrew Duggan4e811252014-04-03 15:17:57 -070069
Andrew Duggan4e811252014-04-03 15:17:57 -070070 enum mode_type {
71 HID_RMI4_MODE_MOUSE = 0,
72 HID_RMI4_MODE_ATTN_REPORTS = 1,
73 HID_RMI4_MODE_NO_PACKED_ATTN_REPORTS = 2,
74 };
75
Andrew Dugganf73fdc72014-11-09 11:02:22 -080076 int GetReport(int *reportId, struct timeval * timeout = NULL);
Andrew Duggan4e811252014-04-03 15:17:57 -070077 void PrintReport(const unsigned char *report);
Andrew Duggan8b774392014-06-18 13:11:49 -070078 void ParseReportSizes();
Andrew Dugganbef9c2d2015-05-06 17:45:48 -070079
80 // static HID utility functions
81 static bool LookupHidDeviceName(int bus, int vendorId, int productId, std::string &deviceName);
Andrew Dugganb6302c32015-05-07 11:07:22 -070082 static bool FindTransportDevice(int bus, std::string & hidDeviceName,
Andrew Dugganbef9c2d2015-05-06 17:45:48 -070083 std::string & transportDeviceName, std::string & driverPath);
84 static bool FindHidRawFile(std::string & hidDeviceName, std::string & hidrawFile);
Andrew Duggan4e811252014-04-03 15:17:57 -070085 };
86
Andrew Dugganf73fdc72014-11-09 11:02:22 -080087#endif /* _HIDDEVICE_H_ */