Beispiel #1
0
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;
}
Beispiel #2
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];

  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;
}
Beispiel #3
0
/**
  * @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; 
}