/** * @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; }
vsf_err_t stm32_usbd_ep_toggle_OUT_toggle(uint8_t idx) { int8_t index; index = stm32_usbd_ep(idx); if (index < 0) { return VSFERR_FAIL; } idx = (uint8_t)index; ToggleDTOG_RX(idx); return VSFERR_NONE; }
/** * @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 : ClearDTOG_RX. * Description : Clear the DTOG_RX bit. * Input : bEpNum: Endpoint Number. * Output : None. * Return : None. *******************************************************************************/ void ClearDTOG_RX(uint8_t bEpNum) { if ((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0) ToggleDTOG_RX(bEpNum); }