mirror of https://github.com/ARMmbed/mbed-os.git
USBDevice - add multiconfiguration support
parent
bfa3dc4962
commit
e515a52ffa
|
@ -52,7 +52,7 @@ USBTester::USBTester(uint16_t vendor_id, uint16_t product_id, uint16_t product_r
|
|||
MBED_ASSERT(resolver.valid());
|
||||
queue = mbed_highprio_event_queue();
|
||||
|
||||
configuration_desc();
|
||||
configuration_desc(0);
|
||||
|
||||
init();
|
||||
USBDevice::connect(connect_blocking);
|
||||
|
@ -321,7 +321,7 @@ const uint8_t *USBTester::string_iproduct_desc()
|
|||
|
||||
#define CONFIG1_DESC_SIZE (9+9+7+7+7+7 + 9+7+7+7+7)
|
||||
|
||||
const uint8_t *USBTester::configuration_desc()
|
||||
const uint8_t *USBTester::configuration_desc(uint8_t index)
|
||||
{
|
||||
static const uint8_t config_descriptor[] = {
|
||||
// configuration descriptor
|
||||
|
@ -434,7 +434,11 @@ const uint8_t *USBTester::configuration_desc()
|
|||
1 // bInterval
|
||||
|
||||
};
|
||||
return config_descriptor;
|
||||
if (index == 0) {
|
||||
return config_descriptor;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,9 +91,10 @@ protected:
|
|||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @param index descriptor index
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual const uint8_t *configuration_desc();
|
||||
virtual const uint8_t *configuration_desc(uint8_t index);
|
||||
|
||||
protected:
|
||||
uint8_t bulk_in;
|
||||
|
|
|
@ -76,22 +76,25 @@ bool USBDevice::_request_get_descriptor()
|
|||
}
|
||||
break;
|
||||
case CONFIGURATION_DESCRIPTOR:
|
||||
if (configuration_desc() != NULL) {
|
||||
if ((configuration_desc()[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
|
||||
&& (configuration_desc()[1] == CONFIGURATION_DESCRIPTOR)) {
|
||||
{
|
||||
const uint8_t idx = DESCRIPTOR_INDEX(_transfer.setup.wValue);
|
||||
if (configuration_desc(idx) != NULL) {
|
||||
if ((configuration_desc(idx)[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
|
||||
&& (configuration_desc(idx)[1] == CONFIGURATION_DESCRIPTOR)) {
|
||||
#ifdef DEBUG
|
||||
printf("conf descr request\r\n");
|
||||
#endif
|
||||
/* Get wTotalLength */
|
||||
_transfer.remaining = configuration_desc()[2] \
|
||||
| (configuration_desc()[3] << 8);
|
||||
_transfer.remaining = configuration_desc(idx)[2] \
|
||||
| (configuration_desc(idx)[3] << 8);
|
||||
|
||||
_transfer.ptr = (uint8_t *)configuration_desc();
|
||||
_transfer.ptr = (uint8_t *)configuration_desc(idx);
|
||||
_transfer.direction = Send;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STRING_DESCRIPTOR:
|
||||
#ifdef DEBUG
|
||||
printf("str descriptor\r\n");
|
||||
|
@ -1126,24 +1129,24 @@ void USBDevice::endpoint_unstall(usb_ep_t endpoint)
|
|||
unlock();
|
||||
}
|
||||
|
||||
uint8_t *USBDevice::find_descriptor(uint8_t descriptorType)
|
||||
uint8_t *USBDevice::find_descriptor(uint8_t descriptorType, uint8_t index)
|
||||
{
|
||||
/* Find a descriptor within the list of descriptors */
|
||||
/* following a configuration descriptor. */
|
||||
uint16_t wTotalLength;
|
||||
uint8_t *ptr;
|
||||
|
||||
if (configuration_desc() == NULL) {
|
||||
if (configuration_desc(index) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check this is a configuration descriptor */
|
||||
if ((configuration_desc()[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \
|
||||
|| (configuration_desc()[1] != CONFIGURATION_DESCRIPTOR)) {
|
||||
if ((configuration_desc(index)[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \
|
||||
|| (configuration_desc(index)[1] != CONFIGURATION_DESCRIPTOR)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wTotalLength = configuration_desc()[2] | (configuration_desc()[3] << 8);
|
||||
wTotalLength = configuration_desc(index)[2] | (configuration_desc(index)[3] << 8);
|
||||
|
||||
/* Check there are some more descriptors to follow */
|
||||
if (wTotalLength <= (CONFIGURATION_DESCRIPTOR_LENGTH + 2))
|
||||
|
@ -1153,7 +1156,7 @@ uint8_t *USBDevice::find_descriptor(uint8_t descriptorType)
|
|||
}
|
||||
|
||||
/* Start at first descriptor after the configuration descriptor */
|
||||
ptr = &(((uint8_t *)configuration_desc())[CONFIGURATION_DESCRIPTOR_LENGTH]);
|
||||
ptr = &(((uint8_t *)configuration_desc(index))[CONFIGURATION_DESCRIPTOR_LENGTH]);
|
||||
|
||||
do {
|
||||
if (ptr[1] /* bDescriptorType */ == descriptorType) {
|
||||
|
@ -1163,7 +1166,7 @@ uint8_t *USBDevice::find_descriptor(uint8_t descriptorType)
|
|||
|
||||
/* Skip to next descriptor */
|
||||
ptr += ptr[0]; /* bLength */
|
||||
} while (ptr < (configuration_desc() + wTotalLength));
|
||||
} while (ptr < (configuration_desc(index) + wTotalLength));
|
||||
|
||||
/* Reached end of the descriptors - not found */
|
||||
return NULL;
|
||||
|
|
|
@ -264,9 +264,10 @@ public:
|
|||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @param index descriptor index
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual const uint8_t *configuration_desc()
|
||||
virtual const uint8_t *configuration_desc(uint8_t index)
|
||||
{
|
||||
return NULL;
|
||||
};
|
||||
|
@ -465,9 +466,10 @@ protected:
|
|||
* Find a descriptor type inside the configuration descriptor
|
||||
*
|
||||
* @param descriptor_type Type of descriptor to find
|
||||
* @param index Configuration descriptor index ( 0 if only one configuration present )
|
||||
* @return A descriptor of the given type or NULL if none were found
|
||||
*/
|
||||
uint8_t *find_descriptor(uint8_t descriptor_type);
|
||||
uint8_t *find_descriptor(uint8_t descriptor_type, uint8_t index = 0);
|
||||
|
||||
/**
|
||||
* Get the endpoint table of this device
|
||||
|
|
|
@ -535,7 +535,7 @@ const uint8_t *USBCDC::string_iproduct_desc()
|
|||
|
||||
#define CONFIG1_DESC_SIZE (9+8+9+5+5+4+5+7+9+7+7)
|
||||
|
||||
const uint8_t *USBCDC::configuration_desc()
|
||||
const uint8_t *USBCDC::configuration_desc(uint8_t index)
|
||||
{
|
||||
uint8_t config_descriptor_temp[] = {
|
||||
// configuration descriptor
|
||||
|
@ -635,7 +635,11 @@ const uint8_t *USBCDC::configuration_desc()
|
|||
0 // bInterval
|
||||
};
|
||||
|
||||
MBED_ASSERT(sizeof(config_descriptor_temp) == sizeof(_config_descriptor));
|
||||
memcpy(_config_descriptor, config_descriptor_temp, sizeof(_config_descriptor));
|
||||
return _config_descriptor;
|
||||
if (index == 0) {
|
||||
MBED_ASSERT(sizeof(config_descriptor_temp) == sizeof(_config_descriptor));
|
||||
memcpy(_config_descriptor, config_descriptor_temp, sizeof(_config_descriptor));
|
||||
return _config_descriptor;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,9 +124,10 @@ protected:
|
|||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @param index descriptor index
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual const uint8_t *configuration_desc();
|
||||
virtual const uint8_t *configuration_desc(uint8_t index);
|
||||
|
||||
/*
|
||||
* Called by USBCallback_requestCompleted when CDC line coding is changed
|
||||
|
|
Loading…
Reference in New Issue