diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2022-10-29 21:49:26 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2022-10-29 21:49:26 +0200 |
commit | de17d29ae0f3e4bbc1e1ff61071472f051cdce75 (patch) | |
tree | 92905ad59e028260ffff0a283ebd581959d54c1e /src/linux/input.md | |
parent | 6f322df0a549ed9e8b0421f86a9aa985add9b970 (diff) | |
download | notes-de17d29ae0f3e4bbc1e1ff61071472f051cdce75.tar.gz notes-de17d29ae0f3e4bbc1e1ff61071472f051cdce75.zip |
linux: add notes about input char devices
Diffstat (limited to 'src/linux/input.md')
-rw-r--r-- | src/linux/input.md | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/linux/input.md b/src/linux/input.md new file mode 100644 index 0000000..8a9771e --- /dev/null +++ b/src/linux/input.md @@ -0,0 +1,68 @@ +# Linux input + +Some notes on using `/dev/input/*` device driver files. + +## mouseX / mice + +These device files are created by the [mousedev] driver. + +- `/dev/input/mouseX` represents the input stream for a *SINGLE* mouse device. +- `/dev/input/mice` represents the merged input stream for *ALL* mouse devices. + +The data stream consists of `3 bytes` per `event`. An event is encoded as `(BTN, X, Y)`. +- `BTN` button pressed +- `X` movement in x-direction `-1 -> left` and `1 -> right` +- `Y` movement in y-direction `-1 -> down` and `1 -> up` + +The raw data stream can be inspected as follows. +```bash +sudo cat /dev/input/mice | od -tx1 -w3 -v +``` + +## eventX + +These device files are created by the [evdev] driver. + +- `/dev/input/eventX` represents the generic input event interface a *SINGLE* input deivece. + +Input events are encoded as given by the `input_event` struct below. Reading +from the `eventX` device file will always yield whole number of input events. +```c +struct input_event { + struct timeval time; + unsigned short type; + unsigned short code; + unsigned int value; +}; +``` + +On most 64bit machines the raw data stream can be inspected as follows. +```bash +sudo cat /dev/input/event4 | od -tx1 -w24 -v +``` + +## Identifyin device files. + +To find out which device file is assigned to which input device the following +file `/proc/bus/input/devices` in the proc filesystem can be consulted. + +This yields entries as follows and shows which `Handlers` are assigned to which +`Name`. +``` +I: Bus=0018 Vendor=04f3 Product=0033 Version=0000 +N: Name="Elan Touchpad" +... +H: Handlers=event15 mouse0 +... +``` + +## Example: Toying with `/dev/input/eventX` + +Once compiled, the example should be run as `sudo ./event /dev/input/eventX`. +```c +{{#include src/event.c:7: }} +``` + +[linux-input]: https://www.kernel.org/doc/Documentation/input/input.txt +[mousedev]: TODO /home/johannst/dev/linux/drivers/input/mousedev.c +[evdev]: TODO /home/johannst/dev/linux/drivers/input/evdev.c |