drv_uart.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2006-2018, Synwit Technology Co.,Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-12-10 Zohar_Lee first version
  9. * 2020-07-10 lik rewrite
  10. */
  11. #ifndef __DRV_UART_H__
  12. #define __DRV_UART_H__
  13. #include "board.h"
  14. /* swm config class */
  15. struct swm_uart_cfg
  16. {
  17. const char *name;
  18. UART_TypeDef *UARTx;
  19. IRQn_Type irq;
  20. UART_InitStructure uart_initstruct;
  21. };
  22. /* swm uart dirver class */
  23. struct swm_uart
  24. {
  25. struct swm_uart_cfg *cfg;
  26. struct rt_serial_device serial_device;
  27. };
  28. #ifdef BSP_USING_UART0
  29. #ifndef UART0_CFG
  30. #define UART0_CFG \
  31. { \
  32. .name = "uart0", \
  33. .UARTx = UART0, \
  34. .irq = UART0_IRQn, \
  35. .uart_initstruct.Baudrate = 115200, \
  36. .uart_initstruct.DataBits = UART_DATA_8BIT, \
  37. .uart_initstruct.Parity = UART_PARITY_NONE, \
  38. .uart_initstruct.StopBits = UART_STOP_1BIT, \
  39. .uart_initstruct.RXThreshold = 0, \
  40. .uart_initstruct.RXThresholdIEn = 1, \
  41. .uart_initstruct.TXThresholdIEn = 0, \
  42. .uart_initstruct.TimeoutTime = 10, \
  43. .uart_initstruct.TimeoutIEn = 1, \
  44. }
  45. #endif /* UART0_CFG */
  46. #endif /* BSP_USING_UART0 */
  47. #ifdef BSP_USING_UART1
  48. #ifndef UART1_CFG
  49. #define UART1_CFG \
  50. { \
  51. .name = "uart1", \
  52. .UARTx = UART1, \
  53. .irq = UART1_IRQn, \
  54. .uart_initstruct.Baudrate = 115200, \
  55. .uart_initstruct.DataBits = UART_DATA_8BIT, \
  56. .uart_initstruct.Parity = UART_PARITY_NONE, \
  57. .uart_initstruct.StopBits = UART_STOP_1BIT, \
  58. .uart_initstruct.RXThreshold = 0, \
  59. .uart_initstruct.RXThresholdIEn = 1, \
  60. .uart_initstruct.TXThresholdIEn = 0, \
  61. .uart_initstruct.TimeoutTime = 10, \
  62. .uart_initstruct.TimeoutIEn = 1, \
  63. }
  64. #endif /* UART1_CFG */
  65. #endif /* BSP_USING_UART1 */
  66. #ifdef BSP_USING_UART2
  67. #ifndef UART2_CFG
  68. #define UART2_CFG \
  69. { \
  70. .name = "uart2", \
  71. .UARTx = UART2, \
  72. .irq = UART2_IRQn, \
  73. .uart_initstruct.Baudrate = 115200, \
  74. .uart_initstruct.DataBits = UART_DATA_8BIT, \
  75. .uart_initstruct.Parity = UART_PARITY_NONE, \
  76. .uart_initstruct.StopBits = UART_STOP_1BIT, \
  77. .uart_initstruct.RXThreshold = 0, \
  78. .uart_initstruct.RXThresholdIEn = 1, \
  79. .uart_initstruct.TXThresholdIEn = 0, \
  80. .uart_initstruct.TimeoutTime = 10, \
  81. .uart_initstruct.TimeoutIEn = 1, \
  82. }
  83. #endif /* UART2_CFG */
  84. #endif /* BSP_USING_UART2 */
  85. #ifdef BSP_USING_UART3
  86. #ifndef UART3_CFG
  87. #define UART3_CFG \
  88. { \
  89. .name = "uart3", \
  90. .UARTx = UART3, \
  91. .irq = UART3_IRQn, \
  92. .uart_initstruct.Baudrate = 115200, \
  93. .uart_initstruct.DataBits = UART_DATA_8BIT, \
  94. .uart_initstruct.Parity = UART_PARITY_NONE, \
  95. .uart_initstruct.StopBits = UART_STOP_1BIT, \
  96. .uart_initstruct.RXThreshold = 0, \
  97. .uart_initstruct.RXThresholdIEn = 1, \
  98. .uart_initstruct.TXThresholdIEn = 0, \
  99. .uart_initstruct.TimeoutTime = 10, \
  100. .uart_initstruct.TimeoutIEn = 1, \
  101. }
  102. #endif /* UART3_CFG */
  103. #endif /* BSP_USING_UART3 */
  104. int rt_hw_serial_init(void);
  105. #endif /* __DRV_UART_H__ */