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());
|
MBED_ASSERT(resolver.valid());
|
||||||
queue = mbed_highprio_event_queue();
|
queue = mbed_highprio_event_queue();
|
||||||
|
|
||||||
configuration_desc();
|
configuration_desc(0);
|
||||||
|
|
||||||
init();
|
init();
|
||||||
USBDevice::connect(connect_blocking);
|
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)
|
#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[] = {
|
static const uint8_t config_descriptor[] = {
|
||||||
// configuration descriptor
|
// configuration descriptor
|
||||||
|
@ -434,7 +434,11 @@ const uint8_t *USBTester::configuration_desc()
|
||||||
1 // bInterval
|
1 // bInterval
|
||||||
|
|
||||||
};
|
};
|
||||||
return config_descriptor;
|
if (index == 0) {
|
||||||
|
return config_descriptor;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -91,9 +91,10 @@ protected:
|
||||||
/*
|
/*
|
||||||
* Get configuration descriptor
|
* Get configuration descriptor
|
||||||
*
|
*
|
||||||
|
* @param index descriptor index
|
||||||
* @returns pointer to the configuration descriptor
|
* @returns pointer to the configuration descriptor
|
||||||
*/
|
*/
|
||||||
virtual const uint8_t *configuration_desc();
|
virtual const uint8_t *configuration_desc(uint8_t index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t bulk_in;
|
uint8_t bulk_in;
|
||||||
|
|
|
@ -76,22 +76,25 @@ bool USBDevice::_request_get_descriptor()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CONFIGURATION_DESCRIPTOR:
|
case CONFIGURATION_DESCRIPTOR:
|
||||||
if (configuration_desc() != NULL) {
|
{
|
||||||
if ((configuration_desc()[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
|
const uint8_t idx = DESCRIPTOR_INDEX(_transfer.setup.wValue);
|
||||||
&& (configuration_desc()[1] == CONFIGURATION_DESCRIPTOR)) {
|
if (configuration_desc(idx) != NULL) {
|
||||||
|
if ((configuration_desc(idx)[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
|
||||||
|
&& (configuration_desc(idx)[1] == CONFIGURATION_DESCRIPTOR)) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("conf descr request\r\n");
|
printf("conf descr request\r\n");
|
||||||
#endif
|
#endif
|
||||||
/* Get wTotalLength */
|
/* Get wTotalLength */
|
||||||
_transfer.remaining = configuration_desc()[2] \
|
_transfer.remaining = configuration_desc(idx)[2] \
|
||||||
| (configuration_desc()[3] << 8);
|
| (configuration_desc(idx)[3] << 8);
|
||||||
|
|
||||||
_transfer.ptr = (uint8_t *)configuration_desc();
|
_transfer.ptr = (uint8_t *)configuration_desc(idx);
|
||||||
_transfer.direction = Send;
|
_transfer.direction = Send;
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case STRING_DESCRIPTOR:
|
case STRING_DESCRIPTOR:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("str descriptor\r\n");
|
printf("str descriptor\r\n");
|
||||||
|
@ -1126,24 +1129,24 @@ void USBDevice::endpoint_unstall(usb_ep_t endpoint)
|
||||||
unlock();
|
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 */
|
/* Find a descriptor within the list of descriptors */
|
||||||
/* following a configuration descriptor. */
|
/* following a configuration descriptor. */
|
||||||
uint16_t wTotalLength;
|
uint16_t wTotalLength;
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
|
|
||||||
if (configuration_desc() == NULL) {
|
if (configuration_desc(index) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check this is a configuration descriptor */
|
/* Check this is a configuration descriptor */
|
||||||
if ((configuration_desc()[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \
|
if ((configuration_desc(index)[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \
|
||||||
|| (configuration_desc()[1] != CONFIGURATION_DESCRIPTOR)) {
|
|| (configuration_desc(index)[1] != CONFIGURATION_DESCRIPTOR)) {
|
||||||
return NULL;
|
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 */
|
/* Check there are some more descriptors to follow */
|
||||||
if (wTotalLength <= (CONFIGURATION_DESCRIPTOR_LENGTH + 2))
|
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 */
|
/* 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 {
|
do {
|
||||||
if (ptr[1] /* bDescriptorType */ == descriptorType) {
|
if (ptr[1] /* bDescriptorType */ == descriptorType) {
|
||||||
|
@ -1163,7 +1166,7 @@ uint8_t *USBDevice::find_descriptor(uint8_t descriptorType)
|
||||||
|
|
||||||
/* Skip to next descriptor */
|
/* Skip to next descriptor */
|
||||||
ptr += ptr[0]; /* bLength */
|
ptr += ptr[0]; /* bLength */
|
||||||
} while (ptr < (configuration_desc() + wTotalLength));
|
} while (ptr < (configuration_desc(index) + wTotalLength));
|
||||||
|
|
||||||
/* Reached end of the descriptors - not found */
|
/* Reached end of the descriptors - not found */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -264,9 +264,10 @@ public:
|
||||||
/*
|
/*
|
||||||
* Get configuration descriptor
|
* Get configuration descriptor
|
||||||
*
|
*
|
||||||
|
* @param index descriptor index
|
||||||
* @returns pointer to the configuration descriptor
|
* @returns pointer to the configuration descriptor
|
||||||
*/
|
*/
|
||||||
virtual const uint8_t *configuration_desc()
|
virtual const uint8_t *configuration_desc(uint8_t index)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
};
|
||||||
|
@ -465,9 +466,10 @@ protected:
|
||||||
* Find a descriptor type inside the configuration descriptor
|
* Find a descriptor type inside the configuration descriptor
|
||||||
*
|
*
|
||||||
* @param descriptor_type Type of descriptor to find
|
* @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
|
* @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
|
* 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)
|
#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[] = {
|
uint8_t config_descriptor_temp[] = {
|
||||||
// configuration descriptor
|
// configuration descriptor
|
||||||
|
@ -635,7 +635,11 @@ const uint8_t *USBCDC::configuration_desc()
|
||||||
0 // bInterval
|
0 // bInterval
|
||||||
};
|
};
|
||||||
|
|
||||||
MBED_ASSERT(sizeof(config_descriptor_temp) == sizeof(_config_descriptor));
|
if (index == 0) {
|
||||||
memcpy(_config_descriptor, config_descriptor_temp, sizeof(_config_descriptor));
|
MBED_ASSERT(sizeof(config_descriptor_temp) == sizeof(_config_descriptor));
|
||||||
return _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
|
* Get configuration descriptor
|
||||||
*
|
*
|
||||||
|
* @param index descriptor index
|
||||||
* @returns pointer to the configuration descriptor
|
* @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
|
* Called by USBCallback_requestCompleted when CDC line coding is changed
|
||||||
|
|
Loading…
Reference in New Issue