From 3518c69e6cd45112d266261aaed254bbe1361fde Mon Sep 17 00:00:00 2001 From: fangpeina Date: Thu, 24 Oct 2024 17:54:35 +0800 Subject: [PATCH] input/ff: extend ioctrl to support factory calibration Signed-off-by: fangpeina --- drivers/input/ff_upper.c | 24 ++++++++++++++++++++++++ include/nuttx/input/ff.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/input/ff_upper.c b/drivers/input/ff_upper.c index ff4646f5b7..b8024b1987 100644 --- a/drivers/input/ff_upper.c +++ b/drivers/input/ff_upper.c @@ -391,6 +391,30 @@ static int ff_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + case EVIOCSETCALIBDATA: + { + if (upper->lower->set_calibvalue == NULL) + { + ret = -ENOTSUP; + break; + } + + ret = upper->lower->set_calibvalue(upper->lower, arg); + } + break; + + case EVIOCCALIBRATE: + { + if (upper->lower->calibrate == NULL) + { + ret = -ENOTSUP; + break; + } + + ret = upper->lower->calibrate(upper->lower, arg); + } + break; + default: ret = -ENOTTY; break; diff --git a/include/nuttx/input/ff.h b/include/nuttx/input/ff.h index b3e3e18b39..0a0fdefb9d 100644 --- a/include/nuttx/input/ff.h +++ b/include/nuttx/input/ff.h @@ -107,6 +107,19 @@ #define EVIOCGEFFECTS _FFIOC(3) +/* This cmd use to calibrate the device and return the calibration value. + * Arg: pointer to address of integer array value, return the calibration + * value. + */ + +#define EVIOCCALIBRATE _FFIOC(4) + +/* This cmd use to set calibration value for the device. + * Arg: pointer to address of the calibration value which should be set. + */ + +#define EVIOCSETCALIBDATA _FFIOC(5) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -403,6 +416,30 @@ struct ff_lowerhalf_s CODE void (*destroy)(FAR struct ff_lowerhalf_s *lower); + /* The calibration value to be written in or the non-volatile memory of the + * device or dedicated registers. At each power-on, so that the values read + * from the device are already corrected. When the device is calibrated, + * the absolute accuracy will be better than before. + * Note: the parameters associated with calibration value, maxinum 32-byte. + */ + + CODE int (*set_calibvalue)(FAR struct ff_lowerhalf_s *lower, + unsigned long arg); + + /* This operation can trigger the calibration operation, and if the + * calibration operation is short-lived, the calibration result value can + * be obtained at the same time, the calibration value to be written in + * the non-volatile memory of the device or dedicated registers. When the + * upper-level application calibration is completed, the current + * calibration value of the device needs to be obtained and backed up, + * so that the last calibration value can be directly obtained after + * power-on. + * Note: the parameters associated with calibration value, maxinum 32-byte. + */ + + CODE int (*calibrate)(FAR struct ff_lowerhalf_s *lower, + unsigned long arg); + /* The bitmap of force feedback capabilities truly supported by device */ unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];