drv_usart.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. *
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2021-9-1 DongBowen first version
  8. */
  9. #ifndef __DRV_USART_H__
  10. #define __DRV_USART_H__
  11. #include <rtthread.h>
  12. #include "rtdevice.h"
  13. #include "board_config.h"
  14. /* hc config class */
  15. struct hc_uart_cfg
  16. {
  17. const char *name;
  18. M0P_UART_TypeDef *uart;
  19. en_sysctrl_peripheral_gate_t uart_periph;
  20. IRQn_Type irqn;
  21. en_gpio_port_t rx_port;
  22. en_gpio_pin_t rx_pin;
  23. en_gpio_af_t rx_af;
  24. en_gpio_port_t tx_port;
  25. en_gpio_pin_t tx_pin;
  26. en_gpio_af_t tx_af;
  27. };
  28. /* hc uart dirver class */
  29. struct hc_uart
  30. {
  31. struct hc_uart_cfg *cfg;
  32. struct rt_serial_device serial_device;
  33. };
  34. #ifdef BSP_USING_UART0
  35. #ifndef UART0_CFG
  36. #define UART0_CFG \
  37. { \
  38. .name = "uart0", \
  39. .uart = M0P_UART0, \
  40. .uart_periph = SysctrlPeripheralUart0, \
  41. .irqn = UART0_2_IRQn, \
  42. .rx_port = UART0_RX_PORT, \
  43. .rx_pin = UART0_RX_PIN, \
  44. .rx_af = UART0_RX_AF, \
  45. .tx_port = UART0_TX_PORT, \
  46. .tx_pin = UART0_TX_PIN, \
  47. .tx_af = UART0_TX_AF, \
  48. }
  49. #endif /* UART0_CFG */
  50. #endif /* BSP_USING_UART0 */
  51. #ifdef BSP_USING_UART1
  52. #ifndef UART1_CFG
  53. #define UART1_CFG \
  54. { \
  55. .name = "uart1", \
  56. .uart = M0P_UART1, \
  57. .uart_periph = SysctrlPeripheralUart1, \
  58. .irqn = UART1_3_IRQn, \
  59. .rx_port = UART1_RX_PORT, \
  60. .rx_pin = UART1_RX_PIN, \
  61. .rx_af = UART1_RX_AF, \
  62. .tx_port = UART1_TX_PORT, \
  63. .tx_pin = UART1_TX_PIN, \
  64. .tx_af = UART1_TX_AF, \
  65. }
  66. #endif /* UART1_CFG */
  67. #endif /* BSP_USING_UART1 */
  68. int rt_hw_uart_init(void);
  69. #endif /* __DRV_USART_H__ */