You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/08/10 14:19:12 UTC
[incubator-nuttx] 01/03: drivers/qencoder: add command to set the
maximum encoder position
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit dca8c653312fd197ffa9ce6738812d71d84ce5b8
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Aug 7 14:25:05 2021 +0200
drivers/qencoder: add command to set the maximum encoder position
---
drivers/sensors/qencoder.c | 18 ++++++++++++++++++
include/nuttx/sensors/qencoder.h | 9 ++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/sensors/qencoder.c b/drivers/sensors/qencoder.c
index 1ea96de..56cf10b 100644
--- a/drivers/sensors/qencoder.c
+++ b/drivers/sensors/qencoder.c
@@ -310,6 +310,24 @@ static int qe_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
}
break;
+ /* QEIOC_SETPOSMAX - Set the maximum encoder position.
+ * Argument: uint32
+ */
+
+ case QEIOC_SETPOSMAX:
+ {
+ uint32_t maxpos = (uint32_t)arg;
+ if (lower->ops->setposmax != NULL)
+ {
+ ret = lower->ops->setposmax(lower, maxpos);
+ }
+ 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 81a783d..7adc939 100644
--- a/include/nuttx/sensors/qencoder.h
+++ b/include/nuttx/sensors/qencoder.h
@@ -50,13 +50,16 @@
* Argument: int32_t pointer to the location to return the position.
* QEIOC_RESET - Reset the position to zero.
* Argument: None
+ * QEIOC_POSMAX - Set the maximum position for the encoder.
+ * Argument: uint32_t maximum position
*/
#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 QE_FIRST 0x0001 /* First required command */
-#define QE_NCMDS 2 /* Two required commands */
+#define QE_NCMDS 3 /* Two 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()
@@ -109,6 +112,10 @@ struct qe_ops_s
CODE int (*position)(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos);
+ /* Set the maximum encoder position. */
+
+ CODE int (*setposmax)(FAR struct qe_lowerhalf_s *lower, uint32_t pos);
+
/* Reset the position measurement to zero. */
CODE int (*reset)(FAR struct qe_lowerhalf_s *lower);