# basecamelectronics/sbgc32-serial-api architecture

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

- Interactive diagram: https://gitdiagram.com/basecamelectronics/sbgc32-serial-api
- Repository: https://github.com/basecamelectronics/sbgc32-serial-api

## Overview

This project is an open‐source C library designed to provide communication with SimpleBGC32 devices via a serial API. Its purpose is to simplify the integration of SBGC32 devices with a broad range of platforms (Arduino, STM32, Linux, and RTOS-based environments) by abstracting low‐level serial exchanges into a set of well‐organized core functions, command modules, and driver implementations.

##### Key components
a. Core Library ("serialAPI/core"): Contains the basic serial API kernel functions, including initialization, command processing, and low‐level functionalities.
b. Modules ("serialAPI/modules"): This folder is segmented by function with subdirectories for commands such as “adjvar”, “calib”, “eeprom”, “gimbalControl”, “imu”, “profiles”, “realtime”, and “service.” They encapsulate functionality related to specific command sets.
c. Drivers ("serialAPI/drivers"): Provides platform-specific low-level implementations. There are drivers for Arduino, Linux, and STM32 – these implement the actual communication routines needed to send commands to the SBGC32 device.
d. OS Glue ("serialAPI/os"): Contains abstraction layers for integration with different operating systems such as AzureRTOS, FreeRTOS, and Linux. This enables the library to be portable and adaptable to various RTOS or bare-metal conditions.
e. Configuration and Support Files: The configuration template (serialAPI_ConfigTemplate.h, to be renamed as serialAPI_Config.h) allows tailoring of internal library settings. Additionally, adjunct.h and the sbgc32.[ch] files tie together the functionality.
f. Examples (found in directories like examples/Arduino, examples/STM32, examples/Linux): These applications demonstrate how to integrate and use the library with actual hardware, serving as both documentation and practical usage models.
g. Documentation (in the doxygen folder): Contains configuration to generate full documentation for the library.

- Next, illustrate the “Serial API Library” as a central block which is internally composed of several layers:
- Layer on top the “Modules” (each represented as separate sub-components) which use the core for command processing and handling different command types.
- “OS Glue” layer that integrates with RTOS or Linux environment features for multi-threading, synchronization, or task management.
- The user’s application calls the library’s initialization (e.g., SBGC32_Init) and command routines.
- The Core and Modules prepare commands.
- Drivers and OS Glue manage the physical data transfer to/from the SBGC32 Device.

##### Architectural patterns and design principles to highlight
- Separation of Concerns: The design clearly splits responsibilities across core processing, command modules, hardware drivers, and OS-specific adaptations.
- Portability/Modularity: The driver implementations and OS glue guarantee that the same API can be used independent of the underlying hardware or OS.
- Configurability: The use of a configuration header (serialAPI_Config.h) makes the internal operations customizable for different device resource constraints.
- Reusability: The organized structure with examples makes it easy for developers to pick a ready-made solution or tailor one for their environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client Application"]:::client

    subgraph "Serial API Library"
        C["Core Kernel"]:::core
        M["Modules"]:::modules
        D["Drivers"]:::drivers
        O["OS Glue"]:::osglue
    end

    S["SBGC32 Device"]:::device

    CS["Configuration & Support Files"]:::config
    subgraph "Examples"
        EXA["Arduino Example"]:::example
        EXS["STM32 Example"]:::example
        EXL["Linux Example"]:::example
    end
    Doc["Documentation"]:::doc

    A -->|"calls_API"| C
    M -->|"uses_Core"| C
    M -->|"sends_cmds_to"| D
    O -->|"assists_Drivers"| D
    D -->|"sends_to"| S
    O -->|"handles_os_tasks"| S
    C -->|"configured_by"| CS
    M -->|"configured_by"| CS
    A -->|"integrates_with"| EXA
    A -->|"integrates_with"| EXS
    A -->|"integrates_with"| EXL
    A -->|"refers_to"| Doc

    click C "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/serialAPI/core"
    click M "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/serialAPI/modules"
    click D "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/serialAPI/drivers"
    click O "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/serialAPI/os"
    click CS "https://github.com/basecamelectronics/sbgc32-serial-api/blob/master/serialAPI/serialAPI_ConfigTemplate.h"
    click EXA "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/examples/Arduino"
    click EXS "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/examples/STM32"
    click EXL "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/examples/Linux"
    click Doc "https://github.com/basecamelectronics/sbgc32-serial-api/tree/master/doxygen"

    classDef client fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef modules fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef drivers fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef osglue fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef device fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef config fill:#F5DEB3,stroke:#000,stroke-width:2px;
    classDef example fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef doc fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
