From 4797f29c0e905ff389aad1a8afaee9c50753cd8d Mon Sep 17 00:00:00 2001 From: fangpeina Date: Tue, 28 May 2024 22:47:41 +0800 Subject: [PATCH] drivers/input: add dummy force feedback driver Signed-off-by: fangpeina --- drivers/input/CMakeLists.txt | 4 + drivers/input/Kconfig | 6 ++ drivers/input/Make.defs | 4 + drivers/input/ff_dummy.c | 138 +++++++++++++++++++++++++++++++++ include/nuttx/input/ff_dummy.h | 50 ++++++++++++ 5 files changed, 202 insertions(+) create mode 100644 drivers/input/ff_dummy.c create mode 100644 include/nuttx/input/ff_dummy.h diff --git a/drivers/input/CMakeLists.txt b/drivers/input/CMakeLists.txt index 4beb158f01de8..48a04ba4a5c56 100644 --- a/drivers/input/CMakeLists.txt +++ b/drivers/input/CMakeLists.txt @@ -31,6 +31,10 @@ if(CONFIG_INPUT) list(APPEND SRCS ff_upper.c) endif() + if(CONFIG_FF_DUMMY) + list(APPEND SRCS ff_dummy.c) + endif() + if(CONFIG_FF_AW86225) list(APPEND SRCS aw86225.c) endif() diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 00d168f8a09ed..fe80790b7980a 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -33,6 +33,12 @@ config INPUT_FF if INPUT_FF +config FF_DUMMY + bool "Enable dummy force feedback driver" + default n + ---help--- + Enable support for a dummy force feedback driver. + config FF_AW86225 bool "Enable aw86225 driver" default n diff --git a/drivers/input/Make.defs b/drivers/input/Make.defs index 980eb7c0228b6..85891e0adf2f8 100644 --- a/drivers/input/Make.defs +++ b/drivers/input/Make.defs @@ -32,6 +32,10 @@ ifeq ($(CONFIG_INPUT_FF),y) CSRCS += ff_upper.c endif +ifeq ($(CONFIG_FF_DUMMY),y) + CSRCS += ff_dummy.c +endif + ifeq ($(CONFIG_FF_AW86225),y) CSRCS += aw86225.c endif diff --git a/drivers/input/ff_dummy.c b/drivers/input/ff_dummy.c new file mode 100644 index 0000000000000..f11418ae2b996 --- /dev/null +++ b/drivers/input/ff_dummy.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * drivers/input/ff_dummy.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include + +#define FF_DEVNAME_FMT "/dev/lra%d" +#define FF_DEVNAME_MAX 32 +#define FF_EFFECT_COUNT_MAX 5 + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +struct ff_dummy_dev_s +{ + struct ff_lowerhalf_s lower; +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int ff_dummy_haptics_upload_effect(FAR struct ff_lowerhalf_s *lower, + FAR struct ff_effect *effect, + FAR struct ff_effect *old) +{ + iinfo("called: effect_id = %d \n", effect->id); + return OK; +} + +static int ff_dummy_haptics_playback(struct ff_lowerhalf_s *lower, + int effect_id, int val) +{ + iinfo("called: effect_id = %d val = %d\n", effect_id, val); + return OK; +} + +static int ff_dummy_haptics_erase(FAR struct ff_lowerhalf_s *lower, + int effect_id) +{ + iinfo("called: effect_id = %d\n", effect_id); + return OK; +} + +static void ff_dummy_haptics_set_gain(FAR struct ff_lowerhalf_s *lower, + uint16_t gain) +{ + iinfo("called: gain = %d\n", gain); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ff_dummy_initialize + * + * Description: + * This function gengrate a vibrator node under /dev/ named lran. Which + * indicates a dummy vibrator device. + * + * Input Parameters: + * devno - The user specifies device number, from 0. If the + * devno alerady exists, -EEXIST will be returned. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ff_dummy_initialize(int devno) +{ + FAR struct ff_lowerhalf_s *lower; + FAR struct ff_dummy_dev_s *dev; + char path[FF_DEVNAME_MAX]; + int ret; + + dev = kmm_zalloc(sizeof(struct ff_dummy_dev_s)); + if (NULL == dev) + { + ierr("failed to alloc memory for ff dummy\n\n"); + return -ENOMEM; + } + + lower = &dev->lower; + lower->upload = ff_dummy_haptics_upload_effect; + lower->playback = ff_dummy_haptics_playback; + lower->set_gain = ff_dummy_haptics_set_gain; + lower->erase = ff_dummy_haptics_erase; + + /* set dummy device capabilities */ + + __set_bit(FF_CUSTOM, lower->ffbit); + __set_bit(FF_GAIN, lower->ffbit); + __set_bit(FF_CONSTANT, lower->ffbit); + __set_bit(FF_PERIODIC, lower->ffbit); + + snprintf(path, FF_DEVNAME_MAX, FF_DEVNAME_FMT, devno); + ret = ff_register(lower, path, FF_EFFECT_COUNT_MAX); + if (ret >= 0) + { + return ret; + } + + ierr("Failed to register driver:%d\n", ret); + kmm_free(dev); + return ret; +} diff --git a/include/nuttx/input/ff_dummy.h b/include/nuttx/input/ff_dummy.h new file mode 100644 index 0000000000000..b2ea7c5eb2e24 --- /dev/null +++ b/include/nuttx/input/ff_dummy.h @@ -0,0 +1,50 @@ +/**************************************************************************** + * include/nuttx/input/ff_dummy.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_INPUT_FF_DUMMY_H_ +#define __INCLUDE_NUTTX_INPUT_FF_DUMMY_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: ff_dummy_initialize + * + * Description: + * This function gengrate a vibrator node under /dev/ named lran. Which + * indicates a dummy vibrator device. + * + * Input Parameters: + * devno - The user specifies device number, from 0. If the + * devno alerady exists, -EEXIST will be returned. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int ff_dummy_initialize(int devno); + +#endif /* __INCLUDE_NUTTX_INPUT_FF_DUMMY_H_ */