Overview
TheDInputBackend class provides DirectInput (HID gamepad) protocol support. This backend offers maximum compatibility with PC applications, older games, and emulators that don’t support XInput.
DInput is ideal for applications that need standard HID gamepad support or when XInput is not available.
Platform Support
- Raspberry Pi Pico: ✅ Supported
- Arduino (AVR with USB): ✅ Supported
The AVR implementation uses the Arduino
Joystick.h library, while the Pico implementation uses TUGamepad from TinyUSB.Constructor
Raspberry Pi Pico
Arduino (AVR)
Reference to the global input state structure that tracks all button and analog input values.
Array of pointers to input source objects (GPIO buttons, analog sticks, etc.) that provide input data.
Number of elements in the
input_sources array.Key Features
Button Mapping (Pico)
The Pico implementation maps 13 buttons:- Button 0: B
- Button 1: A
- Button 2: Y
- Button 3: X
- Button 4: R (right shoulder)
- Button 5: RT (right trigger digital)
- Button 6: L (left shoulder)
- Button 7: LT (left trigger digital)
- Button 8: Select/Back
- Button 9: Start
- Button 10: Right stick click
- Button 11: Left stick click
- Button 12: Home
Analog Inputs
- Left Stick: X/Y axes (8-bit, 0-255)
- Right Stick: X/Y axes (8-bit, 0-255)
- Triggers: L/R analog (8-bit, 0-255)
- D-pad: Hat switch (8 directions + center)
Y-Axis Inversion
The Pico implementation inverts Y-axes to match standard HID conventions:Configuration
To use DInput as your primary backend:Backend ID
COMMS_BACKEND_DINPUT to identify this backend type.
SendReport Method
SendReport() method handles the complete input processing pipeline:
- Scans inputs at three different speeds (slow, medium, fast)
- Waits for HID device to be ready
- Updates output state based on game mode logic
- Maps outputs to HID gamepad report format
- Sends the report via USB
Input Scanning (Pico)
The Pico backend uses a three-stage scanning approach for optimal latency:AVR Implementation Notes
The AVR implementation (for Arduino Leonardo, Pro Micro, etc.) uses a single-stage input scan:Usage Example
Destructor
Platform Differences
Raspberry Pi Pico
- Uses
TUGamepadclass from TinyUSB - Supports hat switch for D-pad
- Includes trigger analog values
- Y-axis inversion for HID compliance
Arduino (AVR)
- Uses
Joystick_library - Standard HID gamepad descriptor
- Compatible with Leonardo, Pro Micro, etc.
Advantages
- Universal compatibility: Works with virtually all PC applications that accept gamepad input
- No driver required: Uses standard HID protocol
- Multi-platform: Supported on both Pico and Arduino
- Simple integration: No special host-side configuration needed
Limitations
- No native rumble support (XInput exclusive feature)
- Less optimized for modern games compared to XInput
- Some games may not properly detect analog triggers
See Also
- XInputBackend - XInput alternative for modern PC games
- CommunicationBackend - Base class for all backends
- Input Sources - Configuring input devices
