/* Handle set current configuration request. 
This function is used to handle set current configuration request. */
static usb_status_t USB_DeviceCh9SetConfiguration(usb_device_handle handle, usb_setup_struct_t *setup, uint8_t **buffer, uint32_t *length)
/* Handle set current configuration request. 
This function is used to handle set current configuration request. */
static usb_status_t USB_DeviceCh9SetConfiguration(usb_device_handle handle, usb_setup_struct_t *setup, uint8_t **buffer, uint32_t *length)
{
    uint8_t state;
    USB_DeviceGetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
    if ((kUSB_DeviceStateAddress != state) && (kUSB_DeviceStateConfigured != state))
    {
        return kStatus_USB_InvalidRequest;
    }
    state = kUSB_DeviceStateConfigured;
    USB_DeviceSetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
    if (!setup->wValue)
    {
        state = kUSB_DeviceStateAddress;
        USB_DeviceSetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
    }
    return USB_DeviceSetConfigure(handle, setup->wValue);
}