esp_rom_uart.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdint.h>
  19. #define ESP_ROM_CDC_ACM_WORK_BUF_MIN 128
  20. typedef enum {
  21. ESP_ROM_UART_0,
  22. ESP_ROM_UART_1,
  23. ESP_ROM_UART_USB
  24. } esp_rom_uart_num_t;
  25. /**
  26. * @brief Wait for UART TX FIFO is empty and all data has been sent out.
  27. *
  28. * @param uart_no UART port number
  29. */
  30. void esp_rom_uart_tx_wait_idle(uint8_t uart_no);
  31. /**
  32. * @brief Set clock source and baud rate for UART.
  33. *
  34. * @param uart_no UART port number
  35. * @param clock_hz Source clock (in Hz)
  36. * @param baud_rate Baud rate to set
  37. */
  38. void esp_rom_uart_set_clock_baudrate(uint8_t uart_no, uint32_t clock_hz, uint32_t baud_rate);
  39. /**
  40. * @brief Wait until UART TX FIFO is empty (i.e. flush TX FIFO)
  41. *
  42. * @param uart_no UART port number
  43. */
  44. void esp_rom_uart_flush_tx(uint8_t uart_no);
  45. /**
  46. * @brief Transmit one character to the console channel.
  47. *
  48. * @param c Character to send
  49. * @return
  50. * - 0 on success
  51. * - 1 on failure
  52. */
  53. int esp_rom_uart_tx_one_char(uint8_t c);
  54. /**
  55. * @brief Transmit one character to the console channel.
  56. * @note This function is a wrapper over esp_rom_uart_tx_one_char, it can help handle line ending issue by replacing '\n' with '\r\n'.
  57. *
  58. * @param c Character to send
  59. */
  60. void esp_rom_uart_putc(char c);
  61. /**
  62. * @brief Get one character from the console channel.
  63. *
  64. * @param c Where to store the character
  65. * @return
  66. * - 0 on success
  67. * - 1 on failure or no data available
  68. */
  69. int esp_rom_uart_rx_one_char(uint8_t *c);
  70. /**
  71. * @brief Get one line of string from console channel (line ending won't be stored in the buffer).
  72. *
  73. * @param str Where to store the string
  74. * @param max_len Maximum length of the buffer (including the NULL delimiter)
  75. * @return always return 0 when on success or wait in a loop for rx data
  76. */
  77. int esp_rom_uart_rx_string(uint8_t *str, uint8_t max_len);
  78. /**
  79. * @brief Set the UART port used by ets_printf.
  80. *
  81. * @param uart_no UART port number
  82. */
  83. void esp_rom_uart_set_as_console(uint8_t uart_no);
  84. /**
  85. * @brief Initialize the USB ACM UART
  86. * @note The ACM working memroy should be at least 128 bytes (ESP_ROM_CDC_ACM_WORK_BUF_MIN) in size.
  87. *
  88. * @param cdc_acm_work_mem Pointer to the work memroy used for CDC-ACM
  89. * @param cdc_acm_work_mem_len Length of work memory
  90. */
  91. void esp_rom_uart_usb_acm_init(void *cdc_acm_work_mem, int cdc_acm_work_mem_len);
  92. #ifdef __cplusplus
  93. }
  94. #endif