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