HardFOC Flux V1 HAL
Unified HAL API for the HardFOC Flux valve-control platform (ESP32-S3)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GpioManager Class Reference

Singleton that manages all MCU GPIO pins defined in the X-MACRO pin config. More...

#include <GpioManager.h>

Collaboration diagram for GpioManager:
[legend]

Public Member Functions

 GpioManager (const GpioManager &)=delete
 
GpioManager & operator= (const GpioManager &)=delete
 
 GpioManager (GpioManager &&)=delete
 
GpioManager & operator= (GpioManager &&)=delete
 
bool EnsureInitialized () noexcept
 Register all GPIO pins and initialise drivers (idempotent).
 
bool IsInitialized () const noexcept
 Check whether the manager is initialised.
 
bool Deinitialize () noexcept
 Reset GPIO manager to uninitialized state.
 
hf_gpio_err_t GetLastError () const noexcept
 Get the most recent error code.
 
flux::hal::ManagerError GetManagerError () const noexcept
 Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
 
BaseGpio * Get (std::string_view name) noexcept
 Get the BaseGpio driver for a named pin. Returns nullptr if not found.
 
BaseGpio * Get (HfFunctionalGpioPin pin) noexcept
 Get the BaseGpio driver for a functional pin enum. Returns nullptr if not found.
 
bool Contains (std::string_view name) const noexcept
 Check if a named pin exists in the registry.
 
size_t Size () const noexcept
 Number of registered GPIO pins.
 
hf_gpio_err_t Set (std::string_view name, bool value) noexcept
 Set a GPIO output to high (true) or low (false).
 
hf_gpio_err_t SetActive (std::string_view name) noexcept
 Drive a pin to its active state.
 
hf_gpio_err_t SetInactive (std::string_view name) noexcept
 Drive a pin to its inactive state.
 
hf_gpio_err_t Read (std::string_view name, bool &state) noexcept
 Read the current digital level of a pin.
 
hf_gpio_err_t Toggle (std::string_view name) noexcept
 Toggle pin output between high and low.
 
hf_gpio_err_t IsActive (std::string_view name, bool &active) noexcept
 Check whether a pin is currently in its active state.
 
hf_gpio_err_t SetDirection (std::string_view name, hf_gpio_direction_t direction) noexcept
 Change pin direction (input / output / open-drain).
 
hf_gpio_err_t SetPullMode (std::string_view name, hf_gpio_pull_mode_t pull_mode) noexcept
 Configure internal pull-up / pull-down resistors.
 
hf_gpio_err_t SetOutputMode (std::string_view name, hf_gpio_output_mode_t mode) noexcept
 Configure output driver mode (push-pull or open-drain).
 
hf_gpio_err_t ConfigureInterrupt (std::string_view name, hf_gpio_interrupt_trigger_t trigger, InterruptCallback callback, void *user_data=nullptr) noexcept
 Configure interrupt on a named GPIO pin.
 
hf_gpio_err_t EnableInterrupt (std::string_view name) noexcept
 Enable a previously configured interrupt on a named pin.
 
hf_gpio_err_t DisableInterrupt (std::string_view name) noexcept
 Disable the interrupt on a named pin.
 
bool SupportsInterrupts (std::string_view name) const noexcept
 Check whether a pin's underlying driver supports interrupts.
 
hf_gpio_err_t GetSystemDiagnostics (GpioSystemDiagnostics &diagnostics) const noexcept
 Populate a diagnostics snapshot.
 
void DumpStatistics () const noexcept
 Log current GPIO state and statistics to the console.
 

Static Public Member Functions

static GpioManager & GetInstance () noexcept
 Access the singleton instance (Meyers singleton, thread-safe).
 

Private Member Functions

 GpioManager () noexcept=default
 
 ~GpioManager ()=default
 
bool Initialize () noexcept
 
void ReleaseLocked () noexcept
 
size_t FindByName (std::string_view name) const noexcept
 Find entry index by string name. Returns kInvalidIndex if not found.
 

Private Attributes

std::array< GpioEntry, kMaxEntries > entries_ {}
 
size_t registered_count_ {0}
 
uint64_t init_time_ms_ {0}
 Timestamp (ms) when Initialize() completed.
 
uint32_t total_ops_ {0}
 
uint32_t successful_ops_ {0}
 
uint32_t failed_ops_ {0}
 
hf_gpio_err_t last_error_ {hf_gpio_err_t::GPIO_SUCCESS}
 
std::atomic< bool > initialized_ {false}
 
std::atomic< flux::hal::ManagerError > manager_error_ {flux::hal::ManagerError::NotInitialized}
 
RtosMutex mutex_
 

Static Private Attributes

static constexpr size_t kMaxEntries = static_cast<size_t>(HfFunctionalGpioPin::HF_FUNCTIONAL_GPIO_COUNT)
 Maximum registerable GPIO entries (all GPIO + USER pins from pincfg).
 
static constexpr size_t kInvalidIndex = SIZE_MAX
 

Detailed Description

Singleton that manages all MCU GPIO pins defined in the X-MACRO pin config.

Registers GPIO and USER category pins, provides name-based and enum-based access to the underlying BaseGpio drivers, and offers high-level Set/Read/Toggle/Interrupt operations routed by pin name. Thread-safe via RtosMutex.

Constructor & Destructor Documentation

◆ GpioManager() [1/3]

GpioManager::GpioManager ( const GpioManager &  )
delete

◆ GpioManager() [2/3]

GpioManager::GpioManager ( GpioManager &&  )
delete

◆ GpioManager() [3/3]

GpioManager::GpioManager ( )
privatedefaultnoexcept

◆ ~GpioManager()

GpioManager::~GpioManager ( )
privatedefault

Member Function Documentation

◆ ConfigureInterrupt()

hf_gpio_err_t GpioManager::ConfigureInterrupt ( std::string_view  name,
hf_gpio_interrupt_trigger_t  trigger,
InterruptCallback  callback,
void *  user_data = nullptr 
)
noexcept

Configure interrupt on a named GPIO pin.

Parameters
namePin name from pincfg
triggerInterrupt trigger edge/level
callbackFunction called on interrupt (keep minimal — ISR context)
user_dataOptional user data passed to callback
Returns
GPIO error code

◆ Contains()

bool GpioManager::Contains ( std::string_view  name) const
noexcept

Check if a named pin exists in the registry.

◆ Deinitialize()

bool GpioManager::Deinitialize ( )
noexcept

Reset GPIO manager to uninitialized state.

Returns
true on success
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DisableInterrupt()

hf_gpio_err_t GpioManager::DisableInterrupt ( std::string_view  name)
noexcept

Disable the interrupt on a named pin.

Parameters
namePin name from pincfg.
Returns
GPIO_SUCCESS on success.

◆ DumpStatistics()

void GpioManager::DumpStatistics ( ) const
noexcept

Log current GPIO state and statistics to the console.

Here is the caller graph for this function:

◆ EnableInterrupt()

hf_gpio_err_t GpioManager::EnableInterrupt ( std::string_view  name)
noexcept

Enable a previously configured interrupt on a named pin.

Parameters
namePin name from pincfg.
Returns
GPIO_SUCCESS on success.

◆ EnsureInitialized()

bool GpioManager::EnsureInitialized ( )
noexcept

Register all GPIO pins and initialise drivers (idempotent).

Returns
true on success or if already initialised.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindByName()

size_t GpioManager::FindByName ( std::string_view  name) const
privatenoexcept

Find entry index by string name. Returns kInvalidIndex if not found.

◆ Get() [1/2]

BaseGpio * GpioManager::Get ( HfFunctionalGpioPin  pin)
noexcept

Get the BaseGpio driver for a functional pin enum. Returns nullptr if not found.

◆ Get() [2/2]

BaseGpio * GpioManager::Get ( std::string_view  name)
noexcept

Get the BaseGpio driver for a named pin. Returns nullptr if not found.

Here is the caller graph for this function:

◆ GetInstance()

GpioManager & GpioManager::GetInstance ( )
staticnoexcept

Access the singleton instance (Meyers singleton, thread-safe).

Returns
Reference to the sole GpioManager instance.
Here is the caller graph for this function:

◆ GetLastError()

hf_gpio_err_t GpioManager::GetLastError ( ) const
inlinenoexcept

Get the most recent error code.

Returns
Last hf_gpio_err_t set by any API call

◆ GetManagerError()

flux::hal::ManagerError GpioManager::GetManagerError ( ) const
inlinenoexcept

Lifecycle / bind error of the last EnsureInitialized() (shared catalog).

BindFailed when any GPIO-category pin of the pin map could not be created or initialised (fail-closed: the manager then stays uninitialised).

◆ GetSystemDiagnostics()

hf_gpio_err_t GpioManager::GetSystemDiagnostics ( GpioSystemDiagnostics &  diagnostics) const
noexcept

Populate a diagnostics snapshot.

Parameters
[out]diagnosticsStruct filled with current counters and state.
Returns
GPIO_SUCCESS on success.

◆ Initialize()

bool GpioManager::Initialize ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsActive()

hf_gpio_err_t GpioManager::IsActive ( std::string_view  name,
bool &  active 
)
noexcept

Check whether a pin is currently in its active state.

Parameters
namePin name from pincfg.
[out]activetrue if pin is active.
Returns
GPIO_SUCCESS on success.

◆ IsInitialized()

bool GpioManager::IsInitialized ( ) const
inlinenoexcept

Check whether the manager is initialised.

Returns
true if ready.

◆ operator=() [1/2]

GpioManager & GpioManager::operator= ( const GpioManager &  )
delete

◆ operator=() [2/2]

GpioManager & GpioManager::operator= ( GpioManager &&  )
delete

◆ Read()

hf_gpio_err_t GpioManager::Read ( std::string_view  name,
bool &  state 
)
noexcept

Read the current digital level of a pin.

Parameters
namePin name from pincfg.
[out]statetrue = high, false = low.
Returns
GPIO_SUCCESS on success.

◆ ReleaseLocked()

void GpioManager::ReleaseLocked ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

hf_gpio_err_t GpioManager::Set ( std::string_view  name,
bool  value 
)
noexcept

Set a GPIO output to high (true) or low (false).

Parameters
namePin name from pincfg.
valuetrue = active/high, false = inactive/low.
Returns
GPIO_SUCCESS on success.

◆ SetActive()

hf_gpio_err_t GpioManager::SetActive ( std::string_view  name)
noexcept

Drive a pin to its active state.

Parameters
namePin name from pincfg.
Returns
GPIO_SUCCESS on success.

◆ SetDirection()

hf_gpio_err_t GpioManager::SetDirection ( std::string_view  name,
hf_gpio_direction_t  direction 
)
noexcept

Change pin direction (input / output / open-drain).

Parameters
namePin name from pincfg.
directionDesired direction.
Returns
GPIO_SUCCESS on success.

◆ SetInactive()

hf_gpio_err_t GpioManager::SetInactive ( std::string_view  name)
noexcept

Drive a pin to its inactive state.

Parameters
namePin name from pincfg.
Returns
GPIO_SUCCESS on success.

◆ SetOutputMode()

hf_gpio_err_t GpioManager::SetOutputMode ( std::string_view  name,
hf_gpio_output_mode_t  mode 
)
noexcept

Configure output driver mode (push-pull or open-drain).

Parameters
namePin name from pincfg.
modeDesired output mode.
Returns
GPIO_SUCCESS on success.

◆ SetPullMode()

hf_gpio_err_t GpioManager::SetPullMode ( std::string_view  name,
hf_gpio_pull_mode_t  pull_mode 
)
noexcept

Configure internal pull-up / pull-down resistors.

Parameters
namePin name from pincfg.
pull_modeDesired pull mode.
Returns
GPIO_SUCCESS on success.

◆ Size()

size_t GpioManager::Size ( ) const
noexcept

Number of registered GPIO pins.

◆ SupportsInterrupts()

bool GpioManager::SupportsInterrupts ( std::string_view  name) const
noexcept

Check whether a pin's underlying driver supports interrupts.

Parameters
namePin name from pincfg.
Returns
true if interrupts are supported.

◆ Toggle()

hf_gpio_err_t GpioManager::Toggle ( std::string_view  name)
noexcept

Toggle pin output between high and low.

Parameters
namePin name from pincfg.
Returns
GPIO_SUCCESS on success.

Member Data Documentation

◆ entries_

std::array<GpioEntry, kMaxEntries> GpioManager::entries_ {}
private

◆ failed_ops_

uint32_t GpioManager::failed_ops_ {0}
private

◆ init_time_ms_

uint64_t GpioManager::init_time_ms_ {0}
private

Timestamp (ms) when Initialize() completed.

◆ initialized_

std::atomic<bool> GpioManager::initialized_ {false}
private

◆ kInvalidIndex

constexpr size_t GpioManager::kInvalidIndex = SIZE_MAX
staticconstexprprivate

◆ kMaxEntries

constexpr size_t GpioManager::kMaxEntries = static_cast<size_t>(HfFunctionalGpioPin::HF_FUNCTIONAL_GPIO_COUNT)
staticconstexprprivate

Maximum registerable GPIO entries (all GPIO + USER pins from pincfg).

◆ last_error_

hf_gpio_err_t GpioManager::last_error_ {hf_gpio_err_t::GPIO_SUCCESS}
private

◆ manager_error_

std::atomic<flux::hal::ManagerError> GpioManager::manager_error_ {flux::hal::ManagerError::NotInitialized}
private

◆ mutex_

RtosMutex GpioManager::mutex_
mutableprivate

◆ registered_count_

size_t GpioManager::registered_count_ {0}
private

◆ successful_ops_

uint32_t GpioManager::successful_ops_ {0}
private

◆ total_ops_

uint32_t GpioManager::total_ops_ {0}
private

The documentation for this class was generated from the following files: