1 /* 2 * SPDX-FileCopyrightText: 2016 Cesanta Software Limited 3 * 4 * SPDX-License-Identifier: GPL-2.0-or-later 5 * 6 * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD 7 */ 8 9 #pragma once 10 11 #include <stdint.h> 12 #include <stdbool.h> 13 14 /* Call to initialize the I/O (either UART or USB CDC at this point). 15 * The argument is a callback function which will handle received characters, 16 * when asynchronous (interrupt-driven) RX is used. 17 * It will be called in an interrupt context. 18 */ 19 void stub_io_init(void(*rx_cb_func)(char)); 20 21 /* Enable or disable asynchronous (interrupt-driven) RX, for UART or USB. 22 * Currently needed only for the read_flash command. 23 */ 24 void stub_rx_async_enable(bool enable); 25 26 /* Wrapper for either uart_tx_one_char or the USB CDC output function. 27 * (uart_tx_one_char in ROM can also handle USB CDC, but it is really 28 * slow because it flushes the FIFO after every byte). 29 */ 30 void stub_tx_one_char(char c); 31 32 /* A blocking (polling) function to receive one character. 33 * Should only be used when async (interrupt-driven) RX is disabled. 34 * Currently only needed for the read_flash command. 35 */ 36 char stub_rx_one_char(void); 37 38 /* Returns after making sure that all output has been sent to the host */ 39 void stub_tx_flush(void); 40 41 /* Updates the baud rate divider based on the current baud rate (from host perspective) 42 * and the requested baud rate. 43 * No-op for USB CDC. 44 */ 45 void stub_io_set_baudrate(uint32_t current_baud, uint32_t new_baud); 46 47 /* To be called periodically while waiting for a command. 48 * No-op for UART, handles DTR/RTS reset for USB CDC. 49 */ 50 void stub_io_idle_hook(void); 51 52 /* Checks if USB-Serial/JTAG is being currently used. 53 */ 54 #if WITH_USB_JTAG_SERIAL 55 bool stub_uses_usb_jtag_serial(void); 56 #endif 57 58 /* Checks if USB-OTG is being currently used. 59 */ 60 #if WITH_USB_OTG 61 bool stub_uses_usb_otg(void); 62 #endif 63