diff --git a/drivers/sensors/qencoder.c b/drivers/sensors/qencoder.c index 1ea96de6e90..56cf10b76a2 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 81a783d3a49..7adc939b19f 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);