menu "TinyUSB Stack"
    config TINYUSB_DEBUG_LEVEL
        int "TinyUSB log level (0-3)"
        default 1
        range 0 3
        help
            Specify verbosity of TinyUSB log output.

    choice TINYUSB_RHPORT
        prompt "USB Peripheral"
        default TINYUSB_RHPORT_HS if IDF_TARGET_ESP32P4
        default TINYUSB_RHPORT_FS
        help
            Allows set the USB Peripheral Controller for TinyUSB.

            - High-speed (USB OTG2.0 Peripheral for High-, Full- and Low-speed)
            - Full-speed (USB OTG1.1 Peripheral for Full- and Low-speed)

        config TINYUSB_RHPORT_HS
            bool "OTG2.0"
            depends on IDF_TARGET_ESP32P4
        config TINYUSB_RHPORT_FS
            bool "OTG1.1"
    endchoice

    menu "TinyUSB DCD"
        choice TINYUSB_MODE
            prompt "DCD Mode"
            default TINYUSB_MODE_DMA
            help
                TinyUSB DCD DWC2 Driver supports two modes: Slave mode (based on IRQ) and Buffer DMA mode.

            config TINYUSB_MODE_SLAVE
                bool "Slave/IRQ"
            config TINYUSB_MODE_DMA
                bool "Buffer DMA"
        endchoice
    endmenu # "TinyUSB DCD"

    menu "TinyUSB task configuration"
        config TINYUSB_NO_DEFAULT_TASK
            bool "Do not create a TinyUSB task"
            default n
            help
                This option allows to not create the FreeRTOS task during the driver initialization.
                User will have to handle TinyUSB events manually.

        config TINYUSB_TASK_PRIORITY
            int "TinyUSB task priority"
            default 5
            depends on !TINYUSB_NO_DEFAULT_TASK
            help
                Set the priority of the default TinyUSB main task.

        config TINYUSB_TASK_STACK_SIZE
            int "TinyUSB task stack size (bytes)"
            default 4096
            depends on !TINYUSB_NO_DEFAULT_TASK
            help
                Set the stack size of the default TinyUSB main task.

        choice TINYUSB_TASK_AFFINITY
            prompt "TinyUSB task affinity"
            default TINYUSB_TASK_AFFINITY_CPU1 if !FREERTOS_UNICORE
            default TINYUSB_TASK_AFFINITY_NO_AFFINITY
            depends on !TINYUSB_NO_DEFAULT_TASK
            help
                Allows setting TinyUSB tasks affinity, i.e. whether the task is pinned to
                CPU0, pinned to CPU1, or allowed to run on any CPU.

            config TINYUSB_TASK_AFFINITY_NO_AFFINITY
                bool "No affinity"
            config TINYUSB_TASK_AFFINITY_CPU0
                bool "CPU0"
            config TINYUSB_TASK_AFFINITY_CPU1
                bool "CPU1"
                depends on !FREERTOS_UNICORE
        endchoice

        config TINYUSB_TASK_AFFINITY
            hex
            default FREERTOS_NO_AFFINITY if TINYUSB_TASK_AFFINITY_NO_AFFINITY
            default 0x0 if TINYUSB_TASK_AFFINITY_CPU0
            default 0x1 if TINYUSB_TASK_AFFINITY_CPU1

        config TINYUSB_INIT_IN_DEFAULT_TASK
            bool "Initialize TinyUSB stack within the default TinyUSB task"
            default n
            depends on !TINYUSB_NO_DEFAULT_TASK
            help
                Run TinyUSB stack initialization just after starting the default TinyUSB task.
                This is especially useful in multicore scenarios, when we need to pin the task
                to a specific core and, at the same time initialize TinyUSB stack
                (i.e. install interrupts) on the same core.
    endmenu # "TinyUSB task configuration"

    menu "Descriptor configuration"
        comment "You can provide your custom descriptors via tinyusb_driver_install()"
        config TINYUSB_DESC_USE_ESPRESSIF_VID
            bool "VID: Use Espressif's vendor ID"
            default y
            help
                Enable this option, USB device will use Espressif's vendor ID as its VID.
                This is helpful at product develop stage.

        config TINYUSB_DESC_CUSTOM_VID
            hex "VID: Custom vendor ID"
            default 0x1234
            depends on !TINYUSB_DESC_USE_ESPRESSIF_VID
            help
                Custom Vendor ID.

        config TINYUSB_DESC_USE_DEFAULT_PID
            bool "PID: Use a default PID assigned to TinyUSB"
            default y
            help
                Default TinyUSB PID assigning uses values 0x4000...0x4007.

        config TINYUSB_DESC_CUSTOM_PID
            hex "PID: Custom product ID"
            default 0x5678
            depends on !TINYUSB_DESC_USE_DEFAULT_PID
            help
                Custom Product ID.

        config TINYUSB_DESC_BCD_DEVICE
            hex "bcdDevice"
            default 0x0100
            help
                Version of the firmware of the USB device.

        config TINYUSB_DESC_MANUFACTURER_STRING
            string "Manufacturer name"
            default "Espressif Systems"
            help
                Name of the manufacturer of the USB device.

        config TINYUSB_DESC_PRODUCT_STRING
            string "Product name"
            default "Espressif Device"
            help
                Name of the USB device.

        config TINYUSB_DESC_SERIAL_STRING
            string "Serial string"
            default "123456"
            help
                Serial number of the USB device.

        config TINYUSB_DESC_CDC_STRING
            depends on TINYUSB_CDC_ENABLED
            string "CDC Device String"
            default "Espressif CDC Device"
            help
                Name of the CDC device.

        config TINYUSB_DESC_MSC_STRING
            depends on TINYUSB_MSC_ENABLED
            string "MSC Device String"
            default "Espressif MSC Device"
            help
                Name of the MSC device.
    endmenu # "Descriptor configuration"

    menu "Massive Storage Class (MSC)"
        config TINYUSB_MSC_ENABLED
            bool "Enable TinyUSB MSC feature"
            default n
            help
                Enable TinyUSB MSC feature.

        config TINYUSB_MSC_BUFSIZE
            depends on TINYUSB_MSC_ENABLED
            int "MSC FIFO size"
            default 512 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
            default 8192 if IDF_TARGET_ESP32P4
            range 64 8192 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
            range 64 32768 if IDF_TARGET_ESP32P4
            help
                MSC FIFO size, in bytes.

        config TINYUSB_MSC_MOUNT_PATH
            depends on TINYUSB_MSC_ENABLED
            string "Mount Path"
            default "/data"
            help
                MSC Mount Path of storage.

        menu "TinyUSB FAT Format Options"
            choice TINYUSB_FAT_FORMAT_TYPE
               prompt "FatFS Format Type"
                default TINYUSB_FAT_FORMAT_ANY
                help
                    Select the FAT filesystem type used when formatting storage.

            config TINYUSB_FAT_FORMAT_ANY
                bool "FM_ANY - Automatically select from FAT12/FAT16/FAT32"

            config TINYUSB_FAT_FORMAT_FAT
                bool "FM_FAT - Allow only FAT12/FAT16"

            config TINYUSB_FAT_FORMAT_FAT32
                bool "FM_FAT32 - Force FAT32 only"

            config TINYUSB_FAT_FORMAT_EXFAT
                bool "FM_EXFAT - Force exFAT (requires exFAT enabled)"

            endchoice

            config TINYUSB_FAT_FORMAT_SFD
                bool "FM_SFD - Use SFD (no partition table)"
                default n
                help
                    Format as a Super Floppy Disk (no partition table).
                    This is typical for USB flash drives and small volumes.
            endmenu

    endmenu # "Massive Storage Class"

    menu "Communication Device Class (CDC)"
        config TINYUSB_CDC_ENABLED
            bool "Enable TinyUSB CDC feature"
            default n
            help
                Enable TinyUSB CDC feature.

        config TINYUSB_CDC_COUNT
            int "CDC Channel Count"
            default 1
            range 1 2
            depends on TINYUSB_CDC_ENABLED
            help
                Number of independent serial ports.

        config TINYUSB_CDC_RX_BUFSIZE
            depends on TINYUSB_CDC_ENABLED
            int "CDC FIFO size of RX channel"
            default 512
            range 64 10000
            help
                CDC FIFO size of RX channel.

        config TINYUSB_CDC_TX_BUFSIZE
            depends on TINYUSB_CDC_ENABLED
            int "CDC FIFO size of TX channel"
            default 512
            help
                CDC FIFO size of TX channel.
    endmenu # "Communication Device Class"

    menu "Musical Instrument Digital Interface (MIDI)"
        config TINYUSB_MIDI_COUNT
            int "TinyUSB MIDI interfaces count"
            default 0
            range 0 2
            help
                Setting value greater than 0 will enable TinyUSB MIDI feature.
    endmenu # "Musical Instrument Digital Interface (MIDI)"

    menu "Human Interface Device Class (HID)"
        config TINYUSB_HID_COUNT
            int "TinyUSB HID interfaces count"
            default 0
            range 0 4
            help
                Setting value greater than 0 will enable TinyUSB HID feature.
    endmenu # "HID Device Class (HID)"

    menu "Device Firmware Upgrade (DFU)"
        choice TINYUSB_DFU_MODE
            prompt "DFU mode"
            default TINYUSB_DFU_MODE_NONE
            help
                Select which DFU driver you want to use.

            config TINYUSB_DFU_MODE_DFU
                bool "DFU"

            config TINYUSB_DFU_MODE_DFU_RUNTIME
                bool "DFU Runtime"

            config TINYUSB_DFU_MODE_NONE
                bool "None"
        endchoice
        config TINYUSB_DFU_BUFSIZE
            depends on TINYUSB_DFU_MODE_DFU
            int "DFU XFER BUFFSIZE"
            default 512
            help
                DFU XFER BUFFSIZE.
    endmenu # Device Firmware Upgrade (DFU)

    menu "Bluetooth Host Class (BTH)"
        config TINYUSB_BTH_ENABLED
            bool "Enable TinyUSB BTH feature"
            default n
            help
                Enable TinyUSB BTH feature.

        config TINYUSB_BTH_ISO_ALT_COUNT
            depends on TINYUSB_BTH_ENABLED
            int "BTH ISO ALT COUNT"
            default 0
            help
                BTH ISO ALT COUNT.
    endmenu # "Bluetooth Host Device Class"

    menu "Network driver (ECM/NCM/RNDIS)"
        choice TINYUSB_NET_MODE
            prompt "Network mode"
            default TINYUSB_NET_MODE_NONE
            help
                Select network driver you want to use.

            config TINYUSB_NET_MODE_ECM_RNDIS
                bool "ECM/RNDIS"

            config TINYUSB_NET_MODE_NCM
                bool "NCM"

            config TINYUSB_NET_MODE_NONE
                bool "None"
        endchoice

        config TINYUSB_NCM_OUT_NTB_BUFFS_COUNT
            int "Number of NCM NTB buffers for reception side"
            depends on TINYUSB_NET_MODE_NCM
            default 3
            range 1 6
            help
                Number of NTB buffers for reception side.
                Can be increased to improve performance and stability with the cost of additional RAM requirements.
                Helps to mitigate "tud_network_can_xmit: request blocked" warning message when running NCM device.

        config TINYUSB_NCM_IN_NTB_BUFFS_COUNT
            int "Number of NCM NTB buffers for transmission side"
            depends on TINYUSB_NET_MODE_NCM
            default 3
            range 1 6
            help
                Number of NTB buffers for transmission side.
                Can be increased to improve performance and stability with the cost of additional RAM requirements.
                Helps to mitigate "tud_network_can_xmit: request blocked" warning message when running NCM device.

        config TINYUSB_NCM_OUT_NTB_BUFF_MAX_SIZE
            int "NCM NTB Buffer size for reception size"
            depends on TINYUSB_NET_MODE_NCM
            default 3200
            range 1600 10240
            help
              Size of NTB buffers on the reception side. The minimum size used by Linux is 2048 bytes.
              NTB buffer size must be significantly larger than the MTU (Maximum Transmission Unit).
              The typical default MTU size for Ethernet is 1500 bytes, plus an additional packet overhead.
              To improve performance, the NTB buffer size should be large enough to fit multiple MTU-sized
              frames in a single NTB buffer and it's length should be multiple of 4.

        config TINYUSB_NCM_IN_NTB_BUFF_MAX_SIZE
            int "NCM NTB Buffer size for transmission size"
            depends on TINYUSB_NET_MODE_NCM
            default 3200
            range 1600 10240
            help
              Size of NTB buffers on the transmission side. The minimum size used by Linux is 2048 bytes.
              NTB buffer size must be significantly larger than the MTU (Maximum Transmission Unit).
              The typical default MTU size for Ethernet is 1500 bytes, plus an additional packet overhead.
              To improve performance, the NTB buffer size should be large enough to fit multiple MTU-sized
              frames in a single NTB buffer and it's length should be multiple of 4.

    endmenu # "Network driver (ECM/NCM/RNDIS)"

    menu "Vendor Specific Interface"
        config TINYUSB_VENDOR_COUNT
            int "TinyUSB Vendor specific interfaces count"
            default 0
            range 0 2
            help
                Setting value greater than 0 will enable TinyUSB Vendor specific feature.
    endmenu # "Vendor Specific Interface"
endmenu # "TinyUSB Stack"
