/** * @brief called when an EP is disabled * @param pdev: device instance * @param ep_addr: endpoint address * @retval : status */ uint32_t DCD_EP_Close(USB_CORE_HANDLE *pdev , uint8_t ep_addr) { USB_EP *ep; if ((ep_addr&0x80) == 0x80) { ep = &pdev->dev.in_ep[ep_addr & 0x7F]; } else { ep = &pdev->dev.out_ep[ep_addr & 0x7F]; } if (ep->doublebuffer == 0) { if (ep->is_in) { ClearDTOG_TX(ep->num); /* Configure DISABLE status for the Endpoint*/ SetEPTxStatus(ep->num, EP_TX_DIS); } else { ClearDTOG_RX(ep->num); /* Configure DISABLE status for the Endpoint*/ SetEPRxStatus(ep->num, EP_RX_DIS); } } /*Double Buffer*/ else { if (ep->is_in==0) { /* Clear the data toggle bits for the endpoint IN/OUT*/ ClearDTOG_RX(ep->num); ClearDTOG_TX(ep->num); /* Reset value of the data toggle bits for the endpoint out*/ ToggleDTOG_TX(ep->num); SetEPRxStatus(ep->num, EP_RX_DIS); SetEPTxStatus(ep->num, EP_TX_DIS); } else { /* Clear the data toggle bits for the endpoint IN/OUT*/ ClearDTOG_RX(ep->num); ClearDTOG_TX(ep->num); ToggleDTOG_RX(ep->num); /* Configure DISABLE status for the Endpoint*/ SetEPTxStatus(ep->num, EP_TX_DIS); SetEPRxStatus(ep->num, EP_RX_DIS); } } return USB_OK; }
/******************************************************************************* * Function Name : MASS_NoData_Setup. * Description : Handle the no data class specific requests. * Input : RequestNo. * Output : None. * Return : RESULT. *******************************************************************************/ RESULT MASS_NoData_Setup(uint8_t RequestNo) { if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) && (RequestNo == MASS_STORAGE_RESET) && (pInformation->USBwValue == 0) && (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x00)) { #ifdef STM32F10X_CL /* Init EP1 IN as Bulk endpoint */ OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); /* Init EP2 OUT as Bulk endpoint */ OTG_DEV_EP_Init(EP2_OUT, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); #else /* Initialize Endpoint 1 */ ClearDTOG_TX(ENDP1); /* Initialize Endpoint 2 */ ClearDTOG_RX(ENDP2); #endif /* STM32F10X_CL */ /*initialize the CBW signature to enable the clear feature*/ CBW.dSignature = BOT_CBW_SIGNATURE; Bot_State = BOT_IDLE; return USB_SUCCESS; } return USB_UNSUPPORT; }
// Обработка запрса SetConfiguration void SomeDev_SetConfiguration(void) { if (pInformation->Current_Configuration != 0) { // Сконфигурирован bDeviceState = CONFIGURED; #ifdef STM32F10X_CL // $USBCONFIG - инициализация ендпойнтов // EP1 IN - Bulk endpoint OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); // EP2 OUT - Bulk endpoint OTG_DEV_EP_Init(EP2_OUT, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); #else // $USBCONFIG - очистка DTOG ClearDTOG_TX(ENDP1); ClearDTOG_RX(ENDP2); #endif // } }
/** * @brief Clear stall condition on endpoints. * @param pdev: device instance * @param epnum: endpoint address * @retval : status */ uint32_t DCD_EP_ClrStall (USB_CORE_HANDLE *pdev, uint8_t epnum) { USB_EP *ep; if ((0x80 & epnum) == 0x80) { ep = &pdev->dev.in_ep[epnum & 0x7F]; } else { ep = &pdev->dev.out_ep[epnum]; } if (ep->is_in) { ClearDTOG_TX(ep->num); SetEPTxStatus(ep->num, EP_TX_VALID); ep->is_stall = 0; } else { ClearDTOG_RX(ep->num); SetEPRxStatus(ep->num, EP_RX_VALID); ep->is_stall = 0; } return USB_OK; }
vsf_err_t stm32_usbd_ep_set_OUT_dbuffer(uint8_t idx) { uint16_t epsize = stm32_usbd_ep_get_OUT_epsize(idx); int8_t index; index = stm32_usbd_ep(idx); if (index < 0) { return VSFERR_FAIL; } idx = (uint8_t)index; if ((EP_Cfg_Ptr - epsize) < STM32_USBD_EP_NUM * 8) { return VSFERR_NOT_ENOUGH_RESOURCES; } EP_Cfg_Ptr -= epsize; SetEPDoubleBuff(idx); SetEPDblBuffAddr(idx, GetEPRxAddr(idx), EP_Cfg_Ptr); SetEPDblBuffCount(idx, EP_DBUF_OUT, epsize); ClearDTOG_RX(idx); ClearDTOG_TX(idx); ToggleDTOG_TX(idx); SetEPRxStatus(idx, EP_RX_VALID); SetEPTxStatus(idx, EP_TX_DIS); stm32_usbd_OUT_dbuffer[idx] = true; return VSFERR_NONE; }
/******************************************************************************* * Function Name : Mass_Storage_SetConfiguration * Description : Handle the SetConfiguration request. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Mass_Storage_SetConfiguration(void) { if (pInformation->Current_Configuration) { ClearDTOG_TX(ENDP1); ClearDTOG_RX(ENDP2); Bot_State = BOT_IDLE; /* set the Bot state machine to the IDLE state */ } }
/******************************************************************************* * Function Name : Standard_ClearFeature. * Description : Clear or disable a specific feature. * Input : None. * Output : None. * Return : - Return USB_SUCCESS, if the request is performed. * - Return USB_UNSUPPORT, if the request is invalid. *******************************************************************************/ RESULT Standard_ClearFeature(void) { uint32_t Type_Rec = Type_Recipient; uint32_t Status; if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT)) { // Device Clear Feature ClrBit(pInformation->Current_Feature, 5); return USB_SUCCESS; } else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) { // EndPoint Clear Feature DEVICE* pDev; uint32_t Related_Endpoint; uint32_t wIndex0; uint32_t rEP; if ((pInformation->USBwValue != ENDPOINT_STALL) || (pInformation->USBwIndex1 != 0)) { return USB_UNSUPPORT; } pDev = &Device_Table; wIndex0 = pInformation->USBwIndex0; rEP = wIndex0 & ~0x80; Related_Endpoint = ENDP0 + rEP; if (ValBit(pInformation->USBwIndex0, 7)) { // Get Status of endpoint & stall the request if the related_ENdpoint is Disabled Status = GetEPTxStatus(Related_Endpoint); } else { Status = GetEPRxStatus(Related_Endpoint); } if ((rEP >= pDev->Total_Endpoint) || (Status == 0) || (pInformation->Current_Configuration == 0)) { return USB_UNSUPPORT; } if (wIndex0 & 0x80) { // IN endpoint if (GetTxStallStatus(Related_Endpoint )) { ClearDTOG_TX(Related_Endpoint); SetEPTxStatus(Related_Endpoint, EP_TX_VALID); } } else { // OUT endpoint if (GetRxStallStatus(Related_Endpoint)) { if (Related_Endpoint == ENDP0) { // After clear the STALL, enable the default endpoint receiver SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize); SetEPRxStatus(Related_Endpoint, EP_RX_VALID); } else { ClearDTOG_RX(Related_Endpoint); SetEPRxStatus(Related_Endpoint, EP_RX_VALID); } } } pUser_Standard_Requests->User_ClearFeature(); return USB_SUCCESS; } return USB_UNSUPPORT; }
/******************************************************************************* Mass_Storage_SetConfiguration: Handle the SetConfiguration request. *******************************************************************************/ void Mass_Storage_SetConfiguration(void) { if (pInformation->Current_Configuration != 0){ bDeviceState = CONFIGURED; // Device configured ClearDTOG_TX(ENDP1); ClearDTOG_RX(ENDP2); Bot_State = BOT_IDLE; // set the Bot state machine to the IDLE state } }
vsf_err_t stm32_usbd_ep_reset_IN_toggle(uint8_t idx) { int8_t index; index = stm32_usbd_ep(idx); if (index < 0) { return VSFERR_FAIL; } idx = (uint8_t)index; ClearDTOG_TX(idx); return VSFERR_NONE; }
/******************************************************************************* MASS_NoData_Setup: Handle the no data class specific requests. *******************************************************************************/ RESULT MASS_NoData_Setup(u8 RequestNo) { if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) && (RequestNo == MASS_STORAGE_RESET) && (pInformation->USBwValue == 0) && (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x00)) { ClearDTOG_TX(ENDP1); // Initialize Endpoint 1 ClearDTOG_RX(ENDP2); // Initialize Endpoint 2 CBW.dSignature = BOT_CBW_SIGNATURE; // intialise the CBW signature to enable the clear feature Bot_State = BOT_IDLE; return USB_SUCCESS; } return USB_UNSUPPORT; }
/******************************************************************************* * Function Name : Speaker_Reset. * Description : Speaker reset routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Speaker_Reset() { /* Set Speaker device as not configured state */ pInformation->Current_Configuration = 0; /* Current Feature initialization */ pInformation->Current_Feature = Speaker_ConfigDescriptor[7]; SetBTABLE(BTABLE_ADDRESS); /* Initialize Endpoint 0 */ SetEPType(ENDP0, EP_CONTROL); SetEPTxStatus(ENDP0, EP_TX_NAK); SetEPRxAddr(ENDP0, ENDP0_RXADDR); SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); SetEPTxAddr(ENDP0, ENDP0_TXADDR); Clear_Status_Out(ENDP0); SetEPRxValid(ENDP0); /* Initialize Endpoint 1 */ SetEPType(ENDP1, EP_ISOCHRONOUS); SetEPDoubleBuff(ENDP4); SetEPDblBuffAddr(ENDP1, ENDP1_BUF0Addr, ENDP1_BUF1Addr); SetEPDblBuffCount(ENDP1, EP_DBUF_IN, PACKET_SIZE); ClearDTOG_RX(ENDP1); ClearDTOG_TX(ENDP1); SetEPRxStatus(ENDP1, EP_RX_DIS); SetEPTxStatus(ENDP1, EP_TX_VALID); SetEPType(ENDP2, EP_INTERRUPT); SetEPTxAddr(ENDP2, ENDP2_TXADDR); SetEPTxCount(ENDP2, 0x40); SetEPRxStatus(ENDP2, EP_RX_DIS); SetEPTxStatus(ENDP2, EP_TX_NAK); SetEPType(ENDP3, EP_INTERRUPT); SetEPTxAddr(ENDP3, ENDP3_TXADDR); SetEPTxCount(ENDP3, 0x40); SetEPRxStatus(ENDP3, EP_RX_DIS); SetEPTxStatus(ENDP3, EP_TX_NAK); SetEPRxValid(ENDP0); /* Set this device to response on default address */ SetDeviceAddress(0); bDeviceState = ATTACHED; }
/******************************************************************************* * Function Name : USB_SetConfiguration * Description : Handle the SetConfiguration request. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void USB_SetConfiguration(void) { if (pInformation->Current_Configuration != 0) { /* Device configured */ bDeviceState = CONFIGURED; #ifdef STM32F10X_CL /* Init EP1 IN as Bulk endpoint */ OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); /* Init EP2 OUT as Bulk endpoint */ OTG_DEV_EP_Init(EP2_OUT, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); #else ClearDTOG_TX(ENDP1); ClearDTOG_RX(ENDP2); #endif /* STM32F10X_CL */ } }
/******************************************************************************* * Function Name : Joystick_SetConfiguration. * Description : Udpade the device state to configured. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void USB_APP_SetConfiguration(void) { DEVICE_INFO *pInfo = &Device_Info; if (pInfo->Current_Configuration != 0) { /* Device configured */ bDeviceState = CONFIGURED; #if(USB_DEVICE_CONFIG & _USE_USB_MASS_STOARGE_DEVICE) if (g_usb_type == USB_MASSSTORAGE) { ClearDTOG_TX(ENDP1); ClearDTOG_RX(ENDP2); Bot_State = BOT_IDLE; /* set the Bot state machine to the IDLE state */ } #endif } }
/******************************************************************************* * Function Name : Mass_Storage_SetConfiguration * Description : Handle the SetConfiguration request. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Mass_Storage_SetConfiguration(void) { if (pInformation->Current_Configuration != 0) { /* Device configured */ bDeviceState = CONFIGURED; #ifdef STM32F10X_CL /* Init EP1 IN as Bulk endpoint */ OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); /* Init EP2 OUT as Bulk endpoint */ OTG_DEV_EP_Init(EP2_OUT, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); #else ClearDTOG_TX(ENDP1); ClearDTOG_RX(ENDP2); #endif /* STM32F10X_CL */ Bot_State = BOT_IDLE; /* set the Bot state machine to the IDLE state */ } }
/******************************************************************************* * Function Name : Microphone_Reset. * Description : Microphone reset routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Microphone_Reset() { /* Set Microphone device as not configured state */ pInformation->Current_Configuration = 0; /* Current Feature initialization */ pInformation->Current_Feature = Microphone_ConfigDescriptor[7]; SetBTABLE(BTABLE_ADDRESS); /* Initialize Endpoint 0 */ SetEPType(ENDP0, EP_CONTROL); SetEPTxStatus(ENDP0, EP_TX_NAK); SetEPRxAddr(ENDP0, ENDP0_RXADDR); SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); SetEPTxAddr(ENDP0, ENDP0_TXADDR); Clear_Status_Out(ENDP0); SetEPRxValid(ENDP0); /* Initialize Endpoint 1 */ SetEPType(ENDP1, EP_ISOCHRONOUS); SetEPDblBuffAddr(ENDP1, ENDP1_BUF0Addr, ENDP1_BUF1Addr); //SetEPDblBuffCount(ENDP1, EP_DBUF_IN, 0x40); SetEPDblBuffCount(ENDP1, EP_DBUF_IN, 0x60); ClearDTOG_RX(ENDP1); ClearDTOG_TX(ENDP1); ToggleDTOG_TX(ENDP1); SetEPRxStatus(ENDP1, EP_RX_DIS); SetEPTxStatus(ENDP1, EP_TX_VALID); SetEPRxValid(ENDP0); /* Set this device to response on default address */ SetDeviceAddress(0); bDeviceState = ATTACHED; //In_Data_Offset = 0; //Out_Data_Offset = 0; }
/******************************************************************************* Function Name : Speaker_Reset. Description : Speaker reset routine. Input : None. Output : None. Return : None. *******************************************************************************/ void Speaker_Reset() { // Set Speaker device as not configured state pInformation->Current_Configuration = 0; // Current Feature initialization pInformation->Current_Feature = Speaker_ConfigDescriptor[7]; // *BTABLE = BTABLE_ADDRESS & 0xFFF8; *BTABLE = BTABLE_ADDRESS; // BTABLE_ADDRESS = 0 // Initialize Endpoint 0 SetEPType(ENDP0,EP_CONTROL); SetEPTxStatus(ENDP0,EP_TX_NAK); SetEPRxAddr(ENDP0,ENDP0_RXADDR); SetEPRxCount(ENDP0,Device_Property.MaxPacketSize); SetEPTxAddr(ENDP0,ENDP0_TXADDR); Clear_Status_Out(ENDP0); SetEPRxValid(ENDP0); // Initialize Endpoint 1 SetEPType(ENDP1,EP_ISOCHRONOUS); SetEPDblBuffAddr(ENDP1,ENDP1_BUF0Addr,ENDP1_BUF1Addr); SetEPDblBuffCount(ENDP1,EP_DBUF_OUT,0x40); ClearDTOG_RX(ENDP1); ClearDTOG_TX(ENDP1); ToggleDTOG_TX(ENDP1); SetEPRxStatus(ENDP1,EP_RX_VALID); SetEPTxStatus(ENDP1,EP_TX_DIS); SetEPRxValid(ENDP0); // Set this device to response on default address SetDeviceAddress(0); bDeviceState = ATTACHED; In_Data_Offset = 0; Out_Data_Offset = 0; }
/** * @brief Configure an EP * @param pdev : Device instance * @param ep_addr: endpoint address * @param ep_mps: endpoint max packet size * @param ep_type: endpoint Type */ uint32_t DCD_EP_Open(USB_CORE_HANDLE *pdev , uint16_t ep_addr, uint16_t ep_mps, uint8_t ep_type) { USB_EP *ep; /* initialize ep structure*/ if ((ep_addr & 0x80) == 0x80) { ep = &pdev->dev.in_ep[ep_addr & 0x7F]; ep->is_in = 1; } else { ep = &pdev->dev.out_ep[ep_addr & 0x7F]; ep->is_in = 0; } ep->maxpacket = ep_mps; ep->type = ep_type; ep->num = ep_addr & 0x7F; if (ep->num == 0) { /* Initialize the control transfer variables*/ ep->ctl_data_len =0; ep->rem_data_len = 0; ep->total_data_len = 0; } /* Initialize the transaction level variables */ ep->xfer_buff = 0; ep->xfer_len = 0; ep->xfer_count = 0; ep->is_stall = 0; /* initialize HW */ switch (ep->type) { case USB_EP_CONTROL: SetEPType(ep->num, EP_CONTROL); break; case USB_EP_BULK: SetEPType(ep->num, EP_BULK); break; case USB_EP_INT: SetEPType(ep->num, EP_INTERRUPT); break; case USB_EP_ISOC: SetEPType(ep->num, EP_ISOCHRONOUS); break; } if (ep->doublebuffer == 0) { if (ep->is_in) { /*Set the endpoint Transmit buffer address */ SetEPTxAddr(ep->num, ep->pmaadress); ClearDTOG_TX(ep->num); /* Configure NAK status for the Endpoint*/ SetEPTxStatus(ep->num, EP_TX_NAK); } else { /*Set the endpoint Receive buffer address */ SetEPRxAddr(ep->num, ep->pmaadress); /*Set the endpoint Receive buffer counter*/ SetEPRxCount(ep->num, ep->maxpacket); ClearDTOG_RX(ep->num); /* Configure VALID status for the Endpoint*/ SetEPRxStatus(ep->num, EP_RX_VALID); } } /*Double Buffer*/ else { /*Set the endpoint as double buffered*/ SetEPDoubleBuff(ep->num); /*Set buffer address for double buffered mode*/ SetEPDblBuffAddr(ep->num,ep->pmaaddr0, ep->pmaaddr1); if (ep->is_in==0) { /* Clear the data toggle bits for the endpoint IN/OUT*/ ClearDTOG_RX(ep->num); ClearDTOG_TX(ep->num); /* Reset value of the data toggle bits for the endpoint out*/ ToggleDTOG_TX(ep->num); SetEPRxStatus(ep->num, EP_RX_VALID); SetEPTxStatus(ep->num, EP_TX_DIS); } else { /* Clear the data toggle bits for the endpoint IN/OUT*/ ClearDTOG_RX(ep->num); ClearDTOG_TX(ep->num); ToggleDTOG_RX(ep->num); /* Configure DISABLE status for the Endpoint*/ SetEPTxStatus(ep->num, EP_TX_DIS); SetEPRxStatus(ep->num, EP_RX_DIS); } } return USB_OK; }
/******************************************************************************* * Function Name : Joystick_NoData_Setup * Description : handle the no data class specific requests * Input : Request Nb. * Output : None. * Return : USB_UNSUPPORT or USB_SUCCESS. *******************************************************************************/ RESULT USB_APP_NoData_Setup(u8 RequestNo) { #if(USB_DEVICE_CONFIG & _USE_USB_VIRTUAL_COMM_DEVICE) if (g_usb_type == USB_VIRTUAL_PORT) { if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) { if (RequestNo == SET_COMM_FEATURE) { return USB_SUCCESS; } else if (RequestNo == SET_CONTROL_LINE_STATE) { return USB_SUCCESS; } } } else #endif #if(USB_DEVICE_CONFIG & _USE_USB_KEYBOARD_DEVICE) if(g_usb_type == USB_KEYBOARD) { if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) && (RequestNo == SET_PROTOCOL)) { return Keyboard_SetProtocol(); } } else #endif #if(USB_DEVICE_CONFIG & _USE_USB_MASS_STOARGE_DEVICE) if(g_usb_type == USB_MASSSTORAGE) { if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) && (RequestNo == MASS_STORAGE_RESET) && (pInformation->USBwValue == 0) && (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x00)) { /* Initialize Endpoint 1 */ ClearDTOG_TX(ENDP1); /* Initialize Endpoint 2 */ ClearDTOG_RX(ENDP2); /*intialise the CBW signature to enable the clear feature*/ CBW.dSignature = BOT_CBW_SIGNATURE; Bot_State = BOT_IDLE; return USB_SUCCESS; } } else #endif #if(USB_DEVICE_CONFIG & _USE_USB_PRINTER_DEVICE) { if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) && (RequestNo == SOFT_RESET) && (pInformation->USBwValue == 0) && (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x00)) { print_device_reset(); return USB_SUCCESS; } } #endif ; return USB_UNSUPPORT; }