drv_gpio.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2006-2021, 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. #define GPIOA_BASE (GPIO_BASE + 0x00000800UL)
  19. #define GPIOB_BASE (GPIO_BASE + 0x00000C00UL)
  20. #define GPIOC_BASE (GPIO_BASE + 0x00001000UL)
  21. #define GPIOD_BASE (GPIO_BASE + 0x00001400UL)
  22. #define GPIOE_BASE (GPIO_BASE + 0x00001800UL)
  23. #define GPIOF_BASE (GPIO_BASE + 0x00001C00UL)
  24. #define GPIOG_BASE (GPIO_BASE + 0x00002000UL)
  25. #define __GD32_PORT(port) GPIO##port##_BASE
  26. #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
  27. GPIO##port, GPIO_PIN_##pin, \
  28. EXTI_SOURCE_GPIO##port, \
  29. EXTI_SOURCE_PIN##pin}
  30. #define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0}
  31. #define GET_PIN(PORTx, PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIOA_BASE)/(0x0400UL) )) + PIN)
  32. struct pin_index
  33. {
  34. rt_int16_t index;
  35. rcu_periph_enum clk;
  36. rt_uint32_t gpio_periph;
  37. rt_uint32_t pin;
  38. rt_uint8_t port_src;
  39. rt_uint8_t pin_src;
  40. };
  41. struct pin_irq_map
  42. {
  43. rt_uint16_t pinbit;
  44. IRQn_Type irqno;
  45. };
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #endif /* __DRV_GPIO_H__ */