Internal Interface Wrap
API reference
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
20// Forward-declare GPIO_TypeDef only when CMSIS / HAL has not already defined it
21// as a typedef (which is the case on every STM32 family).
22#ifndef GPIOA
23struct GPIO_TypeDef;
24#endif
25
38class StmGpio : public BaseGpio {
39public:
40
52 explicit StmGpio(
53 hf_pin_num_t pin_num,
54 GPIO_TypeDef* port,
55 hf_u16_t hal_pin_mask,
61 ) noexcept;
62
66 explicit StmGpio(const hf_stm32_gpio_config_t& config) noexcept;
67
68 ~StmGpio() noexcept override;
69
70 // ── Public pure-virtual overrides ───────────────────────────────────────
71 bool Initialize() noexcept override;
72 bool IsPinAvailable() const noexcept override;
73 hf_u8_t GetMaxPins() const noexcept override;
74 const char* GetDescription() const noexcept override;
75
76 // ── EXTI dispatch (call from HAL_GPIO_EXTI_Callback in user code) ───────
87 static void ExtiCallbackDispatch(hf_u16_t gpio_pin_mask) noexcept;
88
89 // ── Accessors ───────────────────────────────────────────────────────────
90 GPIO_TypeDef* GetPort() const noexcept { return port_; }
91 hf_u16_t GetHalPinMask() const noexcept { return hal_pin_mask_; }
92
93protected:
94 // ── Platform implementation overrides ───────────────────────────────────
95 hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept override;
96 hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t& direction) const noexcept override;
98 hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t& mode) const noexcept override;
100 hf_gpio_pull_mode_t GetPullModeImpl() const noexcept override;
101 hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept override;
102 hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t& level) noexcept override;
103
104private:
105 GPIO_TypeDef* port_;
111
113 void ApplyHalConfig() noexcept;
114
116 static StmGpio* s_exti_instances_[16];
117};
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.
hf_gpio_drive_cap_t
STM32 GPIO output drive strength (subset aligned with EspTypes_GPIO).
Definition StmTypes.h:103
Unified GPIO base class for all digital GPIO implementations.
Definition BaseGpio.h:294
STM32 GPIO implementation with full HAL integration.
Definition StmGpio.h:38
bool IsPinAvailable() const noexcept override
Check if the pin is available for GPIO operations.
Definition StmGpio.cpp:72
hf_gpio_drive_cap_t drive_cap_
Definition StmGpio.h:110
hf_gpio_pull_mode_t GetPullModeImpl() const noexcept override
Hardware read-back of current pull resistor mode from registers.
Definition StmGpio.cpp:113
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:89
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:101
hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t &level) noexcept override
Platform-specific implementation for getting pin electrical level.
Definition StmGpio.cpp:127
static StmGpio * s_exti_instances_[16]
Static EXTI dispatch table — one slot per EXTI line (0–15).
Definition StmGpio.h:43
hf_gpio_output_mode_t output_mode_
Definition StmGpio.h:108
hf_u16_t hal_pin_mask_
Definition StmGpio.h:106
hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept override
Platform-specific implementation for setting pin electrical level.
Definition StmGpio.cpp:115
hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept override
Platform-specific implementation for setting pin direction.
Definition StmGpio.cpp:82
void ApplyHalConfig() noexcept
Rebuild and apply HAL_GPIO_Init for the current config.
Definition StmGpio.cpp:134
hf_gpio_err_t SetPullModeImpl(hf_gpio_pull_mode_t mode) noexcept override
Platform-specific implementation for setting pull resistor mode.
Definition StmGpio.cpp:106
const char * GetDescription() const noexcept override
Get human-readable description of this GPIO instance.
Definition StmGpio.cpp:78
GPIO_TypeDef * GetPort() const noexcept
Definition StmGpio.h:90
hf_gpio_pull_mode_t pull_mode_
Definition StmGpio.h:109
hf_gpio_direction_t direction_
Definition StmGpio.h:107
~StmGpio() noexcept override
hf_u8_t GetMaxPins() const noexcept override
Get the maximum number of pins supported by this GPIO instance.
Definition StmGpio.cpp:76
static void ExtiCallbackDispatch(hf_u16_t gpio_pin_mask) noexcept
Route EXTI callback to the registered StmGpio instance.
Definition StmGpio.cpp:80
bool Initialize() noexcept override
Initialize the GPIO pin with current configuration.
Definition StmGpio.cpp:66
GPIO_TypeDef * port_
Definition StmGpio.h:105
hf_u16_t GetHalPinMask() const noexcept
Definition StmGpio.h:91
hf_gpio_err_t SetOutputModeImpl(hf_gpio_output_mode_t mode) noexcept override
Platform-specific implementation for setting output mode.
Definition StmGpio.cpp:94
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:576