Пример #1
0
static
bool SendDescriptor(USBSetup& setup)
{
	int ret;
	u8 t = setup.wValueH;
	if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
		return SendConfiguration(setup.wLength);

	InitControl(setup.wLength);
#ifdef PLUGGABLE_USB_ENABLED
	ret = PluggableUSB().getDescriptor(setup);
	if (ret != 0) {
		return (ret > 0 ? true : false);
	}
#endif

	const u8* desc_addr = 0;
	if (USB_DEVICE_DESCRIPTOR_TYPE == t)
	{
		if (setup.wLength == 8)
			_cdcComposite = 1;
		desc_addr = _cdcComposite ?  (const u8*)&USB_DeviceDescriptorB : (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), TRANSFER_PGM);
		}
		else if (setup.wValueL == IMANUFACTURER) {
			return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER), TRANSFER_PGM);
		}
		else if (setup.wValueL == ISERIAL) {
#ifdef PLUGGABLE_USB_ENABLED
			char name[ISERIAL_MAX_LEN];
			PluggableUSB().getShortName(name);
			return USB_SendStringDescriptor((uint8_t*)name, strlen(name), 0);
#endif
		}
		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;
}
Пример #2
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;
}
Пример #4
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);
}
Пример #5
0
void SerialComm::ProcessData() {
    MessageType code;
    uint32_t mask;

    if (!data_input.ParseInto(code, mask))
        return;
    if (code != MessageType::Command)
        return;

    uint32_t ack_data{0};

    if (mask & COM_SET_EEPROM_DATA && data_input.ParseInto(config->raw)) {
        writeEEPROM();  // TODO: deal with side effect code
        ack_data |= COM_SET_EEPROM_DATA;
    }
    if (mask & COM_REINIT_EEPROM_DATA) {
        initializeEEPROM();  // TODO: deal with side effect code
        writeEEPROM();       // TODO: deal with side effect code
    }
    if (mask & COM_REQ_EEPROM_DATA) {
        SendConfiguration();
        ack_data |= COM_REQ_EEPROM_DATA;
    }
    if (mask & COM_REQ_ENABLE_ITERATION) {
        uint8_t flag;
        if (data_input.ParseInto(flag)) {
            if (flag == 1)
                state->processMotorEnablingIteration();
            else
                state->disableMotors();
            ack_data |= COM_REQ_ENABLE_ITERATION;
        }
    }
    // This should pass if any motor speed is set
    if (mask & COM_MOTOR_OVERRIDE_SPEED_ALL) {
        if (mask & COM_MOTOR_OVERRIDE_SPEED_0 && data_input.ParseInto(state->MotorOut[0]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_0;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_1 && data_input.ParseInto(state->MotorOut[1]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_1;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_2 && data_input.ParseInto(state->MotorOut[2]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_2;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_3 && data_input.ParseInto(state->MotorOut[3]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_3;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_4 && data_input.ParseInto(state->MotorOut[4]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_4;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_5 && data_input.ParseInto(state->MotorOut[5]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_5;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_6 && data_input.ParseInto(state->MotorOut[6]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_6;
        if (mask & COM_MOTOR_OVERRIDE_SPEED_7 && data_input.ParseInto(state->MotorOut[7]))
            ack_data |= COM_MOTOR_OVERRIDE_SPEED_7;
    }
    if (mask & COM_SET_COMMAND_OVERRIDE) {
        uint8_t flag;
        if (data_input.ParseInto(flag)) {
            if (flag == 1)
                state->set(STATUS_OVERRIDE);
            else
                state->clear(STATUS_OVERRIDE);
            ack_data |= COM_SET_COMMAND_OVERRIDE;
        }
    }
    if (mask & COM_SET_STATE_MASK) {
        uint32_t new_state_mask;
        if (data_input.ParseInto(new_state_mask)) {
            SetStateMsg(new_state_mask);
            ack_data |= COM_SET_STATE_MASK;
        }
    }
    if (mask & COM_SET_STATE_DELAY) {
        uint16_t new_state_delay;
        if (data_input.ParseInto(new_state_delay)) {
            send_state_delay = new_state_delay;
            ack_data |= COM_SET_STATE_DELAY;
        }
    }
    if (mask & COM_REQ_HISTORY) {
        String eeprom_data;
        for (size_t i = EEPROM_LOG_START; i < EEPROM_LOG_END; ++i)
            eeprom_data += char(EEPROM[i]);
        SendDebugString(eeprom_data, MessageType::HistoryData);
        ack_data |= COM_REQ_HISTORY;
    }
    if (mask & COM_SET_LED) {
        uint8_t mode, r1, g1, b1, r2, g2, b2, ind_r, ind_g;
        if (data_input.ParseInto(mode, r1, g1, b1, r2, g2, b2, ind_r, ind_g)) {
            led->set(LED::Pattern(mode), r1, g1, b1, r2, g2, b2, ind_r, ind_g);
            ack_data |= COM_SET_LED;
        }
    }

    if (mask & COM_REQ_RESPONSE) {
        SendResponse(mask, ack_data);
    }
}