2018-11-29 17:00:22 +08:00
|
|
|
/*
|
2021-03-08 22:40:39 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2018-11-29 17:00:22 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2018-12-26 10:43:16 +08:00
|
|
|
* 2018-11-06 balanceTWK first version
|
2019-04-23 18:25:51 +08:00
|
|
|
* 2019-04-23 WillianChan Fix GPIO serial number disorder
|
2020-06-20 14:04:27 +08:00
|
|
|
* 2020-06-16 thread-liu add STM32MP1
|
2020-09-18 18:33:13 +08:00
|
|
|
* 2020-09-01 thread-liu add GPIOZ
|
|
|
|
* 2020-09-18 geniusgogo optimization design pin-index algorithm
|
2018-11-29 17:00:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <board.h>
|
|
|
|
#include "drv_gpio.h"
|
|
|
|
|
|
|
|
#ifdef RT_USING_PIN
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
#define PIN_NUM(port, no) (((((port) & 0xFu) << 4) | ((no) & 0xFu)))
|
|
|
|
#define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
|
|
|
|
#define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
|
|
|
|
|
2020-09-27 13:52:52 +08:00
|
|
|
#if defined(SOC_SERIES_STM32MP1)
|
|
|
|
#if defined(GPIOZ)
|
|
|
|
#define gpioz_port_base (175) /* PIN_STPORT_MAX * 16 - 16 */
|
|
|
|
#define PIN_STPORT(pin) ((pin > gpioz_port_base) ? ((GPIO_TypeDef *)(GPIOZ_BASE )) : ((GPIO_TypeDef *)(GPIOA_BASE + (0x1000u * PIN_PORT(pin)))))
|
|
|
|
#else
|
2020-10-31 16:07:52 +08:00
|
|
|
#define PIN_STPORT(pin) ((GPIO_TypeDef *)(GPIOA_BASE + (0x1000u * PIN_PORT(pin))))
|
2020-09-27 13:52:52 +08:00
|
|
|
#endif /* GPIOZ */
|
|
|
|
#else
|
2020-09-18 18:33:13 +08:00
|
|
|
#define PIN_STPORT(pin) ((GPIO_TypeDef *)(GPIOA_BASE + (0x400u * PIN_PORT(pin))))
|
2020-09-27 13:52:52 +08:00
|
|
|
#endif /* SOC_SERIES_STM32MP1 */
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
#define PIN_STPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
|
|
|
|
|
2020-09-04 10:23:08 +08:00
|
|
|
#if defined(GPIOZ)
|
2020-09-18 18:33:13 +08:00
|
|
|
#define __STM32_PORT_MAX 12u
|
|
|
|
#elif defined(GPIOK)
|
|
|
|
#define __STM32_PORT_MAX 11u
|
|
|
|
#elif defined(GPIOJ)
|
|
|
|
#define __STM32_PORT_MAX 10u
|
|
|
|
#elif defined(GPIOI)
|
|
|
|
#define __STM32_PORT_MAX 9u
|
|
|
|
#elif defined(GPIOH)
|
|
|
|
#define __STM32_PORT_MAX 8u
|
|
|
|
#elif defined(GPIOG)
|
|
|
|
#define __STM32_PORT_MAX 7u
|
|
|
|
#elif defined(GPIOF)
|
|
|
|
#define __STM32_PORT_MAX 6u
|
|
|
|
#elif defined(GPIOE)
|
|
|
|
#define __STM32_PORT_MAX 5u
|
|
|
|
#elif defined(GPIOD)
|
|
|
|
#define __STM32_PORT_MAX 4u
|
|
|
|
#elif defined(GPIOC)
|
|
|
|
#define __STM32_PORT_MAX 3u
|
|
|
|
#elif defined(GPIOB)
|
|
|
|
#define __STM32_PORT_MAX 2u
|
|
|
|
#elif defined(GPIOA)
|
|
|
|
#define __STM32_PORT_MAX 1u
|
|
|
|
#else
|
|
|
|
#define __STM32_PORT_MAX 0u
|
|
|
|
#error Unsupported STM32 GPIO peripheral.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PIN_STPORT_MAX __STM32_PORT_MAX
|
2018-11-29 17:00:22 +08:00
|
|
|
|
|
|
|
static const struct pin_irq_map pin_irq_map[] =
|
|
|
|
{
|
2019-01-27 13:11:15 +08:00
|
|
|
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0)
|
2018-12-26 10:43:16 +08:00
|
|
|
{GPIO_PIN_0, EXTI0_1_IRQn},
|
|
|
|
{GPIO_PIN_1, EXTI0_1_IRQn},
|
|
|
|
{GPIO_PIN_2, EXTI2_3_IRQn},
|
|
|
|
{GPIO_PIN_3, EXTI2_3_IRQn},
|
|
|
|
{GPIO_PIN_4, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_5, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_6, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_7, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_8, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_9, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_10, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_11, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_12, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_13, EXTI4_15_IRQn},
|
|
|
|
{GPIO_PIN_14, EXTI4_15_IRQn},
|
2020-09-18 18:33:13 +08:00
|
|
|
{GPIO_PIN_15, EXTI4_15_IRQn},
|
2021-11-15 10:26:14 +08:00
|
|
|
#elif defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32L5) || defined(SOC_SERIES_STM32U5)
|
2020-06-20 14:04:27 +08:00
|
|
|
{GPIO_PIN_0, EXTI0_IRQn},
|
|
|
|
{GPIO_PIN_1, EXTI1_IRQn},
|
|
|
|
{GPIO_PIN_2, EXTI2_IRQn},
|
|
|
|
{GPIO_PIN_3, EXTI3_IRQn},
|
|
|
|
{GPIO_PIN_4, EXTI4_IRQn},
|
|
|
|
{GPIO_PIN_5, EXTI5_IRQn},
|
|
|
|
{GPIO_PIN_6, EXTI6_IRQn},
|
|
|
|
{GPIO_PIN_7, EXTI7_IRQn},
|
|
|
|
{GPIO_PIN_8, EXTI8_IRQn},
|
|
|
|
{GPIO_PIN_9, EXTI9_IRQn},
|
|
|
|
{GPIO_PIN_10, EXTI10_IRQn},
|
|
|
|
{GPIO_PIN_11, EXTI11_IRQn},
|
|
|
|
{GPIO_PIN_12, EXTI12_IRQn},
|
|
|
|
{GPIO_PIN_13, EXTI13_IRQn},
|
|
|
|
{GPIO_PIN_14, EXTI14_IRQn},
|
2020-09-18 18:33:13 +08:00
|
|
|
{GPIO_PIN_15, EXTI15_IRQn},
|
2021-07-30 11:38:25 +08:00
|
|
|
#elif defined(SOC_SERIES_STM32F3)
|
|
|
|
{GPIO_PIN_0, EXTI0_IRQn},
|
|
|
|
{GPIO_PIN_1, EXTI1_IRQn},
|
|
|
|
{GPIO_PIN_2, EXTI2_TSC_IRQn},
|
|
|
|
{GPIO_PIN_3, EXTI3_IRQn},
|
|
|
|
{GPIO_PIN_4, EXTI4_IRQn},
|
|
|
|
{GPIO_PIN_5, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_6, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_7, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_8, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_9, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_10, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_11, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_12, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_13, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_14, EXTI15_10_IRQn},
|
2021-08-10 10:30:52 +08:00
|
|
|
{GPIO_PIN_15, EXTI15_10_IRQn},
|
2018-12-26 10:43:16 +08:00
|
|
|
#else
|
2018-11-29 17:00:22 +08:00
|
|
|
{GPIO_PIN_0, EXTI0_IRQn},
|
|
|
|
{GPIO_PIN_1, EXTI1_IRQn},
|
|
|
|
{GPIO_PIN_2, EXTI2_IRQn},
|
|
|
|
{GPIO_PIN_3, EXTI3_IRQn},
|
|
|
|
{GPIO_PIN_4, EXTI4_IRQn},
|
|
|
|
{GPIO_PIN_5, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_6, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_7, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_8, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_9, EXTI9_5_IRQn},
|
|
|
|
{GPIO_PIN_10, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_11, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_12, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_13, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_14, EXTI15_10_IRQn},
|
|
|
|
{GPIO_PIN_15, EXTI15_10_IRQn},
|
2018-12-26 10:43:16 +08:00
|
|
|
#endif
|
2018-11-29 17:00:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct rt_pin_irq_hdr pin_irq_hdr_tab[] =
|
|
|
|
{
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
{-1, 0, RT_NULL, RT_NULL},
|
|
|
|
};
|
2020-09-18 18:33:13 +08:00
|
|
|
static uint32_t pin_irq_enable_mask = 0;
|
2018-11-29 17:00:22 +08:00
|
|
|
|
|
|
|
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
|
|
|
|
|
2022-05-30 18:00:26 +08:00
|
|
|
/* e.g. PE.7 */
|
2020-09-11 11:16:42 +08:00
|
|
|
static rt_base_t stm32_pin_get(const char *name)
|
|
|
|
{
|
|
|
|
rt_base_t pin = 0;
|
|
|
|
int hw_port_num, hw_pin_num = 0;
|
2020-09-18 18:33:13 +08:00
|
|
|
int i, name_len;
|
2020-09-11 11:16:42 +08:00
|
|
|
|
|
|
|
name_len = rt_strlen(name);
|
|
|
|
|
|
|
|
if ((name_len < 4) || (name_len >= 6))
|
|
|
|
{
|
|
|
|
return -RT_EINVAL;
|
|
|
|
}
|
|
|
|
if ((name[0] != 'P') || (name[2] != '.'))
|
|
|
|
{
|
|
|
|
return -RT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((name[1] >= 'A') && (name[1] <= 'Z'))
|
|
|
|
{
|
|
|
|
hw_port_num = (int)(name[1] - 'A');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -RT_EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
for (i = 3; i < name_len; i++)
|
2020-09-11 11:16:42 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
hw_pin_num *= 10;
|
|
|
|
hw_pin_num += name[i] - '0';
|
2020-09-11 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
pin = PIN_NUM(hw_port_num, hw_pin_num);
|
2020-09-11 11:16:42 +08:00
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
return pin;
|
2020-09-11 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
static void stm32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
|
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
GPIO_TypeDef *gpio_port;
|
|
|
|
uint16_t gpio_pin;
|
2018-11-29 17:00:22 +08:00
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
if (PIN_PORT(pin) < PIN_STPORT_MAX)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
gpio_port = PIN_STPORT(pin);
|
|
|
|
gpio_pin = PIN_STPIN(pin);
|
2018-11-29 17:00:22 +08:00
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
HAL_GPIO_WritePin(gpio_port, gpio_pin, (GPIO_PinState)value);
|
|
|
|
}
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_pin_read(rt_device_t dev, rt_base_t pin)
|
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
GPIO_TypeDef *gpio_port;
|
|
|
|
uint16_t gpio_pin;
|
|
|
|
int value = PIN_LOW;
|
2018-11-29 17:00:22 +08:00
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
if (PIN_PORT(pin) < PIN_STPORT_MAX)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
gpio_port = PIN_STPORT(pin);
|
|
|
|
gpio_pin = PIN_STPIN(pin);
|
|
|
|
value = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
|
|
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure GPIO_InitStructure */
|
2020-09-18 18:33:13 +08:00
|
|
|
GPIO_InitStruct.Pin = PIN_STPIN(pin);
|
2018-11-29 17:00:22 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
|
|
|
|
if (mode == PIN_MODE_OUTPUT)
|
|
|
|
{
|
|
|
|
/* output setting */
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
}
|
|
|
|
else if (mode == PIN_MODE_INPUT)
|
|
|
|
{
|
|
|
|
/* input setting: not pull. */
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
}
|
|
|
|
else if (mode == PIN_MODE_INPUT_PULLUP)
|
|
|
|
{
|
|
|
|
/* input setting: pull up. */
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
}
|
|
|
|
else if (mode == PIN_MODE_INPUT_PULLDOWN)
|
|
|
|
{
|
|
|
|
/* input setting: pull down. */
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|
|
|
}
|
|
|
|
else if (mode == PIN_MODE_OUTPUT_OD)
|
|
|
|
{
|
|
|
|
/* output setting: od. */
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
HAL_GPIO_Init(PIN_STPORT(pin), &GPIO_InitStruct);
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rt_inline rt_int32_t bit2bitno(rt_uint32_t bit)
|
|
|
|
{
|
2022-03-20 15:46:33 +08:00
|
|
|
rt_uint8_t i;
|
2018-11-29 17:00:22 +08:00
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
if ((0x01 << i) == bit)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_inline const struct pin_irq_map *get_pin_irq_map(uint32_t pinbit)
|
|
|
|
{
|
|
|
|
rt_int32_t mapindex = bit2bitno(pinbit);
|
|
|
|
if (mapindex < 0 || mapindex >= ITEM_NUM(pin_irq_map))
|
|
|
|
{
|
|
|
|
return RT_NULL;
|
|
|
|
}
|
|
|
|
return &pin_irq_map[mapindex];
|
|
|
|
};
|
|
|
|
|
|
|
|
static rt_err_t stm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
|
|
|
|
rt_uint32_t mode, void (*hdr)(void *args), void *args)
|
|
|
|
{
|
|
|
|
rt_base_t level;
|
|
|
|
rt_int32_t irqindex = -1;
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
return -RT_ENOSYS;
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
|
|
|
|
irqindex = bit2bitno(PIN_STPIN(pin));
|
2018-11-29 17:00:22 +08:00
|
|
|
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
|
|
|
{
|
|
|
|
return RT_ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
if (pin_irq_hdr_tab[irqindex].pin == pin &&
|
2020-09-18 18:33:13 +08:00
|
|
|
pin_irq_hdr_tab[irqindex].hdr == hdr &&
|
|
|
|
pin_irq_hdr_tab[irqindex].mode == mode &&
|
|
|
|
pin_irq_hdr_tab[irqindex].args == args)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
if (pin_irq_hdr_tab[irqindex].pin != -1)
|
|
|
|
{
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
return RT_EBUSY;
|
|
|
|
}
|
|
|
|
pin_irq_hdr_tab[irqindex].pin = pin;
|
|
|
|
pin_irq_hdr_tab[irqindex].hdr = hdr;
|
|
|
|
pin_irq_hdr_tab[irqindex].mode = mode;
|
|
|
|
pin_irq_hdr_tab[irqindex].args = args;
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rt_err_t stm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
|
|
|
|
{
|
|
|
|
rt_base_t level;
|
|
|
|
rt_int32_t irqindex = -1;
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
return -RT_ENOSYS;
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
|
|
|
|
irqindex = bit2bitno(PIN_STPIN(pin));
|
2018-11-29 17:00:22 +08:00
|
|
|
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
|
|
|
{
|
|
|
|
return RT_ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
if (pin_irq_hdr_tab[irqindex].pin == -1)
|
|
|
|
{
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
pin_irq_hdr_tab[irqindex].pin = -1;
|
|
|
|
pin_irq_hdr_tab[irqindex].hdr = RT_NULL;
|
|
|
|
pin_irq_hdr_tab[irqindex].mode = 0;
|
|
|
|
pin_irq_hdr_tab[irqindex].args = RT_NULL;
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|
|
|
rt_uint32_t enabled)
|
|
|
|
{
|
|
|
|
const struct pin_irq_map *irqmap;
|
|
|
|
rt_base_t level;
|
|
|
|
rt_int32_t irqindex = -1;
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
|
2018-11-29 17:00:22 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
return -RT_ENOSYS;
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled == PIN_IRQ_ENABLE)
|
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
irqindex = bit2bitno(PIN_STPIN(pin));
|
2018-11-29 17:00:22 +08:00
|
|
|
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
|
|
|
{
|
|
|
|
return RT_ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
|
|
|
|
if (pin_irq_hdr_tab[irqindex].pin == -1)
|
|
|
|
{
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
return RT_ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
irqmap = &pin_irq_map[irqindex];
|
|
|
|
|
|
|
|
/* Configure GPIO_InitStructure */
|
2020-09-18 18:33:13 +08:00
|
|
|
GPIO_InitStruct.Pin = PIN_STPIN(pin);
|
2018-11-29 17:00:22 +08:00
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
switch (pin_irq_hdr_tab[irqindex].mode)
|
|
|
|
{
|
|
|
|
case PIN_IRQ_MODE_RISING:
|
2018-12-13 10:03:51 +08:00
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
2018-11-29 17:00:22 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
|
|
break;
|
|
|
|
case PIN_IRQ_MODE_FALLING:
|
2018-12-13 10:03:51 +08:00
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
2018-11-29 17:00:22 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
|
|
|
break;
|
|
|
|
case PIN_IRQ_MODE_RISING_FALLING:
|
2018-12-13 10:03:51 +08:00
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
2018-11-29 17:00:22 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
|
|
|
break;
|
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
HAL_GPIO_Init(PIN_STPORT(pin), &GPIO_InitStruct);
|
2018-11-29 17:00:22 +08:00
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(irqmap->irqno, 5, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(irqmap->irqno);
|
2018-12-23 21:04:32 +08:00
|
|
|
pin_irq_enable_mask |= irqmap->pinbit;
|
2018-11-29 17:00:22 +08:00
|
|
|
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
}
|
|
|
|
else if (enabled == PIN_IRQ_DISABLE)
|
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
irqmap = get_pin_irq_map(PIN_STPIN(pin));
|
2018-11-29 17:00:22 +08:00
|
|
|
if (irqmap == RT_NULL)
|
|
|
|
{
|
|
|
|
return RT_ENOSYS;
|
|
|
|
}
|
|
|
|
|
2018-12-23 21:04:32 +08:00
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
HAL_GPIO_DeInit(PIN_STPORT(pin), PIN_STPIN(pin));
|
2018-12-23 21:04:32 +08:00
|
|
|
|
|
|
|
pin_irq_enable_mask &= ~irqmap->pinbit;
|
2019-02-15 10:43:09 +08:00
|
|
|
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0)
|
2020-09-18 18:33:13 +08:00
|
|
|
if ((irqmap->pinbit >= GPIO_PIN_0) && (irqmap->pinbit <= GPIO_PIN_1))
|
2019-01-08 09:52:16 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
if (!(pin_irq_enable_mask & (GPIO_PIN_0 | GPIO_PIN_1)))
|
|
|
|
{
|
2019-01-08 09:52:16 +08:00
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
|
|
|
}
|
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
else if ((irqmap->pinbit >= GPIO_PIN_2) && (irqmap->pinbit <= GPIO_PIN_3))
|
2019-01-08 09:52:16 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
if (!(pin_irq_enable_mask & (GPIO_PIN_2 | GPIO_PIN_3)))
|
|
|
|
{
|
2019-01-08 09:52:16 +08:00
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
|
|
|
}
|
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
else if ((irqmap->pinbit >= GPIO_PIN_4) && (irqmap->pinbit <= GPIO_PIN_15))
|
2019-01-08 09:52:16 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
if (!(pin_irq_enable_mask & (GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 |
|
|
|
|
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15)))
|
|
|
|
{
|
2019-01-08 09:52:16 +08:00
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
}
|
2019-01-08 09:52:16 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
2020-09-18 18:33:13 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ((irqmap->pinbit >= GPIO_PIN_5) && (irqmap->pinbit <= GPIO_PIN_9))
|
2018-12-23 21:04:32 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
if (!(pin_irq_enable_mask & (GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9)))
|
|
|
|
{
|
2018-12-23 21:04:32 +08:00
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
|
|
|
}
|
|
|
|
}
|
2020-09-18 18:33:13 +08:00
|
|
|
else if ((irqmap->pinbit >= GPIO_PIN_10) && (irqmap->pinbit <= GPIO_PIN_15))
|
2018-12-23 21:04:32 +08:00
|
|
|
{
|
2020-09-18 18:33:13 +08:00
|
|
|
if (!(pin_irq_enable_mask & (GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15)))
|
|
|
|
{
|
2018-12-23 21:04:32 +08:00
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HAL_NVIC_DisableIRQ(irqmap->irqno);
|
2020-09-18 18:33:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rt_hw_interrupt_enable(level);
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-08 09:52:16 +08:00
|
|
|
return -RT_ENOSYS;
|
2018-11-29 17:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
const static struct rt_pin_ops _stm32_pin_ops =
|
|
|
|
{
|
|
|
|
stm32_pin_mode,
|
|
|
|
stm32_pin_write,
|
|
|
|
stm32_pin_read,
|
|
|
|
stm32_pin_attach_irq,
|
|
|
|
stm32_pin_dettach_irq,
|
|
|
|
stm32_pin_irq_enable,
|
2020-09-11 11:16:42 +08:00
|
|
|
stm32_pin_get,
|
2018-11-29 17:00:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
rt_inline void pin_irq_hdr(int irqno)
|
|
|
|
{
|
|
|
|
if (pin_irq_hdr_tab[irqno].hdr)
|
|
|
|
{
|
|
|
|
pin_irq_hdr_tab[irqno].hdr(pin_irq_hdr_tab[irqno].args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 14:04:27 +08:00
|
|
|
#if defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32MP1)
|
2019-02-15 10:43:09 +08:00
|
|
|
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
|
|
|
|
{
|
|
|
|
pin_irq_hdr(bit2bitno(GPIO_Pin));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
|
|
|
|
{
|
|
|
|
pin_irq_hdr(bit2bitno(GPIO_Pin));
|
|
|
|
}
|
|
|
|
#else
|
2018-11-29 17:00:22 +08:00
|
|
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|
|
|
{
|
|
|
|
pin_irq_hdr(bit2bitno(GPIO_Pin));
|
|
|
|
}
|
2019-02-15 10:43:09 +08:00
|
|
|
#endif
|
2018-11-29 17:00:22 +08:00
|
|
|
|
2019-09-13 02:13:51 +08:00
|
|
|
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32L0)
|
2019-01-08 09:52:16 +08:00
|
|
|
void EXTI0_1_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI2_3_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
void EXTI4_15_IRQHandler(void)
|
|
|
|
{
|
2019-11-27 14:08:42 +08:00
|
|
|
rt_interrupt_enter();
|
2019-01-08 09:52:16 +08:00
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_7);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15);
|
2019-11-27 14:08:42 +08:00
|
|
|
rt_interrupt_leave();
|
2019-01-08 09:52:16 +08:00
|
|
|
}
|
|
|
|
|
2021-11-15 10:26:14 +08:00
|
|
|
#elif defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32U5)
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI0_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI1_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI2_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI3_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI4_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI5_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI6_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI7_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_7);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI8_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI9_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI10_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI11_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI12_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI13_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI14_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 18:33:13 +08:00
|
|
|
void EXTI15_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15);
|
|
|
|
rt_interrupt_leave();
|
2020-06-20 14:04:27 +08:00
|
|
|
}
|
|
|
|
|
2019-01-08 09:52:16 +08:00
|
|
|
#else
|
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
void EXTI0_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI1_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI2_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI3_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI4_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI9_5_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_7);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXTI15_10_IRQHandler(void)
|
|
|
|
{
|
|
|
|
rt_interrupt_enter();
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
|
|
|
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15);
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
2019-01-08 09:52:16 +08:00
|
|
|
#endif
|
2018-12-26 10:43:16 +08:00
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
int rt_hw_pin_init(void)
|
|
|
|
{
|
|
|
|
#if defined(__HAL_RCC_GPIOA_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
|
#endif
|
2020-09-18 18:33:13 +08:00
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
#if defined(__HAL_RCC_GPIOB_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
|
#endif
|
2020-09-18 18:33:13 +08:00
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
#if defined(__HAL_RCC_GPIOC_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
#endif
|
2020-09-18 18:33:13 +08:00
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
#if defined(__HAL_RCC_GPIOD_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAL_RCC_GPIOE_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAL_RCC_GPIOF_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAL_RCC_GPIOG_CLK_ENABLE)
|
2019-04-24 09:35:06 +08:00
|
|
|
#ifdef SOC_SERIES_STM32L4
|
|
|
|
HAL_PWREx_EnableVddIO2();
|
|
|
|
#endif
|
2018-11-29 17:00:22 +08:00
|
|
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAL_RCC_GPIOH_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAL_RCC_GPIOI_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOI_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAL_RCC_GPIOJ_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
2019-02-18 10:08:12 +08:00
|
|
|
#if defined(__HAL_RCC_GPIOK_CLK_ENABLE)
|
|
|
|
__HAL_RCC_GPIOK_CLK_ENABLE();
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
return rt_device_pin_register("pin", &_stm32_pin_ops, RT_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* RT_USING_PIN */
|