Пример #1
0
static
bool SendDescriptor(Setup& setup)
{
//  DEBUG_OUT(F("USB SendDescriptor\r\n"));

#ifdef LED_SIGNAL1
  digitalWrite(LED_SIGNAL1,digitalRead(LED_SIGNAL1) == LOW ? HIGH : LOW);
#endif // LED_SIGNAL1

  u8 t = setup.wValueH;
  if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
    return SendConfiguration(setup.wLength);

  InitControl(setup.wLength);
#ifdef HID_ENABLED
  if (HID_REPORT_DESCRIPTOR_TYPE == t)
    return HID_GetDescriptor(t);
#endif

  u8 desc_length = 0;
  const u8* desc_addr = 0;
  if (USB_DEVICE_DESCRIPTOR_TYPE == t)
  {
    if (setup.wLength == 8)
      _cdcComposite = 1;
    desc_addr = _cdcComposite ?  (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor;
  }
  else if (USB_STRING_DESCRIPTOR_TYPE == t)
  {
    if (setup.wValueL == 0)
      desc_addr = (const u8*)&STRING_LANGUAGE;
    else if (setup.wValueL == IPRODUCT) 
      desc_addr = (const u8*)&STRING_IPRODUCT;
    else if (setup.wValueL == IMANUFACTURER)
      desc_addr = (const u8*)&STRING_IMANUFACTURER;
    else
      return false;
  }

  if (desc_addr == 0)
    return false;
  if (desc_length == 0)
    desc_length = pgm_read_byte(desc_addr);

  USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
  return true;
}
static
bool SendDescriptor(Setup& setup)
{
	u8 t = setup.wValueH;
	if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
		return SendConfiguration(setup.wLength);

	InitControl(setup.wLength);
#ifdef HID_ENABLED
	if (HID_REPORT_DESCRIPTOR_TYPE == t)
		return HID_GetDescriptor(t);
#endif

	const u8* desc_addr = 0;
	if (USB_DEVICE_DESCRIPTOR_TYPE == t)
	{
		if (setup.wLength == 8)
			_cdcComposite = 1;
		desc_addr = _cdcComposite ?  (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor;
	}
	else if (USB_STRING_DESCRIPTOR_TYPE == t)
	{
		if (setup.wValueL == 0) {
			desc_addr = (const u8*)&STRING_LANGUAGE;
		}
		else if (setup.wValueL == IPRODUCT) {
			return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT));
		}
		else if (setup.wValueL == IMANUFACTURER) {
			return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
		}
		else
			return false;
	}

	if (desc_addr == 0)
		return false;
	u8 desc_length = pgm_read_byte(desc_addr);

	USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
	return true;
}
Пример #3
0
static bool 
SendDescriptor(Setup& setup)
{
  uint8_t t = setup.wValueH;
  if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
    return (SendConfiguration(setup.wLength));

  InitControl(setup.wLength);
#ifdef HID_ENABLED
  if (HID_REPORT_DESCRIPTOR_TYPE == t)
    return (HID_GetDescriptor(t));
#endif

  uint8_t desc_length = 0;
  const uint8_t* desc_addr = 0;
  if (USB_DEVICE_DESCRIPTOR_TYPE == t) {
    if (setup.wLength == 8)
      _cdcComposite = 1;
    desc_addr = _cdcComposite ?  (const uint8_t*)&USB_DeviceDescriptorA : (const uint8_t*)&USB_DeviceDescriptor;
  }
  else if (USB_STRING_DESCRIPTOR_TYPE == t) {
    if (setup.wValueL == 0)
      desc_addr = (const uint8_t*)&STRING_LANGUAGE;
    else if (setup.wValueL == IPRODUCT) 
      desc_addr = (const uint8_t*)&STRING_IPRODUCT;
    else if (setup.wValueL == IMANUFACTURER)
      desc_addr = (const uint8_t*)&STRING_IMANUFACTURER;
    else
      return (false);
  }

  if (desc_addr == 0) return (false);
  if (desc_length == 0)
    desc_length = pgm_read_byte(desc_addr);
  
  USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
  return (true);
}