示例#1
0
/** ISR for the general Pipe/Endpoint interrupt vector. This ISR fires when a control request has been issued to the control endpoint,
 *  so that the request can be processed. As several elements of the Mass Storage implementation require asynchronous control requests
 *  (such as endpoint stall clearing and Mass Storage Reset requests during data transfers) this is done via interrupts rather than
 *  polling.
 */
ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
{
	/* Check if the control endpoint has received a request */
	if (Endpoint_HasEndpointInterrupted(ENDPOINT_CONTROLEP))
	{
		/* Clear the endpoint interrupt */
		Endpoint_ClearEndpointInterrupt(ENDPOINT_CONTROLEP);

		/* Process the control request */
		USB_USBTask();

		/* Handshake the endpoint setup interrupt - must be after the call to USB_USBTask() */
		USB_INT_Clear(ENDPOINT_INT_SETUP);
	}
}
示例#2
0
/** ISR for the general Pipe/Endpoint interrupt vector. This ISR fires when an endpoint's status changes (such as
 *  a packet has been received) on an endpoint with its corresponding ISR enabling bits set. This is used to send
 *  HID packets to the host each time the HID interrupt endpoints polling period elapses, as managed by the USB
 *  controller.
 */
ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
{
	/* Save previously selected endpoint before selecting a new endpoint */
	uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();

	#if defined(INTERRUPT_CONTROL_ENDPOINT)
	/* Check if the control endpoint has received a request */
	if (Endpoint_HasEndpointInterrupted(ENDPOINT_CONTROLEP))
	{
		/* Clear the endpoint interrupt */
		Endpoint_ClearEndpointInterrupt(ENDPOINT_CONTROLEP);

		/* Process the control request */
		USB_USBTask();

		/* Handshake the endpoint setup interrupt - must be after the call to USB_USBTask() */
		USB_INT_Clear(ENDPOINT_INT_SETUP);
	}
	#endif

	#if defined(INTERRUPT_DATA_ENDPOINT)
	/* Check if Generic IN endpoint has interrupted */
	if (Endpoint_HasEndpointInterrupted(GENERIC_IN_EPNUM))
	{
		/* Select the Generic IN Report Endpoint */
		Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);

		/* Clear the endpoint IN interrupt flag */
		USB_INT_Clear(ENDPOINT_INT_IN);

		/* Clear the Generic IN Report endpoint interrupt and select the endpoint */
		Endpoint_ClearEndpointInterrupt(GENERIC_IN_EPNUM);

		/* Create a temporary buffer to hold the report to send to the host */
		uint8_t GenericData[GENERIC_REPORT_SIZE];
		
		/* Create Generic Report Data */
		CreateGenericHIDReport(GenericData);

		/* Write Generic Report Data */
		Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));

		/* Finalize the stream transfer to send the last packet */
		Endpoint_ClearIN();
	}

	/* Check if Generic OUT endpoint has interrupted */
	if (Endpoint_HasEndpointInterrupted(GENERIC_OUT_EPNUM))
	{
		/* Select the Generic OUT Report Endpoint */
		Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);

		/* Clear the endpoint OUT Interrupt flag */
		USB_INT_Clear(ENDPOINT_INT_OUT);

		/* Clear the Generic OUT Report endpoint interrupt and select the endpoint */
		Endpoint_ClearEndpointInterrupt(GENERIC_OUT_EPNUM);

		/* Create a temporary buffer to hold the read in report from the host */
		uint8_t GenericData[GENERIC_REPORT_SIZE];
		
		/* Read Generic Report Data */
		Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));
		
		/* Process Generic Report Data */
		ProcessGenericHIDReport(GenericData);

		/* Finalize the stream transfer to send the last packet */
		Endpoint_ClearOUT();
	}
	#endif

	/* Restore previously selected endpoint */
	Endpoint_SelectEndpoint(PrevSelectedEndpoint);
}