# sandeepmistry/arduino-nrf5 architecture

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

- Interactive diagram: https://gitdiagram.com/sandeepmistry/arduino-nrf5
- Repository: https://github.com/sandeepmistry/arduino-nrf5

## Overview

##### Main Components

a. Hardware Layer:
- nRF5 Microcontroller (nRF51/nRF52/nRF52833)
- External Components (32 kHz crystal - optional)
- Hardware Interfaces (SPI, I2C/Wire, UART)

b. Software Stack:
- Nordic SoftDevice Layer (S110/S130/S132)
- Arduino Core Layer
- User Application Layer

##### Key Architectural Elements

a. Core Components (cores/nRF5/):
- Base Arduino Classes (Print, Stream, etc.)
- Hardware Abstraction Layer
- Core Utilities (WMath, WString, etc.)

b. Variant Support (variants/):
- Board-specific configurations
- Pin mappings
- Hardware definitions

c. Libraries (libraries/):
- SPI Implementation
- Wire (I2C) Implementation

d. Nordic SDK Components (cores/nRF5/SDK/):
- Device Definitions
- Driver Layer
- CMSIS Support
- Toolchain Support

**[User Arduino Sketch]**
- ↓
**[Arduino API Layer]**
- ↓
**[Arduino Core Implementation]**
- ↙     ↓    ↘
**[SPI]  [Wire]  [UART]**
- ↓
**[Hardware Abstraction Layer]**
- ↓
**[Nordic SoftDevice (Optional)]**
- ↓
**[Nordic SDK Components]**
- ↓
**[nRF5 Hardware]**

##### Important Relationships

a. Compilation Flow:
- Toolchain integration (gcc-arm-embedded)
- Build process flow

b. Programming Flow:
- Programming interfaces (J-Link, ST-Link V2, CMSIS-DAP)
- SoftDevice flashing path

c. Hardware Interfaces:
- Variant-specific pin configurations
- Peripheral connections

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User_Layer
        UserSketch[User Arduino Sketch]:::user
    end

    subgraph Arduino_Core
        ArduinoAPI[Arduino API Layer]:::arduino
        CoreImpl[Arduino Core Implementation]:::arduino
        BaseClasses[Base Arduino Classes]:::arduino
        CoreUtils[Core Utilities]:::arduino
    end

    subgraph Hardware_Interfaces
        SPI[SPI Interface]:::interface
        Wire[I2C/Wire Interface]:::interface
        UART[UART Interface]:::interface
    end

    subgraph HAL_Layer
        HAL[Hardware Abstraction Layer]:::hal
    end

    subgraph Nordic_Layer
        SoftDevice[Nordic SoftDevice]:::nordic
        subgraph SDK_Components
            DeviceDefs[Device Definitions]:::nordic
            DriverLayer[Driver Layer]:::nordic
            CMSIS[CMSIS Support]:::nordic
            Toolchain[Toolchain Support]:::nordic
        end
    end

    subgraph Hardware_Layer
        nRF5[nRF5 Microcontroller]:::hardware
        Crystal[32kHz Crystal]:::hardware
    end

    subgraph Variant_Support
        BoardConfig[Board Configurations]:::variant
        PinMappings[Pin Mappings]:::variant
        HWDefs[Hardware Definitions]:::variant
    end

    %% Relationships
    UserSketch --> ArduinoAPI
    ArduinoAPI --> CoreImpl
    CoreImpl --> BaseClasses
    CoreImpl --> CoreUtils
    CoreImpl --> |Interfaces| Hardware_Interfaces
    SPI & Wire & UART --> HAL
    HAL --> SoftDevice
    SoftDevice --> SDK_Components
    SDK_Components --> nRF5
    nRF5 --- Crystal
    BoardConfig --> HAL
    PinMappings --> HAL
    HWDefs --> HAL

    %% Click Events
    click BaseClasses "https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/Arduino.h"
    click CoreUtils "https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/WMath.cpp"
    click HAL "https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/wiring_digital.h"
    click SPI "https://github.com/sandeepmistry/arduino-nRF5/blob/master/libraries/SPI/SPI.h"
    click Wire "https://github.com/sandeepmistry/arduino-nRF5/blob/master/libraries/Wire/Wire.h"
    click UART "https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/Uart.h"
    click DeviceDefs "https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/SDK/components/device/nrf.h"
    click DriverLayer "https://github.com/sandeepmistry/arduino-nRF5/tree/master/cores/nRF5/SDK/components/drivers_nrf/"
    click CMSIS "https://github.com/sandeepmistry/arduino-nRF5/tree/master/cores/nRF5/SDK/components/toolchain/CMSIS/"
    click Toolchain "https://github.com/sandeepmistry/arduino-nRF5/tree/master/cores/nRF5/SDK/components/toolchain/gcc/"
    click BoardConfig "https://github.com/sandeepmistry/arduino-nRF5/tree/master/variants/"

    %% Styles
    classDef user fill:#4287f5,stroke:#333,stroke-width:2px
    classDef arduino fill:#90EE90,stroke:#333,stroke-width:2px
    classDef interface fill:#FFD700,stroke:#333,stroke-width:2px
    classDef hal fill:#FFA500,stroke:#333,stroke-width:2px
    classDef nordic fill:#FF6B6B,stroke:#333,stroke-width:2px
    classDef hardware fill:#808080,stroke:#333,stroke-width:2px
    classDef variant fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        UserLayer[User Layer]:::user
        ArduinoLayer[Arduino Layer]:::arduino
        InterfaceLayer[Interface Layer]:::interface
        HALLayer[HAL Layer]:::hal
        NordicLayer[Nordic Layer]:::nordic
        HWLayer[Hardware Layer]:::hardware
        VariantLayer[Variant Layer]:::variant
    end
```
