# chegewara/esptinyusb architecture

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

- Interactive diagram: https://gitdiagram.com/chegewara/esptinyusb
- Repository: https://github.com/chegewara/esptinyusb

## Overview

This is an ESP32 Arduino USB library for composing USB device classes and, experimentally, operating as a USB host. The device workflow configures device identity and class options, builds descriptors, then exposes class-specific behavior; storage classes can use RAM, flash, or SD media. The host side includes device support for CDC ACM and MSC, with MSC block operations and filesystem integration. Source excerpts show descriptor setup and selected class/host operations; several class implementations are indexed but unsampled, so their internal call links are omitted.

Main entry points: [`src/host/msc/usb_msc.cpp`](https://github.com/chegewara/esptinyusb/blob/master/src/host/msc/usb_msc.cpp) (Host MSC), [`src/device/hid/hidcomposite.cpp`](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidcomposite.cpp) (Composite HID), [`src/device/hid/hidkeyboard.cpp`](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidkeyboard.cpp) (HID keyboard), [`src/esptinyusb.cpp`](https://github.com/chegewara/esptinyusb/blob/master/src/esptinyusb.cpp) (EspTinyUSB core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["USB device classes"]
  node_cdc_device["CDC device<br/>[cdcusb.cpp]"]
  node_dfu_device["DFU device<br/>[dfuusb.cpp]"]
  node_hid_composite["Composite HID<br/>[hidcomposite.cpp]"]
  node_hid_keyboard["HID keyboard<br/>[hidkeyboard.cpp]"]
  node_hid_mouse["HID mouse<br/>[hidmouse.cpp]"]
  node_hid_gamepad["HID gamepad<br/>[hidgamepad.cpp]"]
  node_hid_generic["Generic HID<br/>[hidgeneric.cpp]"]
  node_hid_base["HID base<br/>[hidusb.cpp]"]
  node_key_layout["Key layouts<br/>[hidkeylayout.h]"]
  node_midi_device["MIDI device<br/>[midiusb.cpp]"]
  node_msc_device["MSC device<br/>[mscusb.cpp]"]
  node_webusb_device["WebUSB device<br/>[webusb.cpp]"]
end

subgraph group_descriptors["Device configuration"]
  node_devicecore["EspTinyUSB core<br/>[esptinyusb.cpp]"]
  node_descriptors_api["Descriptor generation"]
end

subgraph group_media["Device storage media"]
  node_ramdisk["RAM disk<br/>[ramdisk.cpp]"]
  node_flashdisk["Flash disk<br/>[flashdisk.cpp]"]
  node_sdcard["SD card storage<br/>[sdcard.cpp]"]
end

subgraph group_host["USB host"]
  node_host_core["USB host core<br/>[usb_host.cpp]"]
  node_host_device["Host device base<br/>[usb_device.cpp]"]
  node_host_acm["Host CDC ACM<br/>[usb_acm.cpp]"]
end

subgraph group_hoststorage["Host mass storage"]
  node_host_msc["Host MSC<br/>[usb_msc.cpp]"]
  node_raw_diskio["Raw MSC disk I/O<br/>[diskio_rawmsc.cpp]"]
  node_msc_requests["USB request types<br/>[usb_requests.hpp]"]
end

node_developer(("Library user"))

node_developer -->|"configures"| node_devicecore
node_devicecore -->|"builds descriptors"| node_descriptors_api
node_developer -->|"selects class"| node_cdc_device
node_developer -->|"selects class"| node_msc_device
node_developer -->|"selects class"| node_hid_composite
node_developer -->|"selects class"| node_hid_keyboard
node_developer -->|"selects class"| node_hid_mouse
node_developer -->|"selects class"| node_hid_gamepad
node_developer -->|"selects class"| node_hid_generic
node_developer -->|"selects class"| node_midi_device
node_developer -->|"selects class"| node_dfu_device
node_developer -->|"selects class"| node_webusb_device
node_hid_keyboard -->|"uses layout"| node_key_layout
node_hid_composite -.->|"uses layout"| node_key_layout
node_developer -->|"chooses media"| node_ramdisk
node_developer -->|"chooses media"| node_flashdisk
node_developer -->|"chooses media"| node_sdcard
node_developer -->|"uses host mode"| node_host_core
node_host_acm -->|"uses base"| node_host_device
node_host_msc -->|"uses base"| node_host_device
node_host_msc -.->|"uses commands"| node_msc_requests
node_host_msc -.->|"serves block I/O"| node_raw_diskio

click node_devicecore "https://github.com/chegewara/esptinyusb/blob/master/src/esptinyusb.cpp"
click node_descriptors_api "https://github.com/chegewara/esptinyusb/blob/master/src/usb_descriptors.cpp"
click node_cdc_device "https://github.com/chegewara/esptinyusb/blob/master/src/device/cdc/cdcusb.cpp"
click node_dfu_device "https://github.com/chegewara/esptinyusb/blob/master/src/device/dfu/dfuusb.cpp"
click node_hid_composite "https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidcomposite.cpp"
click node_hid_keyboard "https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidkeyboard.cpp"
click node_hid_mouse "https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidmouse.cpp"
click node_hid_gamepad "https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidgamepad.cpp"
click node_hid_generic "https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidgeneric.cpp"
click node_hid_base "https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidusb.cpp"
click node_key_layout "https://github.com/chegewara/esptinyusb/blob/master/src/hidkeylayout.h"
click node_midi_device "https://github.com/chegewara/esptinyusb/blob/master/src/device/midi/midiusb.cpp"
click node_msc_device "https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/mscusb.cpp"
click node_webusb_device "https://github.com/chegewara/esptinyusb/blob/master/src/device/web/webusb.cpp"
click node_ramdisk "https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/ramdisk.cpp"
click node_flashdisk "https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/flashdisk.cpp"
click node_sdcard "https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/sdcard.cpp"
click node_host_core "https://github.com/chegewara/esptinyusb/blob/master/src/host/common/usb_host.cpp"
click node_host_device "https://github.com/chegewara/esptinyusb/blob/master/src/host/common/usb_device.cpp"
click node_host_acm "https://github.com/chegewara/esptinyusb/blob/master/src/host/acm/usb_acm.cpp"
click node_host_msc "https://github.com/chegewara/esptinyusb/blob/master/src/host/msc/usb_msc.cpp"
click node_raw_diskio "https://github.com/chegewara/esptinyusb/blob/master/src/host/msc/vfs/diskio_rawmsc.cpp"
click node_msc_requests "https://github.com/chegewara/esptinyusb/blob/master/src/usb_requests.hpp"

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_cdc_device,node_dfu_device,node_hid_composite,node_hid_keyboard,node_hid_mouse,node_hid_gamepad,node_hid_generic,node_hid_base,node_key_layout,node_midi_device,node_msc_device,node_webusb_device,node_developer toneBlue
class node_devicecore,node_descriptors_api toneAmber
class node_ramdisk,node_flashdisk,node_sdcard toneMint
class node_host_core,node_host_device,node_host_acm toneRose
class node_host_msc,node_raw_diskio,node_msc_requests toneIndigo
```

## Components

### USB device classes

- [CDC device](https://github.com/chegewara/esptinyusb/blob/master/src/device/cdc/cdcusb.cpp): `src/device/cdc/cdcusb.cpp`
- [DFU device](https://github.com/chegewara/esptinyusb/blob/master/src/device/dfu/dfuusb.cpp): `src/device/dfu/dfuusb.cpp`
- [Composite HID](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidcomposite.cpp): `src/device/hid/hidcomposite.cpp`
- [HID keyboard](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidkeyboard.cpp): `src/device/hid/hidkeyboard.cpp`
- [HID mouse](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidmouse.cpp): `src/device/hid/hidmouse.cpp`
- [HID gamepad](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidgamepad.cpp): `src/device/hid/hidgamepad.cpp`
- [Generic HID](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidgeneric.cpp): `src/device/hid/hidgeneric.cpp`
- [HID base](https://github.com/chegewara/esptinyusb/blob/master/src/device/hid/hidusb.cpp): `src/device/hid/hidusb.cpp`
- [Key layouts](https://github.com/chegewara/esptinyusb/blob/master/src/hidkeylayout.h): `src/hidkeylayout.h`
- [MIDI device](https://github.com/chegewara/esptinyusb/blob/master/src/device/midi/midiusb.cpp): `src/device/midi/midiusb.cpp`
- [MSC device](https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/mscusb.cpp): `src/device/msc/mscusb.cpp`
- [WebUSB device](https://github.com/chegewara/esptinyusb/blob/master/src/device/web/webusb.cpp): `src/device/web/webusb.cpp`

### Device configuration

- [EspTinyUSB core](https://github.com/chegewara/esptinyusb/blob/master/src/esptinyusb.cpp): `src/esptinyusb.cpp`
- [Descriptor generation](https://github.com/chegewara/esptinyusb/blob/master/src/usb_descriptors.cpp): `src/usb_descriptors.cpp`

### Device storage media

- [RAM disk](https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/ramdisk.cpp): `src/device/msc/ramdisk.cpp`
- [Flash disk](https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/flashdisk.cpp): `src/device/msc/flashdisk.cpp`
- [SD card storage](https://github.com/chegewara/esptinyusb/blob/master/src/device/msc/sdcard.cpp): `src/device/msc/sdcard.cpp`

### USB host

- [USB host core](https://github.com/chegewara/esptinyusb/blob/master/src/host/common/usb_host.cpp): `src/host/common/usb_host.cpp`
- [Host device base](https://github.com/chegewara/esptinyusb/blob/master/src/host/common/usb_device.cpp): `src/host/common/usb_device.cpp`
- [Host CDC ACM](https://github.com/chegewara/esptinyusb/blob/master/src/host/acm/usb_acm.cpp): `src/host/acm/usb_acm.cpp`

### Host mass storage

- [Host MSC](https://github.com/chegewara/esptinyusb/blob/master/src/host/msc/usb_msc.cpp): `src/host/msc/usb_msc.cpp`
- [Raw MSC disk I/O](https://github.com/chegewara/esptinyusb/blob/master/src/host/msc/vfs/diskio_rawmsc.cpp): `src/host/msc/vfs/diskio_rawmsc.cpp`
- [USB request types](https://github.com/chegewara/esptinyusb/blob/master/src/usb_requests.hpp): `src/usb_requests.hpp`

### Other components

- **Library user**

## Connections

- Library user → EspTinyUSB core: configures (evidence: `README.md`)
- EspTinyUSB core → Descriptor generation: builds descriptors (evidence: `src/esptinyusb.cpp`)
- Library user → CDC device: selects class (evidence: `README.md`)
- Library user → MSC device: selects class (evidence: `README.md`)
- Library user → Composite HID: selects class (evidence: `README.md`)
- Library user → HID keyboard: selects class (evidence: `README.md`)
- Library user → HID mouse: selects class (evidence: `README.md`)
- Library user → HID gamepad: selects class (evidence: `README.md`)
- Library user → Generic HID: selects class (evidence: `README.md`)
- Library user → MIDI device: selects class (evidence: `README.md`)
- Library user → DFU device: selects class (evidence: `README.md`)
- Library user → WebUSB device: selects class (evidence: `README.md`)
- HID keyboard → Key layouts: uses layout (evidence: `src/device/hid/hidkeyboard.cpp`)
- Composite HID → Key layouts: uses layout
- Library user → RAM disk: chooses media (evidence: `README.md`)
- Library user → Flash disk: chooses media (evidence: `README.md`)
- Library user → SD card storage: chooses media (evidence: `README.md`)
- Library user → USB host core: uses host mode (evidence: `README.md`)
- Host CDC ACM → Host device base: uses base (evidence: `src/host/acm/usb_acm.cpp`)
- Host MSC → Host device base: uses base (evidence: `src/host/msc/usb_msc.cpp`)
- Host MSC → USB request types: uses commands
- Host MSC → Raw MSC disk I/O: serves block I/O
