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 bf23abfbd5968190ec7cbb7879527de8bbe12214
Author: raiden00pl <[email protected]>
AuthorDate: Sat Nov 6 19:08:35 2021 +0100

    drivers/qencoder: add an interface to configure the encoder index pin 
position
---
 drivers/sensors/qencoder.c       | 18 ++++++++++++++++++
 include/nuttx/sensors/qencoder.h |  7 ++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/sensors/qencoder.c b/drivers/sensors/qencoder.c
index 56cf10b..0925eb1 100644
--- a/drivers/sensors/qencoder.c
+++ b/drivers/sensors/qencoder.c
@@ -328,6 +328,24 @@ static int qe_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         }
         break;
 
+      /* QEIOC_SETINDEX - Set the index pin position
+       *   Argument: uint32
+       */
+
+      case QEIOC_SETINDEX:
+        {
+          uint32_t indexpos = (uint32_t)arg;
+          if (lower->ops->setindex != NULL)
+            {
+              ret = lower->ops->setindex(lower, indexpos);
+            }
+          else
+            {
+              ret = -ENOTTY;
+            }
+        }
+        break;
+
       /* Any unrecognized IOCTL commands might be platform-specific ioctl
        * commands
        */
diff --git a/include/nuttx/sensors/qencoder.h b/include/nuttx/sensors/qencoder.h
index 7adc939..6400cef 100644
--- a/include/nuttx/sensors/qencoder.h
+++ b/include/nuttx/sensors/qencoder.h
@@ -57,9 +57,10 @@
 #define QEIOC_POSITION     _QEIOC(0x0001) /* Arg: int32_t* pointer */
 #define QEIOC_RESET        _QEIOC(0x0002) /* Arg: None */
 #define QEIOC_SETPOSMAX    _QEIOC(0x0003) /* Arg: uint32_t */
+#define QEIOC_SETINDEX     _QEIOC(0x0004) /* Arg: uint32_t */
 
 #define QE_FIRST           0x0001         /* First required command */
-#define QE_NCMDS           3              /* Two required commands */
+#define QE_NCMDS           4              /* 4 required commands */
 
 /* User defined ioctl commands are also supported. These will be forwarded
  * by the upper-half QE driver to the lower-half QE driver via the ioctl()
@@ -120,6 +121,10 @@ struct qe_ops_s
 
   CODE int (*reset)(FAR struct qe_lowerhalf_s *lower);
 
+  /* Set the index pin position */
+
+  CODE int (*setindex)(FAR struct qe_lowerhalf_s *lower, uint32_t pos);
+
   /* Lower-half logic may support platform-specific ioctl commands */
 
   CODE int (*ioctl)(FAR struct qe_lowerhalf_s *lower,

Reply via email to