Skip to content

HardFOC core library

Internal Interface Wrap

Abstract C++ interfaces for the peripherals a motor-control board uses (GPIO, ADC, PWM, I2C, SPI, UART, CAN, NVS, timers, logging, Wi-Fi, Bluetooth) and their implementations for ESP32, STM32 and the host.

Quickstart API guide Source on GitHub

Drivers and board code in HardFOC never call ESP-IDF or STM32Cube directly. They take a BaseGpio&, a BaseI2c& or a BaseCan&, and the board decides at build time which class sits behind it: EspGpio on an ESP32-C6, StmGpio on an STM32, a mock in a host test. Porting the stack to a new MCU means implementing these interfaces once, not editing every driver.

What you get

  • 15 interfaces, one shape. Each Base* class has lazy initialisation (EnsureInitialized()), an error enum with a constexpr to-string, and statistics and diagnostics. See Architecture.
  • ESP32 implementations for all of them, on ESP-IDF v5.5: EspGpio, EspAdc, EspCan, EspSpiDevice, EspI2cDevice and the rest. See ESP32.
  • CAN ready for CANopen and CAN FD. BaseCan v2 carries 64-byte frames, sends without blocking (TrySendMessage()), reports TEC, REC and bus-off (GetBusStatus()); EspCan receives into a lock-free ring. See CAN.
  • STM32 wrappers over CubeMX-generated HAL handles for eleven interfaces. See STM32.
  • A small porting surface. A new MCU implements a handful of *Impl() methods per interface; validation, polarity and statistics stay in the base class. See Porting.
  • Utilities for the code above the interfaces: DigitalOutputGuard, SoftChipSelectGuard, HfSpscRing, PlatformMutex. See Utilities.

Used by

Repository Uses it for
hf-core-drivers Carries it as internal/hf-internal-interface-wrap, next to the chip drivers
hf-core Handlers adapt Base* objects to the drivers' communication interfaces; the CANopen frame adapter runs over BaseCan
hf-hal-vortex-v1 Vortex V1 board, through hf-core: its managers create the Esp* objects for the board's pins and buses
hf-hal-flux-v1 Flux V1 board, through hf-core

Where to go next

  • Quickstart


    Create an ESP32 pin and I2C device and pass them to portable code.

  • Architecture


    The interface model, initialisation, errors, threads and MCU selection.

  • API guide


    GPIO, ADC, PWM, SPI, UART, NVS and timers by task.

  • CAN


    BaseCan v2: FD-sized frames, non-blocking send, RX ring, bus status.

  • Porting


    Bring the interfaces to a new MCU.

  • Testing and CI


    Host tests, compiled snippets, ESP32 example builds.