esp_rom_uart.h 3.1 KB

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