# zephyrcodesstuff/rf64 architecture

> Architecture diagram of the GitHub repository zephyrcodesstuff/rf64, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zephyrcodesstuff/rf64
- Repository: https://github.com/zephyrcodesstuff/rf64

## Overview

RF64 is bare-metal Rust firmware for the MIDI Fighter 64. Its main runtime samples and debounces the button matrix, handles USB MIDI input and device behavior, then updates the LEDs; a startup button combination can instead enter USB HID keyboard mode. The firmware also documents an idle Snake animation, Apollo Studio FastRGB/SysEx support, dynamic overcurrent protection, and DFU bootloader compatibility. The graph follows the sampled entry point and source-index references; some feature implementation details are documented but unsampled, so uncertain wiring is omitted.

Main entry points: [`src/main.rs`](https://github.com/zephyrcodesstuff/rf64/blob/main/src/main.rs) (Firmware loop), [`src/led.rs`](https://github.com/zephyrcodesstuff/rf64/blob/main/src/led.rs) (LED driver), [`src/usb/keyboard/mod.rs`](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/mod.rs) (Keyboard mode), [`src/usb/mod.rs`](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/mod.rs) (USB device manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and hardware"]
  node_main["Firmware loop<br/>[main.rs]"]
  node_buttons["Button matrix<br/>[buttons.rs]"]
  node_gpio["GPIO setup<br/>[gpio.rs]"]
  node_timer["Timing utilities<br/>[delay.rs]"]
  node_led["LED driver<br/>[led.rs]"]
  node_rng["Entropy source<br/>[rng.rs]"]
  node_instrumentation["Telemetry<br/>[instrumentation.rs]"]
end

subgraph group_midi["MIDI and lighting protocols"]
  node_midi_io["MIDI event handling<br/>[io.rs]"]
  node_fastled["FastRGB commands<br/>[fastled.rs]"]
  node_sysex["SysEx parser<br/>[sysex.rs]"]
  node_palette["Color palettes<br/>[palette.rs]"]
  node_mystrix["Mystrix protocol<br/>[mystrix.rs]"]
end

subgraph group_usb["USB interfaces"]
  node_usb_core["USB device manager<br/>[mod.rs]"]
  node_usb_midi["USB MIDI class<br/>[midi.rs]"]
  node_keyboard_mode["Keyboard mode<br/>[mod.rs]"]
  node_keyboard_usb["HID keyboard class<br/>[usb.rs]"]
  node_keyboard_layout["Key mapping<br/>[layout.rs]"]
end

subgraph group_boot["Boot and animation"]
  node_bootloader["Bootloader check<br/>[bootloader.rs]"]
  node_snake["Idle Snake animation<br/>[snake.rs]"]
end

node_host(("USB host"))

node_main -->|"checks boot request"| node_bootloader
node_main -->|"samples buttons"| node_buttons
node_main -->|"initializes hardware"| node_gpio
node_main -->|"initializes LEDs"| node_led
node_main -->|"seeds animation"| node_rng
node_main -->|"initializes and polls"| node_usb_core
node_main -->|"drains MIDI"| node_midi_io
node_main -->|"ticks animation"| node_snake
node_main -->|"records metrics"| node_instrumentation
node_midi_io -->|"reads and sends packets"| node_usb_midi
node_midi_io -->|"passes SysEx data"| node_sysex
node_midi_io -->|"updates host colors"| node_led
node_sysex -->|"dispatches lighting commands"| node_fastled
node_sysex -->|"dispatches protocol state"| node_mystrix
node_fastled -->|"applies FastRGB colors"| node_led
node_palette -->|"provides color values"| node_led
node_usb_core -->|"initializes MIDI class"| node_usb_midi
node_usb_core -->|"initializes keyboard class"| node_keyboard_usb
node_host -->|"sends MIDI and SysEx"| node_usb_midi
node_usb_midi -->|"sends MIDI output"| node_host
node_keyboard_mode -->|"polls USB"| node_usb_core
node_keyboard_mode -->|"sends HID reports"| node_keyboard_usb
node_keyboard_mode -->|"maps button colors"| node_keyboard_layout
node_keyboard_mode -->|"reads button state"| node_buttons
node_keyboard_mode -->|"renders status colors"| node_led
node_host -->|"receives HID reports"| node_keyboard_usb
node_snake -->|"fills animation frame"| node_led
node_snake -->|"reacts to button input"| node_buttons
node_snake -->|"uses random sequence"| node_rng
node_bootloader -->|"checks startup button"| node_buttons
node_usb_core -->|"delays bus reset"| node_timer

click node_main "https://github.com/zephyrcodesstuff/rf64/blob/main/src/main.rs"
click node_buttons "https://github.com/zephyrcodesstuff/rf64/blob/main/src/buttons.rs"
click node_gpio "https://github.com/zephyrcodesstuff/rf64/blob/main/src/gpio.rs"
click node_timer "https://github.com/zephyrcodesstuff/rf64/blob/main/src/delay.rs"
click node_led "https://github.com/zephyrcodesstuff/rf64/blob/main/src/led.rs"
click node_rng "https://github.com/zephyrcodesstuff/rf64/blob/main/src/rng.rs"
click node_instrumentation "https://github.com/zephyrcodesstuff/rf64/blob/main/src/instrumentation.rs"
click node_midi_io "https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/io.rs"
click node_fastled "https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/fastled.rs"
click node_sysex "https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/sysex.rs"
click node_palette "https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/palette.rs"
click node_mystrix "https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/mystrix.rs"
click node_usb_core "https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/mod.rs"
click node_usb_midi "https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/midi.rs"
click node_keyboard_mode "https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/mod.rs"
click node_keyboard_usb "https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/usb.rs"
click node_keyboard_layout "https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/layout.rs"
click node_bootloader "https://github.com/zephyrcodesstuff/rf64/blob/main/src/boot/bootloader.rs"
click node_snake "https://github.com/zephyrcodesstuff/rf64/blob/main/src/boot/snake.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_buttons,node_gpio,node_timer,node_led,node_rng,node_instrumentation toneBlue
class node_midi_io,node_fastled,node_sysex,node_palette,node_mystrix toneAmber
class node_usb_core,node_usb_midi,node_keyboard_mode,node_keyboard_usb,node_keyboard_layout toneMint
class node_bootloader,node_snake toneRose
class node_host toneIndigo
```

## Components

### Runtime and hardware

- [Firmware loop](https://github.com/zephyrcodesstuff/rf64/blob/main/src/main.rs): `src/main.rs`
- [Button matrix](https://github.com/zephyrcodesstuff/rf64/blob/main/src/buttons.rs): `src/buttons.rs`
- [GPIO setup](https://github.com/zephyrcodesstuff/rf64/blob/main/src/gpio.rs): `src/gpio.rs`
- [Timing utilities](https://github.com/zephyrcodesstuff/rf64/blob/main/src/delay.rs): `src/delay.rs`
- [LED driver](https://github.com/zephyrcodesstuff/rf64/blob/main/src/led.rs): `src/led.rs`
- [Entropy source](https://github.com/zephyrcodesstuff/rf64/blob/main/src/rng.rs): `src/rng.rs`
- [Telemetry](https://github.com/zephyrcodesstuff/rf64/blob/main/src/instrumentation.rs): `src/instrumentation.rs`

### MIDI and lighting protocols

- [MIDI event handling](https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/io.rs): `src/midi/io.rs`
- [FastRGB commands](https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/fastled.rs): `src/midi/fastled.rs`
- [SysEx parser](https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/sysex.rs): `src/midi/sysex.rs`
- [Color palettes](https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/palette.rs): `src/midi/palette.rs`
- [Mystrix protocol](https://github.com/zephyrcodesstuff/rf64/blob/main/src/midi/mystrix.rs): `src/midi/mystrix.rs`

### USB interfaces

- [USB device manager](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/mod.rs): `src/usb/mod.rs`
- [USB MIDI class](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/midi.rs): `src/usb/midi.rs`
- [Keyboard mode](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/mod.rs): `src/usb/keyboard/mod.rs`
- [HID keyboard class](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/usb.rs): `src/usb/keyboard/usb.rs`
- [Key mapping](https://github.com/zephyrcodesstuff/rf64/blob/main/src/usb/keyboard/layout.rs): `src/usb/keyboard/layout.rs`

### Boot and animation

- [Bootloader check](https://github.com/zephyrcodesstuff/rf64/blob/main/src/boot/bootloader.rs): `src/boot/bootloader.rs`
- [Idle Snake animation](https://github.com/zephyrcodesstuff/rf64/blob/main/src/boot/snake.rs): `src/boot/snake.rs`

### Other components

- **USB host**

## Connections

- Firmware loop → Bootloader check: checks boot request (evidence: `src/main.rs`)
- Firmware loop → Button matrix: samples buttons (evidence: `src/main.rs`)
- Firmware loop → GPIO setup: initializes hardware (evidence: `src/main.rs`)
- Firmware loop → LED driver: initializes LEDs (evidence: `src/main.rs`)
- Firmware loop → Entropy source: seeds animation (evidence: `src/main.rs`)
- Firmware loop → USB device manager: initializes and polls (evidence: `src/main.rs`)
- Firmware loop → MIDI event handling: drains MIDI (evidence: `src/main.rs`)
- Firmware loop → Idle Snake animation: ticks animation (evidence: `src/main.rs`)
- Firmware loop → Telemetry: records metrics (evidence: `src/main.rs`)
- MIDI event handling → USB MIDI class: reads and sends packets (evidence: `src/midi/io.rs`)
- MIDI event handling → SysEx parser: passes SysEx data (evidence: `src/midi/io.rs`)
- MIDI event handling → LED driver: updates host colors (evidence: `src/midi/io.rs`)
- SysEx parser → FastRGB commands: dispatches lighting commands (evidence: `src/midi/sysex.rs`)
- SysEx parser → Mystrix protocol: dispatches protocol state (evidence: `src/midi/sysex.rs`)
- FastRGB commands → LED driver: applies FastRGB colors (evidence: `src/midi/fastled.rs`)
- Color palettes → LED driver: provides color values (evidence: `src/midi/palette.rs`)
- USB device manager → USB MIDI class: initializes MIDI class (evidence: `src/usb/mod.rs`)
- USB device manager → HID keyboard class: initializes keyboard class (evidence: `src/usb/mod.rs`)
- USB host → USB MIDI class: sends MIDI and SysEx (evidence: `src/usb/midi.rs`)
- USB MIDI class → USB host: sends MIDI output (evidence: `src/usb/midi.rs`)
- Keyboard mode → USB device manager: polls USB (evidence: `src/usb/keyboard/mod.rs`)
- Keyboard mode → HID keyboard class: sends HID reports (evidence: `src/usb/keyboard/mod.rs`)
- Keyboard mode → Key mapping: maps button colors (evidence: `src/usb/keyboard/mod.rs`)
- Keyboard mode → Button matrix: reads button state (evidence: `src/usb/keyboard/mod.rs`)
- Keyboard mode → LED driver: renders status colors (evidence: `src/usb/keyboard/mod.rs`)
- USB host → HID keyboard class: receives HID reports (evidence: `src/usb/keyboard/usb.rs`)
- Idle Snake animation → LED driver: fills animation frame (evidence: `src/boot/snake.rs`)
- Idle Snake animation → Button matrix: reacts to button input (evidence: `src/boot/snake.rs`)
- Idle Snake animation → Entropy source: uses random sequence (evidence: `src/boot/snake.rs`)
- Bootloader check → Button matrix: checks startup button (evidence: `src/boot/bootloader.rs`)
- USB device manager → Timing utilities: delays bus reset (evidence: `src/usb/mod.rs`)
