This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3dbc4554806ad566e08247857f06294a192d3cdd
Author: Felipe Moura <[email protected]>
AuthorDate: Sat Aug 1 12:36:49 2026 -0300

    drivers/sensors/l3gd20: always deliver samples with push_event
    
    The driver had two modes selected by CONFIG_SENSORS_L3GD20_BUFFER_SIZE:
    with a buffer it pushed samples from a work queue, and without one it
    exposed fetch() while still using the data ready interrupt to signal
    readiness through notify_event.
    
    That second mode misuses the fetch interface. fetch() means the data is
    read from the device on demand and is therefore always available, while
    an interrupt driven sensor is exactly what push_event is for. Mixing the
    two forces the upper half to guess whether a fetch() only lower half
    will ever notify, and it makes poll() unusable in a multi descriptor
    loop, because the descriptor reports ready while the read still has to
    wait for the next interrupt.
    
    Drop the fetch path and always use the work queue and push_event, which
    is what the driver already did by default since BUFFER_SIZE defaults to
    1. CONFIG_SENSORS_L3GD20_BUFFER_SIZE gains a range of 1 to 32, as a zero
    sized buffer no longer has a meaning, and SCHED_HPWORK is now selected
    unconditionally because the work queue is always used.
    
    No in tree configuration enables this driver and the previous default
    already took the push path, so no defconfig changes are needed.
    
    Assisted-by: Claude:claude-sonnet-5
    
    Signed-off-by: Felipe Moura <[email protected]>
---
 drivers/sensors/Kconfig       |  8 ++++---
 drivers/sensors/l3gd20_uorb.c | 49 -------------------------------------------
 2 files changed, 5 insertions(+), 52 deletions(-)

diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig
index 1fb59146a51..f10ef20d0c1 100644
--- a/drivers/sensors/Kconfig
+++ b/drivers/sensors/Kconfig
@@ -861,17 +861,19 @@ config SENSORS_L3GD20
        bool "STMicro L3GD20 Gyroscope Sensor support"
        default n
        select SPI
-       select SCHED_HPWORK if SENSORS_L3GD20_BUFFER_SIZE > 0
+       select SCHED_HPWORK
        ---help---
                Enable driver support for the STMicro L3GD20 gyroscope sensor.
 
 config SENSORS_L3GD20_BUFFER_SIZE
        int "size of buffer"
        default 1
+       range 1 32
        depends on SENSORS_L3GD20
        ---help---
-               The size of the circular buffer used. If the value equal to 
zero,
-               indicates that the circular buffer is disabled.
+               The number of events that the circular buffer can hold. The data
+               ready interrupt pushes each sample into it, so at least one 
event
+               is required.
 
 config SENSOR_KXTJ9
        bool "Kionix KXTJ9 Accelerometer support"
diff --git a/drivers/sensors/l3gd20_uorb.c b/drivers/sensors/l3gd20_uorb.c
index 26d3f5b5070..c27c348a362 100644
--- a/drivers/sensors/l3gd20_uorb.c
+++ b/drivers/sensors/l3gd20_uorb.c
@@ -69,12 +69,10 @@ struct l3gd20_dev_s
                                        * L3GD20 sensor */
   uint64_t timestamp;                 /* Units is microseconds */
   struct sensor_lowerhalf_s lower;    /* The struct of lower half driver */
-#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
   struct work_s work;                 /* The work queue is responsible for
                                        * retrieving the data from the sensor
                                        * after the arrival of new data was
                                        * signalled in an interrupt */
-#endif
 };
 
 /****************************************************************************
@@ -100,13 +98,7 @@ static int l3gd20_interrupt_handler(int irq, FAR void 
*context,
                                     FAR void *arg);
 static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower,
                            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
 
 /****************************************************************************
  * Private Data
@@ -119,11 +111,7 @@ static const struct sensor_ops_s g_l2gd20_ops =
   .activate = l3gd20_activate,
   .set_interval = NULL,
   .batch = NULL,
-#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
   .fetch = NULL,
-#else
-  .fetch = l3gd20_fetch,
-#endif
   .control = NULL
 };
 
@@ -359,7 +347,6 @@ static int l3gd20_interrupt_handler(int irq, FAR void 
*context,
 
   priv->timestamp = sensor_get_timestamp();
 
-#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
   /* Task the worker with retrieving the latest sensor data. We should not do
    * this in a interrupt since it might take too long. Also we cannot lock
    * the SPI bus from within an interrupt.
@@ -373,17 +360,10 @@ static int l3gd20_interrupt_handler(int irq, FAR void 
*context,
       snerr("ERROR: Failed to queue work: %d\n", ret);
       return ret;
     }
-#else
-
-  /* notify event to upper half driver */
 
-  priv->lower.notify_event(priv->lower.priv);
-
-#endif
   return OK;
 }
 
-#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
 /****************************************************************************
  * Name: l3gd20_worker
  ****************************************************************************/
@@ -405,33 +385,6 @@ static void l3gd20_worker(FAR void *arg)
                          sizeof(struct sensor_gyro_uncal));
 }
 
-#else
-
-/****************************************************************************
- * Name: l3gd20_fetch
- ****************************************************************************/
-
-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,
-                                               FAR struct l3gd20_dev_s,
-                                               lower);
-
-  if (buflen != sizeof(struct sensor_gyro_uncal))
-      return 0;
-
-  DEBUGASSERT(priv != NULL);
-
-  /* Read out the latest sensor data */
-
-  l3gd20_read_measurement_data(priv, (FAR struct sensor_gyro_uncal *)buffer);
-
-  return sizeof(struct sensor_gyro_uncal);
-}
-#endif
-
 /****************************************************************************
  * Name: l3gd20_activate
  ****************************************************************************/
@@ -563,9 +516,7 @@ int l3gd20_register(int devno, FAR struct spi_dev_s *spi,
 
   priv->spi              = spi;
   priv->config           = config;
-#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
   priv->work.worker      = NULL;
-#endif
   priv->timestamp        = 0;
 
   priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;

Reply via email to