# cpb-/spi-tools architecture

> Architecture diagram of the GitHub repository cpb-/spi-tools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cpb-/spi-tools
- Repository: https://github.com/cpb-/spi-tools

## Overview

##### Project type and purpose
- This is an open‑source, command‑line toolset (written in C) for configuring and communicating with Linux SPI devices via the spidev interface.
- It provides two main user‑facing binaries—spi-config (to query/set mode, speed, bits, etc.) and spi-pipe (to send/receive raw SPI data streams).

##### File structure
- Top level contains:
- Build scripts/configs (Autotools: `configure.ac`, `Makefile.am`; CMake: `CMakeLists.txt`, `Android.bp`)
- License (`LICENSE`), version control ignore (`.gitignore`), README and man‐page directory (`man/`).
- The `src/` directory holds:
- Three C sources (`spi-config.c`, `spi-pipe.c`, `spi-tools.c`) and one header (`spi-tools.h`).
- A CMake helper (`config.h.cmake.in`) and its own `Makefile.am`.
- `man/` holds the installation targets for the man pages.

##### README for additional insights
- Confirms the two binaries and their command‑line options.
- Describes dual build workflows (Autotools vs CMake), cross‑compilation support, and usage patterns (e.g., piping data through spi-pipe).

##### Final recommendations
- Every layer—from build to hardware—and show how source files map to binaries.
- Code modules (e.g., “spi-tools.c: common ioctl routines”).

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Build System
  subgraph "Build System"
    AC["Autotools"]:::build
    CONFIG_AC["configure.ac"]:::build
    MAKE_AM_TOP["Makefile.am"]:::build
    MAKE_AM_SRC["src/Makefile.am"]:::build
    AC --> CONFIG_AC
    AC --> MAKE_AM_TOP
    AC --> MAKE_AM_SRC

    CMake["CMake & Android"]:::build
    CMAKE_LISTS["CMakeLists.txt"]:::build
    ANDROID_BP["Android.bp"]:::build
    CMake --> CMAKE_LISTS
    CMake --> ANDROID_BP
  end

  %% Source Code
  subgraph "Source Code Layer"
    SPI_TOOLS_C["spi-tools.c\n(common SPI routines)"]:::src
    SPI_TOOLS_H["spi-tools.h"]:::src
    CONFIG_H_CMAKE["config.h.cmake.in"]:::src
    SPI_CONFIG_C["spi-config.c"]:::src
    SPI_PIPE_C["spi-pipe.c"]:::src
  end

  %% Man Pages
  subgraph "Man Pages"
    MAN_SPI_CONFIG["spi-config.1"]:::man
    MAN_SPI_PIPE["spi-pipe.1"]:::man
    MAKEFILE_AM_MAN["man/Makefile.am"]:::man
  end

  %% Binaries
  subgraph "Binaries"
    BIN_CONFIG["spi-config"]:::runtime
    BIN_PIPE["spi-pipe"]:::runtime
  end

  %% Runtime Environment
  subgraph "Runtime Environment"
    SHELL["Shell/CLI"]:::runtime
    EXTERNAL["External Commands"]:::runtime
  end

  %% Kernel and Hardware
  KERNEL["spidev driver\n(/dev/spidevX.Y)"]:::kernel
  HARDWARE["SPI Hardware\n(MOSI/MISO/CLK/CS)"]:::hardware

  %% Build Flow
  AC -->|"build time"| SPI_TOOLS_C
  CMake -->|"build time"| SPI_TOOLS_C
  SPI_TOOLS_C -->|"compile/link"| BIN_CONFIG
  SPI_TOOLS_C -->|"compile/link"| BIN_PIPE
  SPI_CONFIG_C -->|"compile/link"| BIN_CONFIG
  SPI_PIPE_C -->|"compile/link"| BIN_PIPE

  %% Install Flow
  BIN_CONFIG -->|"install man page"| MAN_SPI_CONFIG
  BIN_PIPE -->|"install man page"| MAN_SPI_PIPE
  MAKEFILE_AM_MAN -->|"defines targets"| MAN_SPI_CONFIG
  MAKEFILE_AM_MAN -->|"defines targets"| MAN_SPI_PIPE

  %% Runtime Flow: spi-config
  SHELL -->|"invokes"| BIN_CONFIG
  BIN_CONFIG -->|"ioctl SPI_IOC_*"| KERNEL
  KERNEL -->|"drives"| HARDWARE

  %% Runtime Flow: spi-pipe
  SHELL -->|"pipes data"| BIN_PIPE
  BIN_PIPE -->|"read/write or ioctl"| KERNEL
  BIN_PIPE -->|"stdin/stdout pipe"| EXTERNAL
  KERNEL -->|"drives"| HARDWARE

  %% Click Events
  click CONFIG_AC "https://github.com/cpb-/spi-tools/blob/master/configure.ac"
  click MAKE_AM_TOP "https://github.com/cpb-/spi-tools/blob/master/Makefile.am"
  click MAKE_AM_SRC "https://github.com/cpb-/spi-tools/blob/master/src/Makefile.am"
  click CMAKE_LISTS "https://github.com/cpb-/spi-tools/blob/master/CMakeLists.txt"
  click ANDROID_BP "https://github.com/cpb-/spi-tools/blob/master/Android.bp"
  click SPI_TOOLS_C "https://github.com/cpb-/spi-tools/blob/master/src/spi-tools.c"
  click SPI_TOOLS_H "https://github.com/cpb-/spi-tools/blob/master/src/spi-tools.h"
  click CONFIG_H_CMAKE "https://github.com/cpb-/spi-tools/blob/master/src/config.h.cmake.in"
  click SPI_CONFIG_C "https://github.com/cpb-/spi-tools/blob/master/src/spi-config.c"
  click SPI_PIPE_C "https://github.com/cpb-/spi-tools/blob/master/src/spi-pipe.c"
  click MAN_SPI_CONFIG "https://github.com/cpb-/spi-tools/blob/master/man/spi-config.1"
  click MAN_SPI_PIPE "https://github.com/cpb-/spi-tools/blob/master/man/spi-pipe.1"
  click MAKEFILE_AM_MAN "https://github.com/cpb-/spi-tools/blob/master/man/Makefile.am"

  %% Styles
  classDef build fill:#e6fde3,stroke:#2ca02c,color:#2c662d;
  classDef src fill:#f0f8ff,stroke:#1f77b4,color:#1a4c74;
  classDef runtime fill:#e7f3ff,stroke:#1f77b4,color:#1a4c74;
  classDef kernel fill:#f2f2f2,stroke:#7f7f7f,color:#595959;
  classDef hardware fill:#fff4e6,stroke:#ff7f0e,color:#8c4700;
  classDef man fill:#f9e6ff,stroke:#9467bd,color:#613b74;
```
