libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_gpio.cpp
1#include "stm32_gpio.hpp"
2
3#ifdef HAL_GPIO_MODULE_ENABLED
4
5using namespace LibXR;
6
7STM32GPIO *STM32GPIO::map[STM32_GPIO_EXTI_NUMBER] = {nullptr};
8
15stm32_gpio_exti_t STM32_GPIO_EXTI_GetID(uint16_t pin)
16{ // NOLINT
18
19 if (pin == 0 || pin_num > 15)
20 {
21 ASSERT(false);
22 return STM32_GPIO_EXTI_NUMBER;
23 }
24
25#if defined(STM32F0) || defined(STM32G0) || defined(STM32L0)
26 if (pin_num <= 1)
27 {
29 }
30 else if (pin_num <= 3)
31 {
33 }
34 else
35 {
37 }
38
39#else
40 if (pin_num <= 4)
41 {
42 return static_cast<stm32_gpio_exti_t>(pin_num);
43 }
44 else if (pin_num <= 9)
45 {
46 return STM32_GPIO_EXTI_5_9;
47 }
48 else
49 {
50 return STM32_GPIO_EXTI_10_15;
51 }
52
53#endif
54
55 return STM32_GPIO_EXTI_NUMBER;
56}
57
58extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
59{
60 auto id = STM32_GPIO_EXTI_GetID(GPIO_Pin);
61 auto gpio = STM32GPIO::map[id];
62
63 if (gpio)
64 {
65 gpio->callback_.Run(true);
66 }
67}
68
69#endif
void Run(bool in_isr, PassArgs &&...args) const
执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
Definition libxr_cb.hpp:207
Callback callback_
GPIO 事件的回调函数。Callback function for GPIO events.
Definition gpio.hpp:54
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值