blob: ba2d9421a742081008233694481055f1120c0717 [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>
22#include "rmidevice.h"
23
24class HIDDevice : public RMIDevice
25{
26public:
Andrew Dugganf73fdc72014-11-09 11:02:22 -080027 HIDDevice() : RMIDevice(), m_inputReport(NULL), m_outputReport(NULL), m_attnData(NULL),
28 m_readData(NULL), m_deviceOpen(false)
Andrew Duggan4e811252014-04-03 15:17:57 -070029 {}
30 virtual int Open(const char * filename);
31 virtual int Read(unsigned short addr, unsigned char *buf,
32 unsigned short len);
33 virtual int Write(unsigned short addr, const unsigned char *buf,
34 unsigned short len);
35 virtual int SetMode(int mode);
Andrew Dugganf73fdc72014-11-09 11:02:22 -080036 virtual int WaitForAttention(struct timeval * timeout = NULL,
37 unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK);
38 virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
39 unsigned char *buf, unsigned int *len);
Andrew Duggan4e811252014-04-03 15:17:57 -070040 virtual void Close();
Andrew Duggan4e811252014-04-03 15:17:57 -070041 ~HIDDevice() { Close(); }
42
43private:
44 int m_fd;
45
46 struct hidraw_report_descriptor m_rptDesc;
47 struct hidraw_devinfo m_info;
48
49 unsigned char *m_inputReport;
50 unsigned char *m_outputReport;
51
Andrew Dugganf73fdc72014-11-09 11:02:22 -080052 unsigned char *m_attnData;
Andrew Duggan4e811252014-04-03 15:17:57 -070053 unsigned char *m_readData;
54 int m_dataBytesRead;
55
56 size_t m_inputReportSize;
57 size_t m_outputReportSize;
58 size_t m_featureReportSize;
59
60 bool m_deviceOpen;
Andrew Duggan4e811252014-04-03 15:17:57 -070061
Andrew Duggan4e811252014-04-03 15:17:57 -070062 enum mode_type {
63 HID_RMI4_MODE_MOUSE = 0,
64 HID_RMI4_MODE_ATTN_REPORTS = 1,
65 HID_RMI4_MODE_NO_PACKED_ATTN_REPORTS = 2,
66 };
67
Andrew Dugganf73fdc72014-11-09 11:02:22 -080068 int GetReport(int *reportId, struct timeval * timeout = NULL);
Andrew Duggan4e811252014-04-03 15:17:57 -070069 void PrintReport(const unsigned char *report);
Andrew Duggan8b774392014-06-18 13:11:49 -070070 void ParseReportSizes();
Andrew Duggan4e811252014-04-03 15:17:57 -070071 };
72
Andrew Dugganf73fdc72014-11-09 11:02:22 -080073#endif /* _HIDDEVICE_H_ */