# morningstar-engineering/mc6-mkii-midi-controller architecture

> Architecture diagram of the GitHub repository morningstar-engineering/mc6-mkii-midi-controller, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/morningstar-engineering/mc6-mkii-midi-controller
- Repository: https://github.com/morningstar-engineering/mc6-mkii-midi-controller

## Overview

##### Project Type and Purpose
This is an embedded‐firmware project for the “MC6 MKII” MIDI Controller. The firmware runs on a microcontroller and implements USB‐MIDI (and optionally USB‐Keyboard) interfaces, scans buttons/encoders, drives LEDs, and manages device configuration and firmware updates.

##### Architectural Overview
Although the repository file tree only lists configuration files and a README, the firmware’s internal structure typically follows these layers:
- Hardware Layer – Physical components (buttons, encoders, LEDs, USB transceiver, microcontroller pins)
- HAL (Hardware Abstraction Layer) – Pin drivers, timers, GPIO, ADC, I2C/SPI if needed
- USB Stack – USB enumeration, endpoint management (MIDI‐class, HID‐class for keyboard)
- MIDI/Keyboard Parsers – MIDI packet framing, transport over USB; optional HID keyboard report generation
- Application Logic – Mapping controls to MIDI messages, handling presets, macros, LED feedback
- Configuration & Persistence – Flash‐based storage of user settings, firmware bootloader for updates

A. Microcontroller (central node)
B. Hardware Peripherals
– Buttons/Encoders → scanned by HAL GPIO/ADC
– LEDs → controlled by HAL GPIO/PWM
– USB Transceiver → driven by USB Stack
C. Firmware Layers (stacked around the MCU)
1. Bootloader Module – handles firmware flashing & versioning
2. HAL – abstracts pin/timer peripherals
3. USB Stack – implements MIDI/HID USB class drivers
4. MIDI + Keyboard Parsers – packetize/depacketize messages
5. App Logic – mapping logic & UI feedback
6. Config Manager – reads/writes settings in flash memory
D. External Host (PC/DAW)
– Sends/receives MIDI messages over USB
– Optionally receives keyboard HID reports
E. Firmware Update Flow
– Host → USB Bootloader Endpoint → Flash rewrite

##### Architectural Patterns & Principles
- Layering: Hardware → HAL → Middleware (USB) → Domain Logic
- Modular Drivers: decouple USB, MIDI, hardware scans
- State Machines: for USB enumeration, MIDI message handling
- Persistent Storage Abstraction: treat flash settings like file I/O

##### Putting It All Together
2. Surround it with concentric layers for bootloader, HAL, USB stack, parsers, and app logic.
4. On the right, show the USB cable linking the USB stack to the Host.
5. On the left or top, show the configuration storage (Flash) and the bootloader update flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    ExternalHost["PC/DAW"]:::external

    subgraph "MC6 MKII MCU"
        subgraph "Bootloader Module"
            Bootloader["Bootloader"]
        end

        subgraph "Firmware Layers"
            HAL["HAL"]:::hal
            USBStack["USB Stack"]:::middleware
            MIDIParser["MIDI Parser"]:::middleware
            KeyboardParser["Keyboard Parser"]:::middleware
            AppLogic["Application Logic"]:::app
            ConfigMgr["Config Manager"]:::app
        end
    end

    subgraph "Hardware Layer"
        Buttons["Buttons/Encoders"]:::hardware
        LEDs["LEDs"]:::hardware
        USBTransceiver["USB Transceiver"]:::hardware
    end

    %% Data flows: Bottom-up control
    Buttons -->|"scan GPIO/ADC"| HAL
    HAL -->|"control signals"| AppLogic
    AppLogic -->|"generate MIDI messages"| MIDIParser
    AppLogic -->|"update LED state"| HAL
    HAL -->|"drive LEDs via PWM/GPIO"| LEDs

    %% USB MIDI and HID flows
    MIDIParser -->|"USB MIDI packets"| USBStack
    KeyboardParser -->|"USB HID reports"| USBStack
    USBStack -->|"MIDI & HID over USB"| ExternalHost
    ExternalHost -->|"MIDI data / HID events"| USBStack
    USBStack -->|"parse USB data"| MIDIParser
    MIDIParser -->|"deliver to AppLogic"| AppLogic

    %% Bootloader and config flows
    ExternalHost -.->|"firmware update over USB"| Bootloader
    Bootloader -->|"rewrite flash settings"| ConfigMgr

    classDef hardware fill:#d3d3d3,stroke:#666;
    classDef hal fill:#add8e6,stroke:#0074D9;
    classDef middleware fill:#87cefa,stroke:#005fa3;
    classDef app fill:#90ee90,stroke:#008000;
    classDef external fill:#ffcc99,stroke:#cc5500;
```
