|
HardFOC Vortex V1 HAL
Unified HAL API for the HardFOC Vortex motor-control platform (ESP32-C6, TMC9660)
|
Singleton managing GPIO pins across ESP32, PCAL95555 I/O expander, and TMC9660 controllers. More...
#include <GpioManager.h>
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 | Deinitialize () noexcept |
| Reset GPIO manager to uninitialised state. | |
| bool | IsInitialized () const noexcept |
| Check whether the manager is initialised. | |
| BaseGpio * | Get (std::string_view name) noexcept |
| Get the pin object of a named pin. | |
| BaseGpio * | Get (HfFunctionalGpioPin pin) noexcept |
| Get the pin object of a functional pin. | |
| 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 | 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 registered in the GPIO table. | |
| 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). | |
| void | RegisterTmc9660BridgePinsIfNeeded () noexcept |
| After MotorController::CreateOnboardDevice(), register TMC9660 GPIO17/18 in the table. | |
| void | UnregisterTmc9660BridgePins () noexcept |
| Remove the TMC9660 GPIO17/18 entries (their objects belong to the TMC9660 handler). | |
| hf_gpio_err_t | Set (std::string_view name, bool value) noexcept |
| Drive a GPIO output to its active (true) or inactive (false) state. | |
| 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 logical (active) state 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. | |
| hf_gpio_err_t | GetLastError () const noexcept |
| Get the most recent error code from any GPIO operation. | |
| 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 |
| Drop every entry and destroy the pin objects and the expander handler. Caller holds mutex_. | |
| size_t | FindByName (std::string_view name) const noexcept |
| Find entry index by string name. Returns kInvalidIndex if not found. | |
| bool | EnsurePcal95555Handler () noexcept |
| Lazy-init the PCAL95555 handler (needs I²C from CommChannelsManager). | |
Private Attributes | |
| std::array< GpioEntry, kMaxEntries > | entries_ {} |
| size_t | registered_count_ {0} |
| uint64_t | init_time_ms_ {0} |
| 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} |
| RtosMutex | mutex_ |
| std::optional< Pcal95555Handler > | pcal95555_handler_ |
| In place; emplaced at init. | |
| std::array< std::optional< Pcal95555GpioPin >, 16 > | pcal_pins_ {} |
| BaseGpio * | pcal_host_int_gpio_ {nullptr} |
| ESP32 GPIO for PCAL95555 /INT (COMM_I2C_PCAL95555_INT); not in the GPIO registry table. | |
Static Private Attributes | |
| static constexpr size_t | kMaxEntries |
| static constexpr size_t | kInvalidIndex = SIZE_MAX |
Singleton managing GPIO pins across ESP32, PCAL95555 I/O expander, and TMC9660 controllers.
Registers all GPIO, USER, ADC, and SPI category pins from the X-MACRO pin config. Handles three chip types:
|
delete |
|
delete |
|
privatedefaultnoexcept |
|
privatedefault |
|
noexcept |
Configure interrupt on a named GPIO pin.
| name | Pin name from pincfg. |
| trigger | Interrupt trigger edge/level. |
| callback | Function called on interrupt (keep minimal — ISR context). |
| user_data | Optional user pointer passed to callback. |
|
noexcept |
Check if a named pin exists in the registry.
|
noexcept |
Read INPUT_PORT_0 and INPUT_PORT_1 in one driver call (bits 0–7 = port0, 8–15 = port1).
For bench / bring-up. Lines tied to GND read as 0 (inactive) with typical strapping; compare against your schematic for A0–A2 and routed nets.
|
noexcept |
Read one PCAL95555 expander pin by hardware index (0–15), independent of whether that line is registered in the GPIO table.
For bench / bring-up only. Uses the shared Pcal95555Handler after I²C init. out_level follows the same convention as Pcal95555Handler::ReadInput.
|
noexcept |
Reset GPIO manager to uninitialised state.
|
noexcept |
Disable the interrupt on a named pin.
| name | Pin name from pincfg. |
|
noexcept |
Log current GPIO state and statistics to the console.
|
noexcept |
Enable a previously configured interrupt on a named pin.
| name | Pin name from pincfg. |
|
noexcept |
Register all GPIO pins and initialise drivers (idempotent).
|
privatenoexcept |
Lazy-init the PCAL95555 handler (needs I²C from CommChannelsManager).
|
privatenoexcept |
Find entry index by string name. Returns kInvalidIndex if not found.
|
noexcept |
Get the pin object of a functional pin.
|
noexcept |
Get the pin object of a named pin.
|
staticnoexcept |
Access the singleton instance (Meyers singleton, thread-safe).
|
inlinenoexcept |
Get the most recent error code from any GPIO operation.
|
noexcept |
Populate a diagnostics snapshot.
| [out] | diagnostics | Struct filled with current counters and state. |
|
privatenoexcept |
|
noexcept |
Check whether a pin is currently in its active state.
| name | Pin name from pincfg. | |
| [out] | active | true if pin is active. |
|
inlinenoexcept |
Check whether the manager is initialised.
|
delete |
|
delete |
|
noexcept |
Read the logical (active) state of a pin.
The result honours the pin's polarity from the pin map: for an active-low pin (PIN_LOGIC_INVERTED), a low electrical level reads as true. It is the same as IsActive(). It is not the electrical level.
| name | Pin name from pincfg. | |
| [out] | state | true = active, false = inactive. |
|
noexcept |
After MotorController::CreateOnboardDevice(), register TMC9660 GPIO17/18 in the table.
Vortex initializes GPIO before motors, so Tmc9660Handler does not exist during the first EnsureInitialized() scan. Call this from Vortex::InitializeMotors() once the onboard handler exists; idempotent if pins are already registered.
Those pins are the same physical lines as PCAL_TMC_GPIO17_EXP_IN / PCAL_TMC_GPIO18_EXP_IN (expander inputs P1–P2): use the PCAL aliases for passive read without TMCL; use TMC_GPIO17 / TMC_GPIO18 for driver-backed direction and output updates over SPI/UART.
|
privatenoexcept |
Drop every entry and destroy the pin objects and the expander handler. Caller holds mutex_.
|
noexcept |
Drive a GPIO output to its active (true) or inactive (false) state.
Logical, like Read(): for an active-low pin, true drives the line low.
| name | Pin name from pincfg. |
| value | true = active, false = inactive. |
|
noexcept |
Drive a pin to its active state.
| name | Pin name from pincfg. |
|
noexcept |
Change pin direction (input / output / open-drain).
| name | Pin name from pincfg. |
| direction | Desired direction. |
|
noexcept |
Drive a pin to its inactive state.
| name | Pin name from pincfg. |
|
noexcept |
Configure output driver mode (push-pull or open-drain).
| name | Pin name from pincfg. |
| mode | Desired output mode. |
|
noexcept |
Configure internal pull-up / pull-down resistors.
| name | Pin name from pincfg. |
| pull_mode | Desired pull mode. |
|
noexcept |
Number of registered GPIO pins.
|
noexcept |
Check whether a pin's underlying driver supports interrupts.
| name | Pin name from pincfg. |
|
noexcept |
Toggle pin output between high and low.
| name | Pin name from pincfg. |
|
noexcept |
Remove the TMC9660 GPIO17/18 entries (their objects belong to the TMC9660 handler).
Called by MotorController::Deinitialize() before it destroys the onboard handler, so Get(TMC_GPIO17/18) returns nullptr instead of a dangling pointer.
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
mutableprivate |
|
private |
In place; emplaced at init.
|
private |
ESP32 GPIO for PCAL95555 /INT (COMM_I2C_PCAL95555_INT); not in the GPIO registry table.
Owned by the board binding
|
private |
Expander pin objects (static)
|
private |
|
private |
|
private |