static inline uint8_t usbd_cdc_transfer(void *pdev) { if (sended != 0 || rndis_tx_ptr == NULL || rndis_tx_size <= 0) return USBD_OK; if (rndis_first_tx) { static uint8_t first[RNDIS_DATA_IN_SZ]; rndis_data_packet_t *hdr; hdr = (rndis_data_packet_t *)first; memset(hdr, 0, sizeof(rndis_data_packet_t)); hdr->MessageType = REMOTE_NDIS_PACKET_MSG; hdr->MessageLength = sizeof(rndis_data_packet_t) + rndis_tx_size; hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset); hdr->DataLength = rndis_tx_size; sended = RNDIS_DATA_IN_SZ - sizeof(rndis_data_packet_t); if (sended > rndis_tx_size) sended = rndis_tx_size; memcpy(first + sizeof(rndis_data_packet_t), rndis_tx_ptr, sended); DCD_EP_Tx(pdev, RNDIS_DATA_IN_EP, (uint8_t *)&first, sizeof(rndis_data_packet_t) + sended); } else { int n = rndis_tx_size; if (n > RNDIS_DATA_IN_SZ) n = RNDIS_DATA_IN_SZ; DCD_EP_Tx(pdev, RNDIS_DATA_IN_EP, rndis_tx_ptr, n); sended = n; } return USBD_OK; }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { (void)pdev; (void)epnum; uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if (USB_Tx_State == USB_CDC_BUSY) { if (APP_Rx_length == 0) { USB_Tx_State = USB_CDC_IDLE; } else { if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; if(USB_Tx_length == CDC_DATA_IN_PACKET_SIZE) { USB_Tx_State = USB_CDC_ZLP; } } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); return USBD_OK; } } /* Avoid any asynchronous transfer during ZLP */ if (USB_Tx_State == USB_CDC_ZLP) { /*Send ZLP to indicate the end of the current transfer */ DCD_EP_Tx (pdev, CDC_IN_EP, NULL, 0); USB_Tx_State = USB_CDC_IDLE; } return USBD_OK; }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if (USB_Tx_State == 1) { if (APP_Rx_length == 0) { if (last_packet ==1) { last_packet =0; /*Send zero-length packet*/ DCD_EP_Tx (pdev, CDC_IN_EP, 0, 0); } else { USB_Tx_State = 0; } } else { if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; if (APP_Rx_length == CDC_DATA_IN_PACKET_SIZE) last_packet = 1; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } } return USBD_OK; }
/** * @brief USBD_CDC_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t USBD_CDC_DataIn (void *pdev, uint8_t epnum) { uint16_t i; if (USBD_CDC_InFlight != 0) { USBD_CDC_InFlight = 0; } if (ringbuffer_isempty(&USBD_CDC_D2H_FIFO) == 0) { for (i = 0; i < CDC_DATA_IN_PACKET_SIZE && ringbuffer_isempty(&USBD_CDC_D2H_FIFO) == 0; i++) { USBD_CDC_D2H_Buff[i] = ringbuffer_pop(&USBD_CDC_D2H_FIFO); } dbgwdg_feed(); DCD_EP_Tx (pdev, USBD_Dev_CDC_D2H_EP, (uint8_t*)USBD_CDC_D2H_Buff, i); USBD_CDC_InFlight = 1; } if (USBD_CDC_InFlight == 0) { DCD_EP_Flush(pdev, epnum); } return USBD_OK; }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { uint32_t USB_Tx_length; usbd_cdc_Change_Open_State(1); if (!USB_Tx_State) return USBD_OK; USB_Tx_length = ring_data_contig(USB_TX_BUFFER_SIZE, USB_Tx_Buffer_head, USB_Tx_Buffer_tail); if (USB_Tx_length) { USB_Tx_length = MIN(USB_Tx_length, CDC_DATA_IN_PACKET_SIZE); } else if (usbd_Last_Tx_Packet_size(pdev, epnum) != CDC_DATA_IN_PACKET_SIZE) { USB_Tx_State = 0; return USBD_OK; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&USB_Tx_Buffer[USB_Tx_Buffer_tail], USB_Tx_length); USB_Tx_Buffer_tail = ring_wrap(USB_TX_BUFFER_SIZE, USB_Tx_Buffer_tail + USB_Tx_length); return USBD_OK; }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { if (USB_Tx_State == 1) { unsigned char USB_TX_Buffer[CDC_DATA_IN_PACKET_SIZE]; int USB_Tx_length = 0; // try and fill the buffer int c; while (USB_Tx_length<CDC_DATA_IN_PACKET_SIZE && ((c = jshGetCharToTransmit(EV_USBSERIAL)) >= 0) ) { // get byte to transmit USB_TX_Buffer[USB_Tx_length++] = c; } // if nothing, set state to 0 if (USB_Tx_length==0) { USB_Tx_State = 0; return USBD_OK; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)USB_TX_Buffer, USB_Tx_length); } return USBD_OK; }
/** * @brief Handle_USBAsynchXfer * Send data to USB * @param pdev: instance * @retval None */ static void Handle_USBAsynchXfer (void *pdev) { if(USB_Tx_State != 1) { unsigned char USB_TX_Buffer[CDC_DATA_IN_PACKET_SIZE]; int USB_Tx_length = 0; // try and fill the buffer int c; while (USB_Tx_length<CDC_DATA_IN_PACKET_SIZE && ((c = jshGetCharToTransmit(EV_USBSERIAL)) >=0) ) { // get byte to transmit USB_TX_Buffer[USB_Tx_length++] = c; } // if nothing, set state to 0 if (USB_Tx_length==0) { USB_Tx_State = 0; return; } USB_Tx_State = 1; DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)USB_TX_Buffer, USB_Tx_length); } }
/** * @brief SCSI_ProcessRead * Handle Read Process * @param lun: Logical unit number * @retval status */ static int8_t SCSI_ProcessRead (uint8_t lun) { uint32_t len; len = MIN(SCSI_blk_len , MSC_MEDIA_PACKET); if( USBD_STORAGE_fops->Read(lun , MSC_BOT_Data, SCSI_blk_addr / SCSI_blk_size, len / SCSI_blk_size) < 0) { SCSI_SenseCode(lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR); return -1; } DCD_EP_Tx (cdev, MSC_IN_EP, MSC_BOT_Data, len); SCSI_blk_addr += len; SCSI_blk_len -= len; /* case 6 : Hi = Di */ MSC_BOT_csw.dDataResidue -= len; if (SCSI_blk_len == 0) { MSC_BOT_State = BOT_LAST_DATA_IN; } return 0; }
/** * @brief Handle_USBAsynchXfer * Send data to USB * @param pdev: instance * @retval None */ static void Handle_USBAsynchXfer (void *pdev) { if(USB_Tx_State != 1) { u8_t *data_p; u16_t len = ringbuf_available_linear(&usb_vcd_ringbuf_tx, &data_p); if (len == 0) { USB_Tx_State = 0; return; } #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED APP_Rx_length &= ~0x03; #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ if (len > CDC_DATA_IN_PACKET_SIZE) { len = CDC_DATA_IN_PACKET_SIZE; } USB_Tx_State = 1; DCD_EP_Tx (pdev, CDC_IN_EP, data_p, len); ringbuf_get(&usb_vcd_ringbuf_tx, 0, len); } }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { if (USB_Tx_State == 1) { u8_t *data_p; u16_t len = ringbuf_available_linear(&usb_vcd_ringbuf_tx, &data_p); if (len == 0) { USB_Tx_State = 0; } else { if (len > CDC_DATA_IN_PACKET_SIZE){ len = CDC_DATA_IN_PACKET_SIZE; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, data_p, len); ringbuf_get(&usb_vcd_ringbuf_tx, 0, len); } } return USBD_OK; }
/** * @brief Handle_USBAsynchXfer * Send data to USB * @param pdev: instance * @retval None */ static void Handle_USBAsynchXfer (void *pdev) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if(USB_Tx_State != 1) { if (APP_Rx_ptr_out == APP_RX_DATA_SIZE) { APP_Rx_ptr_out = 0; } if(APP_Rx_ptr_out == APP_Rx_ptr_in) { USB_Tx_State = 0; return; } if(APP_Rx_ptr_out > APP_Rx_ptr_in) /* rollback */ { APP_Rx_length = APP_RX_DATA_SIZE - APP_Rx_ptr_out; } else { APP_Rx_length = APP_Rx_ptr_in - APP_Rx_ptr_out; } #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED APP_Rx_length &= ~0x03; #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE) { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } USB_Tx_State = 1; DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } }
//-------------------------------------------------------------- USBD_Status USBD_CtlContinueSendData(USB_OTG_CORE_HANDLE * pdev, uint8_t * pbuf, uint16_t len) { USBD_Status ret = USBD_OK; DCD_EP_Tx(pdev, 0, pbuf, len); return ret; }
/** * @brief Handle_USBAsynchXfer * Send data to USB * @param pdev: instance * @retval None */ static void Handle_USBAsynchXfer (void *pdev) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if(USB_Tx_State != 1) { if (APP_Rx_ptr_out == APP_RX_DATA_SIZE) { APP_Rx_ptr_out = 0; } if(APP_Rx_ptr_out == APP_Rx_ptr_in) { USB_Tx_State = 0; return; } if(APP_Rx_ptr_out > APP_Rx_ptr_in) /* rollback */ { APP_Rx_length = APP_RX_DATA_SIZE - APP_Rx_ptr_out; } else { APP_Rx_length = APP_Rx_ptr_in - APP_Rx_ptr_out; } if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE) { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; if (USB_Tx_length == CDC_DATA_IN_PACKET_SIZE) last_packet = 1; //IBA if (APP_Rx_ptr_in == 64) APP_Rx_ptr_in=0; } USB_Tx_State = 1; DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } }
/********************************************************************************************************** *函 数 名: Usb_Send *功能说明: USB发送数据 *形 参: 发送数据缓冲区指针 数据长度 *返 回 值: 无 **********************************************************************************************************/ void Usb_Send(uint8_t *dataToSend, uint8_t length) { if(connectFlag) { DCD_EP_Tx(&USB_OTG_dev, 1, dataToSend, length); DCD_SetEPStatus(&USB_OTG_dev,1, USB_OTG_EP_TX_VALID); } errorCheckCnt = 0; }
//-------------------------------------------------------------- USBD_Status USBD_CtlSendStatus(USB_OTG_CORE_HANDLE * pdev) { USBD_Status ret = USBD_OK; pdev->dev.device_state = USB_OTG_EP0_STATUS_IN; DCD_EP_Tx(pdev, 0, NULL, 0); USB_OTG_EP0_OutStart(pdev); return ret; }
void usb_midi_refresh(void){ uint32_t buf[128]; uint8_t count=FIFO_COUNT(USB_midi_packets_in); if (count && USB_transferPossible){ for (uint8_t i=0; i<count; i++){ buf[i]=FIFO_FRONT(USB_midi_packets_in); FIFO_POP(USB_midi_packets_in); } DCD_EP_Tx(&USB_OTG_dev, MIDI_IN_EP, (uint8_t*)buf, count<<2); } }
static uint8_t usbd_video_SOF (void *pdev) { if (play_status == 1) { DCD_EP_Flush(pdev,USB_ENDPOINT_IN(1)); DCD_EP_Tx (pdev,USB_ENDPOINT_IN(1), (uint8_t*)0x0002, 2);//header play_status = 2; } return USBD_OK; }
uint8_t USBD_SendReport (USB_OTG_CORE_HANDLE *pdev, uint8_t *report, uint16_t len) { if (pdev->dev.device_status == USB_OTG_CONFIGURED ) { DCD_EP_Tx (pdev, HID_IN_EP, report, len); } return USBD_OK; }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_msc_DataIn (void *pdev, uint8_t epnum) { uint16_t USB_Tx_ptr = 0; uint16_t USB_Tx_length; if (epnum == CDC_IN_EP || epnum == CDC_OUT_EP) { if (USB_Tx_State == 1) { if (APP_Rx_length == 0) { if (((USB_OTG_CORE_HANDLE*)pdev)->dev.in_ep[epnum].xfer_len != CDC_DATA_IN_PACKET_SIZE) { USB_Tx_State = 0; return USBD_OK; } /* Transmit zero sized packet in case the last one has maximum allowed size. Otherwise * the recipient may expect more data coming soon and not return buffered data to app. * See section 5.8.3 Bulk Transfer Packet Size Constraints * of the USB Specification document. */ USB_Tx_length = 0; } else { if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } } else { MSC_BOT_DataIn(pdev , epnum); } return USBD_OK; }
/** * @brief MSC_BOT_SendData * Send the requested data * @param pdev: device instance * @param buf: pointer to data buffer * @param len: Data Length * @retval None */ static void MSC_BOT_SendData(USB_OTG_CORE_HANDLE *pdev, uint8_t* buf, uint16_t len) { len = MIN (MSC_BOT_cbw.dDataLength, len); MSC_BOT_csw.dDataResidue -= len; MSC_BOT_csw.bStatus = CSW_CMD_PASSED; MSC_BOT_State = BOT_SEND_DATA; DCD_EP_Tx (pdev, MSC_IN_EP, buf, len); }
void rndis_query_cmplt32(int status, uint32_t data) { rndis_query_cmplt_t *c; c = (rndis_query_cmplt_t *)encapsulated_buffer; c->MessageType = REMOTE_NDIS_QUERY_CMPLT; c->MessageLength = sizeof(rndis_query_cmplt_t) + 4; c->InformationBufferLength = 4; c->InformationBufferOffset = 16; c->Status = status; *(uint32_t *)(c + 1) = data; DCD_EP_Tx(&USB_OTG_dev, RNDIS_NOTIFICATION_IN_EP, (uint8_t *)"\x01\x00\x00\x00\x00\x00\x00\x00", 8); }
//-------------------------------------------------------------- USBD_Status USBD_CtlSendData(USB_OTG_CORE_HANDLE * pdev, uint8_t * pbuf, uint16_t len) { USBD_Status ret = USBD_OK; pdev->dev.in_ep[0].total_data_len = len; pdev->dev.in_ep[0].rem_data_len = len; pdev->dev.device_state = USB_OTG_EP0_DATA_IN; DCD_EP_Tx(pdev, 0, pbuf, len); return ret; }
void rndis_query_cmplt(int status, const void *data, int size) { rndis_query_cmplt_t *c; c = (rndis_query_cmplt_t *)encapsulated_buffer; c->MessageType = REMOTE_NDIS_QUERY_CMPLT; c->MessageLength = sizeof(rndis_query_cmplt_t) + size; c->InformationBufferLength = size; c->InformationBufferOffset = 16; c->Status = status; memcpy(c + 1, data, size); DCD_EP_Tx(&USB_OTG_dev, RNDIS_NOTIFICATION_IN_EP, (uint8_t *)"\x01\x00\x00\x00\x00\x00\x00\x00", 8); }
static uint8_t usbd_cf_SOF (void *pdev) { portBASE_TYPE xTaskWokenByReceive = pdFALSE; if (xQueueReceiveFromISR(usbDataTx, &outPacket, &xTaskWokenByReceive) == pdTRUE) { DCD_EP_Tx (pdev, IN_EP, (uint8_t*)outPacket.data, outPacket.size); } return USBD_OK; }
/** * @brief CCID_IntMessage * Send the Interrupt-IN data to the host * @param pdev: device instance * @retval None */ void CCID_IntMessage(USB_CORE_HANDLE *pdev) { /* Check if there us change in Smartcard Slot status */ if ( CCID_IsSlotStatusChange() && CCID_IsIntrTransferComplete() ) { /* Check Slot Status is changed. Card is Removed/ Fitted */ RDR_to_PC_NotifySlotChange(); CCID_SetIntrTransferStatus(0); /* Reset the Status */ CCID_UpdSlotChange(0); /* Reset the Status of Slot Change */ DCD_EP_Tx (pdev, CCID_INTR_IN_EP, UsbIntMessageBuffer, 2); } }
static void usbd_cdc_Schedule_In(void *pdev) { uint32_t USB_Tx_length; USB_Tx_length = ring_data_contig(USB_TX_BUFFER_SIZE, USB_Tx_Buffer_head, USB_Tx_Buffer_tail); if (USB_Tx_State) { if (USB_Serial_Open) { USB_Tx_failed_counter++; if (USB_Tx_failed_counter >= 500) { usbd_cdc_Change_Open_State(0); // Completely flush TX buffer DCD_EP_Flush(pdev, CDC_IN_EP); // Send ZLP DCD_EP_Tx(pdev, CDC_IN_EP, NULL, 0); if (USB_Tx_length) USB_Tx_Buffer_tail = ring_wrap(USB_TX_BUFFER_SIZE, USB_Tx_Buffer_tail + USB_Tx_length); USB_Tx_State = 0; } } return; } if (!USB_Tx_length) return; USB_Tx_State = 1; USB_Tx_failed_counter = 0; USB_Tx_length = MIN(USB_Tx_length, CDC_DATA_IN_PACKET_SIZE); DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&USB_Tx_Buffer[USB_Tx_Buffer_tail], USB_Tx_length); USB_Tx_Buffer_tail = ring_wrap(USB_TX_BUFFER_SIZE, USB_Tx_Buffer_tail + USB_Tx_length); }
void SCSI_ProcessReadComplete(uint32_t len) { DCD_EP_Tx (cdev, MSC_IN_EP, MSC_BOT_Data, len); SCSI_blk_addr += len; SCSI_blk_len -= len; /* case 6 : Hi = Di */ MSC_BOT_csw.dDataResidue -= len; if (SCSI_blk_len == 0) { MSC_BOT_State = BOT_LAST_DATA_IN; } }
/** * @brief MSC_BOT_SendCSW * Send the Command Status Wrapper * @param pdev: device instance * @param status : CSW status * @retval None */ void MSC_BOT_SendCSW (USB_OTG_CORE_HANDLE *pdev, uint8_t CSW_Status) { MSC_BOT_csw.dSignature = BOT_CSW_SIGNATURE; MSC_BOT_csw.bStatus = CSW_Status; MSC_BOT_State = BOT_IDLE; DCD_EP_Tx (pdev, MSC_IN_EP, (uint8_t *)&MSC_BOT_csw, BOT_CSW_LENGTH); /* Prapare EP to Receive next Cmd */ DCD_EP_PrepareRx (pdev, MSC_OUT_EP, (uint8_t *)&MSC_BOT_cbw, BOT_CBW_LENGTH); }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if (USB_Tx_State == 1) { if (APP_Rx_length == 0) { USB_Tx_State = 0; } else { if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; //ZS - data smaller than 64 bytes - don't increment pointers... APP_Rx_ptr_out = 0; APP_Rx_ptr_in = 0; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } } return USBD_OK; }
/** * @brief usbd_audio_DataIn * Data sent on non-control IN endpoint * @param pdev: device instance * @param epnum: endpoint number * @retval status */ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) { uint16_t USB_Tx_ptr; uint16_t USB_Tx_length; if (USB_Tx_State == 1) { if (APP_Rx_length == 0) { USB_Tx_State = 0; } else { if (APP_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE){ USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE; APP_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE; APP_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE; } else { USB_Tx_ptr = APP_Rx_ptr_out; USB_Tx_length = APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length; APP_Rx_length = 0; } /* Prepare the available data buffer to be sent on IN endpoint */ DCD_EP_Tx (pdev, CDC_IN_EP, (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); } } return USBD_OK; }