drv_gpio.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_GD32VF103V
  19. #include "gd32vf103_gpio.h"
  20. #endif
  21. #define __GD32_PORT(port) GPIO##port
  22. #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
  23. GPIO##port, GPIO_PIN_##pin, \
  24. GPIO_PORT_SOURCE_GPIO##port, \
  25. GPIO_PIN_SOURCE_##pin}
  26. #define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0}
  27. #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN)
  28. #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
  29. #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
  30. #define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin)))
  31. #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(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__ */