# syurazo/cardputer architecture

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

- Interactive diagram: https://gitdiagram.com/syurazo/cardputer
- Repository: https://github.com/syurazo/cardputer

## Overview

- Library Entry Point (cardputer crate): This is the integration point that lets an application use the hardware utilities. The public API is exposed via src/lib.rs.
- Module Components:
- Module (src/display.rs): Responsible for initializing and managing the ST7789 driver.
- Backlight Module (src/backlight.rs): Manages the LCD backlight control.
- Keyboard Module (src/keyboard.rs): Decodes signals using the 74HC138 chip logic and converts them to keycodes.
- Grove Module (src/grove.rs): Initializes and handles the I2C driver for the Grove interface.
- Build & Configuration Component:
- build.rs & Cargo.toml: Handle the build process and dependency management.
- Examples:
- The examples directory with key_monitor.rs shows how to use the library in an application context.

##### Relationships and Interactions
- Application Layer: At the top, illustrate a user’s application (like the key_monitor example) that utilizes the public API provided by the cardputer crate.
- API Layer (cardputer Library): Indicate that the application interacts with the different modules (display, backlight, keyboard, grove) via clearly defined functions.
- The Display Module interacts with the ST7789 display hardware.
- The Backlight Module controls the physical backlight circuitry.
- The Keyboard Module decodes hardware signals (via 74HC138 multiplexing) which are then passed to the application.
- The Grove Module uses I2C communication to interface with various Grove sensors/actuators.

##### Architectural Patterns or Design Principles
- Modular Design: Emphasize the clear separation of concerns by dividing functionalities into distinct modules.
- Hardware Abstraction: The library acts as an abstraction layer that decouples the application logic from the underlying hardware specifics.
- Use of Rust’s Module System: Having a lib.rs that re-exports the functionalities from individual modules (display, keyboard, backlight, grove).

##### Relevant Technologies and Frameworks
- Rust language and Cargo build system (indicated by Cargo.toml, rust-toolchain.toml, build.rs).
- Embedded systems concepts: Direct interfacing with GPIOs, I2C communications, and hardware initialization protocols typical in embedded Rust projects.
- Specific hardware: ST7789 (for LCD), 74HC138 (for keycode decoding), Grove I/F devices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Application (key_monitor Example)"]:::app
    LIB["Cardputer Library (crate)"]:::lib

    subgraph "Modules"
        D["Display Module"]:::module
        B["Backlight Module"]:::module
        K["Keyboard Module"]:::module
        G["Grove Module"]:::module
    end

    subgraph "Hardware Peripherals"
        ST["ST7789 Display"]:::hardware
        L["LCD Backlight"]:::hardware
        HC["74HC138 Key Decoder"]:::hardware
        GI["Grove I2C Interface"]:::hardware
    end

    subgraph "Build & Configuration"
        CARGO["Cargo.toml"]:::config
        BUILD["build.rs"]:::config
    end

    A -->|"uses"| LIB
    LIB --> D
    LIB --> B
    LIB --> K
    LIB --> G

    D -->|"initializes"| ST
    B -->|"controls"| L
    K -->|"decodes"| HC
    G -->|"interfaces"| GI

    CARGO -->|"builds"| LIB
    BUILD -->|"executes"| LIB

    click A "https://github.com/syurazo/cardputer/blob/master/examples/key_monitor.rs"
    click LIB "https://github.com/syurazo/cardputer/blob/master/src/lib.rs"
    click D "https://github.com/syurazo/cardputer/blob/master/src/display.rs"
    click B "https://github.com/syurazo/cardputer/blob/master/src/backlight.rs"
    click K "https://github.com/syurazo/cardputer/blob/master/src/keyboard.rs"
    click G "https://github.com/syurazo/cardputer/blob/master/src/grove.rs"
    click CARGO "https://github.com/syurazo/cardputer/blob/master/Cargo.toml"
    click BUILD "https://github.com/syurazo/cardputer/blob/master/build.rs"

    classDef app fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef lib fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef module fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef hardware fill:#CCDDCC,stroke:#333,stroke-width:2px;
    classDef config fill:#FFCCCC,stroke:#333,stroke-width:2px;
```
