# longdirtyanimalf/fpc-usb-hid architecture

> Architecture diagram of the GitHub repository longdirtyanimalf/fpc-usb-hid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/longdirtyanimalf/fpc-usb-hid
- Repository: https://github.com/longdirtyanimalf/fpc-usb-hid

## Overview

##### Layer Organization (Top to Bottom)

- [Application Layer]
- ↓
- [USB HID Controller Interface]
- ↓
- [Platform Abstraction Layer]
- /                    \
- [Linux Module]    [Windows Module]

- [Native USB]      [JVCL/JCL]

##### Additional Details

A notes section highlighting:
- Platform-specific requirements
- Configuration requirements (udev rules for Linux)
- Supported device types (emphasis on Microchip MCUs)

##### Implementation Details

- Linux implementation details
- Windows implementation with JVCL/JCL integration
- HIDAPI integration points

Remember to include:
- Version information
- Platform compatibility notes
- Required system configurations
- Key class relationships
- Error handling paths
- Device discovery and communication flows

This will provide a comprehensive view of how the system handles USB HID communication across different platforms while maintaining a clean and understandable architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Layer"
        APP[Application Code]
    end

    subgraph "Interface Layer"
        UHID["USB HID Controller Interface"]:::core
        click UHID "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/USB.pas"
    end

    subgraph "Platform Abstraction Layer"
        HIDAPI["HIDAPI Integration Layer"]:::core
        click HIDAPI "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/libhidapi/hidapi.pas"
        HIDCORE["HIDAPI Core Definitions"]:::core
        click HIDCORE "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/libhidapi/hidapi.inc"
    end

    subgraph "Platform-Specific Implementations"
        direction TB
        
        subgraph "Linux Implementation"
            direction TB
            LINUX["Linux USB Controller"]:::linux
            click LINUX "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/linux/usbcontroller.pas"
            BITS["Bit Operations"]:::linux
            click BITS "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/linux/Bits.pas"
            UDEV["udev Rules"]:::linux
            click UDEV "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/udev_rules/10-usbhid.rules"
        end

        subgraph "Windows Implementation"
            direction TB
            WIN["JVCL HID Controller"]:::windows
            click WIN "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/windows/jvcl/jvcl/run/JvHidControllerClass.pas"
            WHID["Windows HID Core"]:::windows
            click WHID "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/windows/jvcl/jvcl/run/Hid.pas"
            WUSAGE["HID Usage Definitions"]:::windows
            click WUSAGE "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/windows/jvcl/jvcl/run/HidUsage.pas"
            WSETUP["Setup API Integration"]:::windows
            click WSETUP "https://github.com/LongDirtyAnimAlf/FPC-USB-HID/blob/master/usblibs/windows/jvcl/jvcl/run/JvSetupApi.pas"
        end
    end

    subgraph "External Dependencies"
        LIBHID["libhidapi"]:::external
        JVCL["JVCL/JCL"]:::external
        NUSB["Native USB/HID APIs"]:::external
    end

    %% Connections
    APP --> UHID
    UHID --> HIDAPI
    HIDAPI --> HIDCORE
    HIDAPI --> LINUX
    HIDAPI --> WIN
    
    LINUX --> BITS
    LINUX --> UDEV
    LINUX --> NUSB
    
    WIN --> WHID
    WIN --> WUSAGE
    WIN --> WSETUP
    WIN --> JVCL
    WHID --> NUSB
    
    %% Styles
    classDef core fill:#a4c2f4,stroke:#0b5394
    classDef linux fill:#b6d7a8,stroke:#274e13
    classDef windows fill:#f9cb9c,stroke:#b45f06
    classDef external fill:#d9d9d9,stroke:#434343

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Linux Components"]:::linux
        L3["Windows Components"]:::windows
        L4["External Dependencies"]:::external
    end
```
