drivers/input: add dummy force feedback driver

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
This commit is contained in:
fangpeina 2024-05-28 22:47:41 +08:00 committed by Xiang Xiao
parent 947a32184b
commit cd15d37396
5 changed files with 202 additions and 0 deletions

View File

@ -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()

View File

@ -34,6 +34,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

View File

@ -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

138
drivers/input/ff_dummy.c Normal file
View File

@ -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 <debug.h>
#include <stdio.h>
#include <nuttx/bits.h>
#include <nuttx/kmalloc.h>
#include <nuttx/input/ff.h>
#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;
}

View File

@ -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_ */