X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/2793c88fc601dcc7ec4961326dd9748a20f3ec83..fa1a092901319b3b41bf09e0c4cb9cbbec470d6b:/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c diff --git a/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c b/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c index 0c1c82008..4c94eaaba 100644 --- a/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c +++ b/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -28,53 +28,64 @@ this software. */ +/** \file + * + * USB Device Configuration Descriptor processing routines, to determine the correct pipe configurations + * needed to communication with an attached USB device. Descriptors are special computer-readable structures + * which the host requests upon device enumeration, to determine the device's capabilities and functions. + */ + #include "ConfigDescriptor.h" +/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This + * routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate + * with compatible devices. + * + * This routine searches for a BT interface descriptor containing bulk IN and OUT data endpoints. + * + * \return An error code from the \ref Bluetooth_GetConfigDescriptorDataCodes_t enum. + */ uint8_t ProcessConfigurationDescriptor(void) { - uint8_t* ConfigDescriptorData; - uint16_t ConfigDescriptorSize; + uint8_t ConfigDescriptorData[512]; + void* CurrConfigLocation = ConfigDescriptorData; + uint16_t CurrConfigBytesRem; uint8_t FoundEndpoints = 0; - - /* Get Configuration Descriptor size from the device */ - if (USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) - return ControlErrorDuringConfigRead; - - /* Ensure that the Configuration Descriptor isn't too large */ - if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE) - return DescriptorTooLarge; - - /* Allocate enough memory for the entire config descriptor */ - ConfigDescriptorData = alloca(ConfigDescriptorSize); /* Retrieve the entire configuration descriptor into the allocated buffer */ - USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, ConfigDescriptorData); + switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) + { + case HOST_GETCONFIG_Successful: + break; + case HOST_GETCONFIG_InvalidData: + return InvalidConfigDataReturned; + case HOST_GETCONFIG_BuffOverflow: + return DescriptorTooLarge; + default: + return ControlError; + } - /* Validate returned data - ensure first entry is a configuration header descriptor */ - if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) - return InvalidConfigDataReturned; - - /* The bluetooth USB transport addendium mandates that the data (not streaming voice) endpoints + /* The bluetooth USB transport addendum mandates that the data (not streaming voice) endpoints be in the first interface descriptor (interface 0) */ - USB_GetNextDescriptorOfType(&ConfigDescriptorSize, &ConfigDescriptorData, DTYPE_Interface); + USB_GetNextDescriptorOfType(&CurrConfigBytesRem, &CurrConfigLocation, DTYPE_Interface); /* Ensure that an interface was found, and the end of the descriptor was not reached */ - if (!(ConfigDescriptorSize)) - return NoInterfaceFound; + if (!(CurrConfigBytesRem)) + return NoBTInterfaceFound; /* Get the data IN, data OUT and event notification endpoints for the bluetooth interface */ while (FoundEndpoints != ((1 << BLUETOOTH_DATA_IN_PIPE) | (1 << BLUETOOTH_DATA_OUT_PIPE) | (1 << BLUETOOTH_EVENTS_PIPE))) { /* Fetch the next endpoint from the current bluetooth interface */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceBluetoothDataEndpoint)) + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextInterfaceBluetoothDataEndpoint)) { /* Descriptor not found, error out */ return NoEndpointFound; } - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); /* Check if the endpoint is a bulk or interrupt type endpoint */ if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) @@ -86,7 +97,6 @@ uint8_t ProcessConfigurationDescriptor(void) EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - Pipe_SetInfiniteINRequests(); Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); /* Set the flag indicating that the events notification pipe has been found */ @@ -102,8 +112,6 @@ uint8_t ProcessConfigurationDescriptor(void) EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - Pipe_SetInfiniteINRequests(); - /* Set the flag indicating that the data IN pipe has been found */ FoundEndpoints |= (1 << BLUETOOTH_DATA_IN_PIPE); } @@ -125,7 +133,7 @@ uint8_t ProcessConfigurationDescriptor(void) return SuccessfulConfigRead; } -uint8_t NextInterfaceBluetoothDataEndpoint(void* CurrentDescriptor) +uint8_t DComp_NextInterfaceBluetoothDataEndpoint(void* CurrentDescriptor) { /* PURPOSE: Find next interface endpoint descriptor before next interface descriptor */