mirror of https://github.com/ARMmbed/mbed-os.git
Fix local static initialization in USB
The local static initialization in USB was causing multiple problems: -Configurable descriptor values are set only once -USB descriptor initialization causes a trap in debug builds since this is acquiring a mutex in an interrupt handler -Extra ram used since all descriptors are in RAM This patch fixes these problems by making fixed descriptors static const so they are stored in flash and never need to be initialized and by making descriptors that do change a member of the class so they are always initialized when requested rather than once though lazy static local initialization.pull/5874/head
parent
635a82495c
commit
6decbedbb8
|
@ -56,6 +56,8 @@ USBAudio::USBAudio(uint32_t frequency_in, uint8_t channel_nb_in, uint32_t freque
|
|||
|
||||
volume = 0;
|
||||
|
||||
_build_configurationDesc();
|
||||
|
||||
// connect the device
|
||||
USBDevice::connect();
|
||||
}
|
||||
|
@ -377,8 +379,8 @@ void USBAudio::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {
|
|||
FEATURE_UNIT_DESCRIPTOR_LENGTH + \
|
||||
2*OUTPUT_TERMINAL_DESCRIPTOR_LENGTH)
|
||||
|
||||
uint8_t * USBAudio::configurationDesc() {
|
||||
static uint8_t configDescriptor[] = {
|
||||
void USBAudio::_build_configurationDesc() {
|
||||
uint8_t configDescriptorTemp[] = {
|
||||
// Configuration 1
|
||||
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
|
||||
CONFIGURATION_DESCRIPTOR, // bDescriptorType
|
||||
|
@ -615,15 +617,19 @@ uint8_t * USBAudio::configurationDesc() {
|
|||
0x00, // bLockDelayUnits
|
||||
LSB(0x0000), // wLockDelay
|
||||
MSB(0x0000), // wLockDelay
|
||||
|
||||
// Terminator
|
||||
0 // bLength
|
||||
};
|
||||
|
||||
MBED_ASSERT(sizeof(configDescriptorTemp) == sizeof(configDescriptor));
|
||||
memcpy(configDescriptor, configDescriptorTemp, sizeof(configDescriptor));
|
||||
}
|
||||
|
||||
const uint8_t * USBAudio::configurationDesc() {
|
||||
|
||||
return configDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBAudio::stringIinterfaceDesc() {
|
||||
static uint8_t stringIinterfaceDescriptor[] = {
|
||||
const uint8_t * USBAudio::stringIinterfaceDesc() {
|
||||
static const uint8_t stringIinterfaceDescriptor[] = {
|
||||
0x0c, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
|
||||
|
@ -631,8 +637,8 @@ uint8_t * USBAudio::stringIinterfaceDesc() {
|
|||
return stringIinterfaceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBAudio::stringIproductDesc() {
|
||||
static uint8_t stringIproductDescriptor[] = {
|
||||
const uint8_t * USBAudio::stringIproductDesc() {
|
||||
static const uint8_t stringIproductDescriptor[] = {
|
||||
0x16, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
|
||||
|
|
|
@ -216,21 +216,21 @@ protected:
|
|||
*
|
||||
* @returns pointer to the string product descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIproductDesc();
|
||||
virtual const uint8_t * stringIproductDesc();
|
||||
|
||||
/*
|
||||
* Get string interface descriptor
|
||||
*
|
||||
* @returns pointer to the string interface descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIinterfaceDesc();
|
||||
virtual const uint8_t * stringIinterfaceDesc();
|
||||
|
||||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
/*
|
||||
* Called by USBDevice layer. Set interface/alternate of the device.
|
||||
|
@ -270,6 +270,20 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
/*
|
||||
* Call to rebuild the configuration descriptor
|
||||
*
|
||||
* This function should be called on creation or when any
|
||||
* value that is part of the configuration descriptor
|
||||
* changes.
|
||||
* @note This function uses ~200 bytes of stack so
|
||||
* make sure your stack is big enough for it.
|
||||
*/
|
||||
void _build_configurationDesc();
|
||||
|
||||
// configuration descriptor
|
||||
uint8_t configDescriptor[183];
|
||||
|
||||
// stream available ?
|
||||
volatile bool available;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("device descr\r\n");
|
||||
#endif
|
||||
transfer.remaining = DEVICE_DESCRIPTOR_LENGTH;
|
||||
transfer.ptr = deviceDesc();
|
||||
transfer.ptr = (uint8_t*)deviceDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
transfer.remaining = configurationDesc()[2] \
|
||||
| (configurationDesc()[3] << 8);
|
||||
|
||||
transfer.ptr = configurationDesc();
|
||||
transfer.ptr = (uint8_t*)configurationDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("1\r\n");
|
||||
#endif
|
||||
transfer.remaining = stringLangidDesc()[0];
|
||||
transfer.ptr = stringLangidDesc();
|
||||
transfer.ptr = (uint8_t*)stringLangidDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
break;
|
||||
|
@ -103,7 +103,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("2\r\n");
|
||||
#endif
|
||||
transfer.remaining = stringImanufacturerDesc()[0];
|
||||
transfer.ptr = stringImanufacturerDesc();
|
||||
transfer.ptr = (uint8_t*)stringImanufacturerDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
break;
|
||||
|
@ -112,7 +112,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("3\r\n");
|
||||
#endif
|
||||
transfer.remaining = stringIproductDesc()[0];
|
||||
transfer.ptr = stringIproductDesc();
|
||||
transfer.ptr = (uint8_t*)stringIproductDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
break;
|
||||
|
@ -121,7 +121,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("4\r\n");
|
||||
#endif
|
||||
transfer.remaining = stringIserialDesc()[0];
|
||||
transfer.ptr = stringIserialDesc();
|
||||
transfer.ptr = (uint8_t*)stringIserialDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
break;
|
||||
|
@ -130,7 +130,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("5\r\n");
|
||||
#endif
|
||||
transfer.remaining = stringIConfigurationDesc()[0];
|
||||
transfer.ptr = stringIConfigurationDesc();
|
||||
transfer.ptr = (uint8_t*)stringIConfigurationDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
break;
|
||||
|
@ -139,7 +139,7 @@ bool USBDevice::requestGetDescriptor(void)
|
|||
printf("6\r\n");
|
||||
#endif
|
||||
transfer.remaining = stringIinterfaceDesc()[0];
|
||||
transfer.ptr = stringIinterfaceDesc();
|
||||
transfer.ptr = (uint8_t*)stringIinterfaceDesc();
|
||||
transfer.direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
break;
|
||||
|
@ -790,7 +790,7 @@ uint8_t * USBDevice::findDescriptor(uint8_t descriptorType)
|
|||
}
|
||||
|
||||
/* Start at first descriptor after the configuration descriptor */
|
||||
ptr = &(configurationDesc()[CONFIGURATION_DESCRIPTOR_LENGTH]);
|
||||
ptr = &(((uint8_t*)configurationDesc())[CONFIGURATION_DESCRIPTOR_LENGTH]);
|
||||
|
||||
do {
|
||||
if (ptr[1] /* bDescriptorType */ == descriptorType)
|
||||
|
@ -926,8 +926,8 @@ bool USBDevice::readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, u
|
|||
|
||||
|
||||
|
||||
uint8_t * USBDevice::deviceDesc() {
|
||||
static uint8_t deviceDescriptor[] = {
|
||||
const uint8_t * USBDevice::deviceDesc() {
|
||||
uint8_t deviceDescriptorTemp[] = {
|
||||
DEVICE_DESCRIPTOR_LENGTH, /* bLength */
|
||||
DEVICE_DESCRIPTOR, /* bDescriptorType */
|
||||
LSB(USB_VERSION_2_0), /* bcdUSB (LSB) */
|
||||
|
@ -947,20 +947,22 @@ uint8_t * USBDevice::deviceDesc() {
|
|||
STRING_OFFSET_ISERIAL, /* iSerialNumber */
|
||||
0x01 /* bNumConfigurations */
|
||||
};
|
||||
MBED_ASSERT(sizeof(deviceDescriptorTemp) == sizeof(deviceDescriptor));
|
||||
memcpy(deviceDescriptor, deviceDescriptorTemp, sizeof(deviceDescriptor));
|
||||
return deviceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBDevice::stringLangidDesc() {
|
||||
static uint8_t stringLangidDescriptor[] = {
|
||||
const uint8_t * USBDevice::stringLangidDesc() {
|
||||
static const uint8_t stringLangidDescriptor[] = {
|
||||
0x04, /*bLength*/
|
||||
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
|
||||
0x09,0x04, /*bString Lang ID - 0x0409 - English*/
|
||||
};
|
||||
return stringLangidDescriptor;
|
||||
return (uint8_t *)stringLangidDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBDevice::stringImanufacturerDesc() {
|
||||
static uint8_t stringImanufacturerDescriptor[] = {
|
||||
const uint8_t * USBDevice::stringImanufacturerDesc() {
|
||||
static const uint8_t stringImanufacturerDescriptor[] = {
|
||||
0x12, /*bLength*/
|
||||
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
|
||||
'm',0,'b',0,'e',0,'d',0,'.',0,'o',0,'r',0,'g',0, /*bString iManufacturer - mbed.org*/
|
||||
|
@ -968,8 +970,8 @@ uint8_t * USBDevice::stringImanufacturerDesc() {
|
|||
return stringImanufacturerDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBDevice::stringIserialDesc() {
|
||||
static uint8_t stringIserialDescriptor[] = {
|
||||
const uint8_t * USBDevice::stringIserialDesc() {
|
||||
static const uint8_t stringIserialDescriptor[] = {
|
||||
0x16, /*bLength*/
|
||||
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
|
||||
'0',0,'1',0,'2',0,'3',0,'4',0,'5',0,'6',0,'7',0,'8',0,'9',0, /*bString iSerial - 0123456789*/
|
||||
|
@ -977,8 +979,8 @@ uint8_t * USBDevice::stringIserialDesc() {
|
|||
return stringIserialDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBDevice::stringIConfigurationDesc() {
|
||||
static uint8_t stringIconfigurationDescriptor[] = {
|
||||
const uint8_t * USBDevice::stringIConfigurationDesc() {
|
||||
static const uint8_t stringIconfigurationDescriptor[] = {
|
||||
0x06, /*bLength*/
|
||||
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
|
||||
'0',0,'1',0, /*bString iConfiguration - 01*/
|
||||
|
@ -986,8 +988,8 @@ uint8_t * USBDevice::stringIConfigurationDesc() {
|
|||
return stringIconfigurationDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBDevice::stringIinterfaceDesc() {
|
||||
static uint8_t stringIinterfaceDescriptor[] = {
|
||||
const uint8_t * USBDevice::stringIinterfaceDesc() {
|
||||
static const uint8_t stringIinterfaceDescriptor[] = {
|
||||
0x08, /*bLength*/
|
||||
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
|
||||
'U',0,'S',0,'B',0, /*bString iInterface - USB*/
|
||||
|
@ -995,8 +997,8 @@ uint8_t * USBDevice::stringIinterfaceDesc() {
|
|||
return stringIinterfaceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBDevice::stringIproductDesc() {
|
||||
static uint8_t stringIproductDescriptor[] = {
|
||||
const uint8_t * USBDevice::stringIproductDesc() {
|
||||
static const uint8_t stringIproductDescriptor[] = {
|
||||
0x16, /*bLength*/
|
||||
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
|
||||
'U',0,'S',0,'B',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0 /*bString iProduct - USB DEVICE*/
|
||||
|
|
|
@ -165,60 +165,60 @@ public:
|
|||
virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
|
||||
|
||||
/*
|
||||
* Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
|
||||
* Get device descriptor.
|
||||
*
|
||||
* @returns pointer to the device descriptor
|
||||
*/
|
||||
virtual uint8_t * deviceDesc();
|
||||
virtual const uint8_t * deviceDesc();
|
||||
|
||||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc(){return NULL;};
|
||||
virtual const uint8_t * configurationDesc(){return NULL;};
|
||||
|
||||
/*
|
||||
* Get string lang id descriptor
|
||||
*
|
||||
* @return pointer to the string lang id descriptor
|
||||
*/
|
||||
virtual uint8_t * stringLangidDesc();
|
||||
virtual const uint8_t * stringLangidDesc();
|
||||
|
||||
/*
|
||||
* Get string manufacturer descriptor
|
||||
*
|
||||
* @returns pointer to the string manufacturer descriptor
|
||||
*/
|
||||
virtual uint8_t * stringImanufacturerDesc();
|
||||
virtual const uint8_t * stringImanufacturerDesc();
|
||||
|
||||
/*
|
||||
* Get string product descriptor
|
||||
*
|
||||
* @returns pointer to the string product descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIproductDesc();
|
||||
virtual const uint8_t * stringIproductDesc();
|
||||
|
||||
/*
|
||||
* Get string serial descriptor
|
||||
*
|
||||
* @returns pointer to the string serial descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIserialDesc();
|
||||
virtual const uint8_t * stringIserialDesc();
|
||||
|
||||
/*
|
||||
* Get string configuration descriptor
|
||||
*
|
||||
* @returns pointer to the string configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIConfigurationDesc();
|
||||
virtual const uint8_t * stringIConfigurationDesc();
|
||||
|
||||
/*
|
||||
* Get string interface descriptor
|
||||
*
|
||||
* @returns pointer to the string interface descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIinterfaceDesc();
|
||||
virtual const uint8_t * stringIinterfaceDesc();
|
||||
|
||||
/*
|
||||
* Get the length of the report descriptor
|
||||
|
@ -242,6 +242,7 @@ protected:
|
|||
uint16_t VENDOR_ID;
|
||||
uint16_t PRODUCT_ID;
|
||||
uint16_t PRODUCT_RELEASE;
|
||||
uint8_t deviceDescriptor[18];
|
||||
|
||||
private:
|
||||
bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
|
||||
|
|
|
@ -105,7 +105,7 @@ bool USBHID::USBCallback_request() {
|
|||
&& (reportDescLength() != 0))
|
||||
{
|
||||
transfer->remaining = reportDescLength();
|
||||
transfer->ptr = reportDesc();
|
||||
transfer->ptr = (uint8_t*)reportDesc();
|
||||
transfer->direction = DEVICE_TO_HOST;
|
||||
success = true;
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ bool USBHID::USBCallback_setConfiguration(uint8_t configuration) {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBHID::stringIinterfaceDesc() {
|
||||
static uint8_t stringIinterfaceDescriptor[] = {
|
||||
const uint8_t * USBHID::stringIinterfaceDesc() {
|
||||
static const uint8_t stringIinterfaceDescriptor[] = {
|
||||
0x08, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'H',0,'I',0,'D',0, //bString iInterface - HID
|
||||
|
@ -186,8 +186,8 @@ uint8_t * USBHID::stringIinterfaceDesc() {
|
|||
return stringIinterfaceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBHID::stringIproductDesc() {
|
||||
static uint8_t stringIproductDescriptor[] = {
|
||||
const uint8_t * USBHID::stringIproductDesc() {
|
||||
static const uint8_t stringIproductDescriptor[] = {
|
||||
0x16, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'H',0,'I',0,'D',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0 //bString iProduct - HID device
|
||||
|
@ -197,8 +197,8 @@ uint8_t * USBHID::stringIproductDesc() {
|
|||
|
||||
|
||||
|
||||
uint8_t * USBHID::reportDesc() {
|
||||
static uint8_t reportDescriptor[] = {
|
||||
const uint8_t * USBHID::reportDesc() {
|
||||
uint8_t reportDescriptorTemp[] = {
|
||||
USAGE_PAGE(2), LSB(0xFFAB), MSB(0xFFAB),
|
||||
USAGE(2), LSB(0x0200), MSB(0x0200),
|
||||
COLLECTION(1), 0x01, // Collection (Application)
|
||||
|
@ -218,6 +218,8 @@ uint8_t * USBHID::reportDesc() {
|
|||
END_COLLECTION(0),
|
||||
};
|
||||
reportLength = sizeof(reportDescriptor);
|
||||
MBED_ASSERT(sizeof(reportDescriptorTemp) == sizeof(reportDescriptor));
|
||||
memcpy(reportDescriptor, reportDescriptorTemp, sizeof(reportDescriptor));
|
||||
return reportDescriptor;
|
||||
}
|
||||
|
||||
|
@ -227,8 +229,8 @@ uint8_t * USBHID::reportDesc() {
|
|||
+ (1 * HID_DESCRIPTOR_LENGTH) \
|
||||
+ (2 * ENDPOINT_DESCRIPTOR_LENGTH))
|
||||
|
||||
uint8_t * USBHID::configurationDesc() {
|
||||
static uint8_t configurationDescriptor[] = {
|
||||
const uint8_t * USBHID::configurationDesc() {
|
||||
uint8_t configurationDescriptorTemp[] = {
|
||||
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
|
||||
CONFIGURATION_DESCRIPTOR, // bDescriptorType
|
||||
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
|
||||
|
@ -275,5 +277,7 @@ uint8_t * USBHID::configurationDesc() {
|
|||
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
|
||||
1, // bInterval (milliseconds)
|
||||
};
|
||||
MBED_ASSERT(sizeof(configurationDescriptorTemp) == sizeof(configurationDescriptor));
|
||||
memcpy(configurationDescriptor, configurationDescriptorTemp, sizeof(configurationDescriptor));
|
||||
return configurationDescriptor;
|
||||
}
|
||||
|
|
|
@ -98,13 +98,14 @@ public:
|
|||
|
||||
protected:
|
||||
uint16_t reportLength;
|
||||
uint8_t reportDescriptor[27];
|
||||
|
||||
/*
|
||||
* Get the Report descriptor
|
||||
*
|
||||
* @returns pointer to the report descriptor
|
||||
*/
|
||||
virtual uint8_t * reportDesc();
|
||||
virtual const uint8_t * reportDesc();
|
||||
|
||||
/*
|
||||
* Get the length of the report descriptor
|
||||
|
@ -118,21 +119,21 @@ protected:
|
|||
*
|
||||
* @returns pointer to the string product descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIproductDesc();
|
||||
virtual const uint8_t * stringIproductDesc();
|
||||
|
||||
/*
|
||||
* Get string interface descriptor
|
||||
*
|
||||
* @returns pointer to the string interface descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIinterfaceDesc();
|
||||
virtual const uint8_t * stringIinterfaceDesc();
|
||||
|
||||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
|
||||
/*
|
||||
|
@ -164,6 +165,7 @@ protected:
|
|||
virtual bool USBCallback_setConfiguration(uint8_t configuration);
|
||||
|
||||
private:
|
||||
uint8_t configurationDescriptor[41];
|
||||
HID_REPORT outputReport;
|
||||
uint8_t output_length;
|
||||
uint8_t input_length;
|
||||
|
|
|
@ -352,8 +352,8 @@ const KEYMAP keymap[KEYMAP_SIZE] = {
|
|||
};
|
||||
#endif
|
||||
|
||||
uint8_t * USBKeyboard::reportDesc() {
|
||||
static uint8_t reportDescriptor[] = {
|
||||
const uint8_t * USBKeyboard::reportDesc() {
|
||||
static const uint8_t reportDescriptor[] = {
|
||||
USAGE_PAGE(1), 0x01, // Generic Desktop
|
||||
USAGE(1), 0x06, // Keyboard
|
||||
COLLECTION(1), 0x01, // Application
|
||||
|
@ -501,8 +501,8 @@ bool USBKeyboard::mediaControl(MEDIA_KEY key) {
|
|||
+ (1 * HID_DESCRIPTOR_LENGTH) \
|
||||
+ (2 * ENDPOINT_DESCRIPTOR_LENGTH))
|
||||
|
||||
uint8_t * USBKeyboard::configurationDesc() {
|
||||
static uint8_t configurationDescriptor[] = {
|
||||
const uint8_t * USBKeyboard::configurationDesc() {
|
||||
uint8_t configurationDescriptorTemp[] = {
|
||||
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
|
||||
CONFIGURATION_DESCRIPTOR, // bDescriptorType
|
||||
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
|
||||
|
@ -549,5 +549,7 @@ uint8_t * USBKeyboard::configurationDesc() {
|
|||
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
|
||||
1, // bInterval (milliseconds)
|
||||
};
|
||||
MBED_ASSERT(sizeof(configurationDescriptorTemp) == sizeof(configurationDescriptor));
|
||||
memcpy(configurationDescriptor, configurationDescriptorTemp, sizeof(configurationDescriptor));
|
||||
return configurationDescriptor;
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public:
|
|||
*
|
||||
* @returns pointer to the report descriptor
|
||||
*/
|
||||
virtual uint8_t * reportDesc();
|
||||
virtual const uint8_t * reportDesc();
|
||||
|
||||
/*
|
||||
* Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
|
||||
|
@ -173,7 +173,7 @@ protected:
|
|||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
private:
|
||||
//dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
|
||||
|
@ -181,6 +181,7 @@ private:
|
|||
return -1;
|
||||
};
|
||||
|
||||
uint8_t configurationDescriptor[41];
|
||||
uint8_t lock_status;
|
||||
|
||||
};
|
||||
|
|
|
@ -103,10 +103,10 @@ bool USBMouse::release(uint8_t button_) {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBMouse::reportDesc() {
|
||||
const uint8_t * USBMouse::reportDesc() {
|
||||
|
||||
if (mouse_type == REL_MOUSE) {
|
||||
static uint8_t reportDescriptor[] = {
|
||||
static const uint8_t reportDescriptor[] = {
|
||||
USAGE_PAGE(1), 0x01, // Genric Desktop
|
||||
USAGE(1), 0x02, // Mouse
|
||||
COLLECTION(1), 0x01, // Application
|
||||
|
@ -141,7 +141,7 @@ uint8_t * USBMouse::reportDesc() {
|
|||
reportLength = sizeof(reportDescriptor);
|
||||
return reportDescriptor;
|
||||
} else if (mouse_type == ABS_MOUSE) {
|
||||
static uint8_t reportDescriptor[] = {
|
||||
static const uint8_t reportDescriptor[] = {
|
||||
USAGE_PAGE(1), 0x01, // Generic Desktop
|
||||
USAGE(1), 0x02, // Mouse
|
||||
COLLECTION(1), 0x01, // Application
|
||||
|
@ -192,8 +192,8 @@ uint8_t * USBMouse::reportDesc() {
|
|||
+ (1 * HID_DESCRIPTOR_LENGTH) \
|
||||
+ (2 * ENDPOINT_DESCRIPTOR_LENGTH))
|
||||
|
||||
uint8_t * USBMouse::configurationDesc() {
|
||||
static uint8_t configurationDescriptor[] = {
|
||||
const uint8_t * USBMouse::configurationDesc() {
|
||||
uint8_t configurationDescriptorTemp[] = {
|
||||
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
|
||||
CONFIGURATION_DESCRIPTOR, // bDescriptorType
|
||||
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
|
||||
|
@ -240,5 +240,7 @@ uint8_t * USBMouse::configurationDesc() {
|
|||
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
|
||||
1, // bInterval (milliseconds)
|
||||
};
|
||||
MBED_ASSERT(sizeof(configurationDescriptorTemp) == sizeof(configurationDescriptor));
|
||||
memcpy(configurationDescriptor, configurationDescriptorTemp, sizeof(configurationDescriptor));
|
||||
return configurationDescriptor;
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ class USBMouse: public USBHID
|
|||
*
|
||||
* @returns pointer to the report descriptor
|
||||
*/
|
||||
virtual uint8_t * reportDesc();
|
||||
virtual const uint8_t * reportDesc();
|
||||
|
||||
protected:
|
||||
/*
|
||||
|
@ -198,11 +198,12 @@ class USBMouse: public USBHID
|
|||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
private:
|
||||
MOUSE_TYPE mouse_type;
|
||||
uint8_t button;
|
||||
uint8_t configurationDescriptor[41];
|
||||
bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
|
||||
};
|
||||
|
||||
|
|
|
@ -348,9 +348,9 @@ const KEYMAP keymap[KEYMAP_SIZE] = {
|
|||
#endif
|
||||
|
||||
|
||||
uint8_t * USBMouseKeyboard::reportDesc() {
|
||||
const uint8_t * USBMouseKeyboard::reportDesc() {
|
||||
if (mouse_type == REL_MOUSE) {
|
||||
static uint8_t reportDescriptor[] = {
|
||||
static const uint8_t reportDescriptor[] = {
|
||||
// Keyboard
|
||||
USAGE_PAGE(1), 0x01,
|
||||
USAGE(1), 0x06,
|
||||
|
@ -442,7 +442,7 @@ uint8_t * USBMouseKeyboard::reportDesc() {
|
|||
reportLength = sizeof(reportDescriptor);
|
||||
return reportDescriptor;
|
||||
} else if (mouse_type == ABS_MOUSE) {
|
||||
static uint8_t reportDescriptor[] = {
|
||||
static const uint8_t reportDescriptor[] = {
|
||||
|
||||
// Keyboard
|
||||
USAGE_PAGE(1), 0x01,
|
||||
|
|
|
@ -195,7 +195,7 @@ class USBMouseKeyboard: public USBHID, public Stream
|
|||
*
|
||||
* @returns pointer to the report descriptor
|
||||
*/
|
||||
virtual uint8_t * reportDesc();
|
||||
virtual const uint8_t * reportDesc();
|
||||
|
||||
/*
|
||||
* Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
|
||||
|
|
|
@ -157,8 +157,8 @@ bool USBMIDI::USBCallback_setConfiguration(uint8_t configuration) {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBMIDI::stringIinterfaceDesc() {
|
||||
static uint8_t stringIinterfaceDescriptor[] = {
|
||||
const uint8_t * USBMIDI::stringIinterfaceDesc() {
|
||||
static const uint8_t stringIinterfaceDescriptor[] = {
|
||||
0x0c, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
|
||||
|
@ -166,8 +166,8 @@ uint8_t * USBMIDI::stringIinterfaceDesc() {
|
|||
return stringIinterfaceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBMIDI::stringIproductDesc() {
|
||||
static uint8_t stringIproductDescriptor[] = {
|
||||
const uint8_t * USBMIDI::stringIproductDesc() {
|
||||
static const uint8_t stringIproductDescriptor[] = {
|
||||
0x16, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
|
||||
|
@ -176,8 +176,8 @@ uint8_t * USBMIDI::stringIproductDesc() {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBMIDI::configurationDesc() {
|
||||
static uint8_t configDescriptor[] = {
|
||||
const uint8_t * USBMIDI::configurationDesc() {
|
||||
static const uint8_t configDescriptor[] = {
|
||||
// configuration descriptor
|
||||
0x09, 0x02, 0x65, 0x00, 0x02, 0x01, 0x00, 0xc0, 0x50,
|
||||
|
||||
|
|
|
@ -85,21 +85,21 @@ protected:
|
|||
*
|
||||
* @returns pointer to the string product descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIproductDesc();
|
||||
virtual const uint8_t * stringIproductDesc();
|
||||
|
||||
/*
|
||||
* Get string interface descriptor
|
||||
*
|
||||
* @returns pointer to the string interface descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIinterfaceDesc();
|
||||
virtual const uint8_t * stringIinterfaceDesc();
|
||||
|
||||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
private:
|
||||
uint8_t data[MAX_MIDI_MESSAGE_SIZE+1];
|
||||
|
|
|
@ -589,8 +589,8 @@ bool USBMSD::USBCallback_setConfiguration(uint8_t configuration) {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBMSD::stringIinterfaceDesc() {
|
||||
static uint8_t stringIinterfaceDescriptor[] = {
|
||||
const uint8_t * USBMSD::stringIinterfaceDesc() {
|
||||
static const uint8_t stringIinterfaceDescriptor[] = {
|
||||
0x08, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'M',0,'S',0,'D',0 //bString iInterface - MSD
|
||||
|
@ -598,8 +598,8 @@ uint8_t * USBMSD::stringIinterfaceDesc() {
|
|||
return stringIinterfaceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBMSD::stringIproductDesc() {
|
||||
static uint8_t stringIproductDescriptor[] = {
|
||||
const uint8_t * USBMSD::stringIproductDesc() {
|
||||
static const uint8_t stringIproductDescriptor[] = {
|
||||
0x12, //bLength
|
||||
STRING_DESCRIPTOR, //bDescriptorType 0x03
|
||||
'M',0,'b',0,'e',0,'d',0,' ',0,'M',0,'S',0,'D',0 //bString iProduct - Mbed Audio
|
||||
|
@ -608,8 +608,8 @@ uint8_t * USBMSD::stringIproductDesc() {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBMSD::configurationDesc() {
|
||||
static uint8_t configDescriptor[] = {
|
||||
const uint8_t * USBMSD::configurationDesc() {
|
||||
static const uint8_t configDescriptor[] = {
|
||||
|
||||
// Configuration 1
|
||||
9, // bLength
|
||||
|
|
|
@ -139,21 +139,21 @@ protected:
|
|||
*
|
||||
* @returns pointer to the string product descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIproductDesc();
|
||||
virtual const uint8_t * stringIproductDesc();
|
||||
|
||||
/*
|
||||
* Get string interface descriptor
|
||||
*
|
||||
* @returns pointer to the string interface descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIinterfaceDesc();
|
||||
virtual const uint8_t * stringIinterfaceDesc();
|
||||
|
||||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
/*
|
||||
* Callback called when a packet is received
|
||||
|
|
|
@ -144,8 +144,8 @@ bool USBCDC::readEP_NB(uint8_t * buffer, uint32_t * size) {
|
|||
}
|
||||
|
||||
|
||||
uint8_t * USBCDC::deviceDesc() {
|
||||
static uint8_t deviceDescriptor[] = {
|
||||
const uint8_t * USBCDC::deviceDesc() {
|
||||
uint8_t deviceDescriptorTemp[] = {
|
||||
18, // bLength
|
||||
1, // bDescriptorType
|
||||
0x10, 0x01, // bcdUSB
|
||||
|
@ -161,11 +161,13 @@ uint8_t * USBCDC::deviceDesc() {
|
|||
3, // iSerialNumber
|
||||
1 // bNumConfigurations
|
||||
};
|
||||
MBED_ASSERT(sizeof(deviceDescriptorTemp) == sizeof(deviceDescriptor));
|
||||
memcpy(deviceDescriptor, deviceDescriptorTemp, sizeof(deviceDescriptor));
|
||||
return deviceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBCDC::stringIinterfaceDesc() {
|
||||
static uint8_t stringIinterfaceDescriptor[] = {
|
||||
const uint8_t * USBCDC::stringIinterfaceDesc() {
|
||||
static const uint8_t stringIinterfaceDescriptor[] = {
|
||||
0x08,
|
||||
STRING_DESCRIPTOR,
|
||||
'C',0,'D',0,'C',0,
|
||||
|
@ -173,8 +175,8 @@ uint8_t * USBCDC::stringIinterfaceDesc() {
|
|||
return stringIinterfaceDescriptor;
|
||||
}
|
||||
|
||||
uint8_t * USBCDC::stringIproductDesc() {
|
||||
static uint8_t stringIproductDescriptor[] = {
|
||||
const uint8_t * USBCDC::stringIproductDesc() {
|
||||
static const uint8_t stringIproductDescriptor[] = {
|
||||
0x16,
|
||||
STRING_DESCRIPTOR,
|
||||
'C',0,'D',0,'C',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0
|
||||
|
@ -185,8 +187,8 @@ uint8_t * USBCDC::stringIproductDesc() {
|
|||
|
||||
#define CONFIG1_DESC_SIZE (9+8+9+5+5+4+5+7+9+7+7)
|
||||
|
||||
uint8_t * USBCDC::configurationDesc() {
|
||||
static uint8_t configDescriptor[] = {
|
||||
const uint8_t * USBCDC::configurationDesc() {
|
||||
static const uint8_t configDescriptor[] = {
|
||||
// configuration descriptor
|
||||
9, // bLength
|
||||
2, // bDescriptorType
|
||||
|
|
|
@ -46,28 +46,28 @@ protected:
|
|||
*
|
||||
* @returns pointer to the device descriptor
|
||||
*/
|
||||
virtual uint8_t * deviceDesc();
|
||||
virtual const uint8_t * deviceDesc();
|
||||
|
||||
/*
|
||||
* Get string product descriptor
|
||||
*
|
||||
* @returns pointer to the string product descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIproductDesc();
|
||||
virtual const uint8_t * stringIproductDesc();
|
||||
|
||||
/*
|
||||
* Get string interface descriptor
|
||||
*
|
||||
* @returns pointer to the string interface descriptor
|
||||
*/
|
||||
virtual uint8_t * stringIinterfaceDesc();
|
||||
virtual const uint8_t * stringIinterfaceDesc();
|
||||
|
||||
/*
|
||||
* Get configuration descriptor
|
||||
*
|
||||
* @returns pointer to the configuration descriptor
|
||||
*/
|
||||
virtual uint8_t * configurationDesc();
|
||||
virtual const uint8_t * configurationDesc();
|
||||
|
||||
/*
|
||||
* Send a buffer
|
||||
|
|
Loading…
Reference in New Issue