HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
esp32_bus_setup.hpp File Reference

Shared ESP32 bus initialization for hf-core handler tests. More...

#include "esp32_test_config.hpp"
#include "mcu/esp32/EspAdc.h"
#include "mcu/esp32/EspGpio.h"
#include "mcu/esp32/EspI2c.h"
#include "mcu/esp32/EspSpi.h"
#include <memory>
#include "esp_log.h"
Include dependency graph for esp32_bus_setup.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

EspI2cBus * get_shared_i2c_bus () noexcept
 Create and initialize the shared I2C bus.
 
BaseI2c * get_i2c_device (uint8_t address) noexcept
 Get an I2C device handle for a specific address on the shared bus.
 
EspSpiBus * get_shared_spi_bus () noexcept
 Create and initialize the shared SPI bus.
 
std::unique_ptr< EspGpio > create_gpio (int pin_num, hf_gpio_direction_t direction=hf_gpio_direction_t::HF_GPIO_DIRECTION_INPUT, hf_gpio_active_state_t active_state=hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH) noexcept
 Create an EspGpio for a specific pin.
 
EspAdc * get_shared_adc () noexcept
 Create and initialize the shared ADC instance.
 
int scan_i2c_bus (EspI2cBus *bus) noexcept
 Scan the I2C bus for responding devices.
 

Variables

static const char * BUS_TAG = "BusSetup"
 

Detailed Description

Shared ESP32 bus initialization for hf-core handler tests.

Provides factory functions to create and configure ESP32 I2C, SPI, GPIO, and ADC peripherals using the internal interface wrap (EspI2c, EspSpi, EspGpio, EspAdc). These are shared across all handler tests.

Each factory returns a unique_ptr or a reference to a static instance. Bus objects persist for the lifetime of the application.

Note
Include this file AFTER esp32_test_config.hpp (for pin definitions).
Author
HardFOC Team
Date
2025-2026

Function Documentation

◆ create_gpio()

std::unique_ptr< EspGpio > create_gpio ( int pin_num,
hf_gpio_direction_t direction = hf_gpio_direction_t::HF_GPIO_DIRECTION_INPUT,
hf_gpio_active_state_t active_state = hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH )
inlinenoexcept

Create an EspGpio for a specific pin.

Parameters
pin_numGPIO pin number.
directionInitial direction (input/output).
active_stateActive-high or active-low.
Returns
unique_ptr to EspGpio instance.
Here is the caller graph for this function:

◆ get_i2c_device()

BaseI2c * get_i2c_device ( uint8_t address)
inlinenoexcept

Get an I2C device handle for a specific address on the shared bus.

Parameters
address7-bit I2C device address.
Returns
Pointer to BaseI2c device, or nullptr if bus isn't initialized.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_shared_adc()

EspAdc * get_shared_adc ( )
inlinenoexcept

Create and initialize the shared ADC instance.

Returns
Pointer to persistent EspAdc instance, or nullptr on failure.
Here is the caller graph for this function:

◆ get_shared_i2c_bus()

EspI2cBus * get_shared_i2c_bus ( )
inlinenoexcept

Create and initialize the shared I2C bus.

Returns an EspI2cBus configured for the pins and speed in esp32_test_config. Multiple I2C devices can be attached to this bus.

Returns
Pointer to persistent EspI2cBus instance, or nullptr on failure.
Here is the caller graph for this function:

◆ get_shared_spi_bus()

EspSpiBus * get_shared_spi_bus ( )
inlinenoexcept

Create and initialize the shared SPI bus.

Returns
Pointer to persistent EspSpiBus instance, or nullptr on failure.
Here is the caller graph for this function:

◆ scan_i2c_bus()

int scan_i2c_bus ( EspI2cBus * bus)
inlinenoexcept

Scan the I2C bus for responding devices.

Probes addresses 0x08–0x77 and logs a grid of found devices. Useful for verifying hardware connections before running handler tests.

Parameters
busPointer to initialized EspI2cBus.
Returns
Number of devices found.
Here is the caller graph for this function:

Variable Documentation

◆ BUS_TAG

const char* BUS_TAG = "BusSetup"
static