HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmGpio Class Reference

STM32 GPIO implementation with full HAL integration. More...

#include <StmGpio.h>

Inheritance diagram for StmGpio:
[legend]
Collaboration diagram for StmGpio:
[legend]

Public Member Functions

 StmGpio (hf_pin_num_t pin_num, GPIO_TypeDef *port, hf_u16_t hal_pin_mask, 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, hf_gpio_output_mode_t output_mode=hf_gpio_output_mode_t::HF_GPIO_OUTPUT_MODE_PUSH_PULL, hf_gpio_pull_mode_t pull_mode=hf_gpio_pull_mode_t::HF_GPIO_PULL_MODE_FLOATING, hf_gpio_drive_cap_t drive_capability=hf_gpio_drive_cap_t::HF_GPIO_DRIVE_CAP_MEDIUM) noexcept
 Full constructor with HAL port + pin mask.
 
 StmGpio (const hf_stm32_gpio_config_t &config) noexcept
 Construct from config struct.
 
 ~StmGpio () noexcept override
 
bool Initialize () noexcept override
 Initialize the GPIO pin with current configuration.
 
bool IsPinAvailable () const noexcept override
 Check if the pin is available for GPIO operations.
 
hf_u8_t GetMaxPins () const noexcept override
 Get the maximum number of pins supported by this GPIO instance.
 
const char * GetDescription () const noexcept override
 Get human-readable description of this GPIO instance.
 
GPIO_TypeDef * GetPort () const noexcept
 
hf_u16_t GetHalPinMask () const noexcept
 
- Public Member Functions inherited from BaseGpio
 BaseGpio (const BaseGpio &copy)=delete
 Copy constructor is deleted to avoid copying instances.
 
BaseGpiooperator= (const BaseGpio &copy)=delete
 Assignment operator is deleted to avoid copying instances.
 
virtual ~BaseGpio () noexcept=default
 Virtual destructor for proper cleanup of derived classes.
 
bool IsInitialized () const noexcept
 Check if the pin is initialized.
 
bool EnsureInitialized () noexcept
 Ensures the pin is initialized (lazy initialization).
 
bool EnsureDeinitialized () noexcept
 Ensures the pin is deinitialized (lazy deinitialization).
 
hf_pin_num_t GetPin () const noexcept
 Get the GPIO pin number/identifier.
 
hf_gpio_direction_t GetDirection () const noexcept
 Get the current pin direction.
 
hf_gpio_err_t SetDirection (hf_gpio_direction_t direction) noexcept
 Set the pin direction (input or output).
 
bool IsInput () const noexcept
 Check if the pin is currently configured as input.
 
bool IsOutput () const noexcept
 Check if the pin is currently configured as output.
 
hf_gpio_output_mode_t GetOutputMode () const noexcept
 Get the output drive mode.
 
hf_gpio_err_t SetOutputMode (hf_gpio_output_mode_t mode) noexcept
 Set the output drive mode.
 
hf_gpio_pull_mode_t GetPullMode () const noexcept
 Get the current pull resistor mode.
 
hf_gpio_err_t SetPullMode (hf_gpio_pull_mode_t mode) noexcept
 Set the pull resistor mode.
 
hf_gpio_state_t GetCurrentState () const noexcept
 Get the current logical state of the pin.
 
hf_gpio_err_t SetState (hf_gpio_state_t state) noexcept
 Set the pin to a specific logical state.
 
hf_gpio_active_state_t GetActiveState () const noexcept
 Get the active state polarity configuration.
 
void SetActiveState (hf_gpio_active_state_t active_state) noexcept
 Set the active state polarity configuration.
 
hf_gpio_err_t SetActive () noexcept
 Set the GPIO to active state.
 
hf_gpio_err_t SetInactive () noexcept
 Set the GPIO to inactive state.
 
hf_gpio_err_t Toggle () noexcept
 Toggle the GPIO state.
 
hf_gpio_err_t IsActive (bool &is_active) noexcept
 Check if the GPIO is currently active.
 
hf_gpio_err_t VerifyDirection (hf_gpio_direction_t &direction) const noexcept
 Verify current direction setting by reading from hardware registers.
 
hf_gpio_err_t VerifyOutputMode (hf_gpio_output_mode_t &mode) const noexcept
 Verify current output mode setting by reading from hardware registers.
 
hf_gpio_err_t VerifyHardwareConfiguration () const noexcept
 Perform comprehensive hardware verification of all pin settings.
 
virtual hf_gpio_err_t SupportsInterrupts () const noexcept
 Check if this GPIO implementation supports interrupts.
 
virtual hf_gpio_err_t ConfigureInterrupt (hf_gpio_interrupt_trigger_t trigger, InterruptCallback callback=nullptr, void *user_data=nullptr) noexcept
 Configure GPIO interrupt settings.
 
virtual hf_gpio_err_t EnableInterrupt () noexcept
 Enable GPIO interrupt.
 
virtual hf_gpio_err_t DisableInterrupt () noexcept
 Disable GPIO interrupt.
 
virtual hf_gpio_err_t WaitForInterrupt (hf_u32_t timeout_ms=0) noexcept
 Wait for GPIO interrupt to occur.
 
virtual hf_gpio_err_t GetInterruptStatus (InterruptStatus &status) noexcept
 Get interrupt status information.
 
virtual hf_gpio_err_t ClearInterruptStats () noexcept
 Clear interrupt statistics.
 
virtual hf_gpio_err_t ResetStatistics () noexcept
 Reset GPIO operation statistics.
 
virtual hf_gpio_err_t ResetDiagnostics () noexcept
 Reset GPIO diagnostic information.
 
virtual hf_gpio_err_t GetStatistics (hf_gpio_statistics_t &statistics) const noexcept
 Get GPIO operation statistics.
 
virtual hf_gpio_err_t GetDiagnostics (hf_gpio_diagnostics_t &diagnostics) const noexcept
 Get GPIO diagnostic information.
 
virtual bool Deinitialize () noexcept
 Deinitialize the GPIO pin.
 

Static Public Member Functions

static void ExtiCallbackDispatch (hf_u16_t gpio_pin_mask) noexcept
 Route EXTI callback to the registered StmGpio instance.
 
- Static Public Member Functions inherited from BaseGpio
static const char * ToString (hf_gpio_state_t state) noexcept
 
static const char * ToString (hf_gpio_level_t level) noexcept
 
static const char * ToString (hf_gpio_active_state_t active_state) noexcept
 
static const char * ToString (hf_gpio_direction_t direction) noexcept
 
static const char * ToString (hf_gpio_output_mode_t output_mode) noexcept
 
static const char * ToString (hf_gpio_pull_mode_t pull_mode) noexcept
 
static const char * ToString (hf_gpio_interrupt_trigger_t trigger) noexcept
 

Protected Member Functions

hf_gpio_err_t SetDirectionImpl (hf_gpio_direction_t direction) noexcept override
 Platform-specific implementation for setting pin direction.
 
hf_gpio_err_t GetDirectionImpl (hf_gpio_direction_t &direction) const noexcept override
 Hardware read-back of current pin direction from registers.
 
hf_gpio_err_t SetOutputModeImpl (hf_gpio_output_mode_t mode) noexcept override
 Platform-specific implementation for setting output mode.
 
hf_gpio_err_t GetOutputModeImpl (hf_gpio_output_mode_t &mode) const noexcept override
 Hardware read-back of current output mode from registers.
 
hf_gpio_err_t SetPullModeImpl (hf_gpio_pull_mode_t mode) noexcept override
 Platform-specific implementation for setting pull resistor mode.
 
hf_gpio_pull_mode_t GetPullModeImpl () const noexcept override
 Hardware read-back of current pull resistor mode from registers.
 
hf_gpio_err_t SetPinLevelImpl (hf_gpio_level_t level) noexcept override
 Platform-specific implementation for setting pin electrical level.
 
hf_gpio_err_t GetPinLevelImpl (hf_gpio_level_t &level) noexcept override
 Platform-specific implementation for getting pin electrical level.
 
- Protected Member Functions inherited from BaseGpio
hf_gpio_err_t ValidateBasicOperation () const noexcept
 Validate basic parameters before GPIO operations.
 
hf_gpio_level_t StateToLevel (hf_gpio_state_t state) const noexcept
 Convert logical state to electrical level based on polarity.
 
hf_gpio_state_t LevelToState (hf_gpio_level_t level) const noexcept
 Convert electrical level to logical state based on polarity.
 
 BaseGpio (hf_pin_num_t 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, hf_gpio_output_mode_t output_mode=hf_gpio_output_mode_t::HF_GPIO_OUTPUT_MODE_PUSH_PULL, hf_gpio_pull_mode_t pull_mode=hf_gpio_pull_mode_t::HF_GPIO_PULL_MODE_FLOATING) noexcept
 Protected constructor with configuration.
 

Private Member Functions

void ApplyHalConfig () noexcept
 Rebuild and apply HAL_GPIO_Init for the current config.
 

Private Attributes

GPIO_TypeDef * port_
 
hf_u16_t hal_pin_mask_
 
hf_gpio_direction_t direction_
 
hf_gpio_output_mode_t output_mode_
 
hf_gpio_pull_mode_t pull_mode_
 
hf_gpio_drive_cap_t drive_cap_
 

Static Private Attributes

static StmGpios_exti_instances_ [16] = {}
 Static EXTI dispatch table — one slot per EXTI line (0–15).
 

Additional Inherited Members

- Protected Attributes inherited from BaseGpio
const hf_pin_num_t pin_
 GPIO pin number/identifier.
 
bool initialized_
 Initialization state flag.
 
hf_gpio_direction_t current_direction_
 Current pin direction.
 
hf_gpio_active_state_t active_state_
 Active state polarity.
 
hf_gpio_output_mode_t output_mode_
 Output drive mode.
 
hf_gpio_pull_mode_t pull_mode_
 Pull resistor configuration.
 
hf_gpio_state_t current_state_
 Current logical state.
 
hf_gpio_statistics_t statistics_
 GPIO operation statistics.
 
hf_gpio_diagnostics_t diagnostics_
 GPIO diagnostic information.
 

Detailed Description

STM32 GPIO implementation with full HAL integration.

Design:

  • Constructor accepts the HAL port pointer + pin mask (matching CubeMX output).
  • Alternatively can use the hf_pin_num_t encoding (port_index * 16 + pin_index) if the port array is registered via StmTypes utility functions.
  • Runtime reconfiguration calls HAL_GPIO_Init with a rebuilt InitTypeDef.
  • EXTI dispatch: a static array of 16 slots (one per EXTI line) routes HAL_GPIO_EXTI_Callback to the correct instance.

Constructor & Destructor Documentation

◆ StmGpio() [1/2]

StmGpio::StmGpio ( hf_pin_num_t pin_num,
GPIO_TypeDef * port,
hf_u16_t hal_pin_mask,
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,
hf_gpio_output_mode_t output_mode = hf_gpio_output_mode_t::HF_GPIO_OUTPUT_MODE_PUSH_PULL,
hf_gpio_pull_mode_t pull_mode = hf_gpio_pull_mode_t::HF_GPIO_PULL_MODE_FLOATING,
hf_gpio_drive_cap_t drive_capability = hf_gpio_drive_cap_t::HF_GPIO_DRIVE_CAP_MEDIUM )
explicitnoexcept

Full constructor with HAL port + pin mask.

Parameters
pin_numLogical pin number (encoded: port*16 + pin_index).
portGPIO_TypeDef* port (e.g. GPIOA).
hal_pin_maskHAL pin bitmask (e.g. GPIO_PIN_5 = 1<<5).
directionInput / Output / Bidirectional.
active_stateActive high / low.
output_modePush-pull / Open-drain.
pull_modeNone / Pull-up / Pull-down.
drive_capabilityLow / Medium / High / Very-High.

◆ StmGpio() [2/2]

StmGpio::StmGpio ( const hf_stm32_gpio_config_t & config)
explicitnoexcept

Construct from config struct.

◆ ~StmGpio()

StmGpio::~StmGpio ( )
overridenoexcept

Member Function Documentation

◆ ApplyHalConfig()

void StmGpio::ApplyHalConfig ( )
privatenoexcept

Rebuild and apply HAL_GPIO_Init for the current config.

◆ ExtiCallbackDispatch()

void StmGpio::ExtiCallbackDispatch ( hf_u16_t gpio_pin_mask)
staticnoexcept

Route EXTI callback to the registered StmGpio instance.

Usage:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
}
static void ExtiCallbackDispatch(hf_u16_t gpio_pin_mask) noexcept
Route EXTI callback to the registered StmGpio instance.
Definition StmGpio.cpp:282

◆ GetDescription()

const char * StmGpio::GetDescription ( ) const
overridevirtualnoexcept

Get human-readable description of this GPIO instance.

Returns
Pointer to description string

Implements BaseGpio.

◆ GetDirectionImpl()

hf_gpio_err_t StmGpio::GetDirectionImpl ( hf_gpio_direction_t & direction) const
overrideprotectedvirtualnoexcept

Hardware read-back of current pin direction from registers.

Parameters
directionOutput parameter: actual hardware pin direction
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Reads the actual direction configuration from hardware registers. Useful for fault detection and hardware verification.

Note
Some hardware may not support this operation.

Implements BaseGpio.

◆ GetHalPinMask()

hf_u16_t StmGpio::GetHalPinMask ( ) const
inlinenoexcept

◆ GetMaxPins()

hf_u8_t StmGpio::GetMaxPins ( ) const
overridevirtualnoexcept

Get the maximum number of pins supported by this GPIO instance.

Returns
Maximum pin count

Implements BaseGpio.

◆ GetOutputModeImpl()

hf_gpio_err_t StmGpio::GetOutputModeImpl ( hf_gpio_output_mode_t & mode) const
overrideprotectedvirtualnoexcept

Hardware read-back of current output mode from registers.

Parameters
modeOutput parameter: actual hardware output mode
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Reads the actual output mode configuration from hardware registers. Useful for fault detection and hardware verification.

Note
Some hardware may not support this operation.

Implements BaseGpio.

◆ GetPinLevelImpl()

hf_gpio_err_t StmGpio::GetPinLevelImpl ( hf_gpio_level_t & level)
overrideprotectedvirtualnoexcept

Platform-specific implementation for getting pin electrical level.

Parameters
levelOutput parameter: current electrical level (Low or High)
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Implements BaseGpio.

◆ GetPort()

GPIO_TypeDef * StmGpio::GetPort ( ) const
inlinenoexcept

◆ GetPullModeImpl()

hf_gpio_pull_mode_t StmGpio::GetPullModeImpl ( ) const
overrideprotectedvirtualnoexcept

Hardware read-back of current pull resistor mode from registers.

Returns
Current pull resistor mode

Reads the actual pull resistor configuration from hardware registers. Useful for fault detection and hardware verification.

Note
Some hardware may not support this operation.

Implements BaseGpio.

◆ Initialize()

bool StmGpio::Initialize ( )
overridevirtualnoexcept

Initialize the GPIO pin with current configuration.

Returns
true if initialization successful, false otherwise

Implements BaseGpio.

◆ IsPinAvailable()

bool StmGpio::IsPinAvailable ( ) const
overridevirtualnoexcept

Check if the pin is available for GPIO operations.

Returns
true if pin is available, false if reserved for other functions

Implements BaseGpio.

◆ SetDirectionImpl()

hf_gpio_err_t StmGpio::SetDirectionImpl ( hf_gpio_direction_t direction)
overrideprotectedvirtualnoexcept

Platform-specific implementation for setting pin direction.

Parameters
directionNew pin direction (Input or Output)
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Implements BaseGpio.

◆ SetOutputModeImpl()

hf_gpio_err_t StmGpio::SetOutputModeImpl ( hf_gpio_output_mode_t mode)
overrideprotectedvirtualnoexcept

Platform-specific implementation for setting output mode.

Parameters
modeNew output mode (PushPull or OpenDrain)
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Implements BaseGpio.

◆ SetPinLevelImpl()

hf_gpio_err_t StmGpio::SetPinLevelImpl ( hf_gpio_level_t level)
overrideprotectedvirtualnoexcept

Platform-specific implementation for setting pin electrical level.

Parameters
levelNew electrical level (Low or High)
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Implements BaseGpio.

◆ SetPullModeImpl()

hf_gpio_err_t StmGpio::SetPullModeImpl ( hf_gpio_pull_mode_t mode)
overrideprotectedvirtualnoexcept

Platform-specific implementation for setting pull resistor mode.

Parameters
modeNew pull resistor mode (Floating, PullUp, PullDown)
Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Implements BaseGpio.

Member Data Documentation

◆ direction_

hf_gpio_direction_t StmGpio::direction_
private

◆ drive_cap_

hf_gpio_drive_cap_t StmGpio::drive_cap_
private

◆ hal_pin_mask_

hf_u16_t StmGpio::hal_pin_mask_
private

◆ output_mode_

hf_gpio_output_mode_t StmGpio::output_mode_
private

◆ port_

GPIO_TypeDef* StmGpio::port_
private

◆ pull_mode_

hf_gpio_pull_mode_t StmGpio::pull_mode_
private

◆ s_exti_instances_

StmGpio * StmGpio::s_exti_instances_ = {}
staticprivate

Static EXTI dispatch table — one slot per EXTI line (0–15).


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