コード例 #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();
    }
  }
}
コード例 #2
0
ファイル: usb_endp.c プロジェクト: JogoJogo/Espruino
/*******************************************************************************
* Function Name  : EP1_IN_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_IN_Callback (void)
{
  if (USB_Tx_State == 1)
  {
    unsigned char USB_TX_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];
    int USB_Tx_length = 0;

    // try and fill the buffer
    int c;
    while (USB_Tx_length<VIRTUAL_COM_PORT_DATA_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;
      }
        
    // else send data and keep going      
      UserToPMABufferCopy(&USB_TX_Buffer[0], ENDP1_TXADDR, USB_Tx_length);
      SetEPTxCount(ENDP1, USB_Tx_length);
      SetEPTxValid(ENDP1); 
    }
  }
コード例 #3
0
/*******************************************************************************
* Function Name  : EP1_IN_Callback.
* Description    : EP1 IN Callback Routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_IN_Callback (void)
{
  uint16_t USB_Tx_ptr;
  uint16_t USB_Tx_length;

  if (USB_Tx_State == 1)
  {
    if (USART_Rx_length == 0)
    {
      USB_Tx_State = 0;
    }
    else
    {
      if (USART_Rx_length > CDC_DATA_SIZE){
        USB_Tx_ptr = USART_Rx_ptr_out;
        USB_Tx_length = CDC_DATA_SIZE;

        USART_Rx_ptr_out += CDC_DATA_SIZE;
        USART_Rx_length -= CDC_DATA_SIZE;
      }
      else
      {
        USB_Tx_ptr = USART_Rx_ptr_out;
        USB_Tx_length = USART_Rx_length;

        USART_Rx_ptr_out += USART_Rx_length;
        USART_Rx_length = 0;
      }
      UserToPMABufferCopy(&USART_Rx_Buffer[USB_Tx_ptr], ENDP1_TXADDR, USB_Tx_length);
      SetEPTxCount(ENDP1, USB_Tx_length);
      SetEPTxValid(ENDP1);
    }
  }
}
コード例 #4
0
ファイル: usb_endp.c プロジェクト: iruka-/ARM_BOOTLOADER
int	usbSendBytes(uchar *data,int size)
{
	if(size==0) wait_us(140);			// 0byte packet対策.

  /* Last transmission hasn't finished, abort */
  	if (countTx) {
    	return 0;
  	}
	if(	GetEPTxStatus(ENDP1) == EP_TX_VALID) return 0;

	if(	size >= MAX_SEND_BYTES_CDC) {
		size  = MAX_SEND_BYTES_CDC;
	}

	UserToPMABufferCopy(data, ENDP1_TXADDR, size);
	SetEPTxCount(ENDP1, size);

    countTx += size;
	if(size==0) countTx++;				// 0byte packet対策.

	SetEPTxValid(ENDP1);

	if(size==0) wait_us(140);			// 0byte packet対策.

	return size;
}
コード例 #5
0
ファイル: usb_endp.c プロジェクト: theoanu/openDrivePlatform
// write to USB
void EP1_IN_Callback (void)
{
	//uint16_t USB_Tx_ptr;
	uint16_t USB_TX_Length;
  
	if (USB_Tx_State == 1)
	{
		if(BUFFER_IS_EMPTY(USB_TX))
		{
			USB_Tx_State = 0;
		}
		else
		{
			USB_TX_Length = BUFFER_CONTIGUOUS_DATA_LENGTH(USB_TX);
			if (USB_TX_Length > VIRTUAL_COM_PORT_DATA_SIZE)
				USB_TX_Length = VIRTUAL_COM_PORT_DATA_SIZE;
      
#ifdef USE_STM3210C_EVAL
			USB_SIL_Write(EP1_IN, &USART_Rx_Buffer[USB_Tx_ptr], USB_TX_Length);
#else
			UserToPMABufferCopy(USB_TX_Head, ENDP1_TXADDR, USB_TX_Length);
			BUFFER_MOVE_HEAD(USB_TX, USB_TX_Length);
			SetEPTxCount(ENDP1, USB_TX_Length);
			SetEPTxValid(ENDP1);
#endif  
		}
	}
}
コード例 #6
0
ファイル: usb.c プロジェクト: Paulxia/navictrl
void USB_Transmit(void)
{   // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal
	// if something has to be send and the txd fifo is not full

	if(USB_tx_buffer.Locked == TRUE)
	{
		if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
		{
			u16 i;
			if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes)
			{
				i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send
				if(i > 64) i = 64; // limit packet size to 64 bytes
				UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i);
				SetEPTxCount(ENDP1,i);
				SetEPTxValid(ENDP1);
	    		USB_tx_buffer.Position += i;
			}
		}
		if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered
		{
			Buffer_Clear(&USB_tx_buffer); // clear buffer
		}
	}
}
コード例 #7
0
ファイル: hw_config.c プロジェクト: liuwwei3/sizhou
/*******************************************************************************
* 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);
}
コード例 #8
0
void sample_packet_send(void)
{
    USB_SIL_Write(EP1_IN, packet_buf, SAMPLE_PACKET_SIZE);

    // Mark that the endpoint has valid data
    SetEPTxValid(ENDP1);
}
コード例 #9
0
ファイル: cdc_serial.c プロジェクト: dtyangcm/rtt-stm32f103c8
/*******************************************************************************
* Function Name  : Handle_USBAsynchXfer.
* Description    : send data to USB.
* Input          : None.
* Return         : none.
*******************************************************************************/
void Handle_USBAsynchXfer (void)
{
  rt_uint32_t level;
  rt_uint32_t remain;
  
  if(USB_Tx_State != 1)
  {
  	level = rt_hw_interrupt_disable();
	  remain = RT_RINGBUFFER_SIZE(&tx_ringbuffer);
    
    if(remain == 0) 
    {
      USB_Tx_State = 0;
	  rt_hw_interrupt_enable(level);
      return;
    }
    
    if (remain > VIRTUAL_COM_PORT_DATA_SIZE)
    {
      remain = VIRTUAL_COM_PORT_DATA_SIZE;	
    }
	rt_ringbuffer_get(&tx_ringbuffer, tx_buf, remain);
	rt_hw_interrupt_enable(level);

    USB_Tx_State = 1; 
    UserToPMABufferCopy(tx_buf, ENDP1_TXADDR, remain);
    SetEPTxCount(ENDP1, remain);
    SetEPTxValid(ENDP1); 
  }  
}
コード例 #10
0
ファイル: pios_usb_cdc.c プロジェクト: 1heinz/TauLabs
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 */
}
コード例 #11
0
ファイル: pios_usb_cdc.c プロジェクト: 1heinz/TauLabs
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);
}
コード例 #12
0
ファイル: usb_endp.c プロジェクト: JogoJogo/Espruino
/*******************************************************************************
* Function Name  : Handle_USBAsynchXfer.
* Description    : send data to USB.
* Input          : None.
* Return         : none.
*******************************************************************************/
void Handle_USBAsynchXfer (void)
{  
  if(USB_Tx_State != 1)
  {
    unsigned char USB_TX_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];
    int USB_Tx_length = 0;

    // try and fill the buffer
    int c;
    while (USB_Tx_length<VIRTUAL_COM_PORT_DATA_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; 
    
#ifdef USE_STM3210C_EVAL
    USB_SIL_Write(EP1_IN, &USB_TX_Buffer[0], USB_Tx_length);  
#else
    UserToPMABufferCopy(&USB_TX_Buffer[0], ENDP1_TXADDR, USB_Tx_length);
    SetEPTxCount(ENDP1, USB_Tx_length);
    SetEPTxValid(ENDP1); 
#endif /* USE_STM3210C_EVAL */
  }  
  
}
コード例 #13
0
ファイル: mios32_usb_com.c プロジェクト: gillspice/mios32
/////////////////////////////////////////////////////////////////////////////
//! puts more than one byte onto the transmit buffer (used for atomic sends)
//! \param[in] usb_com USB_COM number (not supported yet, should always be 0)
//! \param[in] *buffer pointer to buffer which should be transmitted
//! \param[in] len number of bytes which should be transmitted
//! \return 0 if no error
//! \return -1 if USB_COM not available
//! \return -2 if buffer full or cannot get all requested bytes (retry)
//! \return -3 if USB_COM not supported by MIOS32_USB_COM_TxBufferPut Routine
//! \return -4 if too many bytes should be sent
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_COM layer functions
/////////////////////////////////////////////////////////////////////////////
s32 MIOS32_USB_COM_TxBufferPutMore_NonBlocking(u8 usb_com, u8 *buffer, u16 len)
{
#if MIOS32_USB_COM_NUM == 0
  return -1; // no USB_COM available
#else
  if( usb_com >= MIOS32_USB_COM_NUM )
    return -1; // USB_COM not available

  if( len > MIOS32_USB_COM_DATA_IN_SIZE )
    return -4; // cannot get all requested bytes

  if( tx_buffer_busy )
    return -2; // buffer full (retry)

  // copy bytes to be transmitted into transmit buffer
  UserToPMABufferCopy(buffer, MIOS32_USB_ENDP4_TXADDR, len);

  // send buffer
  tx_buffer_busy = 1;
  SetEPTxCount(ENDP4, len);
  SetEPTxValid(ENDP4);

  return 0; // no error
#endif
}
コード例 #14
0
ファイル: usb.c プロジェクト: Paulxia/navictrl
//-----------------------------------------------------------------
void USB_PutChar(u8 c)
{
	u16 timeout = 0;
	while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
	UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
	SetEPTxCount(ENDP1,2);
	SetEPTxValid(ENDP1);
}
コード例 #15
0
/*******************************************************************************
* Function Name  : UART_To_USB_Send_Data. 
* Description    : send the received data from UART 0 to USB. 
* Input          : None.
* Return         : none.
*******************************************************************************/
void UART_To_USB_Send_Data(void)
{
  buffer_in[count_in] = UART_ReceiveData(UART0);
  count_in++;
  UserToPMABufferCopy(buffer_in,ENDP1_TXADDR, count_in);
  SetEPTxCount(ENDP1,count_in);
  SetEPTxValid(ENDP1);
}
コード例 #16
0
ファイル: usb_endp.c プロジェクト: Paolo-Maffei/lxyppc-tetrix
void usb_send_data(const void* buffer, uint32_t len)
{
    memcpy(send_buffer,buffer, len < EP1_PACKET_SIZE ? len : EP1_PACKET_SIZE);
    USB_SIL_Write(EP1_IN, (uint8_t*) send_buffer, EP1_PACKET_SIZE);
    #ifndef STM32F10X_CL
        SetEPTxValid(ENDP1);
    #endif /* STM32F10X_CL */  
    PrevXferComplete = 0;
}
コード例 #17
0
ファイル: main.c プロジェクト: MadLittleMods/STM32F3-Mouse
/**
 * @brief  Main program.
 * @param  None
 * @retval None
 */
int main(void) {
	uint8_t i = 0;
	/* SysTick end of count event each 10ms */
	RCC_GetClocksFreq(&RCC_Clocks);
	SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

	/* Configure the USB */
	USB_Config();

	/* Accelerometer Configuration */
	Acc_Config();

	/* Init push buttons */
	STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);

	/* Init LEDs */
	STM_EVAL_LEDInit(LED3);

	/* Infinite loop */
	while (1) {

		/* Wait for data ready */
		while (DataReady != 0x04) {
		}
		DataReady = 0x00;

		/* Get Data Accelerometer */
		Acc_ReadData(AccBuffer);

		for (i = 0; i < 3; i++)
			AccBuffer[i] /= 100.0f;

		// Get mouse info
		Mouse_Buffer = USBD_HID_GetPos();
		/* Update the cursor position */
		if (!mouseZeroPacketOutputted || (Mouse_Buffer[0] != 0 || Mouse_Buffer[1] != 0 || Mouse_Buffer[2] != 0 || Mouse_Buffer[3] != 0))
		{
			/* Reset the control token to inform upper layer that a transfer is ongoing */
			PrevXferComplete = 0;

			/* Copy mouse position info in ENDP1 Tx Packet Memory Area*/
			USB_SIL_Write(EP1_IN, Mouse_Buffer, 4);

			/* Enable endpoint for transmission */
			SetEPTxValid(ENDP1 );
		}

		// We find that the mouse buffer is zero so we know that we have outputted the zero packet
		// This means we can stop transferring data
		if((Mouse_Buffer[0] == 0 && Mouse_Buffer[1] == 0 && Mouse_Buffer[2] == 0 && Mouse_Buffer[3] == 0))
			mouseZeroPacketOutputted = 1;
		else
			mouseZeroPacketOutputted = 0;

	}
}
コード例 #18
0
ファイル: serial.c プロジェクト: MuiLe/copter
/*******************************************************************************
* Function Name  : Handle_USBAsynchXfer.
* Description    : send data to USB.
* Input          : None.
* Return         : none.
*******************************************************************************/
void Handle_USBAsynchXfer (void)
{

  uint16_t USB_Tx_ptr;
  uint16_t USB_Tx_length;

  if(USB_Tx_State != 1)
  {
    if (USART_Rx_ptr_out == USART_RX_DATA_SIZE)
    {
      USART_Rx_ptr_out = 0;
    }

    if(USART_Rx_ptr_out == USART_Rx_ptr_in)
    {
      USB_Tx_State = 0;
      return;
    }

    if(USART_Rx_ptr_out > USART_Rx_ptr_in) /* rollback */
    {
      USART_Rx_length = USART_RX_DATA_SIZE - USART_Rx_ptr_out;
    }
    else
    {
      USART_Rx_length = USART_Rx_ptr_in - USART_Rx_ptr_out;
    }

    if (USART_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE)
    {
      USB_Tx_ptr = USART_Rx_ptr_out;
      USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE;

      USART_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE;
      USART_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE;
    }
    else
    {
      USB_Tx_ptr = USART_Rx_ptr_out;
      USB_Tx_length = USART_Rx_length;

      USART_Rx_ptr_out += USART_Rx_length;
      USART_Rx_length = 0;
    }
    USB_Tx_State = 1;

#ifdef USE_STM3210C_EVAL
    USB_SIL_Write(EP1_IN, &USART_Rx_Buffer[USB_Tx_ptr], USB_Tx_length);
#else
    UserToPMABufferCopy(&USART_Rx_Buffer[USB_Tx_ptr], ENDP1_TXADDR, USB_Tx_length);
    SetEPTxCount(ENDP1, USB_Tx_length);
    SetEPTxValid(ENDP1);
#endif /* USE_STM3210C_EVAL */
  }

}
コード例 #19
0
ファイル: usb.c プロジェクト: Paulxia/navictrl
//-----------------------------------------------------------------
void USB_PutString(u8 *string)
{
	u8 i = 0;
	u16 timeout = 0;

	while (string[i++] != 0){} // get string len
	while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
	UserToPMABufferCopy(string, ENDP1_TXADDR, ++i);	// copy string to usb buffer
	SetEPTxCount(ENDP1,i);
	SetEPTxValid(ENDP1);
}
コード例 #20
0
ファイル: usb_endp.c プロジェクト: iruka-/ARM_BOOTLOADER
void Handle_USBAsynchXfer (void)
{
	if(	GetEPTxStatus(ENDP1) == EP_TX_VALID) return;

	int Recv_Size = USART_RecvData(Recv_Buffer);
	if(	Recv_Size ) {
		UserToPMABufferCopy(Recv_Buffer, ENDP1_TXADDR, Recv_Size);
		SetEPTxCount(ENDP1, Recv_Size);
		SetEPTxValid(ENDP1);
	}
}
コード例 #21
0
ファイル: hw_config.c プロジェクト: harifun/test
/*******************************************************************************
* 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);
  }
														 
}																 
コード例 #22
0
ファイル: usb_endp.c プロジェクト: FlameN/STM32RUNO
void EP1_IN_Callback(void)
{
	if (USB_Tx_Cnt > 0)
	{
		if (USB_Tx_Cnt > VIRTUAL_COM_PORT_DATA_SIZE)
		{
			UserToPMABufferCopy(USB_Tx_Buffer, ENDP1_TXADDR,
					VIRTUAL_COM_PORT_DATA_SIZE);
			SetEPTxCount(ENDP1, VIRTUAL_COM_PORT_DATA_SIZE);
			SetEPTxValid(ENDP1);
			USB_Tx_Cnt -= VIRTUAL_COM_PORT_DATA_SIZE;
			USB_Tx_Buffer += VIRTUAL_COM_PORT_DATA_SIZE;
		}
		else
		{
			UserToPMABufferCopy(USB_Tx_Buffer, ENDP1_TXADDR, USB_Tx_Cnt);
			SetEPTxCount(ENDP1, USB_Tx_Cnt);
			SetEPTxValid(ENDP1);
			USB_Tx_Cnt = 0;
		}
	}
}
コード例 #23
0
ファイル: cdc_serial.c プロジェクト: dtyangcm/rtt-stm32f103c8
/*******************************************************************************
* Function Name  : EP1_IN_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_IN_Callback (void)
{
  rt_uint32_t level;
  rt_uint32_t remain;

  if (USB_Tx_State == 1)
  {
	  level = rt_hw_interrupt_disable();
	  remain = RT_RINGBUFFER_SIZE(&tx_ringbuffer);
	  if (remain == 0) 
	    {
	      USB_Tx_State = 0;
		  rt_hw_interrupt_enable(level);
		  return;
	    }
	    else
	    {
	    	if (remain > VIRTUAL_COM_PORT_DATA_SIZE)
	    	{
				remain = VIRTUAL_COM_PORT_DATA_SIZE;
			}
	        /* although vcom_in_sending is set in SOF handler in the very
	         * beginning, we have to guarantee the state is right when start
	         * sending. There is at least one extreme case where we have finished the
	         * last IN transaction but the vcom_in_sending is RT_FALSE.
	         *
	         * Ok, what the extreme case is: pour data into vcom in loop. Open
	         * terminal on the PC, you will see the data. Then close it. So the
	         * data will be sent to the PC in the back. When the buffer of the PC
	         * driver is full. It will not send IN packet to the board and you will
	         * have no chance to clear vcom_in_sending in this function. The data
	         * will fill into the ringbuffer until it is full, and we will reset
	         * the state machine and clear vcom_in_sending. When you open the
	         * terminal on the PC again. The IN packet will appear on the line and
	         * we will, eventually, reach here with vcom_in_sending is clear.
	         */
	        vcom_in_sending = RT_TRUE;
	        rt_ringbuffer_get(&tx_ringbuffer, tx_buf, remain);
	        rt_hw_interrupt_enable(level);

	        /* send data to host */
			UserToPMABufferCopy(tx_buf, ENDP1_TXADDR, remain);
	        SetEPTxCount(ENDP1, remain);
	        SetEPTxValid(ENDP1); 

	        //return RT_EOK;
	    }
  	}

}
コード例 #24
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);
  }
}
コード例 #25
0
ファイル: hw_usb_stm32f10.c プロジェクト: t0mac0/wiimouse
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;
}
コード例 #26
0
ファイル: main.c プロジェクト: cloned67/STM32
int main(void)
{
	uint32_t count = 0;
	NVIC_InitTypeDef NVIC_InitStructure;

	/* System Clocks Configuration */
	RCC_Configuration();

	/* NVIC configuration */
	NVIC_Configuration();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

	NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	/* Configure the GPIO ports */
	GPIO_Configuration();

	USB_Init();

	while (1) {
		if ((count_out != 0) && (bDeviceState == CONFIGURED)) {
			uint8_t i;
			bli();

//			USB_SIL_Write(EP1_IN, buffer_out, count_out);
			for (i = 0; i<count_out; i++) {
				buffer_in[(count_in+i)%64] = buffer_out[i];
			}
			count_in += count_out;
			count_out = 0;
			count = 0;
		}

		count++;
		count%=10000000/2;
		if (count == 0 && count_in > 0) {
			bli();
			USB_SIL_Write(EP1_IN, buffer_in, count_in);
			SetEPTxValid(ENDP1);
		}
	}

	while (1);
}
コード例 #27
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 */
}
コード例 #28
0
/*******************************************************************************
 * Function Name  : Handle_USBAsynchXfer.
 * Description    : send data to USB.
 * Input          : None.
 * Return         : None.
 *******************************************************************************/
void Handle_USBAsynchXfer (void)
{
	uint16_t USB_Tx_ptr;
	uint16_t USB_Tx_length;

	if(USB_Tx_State != 1)
	{
		if (USART_Rx_ptr_out == USART_Rx_Buffer_size)
		{
			USART_Rx_ptr_out = 0;
		}

		if(USART_Rx_ptr_out == USART_Rx_ptr_in)
		{
			USB_Tx_State = 0;
			return;
		}

		if(USART_Rx_ptr_out > USART_Rx_ptr_in) /* rollback */
		{
			USART_Rx_length = USART_Rx_Buffer_size - USART_Rx_ptr_out;
		}
		else
		{
			USART_Rx_length = USART_Rx_ptr_in - USART_Rx_ptr_out;
		}

		if (USART_Rx_length > CDC_DATA_SIZE)
		{
			USB_Tx_ptr = USART_Rx_ptr_out;
			USB_Tx_length = CDC_DATA_SIZE;

			USART_Rx_ptr_out += CDC_DATA_SIZE;
			USART_Rx_length -= CDC_DATA_SIZE;
		}
		else
		{
			USB_Tx_ptr = USART_Rx_ptr_out;
			USB_Tx_length = USART_Rx_length;

			USART_Rx_ptr_out += USART_Rx_length;
			USART_Rx_length = 0;
		}
		UserToPMABufferCopy(&USART_Rx_Buffer[USB_Tx_ptr], ENDP1_TXADDR, USB_Tx_length);
		SetEPTxCount(ENDP1, USB_Tx_length);
		SetEPTxValid(ENDP1);
		USB_Tx_State = 1;
	}
}
コード例 #29
0
ファイル: hw_config.c プロジェクト: wind5027/UCOS_Learn
/*******************************************************************************
* Function Name  : UART_To_USB_Send_Data.
* Description    : send the received data from UART 0 to USB.
* Input          : None.
* Return         : none.
*******************************************************************************/
void USART_To_USB_Send_Data(void)
{
  if (USART_InitStructure.USART_WordLength == USART_WordLength_8b)
  {
    buffer_in[count_in] = USART_ReceiveData(USART1) & 0x7F;
  }
  else if (USART_InitStructure.USART_WordLength == USART_WordLength_9b)
  {
    buffer_in[count_in] = USART_ReceiveData(USART1);
  }
  count_in++;
  UserToPMABufferCopy(buffer_in, ENDP1_TXADDR, count_in);
  SetEPTxCount(ENDP1, count_in);
  SetEPTxValid(ENDP1);
}
コード例 #30
0
/* write a full block or less out EndPoint1 every callback */
void EP1_IN_Callback(void)
{
    static uint8_t buffer[VIRTUAL_COM_PORT_DATA_SIZE];
    unsigned int bytes = GetDataFromRing(&tx_ring, VIRTUAL_COM_PORT_DATA_SIZE, buffer);
    if (bytes)
    {
        USB_SIL_Write(EP1_IN, buffer, bytes);
#ifndef STM32F10X_CL
        SetEPTxValid(ENDP1);
#endif /* STM32F10X_CL */
    }
    else
    {
        write_ready = 1;
    }
}