drivers/qencoder: add command to set the maximum encoder position

This commit is contained in:
raiden00pl 2021-08-07 14:25:05 +02:00 committed by Alan Carvalho de Assis
parent 092a0c8453
commit dca8c65331
2 changed files with 26 additions and 1 deletions

View File

@ -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
*/

View File

@ -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);