2 * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "input_hal.h"
24 #include "input_hal_debug.h"
25 #include "input_hal_internal.h"
26 #include "input_touch_ilitek.h"
27 #include "input_udev_monitor.h"
29 // Touch panel operation function info
30 static struct TouchHal g_input_touch_info = { 0 };
32 char* g_app_name = NULL;
33 static bool g_touch_inited = false;
34 static bool g_input_inited = false;
36 extern bool g_break_from_watch;
37 extern pthread_t g_udev_monitor_thread;
39 // Environment key name
40 #define HAL_INPUT_TARGET_BOARD "TARGET_BOARD"
41 // Reference board environment value of HAL_INPUT_TARGET_BOARD
42 #define HAL_INPUT_REF_BOARD_NAME "agl_reference"
43 // Invalid status of report touch panel's touch event
44 #define HAL_INPUT_TOUCH_REPORT_INVALID (-1)
49 int InitInput(const char* app_name) {
50 if (NULL == app_name) {
51 INPUT_ERROR_LOG("param is error");
52 return HAL_INPUT_RET_ERROR;
55 if (!g_touch_inited) {
56 INPUT_ERROR_LOG("call InitTouch first.");
57 return HAL_INPUT_RET_ERROR;
61 INPUT_ERROR_LOG("input inited.");
62 return HAL_INPUT_RET_ERROR;
65 g_break_from_watch = false;
66 if (NULL != g_app_name) {
70 g_app_name = new char[strlen(app_name) + 1];
71 snprintf(g_app_name, strlen(app_name) + 1, "%s", app_name);
72 if (HAL_INPUT_RET_ERROR == InputUdevMonitorThreadCreate()) {
75 return HAL_INPUT_RET_ERROR;
78 g_input_inited = true;
79 return HAL_INPUT_RET_NORMAL;
86 g_break_from_watch = true;
88 if (NULL != g_app_name) {
92 if (g_udev_monitor_thread != static_cast<pthread_t>(-1)) {
93 pthread_join(g_udev_monitor_thread, &ret_val);
95 g_input_inited = false;
96 return HAL_INPUT_RET_NORMAL;
100 * Init those operating function of touch panel driver
103 int ret = InputTouchIlitekInit(&g_input_touch_info);
104 g_touch_inited = true;
109 * Make touch panel start work
112 int ret = HAL_INPUT_RET_ERROR;
114 if (NULL != g_input_touch_info.start) {
115 ret = g_input_touch_info.start();
124 int ConfigTouch(const char *path , int reso_h, int reso_v) {
125 int ret = HAL_INPUT_RET_ERROR;
127 if (NULL != g_input_touch_info.config) {
128 ret = g_input_touch_info.config(path, reso_h, reso_v);
135 * Get touch panel device name
137 int GetPanelNameTouch(char* name, size_t buf_length) {
138 int ret = HAL_INPUT_RET_ERROR;
140 if (NULL != g_input_touch_info.get_touch_devicename) {
141 ret = g_input_touch_info.get_touch_devicename(name, buf_length);
148 * Get touch panel key device name
150 int GetKeyNameTouch(char* name, size_t buf_length) {
151 int ret = HAL_INPUT_RET_ERROR;
153 if (NULL != g_input_touch_info.get_key_devicename) {
154 ret = g_input_touch_info.get_key_devicename(name, buf_length);
161 * Execute touch panel self test
163 int SelfTestTouch(int id, void *result) {
164 int ret = HAL_INPUT_RET_ERROR;
166 if (NULL != g_input_touch_info.selftest) {
167 ret = g_input_touch_info.selftest(id, result);
174 * Get touch panel config status
176 int GetConfigStatusTouch(int *status) {
177 int ret = HAL_INPUT_RET_ERROR;
179 if (NULL != g_input_touch_info.get_config_status) {
180 ret = g_input_touch_info.get_config_status(status);
187 * Set whether the driver sends touch panel data or not
189 int LockTouch(int status) {
190 static int input_touch_lock_status = HAL_INPUT_TOUCH_REPORT_INVALID;
192 if (input_touch_lock_status == status) {
193 return HAL_INPUT_RET_NORMAL;
196 int ret = HAL_INPUT_RET_ERROR;
197 if (NULL != g_input_touch_info.set_touch_lock) {
198 ret = g_input_touch_info.set_touch_lock(status);
199 if (HAL_INPUT_RET_NORMAL == ret) {
200 input_touch_lock_status = status;
208 * Suspend touch panel
211 int ret = HAL_INPUT_RET_ERROR;
213 if (NULL != g_input_touch_info.set_touch_suspend) {
214 ret = g_input_touch_info.set_touch_suspend();
221 * Set touch panel sensitivity level
223 int SetSensitivityLevelTouch(int level) {
224 int cur = HAL_INPUT_TOUCH_SENSITIVITY_LEVEL_NONE;
226 int ret = GetSensitivityLevelTouch(&cur);
227 if (HAL_INPUT_RET_NORMAL == ret) {
229 // Don't need to update sensitivity level
230 INPUT_LOG_TRACE("already set level=%d", level);
232 if (NULL != g_input_touch_info.set_sensitivity_level) {
233 ret = g_input_touch_info.set_sensitivity_level(level);
235 ret = HAL_INPUT_RET_ERROR;
244 * Get touch panel sensitivity level
246 int GetSensitivityLevelTouch(int *level) {
247 int ret = HAL_INPUT_RET_ERROR;
249 if (NULL != g_input_touch_info.get_sensitivity_level) {
250 ret = g_input_touch_info.get_sensitivity_level(level);
257 * Notify radio scan frequency
259 int NotifyRadioScanFreqTouch(struct RadioInfoTouch *info) {
260 int ret = HAL_INPUT_RET_ERROR;
262 if (NULL != g_input_touch_info.notify_radio_scan_frequency) {
263 ret = g_input_touch_info.notify_radio_scan_frequency(info);