Exemplo n.º 1
0
void USBSetupInterrupt()
{
    SetEP(0);
	if (!ReceivedSetupInt())
		return;

	Setup& setup = _setup;	// global saves ~30 bytes
	Recv((u8*)&setup,8);
	ClearSetupInt();

	if (setup.bmRequestType & DEVICETOHOST)
		WaitIN();
	else
		ClearIN();

    bool ok = true;
	u8 r = setup.bRequest;
	if (SET_ADDRESS == r)
	{
		WaitIN();
		UDADDR = setup.wValueL | (1<<ADDEN);
	}
	else if (SET_CONFIGURATION == r)
	{
		_usbConfiguration = setup.wValueL;
		InitEndpoints();
	}
	else if (GET_CONFIGURATION == r)
	{
		Send8(_usbConfiguration);
	}
	else if (GET_STATUS == r)
	{
		Send8(0);		// All good as far as I know
	}
	else if (GET_DESCRIPTOR == r)
	{
		ok = SendDescriptor();
	}
	else
	{
		ok = USBHook();
	}

	if (ok)
		ClearIN();
	else
		Stall();
}
Exemplo n.º 2
0
static inline void Send8(u8 d)
{
  uint8_t iTemp, oldSREG;
//  UEDATX = d;

  oldSREG = SREG;
  cli(); // disable interrupts

  // auto wait-to-send if buffer being sent right now

  WaitIN(); // automatic (for now), misleading function name waits for OUTPUT COMPLETE

  iTemp = aEPBuff[endpointIndex].iBufLen2;

  if(iTemp < INTERNAL_BUFFER_LENGTH)
  {

    aEPBuff[endpointIndex].aBuf2[iTemp++] = d;

    aEPBuff[endpointIndex].iBufLen2 = iTemp;

    if(iTemp >= INTERNAL_BUFFER_LENGTH)
    {
      // do I force-send the buffer now?
      ClearIN(); /// misleading function name, sends the data      
    }

  }

  SREG=oldSREG;
}
Exemplo n.º 3
0
bool SendDescriptor()
{
	Setup& setup = _setup;
	u8 desc_length = 0;
	const u8* desc_addr = 0;

	u8 t = setup.wValueH;
	if (0x22 == t)
	{
		desc_addr = _rawHID;
		desc_length = sizeof(desc_length);
	} else 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_CONFIGURATION_DESCRIPTOR_TYPE == t)
	{
		desc_addr = (const u8*)&USB_ConfigDescriptor;
		desc_length = sizeof(USB_ConfigDescriptor);
	}
	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 == ISERIAL)
			desc_addr = (const u8*)&STRING_SERIAL;
		else if (setup.wValueL == IMANUFACTURER)
			desc_addr = (const u8*)&STRING_IMANUFACTURER;
		else
			return false;
	} else 
		return false;

	if (desc_length == 0)
		desc_length = pgm_read_byte(desc_addr);
	if ((u8)setup.wLength < desc_length)		// bit of a cheat limiting to 255 bytes TODO (saved 8 bytes)
		desc_length = (u8)setup.wLength;

	//	Send descriptor
	//	EP0 is 64 bytes long
	//	RWAL and FIFOCON don't work on EP0
	u8 n = 0;
	do
	{
		if (!WaitForINOrOUT())
			return false;
		Send8(pgm_read_byte(&desc_addr[n++]));
		u8 clr = n & 0x3F;
		if (!clr)
			ClearIN();	// Fifo is full, release this packet
	} while (n < desc_length);
	return true;
}
Exemplo n.º 4
0
Arquivo: Core.cpp Projeto: Dzenik/Cosa
static bool 
SendControl(uint8_t d)
{
  if (_cmark < _cend) {
    if (!WaitForINOrOUT()) return (false);
    Send8(d);
    if (!((_cmark + 1) & 0x3F)) ClearIN();
  }
  _cmark++;
  return (true);
};
Exemplo n.º 5
0
static
bool SendControl(u8 d)
{
	if (_cmark < _cend)
	{
		if (!WaitForINOrOUT())
			return false;
		Send8(d);
		if (!((_cmark + 1) & 0x3F))
			ClearIN();	// Fifo is full, release this packet
	}
	_cmark++;
	return true;
};