# kleutzinger-forks/haybox-gramctrl-kevbot architecture

> Architecture diagram of the GitHub repository kleutzinger-forks/haybox-gramctrl-kevbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kleutzinger-forks/haybox-gramctrl-kevbot
- Repository: https://github.com/kleutzinger-forks/haybox-gramctrl-kevbot

## Overview

##### Main Components

a) Hardware Abstraction Layer (HAL)
- Two main microcontroller platforms: AVR and Pico
- Sub-components for USB and non-USB variants
- GPIO, Serial, and Communication interfaces

b) Core System
- Input Processing Layer
- SOCD (Simultaneous Opposite Cardinal Direction) Handling
- State Management
- Controller Mode Management

c) Input Sources
- GPIO Buttons
- Switch Matrix
- GameCube Controller
- Nunchuk

d) Communication Backends
- DInput
- XInput
- GameCube
- N64
- Nintendo Switch
- B0XX Input Viewer

e) Game-Specific Modes
- Melee (Traditional and WASD)
- FGC (Traditional and WASD)
- Ultimate
- Project M
- Rivals
- Extra Games Support

**[Hardware Layer (AVR/Pico)] → [HAL] → [Core System] → [Input Processing] → [Mode-Specific Logic] → [Output Backends]**

##### Connection Types

**[Input Source] → [Mode Selection Logic] → [Active Game Mode] → [Output Backend]**

##### Configuration System
How different board configurations (b0xx_r1, b0xx_r2, gccmx, etc.) interact with the core system.

##### Key Relationships to Highlight
- Input source to SOCD handling
- Mode-specific logic to communication backends
- Configuration system to HAL
- USB/Non-USB variants in the HAL layer

For this specific project, emphasize:
##### The configuration system's role

Keep the abstraction level focused on the major architectural components while showing the key relationships between the different subsystems. This will help maintain clarity while still conveying the complexity and flexibility of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        AVR["AVR MCU"]:::hardware
        Pico["Pico MCU"]:::hardware
    end

    subgraph HAL["Hardware Abstraction Layer"]
        AVR_HAL["AVR HAL"]:::hal
        PICO_HAL["Pico HAL"]:::hal
        USB["USB Variant"]:::hal
        NoUSB["Non-USB Variant"]:::hal
    end

    subgraph InputSources["Input Sources"]
        GPIO["GPIO Buttons"]:::input
        Matrix["Switch Matrix"]:::input
        GCC["GameCube Controller"]:::input
        Nunchuk["Nunchuk"]:::input
    end

    subgraph CoreSystem["Core System"]
        InputProc["Input Processing"]:::core
        SOCD["SOCD Handling"]:::core
        State["State Management"]:::core
        CtrlMode["Controller Mode"]:::core
    end

    subgraph GameModes["Game-Specific Modes"]
        Melee["Melee"]:::mode
        MeleeWASD["Melee WASD"]:::mode
        FGC["FGC"]:::mode
        Ultimate["Ultimate"]:::mode
        ProjectM["Project M"]:::mode
        Rivals["Rivals"]:::mode
    end

    subgraph Backends["Communication Backends"]
        DInput["DInput"]:::backend
        XInput["XInput"]:::backend
        GCBackend["GameCube"]:::backend
        N64["N64"]:::backend
        Switch["Nintendo Switch"]:::backend
        B0XX["B0XX Input Viewer"]:::backend
    end

    subgraph Config["Configuration System"]
        ModeSelect["Mode Selection"]:::config
        BoardConfig["Board Configs"]:::config
    end

    %% Hardware to HAL
    AVR --> AVR_HAL
    Pico --> PICO_HAL
    AVR_HAL --> USB & NoUSB

    %% Input Sources to Core
    GPIO & Matrix & GCC & Nunchuk --> InputProc
    InputProc --> SOCD
    SOCD --> State
    State --> CtrlMode

    %% Core to Modes
    CtrlMode --> GameModes

    %% Modes to Backends
    GameModes --> Backends

    %% Config System
    BoardConfig --> HAL
    ModeSelect --> CtrlMode

    %% Click Events
    click AVR_HAL "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/tree/main//HAL/avr/"
    click PICO_HAL "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/tree/main//HAL/pico/"
    click USB "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/tree/main//HAL/avr/avr_usb/"
    click NoUSB "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/tree/main//HAL/avr/avr_nousb/"
    click InputProc "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/core/InputMode.hpp"
    click SOCD "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/core/socd.hpp"
    click State "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/core/state.hpp"
    click CtrlMode "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/core/ControllerMode.hpp"
    click GPIO "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/input/GpioButtonInput.hpp"
    click Matrix "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/input/SwitchMatrixInput.hpp"
    click GCC "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/input/GamecubeControllerInput.hpp"
    click Nunchuk "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/input/NunchukInput.hpp"
    click DInput "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/comms/DInputBackend.hpp"
    click XInput "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/comms/XInputBackend.hpp"
    click GCBackend "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/comms/GamecubeBackend.hpp"
    click N64 "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/comms/N64Backend.hpp"
    click Switch "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//HAL/pico/include/comms/NintendoSwitchBackend.hpp"
    click B0XX "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/comms/B0XXInputViewer.hpp"
    click Melee "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/modes/Melee21Button.hpp"
    click MeleeWASD "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/modes/Melee21ButtonWASD.hpp"
    click FGC "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/modes/FgcMode.hpp"
    click Ultimate "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/modes/Ultimate.hpp"
    click ProjectM "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/modes/ProjectM.hpp"
    click Rivals "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//include/modes/RivalsOfAether.hpp"
    click ModeSelect "https://github.com/kleutzinger-forks/haybox-GRAMCTRL-kevbot/blob/main//config/mode_selection.hpp"

    %% Styles
    classDef hardware fill:#a8d1f0
    classDef hal fill:#90caf9
    classDef input fill:#a5d6a7
    classDef core fill:#fff59d
    classDef mode fill:#ffcc80
    classDef backend fill:#ce93d8
    classDef config fill:#ef9a9a
```
