menu "ESP Trace Configuration"

    choice ESP_TRACE_LIBRARY
        prompt "Trace library"
        default ESP_TRACE_LIB_NONE
        help
            Select the trace library to use.

        config ESP_TRACE_LIB_EXTERNAL
            bool "External library from component registry"
            help
                Use a custom encoder provided by an external component.
                The trace core system will be enabled but no built-in encoder is included.

                The external component MUST provide a header file named
                "esp_trace_freertos_impl.h" in its include directories that
                defines all required FreeRTOS trace macros.

        config ESP_TRACE_LIB_NONE
            bool "Disabled"
    endchoice

    config ESP_TRACE_LIB_NAME
        string
        default "ext" if ESP_TRACE_LIB_EXTERNAL
        default "none" if ESP_TRACE_LIB_NONE

    choice ESP_TRACE_TRANSPORT
        prompt "Trace transport"
        default ESP_TRACE_TRANSPORT_NONE
        help
            Select the trace backend to use.

        config ESP_TRACE_TRANSPORT_APPTRACE
            bool "ESP-IDF apptrace"

        config ESP_TRACE_TRANSPORT_USB_SERIAL_JTAG
            bool "USB Serial JTAG"
            depends on SOC_USB_SERIAL_JTAG_SUPPORTED && !ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED
            help
                Use USB Serial JTAG peripheral as trace transport.

                Note: This option is not available when USB Serial JTAG is used as
                primary or secondary console (ESP_CONSOLE_USB_SERIAL_JTAG or
                ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG).

        config ESP_TRACE_TRANSPORT_EXTERNAL
            bool "External transport from component registry"
            depends on !ESP_TRACE_LIB_NONE
            help
                Use a transport registered by an external component.
                The trace core system will be enabled but no built-in transport is included.

        config ESP_TRACE_TRANSPORT_NONE
            bool "None"
    endchoice

    config ESP_TRACE_TRANSPORT_NAME
        string
        default "apptrace" if ESP_TRACE_TRANSPORT_APPTRACE
        default "usb_serial_jtag" if ESP_TRACE_TRANSPORT_USB_SERIAL_JTAG
        default "ext" if ESP_TRACE_TRANSPORT_EXTERNAL
        default "none" if ESP_TRACE_TRANSPORT_NONE

    config ESP_TRACE_ENABLE
        bool
        default !ESP_TRACE_LIB_NONE
        help
            Internal config to enable tracing dependency around components.

    rsource "$IDF_PATH/components/app_trace/Kconfig.apptrace"

    menu "USB Serial JTAG Trace Configuration"
        depends on ESP_TRACE_TRANSPORT_USB_SERIAL_JTAG

        config ESP_TRACE_USJ_TX_BUFFER_SIZE
            int "TX buffer size"
            default 2048
            range 256 32768
            help
                Size of the TX ring buffer for USB Serial JTAG trace transport.
                Larger buffer allows more trace data to be queued before blocking.

                Note: Buffer size must be a power of 2.

    endmenu

    choice ESP_TRACE_TIMESTAMP_SOURCE
        depends on ESP_TRACE_ENABLE
        prompt "Trace timestamp source"
        default ESP_TRACE_TS_SOURCE_CCOUNT if ESP_SYSTEM_SINGLE_CORE_MODE && !PM_ENABLE && !IDF_TARGET_ESP32C3
        default ESP_TRACE_TS_SOURCE_GPTIMER if !ESP_SYSTEM_SINGLE_CORE_MODE && !PM_ENABLE && !IDF_TARGET_ESP32C3
        default ESP_TRACE_TS_SOURCE_ESP_TIMER if PM_ENABLE || IDF_TARGET_ESP32C3
        help
            Select the timestamp source for tracing.

        config ESP_TRACE_TS_SOURCE_CCOUNT
            bool "CPU cycle counter (CCOUNT)"
            depends on ESP_SYSTEM_SINGLE_CORE_MODE && !PM_ENABLE && !IDF_TARGET_ESP32C3

        config ESP_TRACE_TS_SOURCE_GPTIMER
            bool "General Purpose Timer (Timer Group)"
            depends on !PM_ENABLE && !IDF_TARGET_ESP32C3

        config ESP_TRACE_TS_SOURCE_ESP_TIMER
            bool "esp_timer high resolution timer"

    endchoice

endmenu
