34#ifndef VORTEX_GPIO_MANAGER_H_
35#define VORTEX_GPIO_MANAGER_H_
43#include "base/BaseGpio.h"
44#include "handlers/pcal95555/Pcal95555Handler.h"
46#include "core/hf-core-drivers/internal/hf-pincfg/src/hf_functional_pin_config_vortex_v1.hpp"
52class Pcal95555Handler;
86 uint32_t
pins_by_chip[
static_cast<uint8_t
>(HfGpioChipType::TMC9660_CONTROLLER) + 1];
152 [[nodiscard]] BaseGpio*
Get(std::string_view name)
noexcept;
159 [[nodiscard]] BaseGpio*
Get(HfFunctionalGpioPin pin)
noexcept;
162 [[nodiscard]]
bool Contains(std::string_view name)
const noexcept;
165 [[nodiscard]]
size_t Size() const noexcept;
174 bool& out_level) noexcept;
214 [[nodiscard]] hf_gpio_err_t
Set(std::string_view name,
bool value) noexcept;
221 [[nodiscard]] hf_gpio_err_t
SetActive(std::string_view name) noexcept;
228 [[nodiscard]] hf_gpio_err_t
SetInactive(std::string_view name) noexcept;
239 [[nodiscard]] hf_gpio_err_t
Read(std::string_view name,
bool& state) noexcept;
246 [[nodiscard]] hf_gpio_err_t
Toggle(std::string_view name) noexcept;
254 [[nodiscard]] hf_gpio_err_t
IsActive(std::string_view name,
bool& active) noexcept;
266 [[nodiscard]] hf_gpio_err_t
SetDirection(std::string_view name, hf_gpio_direction_t direction) noexcept;
274 [[nodiscard]] hf_gpio_err_t
SetPullMode(std::string_view name, hf_gpio_pull_mode_t pull_mode) noexcept;
282 [[nodiscard]] hf_gpio_err_t
SetOutputMode(std::string_view name, hf_gpio_output_mode_t mode) noexcept;
297 hf_gpio_interrupt_trigger_t trigger,
298 InterruptCallback callback,
299 void* user_data =
nullptr) noexcept;
306 [[nodiscard]] hf_gpio_err_t
EnableInterrupt(std::string_view name) noexcept;
313 [[nodiscard]] hf_gpio_err_t
DisableInterrupt(std::string_view name) noexcept;
352 [[nodiscard]]
size_t FindByName(std::string_view name) const noexcept;
363 static_cast<
size_t>(HfFunctionalGpioPin::HF_FUNCTIONAL_GPIO_COUNT);
383 std::array<std::optional<Pcal95555GpioPin>, 16>
pcal_pins_{};
GpioManager & GetGpioManager() noexcept
Convenience accessor — equivalent to GpioManager::GetInstance().
Definition GpioManager.h:396
Singleton managing GPIO pins across ESP32, PCAL95555 I/O expander, and TMC9660 controllers.
Definition GpioManager.h:110
bool Contains(std::string_view name) const noexcept
Check if a named pin exists in the registry.
Definition GpioManager.cpp:427
uint32_t failed_ops_
Definition GpioManager.h:372
uint64_t init_time_ms_
Definition GpioManager.h:368
std::optional< Pcal95555Handler > pcal95555_handler_
In place; emplaced at init.
Definition GpioManager.h:382
std::array< GpioEntry, kMaxEntries > entries_
Definition GpioManager.h:366
hf_gpio_err_t last_error_
Definition GpioManager.h:373
GpioManager(const GpioManager &)=delete
hf_gpio_err_t Read(std::string_view name, bool &state) noexcept
Read the logical (active) state of a pin.
Definition GpioManager.cpp:480
static constexpr size_t kMaxEntries
Definition GpioManager.h:362
bool IsInitialized() const noexcept
Check whether the manager is initialised.
Definition GpioManager.h:141
GpioManager(GpioManager &&)=delete
void UnregisterTmc9660BridgePins() noexcept
Remove the TMC9660 GPIO17/18 entries (their objects belong to the TMC9660 handler).
Definition GpioManager.cpp:382
GpioManager & operator=(GpioManager &&)=delete
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).
Definition GpioManager.cpp:530
size_t registered_count_
Definition GpioManager.h:367
hf_gpio_err_t IsActive(std::string_view name, bool &active) noexcept
Check whether a pin is currently in its active state.
Definition GpioManager.cpp:506
hf_gpio_err_t SetDirection(std::string_view name, hf_gpio_direction_t direction) noexcept
Change pin direction (input / output / open-drain).
Definition GpioManager.cpp:514
size_t FindByName(std::string_view name) const noexcept
Find entry index by string name. Returns kInvalidIndex if not found.
Definition GpioManager.cpp:397
std::atomic< bool > initialized_
Definition GpioManager.h:375
hf_gpio_err_t DebugReadPcal95555InputSnapshot(uint16_t &out_bits) noexcept
Read INPUT_PORT_0 and INPUT_PORT_1 in one driver call (bits 0–7 = port0, 8–15 = port1).
Definition GpioManager.cpp:314
uint32_t successful_ops_
Definition GpioManager.h:371
bool SupportsInterrupts(std::string_view name) const noexcept
Check whether a pin's underlying driver supports interrupts.
Definition GpioManager.cpp:569
bool Deinitialize() noexcept
Reset GPIO manager to uninitialised state.
Definition GpioManager.cpp:70
std::array< std::optional< Pcal95555GpioPin >, 16 > pcal_pins_
Definition GpioManager.h:383
bool Initialize() noexcept
Definition GpioManager.cpp:101
hf_gpio_err_t DisableInterrupt(std::string_view name) noexcept
Disable the interrupt on a named pin.
Definition GpioManager.cpp:561
hf_gpio_err_t GetLastError() const noexcept
Get the most recent error code from any GPIO operation.
Definition GpioManager.h:337
hf_gpio_err_t Toggle(std::string_view name) noexcept
Toggle pin output between high and low.
Definition GpioManager.cpp:493
size_t Size() const noexcept
Number of registered GPIO pins.
Definition GpioManager.cpp:432
hf_gpio_err_t DebugReadPcal95555Pin(uint8_t expander_pin_0_to_15, bool &out_level) noexcept
Read one PCAL95555 expander pin by hardware index (0–15), independent of whether that line is registe...
Definition GpioManager.cpp:301
hf_gpio_err_t GetSystemDiagnostics(GpioSystemDiagnostics &diagnostics) const noexcept
Populate a diagnostics snapshot.
Definition GpioManager.cpp:581
bool EnsureInitialized() noexcept
Register all GPIO pins and initialise drivers (idempotent).
Definition GpioManager.cpp:57
RtosMutex mutex_
Definition GpioManager.h:376
hf_gpio_err_t Set(std::string_view name, bool value) noexcept
Drive a GPIO output to its active (true) or inactive (false) state.
Definition GpioManager.cpp:441
uint32_t total_ops_
Definition GpioManager.h:370
bool EnsurePcal95555Handler() noexcept
Lazy-init the PCAL95555 handler (needs I²C from CommChannelsManager).
Definition GpioManager.cpp:238
static constexpr size_t kInvalidIndex
Definition GpioManager.h:364
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.
Definition GpioManager.cpp:542
hf_gpio_err_t EnableInterrupt(std::string_view name) noexcept
Enable a previously configured interrupt on a named pin.
Definition GpioManager.cpp:553
void DumpStatistics() const noexcept
Log current GPIO state and statistics to the console.
Definition GpioManager.cpp:616
void RegisterTmc9660BridgePinsIfNeeded() noexcept
After MotorController::CreateOnboardDevice(), register TMC9660 GPIO17/18 in the table.
Definition GpioManager.cpp:325
hf_gpio_err_t SetPullMode(std::string_view name, hf_gpio_pull_mode_t pull_mode) noexcept
Configure internal pull-up / pull-down resistors.
Definition GpioManager.cpp:522
hf_gpio_err_t SetInactive(std::string_view name) noexcept
Drive a pin to its inactive state.
Definition GpioManager.cpp:467
BaseGpio * Get(std::string_view name) noexcept
Get the pin object of a named pin.
Definition GpioManager.cpp:406
void ReleaseLocked() noexcept
Drop every entry and destroy the pin objects and the expander handler. Caller holds mutex_.
Definition GpioManager.cpp:79
BaseGpio * pcal_host_int_gpio_
ESP32 GPIO for PCAL95555 /INT (COMM_I2C_PCAL95555_INT); not in the GPIO registry table.
Definition GpioManager.h:385
GpioManager & operator=(const GpioManager &)=delete
static GpioManager & GetInstance() noexcept
Access the singleton instance (Meyers singleton, thread-safe).
Definition GpioManager.cpp:48
hf_gpio_err_t SetActive(std::string_view name) noexcept
Drive a pin to its active state.
Definition GpioManager.cpp:454
Singleton managing multiple TMC9660 motor controllers on Vortex V1.
Definition MotorController.h:207
A single GPIO entry in the fixed-size registry.
Definition GpioManager.h:66
uint32_t error_count
Error counter.
Definition GpioManager.h:71
uint32_t access_count
Operation counter.
Definition GpioManager.h:70
bool registered
Whether this slot is active.
Definition GpioManager.h:69
BaseGpio * driver
Pin object (not owned; static storage elsewhere)
Definition GpioManager.h:67
GpioEntry() noexcept
Definition GpioManager.h:73
HfFunctionalGpioPin functional_pin
Functional pin enum.
Definition GpioManager.h:68
System-level GPIO diagnostics snapshot.
Definition GpioManager.h:83
uint32_t pins_by_chip[static_cast< uint8_t >(HfGpioChipType::TMC9660_CONTROLLER)+1]
Pin count per chip type.
Definition GpioManager.h:86
uint32_t successful_operations
Calls that returned GPIO_SUCCESS.
Definition GpioManager.h:89
hf_gpio_err_t last_error
Most recent error code.
Definition GpioManager.h:92
uint32_t total_pins_registered
Number of GPIO pins currently registered.
Definition GpioManager.h:85
bool system_healthy
true when manager is initialised and operational.
Definition GpioManager.h:84
uint32_t total_operations
Lifetime count of read/write/toggle calls.
Definition GpioManager.h:88
uint64_t system_uptime_ms
Milliseconds since manager initialisation.
Definition GpioManager.h:91
uint32_t pins_by_category[4]
Pin count per functional category.
Definition GpioManager.h:87
uint32_t failed_operations
Calls that returned an error.
Definition GpioManager.h:90