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; }
/** * @brief Transmit data Buffer * @param pdev: device instance * @param ep_addr: endpoint address * @param pbuf: pointer to Tx buffer * @param buf_len: data length * @retval : status */ uint32_t DCD_EP_Tx ( USB_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len) { __IO uint32_t len = 0; USB_EP *ep; ep = &pdev->dev.in_ep[ep_addr & 0x7F]; /*setup and start the Xfer */ ep->num = ep_addr & 0x7F; ep->xfer_buff = pbuf; ep->xfer_len = buf_len; ep->xfer_count = 0; /*Multi packet transfer*/ if (ep->xfer_len > ep->maxpacket) { len=ep->maxpacket; ep->xfer_len-=len; } else { len=ep->xfer_len; ep->xfer_len =0; } /* configure and validate Tx endpoint */ if (ep->doublebuffer == 0) { UserToPMABufferCopy(ep->xfer_buff, ep->pmaadress, len); SetEPTxCount(ep->num, len); } else { uint16_t pmabuffer=0; /*Set the Double buffer counter*/ SetEPDblBuffCount(ep->num, ep->is_in, len); /*Write the data to the USB endpoint*/ if (GetENDPOINT(ep->num)&EP_DTOG_TX) { pmabuffer = ep->pmaaddr1; } else { pmabuffer = ep->pmaaddr0; } UserToPMABufferCopy(ep->xfer_buff, pmabuffer, len); FreeUserBuffer(ep->num, ep->is_in); } SetEPTxStatus(ep->num, EP_TX_VALID); return USB_OK; }
/******************************************************************************* * 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; }
/** * @brief DCD_EP_PrepareRx * @param pdev: device instance * @param ep_addr: endpoint address * @param pbuf: pointer to Rx buffer * @param buf_len: data length * @retval : status */ uint32_t DCD_EP_PrepareRx( USB_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len) { __IO uint32_t len = 0; USB_EP *ep; ep = &pdev->dev.out_ep[ep_addr & 0x7F]; /*setup and start the Xfer */ ep->xfer_buff = pbuf; ep->xfer_len = buf_len; ep->xfer_count = 0; /*Multi packet transfer*/ if (ep->xfer_len > ep->maxpacket) { len=ep->maxpacket; ep->xfer_len-=len; } else { len=ep->xfer_len; ep->xfer_len =0; } /* configure and validate Rx endpoint */ if (ep->doublebuffer == 0) { /*Set RX buffer count*/ SetEPRxCount(ep->num, len); } else { /*Set the Double buffer counter*/ SetEPDblBuffCount(ep->num, ep->is_in, len); } SetEPRxStatus(ep->num, EP_RX_VALID); return USB_OK; }
/******************************************************************************* * 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; }