跳转到内容

bsp::GPIO_Driver API

文档稀疏
符号
62
已记录
35
修订版本
0.1.0+855c407f828e

27 / 62 个公开 API 符号没有说明。

命名空间

3

结构体

4

bsp::gpio::GpioPin

面向对象的 GPIO 引脚句柄。 轻量值类型,可复制,public 成员兼容 brace 初始化。 推荐使用此类型替代 GPIO_t。

bsp/gpio_driver/gpio_driver.hpp:49

函数

26

GPIO_EXTI_Callback

                    void GPIO_EXTI_Callback (const uint16_t GPIO_Pin)
                  

统一的 EXTI 中断分发入口。 HAL_GPIO_EXTI_Callback 应在中调用,把 HAL 回调转发到本库。

bsp/gpio_driver/gpio_driver.c:82

GPIO_EXTI_RegisterCallback

                    void GPIO_EXTI_RegisterCallback (const GPIO_t *gpio, const EXTI_Callback callback, void *data)
                  

注册某个 GPIO 的 EXTI 回调。 这里按 pin 位序号直接索引数组,速度比 map 查找更适合中断上下文。

bsp/gpio_driver/gpio_driver.c:57

PWM_SetCompare

                    static void PWM_SetCompare (PWM_t *hpwm, const uint32_t compare)
                  

直接设置比较值。 compare 超过 ARR 时不生效,避免写入非法值。

bsp/gpio_driver/pwm.h:72

PWM_SetDutyCircle

                    static void PWM_SetDutyCircle (PWM_t *hpwm, const float duty_circle)
                  

按占空比设置 PWM 输出。 duty_circle 的有效范围是 [0, 1];越界时会钳位到边界值。

bsp/gpio_driver/pwm.h:84

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::DispatchExtiInterrupt() instead"))) void GPIO_EXTI_Callback(const uint16_t GPIO_Pin)
                  

上游未提供说明。

bsp/gpio_driver/gpio_driver.h:125

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::GpioPin::read() instead"))) static inline GPIO_PinState GPIO_ReadPin(GPIO_t *hgpio)
                  

读取 GPIO 输入状态。 直接转发到底层 HAL 接口。 Deprecated bsp::gpio::GpioPin::read() 请使用。

bsp/gpio_driver/gpio_driver.h:62

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::GpioPin::reset() instead"))) static inline void GPIO_ResetPin(GPIO_t *hgpio)
                  

输出低电平。 Deprecated bsp::gpio::GpioPin::reset() 请使用。

bsp/gpio_driver/gpio_driver.h:95

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::GpioPin::set() instead"))) static inline void GPIO_SetPin(GPIO_t *hgpio)
                  

输出高电平。 Deprecated bsp::gpio::GpioPin::set() 请使用。

bsp/gpio_driver/gpio_driver.h:84

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::GpioPin::toggle() instead"))) static inline void GPIO_TogglePin(GPIO_t *hgpio)
                  

翻转 GPIO 输出状态。 Deprecated bsp::gpio::GpioPin::toggle() 请使用。

bsp/gpio_driver/gpio_driver.h:106

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::GpioPin::write() instead"))) static inline void GPIO_WritePin(GPIO_t *hgpio
                  

写入 GPIO 输出状态。 Deprecated bsp::gpio::GpioPin::write() 请使用。

bsp/gpio_driver/gpio_driver.h:73

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::RegisterExtiCallback() instead"))) void GPIO_EXTI_RegisterCallback(const GPIO_t *gpio
                  

上游未提供说明。

bsp/gpio_driver/gpio_driver.h:121

__attribute__

                    __attribute__ ((deprecated("Use bsp::gpio::UnregisterExtiCallback() instead"))) void GPIO_EXTI_UnregisterCallback(const GPIO_t *gpio)
                  

上游未提供说明。

bsp/gpio_driver/gpio_driver.h:123

bsp::gpio::DispatchExtiInterrupt

                    void bsp::gpio::DispatchExtiInterrupt (uint16_t GPIO_Pin)
                  

统一的 EXTI 中断分发入口,应在 HAL_GPIO_EXTI_Callback 中调用。

bsp/gpio_driver/gpio_driver.cpp:61

bsp::gpio::RegisterExtiCallback

                    void bsp::gpio::RegisterExtiCallback (const GpioPin *gpio, ExtiCallback callback)
                  

注册某个 GPIO 的 EXTI 回调。回调上下文从 gpio->user_data 读取。

bsp/gpio_driver/gpio_driver.cpp:45

bsp::gpio::anonymous_namespace{gpio_driver.cpp}::pin_to_index

                    size_t bsp::gpio::anonymous_namespace{gpio_driver.cpp}::pin_to_index (const uint16_t pin)
                  

把 GPIO pin 转成索引。 pin 必须是单 bit 值,例如 GPIO_PIN_0、GPIO_PIN_1。

bsp/gpio_driver/gpio_driver.cpp:35

gpio_pin_to_index

                    size_t gpio_pin_to_index (uint16_t pin)
                  

把 GPIO pin 转成索引。 pin 必须是单 bit 值,例如 GPIO_PIN_0、GPIO_PIN_1。

bsp/gpio_driver/gpio_driver.c:32

类型定义

2

EXTI_Callback

                    typedef void(* EXTI_Callback) (const GPIO_t *gpio, uint32_t counter, void *data) )(const GPIO_t *gpio, uint32_t counter, void *data)
                  

EXTI 回调函数签名。 回调里带上触发计数和用户数据,通常用于去抖、边沿累计或者事件分发。 Deprecated 新代码请使用 bsp::gpio::ExtiCallback。

bsp/gpio_driver/gpio_driver.h:120

bsp::gpio::ExtiCallback

                    using bsp::gpio::ExtiCallback = void (*)(const GpioPin* gpio, uint32_t counter)
                  

EXTI 回调签名。上下文通过 gpio->user_data 获取。

bsp/gpio_driver/gpio_driver.hpp:71

变量

19

GPIO_t::port

                    GPIO_TypeDef* GPIO_t::port
                  

GPIO 句柄。 这里把端口和引脚打包成一个轻量结构体,便于在中断回调和普通业务函数之间传递。 Deprecated 新代码请使用 bsp::gpio::GpioPin。

bsp/gpio_driver/gpio_driver.h:51

PWM_t::htim

                    TIM_HandleTypeDef* PWM_t::htim
                  

PWM 句柄。 PWM_t 一个对应一个定时器通道,上层只需要传这个结构体即可操作输出。

bsp/gpio_driver/pwm.h:47

bsp::gpio::anonymous_namespace{gpio_driver.cpp}::ExtiSlot::callback

                    ExtiCallback bsp::gpio::anonymous_namespace{gpio_driver.cpp}::ExtiSlot::callback
                  

回调

bsp/gpio_driver/gpio_driver.cpp:25

bsp::gpio::anonymous_namespace{gpio_driver.cpp}::ExtiSlot::counter

                    uint32_t bsp::gpio::anonymous_namespace{gpio_driver.cpp}::ExtiSlot::counter
                  

触发次数

bsp/gpio_driver/gpio_driver.cpp:24

bsp::gpio::anonymous_namespace{gpio_driver.cpp}::ExtiSlot::gpio

                    const GpioPin* bsp::gpio::anonymous_namespace{gpio_driver.cpp}::ExtiSlot::gpio
                  

被注册的 GPIO

bsp/gpio_driver/gpio_driver.cpp:23

bsp::gpio::anonymous_namespace{gpio_driver.cpp}::g_exti_callback_map

                    ExtiSlot bsp::gpio::anonymous_namespace{gpio_driver.cpp}::g_exti_callback_map[16] [16]
                  

上游未提供说明。

bsp/gpio_driver/gpio_driver.cpp:28

宏定义

3

文件

5

bsp/gpio_driver/gpio_driver.c

GPIO / EXTI 封装实现 syhanjin 2026-01-24 这里主要负责把 HAL 的 EXTI 回调变成可注册、可计数、可携带用户数据的形式。

bsp/gpio_driver/gpio_driver.c

bsp/gpio_driver/gpio_driver.cpp

GPIO 面向对象封装 — EXTI 实现 syhanjin 2026-06-30 bsp::gpio gpio_driver.c 独立的 EXTI 回调系统实现,使用新类型, 与中的旧实现互不依赖。

bsp/gpio_driver/gpio_driver.cpp

bsp/gpio_driver/gpio_driver.h

GPIO / EXTI / PWM 的基础封装 syhanjin 2025-09-10 GPIO_t PWM_t 这个模块把 HAL 的 GPIO、外部中断和 PWM 接口做了一层很薄的封装,核心目标是统一句柄形式, 让上层代码只需要围绕和这类结构体操作,而不必反复处理底层 HAL 句柄细节。 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. https://www.gnu.org/licenses/ You should have received a copy of the GNU General Public License along with this program. If not, see. https://github.com/HITSZ-WTRobot-Packages/BasicComponents Project repository:

bsp/gpio_driver/gpio_driver.h

bsp/gpio_driver/gpio_driver.hpp

GPIO 面向对象封装(C++) syhanjin 2026-06-30 gpio_driver.h 此头文件提供面向对象的 GPIO 操作 API,推荐用于所有新代码。 旧 C 风格 API 在中保留但已标记为弃用。 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. https://www.gnu.org/licenses/ You should have received a copy of the GNU General Public License along with this program. If not, see. https://github.com/HITSZ-WTRobot-Packages/BasicComponents Project repository:

bsp/gpio_driver/gpio_driver.hpp

bsp/gpio_driver/pwm.h

TIM PWM 的基础封装 syhanjin 2025-09-10 这个头文件只做最常见的 PWM 启停和占空比换算,目的是让上层代码不用反复接触 __HAL_TIM_* 宏。 这样做的好处是调用方式统一,也更容易在代码里看出“这是一个 PWM 句柄,而不是裸 TIM 句柄”。 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. https://www.gnu.org/licenses/ You should have received a copy of the GNU General Public License along with this program. If not, see. https://github.com/HITSZ-WTRobot-Packages/BasicComponents Project repository:

bsp/gpio_driver/pwm.h