|
libxr
1.0
Want to be the best embedded framework
|
HPM 平台 GPIO 驱动实现 / GPIO driver implementation for HPM platform. More...
#include <hpm_gpio.hpp>
Public Member Functions | |
| HPMGPIO (GPIO_Type *gpio, uint32_t port, uint8_t pin, uint32_t irq=kInvalidIrq, uint16_t pad_index=kInvalidPadIndex) | |
| 构造 HPM GPIO 对象 / Construct an HPM GPIO object. | |
| bool | Read () override |
| 读取引脚电平 / Read current pin level. | |
| void | Write (bool value) override |
| 写引脚电平 / Write output pin level. | |
| ErrorCode | EnableInterrupt () override |
| 使能当前引脚中断 / Enable GPIO interrupt for current pin. | |
| ErrorCode | DisableInterrupt () override |
| 失能当前引脚中断 / Disable GPIO interrupt for current pin. | |
| ErrorCode | SetConfig (Configuration config) override |
| 配置当前引脚模式 / Configure GPIO mode for current pin. | |
| ErrorCode | SetAnalogHighImpedance () |
| 将当前 PAD 配置为模拟高阻 / Configure current pad to analog high-impedance. | |
Public Member Functions inherited from LibXR::GPIO | |
| GPIO () | |
| 默认构造函数。Default constructor. | |
| ErrorCode | RegisterCallback (Callback callback) |
| 注册 GPIO 事件回调函数。Registers a callback function for GPIO events. | |
Static Public Member Functions | |
| static void | CheckInterrupt (uint32_t port) |
| 分发某一端口的 GPIO 中断回调 / Dispatch GPIO interrupt callbacks for one port. | |
Static Private Member Functions | |
| static uint16_t | ResolvePadIndex (GPIO_Type *gpio, uint32_t port, uint8_t pin) |
| 根据控制器与端口引脚推导 IOC PAD 编号 / Resolve IOC PAD index from controller/port/pin tuple. | |
Private Attributes | |
| GPIO_Type * | gpio_ |
| GPIO 控制器实例 / GPIO controller instance. | |
| uint32_t | port_ |
| GPIO 端口号 / GPIO port index. | |
| uint8_t | pin_ |
| GPIO 引脚号 / GPIO pin index. | |
| uint32_t | irq_ |
| 引脚对应 IRQ 号 / IRQ number for this pin. | |
| uint16_t | pad_index_ |
| IOC PAD 编号 / IOC PAD index. | |
Static Private Attributes | |
| static constexpr uint32_t | kPortCount = 15 |
| 支持的端口数量 / Supported port count. | |
| static constexpr uint32_t | kPinCount = 32 |
| 每个端口引脚数 / Pins per port. | |
| static constexpr uint32_t | kInvalidIrq = 0xFFFFFFFFu |
| 无效 IRQ 标记 / Invalid IRQ marker. | |
| static constexpr uint16_t | kInvalidPadIndex = 0xFFFFu |
| 无效 PAD 标记 / Invalid PAD marker. | |
| static HPMGPIO * | map [kPortCount][kPinCount] = {} |
| GPIO 对象映射表 / GPIO object dispatch map. | |
| static GPIO_Type * | port_controller_map [kPortCount] = {} |
Additional Inherited Members | |
Public Types inherited from LibXR::GPIO | |
| enum class | Direction : uint8_t { INPUT , OUTPUT_PUSH_PULL , OUTPUT_OPEN_DRAIN , FALL_INTERRUPT , RISING_INTERRUPT , FALL_RISING_INTERRUPT } |
| 定义 GPIO 引脚的方向类型。Defines the direction types for GPIO pins. More... | |
| enum class | Pull : uint8_t { NONE , UP , DOWN } |
| 定义 GPIO 引脚的上拉/下拉模式。Defines the pull-up/pull-down configurations for GPIO pins. More... | |
| using | Callback = LibXR::Callback<> |
Data Fields inherited from LibXR::GPIO | |
| Callback | callback_ |
| GPIO 事件的回调函数。Callback function for GPIO events. | |
HPM 平台 GPIO 驱动实现 / GPIO driver implementation for HPM platform.
该类将 LibXR GPIO 抽象接口适配到 HPM SDK GPIO API。 This class adapts the LibXR GPIO abstraction to HPM SDK GPIO APIs.
中断回调由 CheckInterrupt() 统一分发。 Interrupt callbacks are dispatched through CheckInterrupt().
Definition at line 20 of file hpm_gpio.hpp.
| HPMGPIO::HPMGPIO | ( | GPIO_Type * | gpio, |
| uint32_t | port, | ||
| uint8_t | pin, | ||
| uint32_t | irq = kInvalidIrq, | ||
| uint16_t | pad_index = kInvalidPadIndex ) |
构造 HPM GPIO 对象 / Construct an HPM GPIO object.
构造 HPM GPIO 对象并注册到中断映射表 / Construct HPM GPIO object and register into interrupt map.
| gpio | GPIO 控制器基地址 / GPIO controller base address. |
| port | GPIO 端口号 / GPIO port index. |
| pin | GPIO 引脚号 / GPIO pin index. |
| irq | 该引脚/端口对应的中断号(可选) / IRQ number for this pin/port (optional). |
| pad_index | IOC PAD 编号,默认值表示自动由 (gpio, port, pin) 推导 / IOC PAD index. Use default value to auto-resolve from (gpio, port, pin). |
Definition at line 49 of file hpm_gpio.cpp.
|
static |
分发某一端口的 GPIO 中断回调 / Dispatch GPIO interrupt callbacks for one port.
扫描并分发指定端口的 GPIO 中断 / Scan and dispatch GPIO IRQ callbacks for one port.
该函数应在板级 GPIO IRQ Handler 中调用。 This function should be called by board IRQ handlers.
同时会清除触发引脚的中断标志位。 It also clears interrupt flags for triggered pins.
建议在板级 IRQHandler 中仅调用一次该函数:
Definition at line 238 of file hpm_gpio.cpp.
|
overridevirtual |
失能当前引脚中断 / Disable GPIO interrupt for current pin.
失能当前引脚中断 / Disable interrupt for current pin.
ErrorCode::OK,IRQ 无效返回 ErrorCode::ARG_ERR / Returns ErrorCode::OK on success, ErrorCode::ARG_ERR when IRQ is invalid.先关闭 GPIO 事件,再关闭 PLIC 路由,避免在关中断过程中出现残留触发。 Disable GPIO event first, then PLIC routing, to avoid residual triggers while disabling.
Implements LibXR::GPIO.
Definition at line 96 of file hpm_gpio.cpp.
|
overridevirtual |
使能当前引脚中断 / Enable GPIO interrupt for current pin.
使能当前引脚中断 / Enable interrupt for current pin.
ErrorCode::OK,IRQ 无效返回 ErrorCode::ARG_ERR / Returns ErrorCode::OK on success, ErrorCode::ARG_ERR when IRQ is invalid.对于从 STM32 迁移的开发者:
gpio_enable_pin_interrupt() 只打开 GPIO 侧事件;intc_m_enable_irq_with_priority() 打开 PLIC 路由并设置优先级。 For STM32-oriented users:gpio_enable_pin_interrupt() enables GPIO-side event generation only.intc_m_enable_irq_with_priority() enables PLIC routing and IRQ priority. Implements LibXR::GPIO.
Definition at line 78 of file hpm_gpio.cpp.
|
inlineoverridevirtual |
读取引脚电平 / Read current pin level.
true 高电平,false 低电平 / true for high level, false for low level. Implements LibXR::GPIO.
Definition at line 39 of file hpm_gpio.hpp.
|
staticprivate |
根据控制器与端口引脚推导 IOC PAD 编号 / Resolve IOC PAD index from controller/port/pin tuple.
推导指定 GPIO 对应的 IOC PAD 编号 / Resolve IOC PAD index for a GPIO pin.
| gpio | GPIO 控制器基地址 / GPIO controller base address. |
| port | GPIO 端口号 / GPIO port index. |
| pin | GPIO 引脚号 / GPIO pin index. |
kInvalidPadIndex / Resolved PAD index, or kInvalidPadIndex if unavailable. 端口-引脚到对象实例的静态映射,用于中断分发 / Static port-pin to object map for interrupt dispatch. Definition at line 275 of file hpm_gpio.cpp.
| ErrorCode HPMGPIO::SetAnalogHighImpedance | ( | ) |
将当前 PAD 配置为模拟高阻 / Configure current pad to analog high-impedance.
将引脚切换为模拟高阻 / Put current pin into analog high-impedance mode.
ErrorCode::OK,PAD 不可解析返回 ErrorCode::NOT_SUPPORT / Returns ErrorCode::OK on success, ErrorCode::NOT_SUPPORT when PAD is unavailable.用途:
Definition at line 200 of file hpm_gpio.cpp.
|
overridevirtual |
配置当前引脚模式 / Configure GPIO mode for current pin.
配置 GPIO 方向、中断模式与上下拉 / Configure GPIO direction, interrupt mode, and pull.
ErrorCode::OK,失败返回对应错误码 / Returns ErrorCode::OK on success, error code otherwise. Read() 读取实际引脚电平 / When PAD can be resolved, IOC loopback is enabled so Read() can return the actual pad level even in output mode.与 STM32 HAL 的常见用法对齐:
Direction 对应 GPIO 模式(输入/输出/中断边沿)Pull 对应上拉/下拉配置 Aligned with common STM32 HAL usage:Direction maps to GPIO mode (input/output/IRQ edge)Pull maps to pull-up / pull-down configuration Implements LibXR::GPIO.
Definition at line 118 of file hpm_gpio.cpp.
|
inlineoverridevirtual |
写引脚电平 / Write output pin level.
| value | true 高电平,false 低电平 / true for high level, false for low level. |
Implements LibXR::GPIO.
Definition at line 50 of file hpm_gpio.hpp.
|
private |
GPIO 控制器实例 / GPIO controller instance.
Definition at line 123 of file hpm_gpio.hpp.
|
private |
引脚对应 IRQ 号 / IRQ number for this pin.
Definition at line 126 of file hpm_gpio.hpp.
|
staticconstexprprivate |
无效 IRQ 标记 / Invalid IRQ marker.
Definition at line 104 of file hpm_gpio.hpp.
|
staticconstexprprivate |
无效 PAD 标记 / Invalid PAD marker.
Definition at line 105 of file hpm_gpio.hpp.
|
staticconstexprprivate |
每个端口引脚数 / Pins per port.
Definition at line 103 of file hpm_gpio.hpp.
|
staticconstexprprivate |
支持的端口数量 / Supported port count.
Definition at line 102 of file hpm_gpio.hpp.
|
staticprivate |
GPIO 对象映射表 / GPIO object dispatch map.
按端口和引脚保存对象指针,供中断入口快速找到具体实例并触发回调。 Stores instance pointers by port/pin so IRQ entry can dispatch callbacks quickly.
Definition at line 120 of file hpm_gpio.hpp.
|
private |
IOC PAD 编号 / IOC PAD index.
Definition at line 127 of file hpm_gpio.hpp.
|
private |
Definition at line 125 of file hpm_gpio.hpp.
|
private |
Definition at line 124 of file hpm_gpio.hpp.
|
staticprivate |
Definition at line 121 of file hpm_gpio.hpp.