You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/07/25 09:44:37 UTC
[incubator-nuttx] branch master updated: driver/sensor: add calibrate interface for sensor driver.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new fc84813b0a driver/sensor: add calibrate interface for sensor driver.
fc84813b0a is described below
commit fc84813b0a6b7535a4d2feaadd1bebdccaf6738d
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jul 21 02:47:12 2022 +0000
driver/sensor: add calibrate interface for sensor driver.
Add standard sensor interface for calibrate, can trigger
calibration and obtain calibration value.
Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
drivers/sensors/sensor.c | 12 ++++++++++++
include/nuttx/sensors/ioctl.h | 10 ++++++++++
include/nuttx/sensors/sensor.h | 24 ++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c
index 7f713b6ca8..670302c6f9 100644
--- a/drivers/sensors/sensor.c
+++ b/drivers/sensors/sensor.c
@@ -470,6 +470,18 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
}
break;
+ case SNIOC_CALIBRATE:
+ {
+ if (lower->ops->calibrate == NULL)
+ {
+ ret = -ENOTSUP;
+ break;
+ }
+
+ ret = lower->ops->calibrate(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 3f205469f8..ff9d76679e 100644
--- a/include/nuttx/sensors/ioctl.h
+++ b/include/nuttx/sensors/ioctl.h
@@ -305,4 +305,14 @@
#define SNIOC_SET_CALIBVALUE _SNIOC(0x0087)
+/* Command: SNIOC_CALIBRATE
+ * Description: Trigger calibration and obtain calibration value.
+ * Argument: A argument of calibration value for sensor.
+ * Note: If getting calibvalue is failed, return errno, otherwise,
+ * return OK.
+ * This cmd is handled by sensor_ops_s::get_calibvalue.
+ */
+
+#define SNIOC_CALIBRATE _SNIOC(0x0088)
+
#endif /* __INCLUDE_NUTTX_SENSORS_IOCTL_H */
diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h
index 4c8f28d9c1..a0298d4bd4 100644
--- a/include/nuttx/sensors/sensor.h
+++ b/include/nuttx/sensors/sensor.h
@@ -748,6 +748,30 @@ struct sensor_ops_s
CODE int (*set_calibvalue)(FAR struct sensor_lowerhalf_s *lower,
unsigned long arg);
+/****************************************************************************
+ * Name: calibrate
+ *
+ * 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 or
+ * the non-volatile memory of the sensor or dedicated registers. When the
+ * upper-level application calibration is completed, the current
+ * calibration value of the sensor needs to be obtained and backed up,
+ * so that the last calibration value can be directly obtained after
+ * power-on.
+ *
+ * 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 (*calibrate)(FAR struct sensor_lowerhalf_s *lower,
+ unsigned long arg);
+
/**************************************************************************
* Name: control
*