From 550d2bff32b4d1f2b3f5974b54391dd6ee145339 Mon Sep 17 00:00:00 2001 From: songnannan Date: Tue, 9 Nov 2021 20:37:27 +0800 Subject: [PATCH] feature: sensor: add set calibration interface for sensor driver. Add standard sensor interface for setting calibartiion value. Signed-off-by: songnannan --- drivers/sensors/sensor.c | 12 ++++++++++++ include/nuttx/sensors/ioctl.h | 10 ++++++++++ include/nuttx/sensors/sensor.h | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index fc9d1c8427..13bad96634 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -445,6 +445,18 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + case SNIOC_SET_CALIBVALUE: + { + if (lower->ops->set_calibvalue == NULL) + { + ret = -ENOTSUP; + break; + } + + ret = lower->ops->set_calibvalue(lower, arg); + } + break; + case SNIOC_GET_NEVENTBUF: { *val = lower->buffer_number + lower->batch_number; diff --git a/include/nuttx/sensors/ioctl.h b/include/nuttx/sensors/ioctl.h index 2b4e4ea4d6..5e661f3aa2 100644 --- a/include/nuttx/sensors/ioctl.h +++ b/include/nuttx/sensors/ioctl.h @@ -297,4 +297,14 @@ #define SNIOC_SELFTEST _SNIOC(0x0086) +/* Command: SNIOC_SET_CALIBVALUE + * Description: Set calibration value for sensor. + * Argument: Calibration value for the sensor. + * Note: If setting calibvalue failed, a negated errno value is + * returned, otherwise, OK is returned. + * This cmd is handled by sensor_ops_s::set_calibvalue. + */ + +#define SNIOC_SET_CALIBVALUE _SNIOC(0x0087) + #endif /* __INCLUDE_NUTTX_SENSORS_IOCTL_H */ diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h index 6374c8a169..02fb26962b 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -678,6 +678,26 @@ struct sensor_ops_s CODE int (*selftest)(FAR struct sensor_lowerhalf_s *lower, unsigned long arg); + /************************************************************************** + * Name: set_calibvalue + * + * The calibration value to be written in or the non-volatile memory of the + * sensor or dedicated registers. At each power-on, so that the values read + * from the sensor are already corrected. When the device is calibrated, + * the absolute accuracy will be better than before. + * + * Input Parameters: + * lower - The instance of lower half sensor driver. + * arg - The parameters associated with calibration value. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + **************************************************************************/ + + CODE int (*set_calibvalue)(FAR struct sensor_lowerhalf_s *lower, + unsigned long arg); + /************************************************************************** * Name: control *