drv_usart.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2006-2025, 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 first implementation
  9. */
  10. #ifndef __DRV_USART_H__
  11. #define __DRV_USART_H__
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <board.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
  19. #define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
  20. /* GD32 uart driver */
  21. /* Todo: compress uart info */
  22. struct gd32_uart
  23. {
  24. uint32_t uart_periph; /* Todo: 3bits */
  25. IRQn_Type irqn; /* Todo: 7bits */
  26. rcu_periph_enum per_clk; /* Todo: 5bits */
  27. rcu_periph_enum tx_gpio_clk; /* Todo: 5bits */
  28. rcu_periph_enum rx_gpio_clk; /* Todo: 5bits */
  29. uint32_t tx_port; /* Todo: 4bits */
  30. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
  31. uint16_t tx_af; /* Todo: 4bits */
  32. #elif defined SOC_SERIES_GD32E50x
  33. uint32_t tx_af; /* alternate1 cfg */
  34. #endif
  35. uint16_t tx_pin; /* Todo: 4bits */
  36. uint32_t rx_port; /* Todo: 4bits */
  37. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
  38. uint16_t rx_af; /* Todo: 4bits */
  39. #elif defined SOC_SERIES_GD32E50x
  40. uint32_t rx_af; /* alternate1 cfg */
  41. #endif
  42. uint16_t rx_pin; /* Todo: 4bits */
  43. #if defined SOC_SERIES_GD32E50x
  44. uint32_t uart_remap; /* remap */
  45. #endif
  46. struct rt_serial_device * serial;
  47. char *device_name;
  48. };
  49. int rt_hw_usart_init(void);
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif /* __DRV_USART_H__ */