@@ -157,7 +157,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
157157 /* Configuration 1 */
158158 0x09 , /* bLength */
159159 USB_DESC_TYPE_CONFIGURATION , /* bDescriptorType */
160- LOBYTE (USB_AUDIO_CONFIG_DESC_SIZ ), /* wTotalLength 109 bytes */
160+ LOBYTE (USB_AUDIO_CONFIG_DESC_SIZ ), /* wTotalLength */
161161 HIBYTE (USB_AUDIO_CONFIG_DESC_SIZ ),
162162 0x02 , /* bNumInterfaces */
163163 0x01 , /* bConfigurationValue */
@@ -167,7 +167,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
167167#else
168168 0x80 , /* bmAttributes: Bus Powered according to user configuration */
169169#endif
170- USBD_MAX_POWER , /* bMaxPower = 100 mA */
170+ USBD_MAX_POWER , /* MaxPower (mA) */
171171 /* 09 byte*/
172172
173173 /* USB Speaker Standard interface descriptor */
@@ -188,7 +188,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
188188 AUDIO_CONTROL_HEADER , /* bDescriptorSubtype */
189189 0x00 , /* 1.00 */ /* bcdADC */
190190 0x01 ,
191- 0x27 , /* wTotalLength = 39 */
191+ 0x27 , /* wTotalLength */
192192 0x00 ,
193193 0x01 , /* bInCollection */
194194 0x01 , /* baInterfaceNr */
@@ -219,22 +219,22 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
219219 AUDIO_CONTROL_MUTE , /* bmaControls(0) */
220220 0 , /* bmaControls(1) */
221221 0x00 , /* iTerminal */
222- /* 09 byte*/
222+ /* 09 byte */
223223
224- /*USB Speaker Output Terminal Descriptor */
224+ /* USB Speaker Output Terminal Descriptor */
225225 0x09 , /* bLength */
226226 AUDIO_INTERFACE_DESCRIPTOR_TYPE , /* bDescriptorType */
227227 AUDIO_CONTROL_OUTPUT_TERMINAL , /* bDescriptorSubtype */
228228 0x03 , /* bTerminalID */
229- 0x01 , /* wTerminalType 0x0301*/
229+ 0x01 , /* wTerminalType 0x0301 */
230230 0x03 ,
231231 0x00 , /* bAssocTerminal */
232232 0x02 , /* bSourceID */
233233 0x00 , /* iTerminal */
234- /* 09 byte*/
234+ /* 09 byte */
235235
236236 /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwidth */
237- /* Interface 1, Alternate Setting 0 */
237+ /* Interface 1, Alternate Setting 0 */
238238 AUDIO_INTERFACE_DESC_SIZE , /* bLength */
239239 USB_DESC_TYPE_INTERFACE , /* bDescriptorType */
240240 0x01 , /* bInterfaceNumber */
@@ -292,7 +292,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
292292 0x00 , /* bSynchAddress */
293293 /* 09 byte*/
294294
295- /* Endpoint - Audio Streaming Descriptor*/
295+ /* Endpoint - Audio Streaming Descriptor */
296296 AUDIO_STREAMING_ENDPOINT_DESC_SIZE , /* bLength */
297297 AUDIO_ENDPOINT_DESCRIPTOR_TYPE , /* bDescriptorType */
298298 AUDIO_ENDPOINT_GENERAL , /* bDescriptor */
@@ -339,7 +339,7 @@ static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
339339 USBD_AUDIO_HandleTypeDef * haudio ;
340340
341341 /* Allocate Audio structure */
342- haudio = USBD_malloc (sizeof (USBD_AUDIO_HandleTypeDef ));
342+ haudio = ( USBD_AUDIO_HandleTypeDef * ) USBD_malloc (sizeof (USBD_AUDIO_HandleTypeDef ));
343343
344344 if (haudio == NULL )
345345 {
@@ -791,10 +791,11 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
791791 return ;
792792 }
793793
794- (void )USBD_memset (haudio -> control .data , 0 , 64U );
794+ (void )USBD_memset (haudio -> control .data , 0 , USB_MAX_EP0_SIZE );
795795
796796 /* Send the current mute state */
797- (void )USBD_CtlSendData (pdev , haudio -> control .data , req -> wLength );
797+ (void )USBD_CtlSendData (pdev , haudio -> control .data ,
798+ MIN (req -> wLength , USB_MAX_EP0_SIZE ));
798799}
799800
800801/**
@@ -816,12 +817,12 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
816817
817818 if (req -> wLength != 0U )
818819 {
819- /* Prepare the reception of the buffer over EP0 */
820- (void )USBD_CtlPrepareRx (pdev , haudio -> control .data , req -> wLength );
821-
822820 haudio -> control .cmd = AUDIO_REQ_SET_CUR ; /* Set the request value */
823- haudio -> control .len = (uint8_t )req -> wLength ; /* Set the request data length */
821+ haudio -> control .len = (uint8_t )MIN ( req -> wLength , USB_MAX_EP0_SIZE ); /* Set the request data length */
824822 haudio -> control .unit = HIBYTE (req -> wIndex ); /* Set the request target unit */
823+
824+ /* Prepare the reception of the buffer over EP0 */
825+ (void )USBD_CtlPrepareRx (pdev , haudio -> control .data , haudio -> control .len );
825826 }
826827}
827828
0 commit comments