Hardware-independent C++11 interfaces for microcontroller adapters and peripheral libraries.
This repository defines the interfaces that device-specific adapters implement to expose hardware through a common API. It contains contracts, not implementations.
It does not contain hardware definitions, register addresses or peripheral drivers.
- Hardware definitions describe a device.
- A device-specific adapter implements these interfaces using its hardware definitions.
- Peripheral libraries consume the interfaces without depending on a specific device.
Start with the Getting Started guide to implement an ADC interface, group it in an MCU class and construct it directly. A complete C++11 example is also available.
A device-specific adapter can provide an MCU class that groups its available peripherals. Applications construct it directly:
MCU mcu;
ADC& adc = mcu.adc();The MCU class and its accessors belong to the device-specific adapter, not this repository. No common MCU interface or creation helper is required.
See MCU composition for the recommended structure.
- GPIO
- ADC
- PWM
- Timer
- Serial
- SPI
- I2C
- EEPROM
- Watchdog
- External interrupts
- Analog comparator
- Global interrupts
- Clock
- Power management
- Reset
Optional hardware features are represented by separate interfaces. An adapter only implements an optional interface when the hardware supports that feature.
- C++11 or later.
- Header-only.
- No device-specific dependencies.
- No dynamic allocation requirement.
Add include/ to the compiler's include paths:
#include <adapter/adapter.hpp>Individual modules can be included separately:
#include <adapter/adc.hpp>
#include <adapter/gpio.hpp>Contracts use pure virtual functions. An adapter derives from the relevant interface and implements its required methods using override.
A class that omits a required method remains abstract. Adapters can verify that their concrete class is not abstract:
#include <type_traits>
static_assert(
!std::is_abstract<MyAdapter>::value,
"Adapter does not implement the complete interface."
);This checks interface conformance at compile time. It does not verify the functional correctness of the implementation.
API documentation is generated with Doxygen using Doxyfile.
See LICENSE.