rswitch(4)

NAME
rswitch - device driver for TRAB board rotary switch

SYNOPSIS
#include <linux/rswitch.h>

DESCRIPTION
The driver provides interface to the Incremental Rotary Switch connected to the TRAB board. Supported operations are:
Reading the current setting of the switch (angle).
Reading current state of the knob (pressed or released).
Setting the current angle.
Waiting for an event using poll()/select()functions.
The driver device node has the major number of 241 and may have any minor number (the minor number of the node is ignored by the driver).

FUNCTIONS
In general, the rswitch driver's functions behave as used with other drivers. A function return value of (-1) indicates an error, in which case an appropriate error code can be found in errno. The rswitch driver supports the following driver calls:

open()
    The node may be opened for reading and/or writing (mode is ignored). The minor number of the device node is ignored.
    Error codes:
    none

close()
    Error codes:
    none

read()
    The read() function copies the value of the current position of the rotary switch - the angle - to the buffer provided by the application. The buffer must be at least 4 bytes long.
    The value of the current angle is maintained and copied to the application's buffer as a signed integer variable. When the driver is loaded, the angle value is reset to zero. Each clockwise incremental turn of the rotary switch increments the angle value by one. Each anticlockwise incremental turn of the rotary switch decrements the angle value by one. The current angle value may be negative.
    Error codes:
    ENOMEM - size of the provided buffer is less than 4 bytes.

write()
    The write() call is not supported by the rswitch driver. It always returns (-1) with errno set to ENOSYS.

ioctl()
    The third argument to the ioctl() call must be a pointer to a variable of type int.
    The following IOCTL commands are supported:
    RSWITCH_SET_ANGLE
    Sets the value of the current angle of the rotary switch to the value of the variable pointed to by the command argument.
    RSWITCH_GET_KNOB_STATE
    Sets the value of the variable pointed to by the command argument to either 0 or 1, depending on the current state of the knob. If the knob is currently pressed, the value is 1, and if the knob is released, the value is 0.

poll()
    The poll() function implemented by the rswitch driver lets the application wait for an event to occurr on a file descriptor corresponding to the open path to rotary switch. The poll() function allows to wait separately for a switch rotation event and for a knob press or release event. The rotation events are returned as POLLIN (an event on the read file descriptor set, in case of select()), and knob press/release events are returned as POLLPRI (an event on the exception file descriptor set, in case of select()).
    To clear the indication of a rotation event, the application has to call the read() function of the driver. To clear the indication of the knob press or release event, the application must issue the RSWITCH_GET_KNOB_STATE IOCTL command.