# berknylm/embedlink architecture

> Architecture diagram of the GitHub repository berknylm/embedlink, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/berknylm/embedlink
- Repository: https://github.com/berknylm/embedlink

## Overview

1. **What this repo is**
   EmbedLink is an STM32 embedded firmware stack built around RTOS-compatible serial communication and background processing of sensor/GPS data. The codebase is centered on a quadcopter/robotics use case: reading hardware sensors, estimating state, running control modes, and exposing communication links for configuration/telemetry.

2. **Top-level layering**
   The repository is organized in a clear hardware-to-application stack:
   - **Src/Hal**: MCU peripheral abstraction
   - **Lib**: vendor chip libraries for specific sensors/radios/GPS parsers
   - **Src/Drivers**: device-facing drivers that wrap the libraries into uniform subsystem APIs
   - **Src/Modules**: reusable functional building blocks like ESC, RC, battery, LEDs, telemetry
   - **Src/Application**: quadcopter-specific coordination, control modes, and communication logic
   - **Src/Codex**: shared math, event, queue, stream, and navigation utilities plus the program entry point

3. **Hardware abstraction boundary**
   `Src/Hal` contains the low-level interfaces for GPIO, I2C, SPI, UART, USB, ADC, PWM, IRQ, and RTOS integration. This is the boundary between the firmware and the STM32 peripherals. Everything above this layer depends on these abstractions rather than talking to registers directly.

4. **Device libraries and sensor support**
   `Lib/` contains chip-specific implementations for common embedded parts: IMUs (`bmi08`, `bno055`, `icm20948`, `mpu6500`), barometers (`bmp3`, `bmp5`, `ms5611`, `icp20100`), GPS/NMEA/UBlox, radio (`rf24`), and power sensing (`ina219`). These are not the application logic; they are the vendor/protocol-level drivers consumed by the higher layers.

5. **Unified driver layer**
   `Src/Drivers` normalizes those vendor libraries into subsystem interfaces:
   - **Sensor**: specific sensor adapters such as BMI088, BMP388/BMP581, BNO055, HMC5883L, ICM20948, ICP20100, MPU6500
   - **Navigator**: GPS-focused adapters for Neo-M8N and ZED-F9P
   - **Estimator**: complementary and Kalman-filter-based state estimation
   - **Telemetry**: radio transport adapters for RF24 and RF52
   - **Memory**: persistent storage, including external EEPROM support
   This layer is where heterogeneous hardware gets converted into a consistent internal API.

6. **State estimation and navigation flow**
   Sensor data and navigation data are processed in the estimator/navigation path. The presence of `estimator_cf` and `estimator_kf`, plus `navigation`, `kinematics`, and math utilities in `Src/Codex`, indicates a pipeline that turns raw sensor/GPS samples into fused attitude, position, velocity, and related kinematic state. This is one of the core architectural flows in the repo.

7. **Flight/control application layer**
   `Src/Application/QMode` contains control strategies:
   - `control_attitude`
   - `control_height`
   - `control_navigation`
   - `quadmode`
   This is the decision layer that turns estimated state and operator commands into control outputs. It is quadcopter-specific and sits above the generic drivers/estimator stack.

8. **Vehicle coordination and configuration**
   `Src/Application/quadcopter.*`, `quadcal.*`, and `quadconfig.h` appear to hold vehicle-level orchestration, calibration, and compile-time tuning. This layer likely binds together sensors, estimation, RC input, mode selection, and output mixing for the actual aircraft configuration.

9. **Operator communication and command handling**
   `Src/Application/QCom` (`rccom`, `uavcom`, `uavexe`) is the command/communication interface used for serial exchange with external tools or controllers. Combined with the README’s emphasis on serial communication, this is likely the primary user-facing control boundary for configuration, diagnostics, and command execution.

10. **Reusable runtime/core utilities**
   `Src/Codex` is a shared utility/runtime layer containing:
   - event, queue, list, and stream primitives
   - matrix and math types/functions
   - kinematics and navigation helpers
   - `executer` and `main`
   This looks like the framework core that underpins asynchronous processing, message passing, and math-heavy computations.

11. **Support modules for the platform**
   `Src/Modules` contains operational subsystems that are not directly part of the flight control loop but are essential to the product:
   - **Battery** monitoring
   - **Esc** motor output
   - **RC** receiver interface
   - **Signal** LEDs and LED sequencing
   - **Debug** timing/watch utilities
   - **Northlib** internal communication/protocol support
   These modules connect the high-level vehicle logic to real-world peripherals and user feedback.

12. **Main data paths to draw**
   The most important architecture flows are:
   - **Sensors/GPS → Drivers → Estimator/Navigation → QMode control → ESC/PWM**
   - **RC / serial commands → QCom / RC modules → mode selection and parameters**
   - **Telemetry/USB/UART → external host or radio link**
   - **Battery/diagnostics → signaling and safety-related behavior**
   These are the paths most worth highlighting in a diagram.

13. **Concurrency and runtime**
   The repository is explicitly RTOS-aware, so the system is likely split into background tasks or event-driven loops rather than a single blocking control loop. The presence of queues, events, streams, IRQ handling, and separate subsystem modules suggests asynchronous acquisition, estimation, communication, and actuation.

14. **How to frame the architecture**
   For diagramming, treat this repo as an **embedded UAV firmware platform** with four vertical slices: hardware abstraction, device drivers, core computation, and application/control logic. The key boundary is between reusable platform code and the quadcopter-specific application layer, with telemetry/RC/serial forming the external interaction boundary.

Main entry points: [`Src/Application/quadcopter.c`](https://github.com/berknylm/embedlink/blob/main/Src/Application/quadcopter.c) (Quadcopter), [`Src/Hal/gpio.c`](https://github.com/berknylm/embedlink/blob/main/Src/Hal/gpio.c) (HAL IO), [`Lib/ublox/ublox.c`](https://github.com/berknylm/embedlink/blob/main/Lib/ublox/ublox.c) (GPS & radio), [`Src/Drivers/Sensor/sensor.c`](https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Sensor/sensor.c) (Sensor drv)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hal["HAL"]
  node_hal_io["HAL IO<br/>mcu abstraction<br/>[gpio.c]"]
end

subgraph group_libs["Libraries"]
  node_lib_imu["IMU libs<br/>vendor sensor libs<br/>[bmi08a.c]"]
  node_lib_baro["Baro libs<br/>vendor sensor libs<br/>[bmp3.c]"]
  node_lib_gpsradio["GPS & radio<br/>protocol libs<br/>[ublox.c]"]
  node_lib_power["Power libs<br/>chip libs<br/>[ina219.c]"]
end

subgraph group_drivers["Drivers"]
  node_drv_sensor["Sensor drv<br/>sensor adapters<br/>[sensor.c]"]
  node_drv_nav["Navigator drv<br/>gps adapters<br/>[navigator.c]"]
  node_drv_est["Estimator drv<br/>state fusion<br/>[estimator.c]"]
  node_drv_tel["Telemetry drv<br/>link adapters<br/>[telemetry.c]"]
  node_drv_mem["Memory drv<br/>storage adapter<br/>[memory.c]"]
end

subgraph group_core["Core"]
  node_core_main["Entry point<br/>startup<br/>[main.c]"]
  node_core_exec["Executer<br/>runtime loop<br/>[executer.c]"]
  node_core_math["Math core<br/>math & kinematics<br/>[kinematics.c]"]
  node_core_event["Events<br/>queue primitives<br/>[xevent.c]"]
end

subgraph group_modules["Modules"]
  node_mod_rc["RC module<br/>receiver input<br/>[rc_interface.c]"]
  node_mod_esc["ESC module<br/>motor output<br/>[esc.c]"]
  node_mod_batt["Battery<br/>power monitor<br/>[battery.c]"]
  node_mod_sig["Signals<br/>led status<br/>[ledseq.c]"]
  node_mod_north["Northlib<br/>internal comms<br/>[northcom.c]"]
end

subgraph group_app["Application"]
  node_app_quad["Quadcopter<br/>vehicle orchestration<br/>[quadcopter.c]"]
  node_app_mode["QMode<br/>control modes<br/>[quadmode.c]"]
  node_app_com["QCom<br/>command link<br/>[uavcom.c]"]
end

node_core_main -->|"starts runtime"| node_core_exec
node_core_exec -->|"orchestrates"| node_app_quad
node_hal_io -->|"bus access"| node_lib_imu
node_hal_io -->|"bus access"| node_lib_baro
node_hal_io -->|"serial/spi"| node_lib_gpsradio
node_hal_io -->|"i2c/adc"| node_lib_power
node_lib_imu -->|"feeds"| node_drv_sensor
node_lib_baro -->|"feeds"| node_drv_sensor
node_lib_gpsradio -->|"feeds"| node_drv_nav
node_lib_gpsradio -->|"feeds"| node_drv_tel
node_drv_sensor -->|"state input"| node_drv_est
node_drv_nav -->|"navigation data"| node_core_math
node_core_math -->|"fusion math"| node_drv_est
node_drv_est -->|"estimated state"| node_app_mode
node_mod_rc -->|"operator input"| node_app_com
node_app_com -->|"configures"| node_app_quad
node_app_quad -->|"selects mode"| node_app_mode
node_app_mode -->|"actuates"| node_mod_esc
node_mod_batt -->|"safety input"| node_app_quad
node_mod_sig -->|"status output"| node_app_quad
node_mod_north -->|"internal protocol"| node_app_com
node_drv_mem -->|"persistent state"| node_app_quad

click node_hal_io "https://github.com/berknylm/embedlink/blob/main/Src/Hal/gpio.c"
click node_lib_imu "https://github.com/berknylm/embedlink/blob/main/Lib/bmi08/bmi08a.c"
click node_lib_baro "https://github.com/berknylm/embedlink/blob/main/Lib/bmp3/bmp3.c"
click node_lib_gpsradio "https://github.com/berknylm/embedlink/blob/main/Lib/ublox/ublox.c"
click node_lib_power "https://github.com/berknylm/embedlink/blob/main/Lib/ina219/ina219.c"
click node_drv_sensor "https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Sensor/sensor.c"
click node_drv_nav "https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Navigator/navigator.c"
click node_drv_est "https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Estimator/estimator.c"
click node_drv_tel "https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Telemetry/telemetry.c"
click node_drv_mem "https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Memory/memory.c"
click node_core_main "https://github.com/berknylm/embedlink/blob/main/Src/Codex/main.c"
click node_core_exec "https://github.com/berknylm/embedlink/blob/main/Src/Codex/executer.c"
click node_core_math "https://github.com/berknylm/embedlink/blob/main/Src/Codex/kinematics.c"
click node_core_event "https://github.com/berknylm/embedlink/blob/main/Src/Codex/xevent.c"
click node_mod_rc "https://github.com/berknylm/embedlink/blob/main/Src/Modules/RC/rc_interface.c"
click node_mod_esc "https://github.com/berknylm/embedlink/blob/main/Src/Modules/Esc/esc.c"
click node_mod_batt "https://github.com/berknylm/embedlink/blob/main/Src/Modules/Battery/battery.c"
click node_mod_sig "https://github.com/berknylm/embedlink/blob/main/Src/Modules/Signal/ledseq.c"
click node_mod_north "https://github.com/berknylm/embedlink/blob/main/Src/Modules/Northlib/northcom.c"
click node_app_quad "https://github.com/berknylm/embedlink/blob/main/Src/Application/quadcopter.c"
click node_app_mode "https://github.com/berknylm/embedlink/blob/main/Src/Application/QMode/quadmode.c"
click node_app_com "https://github.com/berknylm/embedlink/blob/main/Src/Application/QCom/uavcom.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_hal_io toneBlue
class node_lib_imu,node_lib_baro,node_lib_gpsradio,node_lib_power toneAmber
class node_drv_sensor,node_drv_nav,node_drv_est,node_drv_tel,node_drv_mem toneMint
class node_core_main,node_core_exec,node_core_math,node_core_event toneRose
class node_mod_rc,node_mod_esc,node_mod_batt,node_mod_sig,node_mod_north toneIndigo
class node_app_quad,node_app_mode,node_app_com toneTeal
```

## Components

### HAL

MCU peripheral and RTOS boundary

- [HAL IO](https://github.com/berknylm/embedlink/blob/main/Src/Hal/gpio.c): mcu abstraction · GPIO, UART, SPI, I2C, ADC, PWM, USB, IRQ, and RTOS-facing peripheral layer · `Src/Hal/gpio.c`

### Libraries

Vendor sensor, radio, and protocol code

- [IMU libs](https://github.com/berknylm/embedlink/blob/main/Lib/bmi08/bmi08a.c): vendor sensor libs · Raw device libraries for inertial sensors and motion chips · `Lib/bmi08/bmi08a.c`
- [Baro libs](https://github.com/berknylm/embedlink/blob/main/Lib/bmp3/bmp3.c): vendor sensor libs · Pressure and altitude sensor libraries · `Lib/bmp3/bmp3.c`
- [GPS & radio](https://github.com/berknylm/embedlink/blob/main/Lib/ublox/ublox.c): protocol libs · NMEA/Ublox GPS parsing plus RF24 radio support · `Lib/ublox/ublox.c`
- [Power libs](https://github.com/berknylm/embedlink/blob/main/Lib/ina219/ina219.c): chip libs · Power sensing and other peripheral vendor drivers · `Lib/ina219/ina219.c`

### Drivers

Unified hardware adapters

- [Sensor drv](https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Sensor/sensor.c): sensor adapters · Normalizes IMU, barometer, and compass hardware into subsystem sensor APIs · `Src/Drivers/Sensor/sensor.c`
- [Navigator drv](https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Navigator/navigator.c): gps adapters · GPS receiver adapters and navigation input normalization · `Src/Drivers/Navigator/navigator.c`
- [Estimator drv](https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Estimator/estimator.c): state fusion · Complementary and Kalman estimation wrappers · `Src/Drivers/Estimator/estimator.c`
- [Telemetry drv](https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Telemetry/telemetry.c): link adapters · Radio transport adapters for telemetry links · `Src/Drivers/Telemetry/telemetry.c`
- [Memory drv](https://github.com/berknylm/embedlink/blob/main/Src/Drivers/Memory/memory.c): storage adapter · Persistent storage and external EEPROM support · `Src/Drivers/Memory/memory.c`

### Core

Shared runtime, math, and program entry

- [Entry point](https://github.com/berknylm/embedlink/blob/main/Src/Codex/main.c): startup · Program entry and top-level boot orchestration · `Src/Codex/main.c`
- [Executer](https://github.com/berknylm/embedlink/blob/main/Src/Codex/executer.c): runtime loop · Asynchronous task and message execution core · `Src/Codex/executer.c`
- [Math core](https://github.com/berknylm/embedlink/blob/main/Src/Codex/kinematics.c): math & kinematics · Matrices, kinematics, and navigation support functions · `Src/Codex/kinematics.c`
- [Events](https://github.com/berknylm/embedlink/blob/main/Src/Codex/xevent.c): queue primitives · Events, queues, lists, and streams used for background processing · `Src/Codex/xevent.c`

### Modules

Reusable platform subsystems

- [RC module](https://github.com/berknylm/embedlink/blob/main/Src/Modules/RC/rc_interface.c): receiver input · Radio control receiver interface and signal handling · `Src/Modules/RC/rc_interface.c`
- [ESC module](https://github.com/berknylm/embedlink/blob/main/Src/Modules/Esc/esc.c): motor output · Motor/ESC actuation layer · `Src/Modules/Esc/esc.c`
- [Battery](https://github.com/berknylm/embedlink/blob/main/Src/Modules/Battery/battery.c): power monitor · Battery sensing and power-state monitoring · `Src/Modules/Battery/battery.c`
- [Signals](https://github.com/berknylm/embedlink/blob/main/Src/Modules/Signal/ledseq.c): led status · LEDs and blink sequencing for user feedback · `Src/Modules/Signal/ledseq.c`
- [Northlib](https://github.com/berknylm/embedlink/blob/main/Src/Modules/Northlib/northcom.c): internal comms · Internal communication and protocol support utilities · `Src/Modules/Northlib/northcom.c`

### Application

Quadcopter-specific coordination and control

- [Quadcopter](https://github.com/berknylm/embedlink/blob/main/Src/Application/quadcopter.c): vehicle orchestration · Vehicle-level integration, calibration, and configuration · `Src/Application/quadcopter.c`
- [QMode](https://github.com/berknylm/embedlink/blob/main/Src/Application/QMode/quadmode.c): control modes · Attitude, height, and navigation control strategies · `Src/Application/QMode/quadmode.c`
- [QCom](https://github.com/berknylm/embedlink/blob/main/Src/Application/QCom/uavcom.c): command link · Serial command, configuration, and operator communication · `Src/Application/QCom/uavcom.c`

## Connections

- Entry point → Executer: starts runtime · Boot entry hands control to the background execution core
- Executer → Quadcopter: orchestrates · Runtime dispatch drives the vehicle application
- HAL IO → IMU libs: bus access · Vendor sensor libraries depend on MCU peripheral access
- HAL IO → Baro libs: bus access · Pressure sensors are accessed through HAL buses
- HAL IO → GPS & radio: serial/spi · GPS and radio libraries use UART/SPI and timing support
- HAL IO → Power libs: i2c/adc · Power sensing libraries rely on HAL peripherals
- IMU libs → Sensor drv: feeds · Raw IMU libraries are wrapped by sensor adapters
- Baro libs → Sensor drv: feeds · Barometer libraries are wrapped by sensor adapters
- GPS & radio → Navigator drv: feeds · GPS parsing and receiver libraries feed navigation adapters
- GPS & radio → Telemetry drv: feeds · Radio protocol code supports telemetry transport
- Sensor drv → Estimator drv: state input · Sensor outputs are consumed by state estimation
- Navigator drv → Math core: navigation data · GPS/navigation information flows into shared math and kinematics
- Math core → Estimator drv: fusion math · Kinematics and math utilities support estimation
- Estimator drv → QMode: estimated state · Fused attitude and motion state drives control modes
- RC module → QCom: operator input · Receiver input and command handling meet at the communication boundary
- QCom → Quadcopter: configures · Command interface configures and controls the vehicle layer
- Quadcopter → QMode: selects mode · Vehicle orchestration selects and wires active control mode
- QMode → ESC module: actuates · Control outputs are converted to motor/ESC commands
- Battery → Quadcopter: safety input · Battery state influences vehicle orchestration and safety behavior
- Signals → Quadcopter: status output · LED signaling reflects system and flight status
- Northlib → QCom: internal protocol · Northlib provides shared communication plumbing for the command layer
- Memory drv → Quadcopter: persistent state · Stored parameters and calibration data support the vehicle layer
