# wyatt-mattas/bmi323-rs architecture

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

- Interactive diagram: https://gitdiagram.com/wyatt-mattas/bmi323-rs
- Repository: https://github.com/wyatt-mattas/bmi323-rs

## Overview

##### Main Components
- BMI323 Driver Core: Represent the central library (located in src/lib.rs) that binds together all the driver functionality.
- Device & Interface Modules: Show the modules that manage low-level operations – notably, the device.rs (likely handling initialization and device-specific logic), interface.rs (defining communication methods), registers.rs (abstraction of sensor registers), sensor_data.rs (handling raw and processed sensor data), and types.rs (defining data types and configurations).
- Configuration & Initialization: Include the initialization flow (init() method in the device abstraction) and configuration of sensor parameters (accelerometer and gyroscope via builder patterns in AccelConfig and GyroConfig).
- Examples: Diagrammatically illustrate the two example implementations:
- embassy-stm32-implementation: Likely demonstrating integration with the Embassy ecosystem on STM32 boards.
- peripheral-crate-implementation: Illustrating another approach (possibly using direct hardware abstraction) including a memory.x linker script and custom build.rs.
- Testing: Show that the project incorporates a test suite with both integration and unit tests (located in the tests directory).

##### Relationships and Data Flow
- Testing and Examples Integration: Represent examples as distinct nodes that make use of the driver core, demonstrating how the configuration and reading functions are utilized. Similarly, include a node for "Tests" that validate various components (unit and integration tests).

##### Architectural Patterns & Design Principles
- Modularity: Emphasize how the project is divided into distinct modules, each handling a separate concern (communication, device state, register mapping, and sensor data processing).
- Abstraction Layers: Illustrate the use of abstraction (via traits or wrapper interfaces) that decouples hardware-specific details from generic driver logic.
- Builder Pattern: Note the use of builder patterns in configuration structures (for accelerometer and gyroscope settings) ensuring that configurations are validated and set in a controlled manner.
- Dependency Injection: Point out that the embedded_hal (and possibly other dependency injection patterns) allow the driver to be hardware-agnostic.

##### Relevant Technologies, Frameworks, or Libraries
- Rust and Cargo: Indicate that the project is built using Rust (Cargo.toml, Cargo.lock).
- Embedded HAL: This is a key external dependency for handling I2C/SPI abstractions.
- Example Integrations: Reference the embassy-stm32 and peripheral crate examples, which show real-world hardware integrations and how the driver can be practically used.

##### Putting It All Together
- Follow that with the "BMI323 Driver Core" that interacts with the HAL and consists of multiple internal modules (device, interface, registers, sensor_data, types).

## Diagram (Mermaid)

```mermaid
flowchart TD
    extHw["External Hardware\n(Microcontroller)"]:::hardware
    hal["Embedded HAL\n(I2C/SPI Abstraction)"]:::hal
    extHw -->|"I2C/SPI"| hal

    subgraph "BMI323 Driver Core"
        direction TB
        coreInterface["Driver API"]:::core
        config["Configuration\n(AccelConfig & GyroConfig)"]:::module
        device["Device Module\n(Initialization & Abstraction)"]:::module
        interface["Interface Module\n(Communication Methods)"]:::module
        registers["Registers Module\n(Sensor Register Abstraction)"]:::module
        sensorData["Sensor Data Module\n(Raw/Processed Data)"]:::module
        types["Types Module\n(Data Types & Configurations)"]:::module

        coreInterface --> config
        config --> device
        device --> sensorData
        device --> interface
        interface --> registers
        types --- device
        types --- sensorData
        types --- config
    end

    hal --> coreInterface

    coreInterface --> embassy["Embassy STM32 Example"]:::example
    coreInterface --> peripheral["Peripheral Crate Example"]:::example
    coreInterface --> tests["Tests Suite"]:::test

    click coreInterface "https://github.com/wyatt-mattas/bmi323-rs/blob/main/src/lib.rs"
    click device "https://github.com/wyatt-mattas/bmi323-rs/blob/main/src/device.rs"
    click interface "https://github.com/wyatt-mattas/bmi323-rs/blob/main/src/interface.rs"
    click registers "https://github.com/wyatt-mattas/bmi323-rs/blob/main/src/registers.rs"
    click sensorData "https://github.com/wyatt-mattas/bmi323-rs/blob/main/src/sensor_data.rs"
    click types "https://github.com/wyatt-mattas/bmi323-rs/blob/main/src/types.rs"
    click embassy "https://github.com/wyatt-mattas/bmi323-rs/tree/main/examples/embassy-stm32-implementation"
    click peripheral "https://github.com/wyatt-mattas/bmi323-rs/tree/main/examples/peripheral-crate-implementation"
    click tests "https://github.com/wyatt-mattas/bmi323-rs/tree/main/tests"

    classDef hardware fill:#ffcccc,stroke:#900,stroke-width:2px;
    classDef hal fill:#ffebcc,stroke:#b8860b,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#090,stroke-width:2px;
    classDef module fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef example fill:#e6ccff,stroke:#800080,stroke-width:2px;
    classDef test fill:#d6d8db,stroke:#212529,stroke-width:2px;
```
