Example #1
0
File: Core.cpp Project: Dzenik/Cosa
void 
InitControl(int end)
{
  SetEP(0);
  _cmark = 0;
  _cend = end;
}
Example #2
0
File: Core.cpp Project: Dzenik/Cosa
void 
USB_Flush(uint8_t ep)
{
  SetEP(ep);
  if (FifoByteCount())
    ReleaseTX();
}
Example #3
0
//	Space in send EP
uint8_t USBD_SendSpace(uint8_t ep)
{
	SetEP(ep);
	if (!ReadWriteAllowed())
  {
		return 0;
  }

	return 64 - FifoByteCount();
}
Example #4
0
void Recv(u8 ep, u8* dst, u8 len)
{
	SetEP(ep);
	while (len--)
	{
		while (!ReadWriteAllowed())
			;
		*dst++ = Recv8();
		if (!ReadWriteAllowed())	// release empty buffer
			ReleaseRX();
	}
}
Example #5
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();
}
Example #6
0
void USBD_InitControl(int end)
{
	SetEP(0);
  UDPHS->UDPHS_EPT[0].UDPHS_EPTCFG = _initEndpoints[0];

  while( (signed int)UDPHS_EPTCFG_EPT_MAPD != (signed int)((UDPHS->UDPHS_EPT[0].UDPHS_EPTCFG) & (unsigned int)UDPHS_EPTCFG_EPT_MAPD) )
  ;

  UDPHS->UDPHS_EPT[0].UDPHS_EPTCTLENB = UDPHS_EPTCTLENB_RX_BK_RDY
                                       | UDPHS_EPTCTLENB_RX_SETUP
                                       | UDPHS_EPTCTLENB_EPT_ENABL;

	_cmark = 0;
	_cend = end;
}
Example #7
0
//	Blocking Send of data to an endpoint
int USBD_Send(uint8_t ep, const void* d, int len)
{
	if (!_usbConfiguration)
		return -1;

	int r = len;
	const uint8_t* data = (const uint8_t*)d;
	uint8_t zero = ep & TRANSFER_ZERO;
	uint8_t timeout = 250;		// 250ms timeout on send? TODO
	while (len)
	{
		uint8_t n = USB_SendSpace(ep);
		if (n == 0)
		{
			if (!(--timeout))
				return -1;
			delay(1);
			continue;
		}

		if (n > len)
			n = len;
		len -= n;
		{
			SetEP(ep);
			if (ep & TRANSFER_ZERO)
			{
				while (n--)
					Send8(0);
			}
			else if (ep & TRANSFER_PGM)
			{
				while (n--)
					Send8(*data++);
			}
			else
			{
				while (n--)
					Send8(*data++);
			}
//			if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE)))	// Release full buffer
//				ReleaseTX();
		}
	}
	TXLED1;					// light the TX LED
	TxLEDPulse = TX_RX_LED_PULSE_MS;
	return r;
}
Example #8
0
//	Transmit a packet to endpoint
void Transfer(u8 ep, const u8* data, int len)
{
	u8 zero = ep & TRANSFER_ZERO;
	SetEP(ep & 7);
	while (len--)
	{
		while (!ReadWriteAllowed())
			;	// TODO Check for STALL etc

		u8 d = (ep & TRANSFER_PGM) ? pgm_read_byte(data) : data[0];
		data++;
		if (zero)
			d = 0;
		Send8(d);

		if (!ReadWriteAllowed())
			ReleaseTX();
	}
	if (ep & TRANSFER_RELEASE)
		ReleaseTX();
}
Example #9
0
	LockEP(u8 ep) : _sreg(SREG)
	{
		cli();
		SetEP(ep & 7);
	}
Example #10
0
//	Number of bytes, assumes a rx endpoint
uint8_t USBD_Available(uint8_t ep)
{
	SetEP(ep);

	return FifoByteCount();
}
Example #11
0
File: Core.cpp Project: Dzenik/Cosa
 LockEP(uint8_t ep) : _sreg(SREG)
 {
   cli();
   SetEP(ep & 7);
 }
Example #12
0
  LockEP(u8 ep) : _sreg(SREG)
  {
// POOBAH - see if there's a better way
//    cli();
    SetEP(ep & 7);
  }
Example #13
0
void USB_Flush(u8 ep)
{
  SetEP(ep);
  if (WriteByteCount())//FifoByteCount())
    ReleaseTX();
}
Example #14
0
u8 HasData(u8 ep)
{
	SetEP(ep);
	return ReadWriteAllowed();	// count in fifo
}