You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.2 KiB

  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 <hal.h>
  19. #ifndef SERIAL_DRIVER
  20. # define SERIAL_DRIVER SD1
  21. #endif
  22. #ifndef SD1_TX_PIN
  23. # define SD1_TX_PIN A9
  24. #endif
  25. #ifndef SD1_RX_PIN
  26. # define SD1_RX_PIN A10
  27. #endif
  28. #ifndef SD1_CTS_PIN
  29. # define SD1_CTS_PIN A11
  30. #endif
  31. #ifndef SD1_RTS_PIN
  32. # define SD1_RTS_PIN A12
  33. #endif
  34. #ifdef USE_GPIOV1
  35. # ifndef SD1_TX_PAL_MODE
  36. # define SD1_TX_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
  37. # endif
  38. # ifndef SD1_RX_PAL_MODE
  39. # define SD1_RX_PAL_MODE PAL_MODE_INPUT
  40. # endif
  41. # ifndef SD1_CTS_PAL_MODE
  42. # define SD1_CTS_PAL_MODE PAL_MODE_INPUT
  43. # endif
  44. # ifndef SD1_RTS_PAL_MODE
  45. # define SD1_RTS_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
  46. # endif
  47. #else
  48. # ifndef SD1_TX_PAL_MODE
  49. # define SD1_TX_PAL_MODE 7
  50. # endif
  51. # ifndef SD1_RX_PAL_MODE
  52. # define SD1_RX_PAL_MODE 7
  53. # endif
  54. # ifndef SD1_CTS_PAL_MODE
  55. # define SD1_CTS_PAL_MODE 7
  56. # endif
  57. # ifndef SD1_RTS_PAL_MODE
  58. # define SD1_RTS_PAL_MODE 7
  59. # endif
  60. #endif
  61. #ifndef SD1_CR1
  62. # define SD1_CR1 0
  63. #endif
  64. #ifndef SD1_CR2
  65. # define SD1_CR2 0
  66. #endif
  67. #ifndef SD1_CR3
  68. # define SD1_CR3 0
  69. #endif
  70. #ifndef SD1_WRDLEN
  71. # define SD1_WRDLEN 3
  72. #endif
  73. #ifndef SD1_STPBIT
  74. # define SD1_STPBIT 0
  75. #endif
  76. #ifndef SD1_PARITY
  77. # define SD1_PARITY 0
  78. #endif
  79. #ifndef SD1_ATFLCT
  80. # define SD1_ATFLCT 0
  81. #endif
  82. void uart_init(uint32_t baud);
  83. void uart_write(uint8_t data);
  84. uint8_t uart_read(void);
  85. void uart_transmit(const uint8_t *data, uint16_t length);
  86. void uart_receive(uint8_t *data, uint16_t length);
  87. bool uart_available(void);