drv_gpio.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-08-20 BruceOu the first version
  9. */
  10. #ifndef __DRV_GPIO_H__
  11. #define __DRV_GPIO_H__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #include <board.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #if defined SOC_SERIES_GD32F10x
  19. #include "gd32f10x_gpio.h"
  20. #elif defined SOC_SERIES_GD32F20x
  21. #include "gd32f20x_gpio.h"
  22. #elif defined SOC_SERIES_GD32F30x
  23. #include "gd32f30x_gpio.h"
  24. #elif defined SOC_SERIES_GD32F4xx
  25. #include "gd32f4xx_gpio.h"
  26. #endif
  27. #define __GD32_PORT(port) GPIO##port
  28. #if defined SOC_SERIES_GD32F4xx
  29. #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
  30. GPIO##port, GPIO_PIN_##pin, \
  31. EXTI_SOURCE_GPIO##port, \
  32. EXTI_SOURCE_PIN##pin}
  33. #else
  34. #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
  35. GPIO##port, GPIO_PIN_##pin, \
  36. GPIO_PORT_SOURCE_GPIO##port, \
  37. GPIO_PIN_SOURCE_##pin}
  38. #endif
  39. #define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0}
  40. #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN)
  41. #define PIN_NUM(port, no) (((((port)&0xFu) << 4) | ((no)&0xFu)))
  42. #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
  43. #define PIN_NO(pin) ((uint8_t)((pin)&0xFu))
  44. #define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin))) /* gpio_periph GPIOA~GPIOG */
  45. #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin))) /* GPIO_PIN_0~GPIO_PIN_15 */
  46. #define PIN_GDRCU(pin) RCU_REGIDX_BIT(APB2EN_REG_OFFSET, PIN_PORT(pin) + 2) /* pin gpio外设时钟 */
  47. struct pin_index
  48. {
  49. rt_int16_t index;
  50. rcu_periph_enum clk;
  51. rt_uint32_t gpio_periph;
  52. rt_uint32_t pin;
  53. rt_uint8_t port_src;
  54. rt_uint8_t pin_src;
  55. };
  56. struct pin_irq_map
  57. {
  58. rt_uint16_t pinbit;
  59. IRQn_Type irqno;
  60. };
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* __DRV_GPIO_H__ */