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