drv_usart.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * 2025-10-09 WangShun optimize the serial driver
  10. * 2025-11-13 kurisaw general GD driver adaptation
  11. */
  12. #ifndef __DRV_USART_H__
  13. #define __DRV_USART_H__
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <board.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #if !defined(SOC_SERIES_GD32H7xx) || !defined(SOC_SERIES_GD32H75E)
  21. #undef RT_SERIAL_USING_DMA
  22. #endif
  23. #define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
  24. #define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
  25. #ifdef RT_SERIAL_USING_DMA
  26. typedef struct
  27. {
  28. /* dma peripheral */
  29. uint32_t dma_periph;
  30. /* dma channel */
  31. dma_channel_enum dma_ch;
  32. #if defined(SOC_SERIES_GD32H7xx) || defined(SOC_SERIES_GD32H75E)
  33. /* rx dma request */
  34. uint32_t dma_mux_req_rx;
  35. #endif
  36. /* dma flag */
  37. uint32_t rx_flag;
  38. /* dma irq channel */
  39. uint8_t rx_irq_ch;
  40. /* setting receive len */
  41. rt_size_t setting_recv_len;
  42. /* last receive index */
  43. rt_size_t last_recv_index;
  44. } gd32_uart_dma;
  45. #endif
  46. /* GD32 uart driver */
  47. struct gd32_uart
  48. {
  49. uint32_t uart_periph; /* Instance */
  50. IRQn_Type irqn; /* irqn */
  51. rcu_periph_enum per_clk; /* uart_clk */
  52. const char *tx_pin_name; /* tx pin name */
  53. const char *rx_pin_name; /* rx pin name */
  54. const char *alternate; /* pin alternate */
  55. #ifdef RT_SERIAL_USING_DMA
  56. gd32_uart_dma *uart_dma;
  57. #ifdef RT_SERIAL_USING_TX_DMA
  58. gd32_uart_dma *uart_tx_dma;
  59. #endif
  60. #endif
  61. struct rt_serial_device * serial; /* serial device */
  62. char *device_name;
  63. };
  64. int rt_hw_usart_init(void);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif /* __DRV_USART_H__ */