input_hal branch
[staging/toyota.git] / src / input_touch_ilitek.cpp
1 /*
2  * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "input_touch_ilitek.h"
17
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <string.h>
21
22 #include "input_hal.h"
23
24 // Touch panel device name
25 #define HAL_INPUT_ILITEK_TOUCH_DEVICE_NAME "ILITEK ILITEK Multi-Touch"
26 // Touch panel key device name
27 #define HAL_INPUT_ILITEK_KEY_DEVICE_NAME ""
28
29 // Touch panel horizontal resolution value
30 #define HAL_INPUT_TOUCH_RESOLUTION_HORIZONTAL   4816
31
32 // Touch panel vertical resolution value
33 #define HAL_INPUT_TOUCH_RESOLUTION_VERTICAL     2992
34
35 /*
36  * Make touch panel start work
37  */
38 static int InputTouchStart() {
39   return HAL_INPUT_RET_NORMAL;
40 }
41
42 /*
43  * Config touch panel
44  */
45 static int InputTouchConfig(const char *path,
46                             int resolution_h, int resolution_v) {
47   if (NULL == path) {
48     return HAL_INPUT_RET_ERROR;
49   }
50
51   if (-1 == ::access(path, F_OK)) {
52     return HAL_INPUT_RET_ERROR;
53   }
54   return HAL_INPUT_RET_NORMAL;
55 }
56
57 /*
58  * Get touch panel device name
59  */
60 static int InputTouchGetDeviceName(char* name, size_t buf_length) {
61   if (NULL == name) {
62     return HAL_INPUT_RET_ERROR;
63   }
64
65   if (buf_length < (strlen(HAL_INPUT_ILITEK_TOUCH_DEVICE_NAME) + 1)) {
66     return HAL_INPUT_RET_ERROR;
67   }
68
69   snprintf(name, buf_length, "%s", HAL_INPUT_ILITEK_TOUCH_DEVICE_NAME);
70   return HAL_INPUT_RET_NORMAL;
71 }
72
73 /*
74  * Get touch panel key device name
75  */
76 static int InputTouchGetKeyName(char* name, size_t buf_length) {
77   if (NULL == name) {
78     return HAL_INPUT_RET_ERROR;
79   }
80
81   if (buf_length < (strlen(HAL_INPUT_ILITEK_KEY_DEVICE_NAME) + 1)) {
82     return HAL_INPUT_RET_ERROR;
83   }
84
85   snprintf(name, buf_length, "%s", HAL_INPUT_ILITEK_KEY_DEVICE_NAME);
86   return HAL_INPUT_RET_NORMAL;
87 }
88
89 /*
90  * Get touch panel device horizontal resolution
91  */
92 static int InputTouchGetDeviceHResolution(int *resolution) {
93   if (NULL == resolution) {
94     return HAL_INPUT_RET_ERROR;
95   }
96   *resolution = HAL_INPUT_TOUCH_RESOLUTION_HORIZONTAL;
97   return HAL_INPUT_RET_NORMAL;
98 }
99
100 /*
101  * Get touch panel device vertical resolution
102  */
103 static int InputTouchGetDeviceVResolution(int *resolution) {
104   if (NULL == resolution) {
105     return HAL_INPUT_RET_ERROR;
106   }
107   *resolution = HAL_INPUT_TOUCH_RESOLUTION_VERTICAL;
108   return HAL_INPUT_RET_NORMAL;
109 }
110
111 /*
112  * Get whether X axis is inversion
113  */
114 static int InputTouchGetXAxisReverse(bool* is_reverse) {
115   if (NULL == is_reverse) {
116     return HAL_INPUT_RET_ERROR;
117   }
118   *is_reverse = false;
119   return HAL_INPUT_RET_NORMAL;
120 }
121
122 /*
123  * Get whether Y axis is inversion
124  */
125 static int InputTouchGetYAxisReverse(bool* is_reverse) {
126   if (NULL == is_reverse) {
127     return HAL_INPUT_RET_ERROR;
128   }
129   *is_reverse = false;
130   return HAL_INPUT_RET_NORMAL;
131 }
132
133 /*
134  * Execute touch panel self test
135  */
136 static int InputTouchSelftest(int id, void *result) {
137   if (NULL == result) {
138     return HAL_INPUT_RET_ERROR;
139   }
140   return HAL_INPUT_RET_NOT_SUPPORT;
141 }
142
143 /*
144  * Get touch panel config status
145  */
146 static int InputTouchGetConfigStatus(int *status) {
147   if (NULL == status) {
148     return HAL_INPUT_RET_ERROR;
149   }
150   *status = HAL_INPUT_TOUCH_CONFIG_OFF;
151   return HAL_INPUT_RET_NORMAL;
152 }
153
154 /*
155  * Set whether the driver sends touch panel data or not
156  */
157 static int InputTouchSetTouchLock(int lock) {
158   if ((HAL_INPUT_TOUCH_UNREPORT == lock) ||
159     (HAL_INPUT_TOUCH_REPORT == lock)) {
160     return HAL_INPUT_RET_NOT_SUPPORT;
161   }
162   return HAL_INPUT_RET_ERROR;
163 }
164
165 /*
166  * Suspend touch panel
167  */
168 static int InputTouchSetTouchSuspend() {
169   return HAL_INPUT_RET_NOT_SUPPORT;
170 }
171
172 /*
173  * Set touch panel sensitivity level
174  */
175 static int InputTouchSetSensitivityLevel(int level) {
176   if ((HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_LOW == level) ||
177     (HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_MIDDLE == level) ||
178     (HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_HIGH == level) ||
179     (HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_NONE == level) ) {
180     return HAL_INPUT_RET_NOT_SUPPORT;
181   }
182   return HAL_INPUT_RET_ERROR;
183 }
184
185 /*
186  * Get touch panel sensitivity level
187  */
188 static int InputTouchGetSensitivityLevel(int *level) {
189   if (NULL == level) {
190     return HAL_INPUT_RET_ERROR;
191   }
192
193   return HAL_INPUT_RET_NOT_SUPPORT;
194 }
195
196 /*
197  * Notify radio scan frequency
198  */
199 static int InputTouchNotifyRadioScanFrequency(struct RadioInfoTouch *info) {
200   if (NULL == info) {
201     return HAL_INPUT_RET_ERROR;
202   }
203   return HAL_INPUT_RET_NOT_SUPPORT;
204 }
205
206 /*
207  * Init touch panel operation function
208  */
209 int InputTouchIlitekInit(struct TouchHal *touch) {
210   touch->start = InputTouchStart;
211   touch->config = InputTouchConfig;
212   touch->get_touch_devicename = InputTouchGetDeviceName;
213   touch->get_key_devicename = InputTouchGetKeyName;
214   touch->get_reso_h = InputTouchGetDeviceHResolution;
215   touch->get_reso_v = InputTouchGetDeviceVResolution;
216   touch->get_reverse_axis_x = InputTouchGetXAxisReverse;
217   touch->get_reverse_axis_y = InputTouchGetYAxisReverse;
218   touch->selftest = InputTouchSelftest;
219   touch->get_config_status = InputTouchGetConfigStatus;
220   touch->set_touch_lock = InputTouchSetTouchLock;
221   touch->set_touch_suspend = InputTouchSetTouchSuspend;
222   touch->set_sensitivity_level = InputTouchSetSensitivityLevel;
223   touch->get_sensitivity_level = InputTouchGetSensitivityLevel;
224   touch->notify_radio_scan_frequency = InputTouchNotifyRadioScanFrequency;
225   return HAL_INPUT_RET_NORMAL;
226 }