From 06da4c2f5f73e99e18aa5d98ed006ad6d3bcec4e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 28 Feb 2019 19:48:37 +0900 Subject: [PATCH] Add touchsensitivity for HAL Change-Id: Ie9fbaf35f8b95dbf14b06211d084ec93fa90baf5 Signed-off-by: lokilee73 --- CMakeLists.txt | 3 +- hw/touchsensitivity/CMakeLists.txt | 19 ++++++ hw/touchsensitivity/touchsensitivity.c | 116 +++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 hw/touchsensitivity/CMakeLists.txt create mode 100644 hw/touchsensitivity/touchsensitivity.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 89092ae..fb224ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,4 +10,5 @@ ADD_SUBDIRECTORY(hw/touchscreen) ADD_SUBDIRECTORY(hw/usb_gadget) ADD_SUBDIRECTORY(hw/usb_client) ADD_SUBDIRECTORY(hw/thermal) -ADD_SUBDIRECTORY(hw/bezel) \ No newline at end of file +ADD_SUBDIRECTORY(hw/bezel) +ADD_SUBDIRECTORY(hw/touchsensitivity) \ No newline at end of file diff --git a/hw/touchsensitivity/CMakeLists.txt b/hw/touchsensitivity/CMakeLists.txt new file mode 100644 index 0000000..7be54da --- /dev/null +++ b/hw/touchsensitivity/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(touchsensitivity C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(touchsensitivity_pkgs REQUIRED hwcommon dlog) + +FOREACH(flag ${touchsensitivity_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} MODULE touchsensitivity.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${touchsensitivity_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/touchsensitivity/touchsensitivity.c b/hw/touchsensitivity/touchsensitivity.c new file mode 100644 index 0000000..343de41 --- /dev/null +++ b/hw/touchsensitivity/touchsensitivity.c @@ -0,0 +1,116 @@ +/* + * device-node + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define TOUCHSENSITIVITY_GLOVE_MODE_PATH "/sys/class/sec/tsp/glove_mode" + +static int glove_mode_get_state(int *state) +{ + int ret, val; + + if (!state) + return -EINVAL; + + ret = sys_get_int(TOUCHSENSITIVITY_GLOVE_MODE_PATH, &val); + if (ret < 0) { + _E("Failed to get touch glove mode state (%d)", ret); + return ret; + } + + switch (val) { + case TOUCHSENSITIVITY_GLOVE_MODE_OFF: + case TOUCHSENSITIVITY_GLOVE_MODE_ON: + *state = val; + break; + default: + _E("Failed to get touch glove mode state (%d)", val); + return -EINVAL; + } + + return 0; +} + +static int glove_mode_set_state(int state) +{ + int ret, val; + + switch (state) { + case TOUCHSENSITIVITY_GLOVE_MODE_OFF: + case TOUCHSENSITIVITY_GLOVE_MODE_ON: + val = state; + break; + default: + _E("Invalid input (%d)", state); + return -EINVAL; + } + + ret = sys_set_int(TOUCHSENSITIVITY_GLOVE_MODE_PATH, val); + if (ret < 0) + _E("Failed to change touch glove mode state (%d)", ret); + + return ret; +} + +static int touchsensitivity_open(struct hw_info *info, + const char *id, struct hw_common **common) +{ + struct touchsensitivity_device *touchsensitivity_dev; + + if (!info || !common) + return -EINVAL; + + touchsensitivity_dev = calloc(1, sizeof(struct touchsensitivity_device)); + if (!touchsensitivity_dev) + return -ENOMEM; + + touchsensitivity_dev->common.info = info; + touchsensitivity_dev->glove_mode_get_state = glove_mode_get_state; + touchsensitivity_dev->glove_mode_set_state = glove_mode_set_state; + + *common = (struct hw_common *)touchsensitivity_dev; + return 0; +} + +static int touchsensitivity_close(struct hw_common *common) +{ + if (!common) + return -EINVAL; + + free(common); + return 0; +} + +HARDWARE_MODULE_STRUCTURE = { + .magic = HARDWARE_INFO_TAG, + .hal_version = HARDWARE_INFO_VERSION, + .device_version = TOUCHSENSITIVITY_HARDWARE_DEVICE_VERSION, + .id = TOUCHSENSITIVITY_HARDWARE_DEVICE_ID, + .name = "touchsensitivity", + .open = touchsensitivity_open, + .close = touchsensitivity_close, +}; -- 2.7.4