NHAL Interface v0.5.0
Hardware Abstraction Layer Interface for Embedded Systems
|
The NHAL Interface is a pure C header-only component that aims to define hardware abstraction layer interfaces for embedded systems. This component provides no implementation - only interface definitions, types, and contracts that implementation layers must fulfill.
It's part of nexus-embedded-ecosystem ← You can find more documentation and references to other components here
My main goal is simply to provide a set of interfaces for myself, and ease the pain points I mentioned before. That said, if someone else finds it useful is most welcomed to use it, collaborate, ask for some functionality or interface not yet contemplated, etc.
The goals as an interface are the following:
The interface is built around the concept of "contexts" rather than direct peripheral addressing. Instead of passing bus numbers or channel IDs, all operations work with context structures that encapsulate:
All peripherals follow a the following lifecycle:
*_init()
)*_set_config()
) Operations will fail with appropriate error codes if attempted in wrong states. Why do I follow this pattern? Because depending on the platform, the initialization phase follows a different flow than the configuration step, and sometimes you may want to update peripheral configuration at runtime.
All operations return nhal_result_t
with standardized error categories:
NHAL_ERR_INVALID_ARG
, NHAL_ERR_INVALID_CONFIG
NHAL_ERR_NOT_INITIALIZED
, NHAL_ERR_NOT_CONFIGURED
, NHAL_ERR_BUSY
NHAL_ERR_TIMEOUT
, NHAL_ERR_HW_FAILURE
, NHAL_ERR_UNSUPPORTED
NHAL_ERR_NO_RESPONSE
, NHAL_ERR_TRANSMISSION_ERROR
NHAL_ERR_BUFFER_FULL
, NHAL_ERR_OUT_OF_MEMORY
The kind of errors the hal defines are up for debate and extension, of course.
nhal_i2c_master.h
- Read/write operationsnhal_i2c_transfer.h
- Complex transaction supportnhal_i2c_master_async.h
- Non-blocking operationsnhal_i2c_types.h
nhal_spi_master.h
- Blocking read/write/exchangenhal_spi_master_async.h
- DMA-based operationsnhal_spi_daisy_chain.h
- Multi-device chainingnhal_spi_types.h
nhal_uart_basic.h
- Synchronous read/writenhal_uart_async.h
- Buffered, non-blocking I/Onhal_uart_types.h
nhal_pin.h
- State control, interrupts, configurationnhal_pin_types.h
nhal_wdt.h
- Initialization, feeding, enable/disablenhal_wdt_types.h
nhal_common.h
- Result types, delays, common definitionsPublic interfaces expose only commonly-needed configuration parameters. Platform-specific configuration is handled through opaque impl_config
pointers, allowing implementations to extend functionality without interface changes.
Many peripherals support multiple operation modes:
All blocking operations accept timeout parameters (nhal_timeout_ms
) for predictable behavior in real-time systems.
The interface assumes:
This repository contains:
include/
** - Pure C header files defining hardware abstraction interfacesscripts/
** - West build system integration for the Nexus Ecosystemwest-commands.yml
- Command definitionsnexus_commands/
- Python command implementationstesting/
** - GoogleTest mock implementations for unit testingdocs-utils/
** - Doxygen configuration and build scriptsbuild-docs.sh
** - Automated documentation generationThis interface component only depends on std C headers - it consists entirely of headers files defining:
Include the appropriate headers for your peripheral needs:
Any implementation of these interfaces must:
impl_*
structures (Empty if not needed)