menu "ESP-STDIO"
    choice ESP_CONSOLE_UART
        prompt "Channel for console output"
        default ESP_CONSOLE_UART_DEFAULT
        help
            Select where to send console output (through stdout and stderr).

            - Default is to use UART0 on pre-defined GPIOs.
            - If "Custom" is selected, UART0 or UART1 can be chosen,
              and any pins can be selected.
            - If "None" is selected, there will be no console output on any UART, except
              for initial output from ROM bootloader. This ROM output can be suppressed by
              GPIO strapping or EFUSE, refer to chip datasheet for details.
            - On chips with USB OTG peripheral, "USB CDC" option redirects output to the
              CDC port. This option uses the CDC driver in the chip ROM.
              This option is incompatible with TinyUSB stack.
            - On chips with an USB serial/JTAG debug controller, selecting the option
              for that redirects output to the CDC/ACM (serial port emulation) component
              of that device.
        config ESP_CONSOLE_UART_DEFAULT
            bool "Default: UART0"
        config ESP_CONSOLE_USB_CDC
            bool "USB CDC"
            # && !TINY_USB is because the ROM CDC driver is currently incompatible with TinyUSB.
            depends on SOC_USB_OTG_CONSOLE_SUPPORTED && !TINY_USB
        config ESP_CONSOLE_USB_SERIAL_JTAG
            bool "USB Serial/JTAG Controller"
            depends on SOC_USB_SERIAL_JTAG_SUPPORTED
        config ESP_CONSOLE_UART_CUSTOM
            bool "Custom UART"
        config ESP_CONSOLE_NONE
            bool "None"
    endchoice

    choice ESP_CONSOLE_SECONDARY
        depends on SOC_USB_SERIAL_JTAG_SUPPORTED
        prompt "Channel for console secondary output"
        default ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
        help
            This secondary option supports output through other specific port like USB_SERIAL_JTAG
            when UART0 port as a primary is selected but not connected. This secondary output currently only supports
            non-blocking mode without using REPL. If you want to output in blocking mode with REPL or
            input through this secondary port, please change the primary config to this port
            in `Channel for console output` menu.
        config ESP_CONSOLE_SECONDARY_NONE
            bool "No secondary console"
        config ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
            bool "USB_SERIAL_JTAG PORT"
            depends on !ESP_CONSOLE_USB_SERIAL_JTAG
            help
                This option supports output through USB_SERIAL_JTAG port when the UART0 port is not connected.
                The output currently only supports non-blocking mode without using the console.
                If you want to output in blocking mode with REPL or input through USB_SERIAL_JTAG port,
                please change the primary config to ESP_CONSOLE_USB_SERIAL_JTAG above.
    endchoice

    config ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED
        # Internal option, indicates that console USB SERIAL JTAG is used
        bool
        default y if ESP_CONSOLE_USB_SERIAL_JTAG || ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
        select USJ_ENABLE_USB_SERIAL_JTAG

    config ESP_CONSOLE_UART
        # Internal option, indicates that console UART is used (and not USB, for example)
        bool
        default y if ESP_CONSOLE_UART_DEFAULT || ESP_CONSOLE_UART_CUSTOM

    choice ESP_CONSOLE_UART_NUM
        prompt "UART peripheral to use for console output (0-1)"
        depends on ESP_CONSOLE_UART_CUSTOM
        default ESP_CONSOLE_UART_CUSTOM_NUM_0
        help
            This UART peripheral is used for console output from the ESP-IDF Bootloader and the app.

            If the configuration is different in the Bootloader binary compared to the app binary, UART
            is reconfigured after the bootloader exits and the app starts.

            Due to an ESP32 ROM bug, UART2 is not supported for console output
            via esp_rom_printf.

        config ESP_CONSOLE_UART_CUSTOM_NUM_0
            bool "UART0"
        config ESP_CONSOLE_UART_CUSTOM_NUM_1
            bool "UART1"
    endchoice

    config ESP_CONSOLE_UART_NUM
        int
        default 0 if ESP_CONSOLE_UART_DEFAULT
        default 0 if ESP_CONSOLE_UART_CUSTOM_NUM_0
        default 1 if ESP_CONSOLE_UART_CUSTOM_NUM_1
        default -1 if !ESP_CONSOLE_UART

    config ESP_CONSOLE_ROM_SERIAL_PORT_NUM
        # This config is used for the correct serial number used in ROM uart function.
        int
        default 0 if ESP_CONSOLE_UART_DEFAULT
        default 0 if ESP_CONSOLE_UART_CUSTOM_NUM_0
        default 1 if ESP_CONSOLE_UART_CUSTOM_NUM_1
        # Can be extended if we have more uarts.
        default ESP_ROM_USB_SERIAL_DEVICE_NUM if ESP_CONSOLE_USB_SERIAL_JTAG
        default ESP_ROM_USB_OTG_NUM if ESP_CONSOLE_USB_CDC
        default -1 if ESP_CONSOLE_NONE

    config ESP_CONSOLE_UART_TX_GPIO
        int "UART TX on GPIO<num>"
        depends on ESP_CONSOLE_UART_CUSTOM
        range -1 SOC_GPIO_OUT_RANGE_MAX
        # Specific value for old targets for compatibility. No need to add for new targets.
        default 1 if IDF_TARGET_ESP32
        default 43 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
        default 20 if IDF_TARGET_ESP32C2
        default 21 if IDF_TARGET_ESP32C3
        default 16 if IDF_TARGET_ESP32C6
        default 37 if IDF_TARGET_ESP32P4
        default 24 if IDF_TARGET_ESP32H2
        default -1
        help
             This GPIO is used for console UART TX output in the ESP-IDF Bootloader and the app (including
             boot log output and default standard output and standard error of the app). Value -1 means to
             continue using the default console UART TX pin.

             If the configuration is different in the Bootloader binary compared to the app binary, UART
             is reconfigured after the bootloader exits and the app starts.

    config ESP_CONSOLE_UART_RX_GPIO
        int "UART RX on GPIO<num>"
        depends on ESP_CONSOLE_UART_CUSTOM
        range -1 SOC_GPIO_IN_RANGE_MAX
        # Specific value for old targets for compatibility. No need to add for new targets.
        default 3 if IDF_TARGET_ESP32
        default 44 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
        default 19 if IDF_TARGET_ESP32C2
        default 20 if IDF_TARGET_ESP32C3
        default 17 if IDF_TARGET_ESP32C6
        default 38 if IDF_TARGET_ESP32P4
        default 23 if IDF_TARGET_ESP32H2
        default -1
        help
            This GPIO is used for console UART RX input in the ESP-IDF Bootloader and the app (including
            default standard input of the app). Value -1 means to continue using the default console UART
            RX pin.

            Note: The default ESP-IDF Bootloader configures this pin but doesn't read anything from the UART.

            If the configuration is different in the Bootloader binary compared to the app binary, UART
            is reconfigured after the bootloader exits and the app starts.


    config ESP_CONSOLE_UART_BAUDRATE
        int
        prompt "UART console baud rate" if ESP_CONSOLE_UART_CUSTOM
        depends on ESP_CONSOLE_UART
        default 74880 if (IDF_TARGET_ESP32C2 && XTAL_FREQ_26)
        default 115200
        range 1200 4000000 if !PM_ENABLE
        range 1200 1000000 if PM_ENABLE
        help
            This baud rate is used by both the ESP-IDF Bootloader and the app (including
            boot log output and default standard input/output/error of the app).

            The app's maximum baud rate depends on the UART clock source. If Power Management is disabled,
            the UART clock source is the APB clock and all baud rates in the available range will be sufficiently
            accurate. If Power Management is enabled, REF_TICK clock source is used so the baud rate is divided
            from 1MHz. Baud rates above 1Mbps are not possible and values between 500Kbps and 1Mbps may not be
            accurate.

            If the configuration is different in the Bootloader binary compared to the app binary, UART
            is reconfigured after the bootloader exits and the app starts.

    config ESP_CONSOLE_USB_CDC_RX_BUF_SIZE
        int "Size of USB CDC RX buffer"
        depends on ESP_CONSOLE_USB_CDC
        default 64
        range 4 16384
        help
            Set the size of USB CDC RX buffer. Increase the buffer size if your application
            is often receiving data over USB CDC.

    config ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF
        bool "Enable esp_rom_printf / ESP_EARLY_LOG via USB CDC"
        depends on ESP_CONSOLE_USB_CDC
        default n
        help
            If enabled, esp_rom_printf and ESP_EARLY_LOG output will also be sent over USB CDC.
            Disabling this option saves about 1kB or RAM.

    config ESP_STDIO_MAX_VFS_ENTRIES
        int "Maximum number of registerable VFS sinks"
        depends on VFS_SUPPORT_IO
        range 1 10
        default 2
        help
            Maximum number of filesystems that can be registered as sinks for console output.

endmenu
