45 uint8_t USBD_StrDesc[USB_STR_DESC_MAX_SIZE];
57 USBD_GetConfiguration,
58 USBD_SetConfiguration,
81 (*StandardDeviceRequest[req->bRequest])(pudev, req);
96 switch (pudev->dev.device_cur_status)
98 case USB_STATUS_CONFIGURED:
99 if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
102 ret = (
USBD_Status)(pudev->dev.class_cb->ClassReqHandle(pudev, req));
104 if((req->wLength == 0) && (ret == USBD_OK))
157 uint16_t config_status = 0x0000;
158 uint16_t endp_status = 0x0000;
160 switch(req->bmRequestType & USB_REQ_RECIPIENT_MASK)
162 case USB_REQTYPE_DEVICE:
163 switch (pudev->dev.device_cur_status)
165 case USB_STATUS_ADDRESSED:
166 case USB_STATUS_CONFIGURED:
168 #ifdef USBD_SELF_POWERED
169 config_status = USB_STATUS_SELF_POWERED;
172 if (pudev->dev.DevRemoteWakeup)
174 config_status |= USB_STATUS_REMOTE_WAKEUP;
176 USB_CtlTx(pudev, (uint8_t *)&config_status, 2);
184 case USB_REQTYPE_INTERFACE:
185 switch (pudev->dev.device_cur_status)
187 case USB_STATUS_ADDRESSED:
191 case USB_STATUS_CONFIGURED:
192 if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
194 USB_CtlTx(pudev, (uint8_t *)&config_status, 2);
207 case USB_REQTYPE_ENDPOINT:
208 ep_addr = LOWBYTE(req->wIndex);
210 switch (pudev->dev.device_cur_status)
212 case USB_STATUS_ADDRESSED:
213 if (IS_NOT_EP0(ep_addr))
219 case USB_STATUS_CONFIGURED:
220 if ((ep_addr & 0x80)== 0x80)
222 if(pudev->dev.in_ep[ep_addr & 0x7F].is_stall)
224 endp_status = 0x0001;
229 if(pudev->dev.out_ep[ep_addr].is_stall)
231 endp_status = 0x0001;
234 USB_CtlTx(pudev, (uint8_t *)&endp_status, 2);
258 switch(req->bmRequestType & USB_REQ_RECIPIENT_MASK)
260 case USB_REQTYPE_DEVICE:
261 switch (pudev->dev.device_cur_status)
263 case USB_STATUS_ADDRESSED:
264 case USB_STATUS_CONFIGURED:
265 if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
267 pudev->dev.DevRemoteWakeup = 0;
270 else if(req->wValue == USB_FEATURE_TEST_MODE)
282 case USB_REQTYPE_INTERFACE:
283 switch(pudev->dev.device_cur_state)
285 case USB_STATUS_ADDRESSED:
289 case USB_STATUS_CONFIGURED:
290 if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
304 case USB_REQTYPE_ENDPOINT:
305 ep_addr = LOWBYTE(req->wIndex);
307 switch (pudev->dev.device_cur_status)
309 case USB_STATUS_ADDRESSED:
310 if (IS_NOT_EP0(ep_addr))
316 case USB_STATUS_CONFIGURED:
317 if (req->wValue == USB_FEATURE_ENDP_HALT)
319 if (IS_NOT_EP0(ep_addr))
348 switch(req->bmRequestType & USB_REQ_RECIPIENT_MASK)
350 case USB_REQTYPE_DEVICE:
351 switch (pudev->dev.device_cur_status)
353 case USB_STATUS_ADDRESSED:
354 case USB_STATUS_CONFIGURED:
355 if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
357 pudev->dev.DevRemoteWakeup = 1;
367 case USB_REQTYPE_INTERFACE:
368 switch(pudev->dev.device_cur_state)
370 case USB_STATUS_ADDRESSED:
374 case USB_STATUS_CONFIGURED:
375 if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
389 case USB_REQTYPE_ENDPOINT:
390 switch (pudev->dev.device_cur_status)
392 case USB_STATUS_ADDRESSED:
393 if (IS_NOT_EP0(ep_addr))
399 case USB_STATUS_CONFIGURED:
400 if (req->wValue == USB_FEATURE_ENDP_HALT)
402 if (IS_NOT_EP0(ep_addr))
429 if ((req->wIndex == 0) && (req->wLength == 0))
431 gAddress = (uint8_t)(req->wValue) & 0x7F;
433 if (pudev->dev.device_cur_status == USB_STATUS_CONFIGURED)
443 pudev->dev.device_cur_status = USB_STATUS_ADDRESSED;
447 pudev->dev.device_cur_status = USB_STATUS_DEFAULT;
465 if((req->bmRequestType & USB_REQ_RECIPIENT_MASK) == USB_REQTYPE_DEVICE)
470 switch (req->wValue >> 8)
472 case USB_DESCTYPE_DEVICE:
473 pbuf = pudev->dev.desc_cb->GetDeviceDescriptor(pudev->dev.speed, &len);
474 if (req->wLength == 64) len = 8;
477 case USB_DESCTYPE_CONFIGURATION:
478 pbuf = (uint8_t *)pudev->dev.class_cb->GetConfigDescriptor(pudev->dev.speed, &len);
481 case USB_DESCTYPE_STRING:
482 switch ((uint8_t)(req->wValue))
484 case USBD_LANGID_STR_IDX:
485 pbuf = pudev->dev.desc_cb->GetLangIDStrDescriptor(pudev->dev.speed, &len);
488 case USBD_MFC_STR_IDX:
489 pbuf = pudev->dev.desc_cb->GetManufacturerStrDescriptor(pudev->dev.speed, &len);
492 case USBD_PRODUCT_STR_IDX:
493 pbuf = pudev->dev.desc_cb->GetProductStrDescriptor(pudev->dev.speed, &len);
496 case USBD_SERIAL_STR_IDX:
497 pbuf = pudev->dev.desc_cb->GetSerialStrDescriptor(pudev->dev.speed, &len);
500 case USBD_CONFIG_STR_IDX:
501 pbuf = pudev->dev.desc_cb->GetConfigurationStrDescriptor(pudev->dev.speed, &len);
504 case USBD_INTERFACE_STR_IDX:
505 pbuf = pudev->dev.desc_cb->GetInterfaceStrDescriptor(pudev->dev.speed, &len);
509 #ifdef USB_SUPPORT_USER_STRING_DESC
510 pbuf = pudev->dev.class_cb->GetUsrStrDescriptor(pudev->dev.speed, (req->wValue), &len);
519 case USB_DESCTYPE_DEVICE_QUALIFIER:
523 case USB_DESCTYPE_OTHER_SPEED_CONFIGURATION:
532 if((len != 0) && (req->wLength != 0))
534 len = MIN(len, req->wLength);
539 else if((req->bmRequestType & USB_REQ_RECIPIENT_MASK) == USB_REQTYPE_INTERFACE)
541 pudev->dev.class_cb->GetClassDescriptor(pudev, req);
564 uint32_t USBD_default_config = 0;
566 if (req->wLength != 1)
572 switch (pudev->dev.device_cur_status)
574 case USB_STATUS_ADDRESSED:
575 USB_CtlTx (pudev, (uint8_t *)&USBD_default_config, 1);
578 case USB_STATUS_CONFIGURED:
579 USB_CtlTx (pudev, &pudev->dev.device_cur_config, 1);
596 static uint8_t cfgidx;
598 cfgidx = (uint8_t)(req->wValue);
600 if (cfgidx > USBD_CFG_MAX_NUM)
606 switch (pudev->dev.device_cur_status)
608 case USB_STATUS_ADDRESSED:
611 pudev->dev.device_cur_config = cfgidx;
612 pudev->dev.device_cur_status = USB_STATUS_CONFIGURED;
622 case USB_STATUS_CONFIGURED:
625 pudev->dev.device_cur_status = USB_STATUS_ADDRESSED;
626 pudev->dev.device_cur_config = cfgidx;
630 else if (cfgidx != pudev->dev.device_cur_config)
636 pudev->dev.device_cur_config = cfgidx;
660 switch (pudev->dev.device_cur_status)
662 case USB_STATUS_ADDRESSED:
666 case USB_STATUS_CONFIGURED:
667 if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
669 pudev->dev.class_cb->GetInterface (pudev, req);
690 switch (pudev->dev.device_cur_status)
692 case USB_STATUS_ADDRESSED:
696 case USB_STATUS_CONFIGURED:
697 if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
699 pudev->dev.class_cb->SetInterface (pudev, req);
733 req->bmRequestType = *(uint8_t *) (pudev->dev.setup_packet);
734 req->bRequest = *(uint8_t *) (pudev->dev.setup_packet + 1);
735 req->wValue = SWAPBYTE (pudev->dev.setup_packet + 2);
736 req->wIndex = SWAPBYTE (pudev->dev.setup_packet + 4);
737 req->wLength = SWAPBYTE (pudev->dev.setup_packet + 6);
739 pudev->dev.device_cur_state = USB_CTRL_SETUP;
768 unicode[idx++] = USB_DESCTYPE_STRING;
770 for (; *desc != NULL; )
772 unicode[idx++] = *desc++;
773 unicode[idx++] = 0x00;
uint8_t USBD_VdrDefReq(USB_DEVICE_HANDLE *pudev, USB_DEVICE_REQ *req)
Handle usb vendor request.
void USBD_EnumError(USB_CORE_HANDLE *pudev, USB_DEVICE_REQ *req)
Handle usb enumeration error event.
uint8_t USBD_StdReq(USB_DEVICE_HANDLE *pudev, USB_DEVICE_REQ *req)
Handle usb standard device request.
void USB_EP_ClrStall(USB_CORE_HANDLE *pudev, uint8_t EpID)
Clear endpoint stalled status.
uint8_t USB_CtlTransmitStatus(USB_CORE_HANDLE *pudev)
Transmit status stage on the control pipe.
uint8_t USBD_DevClsReq(USB_DEVICE_HANDLE *pudev, USB_DEVICE_REQ *req)
Handle device class request.
USBD_Status USBD_SetCfg(USB_DEVICE_HANDLE *pudev, uint8_t ConfigIndex)
Device configuration and interface setting.
USBD_Status
USB device operation status.
uint8_t USB_CtlTx(USB_CORE_HANDLE *pudev, uint8_t *pbuf, uint16_t Len)
Transmit data on the control pipe.
void USB_EP_Stall(USB_CORE_HANDLE *pudev, uint8_t EpID)
Set an endpoint to STALL status.
void USBD_GetUnicodeString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
Convert normal string into unicode one.
void USBD_ParseSetupRequest(USB_CORE_HANDLE *pudev, USB_DEVICE_REQ *req)
Decode setup data packet.
USB enumeration function prototypes.
USBD_Status USBD_ClrCfg(USB_DEVICE_HANDLE *pudev, uint8_t ConfigIndex)
Clear current configuration.
USB standard device request struct.