drv_gpio.h 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. * 2020-12-27 iysheng first release
  9. */
  10. #ifndef __DRV_GPIO_H__
  11. #define __DRV_GPIO_H__
  12. #include <rtthread.h>
  13. #include <rthw.h>
  14. #include <rtdevice.h>
  15. #include <board.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define __GD32_PORT(port) GPIO##port##_BASE
  20. #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIOA_BASE)/(0x0400UL) )) + PIN)
  21. #define PIN_NUM(port, no) (((((port) & 0xFu) << 4) | ((no) & 0xFu)))
  22. #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
  23. #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
  24. #define PIN_GDPORT(pin) ((GPIO_TypeDef *)(GPIOA_BASE + (0x400u * PIN_PORT(pin))))
  25. #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
  26. struct pin_irq_map
  27. {
  28. rt_uint16_t pinbit;
  29. IRQn_Type irqno;
  30. };
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. #endif /* __DRV_GPIO_H__ */