1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <assert.h>
6#include <hid/egalax.h>
7#include <zircon/errors.h>
8#include <stdio.h>
9#include <string.h>
10
11static const uint8_t egalax_touch_report_desc[] = {
12    0x05, 0x0D,       // Usage Page (Digitizer)
13    0x09, 0x04,       // Usage (Touch Screen)
14    0xA1, 0x01,       // Collection (Application)
15    0x85, 0x02,       //   Report ID (2)
16    0x09, 0x20,       //   Usage (Stylus)
17    0xA1, 0x00,       //   Collection (Physical)
18    0x09, 0x42,       //     Usage (Tip Switch)
19    0x09, 0x32,       //     Usage (In Range)
20    0x15, 0x00,       //     Logical Minimum (0)
21    0x25, 0x01,       //     Logical Maximum (1)
22    0x95, 0x02,       //     Report Count (2)
23    0x75, 0x01,       //     Report Size (1)
24    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
25    0x95, 0x06,       //     Report Count (6)
26    0x75, 0x01,       //     Report Size (1)
27    0x81, 0x03,       //     Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
28    0x05, 0x01,       //     Usage (Generic Desktop Controls)
29    0x09, 0x30,       //     Usage (X)
30    0x75, 0x10,       //     Report Size (16)
31    0x95, 0x01,       //     Report Count (1)
32    0xA4,             //     Push
33    0x55, 0x0D,       //       Unit Exponent (-3)
34    0x65, 0x33,       //       Unit (System: English, Length: Inch)
35    0x36, 0x00, 0x00, //       Physical Minimum (0)
36    0x46, 0x99, 0x28, //       Physical Maximum, (10393)
37    0x16, 0x00, 0x00, //       Logical Minimum (0)
38    0x26, 0xFF, 0x0F, //       Logical Maximum (4095)
39    0x81, 0x02,       //       Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
40    0x09, 0x31,       //       Usage (Y)
41    0x16, 0x00, 0x00, //       Logical Minimum (0)
42    0x26, 0xFF, 0x0F, //       Logical Maximum (4095)
43    0x36, 0x00, 0x00, //       Physical Minimum (0)
44    0x46, 0xAF, 0x19, //       Physical Maximum (6575)
45    0x81, 0x02,       //       Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
46    0xB4,             //     Pop
47    0xC0,             //   End Collection
48    0xC0,             // End Collection
49    0x05, 0x01,       // Usage Page (Generic Desktop Ctrls)
50    0x09, 0x01,       // Usage (Pointer)
51    0xA1, 0x01,       // Collection (Application)
52    0x85, 0x01,       //   Report ID (1)
53    0x09, 0x01,       //   Usage (Pointer)
54    0xA1, 0x00,       //   Collection (Physical)
55    0x05, 0x09,       //   Usage Page (Button)
56    0x19, 0x01,       //   Usage Minimum (1)
57    0x29, 0x02,       //   Usage Maximum (2)
58    0x15, 0x00,       //   Logical Minimum (0)
59    0x25, 0x01,       //   Logical Maximum (1)
60    0x95, 0x02,       //   Report Count (2)
61    0x75, 0x01,       //   Report Size (1)
62    0x81, 0x02,       //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
63    0x95, 0x01,       //   Report Count (1)
64    0x75, 0x06,       //   Report Size (6)
65    0x81, 0x01,       //   Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
66    0x05, 0x01,       //   Usage Page (Generic Desktop Ctrls)
67    0x09, 0x30,       //   Usage (X)
68    0x09, 0x31,       //   Usage (Y)
69    0x16, 0x00, 0x00, //   Logical Minimum (0)
70    0x26, 0xFF, 0x0F, //   Logical Maximum (4095)
71    0x36, 0x00, 0x00, //   Physical Minimum (0)
72    0x46, 0xFF, 0x0F, //   Physical Maximum (4095)
73    0x66, 0x00, 0x00, //   Unit (None)
74    0x75, 0x10,       //   Report Size (16)
75    0x95, 0x02,       //   Report Count (2)
76    0x81, 0x02,       //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
77    0xC0,             //   End Collection
78    0xC0,             // End Collection
79    0x06, 0x00, 0xFF, // Usage Page (Vendor Defined)
80    0x09, 0x01,       // Usage (Pointer)
81    0xA1, 0x01,       // Collection (Application)
82    0x09, 0x01,       //   Usage (Pointer)
83    0x15, 0x00,       //   Logical Minimum (0)
84    0x26, 0xFF, 0x00, //   Logical Maximum (255)
85    0x85, 0x03,       //   Report ID (3)
86    0x75, 0x08,       //   Report Size (8)
87    0x95, 0x05,       //   Report Count (5)
88    0x81, 0x02,       //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
89    0x06, 0x00, 0xFF, //   Usage Page (Vendor Defined)
90    0x09, 0x01,       //   Usage (Pointer)
91    0x15, 0x00,       //   Logical Minimum (0)
92    0x26, 0xFF, 0x00, //   Logical Maximum (255)
93    0x75, 0x08,       //   Report Size (8)
94    0x95, 0x05,       //   Report Count (5)
95    0x91, 0x02,       //   Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
96    0xC0,             // End Collection
97    0x05, 0x0D,       // Usage Page (Digitizer)
98    0x09, 0x04,       // Usage (Touch Screen)
99    0xA1, 0x01,       // Collection (Application)
100    0x85, 0x04,       //   Report ID (4)
101    0x09, 0x22,       //   Usage (Finger)
102    0xA1, 0x00,       //   Collection (Physical)
103    0x09, 0x42,       //     Usage (Tip Switch)
104    0x15, 0x00,       //     Logical Minimum (0)
105    0x25, 0x01,       //     Logical Maximum (1)
106    0x75, 0x01,       //     Report Size (1)
107    0x95, 0x01,       //     Report Count (1)
108    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
109    0x09, 0x32,       //     Usage (In Range)
110    0x15, 0x00,       //     Logical Minimum (0)
111    0x25, 0x01,       //     Logical Maximum (1)
112    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
113    0x09, 0x51,       //     Usage (Contact Identifier)
114    0x75, 0x05,       //     Report Size (5)
115    0x95, 0x01,       //     Report Count (1)
116    0x16, 0x00, 0x00, //     Logical Minimum (0)
117    0x26, 0x10, 0x00, //     Logical Maximum (16)
118    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
119    0x09, 0x47,       //     Usage (Confidence)
120    0x75, 0x01,       //     Report Size (1)
121    0x95, 0x01,       //     Report Count (1)
122    0x15, 0x00,       //     Logical Minimum (0)
123    0x25, 0x01,       //     Logical Maximum (1)
124    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
125    0x05, 0x01,       //     Usage Page (Generic Desktop Ctrls)
126    0x09, 0x30,       //     Usage (X)
127    0x75, 0x10,       //     Report Size (16)
128    0x95, 0x01,       //     Report Count (1)
129    0x55, 0x0D,       //     Unit Exponent (-3)
130    0x65, 0x33,       //     Unit (System: English, Length: Inch)
131    0x35, 0x00,       //     Physical Minimum (0)
132    0x46, 0x60, 0x17, //     Physical Maximum (5984)
133    0x26, 0xFF, 0x0F, //     Logical Maximum (4095)
134    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
135    0x09, 0x31,       //     Usage (Y)
136    0x75, 0x10,       //     Report Size (16)
137    0x95, 0x01,       //     Report Count (1)
138    0x55, 0x0D,       //     Report Exponent (-3)
139    0x65, 0x33,       //     Unit (System: English, Length: Inch)
140    0x35, 0x00,       //     Physical Minimum (0)
141    0x46, 0x26, 0x0e, //     Physical Maximum (3622)
142    0x26, 0xFF, 0x0F, //     Logical Maximum (4095)
143    0x81, 0x02,       //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
144    0x05, 0x0D,       //     Usage Page (Digitizer)
145    0x09, 0x55,       //     Usage (Max Contact Points)
146    0x25, 0x08,       //     Logical Maximum (8)
147    0x75, 0x08,       //     Report Size (8)
148    0x95, 0x01,       //     Report Count (1)
149    0xB1, 0x02,       //     Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
150    0xC0,             //   End Collection
151    0xC0,             // End Collection
152    0x05, 0x0D,       // Usage Page (Digitizer)
153    0x09, 0x0E,       // Usage (Configuration)
154    0xA1, 0x01,       // Collection (Application)
155    0x85, 0x05,       //   Report ID (5)
156    0x09, 0x22,       //   Usage (Finger)
157    0xA1, 0x00,       //   Collection (Physical)
158    0x09, 0x52,       //     Usage (Device Mode)
159    0x09, 0x53,       //     Usage (Device Index)
160    0x15, 0x00,       //     Logical Minimum (0)
161    0x25, 0x0A,       //     Logical Maximum (10)
162    0x75, 0x08,       //     Report Size (8)
163    0x95, 0x02,       //     Report Count (2)
164    0xB1, 0x02,       //     Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
165    0xC0,             //   End Collection
166    0xC0              // End Collection
167    // 322 bytes
168};
169
170
171bool is_egalax_touchscreen_report_desc(const uint8_t* data, size_t len) {
172    if (!data)
173        return false;
174
175    if (len != sizeof(egalax_touch_report_desc)) {
176        return false;
177    }
178
179    return (memcmp(data, egalax_touch_report_desc, len) == 0);
180}
181
182zx_status_t setup_egalax_touchscreen(int fd) {
183    if (fd < 0)
184        return ZX_ERR_INVALID_ARGS;
185
186    return ZX_OK;
187}
188