Skip to content
@mhaa-arch

Modular Hardware Abstraction Architecture

Modular hardware abstraction for portable embedded software.

Modular Hardware Abstraction Architecture

Architecture and Core Contracts Hardware Mapping and MCU Adapters MCU Composition and Integration Cross-MCU Validation

Note

Looking for the Brazilian Portuguese version? Read it here.

Modular Hardware Abstraction Architecture (MHAA) is a C++ architectural study for embedded software. It explores a layered and modular approach to hardware abstraction and source-level portability across compatible microcontrollers.

The project studies how established architectural concepts, C++ templates, and interfaces with pure virtual functions can work together to create reusable peripheral APIs while keeping hardware-specific details explicit.

Objectives

  • Layered hardware abstraction: organize software from hardware-specific definitions and MCU adapters through Peripheral Contracts and reusable Core modules to application-level APIs.
  • Microcontroller compatibility: explore source-level portability between microcontrollers that provide compatible capabilities.
  • Reusable components: keep common peripheral functionality in independent Core modules with clearly defined Peripheral Contracts.
  • Hybrid C++ abstraction: combine templates and pure virtual interfaces, using compile-time specialization and runtime polymorphism where each is appropriate.
  • Clear dependencies: separate hardware-specific implementation from reusable functionality and make component composition explicit.

Architecture

graph TD
    APP[Application] --> COMPOSITION[MCU Composition Layer]
    COMPOSITION --> CORE[Core]
    COMPOSITION --> ADAPTER[MCU Adapter]
    CORE --> CONTRACT[Peripheral Contract]
    ADAPTER --> CONTRACT
    ADAPTER --> HW[Hardware Definitions]
Loading

Note

The arrows represent code dependencies, not a sequence of runtime steps. The Core and the MCU Adapter both depend on the same Peripheral Contract. The Peripheral Contract defines an abstraction boundary; it is not a separate object that every operation must pass through.

Components

Component Responsibility
Application Contains firmware logic and uses the available Core APIs.
MCU Composition Layer Acts as the Composition Root, selecting the target MCU, instantiating the required Core modules and MCU Adapters, and connecting their dependencies to compose the MCU interface exposed to the application.
Core Provides reusable peripheral operations without depending on MCU registers.
Peripheral Contract Defines the interface and expected behavior for a peripheral's implementations.
MCU Adapters Implement Peripheral Contracts for a specific microcontroller.
Hardware Definitions Describe hardware-specific registers, pins, mappings, and capabilities.

Design Foundations

MHAA combines six established architectural concepts:

Concept Role in MHAA
Layered Architecture Separates application logic, composition, reusable functionality, Peripheral Contracts, and hardware-specific code.
Ports and Adapters Uses Peripheral Contracts as ports and MCU-specific implementations as adapters.
SOLID Guides responsibility boundaries, interface design, substitutability, and dependency direction.
Hardware Abstraction Layer (HAL) Provides consistent APIs for hardware capabilities supported by each target.
Composition Root Places target MCU selection and dependency composition in the MCU Composition Layer.
Modular Architecture Organizes functionality into independent components, including separate Core and Peripheral Contract modules.

These are established practices. MHAA studies how they can be combined and applied to embedded C++ software.

Implementation and Validation

The project already provides basic Core modules and their corresponding Peripheral Contracts for common peripheral capabilities.

Development is currently focused on mapping the hardware characteristics of selected microcontrollers and implementing their corresponding MCU Adapters.

This stage involves identifying registers, pins, mappings, and hardware-specific capabilities for each microcontroller, while developing adapters that implement the Peripheral Contracts and connect reusable Core functionality to the corresponding hardware.

After this stage, the next objective will be to integrate the components through the MCU Composition Layer and proceed with architectural validation across the following planned targets:

  • ATmega328P
  • ATmega2560
  • STM32
  • RP2040
  • ESP32

Important

These are the planned targets for development and validation. Including a platform in this list does not mean that its adapter or complete hardware support has already been implemented.

Design Priorities

Architectural clarity and source-level portability guide the design.

MHAA explores a hybrid approach to C++ abstraction:

  • Templates provide compile-time specialization where it is useful.
  • Pure virtual interfaces define Peripheral Contracts and allow implementations to be substituted.
  • Core modules use these abstractions to keep reusable peripheral behavior independent of a specific MCU.

Memory usage and runtime overhead remain relevant design considerations. However, avoiding object-oriented design or virtual dispatch is not an absolute goal. The project evaluates these trade-offs in the context of clarity, modularity, and portability.

Pinned Loading

  1. gpio gpio Public

    MHAA core providing reusable operations for general purpose digital input and output.

    C++

  2. adc adc Public

    MHAA core providing reusable operations for analog to digital conversion.

    C++

  3. eeprom eeprom Public

    MHAA core providing reusable operations for EEPROM memory access.

    C++

  4. pwm pwm Public

    MHAA core providing reusable operations for pulse width modulation.

    C++

  5. serial serial Public

    MHAA core providing reusable operations for serial communication.

    C++

  6. timer timer Public

    MHAA core providing reusable operations for timer and counter management.

    C++

Repositories

Showing 10 of 31 repositories

Top languages

Loading…

Most used topics

Loading…