Esempio n. 1
0
void ep_send_zlp(U8 ep_num)
{
    if( ep_num == 0 )
    {
        SI32_USB_A_set_data_end_ep0( SI32_USB_0 );
        SI32_USB_A_clear_out_packet_ready_ep0( SI32_USB_0 );
    }
}
// Finish handling the setup packet and move on to the IN/OUT data phase
// of the control request
void Finish_Setup(void)
{
  // Copy selected bytes from the Setup packet
  for (int i = 0; i < DFU_SETUP_PACKET_COPY_SIZE; i++)
  {
    RxBuffer[i] = ((uint8_t*)&Setup)[i + DFU_SETUP_PACKET_COPY_OFFSET];
  }

  // Set Serviced Out packet ready
  SI32_USB_A_clear_out_packet_ready_ep0(SI32_USB_0);

  // Handle out class requests
  if ((Setup.bmRequestType & DIR_BITMASK) == DIR_OUT)
  {
    // No data phase, end the control transfer
    if (Setup.wLength == 0)
    {
      // Set Serviced Out packet ready and
      // data end to indicate transaction
      // is over
      SI32_USB_A_set_data_end_ep0(SI32_USB_0);

      // Return to IDLE state
      EP_Status = EP_IDLE;

      // Control transfer complete
      USB0_RX_Complete(DFU_SETUP_PACKET_COPY_SIZE);
    }
    else
    {
      // Set the DataPtr to store data in the ClassOutBuffer (after the Setup packet data)
      ReadDataPtr = RxBuffer + DFU_SETUP_PACKET_COPY_SIZE;
      ReadDataSize = RxBufferSize - DFU_SETUP_PACKET_COPY_SIZE;
      ReadDataReceived = 0;

      // Setup the RX phase of the control transfer
      EP_Status = EP_RX;
    }
  }
  // Handle in class requests
  else
  {
    // Wait until TX data is ready from the App
    EP_Status = EP_WAIT_TX;

    // Control transfer setup complete
    USB0_RX_Complete(DFU_SETUP_PACKET_COPY_SIZE);
  }
}