esp_rom_uart.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdint.h>
  11. #define ESP_ROM_CDC_ACM_WORK_BUF_MIN 128
  12. typedef enum {
  13. ESP_ROM_UART_0,
  14. ESP_ROM_UART_1,
  15. ESP_ROM_UART_USB
  16. } esp_rom_uart_num_t;
  17. /**
  18. * @brief Wait for UART TX FIFO is empty and all data has been sent out.
  19. *
  20. * @param uart_no UART port number
  21. */
  22. void esp_rom_uart_tx_wait_idle(uint8_t uart_no);
  23. /**
  24. * @brief Set clock source and baud rate for UART.
  25. *
  26. * @param uart_no UART port number
  27. * @param clock_hz Source clock (in Hz)
  28. * @param baud_rate Baud rate to set
  29. */
  30. void esp_rom_uart_set_clock_baudrate(uint8_t uart_no, uint32_t clock_hz, uint32_t baud_rate);
  31. /**
  32. * @brief Wait until UART TX FIFO is empty (i.e. flush TX FIFO)
  33. *
  34. * @param uart_no UART port number
  35. */
  36. void esp_rom_uart_flush_tx(uint8_t uart_no);
  37. /**
  38. * @brief Transmit one character to the console channel.
  39. *
  40. * @param c Character to send
  41. * @return
  42. * - 0 on success
  43. * - 1 on failure
  44. */
  45. int esp_rom_uart_tx_one_char(uint8_t c);
  46. /**
  47. * @brief Transmit one character to the console channel.
  48. * @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'.
  49. *
  50. * @param c Character to send
  51. */
  52. void esp_rom_uart_putc(char c);
  53. /**
  54. * @brief Get one character from the console channel.
  55. *
  56. * @param c Where to store the character
  57. * @return
  58. * - 0 on success
  59. * - 1 on failure or no data available
  60. */
  61. int esp_rom_uart_rx_one_char(uint8_t *c);
  62. /**
  63. * @brief Get one line of string from console channel (line ending won't be stored in the buffer).
  64. *
  65. * @param str Where to store the string
  66. * @param max_len Maximum length of the buffer (including the NULL delimiter)
  67. * @return always return 0 when on success or wait in a loop for rx data
  68. */
  69. int esp_rom_uart_rx_string(uint8_t *str, uint8_t max_len);
  70. /**
  71. * @brief Set the UART port used by ets_printf.
  72. *
  73. * @note USB-CDC port is also treated as "UART" port in the ROM code.
  74. * Use ESP_ROM_USB_SERIAL_DEVICE_NUM or ESP_ROM_USB_OTG_NUM to identify USB_SERIAL_JTAG and USB_OTG, respectively.
  75. *
  76. * @param uart_no UART port number
  77. */
  78. void esp_rom_uart_set_as_console(uint8_t uart_no);
  79. /**
  80. * @brief Switch the UART port that will use a buffer for TX and RX.
  81. *
  82. * @note USB-CDC port is also treated as "UART" port in the ROM code.
  83. * Use ESP_ROM_USB_SERIAL_DEVICE_NUM or ESP_ROM_USB_OTG_NUM to identify USB_SERIAL_JTAG and USB_OTG, respectively.
  84. *
  85. * @param uart_no UART port number
  86. */
  87. void esp_rom_uart_switch_buffer(uint8_t uart_no);
  88. /**
  89. * @brief Initialize the USB ACM UART
  90. * @note The ACM working memroy should be at least 128 bytes (ESP_ROM_CDC_ACM_WORK_BUF_MIN) in size.
  91. *
  92. * @param cdc_acm_work_mem Pointer to the work memroy used for CDC-ACM
  93. * @param cdc_acm_work_mem_len Length of work memory
  94. */
  95. void esp_rom_uart_usb_acm_init(void *cdc_acm_work_mem, int cdc_acm_work_mem_len);
  96. #ifdef __cplusplus
  97. }
  98. #endif