Commit 092f82e0 authored by Dean Camera's avatar Dean Camera
Browse files

Changed the signature of the CALLBACK_USB_GetDescriptor() callback function so...

Changed the signature of the CALLBACK_USB_GetDescriptor() callback function so that the descriptor pointer is const, to remove the need for extra casting inside the callback (thanks to Jonathan Kollasch).
parent ed8ad18f
...@@ -340,37 +340,37 @@ USB_Descriptor_String_t PROGMEM ProductString = ...@@ -340,37 +340,37 @@ USB_Descriptor_String_t PROGMEM ProductString =
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&ProductString.Header.Size);
break; break;
} }
......
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif #endif
...@@ -201,48 +201,48 @@ USB_Descriptor_String_t PROGMEM ProductString = ...@@ -201,48 +201,48 @@ USB_Descriptor_String_t PROGMEM ProductString =
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&ProductString.Header.Size);
break; break;
} }
break; break;
case DTYPE_HID: case DTYPE_HID:
Address = (void*)&ConfigurationDescriptor.HID_GenericHID; Address = &ConfigurationDescriptor.HID_GenericHID;
Size = sizeof(USB_Descriptor_HID_t); Size = sizeof(USB_Descriptor_HID_t);
break; break;
case DTYPE_Report: case DTYPE_Report:
Address = (void*)&GenericReport; Address = &GenericReport;
Size = sizeof(GenericReport); Size = sizeof(GenericReport);
break; break;
} }
......
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif #endif
...@@ -201,48 +201,48 @@ USB_Descriptor_String_t PROGMEM ProductString = ...@@ -201,48 +201,48 @@ USB_Descriptor_String_t PROGMEM ProductString =
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&ProductString.Header.Size);
break; break;
} }
break; break;
case DTYPE_HID: case DTYPE_HID:
Address = (void*)&ConfigurationDescriptor.HID_JoystickHID; Address = &ConfigurationDescriptor.HID_JoystickHID;
Size = sizeof(USB_Descriptor_HID_t); Size = sizeof(USB_Descriptor_HID_t);
break; break;
case DTYPE_Report: case DTYPE_Report:
Address = (void*)&JoystickReport; Address = &JoystickReport;
Size = sizeof(JoystickReport); Size = sizeof(JoystickReport);
break; break;
} }
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif #endif
...@@ -218,48 +218,48 @@ USB_Descriptor_String_t PROGMEM ProductString = ...@@ -218,48 +218,48 @@ USB_Descriptor_String_t PROGMEM ProductString =
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&ProductString.Header.Size);
break; break;
} }
break; break;
case DTYPE_HID: case DTYPE_HID:
Address = (void*)&ConfigurationDescriptor.HID_KeyboardHID; Address = &ConfigurationDescriptor.HID_KeyboardHID;
Size = sizeof(USB_Descriptor_HID_t); Size = sizeof(USB_Descriptor_HID_t);
break; break;
case DTYPE_Report: case DTYPE_Report:
Address = (void*)&KeyboardReport; Address = &KeyboardReport;
Size = sizeof(KeyboardReport); Size = sizeof(KeyboardReport);
break; break;
} }
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif #endif
...@@ -288,37 +288,37 @@ USB_Descriptor_String_t PROGMEM ProductString = ...@@ -288,37 +288,37 @@ USB_Descriptor_String_t PROGMEM ProductString =
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&ProductString.Header.Size);
break; break;
} }
...@@ -327,24 +327,24 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, ...@@ -327,24 +327,24 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
case DTYPE_HID: case DTYPE_HID:
if (!(wIndex)) if (!(wIndex))
{ {
Address = (void*)&ConfigurationDescriptor.HID1_KeyboardHID; Address = &ConfigurationDescriptor.HID1_KeyboardHID;
Size = sizeof(USB_Descriptor_HID_t); Size = sizeof(USB_Descriptor_HID_t);
} }
else else
{ {
Address = (void*)&ConfigurationDescriptor.HID2_MouseHID; Address = &ConfigurationDescriptor.HID2_MouseHID;
Size = sizeof(USB_Descriptor_HID_t); Size = sizeof(USB_Descriptor_HID_t);
} }
break; break;
case DTYPE_Report: case DTYPE_Report:
if (!(wIndex)) if (!(wIndex))
{ {
Address = (void*)&KeyboardReport; Address = &KeyboardReport;
Size = sizeof(KeyboardReport); Size = sizeof(KeyboardReport);
} }
else else
{ {
Address = (void*)&MouseReport; Address = &MouseReport;
Size = sizeof(MouseReport); Size = sizeof(MouseReport);
} }
......
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif #endif
...@@ -285,37 +285,37 @@ USB_Descriptor_String_t PROGMEM ProductString = ...@@ -285,37 +285,37 @@ USB_Descriptor_String_t PROGMEM ProductString =
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&ProductString.Header.Size);
break; break;
} }
......
...@@ -185,6 +185,7 @@ ...@@ -185,6 +185,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,