Overview
TheGamecubeBackend class implements the Joybus protocol for communicating with GameCube consoles. It handles bidirectional communication over a single data line, responding to console polls and sending controller state.
The GameCube backend uses hardware-specific features: PIO state machines on Pico and bit-banging on Arduino.
Platform Support
- Raspberry Pi Pico: ✅ Supported (PIO-based)
- Arduino (AVR): ✅ Supported (Nintendo library)
Constructor
Raspberry Pi Pico
Reference to the global input state structure.
Array of pointers to input source objects.
Number of elements in the
input_sources array.GPIO pin number for the Joybus data line (bidirectional communication).
PIO block to use for Joybus communication (pio0 or pio1).
State machine index to use. -1 for automatic allocation.
Program offset in PIO instruction memory. -1 for automatic allocation.
Arduino (AVR)
Expected polling rate from the console in Hz (typically 125 or 200). Set to 0 to disable delay compensation.
Arduino pin number for the Joybus data line.
The AVR version uses the polling rate to calculate optimal timing delays, ensuring reports are ready just before the next poll.
Configuration Example
Backend ID
SendReport Method
SendReport() method implements the GameCube polling response protocol:
Pico Implementation
- Scans slow and medium-speed inputs
- Waits for console poll start signal
- Delays 40μs to optimize timing
- Scans fast inputs (maximum 40μs old when sending)
- Updates output state based on game mode
- Maps outputs to GameCube report format
- Sends report if poll command is valid
Arduino Implementation
- Scans all inputs at once
- Updates output state based on game mode
- Maps outputs to GameCube report format
- Sends report to console
- Delays until just before next expected poll
Report Structure
GameCube controllers report the following:Digital Buttons
- A, B, X, Y
- Z (mapped from buttonR)
- L, R (trigger digital)
- Start
- D-pad: Up, Down, Left, Right
Analog Inputs
- Main stick: X/Y (0-255, 128 = center)
- C-stick: X/Y (0-255, 128 = center)
- L trigger analog (0-255)
- R trigger analog (0-255)
Special Mappings
Polling Rate and Timing
Pico (PIO-based)
- Uses hardware state machines for precise timing
- Automatically synchronizes with console polls
- 40μs optimization window for minimal input lag
Arduino (Software-based)
- Requires manual polling rate configuration
- Calculates delay:
(1000000 / polling_rate) - 850 - Leaves 850μs for processing before next poll
GetOffset Method (Pico Only)
Hardware Requirements
Signal Line
- Voltage: 3.3V logic (use level shifter if needed)
- Pull-up: 1kΩ resistor to 3.3V
- Cable: Connect to controller port data line
Pin Configuration
- Bidirectional data line (input/output)
- Must support fast GPIO operations
- Pico: Any GPIO pin
- Arduino: Pin 2 recommended (interrupt capable)
Usage Example
Console Detection
The GameCube backend can be automatically selected based on console detection:Performance Notes
- Pico: Uses hardware PIO for precise timing, minimal CPU overhead
- Arduino: Software-based, requires careful timing calibration
- Polling delay: Optimized to minimize latency while ensuring stability
- Input lag: Typically under 1ms with proper configuration
Troubleshooting
If the console doesn’t detect the controller:
- Check data pin connection and pull-up resistor
- Verify voltage levels (3.3V for Pico)
- Ensure polling rate matches console (125-200 Hz)
- Check for proper grounding between controller and console
See Also
- N64Backend - Similar Joybus protocol for N64
- Communication Backends - Backend selection guide
- Pinouts - Hardware pin mapping
