drv_gpio.h 836 B

123456789101112131415161718192021222324252627282930313233343536373839
  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-23 lianzhian first implementation.
  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
  20. #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_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_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
  25. #ifdef __cplusplus
  26. }
  27. #endif
  28. #endif /* __DRV_GPIO_H__ */