drv_gpio.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2025, 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. #elif defined SOC_SERIES_GD32H7xx
  27. #include "gd32h7xx_gpio.h"
  28. #elif defined SOC_SERIES_GD32E50x
  29. #include "gd32e50x_gpio.h"
  30. #elif defined SOC_SERIES_GD32F5xx
  31. #include "gd32f5xx_gpio.h"
  32. #elif defined SOC_SERIES_GD32E23x
  33. #include "gd32e23x_gpio.h"
  34. #endif
  35. #define __GD32_PORT(port) GPIO##port
  36. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
  37. #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
  38. GPIO##port, GPIO_PIN_##pin, \
  39. EXTI_SOURCE_GPIO##port, \
  40. EXTI_SOURCE_PIN##pin}
  41. #else
  42. #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
  43. GPIO##port, GPIO_PIN_##pin, \
  44. GPIO_PORT_SOURCE_GPIO##port, \
  45. GPIO_PIN_SOURCE_##pin}
  46. #endif
  47. #define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0}
  48. #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN)
  49. #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
  50. #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
  51. #define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin)))
  52. #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
  53. struct pin_index
  54. {
  55. rt_int16_t index;
  56. rcu_periph_enum clk;
  57. rt_uint32_t gpio_periph;
  58. rt_uint32_t pin;
  59. rt_uint8_t port_src;
  60. rt_uint8_t pin_src;
  61. };
  62. struct pin_irq_map
  63. {
  64. rt_uint16_t pinbit;
  65. IRQn_Type irqno;
  66. };
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif /* __DRV_GPIO_H__ */