menu "USB-OTG"
    depends on SOC_USB_OTG_SUPPORTED

    config USB_HOST_CONTROL_TRANSFER_MAX_SIZE
        int "Largest size (in bytes) of transfers to/from default endpoints"
        default 256
        help
            Each USB device attached is allocated a dedicated buffer for its OUT/IN transfers to/from the device's
            control endpoint. The maximum size of that buffer is determined by this option. The limited size of the
            transfer buffer have the following implications:
            - The maximum length of control transfers is limited
            - Device's with configuration descriptors larger than this limit cannot be supported

    choice USB_HOST_HW_BUFFER_BIAS
        prompt "Hardware FIFO size biasing"
        default USB_HOST_HW_BUFFER_BIAS_BALANCED
        help
            The underlying hardware has size adjustable FIFOs to cache USB packets on reception (IN) or for
            transmission (OUT). The size of these FIFOs will affect the largest MPS (maximum packet size) and the
            maximum number of packets that can be cached at any one time. The hardware contains the following
            FIFOS: RX (for all IN packets), Non-periodic TX (for Bulk and Control OUT packets), and Periodic TX
            (for Interrupt and Isochronous OUT packets). This configuration option allows biasing the FIFO sizes
            towards a particular use case, which may be necessary for devices that have endpoints with large MPS.
            The MPS limits for each biasing are listed below:

            Balanced:
            - IN (all transfer types), 408 bytes
            - OUT non-periodic (Bulk/Control), 192 bytes (i.e., 3 x 64 byte packets)
            - OUT periodic (Interrupt/Isochronous), 192 bytes

            Bias IN:
            - IN (all transfer types), 600 bytes
            - OUT non-periodic (Bulk/Control), 64 bytes (i.e., 1 x 64 byte packets)
            - OUT periodic (Interrupt/Isochronous), 128 bytes

            Bias Periodic OUT:
            - IN (all transfer types), 128 bytes
            - OUT non-periodic (Bulk/Control), 64 bytes (i.e., 1 x 64 byte packets)
            - OUT periodic (Interrupt/Isochronous), 600 bytes

        config USB_HOST_HW_BUFFER_BIAS_BALANCED
            bool "Balanced"
        config USB_HOST_HW_BUFFER_BIAS_IN
            bool "Bias IN"
        config USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT
            bool "Periodic OUT"
    endchoice

    menu "Hub Driver Configuration"

        menu "Root Port configuration"

            config USB_HOST_DEBOUNCE_DELAY_MS
                int "Debounce delay in ms"
                default 250
                help
                    On connection of a USB device, the USB 2.0 specification requires
                    a "debounce interval with a minimum duration of 100ms" to allow the connection to stabilize
                    (see USB 2.0 chapter 7.1.7.3 for more details).
                    During the debounce interval, no new connection/disconnection events are registered.

                    The default value is set to 250 ms to be safe.

            config USB_HOST_RESET_HOLD_MS
                int "Reset hold in ms"
                default 30
                help
                    The reset signaling can be generated on any Hub or Host Controller port by request from
                    the USB System Software. The USB 2.0 specification requires that "the reset signaling must
                    be driven for a minimum of 10ms" (see USB 2.0 chapter 7.1.7.5 for more details).
                    After the reset, the hub port will transition to the Enabled state (refer to Section 11.5).

                    The default value is set to 30 ms to be safe.

            config USB_HOST_RESET_RECOVERY_MS
                int "Reset recovery delay in ms"
                default 30
                help
                    After a port stops driving the reset signal, the USB 2.0 specification requires that
                    the "USB System Software guarantees a minimum of 10 ms for reset recovery" before the
                    attached device is expected to respond to data transfers (see USB 2.0 chapter 7.1.7.3 for
                    more details).
                    The device may ignore any data transfers during the recovery interval.

                    The default value is set to 30 ms to be safe.


            config USB_HOST_SET_ADDR_RECOVERY_MS
                int "SetAddress() recovery time in ms"
                default 10
                help
                    "After successful completion of the Status stage, the device is allowed a SetAddress()
                    recovery interval of 2 ms. At the end of this interval, the device must be able to accept
                    Setup packets addressed to the new address. Also, at the end of the recovery interval, the
                    device must not respond to tokens sent to the old address (unless, of course, the old and new
                    address is the same)." See USB 2.0 chapter 9.2.6.3 for more details.

                    The default value is set to 10 ms to be safe.

        endmenu #Root Hub configuration

        config USB_HOST_HUBS_SUPPORTED
            bool "Support Hubs"
            default n
            help
                Enables support of external Hubs.

        config USB_HOST_HUB_MULTI_LEVEL
            depends on USB_HOST_HUBS_SUPPORTED
            bool "Support multiple Hubs"
            default y
            help
                Enables support for connecting multiple Hubs simultaneously.

        menu "Downstream Port configuration"
            depends on USB_HOST_HUBS_SUPPORTED

            config USB_HOST_EXT_PORT_RESET_ATTEMPTS
                depends on IDF_EXPERIMENTAL_FEATURES
                # Invisible config option
                # Todo: IDF-11283
                int
                default 1
                help
                    Amount of attempts to reset the device.

                    The default value is 1.

            config USB_HOST_EXT_PORT_RESET_RECOVERY_DELAY_MS
                int "Reset recovery delay in ms"
                default 30
                help
                    After a port stops driving the reset signal, the USB 2.0 specification requires that
                    the "USB System Software guarantees a minimum of 10 ms for reset recovery" before the
                    attached device is expected to respond to data transfers (see USB 2.0 chapter 7.1.7.3 for
                    more details).
                    The device may ignore any data transfers during the recovery interval.

                    The default value is set to 30 ms to be safe.

            config USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_ENABLE
                bool "Custom bPwrOn2PwrGood value"
                default n
                help
                    Enables the possibility to configure custom time for the power-on sequence on a port
                    until power is good on that port.

                    When enabled, applies the custom PwrOn2PwrGood delay.
                    When disabled, applies the PwrOn2PwrGood value from the Hub Descriptor.

            config USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_MS
                depends on USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_ENABLE
                int "PwrOn2PwrGood delay in ms"
                default 100
                range 0 5000
                help
                    Custom value of delay from the time the power-on sequence begins on a port
                    until power is good on that port.
                    Value 0 is used for a hub with no power switches.

                    The default value is 100 ms.

        endmenu #Downstream Port configuration

    endmenu #Hub Driver Configuration

    config USB_HOST_ENABLE_ENUM_FILTER_CALLBACK
        bool "Enable enumeration filter callback"
        default n
        help
            The enumeration filter callback is called before enumeration of each newly attached device.
            This callback allows users to control whether a device should be enumerated, and what configuration
            number to use when enumerating a device.

            If enabled, the enumeration filter callback can be set via 'usb_host_config_t' when calling
            'usb_host_install()'.

    config USB_HOST_DWC_DMA_CAP_MEMORY_IN_PSRAM
        depends on IDF_TARGET_ESP32P4 && SPIRAM
        bool "Allocate USB_DWC DMA capable memory in PSRAM"
        default n
        help
            In the ESP32P4, the USB-DWC internal DMA can access external RAM. Enabling this configuration can save
            internal RAM by allocating the memory buffers used by the USB-DWC peripheral's DMA to external RAM.
            However, it introduces minor performance degradation due to the overhead of accessing external RAM.
        # Todo: IDF-11368 (aligned memory alloc size)

    # Hidden or compatibility options
    config USB_OTG_SUPPORTED
        # Invisible config kept for compatibility
        # Todo: Remove in v6.0 (IDF-8936)
        bool
        default y

endmenu #USB-OTG
