Available Input Sources
HayBox provides four main types of input sources:GpioButtonInput
Read switches/buttons connected directly to GPIO pins
SwitchMatrixInput
Scan a keyboard-style switch matrix
NunchukInput
Read inputs from a Wii Nunchuk via I2C
GamecubeControllerInput
Read inputs from a GameCube controller (Pico only)
Scan Speed
Each input source has a “scan speed” value which indicates roughly how long it takes to read inputs:- FAST - Read at the last possible moment for minimal latency (e.g., GPIO buttons, switch matrix)
- MEDIUM - Moderate reading speed
- SLOW - Takes longer to read, ideal to run continuously on a separate core (e.g., Nunchuk, GameCube controller)
Fast input sources are always read at the last possible moment (at least on Pico), resulting in very low latency. Slow input sources are typically read long before they are needed and are best run on a separate core using
setup1() and loop1().GpioButtonInput
The most commonly used input source for reading switches/buttons connected directly to GPIO pins.Configuration
Define your button mappings as an array ofGpioButtonMapping:
Button Naming Convention
BTN_LF1-8- Left Face buttons 1-8BTN_LT1-6- Left Thumb buttons 1-6BTN_MB1-12- Middle buttons 1-12BTN_RT1-7- Right Thumb buttons 1-7BTN_RF1-12- Right Face buttons 1-12
Usage in Config
Create the input source and add it to your backends:config/pico/config.cpp
SwitchMatrixInput
Scans a keyboard-style switch matrix instead of individual switches. This is more efficient for controllers with many buttons.Configuration
Define the matrix dimensions, pins, and button layout:Diode Direction
Specify the direction of your diodes:DiodeDirection::COL2ROW- Diodes point from columns to rowsDiodeDirection::ROW2COL- Diodes point from rows to columns
Use
NA (Not Assigned) for empty positions in the matrix where no button exists.Scan Speed
SwitchMatrixInput returns InputScanSpeed::FAST, making it suitable for low-latency reading.
NunchukInput
Reads inputs from a Wii Nunchuk using I2C communication. This is ideal for mixed input controllers where one hand uses analog stick movement.Configuration
Constructor Parameters
Scan Speed
NunchukInput returns InputScanSpeed::SLOW, so it should be read continuously on a separate core (see Dual-Core Setup).
GamecubeControllerInput
Reads inputs from a GameCube controller. Only available on Pico/RP2040.Configuration
Constructor Parameters
Scan Speed
GamecubeControllerInput returns InputScanSpeed::SLOW. Run it on core1 for best performance.
When using both
GamecubeControllerInput and GamecubeBackend, make sure they use different PIO instances (pio0 and pio1) or the same PIO instruction memory offset to avoid conflicts.Combining Multiple Input Sources
You can combine multiple input sources to create mixed input controllers:- GPIO + Nunchuk
- Matrix + GameCube
config.cpp
Backend Integration
Input sources work with communication backends through theinitialize_backends() function:
You can use multiple communication backends at once. For example, most configs use the B0XX input viewer backend as a secondary backend when the DInput backend is active.
