sensors/qencoder: add QEIOC_GETINDEX ioctl

This IOCTL (QEIOC_GETINDEX) allows the application to get the actual
encoder position, the index last position and the index count with
one IOCTL call if supported by architecture specific level.

The position, index and count is passed to application level through
qe_index_s structure.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc 2022-09-02 14:35:08 +02:00 committed by Xiang Xiao
parent 1a9252aec9
commit 8e2b4576bf

View File

@ -54,15 +54,20 @@
* Argument: uint32_t maximum position * Argument: uint32_t maximum position
* QEIOC_SETINDEX - Set the index position for the encoder. * QEIOC_SETINDEX - Set the index position for the encoder.
* Argument: uint32_t index position * Argument: uint32_t index position
* QEIOC_GETINDEX - Get the index position and count of the encoder.
* The structure also contains current position so QEIOC_POSITION
* is not required when QEIOC_GETINDEX is used.
* Argment: qe_index_s structure (refer below)
*/ */
#define QEIOC_POSITION _QEIOC(0x0001) /* Arg: int32_t* pointer */ #define QEIOC_POSITION _QEIOC(0x0001) /* Arg: int32_t* pointer */
#define QEIOC_RESET _QEIOC(0x0002) /* Arg: None */ #define QEIOC_RESET _QEIOC(0x0002) /* Arg: None */
#define QEIOC_SETPOSMAX _QEIOC(0x0003) /* Arg: uint32_t */ #define QEIOC_SETPOSMAX _QEIOC(0x0003) /* Arg: uint32_t */
#define QEIOC_SETINDEX _QEIOC(0x0004) /* Arg: uint32_t */ #define QEIOC_SETINDEX _QEIOC(0x0004) /* Arg: uint32_t */
#define QEIOC_GETINDEX _QEIOC(0x0005) /* Arg: qe_index_s struct */
#define QE_FIRST 0x0001 /* First required command */ #define QE_FIRST 0x0001 /* First required command */
#define QE_NCMDS 4 /* 4 required commands */ #define QE_NCMDS 5 /* 5 required commands */
/* User defined ioctl commands are also supported. These will be forwarded /* 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() * by the upper-half QE driver to the lower-half QE driver via the ioctl()
@ -138,6 +143,18 @@ struct qe_ops_s
int cmd, unsigned long arg); int cmd, unsigned long arg);
}; };
/* Structure qe_index_s is used for QEIOC_GETINDEX call. This call returns
* current encoder position, the last index position and number of index
* occurances.
*/
struct qe_index_s
{
int32_t qenc_pos; /* Qencoder actual position */
int32_t indx_pos; /* Index last position */
int16_t indx_cnt; /* Number of index occurances */
};
/* This is the interface between the lower half quadrature encoder driver /* This is the interface between the lower half quadrature encoder driver
* and the upper half quadrature encoder driver. A (device-specific) * and the upper half quadrature encoder driver. A (device-specific)
* instance of this structure is passed to the upper-half driver when the * instance of this structure is passed to the upper-half driver when the