# erwinschrodinger1/dln2-generic architecture

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

- Interactive diagram: https://gitdiagram.com/erwinschrodinger1/dln2-generic
- Repository: https://github.com/erwinschrodinger1/dln2-generic

## Overview

dln2-generic is firmware and reusable components for making a microcontroller act as a DLN2 USB I/O adapter. Its main workflow is: a Linux DLN2 host sends commands over USB bulk endpoints; the USB class driver hands transfers to the protocol layer, which dispatches by module to GPIO, I2C, SPI, or ADC handlers; handlers use platform driver interfaces to operate hardware and form protocol responses. GPIO events and I2C bus recovery are additional capabilities. The source excerpts show transport dispatch and several handler-to-driver calls; subsystem links not shown directly are omitted or marked unverified.

Main entry points: [`src/app/dln2.c`](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2.c) (Transfer and slots), [`src/app/dln2-i2c-master.c`](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-i2c-master.c) (I2C master), [`src/app/dln2-gpio.c`](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-gpio.c) (GPIO commands), [`src/drivers/gpio_driver.h`](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/gpio_driver.h) (GPIO interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_usb["USB transport"]
  node_usb_descriptor["USB descriptors<br/>[usb_descriptors.c]"]
  node_usb_driver["USB class driver<br/>[driver.c]"]
end

subgraph group_protocol["Protocol handling"]
  node_protocol_core["Transfer and slots<br/>[dln2.c]"]
  node_protocol_api["Protocol definitions<br/>[dln2.h]"]
  node_pin_manager["Pin ownership<br/>[dln2-pin.c]"]
  node_logging["Logging<br/>[dln2_log.h]"]
end

subgraph group_modules["I/O modules"]
  node_gpio["GPIO commands<br/>[dln2-gpio.c]"]
  node_i2c["I2C master<br/>[dln2-i2c-master.c]"]
  node_spi["SPI master<br/>[dln2-spi-master.c]"]
  node_adc["ADC commands<br/>[dln2-adc.c]"]
end

subgraph group_platform["Platform interfaces"]
  node_gpio_api["GPIO interface<br/>[gpio_driver.h]"]
  node_i2c_api["I2C interface"]
  node_spi_api["SPI interface"]
  node_adc_api["ADC interface<br/>[adc_driver.h]"]
end

node_host(("DLN2 host"))
node_mcu["MCU hardware"]

node_host -->|"sends bulk commands"| node_usb_driver
node_usb_descriptor -->|"exposes bulk interface"| node_host
node_usb_driver -->|"forwards transfers"| node_protocol_core
node_protocol_core -->|"uses definitions"| node_protocol_api
node_protocol_core -->|"dispatches commands"| node_gpio
node_protocol_core -->|"dispatches commands"| node_i2c
node_protocol_core -->|"dispatches commands"| node_spi
node_protocol_core -->|"dispatches commands"| node_adc
node_gpio -->|"calls driver"| node_gpio_api
node_i2c -->|"calls driver"| node_i2c_api
node_i2c -->|"recovers bus"| node_gpio_api
node_spi -.->|"uses driver"| node_spi_api
node_adc -->|"uses driver"| node_adc_api
node_gpio -.->|"claims pins"| node_pin_manager
node_i2c -->|"claims pins"| node_pin_manager
node_gpio_api -.->|"operates pins"| node_mcu
node_i2c_api -.->|"operates bus"| node_mcu
node_spi_api -.->|"operates bus"| node_mcu
node_adc_api -.->|"reads channels"| node_mcu
node_protocol_core -->|"logs transfers"| node_logging

click node_usb_descriptor "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/tusb/usb_descriptors.c"
click node_usb_driver "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/driver.c"
click node_protocol_core "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2.c"
click node_protocol_api "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2.h"
click node_pin_manager "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-pin.c"
click node_gpio "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-gpio.c"
click node_i2c "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-i2c-master.c"
click node_spi "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-spi-master.c"
click node_adc "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-adc.c"
click node_gpio_api "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/gpio_driver.h"
click node_i2c_api "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/i2c_master_driver.h"
click node_spi_api "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/spi_master_driver.h"
click node_adc_api "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/adc_driver.h"
click node_logging "https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/utils/dln2_log.h"

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_usb_descriptor,node_usb_driver toneBlue
class node_protocol_core,node_protocol_api,node_pin_manager,node_logging toneAmber
class node_gpio,node_i2c,node_spi,node_adc toneMint
class node_gpio_api,node_i2c_api,node_spi_api,node_adc_api toneRose
class node_host,node_mcu toneIndigo
```

## Components

### USB transport

- [USB descriptors](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/tusb/usb_descriptors.c): `src/tusb/usb_descriptors.c`
- [USB class driver](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/driver.c): `src/app/driver.c`

### Protocol handling

- [Transfer and slots](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2.c): `src/app/dln2.c`
- [Protocol definitions](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2.h): `src/app/dln2.h`
- [Pin ownership](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-pin.c): `src/app/dln2-pin.c`
- [Logging](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/utils/dln2_log.h): `src/utils/dln2_log.h`

### I/O modules

- [GPIO commands](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-gpio.c): `src/app/dln2-gpio.c`
- [I2C master](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-i2c-master.c): `src/app/dln2-i2c-master.c`
- [SPI master](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-spi-master.c): `src/app/dln2-spi-master.c`
- [ADC commands](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/app/dln2-adc.c): `src/app/dln2-adc.c`

### Platform interfaces

- [GPIO interface](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/gpio_driver.h): `src/drivers/gpio_driver.h`
- [I2C interface](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/i2c_master_driver.h): `src/drivers/i2c_master_driver.h`
- [SPI interface](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/spi_master_driver.h): `src/drivers/spi_master_driver.h`
- [ADC interface](https://github.com/erwinschrodinger1/dln2-generic/blob/main/src/drivers/adc_driver.h): `src/drivers/adc_driver.h`

### Other components

- **DLN2 host**
- **MCU hardware**

## Connections

- DLN2 host → USB class driver: sends bulk commands (evidence: `README.md`)
- USB descriptors → DLN2 host: exposes bulk interface (evidence: `src/tusb/usb_descriptors.c`)
- USB class driver → Transfer and slots: forwards transfers (evidence: `src/app/driver.c`)
- Transfer and slots → Protocol definitions: uses definitions (evidence: `src/app/dln2.c`)
- Transfer and slots → GPIO commands: dispatches commands (evidence: `src/app/dln2.c`)
- Transfer and slots → I2C master: dispatches commands (evidence: `src/app/dln2.c`)
- Transfer and slots → SPI master: dispatches commands (evidence: `src/app/dln2.c`)
- Transfer and slots → ADC commands: dispatches commands (evidence: `src/app/dln2.c`)
- GPIO commands → GPIO interface: calls driver (evidence: `src/app/dln2-gpio.c`)
- I2C master → I2C interface: calls driver (evidence: `src/app/dln2-i2c-master.c`)
- I2C master → GPIO interface: recovers bus (evidence: `src/app/dln2-i2c-master.c`)
- SPI master → SPI interface: uses driver
- ADC commands → ADC interface: uses driver (evidence: `src/app/dln2-adc.c`)
- GPIO commands → Pin ownership: claims pins
- I2C master → Pin ownership: claims pins (evidence: `src/app/dln2-i2c-master.c`)
- GPIO interface → MCU hardware: operates pins
- I2C interface → MCU hardware: operates bus
- SPI interface → MCU hardware: operates bus
- ADC interface → MCU hardware: reads channels
- Transfer and slots → Logging: logs transfers (evidence: `src/app/dln2.c`)
