drv_usart.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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-06-20 RiceChen the first version
  9. */
  10. #ifndef __DRV_USART_H__
  11. #define __DRV_USART_H__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #include "gd32f3x0.h"
  15. #include "gd32f3x0_usart.h"
  16. #include "gd32f3x0_exti.h"
  17. struct gd32_usart_config
  18. {
  19. char *dev_name;
  20. rt_uint32_t periph;
  21. IRQn_Type irqn;
  22. rcu_periph_enum per_clk;
  23. rcu_periph_enum tx_gpio_clk;
  24. rcu_periph_enum rx_gpio_clk;
  25. rt_uint32_t tx_port;
  26. rt_uint32_t tx_pin;
  27. rt_uint32_t rx_port;
  28. rt_uint32_t rx_pin;
  29. };
  30. struct gd32_usart_bus
  31. {
  32. struct rt_serial_device serial;
  33. struct gd32_usart_config *config;
  34. };
  35. #ifdef BSP_USING_UART0
  36. #define UART0_BUS_CONFIG \
  37. { \
  38. .dev_name = "uart0", \
  39. .periph = USART0, \
  40. .irqn = USART0_IRQn, \
  41. .per_clk = RCU_USART0, \
  42. .tx_gpio_clk = RCU_GPIOA, \
  43. .rx_gpio_clk = RCU_GPIOA, \
  44. .tx_port = GPIOA, \
  45. .tx_pin = GPIO_PIN_9, \
  46. .rx_port = GPIOA, \
  47. .rx_pin = GPIO_PIN_10, \
  48. }
  49. #endif /* BSP_USING_UART0 */
  50. #ifdef BSP_USING_UART1
  51. #define UART1_BUS_CONFIG \
  52. { \
  53. .dev_name = "uart1", \
  54. .periph = USART1, \
  55. .irqn = USART1_IRQn, \
  56. .per_clk = RCU_USART1, \
  57. .tx_gpio_clk = RCU_GPIOA, \
  58. .rx_gpio_clk = RCU_GPIOA, \
  59. .tx_port = GPIOA, \
  60. .tx_pin = GPIO_PIN_2, \
  61. .rx_port = GPIOA, \
  62. .rx_pin = GPIO_PIN_3, \
  63. }
  64. #endif /* BSP_USING_UART1 */
  65. #endif