Exemplo n.º 1
0
void  MouseProcess(void)
{
  Msg msg = GetMessage();
  if(msg == MSG_SWITCH){
    CurrentProcess = KeyboardProcess;
    CurrentSystick = KeyboardSystick;
    KeyboardUIInit();
    for(u32 i=0;i<sizeof(JoyMouseBuffer);i++){
      JoyMouseBuffer[i] = 0;
    }
    JoyMouseBuffer[IDX_ID] = MOUSE_REPORT_ID;
    UserToPMABufferCopy(JoyMouseBuffer, GetEPTxAddr(ENDP2), 5);
    /* enable endpoint for transmission */
    SetEPTxCount(ENDP2, 5);
    SetEPTxValid(ENDP2);
  }else if(KEY_PAUSE == msg){
    bMode = !bMode;
    if(bMode){
      AirMouseUIInit();
    }else{
      MouseUIInit();
    }
  }else if(msg){
    JoyMouseBuffer[IDX_ID] = MOUSE_REPORT_ID;
    UserToPMABufferCopy(JoyMouseBuffer, GetEPTxAddr(ENDP2), 5);
    /* enable endpoint for transmission */
    SetEPTxCount(ENDP2, 5);
    SetEPTxValid(ENDP2);
    
    if(bMode){
      UpdateBall();
    }
  }
}
Exemplo n.º 2
0
static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
{
	uint16_t bytes_to_tx;

	if (!usb_hid_dev->tx_out_cb) {
		return;
	}

	bool need_yield = false;
#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
	bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
					       &usb_hid_dev->tx_packet_buffer[1],
					       sizeof(usb_hid_dev->tx_packet_buffer)-1,
					       NULL,
					       &need_yield);
#else
	bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
					       &usb_hid_dev->tx_packet_buffer[2],
					       sizeof(usb_hid_dev->tx_packet_buffer)-2,
					       NULL,
					       &need_yield);
#endif
	if (bytes_to_tx == 0) {
		return;
	}

	/* Always set type as report ID */
	usb_hid_dev->tx_packet_buffer[0] = 1;

#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
	UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer,
			GetEPTxAddr(usb_hid_dev->cfg->data_tx_ep),
			bytes_to_tx + 1);
#else
	usb_hid_dev->tx_packet_buffer[1] = bytes_to_tx;
	UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer,
			GetEPTxAddr(usb_hid_dev->cfg->data_tx_ep),
			bytes_to_tx + 2);
#endif
	/* Is this correct?  Why do we always send the whole buffer? */
	SetEPTxCount(usb_hid_dev->cfg->data_tx_ep, sizeof(usb_hid_dev->tx_packet_buffer));
	SetEPTxValid(usb_hid_dev->cfg->data_tx_ep);

#if defined(PIOS_INCLUDE_FREERTOS)
	if (need_yield) {
		vPortYieldFromISR();
	}
#endif	/* PIOS_INCLUDE_FREERTOS */
}
Exemplo n.º 3
0
/*******************************************************************************
* Function Name  : DataStageIn.
* Description    : Data stage of a Control Read Transfer.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DataStageIn(void) {
	ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
	uint32_t save_wLength = pEPinfo->Usb_wLength;
	uint32_t ControlState = pInformation->ControlState;
	uint8_t *DataBuffer;
	uint32_t Length;

	if ((save_wLength == 0) && (ControlState == LAST_IN_DATA)) {
		if(Data_Mul_MaxPacketSize == TRUE) {
			// No more data to send and empty packet
			Send0LengthData();
			ControlState = LAST_IN_DATA;
			Data_Mul_MaxPacketSize = FALSE;
		} else {
			// No more data to send so STALL the TX Status
			ControlState = WAIT_STATUS_OUT;
			vSetEPTxStatus(EP_TX_STALL);
		}
		goto Expect_Status_Out;  // FIXME: <--- ZOMG TEH 'GOTO' !!!!
	}
	Length = pEPinfo->PacketSize;
	ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
	if (Length > save_wLength) Length = save_wLength;
	DataBuffer = (*pEPinfo->CopyData)(Length);
	UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
	SetEPTxCount(ENDP0, Length);
	pEPinfo->Usb_wLength -= Length;
	pEPinfo->Usb_wOffset += Length;
	vSetEPTxStatus(EP_TX_VALID);
	USB_StatusOut();

	// Expect the host to abort the data IN stage
	Expect_Status_Out:    // FIXME: <--- ZOMG TEH LABEL !!!!
		pInformation->ControlState = ControlState;
}
Exemplo n.º 4
0
static void PIOS_USB_CDC_CTRL_EP_IN_Callback(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	/* Give back UART State Bitmap */
	/* UART State Bitmap
	 *   15-7: reserved
	 *      6:  bOverRun    overrun error
	 *      5:  bParity     parity error
	 *      4:  bFraming    framing error
	 *      3:  bRingSignal RI
	 *      2:  bBreak      break reception
	 *      1:  bTxCarrier  DSR
	 *      0:  bRxCarrier  DCD
	 */
	uart_state.bmUartState = htousbs(0x0003);

	UserToPMABufferCopy((uint8_t *) &uart_state,
			GetEPTxAddr(usb_cdc_dev->cfg->ctrl_tx_ep),
			sizeof(uart_state));
	SetEPTxCount(usb_cdc_dev->cfg->ctrl_tx_ep, PIOS_USB_BOARD_CDC_MGMT_LENGTH);
	SetEPTxValid(usb_cdc_dev->cfg->ctrl_tx_ep);
}
Exemplo n.º 5
0
/*******************************************************************************
* Function Name : Joystick_Send.
* Description   : prepares buffer to be sent containing Joystick event infos.
* Input         : Keys: keys received from terminal.
* Output        : None.
* Return value  : None.
*******************************************************************************/
void Joystick_Send(u8 Keys)
{
  u8 Mouse_Buffer[4] = {0, 0, 0, 0};
  s8 X = 0, Y = 0;

  switch (Keys)
  {
    case LEFT:
      X -= CURSOR_STEP;
      break;
    case RIGHT:

      X += CURSOR_STEP;
      break;
    case UP:
      Y -= CURSOR_STEP;
      break;
    case DOWN:
      Y += CURSOR_STEP;
      break;
    default:
      return;
  }

  /* prepare buffer to send */
  Mouse_Buffer[1] = X;
  Mouse_Buffer[2] = Y;
  /*copy mouse position info in ENDP1 Tx Packet Memory Area*/
  UserToPMABufferCopy(Mouse_Buffer, GetEPTxAddr(ENDP1), 4);
  /* enable endpoint for transmission */
  SetEPTxValid(ENDP1);
}
Exemplo n.º 6
0
/*******************************************************************************
* Function Name  : DataStageIn.
* Description    : Data stage of a Control Read Transfer.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DataStageIn(void) {
	ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
	uint32_t save_wLength = pEPinfo->Usb_wLength;
	uint32_t ControlState = pInformation->ControlState;

	uint8_t *DataBuffer;
	uint32_t Length;

	if ((save_wLength == 0) && (ControlState == LAST_IN_DATA)) {
		if (Data_Mul_MaxPacketSize == TRUE) {
			// No more data to send and empty packet
			SetEPTxCount(ENDP0,0);
			SaveTState = EP_TX_VALID;
			ControlState = LAST_IN_DATA;
			Data_Mul_MaxPacketSize = FALSE;
		} else {
			// No more data to send so STALL the TX Status
			ControlState = WAIT_STATUS_OUT;
			SaveTState = EP_TX_STALL;
		}
	} else {
		Length = pEPinfo->PacketSize;
		ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
		if (Length > save_wLength) Length = save_wLength;
		DataBuffer = (*pEPinfo->CopyData)(Length);
		UserToPMABufferCopy(DataBuffer,GetEPTxAddr(ENDP0),Length);
		SetEPTxCount(ENDP0,Length);
		pEPinfo->Usb_wLength -= Length;
		pEPinfo->Usb_wOffset += Length;
		SaveTState = EP_TX_VALID;
		SaveRState = EP_RX_VALID; // Expect the host to abort the data IN stage
	}

	pInformation->ControlState = ControlState;
}
Exemplo n.º 7
0
static void PIOS_USB_CDC_SendData(struct pios_usb_cdc_dev * usb_cdc_dev)
{
	uint16_t bytes_to_tx;

	if (!usb_cdc_dev->tx_out_cb) {
		return;
	}

	bool need_yield = false;
	bytes_to_tx = (usb_cdc_dev->tx_out_cb)(usb_cdc_dev->tx_out_context,
					       usb_cdc_dev->tx_packet_buffer,
					       sizeof(usb_cdc_dev->tx_packet_buffer),
					       NULL,
					       &need_yield);
	if (bytes_to_tx == 0) {
		return;
	}

	UserToPMABufferCopy(usb_cdc_dev->tx_packet_buffer,
			GetEPTxAddr(usb_cdc_dev->cfg->data_tx_ep),
			bytes_to_tx);
	SetEPTxCount(usb_cdc_dev->cfg->data_tx_ep, bytes_to_tx);
	SetEPTxValid(usb_cdc_dev->cfg->data_tx_ep);

#if defined(PIOS_INCLUDE_FREERTOS)
	portEND_SWITCHING_ISR(need_yield);
#endif	/* PIOS_INCLUDE_FREERTOS */
}
Exemplo n.º 8
0
vsf_err_t stm32_usbd_ep_set_IN_dbuffer(uint8_t idx)
{
	uint16_t epsize = stm32_usbd_ep_get_IN_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, GetEPTxAddr(idx), EP_Cfg_Ptr);
	SetEPDblBuffCount(idx, EP_DBUF_IN, 0);
	ClearDTOG_RX(idx);
	ClearDTOG_TX(idx);
	SetEPRxStatus(idx, EP_RX_DIS);
	SetEPTxStatus(idx, EP_TX_NAK);
	stm32_usbd_IN_dbuffer[idx] = true;
	return VSFERR_NONE;
}
Exemplo n.º 9
0
vsf_err_t stm32_usbd_ep_write_IN_buffer(uint8_t idx, uint8_t *buffer,
										uint16_t size)
{
	uint32_t PMA_ptr;
	int8_t index;
	
	index = stm32_usbd_ep(idx);
	if (index < 0)
	{
		return VSFERR_FAIL;
	}
	idx = (uint8_t)index;
	
	if (stm32_usbd_IN_dbuffer[idx])
	{
		if(GetENDPOINT(idx) & EP_DTOG_RX)
		{
			PMA_ptr = GetEPDblBuf1Addr(idx);
		}
		else
		{
			PMA_ptr = GetEPDblBuf0Addr(idx);
		}
	}
	else
	{
		PMA_ptr = GetEPTxAddr(idx);
	}
	UserToPMABufferCopy(buffer, PMA_ptr, size);
	return VSFERR_NONE;
}
Exemplo n.º 10
0
/*******************************************************************************
* Function Name  : USB_SIL_Write
* Description    : Write a buffer of data to a selected endpoint.
* Input          : - bEpAddr: The address of the non control endpoint.
*                  - pBufferPointer: The pointer to the buffer of data to be written
*                    to the endpoint.
*                  - wBufferSize: Number of data to be written (in bytes).
* Output         : None.
* Return         : Status.
*******************************************************************************/
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize) {
    /* Use the memory interface function to write to the selected endpoint */
    UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);

    /* Update the data length in the control register */
    SetEPTxCount((bEpAddr & 0x7F), wBufferSize);

    return 0;
}
Exemplo n.º 11
0
/*******************************************************************************
* Function Name  : DataStageIn.
* Description    : Data stage of a Control Read Transfer.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DataStageIn(void) {
    ENDPOINT_INFO* pEPinfo = &pInformation->Ctrl_Info;
    uint32_t save_wLength = pEPinfo->Usb_wLength;
    uint32_t ControlState = pInformation->ControlState;

    uint8_t* DataBuffer;
    uint32_t Length;

    if((save_wLength == 0) && (ControlState == LAST_IN_DATA)) {
        if(Data_Mul_MaxPacketSize == TRUE) {
            /* No more data to send and empty packet */
            Send0LengthData();
            ControlState = LAST_IN_DATA;
            Data_Mul_MaxPacketSize = FALSE;
        } else {
            /* No more data to send so STALL the TX Status*/
            ControlState = WAIT_STATUS_OUT;

#ifdef STM32F10X_CL
            PCD_EP_Read(ENDP0, 0, 0);
#endif /* STM32F10X_CL */

#ifndef STM32F10X_CL
            vSetEPTxStatus(EP_TX_STALL);
#endif /* STM32F10X_CL */
        }

        goto Expect_Status_Out;
    }

    Length = pEPinfo->PacketSize;
    ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;

    if(Length > save_wLength) {
        Length = save_wLength;
    }

    DataBuffer = (*pEPinfo->CopyData)(Length);

#ifdef STM32F10X_CL
    PCD_EP_Write(ENDP0, DataBuffer, Length);
#else
    UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
#endif /* STM32F10X_CL */

    SetEPTxCount(ENDP0, Length);

    pEPinfo->Usb_wLength -= Length;
    pEPinfo->Usb_wOffset += Length;
    vSetEPTxStatus(EP_TX_VALID);

    USB_StatusOut(); /* Expect the host to abort the data IN stage */

Expect_Status_Out:
    pInformation->ControlState = ControlState;
}
Exemplo n.º 12
0
/*******************************************************************************
* Function Name : Joystick_Send.
* Description   : prepares buffer to be sent containing Joystick event infos.
* Input         : Keys: keys received from terminal.
* Output        : None.
* Return value  : None.
*******************************************************************************/
void Joystick_Send(u8 buf0, u8 buf1)
{
  u8 Buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  
  Buffer[0] = buf0;
  /* prepare buffer to send */
  Buffer[3] = buf1;

  if(Buffer[0]==0)	//键盘
  {
	  /*copy mouse position info in ENDP1 Tx Packet Memory Area*/
	  UserToPMABufferCopy(Buffer, GetEPTxAddr(ENDP1), 8);
	  /* enable endpoint for transmission */
	  SetEPTxValid(ENDP1);
  }
  else				//鼠标
  {
	  UserToPMABufferCopy(Buffer, GetEPTxAddr(ENDP2), 5);
	  SetEPTxValid(ENDP2);
  }
														 
}																 
Exemplo n.º 13
0
/*******************************************************************************
* Function Name  : DataStageIn.
* Description    : Data stage of a Control Read Transfer.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DataStageIn(void)
{
	ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
	u32 save_wLength = pEPinfo->Usb_wLength;
	u32 ControlState = pInformation->ControlState;

	u8 *DataBuffer;
	u32 Length;

	if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
	{
		if (Data_Mul_MaxPacketSize == true)
		{
			/* No more data to send and empty packet */
			Send0LengthData();
			ControlState = LAST_IN_DATA;
			Data_Mul_MaxPacketSize = false;
		}
		else
		{
			/* No more data to send so STALL the TX Status*/
			ControlState = WAIT_STATUS_OUT;
			vSetEPTxStatus(EP_TX_STALL);
		}

		goto Expect_Status_Out;
	}

	Length = pEPinfo->PacketSize;
	ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;

	if (Length > save_wLength)
	{
		Length = save_wLength;
	}

	DataBuffer = (*pEPinfo->CopyData)(Length);

	UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);

	SetEPTxCount(ENDP0, Length);

	pEPinfo->Usb_wLength -= Length;
	pEPinfo->Usb_wOffset += Length;
	vSetEPTxStatus(EP_TX_VALID);

	USB_StatusOut();/* Expect the host to abort the data IN stage */

Expect_Status_Out:
	pInformation->ControlState = ControlState;
}
Exemplo n.º 14
0
PUBLIC uint32 HW_USB_Write(uint8 bEpAddr, uint8* pBufferPointer, uint32 wBufferSize, bool SetValid)
{

    /* Use the memory interface function to write to the selected endpoint */
    HwUsbUserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);

    /* Update the data length in the control register */
    SetEPTxCount((bEpAddr & 0x7F), wBufferSize);

    if(SetValid)
    SetEPTxValid(bEpAddr&0x0F);

    return wBufferSize;
}
Exemplo n.º 15
0
void  JoystickProcess(void)
{
  Msg msg = GetMessage();
  if(msg == MSG_SWITCH){
    CurrentProcess = MouseProcess;
    CurrentSystick = MouseSystick;
    MouseUIInit();
    for(u32 i=0;i<sizeof(JoyMouseBuffer);i++){
      JoyMouseBuffer[i] = 0;
    }
    JoyMouseBuffer[IDX_ID] = JOYSTICK_REPORT_ID;
    UserToPMABufferCopy(JoyMouseBuffer, GetEPTxAddr(ENDP2), 8);
    /* enable endpoint for transmission */
    SetEPTxCount(ENDP2, 8);
    SetEPTxValid(ENDP2);
  }else if(msg){
    JoyMouseBuffer[IDX_ID] = JOYSTICK_REPORT_ID;
    UserToPMABufferCopy(JoyMouseBuffer, GetEPTxAddr(ENDP2), 8);
    /* enable endpoint for transmission */
    SetEPTxCount(ENDP2, 8);
    SetEPTxValid(ENDP2);
  }
}
/*******************************************************************************
* Function Name  : USB_SIL_Write
* Description    : Write a buffer of data to a selected endpoint.
* Input          : - bEpAddr: The address of the non control endpoint.
*                  - pBufferPointer: The pointer to the buffer of data to be written
*                    to the endpoint.
*                  - wBufferSize: Number of data to be written (in bytes).
* Output         : None.
* Return         : Status.
*******************************************************************************/
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
{
#ifndef STM32F10X_CL

  /* Use the memory interface function to write to the selected endpoint */
  UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);

  /* Update the data length in the control register */
  SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
  
#else
  
   /* Use the PCD interface layer function to write to the selected endpoint */
   PCD_EP_Write (bEpAddr, pBufferPointer, wBufferSize); 
   
#endif /* STM32F10X_CL */

  return 0;
}
Exemplo n.º 17
0
int usb_test_connect(void)
{
	volatile int i = 0;
	unsigned char pData[2] = {0};

	count_in = 1;
	UserToPMABufferCopy(pData, GetEPTxAddr(ENDP1), count_in);
	/* enable endpoint for transmission */
	SetEPTxValid(ENDP1);
	while (count_in != 0 && i < 100000)
	{
		i++;
	}
	if (count_in == 0)
	{
		return 0;
	}
	return -1;
}
Exemplo n.º 18
0
static void PIOS_USB_RCTX_SendReport(struct pios_usb_rctx_dev *usb_rctx_dev)
{
#ifdef PIOS_INCLUDE_FREERTOS
    bool need_yield = false;
#endif /* PIOS_INCLUDE_FREERTOS */

    usb_rctx_dev->report.id = 3; /* FIXME: shouldn't hard-code this report ID */

    UserToPMABufferCopy((uint8_t *)&usb_rctx_dev->report,
                        GetEPTxAddr(usb_rctx_dev->cfg->data_tx_ep),
                        sizeof(usb_rctx_dev->report));

    SetEPTxCount(usb_rctx_dev->cfg->data_tx_ep, sizeof(usb_rctx_dev->report));
    SetEPTxValid(usb_rctx_dev->cfg->data_tx_ep);

#ifdef PIOS_INCLUDE_FREERTOS
    if (need_yield) {
        vPortYield();
    }
#endif /* PIOS_INCLUDE_FREERTOS */
}
Exemplo n.º 19
0
void SendData_To_PC(unsigned char *pData, int length)
{
	volatile int i = 0;

	count_in = length;
	UserToPMABufferCopy(pData, GetEPTxAddr(ENDP1), count_in);
	/* enable endpoint for transmission */
	SetEPTxValid(ENDP1);
	while (count_in != 0 && i < 100000)
	{
			i++;
	}
	//int batch = length/VIRTUAL_COM_PORT_DATA_SIZE;
	//int res	  = length%VIRTUAL_COM_PORT_DATA_SIZE;
	//int i;

	//for (i = 0; i < batch; i++)
	//{
	//	count_in	= VIRTUAL_COM_PORT_DATA_SIZE;
	//	UserToPMABufferCopy(pData+i*VIRTUAL_COM_PORT_DATA_SIZE, ENDP1_TXADDR, count_in);
	//	SetEPTxCount(ENDP1, count_in);
	//	SetEPTxValid(ENDP1);
	//	while (count_in != 0)
	//	{
	//		;
	//	}
	//}
	//if (res > 0)
	//{
	//	//×îºóÒ»°ü
	//	count_in	= res;
	//	UserToPMABufferCopy(pData+batch*VIRTUAL_COM_PORT_DATA_SIZE, ENDP1_TXADDR, count_in);
	//	SetEPTxCount(ENDP1, count_in);
	//	SetEPTxValid(ENDP1);
	//	while (count_in != 0)
	//	{
	//		;
	//	}
	//}
}
Exemplo n.º 20
0
void UsbSendBufferProcess(u8 ucEndpointNumber)
{
	u16 wSendLength;
	u16 * wpPMABufferPointer;
	u16 wTemp1, wTemp2;
	u32 i, n;

	wpPMABufferPointer = (u16 *)(GetEPTxAddr(ucEndpointNumber) * 2 + PMAAddr);
	
	wTemp1 = (u16)(cIdleData[1]);						//fill 2 byte of FT232HL status to every IN data at the very first location
	wTemp2 = (wTemp1<<8) | ((u16)(cIdleData[0])) ;
	* wpPMABufferPointer = wTemp2;
	wpPMABufferPointer ++;
	wpPMABufferPointer ++;
	wSendLength = 2;

	/* calc the wSendLength */
	if(cFlagUsbIdle == 0)
	{
		if(wSendLoopBufferEnd > wSendLoopBufferStart)
		{
			wSendLength = wSendLoopBufferEnd - wSendLoopBufferStart;
			if(wSendLength > (MAX_USB_DATA_PACKET_SIZE - 2))
			{
				wSendLength = MAX_USB_DATA_PACKET_SIZE - 2;
				cFlagUsbEp1Send = 1;						//if need multi-packet to send, set send data flag true for the next transaction
			}
			else
			{
				cFlagUsbEp1Send = 0;	
			}
		}
		else if(wSendLoopBufferEnd < wSendLoopBufferStart)
		{
			wSendLength = wSendLoopBufferEnd - wSendLoopBufferStart + USB_LOOP_BUFFER_SIZE;
			if(wSendLength > (MAX_USB_DATA_PACKET_SIZE - 2))
			{
				wSendLength = MAX_USB_DATA_PACKET_SIZE - 2;
				cFlagUsbEp1Send = 1;						//if need multi-packet to send, set send data flag true for the next transaction
			}
			else
			{
				cFlagUsbEp1Send = 0;	
			}
		}
		else
		{
			wSendLength = 0;
			cFlagUsbEp1Send = 0;	
		}

		n = (wSendLength + 1) >> 1;			//usb ip is 16bit databus width, read/write should be word access each time
		i = n;
		while(i!=0)
		{
			wTemp1 = (u16)(* (cUsbSendLoopBuffer + wSendLoopBufferStart));
			wSendLoopBufferStart ++;
			if(wSendLoopBufferStart == USB_LOOP_BUFFER_SIZE)
			{
				wSendLoopBufferStart = 0;
			}
			wTemp2 = wTemp1 | (((u16)(* (cUsbSendLoopBuffer + wSendLoopBufferStart))) << 8);
			* wpPMABufferPointer = wTemp2;
			wpPMABufferPointer ++;
			wpPMABufferPointer ++;
			if((i == 1) && (wSendLength != n*2))
			{
				i--;
				continue;
				
			}
			else
			{
				wSendLoopBufferStart ++;
				if(wSendLoopBufferStart == USB_LOOP_BUFFER_SIZE)
				{
					wSendLoopBufferStart = 0;
				}
			}
			i--;
		}
		dwUsbSendSize += wSendLength;
		wSendLength += 2;
	}
	
	cFlagUsbIdle = 0;
	dwSofCount = 0;
	
	SetUsbSend(ENDP1, wSendLength);
	
}
Exemplo n.º 21
0
void SendData_To_PC(unsigned char *pData, int length)
{
	volatile int i = 0;
	int batch = length/VIRTUAL_COM_PORT_DATA_SIZE;
	int res	  = length%VIRTUAL_COM_PORT_DATA_SIZE;
	unsigned int	delay_cnt;

	if (g_usb_type == USB_KEYBOARD)	//按键
	{
		count_in = length;
		UserToPMABufferCopy(pData, GetEPTxAddr(ENDP1), count_in);
		SetEPTxCount(ENDP1, count_in);
		/* enable endpoint for transmission */
		SetEPTxValid(ENDP1);
		//StartDelay(600);	//3S的延时
		delay_cnt = 300;
		while (count_in != 0 && delay_cnt != 0 &&(bDeviceState == CONFIGURED))
		{
			delay_cnt--;
			Delay(20000);
		}
	}
	else if(g_usb_type == USB_VIRTUAL_PORT)
	{
		for (i = 0; i < batch; i++)
		{
			count_in	= VIRTUAL_COM_PORT_DATA_SIZE;
			UserToPMABufferCopy(pData+i*VIRTUAL_COM_PORT_DATA_SIZE, ENDP1_TXADDR, count_in);
			SetEPTxCount(ENDP1, count_in);
			SetEPTxValid(ENDP1);
			//StartDelay(600);
			delay_cnt = 300;
			while (count_in != 0 && delay_cnt != 0 && (bDeviceState == CONFIGURED))
			{
				delay_cnt--;
				Delay(20000);
			}
		}
		if (res > 0)
		{
			//最后一包
			count_in	= res;
			UserToPMABufferCopy(pData+batch*VIRTUAL_COM_PORT_DATA_SIZE, ENDP1_TXADDR, count_in);
			SetEPTxCount(ENDP1, count_in);
			SetEPTxValid(ENDP1);
			//StartDelay(600);
			delay_cnt = 300;
			while (count_in != 0 && delay_cnt != 0 &&(bDeviceState == CONFIGURED))
			{
				delay_cnt--;
				Delay(20000);
			}
		}
	}//Virtual port
	else
	{
		if (length > G_SEND_BUF_LENGTH)
		{
			length = G_SEND_BUF_LENGTH;
		}
		memcpy(g_send_buff,pData,length);
	}//USB_Masstorage
	
}
Exemplo n.º 22
0
void usb_SendData(unsigned char *pData, int length)
{
	volatile int i = 0;
        unsigned int	delay_cnt;
        
#if (USB_DEVICE_CONFIG & _USE_USB_VIRTUAL_COMM_DEVICE)        
	int batch = length/VIRTUAL_COM_PORT_DATA_SIZE;
	int res	  = length%VIRTUAL_COM_PORT_DATA_SIZE;
#endif 
	

#if(USB_DEVICE_CONFIG & _USE_USB_KEYBOARD_DEVICE)
	if (g_usb_type == USB_KEYBOARD)	//按键
	{
		count_in = length;
		UserToPMABufferCopy(pData, GetEPTxAddr(ENDP1), count_in);
		SetEPTxCount(ENDP1, count_in);
		/* enable endpoint for transmission */
		SetEPTxValid(ENDP1);
		//StartDelay(600);	//3S的延时
		delay_cnt = 300;
		while (count_in != 0 && delay_cnt != 0 &&(bDeviceState == CONFIGURED))
		{
			delay_cnt--;
			delay_ms(10);
		}
	}
	else 
#elif (USB_DEVICE_CONFIG & _USE_USB_VIRTUAL_COMM_DEVICE)
	if(g_usb_type == USB_VIRTUAL_PORT)
	{
		for (i = 0; i < batch; i++)
		{
			count_in	= VIRTUAL_COM_PORT_DATA_SIZE;
			UserToPMABufferCopy(pData+i*VIRTUAL_COM_PORT_DATA_SIZE, ENDP1_TXADDR, count_in);
			SetEPTxCount(ENDP1, count_in);
			SetEPTxValid(ENDP1);
			//StartDelay(600);
			delay_cnt = 300;
			while (count_in != 0 && delay_cnt != 0 && (bDeviceState == CONFIGURED))
			{
				delay_cnt--;
				delay_ms(10);
			}
		}
		if (res > 0)
		{
			//最后一包
			count_in	= res;
			UserToPMABufferCopy(pData+batch*VIRTUAL_COM_PORT_DATA_SIZE, ENDP1_TXADDR, count_in);
			SetEPTxCount(ENDP1, count_in);
			SetEPTxValid(ENDP1);
			//StartDelay(600);
			delay_cnt = 300;
			while (count_in != 0 && delay_cnt != 0 &&(bDeviceState == CONFIGURED))
			{
				delay_cnt--;
				delay_ms(10);
			}
		}
	}//Virtual port
	else 
#elif (USB_DEVICE_CONFIG & _USE_USB_MASS_STOARGE_DEVICE)
#ifdef DUMMY_FAT_FS
	if((g_usb_type == USB_MASSSTORAGE)&&(g_mass_storage_device_type == MASSTORAGE_DEVICE_TYPE_DUMMY_FAT))
	{
		if (length > G_SEND_BUF_LENGTH)
		{
			length = G_SEND_BUF_LENGTH;
		}
		MEMCPY(g_send_buff,pData,length);
	}//USB_Masstorage
#endif
#endif
        ;
}