2.2.4.24 USB_DEVICE_EndpointEnable Function

C

USB_DEVICE_RESULT USB_DEVICE_EndpointEnable(
    USB_DEVICE_HANDLE usbDeviceHandle, 
    uint8_t interface, 
    USB_ENDPOINT_ADDRESS endpoint, 
    USB_TRANSFER_TYPE transferType, 
    size_t size
);

Summary

This function enables a device endpoint for the specified transfer type and size. A Vendor specific device application may typically call this function in response to a Set Interface request from the host. Note that Device Layer will enable endpoints contained in Alternate Setting 0 of an interface, when the host configures the device. If there is only one alternate setting in an interface, the application may not need to call the USB_DEVICE_EndpointEnable function.

If the device supports multiple alternate settings in an Interface, the device application must then disable an endpoint (if it was enabled) before re-enabling it with the new settings. The application can use the USB_DEVICE_EndpointIsEnabled function to check the status of the endpoint and USB_DEVICE_EndpointDisable function to disable the endpoint.

Precondition

The device should have been configured.

Parameters

Parameters Description
usbDeviceHandle USB Device Layer Handle.
interface This parameter is ignored in the PIC32 USB Device Stack implementation.
endpoint Endpoint to enable.
transferType Type of transfer that this is endpoint will support. This should match the type reported to the host.
size Maximum endpoint size. This should match the value reported to the host.

Returns

USB_DEVICE_RESULT_OK - The endpoint was enabled successfully.

USB_DEVICE_RESULT_ERROR_ENDPOINT_INVALID - The specified instance was not provisioned in the application and is invalid.

Example

// The following code example checks if an Set Alternate request has
// been received and changes the endpoint characteristics based on the
// alternate setting. Endpoint is 1 and direction is device to host.
// Assume that endpoint size was 32 bytes in alternate setting 0.

if(setAlternateRequest)
{
    if(alternateSetting == 1)
    {
        // Check if the endpoint is already enabled.
        if(USB_DEVICE_EndpointIsEnabled(usbDeviceHandle, (0x1|USB_EP_DIRECTION_IN)))
        {
            // Disable the endpoint.
            USB_DEVICE_EndpointDisable(usbDeviceHandle, (0x1|USB_EP_DIRECTION_IN));
        }

        // Re-enable the endpoint with new settings
        USB_DEVICE_EndpointEnable(usbDeviceHandle, 0, (0x1|USB_EP_DIRECTION_IN)
                    USB_TRANSFER_TYPE_BULK, 64);
    }
}

Remarks

None.