diff --git a/drivers/sensors/qencoder.c b/drivers/sensors/qencoder.c index 56cf10b76a..0925eb1221 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 7adc939b19..6400cefbec 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,