HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmGpio.h
Go to the documentation of this file.
1
15#pragma once
16
17#include "BaseGpio.h"
18#include "StmTypes.h"
19
20struct GPIO_TypeDef; // Forward — defined by stm32xxxx_hal_gpio.h
21
34class StmGpio : public BaseGpio {
35public:
36
48 explicit StmGpio(
49 hf_pin_num_t pin_num,
50 GPIO_TypeDef* port,
51 hf_u16_t hal_pin_mask,
56 hf_gpio_drive_cap_t drive_capability = hf_gpio_drive_cap_t::HF_GPIO_DRIVE_CAP_MEDIUM
57 ) noexcept;
58
62 explicit StmGpio(const hf_stm32_gpio_config_t& config) noexcept;
63
64 ~StmGpio() noexcept override;
65
66 // ── Public pure-virtual overrides ───────────────────────────────────────
67 bool Initialize() noexcept override;
68 bool IsPinAvailable() const noexcept override;
69 hf_u8_t GetMaxPins() const noexcept override;
70 const char* GetDescription() const noexcept override;
71
72 // ── EXTI dispatch (call from HAL_GPIO_EXTI_Callback in user code) ───────
83 static void ExtiCallbackDispatch(hf_u16_t gpio_pin_mask) noexcept;
84
85 // ── Accessors ───────────────────────────────────────────────────────────
86 GPIO_TypeDef* GetPort() const noexcept { return port_; }
87 hf_u16_t GetHalPinMask() const noexcept { return hal_pin_mask_; }
88
89protected:
90 // ── Platform implementation overrides ───────────────────────────────────
91 hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept override;
92 hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t& direction) const noexcept override;
94 hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t& mode) const noexcept override;
96 hf_gpio_pull_mode_t GetPullModeImpl() const noexcept override;
97 hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept override;
98 hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t& level) noexcept override;
99
100private:
101 GPIO_TypeDef* port_;
106 hf_gpio_drive_cap_t drive_cap_;
107
109 void ApplyHalConfig() noexcept;
110
112 static StmGpio* s_exti_instances_[16];
113};
Unified GPIO base class for all digital GPIO implementations.
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
hf_i32_t hf_pin_num_t
Platform-agnostic GPIO pin number type.
Definition HardwareTypes.h:99
uint16_t hf_u16_t
Platform-agnostic 16-bit unsigned integer type.
Definition HardwareTypes.h:46
STM32 platform-specific type definitions for hardware abstraction.
Unified GPIO base class for all digital GPIO implementations.
Definition BaseGpio.h:294
STM32 GPIO implementation with full HAL integration.
Definition StmGpio.h:34
bool IsPinAvailable() const noexcept override
Check if the pin is available for GPIO operations.
Definition StmGpio.cpp:124
hf_gpio_drive_cap_t drive_cap_
Definition StmGpio.h:106
hf_gpio_pull_mode_t GetPullModeImpl() const noexcept override
Hardware read-back of current pull resistor mode from registers.
Definition StmGpio.cpp:179
hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t &direction) const noexcept override
Hardware read-back of current pin direction from registers.
Definition StmGpio.cpp:147
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.
Definition StmGpio.cpp:79
hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t &mode) const noexcept override
Hardware read-back of current output mode from registers.
Definition StmGpio.cpp:163
hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t &level) noexcept override
Platform-specific implementation for getting pin electrical level.
Definition StmGpio.cpp:195
static StmGpio * s_exti_instances_[16]
Static EXTI dispatch table — one slot per EXTI line (0–15).
Definition StmGpio.h:73
hf_gpio_output_mode_t output_mode_
Definition StmGpio.h:104
hf_u16_t hal_pin_mask_
Definition StmGpio.h:102
hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept override
Platform-specific implementation for setting pin electrical level.
Definition StmGpio.cpp:187
hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept override
Platform-specific implementation for setting pin direction.
Definition StmGpio.cpp:140
void ApplyHalConfig() noexcept
Rebuild and apply HAL_GPIO_Init for the current config.
Definition StmGpio.cpp:321
hf_gpio_err_t SetPullModeImpl(hf_gpio_pull_mode_t mode) noexcept override
Platform-specific implementation for setting pull resistor mode.
Definition StmGpio.cpp:172
StmGpio(const hf_stm32_gpio_config_t &config) noexcept
Construct from config struct.
const char * GetDescription() const noexcept override
Get human-readable description of this GPIO instance.
Definition StmGpio.cpp:132
GPIO_TypeDef * GetPort() const noexcept
Definition StmGpio.h:86
hf_gpio_pull_mode_t pull_mode_
Definition StmGpio.h:105
hf_gpio_direction_t direction_
Definition StmGpio.h:103
~StmGpio() noexcept override
Definition StmGpio.cpp:100
hf_u8_t GetMaxPins() const noexcept override
Get the maximum number of pins supported by this GPIO instance.
Definition StmGpio.cpp:128
static void ExtiCallbackDispatch(hf_u16_t gpio_pin_mask) noexcept
Route EXTI callback to the registered StmGpio instance.
Definition StmGpio.cpp:282
bool Initialize() noexcept override
Initialize the GPIO pin with current configuration.
Definition StmGpio.cpp:111
GPIO_TypeDef * port_
Definition StmGpio.h:101
hf_u16_t GetHalPinMask() const noexcept
Definition StmGpio.h:87
hf_gpio_err_t SetOutputModeImpl(hf_gpio_output_mode_t mode) noexcept override
Platform-specific implementation for setting output mode.
Definition StmGpio.cpp:156
hf_gpio_level_t
GPIO pin electrical levels.
Definition BaseGpio.h:148
hf_gpio_err_t
HardFOC GPIO error codes.
Definition BaseGpio.h:108
hf_gpio_direction_t
GPIO pin direction/mode configuration.
Definition BaseGpio.h:168
hf_gpio_pull_mode_t
GPIO pull resistor configuration.
Definition BaseGpio.h:188
hf_gpio_output_mode_t
GPIO output drive modes.
Definition BaseGpio.h:178
hf_gpio_active_state_t
GPIO active state polarity configuration.
Definition BaseGpio.h:158
@ HF_GPIO_DIRECTION_INPUT
Pin configured as input.
@ HF_GPIO_PULL_MODE_FLOATING
No pull resistor (floating/high-impedance)
@ HF_GPIO_OUTPUT_MODE_PUSH_PULL
Push-pull output (strong high and low)
@ HF_GPIO_ACTIVE_HIGH
Active state is electrical high.
GPIO configuration for STM32 wrapping CubeMX port/pin.
Definition StmTypes.h:496