Пример #1
0
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void myUsbDevice_request_handler(void)
{
  switch (myUSB0_setup.wRequest)
  {
  case USB_REQUEST_STANDARD_DEVICE_GET_DESCRIPTOR: // Support device, configuration, string
    if (myUSB0_setup.wValue == 0x0100)
    {
      myUSB0_ep0_data_pointer = (uint8_t *)&myUsbDeviceDescriptor;
      myUSB0_ep0_data_size    = _min(myUSB0_setup.wValue, sizeof(myUsbDeviceDescriptor));
      myUSB0_ep0_state        = EP0_START_IN_DATA;
    }
    else if (myUSB0_setup.wValue == 0x0200)
    {
      myUSB0_ep0_data_pointer = (uint8_t *)&myUsbConfigurationDescriptors;
      myUSB0_ep0_data_size    = _min(myUSB0_setup.wValue, sizeof(myUsbConfigurationDescriptors));
      myUSB0_ep0_state        = EP0_START_IN_DATA;
    }
    else
    {
      myUSB0_ep0_state = EP0_SEND_STALL;
    }
    break;

  case USB_REQUEST_STANDARD_DEVICE_SET_ADDRESS:
    SI32_USB_A_write_faddr(SI32_USB_0, (0x7F & myUSB0_setup.wValue));
    myUSB0_ep0_state = EP0_NODATA_STATUS;
    break;

  case USB_REQUEST_STANDARD_DEVICE_SET_CONFIG:
  case USB_REQUEST_STANDARD_DEVICE_SET_INTERFACE:
    SI32_USBEP_A_set_endpoint_direction_in(SI32_USB_0_EP1);
    SI32_USBEP_A_clear_in_data_underrun(SI32_USB_0_EP1);
    SI32_USBEP_A_select_in_bulk_interrupt_mode(SI32_USB_0_EP1);
    SI32_USBEP_A_stop_in_stall(SI32_USB_0_EP1);
    SI32_USBEP_A_reset_in_data_toggle(SI32_USB_0_EP1);
    SI32_USBEP_A_set_in_max_packet_size(SI32_USB_0_EP1, 64>>3);
    SI32_USB_A_enable_ep1(SI32_USB_0);
    myUSB0_ep1_state=EPN_IDLE;
    myUSB0_ep0_state = EP0_NODATA_STATUS;
    break;


  case USB_REQUEST_STANDARD_INTERFACE_GET_DESCRIPTOR:
    if (myUSB0_setup.wValue == 0x2200)
    {
      myUSB0_ep0_data_pointer = (uint8_t *)&myUsbHidKeypadUsage;
      myUSB0_ep0_data_size    = _min(myUSB0_setup.wValue, sizeof(myUsbHidKeypadUsage));
      myUSB0_ep0_state        = EP0_START_IN_DATA;
      break;
    }

  default:
    myUSB0_ep0_state = EP0_SEND_STALL;
    break;
  }
}
Пример #2
0
void ep_set_addr(U8 addr)
{
    // send out a zlp to ack the set address request
    ep_send_zlp(EP_CTRL);

    // only write the top 7 bits of the address. the 8th bit is for enable
    SI32_USB_A_write_faddr( SI32_USB_0, addr & 0x7F);

    // Wait for address to be updated
    while( SI32_USB_A_is_function_address_updating( SI32_USB_0 ) );
}