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/29 19:15:32 UTC
[incubator-nuttx] 03/04: driver/sensor: add struct file for all sensor_ops_s
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
commit 2ae5a82607f1bb25ab13c07763d75236af9d7cb9
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Apr 14 11:58:35 2022 +0800
driver/sensor: add struct file for all sensor_ops_s
Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
drivers/sensors/bmp280.c | 6 ++++++
drivers/sensors/ds18b20.c | 21 +++++++++++++++------
drivers/sensors/fakesensor.c | 9 +++++++--
drivers/sensors/hyt271.c | 17 ++++++++++++-----
drivers/sensors/l3gd20.c | 6 ++++--
drivers/sensors/ms5611.c | 6 ++++--
drivers/sensors/wtgahrs2.c | 8 ++++++--
7 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/drivers/sensors/bmp280.c b/drivers/sensors/bmp280.c
index 723c6cc349..93c3bc70c7 100644
--- a/drivers/sensors/bmp280.c
+++ b/drivers/sensors/bmp280.c
@@ -160,10 +160,13 @@ static int bmp280_putreg8(FAR struct bmp280_dev_s *priv, uint8_t regaddr,
/* Sensor methods */
static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us);
static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
bool enable);
static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen);
/****************************************************************************
@@ -504,6 +507,7 @@ static uint32_t bmp280_compensate_press(FAR struct bmp280_dev_s *priv,
****************************************************************************/
static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us)
{
FAR struct bmp280_dev_s *priv = container_of(lower,
@@ -557,6 +561,7 @@ static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
bool enable)
{
FAR struct bmp280_dev_s *priv = container_of(lower,
@@ -591,6 +596,7 @@ static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen)
{
FAR struct bmp280_dev_s *priv = container_of(lower,
diff --git a/drivers/sensors/ds18b20.c b/drivers/sensors/ds18b20.c
index 67014bdf8f..ffef8a4a17 100644
--- a/drivers/sensors/ds18b20.c
+++ b/drivers/sensors/ds18b20.c
@@ -158,16 +158,20 @@ struct ds18b20_dev_s
/* Sensor functions */
static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
bool enabled);
static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen);
static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
int cmd, unsigned long arg);
#ifdef CONFIG_SENSORS_DS18B20_POLL
static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us);
#endif
@@ -623,16 +627,18 @@ static int ds18b20_measure_read(FAR struct ds18b20_dev_s *dev,
* conversion.
*
* Parameter:
- * lower - Pointer to lower half sensor driver instance
- * buffer - Pointer to the buffer for reading data
- * buflen - Size of the buffer
+ * lower - Pointer to lower half sensor driver instance.
+ * filep - The pointer of file, represents each user using the sensor.
+ * buffer - Pointer to the buffer for reading data.
+ * buflen - Size of the buffer.
*
* Return:
* OK - on success
****************************************************************************/
static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower,
- FAR char *buffer, size_t buflen)
+ FAR struct file *filep,
+ FAR char *buffer, size_t buflen)
{
int ret;
struct ds18b20_sensor_data_s data;
@@ -673,7 +679,8 @@ static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower,
- int cmd, unsigned long arg)
+ FAR struct file *filep,
+ int cmd, unsigned long arg)
{
int ret;
struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower;
@@ -740,6 +747,7 @@ static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
bool enabled)
{
#ifdef CONFIG_SENSORS_DS18B20_POLL
@@ -778,7 +786,8 @@ static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower,
#ifdef CONFIG_SENSORS_DS18B20_POLL
static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower,
- FAR unsigned long *period_us)
+ FAR struct file *filep,
+ FAR unsigned long *period_us)
{
FAR struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower;
priv->interval = *period_us;
diff --git a/drivers/sensors/fakesensor.c b/drivers/sensors/fakesensor.c
index 823f15b1a2..06953c88ec 100644
--- a/drivers/sensors/fakesensor.c
+++ b/drivers/sensors/fakesensor.c
@@ -60,10 +60,12 @@ struct fakesensor_s
****************************************************************************/
static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower,
- bool sw);
+ FAR struct file *filep, bool sw);
static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us);
static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *latency_us);
static void fakesensor_push_event(FAR struct sensor_lowerhalf_s *lower);
static int fakesensor_thread(int argc, char** argv);
@@ -213,7 +215,8 @@ static inline void fakesensor_read_gps(FAR struct fakesensor_s *sensor)
sizeof(struct sensor_gps));
}
-static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, bool sw)
+static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep, bool sw)
{
FAR struct fakesensor_s *sensor = container_of(lower,
struct fakesensor_s, lower);
@@ -234,6 +237,7 @@ static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, bool sw)
}
static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us)
{
FAR struct fakesensor_s *sensor = container_of(lower,
@@ -243,6 +247,7 @@ static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
}
static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *latency_us)
{
FAR struct fakesensor_s *sensor = container_of(lower,
diff --git a/drivers/sensors/hyt271.c b/drivers/sensors/hyt271.c
index 06945942ca..197c20e8e1 100644
--- a/drivers/sensors/hyt271.c
+++ b/drivers/sensors/hyt271.c
@@ -110,16 +110,19 @@ struct hyt271_dev_s
/* Sensor functions */
static int hyt271_active(FAR struct sensor_lowerhalf_s *lower,
- bool enabled);
+ FAR struct file *filep, bool enabled);
static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen);
static int hyt271_control(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
int cmd, unsigned long arg);
#ifdef CONFIG_SENSORS_HYT271_POLL
static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us);
#endif
@@ -601,15 +604,17 @@ err_unlock:
* conversion.
*
* Parameter:
- * lower - Pointer to lower half sensor driver instance
- * buffer - Pointer to the buffer for reading data
- * buflen - Size of the buffer
+ * lower - Pointer to lower half sensor driver instance.
+ * filep - The pointer of file, represents each user using the sensor.
+ * buffer - Pointer to the buffer for reading data.
+ * buflen - Size of the buffer.
*
* Return:
* OK - on success
****************************************************************************/
static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen)
{
int ret;
@@ -664,6 +669,7 @@ static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int hyt271_control(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
int cmd, unsigned long arg)
{
int ret;
@@ -712,7 +718,7 @@ static int hyt271_control(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int hyt271_active(FAR struct sensor_lowerhalf_s *lower,
- bool enabled)
+ FAR struct file *filep, bool enabled)
{
#ifdef CONFIG_SENSORS_HYT271_POLL
bool start_thread = false;
@@ -751,6 +757,7 @@ static int hyt271_active(FAR struct sensor_lowerhalf_s *lower,
#ifdef CONFIG_SENSORS_HYT271_POLL
static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us)
{
FAR struct hyt271_sensor_s *priv = (FAR struct hyt271_sensor_s *)lower;
diff --git a/drivers/sensors/l3gd20.c b/drivers/sensors/l3gd20.c
index dad4cd5181..648b7bfe68 100644
--- a/drivers/sensors/l3gd20.c
+++ b/drivers/sensors/l3gd20.c
@@ -91,11 +91,12 @@ static void l3gd20_read_temperature(FAR struct l3gd20_dev_s *dev,
static int l3gd20_interrupt_handler(int irq, FAR void *context,
FAR void *arg);
static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower,
- bool enable);
+ FAR struct file *filep, bool enable);
#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
static void l3gd20_worker(FAR void *arg);
#else
static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen);
#endif
@@ -403,6 +404,7 @@ static void l3gd20_worker(FAR void *arg)
****************************************************************************/
static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR char *buffer, size_t buflen)
{
FAR struct l3gd20_dev_s *priv = container_of(lower,
@@ -427,7 +429,7 @@ static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower,
- bool enable)
+ FAR struct file *filep, bool enable)
{
FAR struct l3gd20_dev_s *priv = container_of(lower,
FAR struct l3gd20_dev_s,
diff --git a/drivers/sensors/ms5611.c b/drivers/sensors/ms5611.c
index 095e08e9b8..506d05eaca 100644
--- a/drivers/sensors/ms5611.c
+++ b/drivers/sensors/ms5611.c
@@ -121,9 +121,10 @@ static unsigned long ms5611_curtime(void);
/* Sensor methods */
static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us);
static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
- bool enable);
+ FAR struct file *filep, bool enable);
#if 0 /* Please read below */
static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower,
@@ -540,6 +541,7 @@ static uint32_t ms5611_compensate_press(FAR struct ms5611_dev_s *priv,
****************************************************************************/
static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *period_us)
{
FAR struct ms5611_dev_s *priv = container_of(lower,
@@ -555,7 +557,7 @@ static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/
static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
- bool enable)
+ FAR struct file *filep, bool enable)
{
bool start_thread = false;
struct ms5611_dev_s *priv = (FAR struct ms5611_dev_s *)lower;
diff --git a/drivers/sensors/wtgahrs2.c b/drivers/sensors/wtgahrs2.c
index c1c54a2f83..8ae2156b50 100644
--- a/drivers/sensors/wtgahrs2.c
+++ b/drivers/sensors/wtgahrs2.c
@@ -95,8 +95,10 @@ struct wtgahrs2_dev_s
* Private Function Prototypes
****************************************************************************/
-static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw);
+static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep, bool sw);
static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *interval);
/****************************************************************************
@@ -152,7 +154,8 @@ static void wtgahrs2_sendcmd(FAR struct wtgahrs2_dev_s *rtdata,
usleep(10000);
}
-static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw)
+static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep, bool sw)
{
FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower;
dev->enable = sw;
@@ -161,6 +164,7 @@ static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw)
}
static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower,
+ FAR struct file *filep,
FAR unsigned long *interval)
{
FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower;