Overview
GpioButtonInput is an input source that reads button states from GPIO pins with internal pull-up resistors. This is the most common input method for reading individual buttons that are wired directly to microcontroller pins.
Buttons are read as active-low (pressed when pin reads LOW), utilizing internal pull-up resistors on each configured pin.
Class Declaration
Button Mapping Structure
The button identifier from the Button enum (e.g.,
BTN_LF1, BTN_RF1, BTN_MB1). See the button reference for all available button identifiers.The GPIO pin number where the button is connected. Pin numbers are platform-specific (e.g.,
0-28 on Pico, Arduino pin constants like A0-A5).Constructor
Pointer to an array of
GpioButtonMapping structures that define which buttons are connected to which pins.The number of button mappings in the array. Typically calculated using
sizeof(button_mappings) / sizeof(GpioButtonMapping).Methods
ScanSpeed()
ReturnsInputScanSpeed::FAST, indicating this input source should be polled frequently.
Always returns
InputScanSpeed::FASTUpdateInputs()
Reads the current state of all configured GPIO pins and updates the input state.Reference to the
InputState structure to update with current button states.Configuration Example
Basic GPIO Button Configuration
config.cpp
Reading Button States Early
You can read button states before backend initialization (e.g., to check for bootloader entry):config.cpp
Platform-Specific Notes
Raspberry Pi Pico
- GPIO pins are numbered 0-28
- All pins support internal pull-up resistors
- Pin initialization is handled automatically by the constructor
Arduino (AVR)
- Digital pins are numbered 0-13 (board-dependent)
- Analog pins can be used as digital inputs:
A0-A5 - Pin constants like
A0,A1are automatically defined
All GPIO pins are automatically configured with internal pull-up resistors. Buttons should be wired to connect the pin to ground (GND) when pressed.
Hardware Wiring
Buttons should be wired with a simple pull-down configuration:- When the button is not pressed: Pin reads HIGH (1)
- When the button is pressed: Pin reads LOW (0)
Button Identifiers
HayBox supports 60 button identifiers organized by controller region:| Region | Identifiers | Description |
|---|---|---|
| Left Face | BTN_LF1 - BTN_LF16 | Left face buttons (16 available) |
| Right Face | BTN_RF1 - BTN_RF16 | Right face buttons (16 available) |
| Left Thumb | BTN_LT1 - BTN_LT8 | Left thumb cluster buttons (8 available) |
| Right Thumb | BTN_RT1 - BTN_RT8 | Right thumb cluster buttons (8 available) |
| Middle | BTN_MB1 - BTN_MB12 | Middle/center buttons (12 available) |
Performance
- Scan Speed:
FAST- This input source is designed for rapid polling - Typical Scan Rate: 1000Hz+ depending on firmware loop speed
- Latency: < 1ms for button state changes
GPIO button inputs are extremely fast and suitable for competitive gaming applications where low latency is critical.
See Also
- SwitchMatrixInput - For matrix-wired button layouts
- DebouncedGpioButtonInput - GPIO input with hardware debouncing
- Button Reference - Complete button identifier reference
- Input Sources - Overview of all input source types
