drv_gpio.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
  42. #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
  43. #define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin)))
  44. #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
  45. struct pin_index
  46. {
  47. rt_int16_t index;
  48. rcu_periph_enum clk;
  49. rt_uint32_t gpio_periph;
  50. rt_uint32_t pin;
  51. rt_uint8_t port_src;
  52. rt_uint8_t pin_src;
  53. };
  54. struct pin_irq_map
  55. {
  56. rt_uint16_t pinbit;
  57. IRQn_Type irqno;
  58. };
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* __DRV_GPIO_H__ */