Objective
- Implement a GPIO button as an input device
- Generate input events (short / long / double click)
- Verify with evtest and userspace
Driver Flow
GPIO IRQ
↓
debounce (delayed_work)
↓
state machine
↓
input_report_key()
↓
evdev
Click Definition
- Short click: press < 2 sec
- Long click: press >= 2 sec
- Double click:
- second press within 750 ms
Event Mapping
| Action |
Event |
| Short |
KEY_ENTER |
| Long |
KEY_ESC |
| Double |
KEY_SPACE |
State Machine
IDLE
↓ press
PRESSED
↓ release (<2s)
WAIT_SECOND
↓ timeout → SHORT
↓ second press → SECOND_PRESSED
↓ release → DOUBLE
Build
Load Driver
sudo insmod mygpio_input.ko
Load Overlay
sudo dtoverlay mygpio-input
Test
1. Find device
cat /proc/bus/input/devices
2. evtest
sudo evtest /dev/input/eventX
3. Userspace reader
4. Terminal test
Cleanup