libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::STM32GPIO Class Reference
Inheritance diagram for LibXR::STM32GPIO:
Collaboration diagram for LibXR::STM32GPIO:

Public Member Functions

 STM32GPIO (GPIO_TypeDef *port, uint16_t pin, IRQn_Type irq=NonMaskableInt_IRQn)
 
bool Read ()
 读取 GPIO 引脚状态。Reads the GPIO pin state.
 
ErrorCode Write (bool value)
 写入 GPIO 引脚状态。Writes the GPIO pin state.
 
ErrorCode EnableInterrupt ()
 使能 GPIO 引脚中断。Enables the GPIO pin interrupt.
 
ErrorCode DisableInterrupt ()
 禁用 GPIO 引脚中断。Disables the GPIO pin interrupt.
 
ErrorCode SetConfig (Configuration config)
 配置 GPIO 引脚参数。Configures the GPIO pin settings.
 
- Public Member Functions inherited from LibXR::GPIO
 GPIO ()
 默认构造函数。Default constructor.
 
ErrorCode RegisterCallback (Callback<> callback)
 注册 GPIO 事件回调函数。Registers a callback function for GPIO events.
 

Static Public Attributes

static STM32GPIOmap [STM32_GPIO_EXTI_NUMBER] = {nullptr}
 

Private Attributes

GPIO_TypeDefport_
 
uint16_t pin_
 
IRQn_Type irq_
 

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...
 
- Data Fields inherited from LibXR::GPIO
Callback callback_
 GPIO 事件的回调函数。Callback function for GPIO events.
 

Detailed Description

Definition at line 33 of file stm32_gpio.hpp.

Constructor & Destructor Documentation

◆ STM32GPIO()

LibXR::STM32GPIO::STM32GPIO ( GPIO_TypeDef port,
uint16_t  pin,
IRQn_Type  irq = NonMaskableInt_IRQn 
)
inline

Definition at line 36 of file stm32_gpio.hpp.

37 : port_(port), pin_(pin), irq_(irq)
38 {
39 if (irq_ != NonMaskableInt_IRQn)
40 {
41 map[STM32_GPIO_EXTI_GetID(pin)] = this;
42 }
43 }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

Member Function Documentation

◆ DisableInterrupt()

ErrorCode LibXR::STM32GPIO::DisableInterrupt ( )
inlinevirtual

禁用 GPIO 引脚中断。Disables the GPIO pin interrupt.

Returns
操作结果的错误码。Error code indicating the result of the operation.

Implements LibXR::GPIO.

Definition at line 60 of file stm32_gpio.hpp.

61 {
62 ASSERT(irq_ != NonMaskableInt_IRQn);
64 return ErrorCode::OK;
65 }

◆ EnableInterrupt()

ErrorCode LibXR::STM32GPIO::EnableInterrupt ( )
inlinevirtual

使能 GPIO 引脚中断。Enables the GPIO pin interrupt.

Returns
操作结果的错误码。Error code indicating the result of the operation.

Implements LibXR::GPIO.

Definition at line 53 of file stm32_gpio.hpp.

54 {
55 ASSERT(irq_ != NonMaskableInt_IRQn);
57 return ErrorCode::OK;
58 }

◆ Read()

bool LibXR::STM32GPIO::Read ( )
inlinevirtual

读取 GPIO 引脚状态。Reads the GPIO pin state.

Returns
返回引脚状态,true 表示高电平,false 表示低电平。Returns the pin state, true for high, false for low.

Implements LibXR::GPIO.

Definition at line 45 of file stm32_gpio.hpp.

45{ return HAL_GPIO_ReadPin(port_, pin_) == GPIO_PIN_SET; }

◆ SetConfig()

ErrorCode LibXR::STM32GPIO::SetConfig ( Configuration  config)
inlinevirtual

配置 GPIO 引脚参数。Configures the GPIO pin settings.

Parameters
config需要应用的 GPIO 配置。The GPIO configuration to apply.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Implements LibXR::GPIO.

Definition at line 67 of file stm32_gpio.hpp.

68 {
70
71 HAL_GPIO_DeInit(port_, pin_);
72
73 gpio_init.Pin = pin_;
74
75 switch (config.direction)
76 {
79 break;
82 break;
85 break;
88 break;
91 break;
94 break;
95 }
96
97 switch (config.pull)
98 {
99 case Pull::NONE:
100 gpio_init.Pull = GPIO_NOPULL;
101 break;
102 case Pull::UP:
103 gpio_init.Pull = GPIO_PULLUP;
104 break;
105 case Pull::DOWN:
107 break;
108 }
109
111
112 HAL_GPIO_Init(port_, &gpio_init);
113
114 return ErrorCode::OK;
115 }
@ OUTPUT_PUSH_PULL
推挽输出模式。Push-pull output mode.
@ RISING_INTERRUPT
上升沿中断模式。Rising edge interrupt mode.
@ FALL_RISING_INTERRUPT
双沿触发中断模式。Both edge interrupt mode.
@ OUTPUT_OPEN_DRAIN
开漏输出模式。Open-drain output mode.
@ INPUT
输入模式。Input mode.
@ FALL_INTERRUPT
下降沿中断模式。Falling edge interrupt mode.
@ NONE
无上拉或下拉。No pull-up or pull-down.
@ DOWN
下拉模式。Pull-down mode.
@ UP
上拉模式。Pull-up mode.

◆ Write()

ErrorCode LibXR::STM32GPIO::Write ( bool  value)
inlinevirtual

写入 GPIO 引脚状态。Writes the GPIO pin state.

Parameters
value要写入的状态,true 表示高电平,false 表示低电平。The value to write, true for high, false for low.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Implements LibXR::GPIO.

Definition at line 47 of file stm32_gpio.hpp.

48 {
50 return ErrorCode::OK;
51 }

Field Documentation

◆ irq_

IRQn_Type LibXR::STM32GPIO::irq_
private

Definition at line 122 of file stm32_gpio.hpp.

◆ map

STM32GPIO * STM32GPIO::map = {nullptr}
static

Definition at line 117 of file stm32_gpio.hpp.

◆ pin_

uint16_t LibXR::STM32GPIO::pin_
private

Definition at line 121 of file stm32_gpio.hpp.

◆ port_

GPIO_TypeDef* LibXR::STM32GPIO::port_
private

Definition at line 120 of file stm32_gpio.hpp.


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