Skip to content

Quickstart

Select a board, include one header and read its pin map, in about a dozen lines.

1. Add the repository

Most projects get it through hf-core-drivers as internal/hf-pincfg. On its own:

git submodule add https://github.com/hardfoc/hf-pincfg.git external/hf-pincfg

2. Select the board

Define exactly one board macro for every translation unit that includes the header, normally in the HAL's CMakeLists.txt:

target_include_directories(my_hal PUBLIC external/hf-pincfg/src)
target_compile_definitions(my_hal PUBLIC HARDFOC_BOARD_VORTEX_V1=1)

Without one, the selector stops the build with No supported board variant defined!.

3. Read the map

tests/docs/quickstart.cpp
#include "hf_functional_pin_config.hpp"  // the build defines one HARDFOC_BOARD_* macro

// Print where every pin that the GPIO layer should own lives on this board.
void list_gpio_pins() {
  for (size_t i = 0; i < HF_GPIO_MAPPING_SIZE; ++i) {
    const HfGpioMapping& m = HF_GPIO_MAPPING[i];
    if (!should_register_as_gpio(static_cast<HfPinCategory>(m.category))) {
      continue;  // core and comm pins belong to the system and the bus drivers
    }
    std::printf("%-28.*s chip %u pin %2u %s\n", static_cast<int>(m.name.size()), m.name.data(),
                m.chip_type, m.physical_pin, m.is_inverted ? "active-low" : "active-high");
  }
}

What happens:

Step What it does
#include "hf_functional_pin_config.hpp" The selector includes the board header named by the define
HF_GPIO_MAPPING, HF_GPIO_MAPPING_SIZE One HfGpioMapping per row of the board's GPIO list, in header order
should_register_as_gpio() True for gpio and user rows; core and comm rows belong to the system and bus drivers
m.chip_type, m.physical_pin Which chip carries the pin and its number on that chip

The library needs C++20 (std::string_view::starts_with).

If it does not compile

Message Cause Fix
No supported board variant defined! No HARDFOC_BOARD_* define reached this file Add it with PUBLIC scope, or to the component's compile options
no member named 'starts_with' Built as C++17 Build with -std=c++20 or later
redefinition of 'HfGpioChipType' Two board headers included Include only hf_functional_pin_config.hpp, never a board header directly

Next: Integration.