uart.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Copyright 2021
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include <hal.h>
  20. #include "gpio.h"
  21. #include "chibios_config.h"
  22. #ifndef SERIAL_DRIVER
  23. # define SERIAL_DRIVER SD1
  24. #endif
  25. #ifndef SD1_TX_PIN
  26. # define SD1_TX_PIN A9
  27. #endif
  28. #ifndef SD1_RX_PIN
  29. # define SD1_RX_PIN A10
  30. #endif
  31. #ifndef SD1_CTS_PIN
  32. # define SD1_CTS_PIN A11
  33. #endif
  34. #ifndef SD1_RTS_PIN
  35. # define SD1_RTS_PIN A12
  36. #endif
  37. #ifdef USE_GPIOV1
  38. # ifndef SD1_TX_PAL_MODE
  39. # define SD1_TX_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
  40. # endif
  41. # ifndef SD1_RX_PAL_MODE
  42. # define SD1_RX_PAL_MODE PAL_MODE_INPUT
  43. # endif
  44. # ifndef SD1_CTS_PAL_MODE
  45. # define SD1_CTS_PAL_MODE PAL_MODE_INPUT
  46. # endif
  47. # ifndef SD1_RTS_PAL_MODE
  48. # define SD1_RTS_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
  49. # endif
  50. #else
  51. # ifndef SD1_TX_PAL_MODE
  52. # define SD1_TX_PAL_MODE 7
  53. # endif
  54. # ifndef SD1_RX_PAL_MODE
  55. # define SD1_RX_PAL_MODE 7
  56. # endif
  57. # ifndef SD1_CTS_PAL_MODE
  58. # define SD1_CTS_PAL_MODE 7
  59. # endif
  60. # ifndef SD1_RTS_PAL_MODE
  61. # define SD1_RTS_PAL_MODE 7
  62. # endif
  63. #endif
  64. #ifndef SD1_CR1
  65. # define SD1_CR1 0
  66. #endif
  67. #ifndef SD1_CR2
  68. # define SD1_CR2 0
  69. #endif
  70. #ifndef SD1_CR3
  71. # define SD1_CR3 0
  72. #endif
  73. #ifndef SD1_WRDLEN
  74. # define SD1_WRDLEN 3
  75. #endif
  76. #ifndef SD1_STPBIT
  77. # define SD1_STPBIT 0
  78. #endif
  79. #ifndef SD1_PARITY
  80. # define SD1_PARITY 0
  81. #endif
  82. #ifndef SD1_ATFLCT
  83. # define SD1_ATFLCT 0
  84. #endif
  85. void uart_init(uint32_t baud);
  86. void uart_write(uint8_t data);
  87. uint8_t uart_read(void);
  88. void uart_transmit(const uint8_t *data, uint16_t length);
  89. void uart_receive(uint8_t *data, uint16_t length);
  90. bool uart_available(void);