Merge pull request #301 from adafruit/develop

fix auto descriptor's auto interface e.g MIDI interface
This commit is contained in:
hathach authored and GitHub committed 2019-07-09 00:28:41 +07:00
commit 4a51ae1ea5
4 files changed
+9 -18

No files matched your search

@@ -37,11 +37,11 @@ Adafruit_USBD_CDC::Adafruit_USBD_CDC(void)
}
uint16_t Adafruit_USBD_CDC::getDescriptor(uint8_t* buf, uint16_t bufsize)
uint16_t Adafruit_USBD_CDC::getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize)
{
// CDC is mostly always existed for DFU
// usb core will automatically update interface number and endpoint number
uint8_t desc[] = { TUD_CDC_DESCRIPTOR(0, 0, EPIN, 8, EPOUT, EPIN, 64) };
// usb core will automatically update endpoint number
uint8_t desc[] = { TUD_CDC_DESCRIPTOR(itfnum, 0, EPIN, 8, EPOUT, EPIN, 64) };
uint16_t const len = sizeof(desc);
if ( bufsize < len ) return 0;
@@ -34,7 +34,7 @@ public:
Adafruit_USBD_CDC(void);
// fron Adafruit_USBD_Interface
virtual uint16_t getDescriptor(uint8_t* buf, uint16_t bufsize);
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize);
void setPins(uint8_t pin_rx, uint8_t pin_tx) { (void) pin_rx; (void) pin_tx; }
void begin(uint32_t baud_count);
@@ -95,26 +95,17 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
bool Adafruit_USBD_Device::addInterface(Adafruit_USBD_Interface& itf)
{
uint8_t* desc = _desc_cfg+_desc_cfglen;
uint16_t const len = itf.getDescriptor(desc, sizeof(_desc_cfg)-_desc_cfglen);
uint16_t const len = itf.getDescriptor(_itf_count, desc, sizeof(_desc_cfg)-_desc_cfglen);
uint8_t* desc_end = desc+len;
if ( !len ) return false;
// Handle IAD
if ( desc[1] == TUSB_DESC_INTERFACE_ASSOCIATION )
{
// update starting interface
((tusb_desc_interface_assoc_t*) desc)->bFirstInterface = _itf_count;
desc += desc[0]; // next
}
while (desc < desc_end)
{
if (desc[1] == TUSB_DESC_INTERFACE)
{
// No alternate interface support
((tusb_desc_interface_t*) desc)->bInterfaceNumber = _itf_count++;
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) desc;
if (desc_itf->bAlternateSetting == 0) _itf_count++;
}else if (desc[1] == TUSB_DESC_ENDPOINT)
{
tusb_desc_endpoint_t* desc_ep = (tusb_desc_endpoint_t*) desc;
@@ -127,7 +118,7 @@ bool Adafruit_USBD_Device::addInterface(Adafruit_USBD_Interface& itf)
_desc_cfglen += len;
// Update config descriptor
// Update configuration descriptor
tusb_desc_configuration_t* config = (tusb_desc_configuration_t*)_desc_cfg;
config->wTotalLength = _desc_cfglen;
config->bNumInterfaces = _itf_count;
@@ -30,7 +30,7 @@
class Adafruit_USBD_Interface
{
public:
virtual uint16_t getDescriptor(uint8_t* buf, uint16_t bufsize) = 0;
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize) = 0;
};
class Adafruit_USBD_Device