Andrew Duggan | 052556f | 2014-04-16 11:32:30 -0700 | [diff] [blame] | 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 | |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 18 | #ifndef _HIDDEVICE_H_ |
| 19 | #define _HIDDEVICE_H_ |
| 20 | |
| 21 | #include <linux/hidraw.h> |
Andrew Duggan | bef9c2d | 2015-05-06 17:45:48 -0700 | [diff] [blame] | 22 | #include <string> |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 23 | #include "rmidevice.h" |
| 24 | |
| 25 | class HIDDevice : public RMIDevice |
| 26 | { |
| 27 | public: |
Andrew Duggan | f73fdc7 | 2014-11-09 11:02:22 -0800 | [diff] [blame] | 28 | HIDDevice() : RMIDevice(), m_inputReport(NULL), m_outputReport(NULL), m_attnData(NULL), |
Andrew de los Reyes | 242ea83 | 2015-09-04 14:40:06 -0700 | [diff] [blame] | 29 | m_readData(NULL), |
| 30 | m_inputReportSize(0), |
| 31 | m_outputReportSize(0), |
| 32 | m_featureReportSize(0), |
| 33 | m_deviceOpen(false) |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 34 | {} |
| 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 Duggan | f73fdc7 | 2014-11-09 11:02:22 -0800 | [diff] [blame] | 41 | 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 Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 45 | virtual void Close(); |
Andrew Duggan | bef9c2d | 2015-05-06 17:45:48 -0700 | [diff] [blame] | 46 | virtual void RebindDriver(); |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 47 | ~HIDDevice() { Close(); } |
| 48 | |
Andrew Duggan | 2c24adb | 2015-05-06 18:18:06 -0700 | [diff] [blame] | 49 | virtual void PrintDeviceInfo(); |
| 50 | |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 51 | private: |
| 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 Duggan | f73fdc7 | 2014-11-09 11:02:22 -0800 | [diff] [blame] | 60 | unsigned char *m_attnData; |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 61 | 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 Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 69 | |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 70 | 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 Duggan | f73fdc7 | 2014-11-09 11:02:22 -0800 | [diff] [blame] | 76 | int GetReport(int *reportId, struct timeval * timeout = NULL); |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 77 | void PrintReport(const unsigned char *report); |
Andrew Duggan | 8b77439 | 2014-06-18 13:11:49 -0700 | [diff] [blame] | 78 | void ParseReportSizes(); |
Andrew Duggan | bef9c2d | 2015-05-06 17:45:48 -0700 | [diff] [blame] | 79 | |
| 80 | // static HID utility functions |
| 81 | static bool LookupHidDeviceName(int bus, int vendorId, int productId, std::string &deviceName); |
Andrew Duggan | b6302c3 | 2015-05-07 11:07:22 -0700 | [diff] [blame] | 82 | static bool FindTransportDevice(int bus, std::string & hidDeviceName, |
Andrew Duggan | bef9c2d | 2015-05-06 17:45:48 -0700 | [diff] [blame] | 83 | std::string & transportDeviceName, std::string & driverPath); |
| 84 | static bool FindHidRawFile(std::string & hidDeviceName, std::string & hidrawFile); |
Andrew Duggan | 4e81125 | 2014-04-03 15:17:57 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Andrew Duggan | f73fdc7 | 2014-11-09 11:02:22 -0800 | [diff] [blame] | 87 | #endif /* _HIDDEVICE_H_ */ |