当前位置: 首页>>代码示例>>C++>>正文


C++ Pipe_IsReadWriteAllowed函数代码示例

本文整理汇总了C++中Pipe_IsReadWriteAllowed函数的典型用法代码示例。如果您正苦于以下问题:C++ Pipe_IsReadWriteAllowed函数的具体用法?C++ Pipe_IsReadWriteAllowed怎么用?C++ Pipe_IsReadWriteAllowed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Pipe_IsReadWriteAllowed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MouseHost_Task

/** Task to read and process the HID report descriptor and HID reports from the device and display the
 *  results onto the board LEDs.
 */
void MouseHost_Task(void)
{
	if (USB_HostState != HOST_STATE_Configured)
	  return;

	/* Select and unfreeze mouse data pipe */
	Pipe_SelectPipe(MOUSE_DATA_IN_PIPE);
	Pipe_Unfreeze();

	/* Check to see if a packet has been received */
	if (Pipe_IsINReceived())
	{
		/* Check if data has been received from the attached mouse */
		if (Pipe_IsReadWriteAllowed())
		{
			/* Create buffer big enough for the report */
			uint8_t MouseReport[Pipe_BytesInPipe()];

			/* Load in the mouse report */
			Pipe_Read_Stream_LE(MouseReport, Pipe_BytesInPipe(), NULL);

			/* Process the read in mouse report from the device */
			ProcessMouseReport(MouseReport);
		}

		/* Clear the IN endpoint, ready for next data packet */
		Pipe_ClearIN();
	}

	/* Freeze mouse data pipe */
	Pipe_Freeze();
}
开发者ID:hopfgarten,项目名称:jnode-atmega-dual-firmware,代码行数:35,代码来源:MouseHostWithParser.c

示例2: Pipe_WaitUntilReady

uint8_t Pipe_WaitUntilReady(const uint8_t corenum)
{
	/*	#if (USB_STREAM_TIMEOUT_MS < 0xFF)
	    uint8_t  TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
	   #else
	    uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
	   #endif

	    uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();*/

	for (;; ) {
		if (Pipe_IsReadWriteAllowed(corenum)) {
			return PIPE_READYWAIT_NoError;
		}

		if (Pipe_IsStalled(corenum)) {
			return PIPE_READYWAIT_PipeStalled;
		}
		else if (USB_HostState[corenum] == HOST_STATE_Unattached) {
			return PIPE_READYWAIT_DeviceDisconnected;
		}

		/*TODO no timeout yet */
		/* uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();

		   if (CurrentFrameNumber != PreviousFrameNumber)
		   {
		    PreviousFrameNumber = CurrentFrameNumber;

		    if (!(TimeoutMSRem--))
		      return PIPE_READYWAIT_Timeout;
		   }*/
	}
}
开发者ID:Goodchaild,项目名称:svofski,代码行数:34,代码来源:Pipe.c

示例3: ReadNextReport

/** Reads in and processes the next report from the attached device, displaying the report
 *  contents on the board LEDs and via the serial port.
 */
void ReadNextReport(void)
{
	USB_MouseReport_Data_t MouseReport;
	uint8_t                LEDMask = LEDS_NO_LEDS;

	/* Select mouse data pipe */
	Pipe_SelectPipe(MOUSE_DATA_IN_PIPE);

	/* Unfreeze keyboard data pipe */
	Pipe_Unfreeze();

	/* Check to see if a packet has been received */
	if (!(Pipe_IsINReceived()))
	{
		/* No packet received (no movement), turn off LEDs */
		LEDs_SetAllLEDs(LEDS_NO_LEDS);

		/* Refreeze HID data IN pipe */
		Pipe_Freeze();

		return;
	}

	/* Ensure pipe contains data before trying to read from it */
	if (Pipe_IsReadWriteAllowed())
	{
		/* Read in mouse report data */
		Pipe_Read_Stream_LE(&MouseReport, sizeof(MouseReport));

		/* Alter status LEDs according to mouse X movement */
		if (MouseReport.X > 0)
		  LEDMask |= LEDS_LED1;
		else if (MouseReport.X < 0)
		  LEDMask |= LEDS_LED2;

		/* Alter status LEDs according to mouse Y movement */
		if (MouseReport.Y > 0)
		  LEDMask |= LEDS_LED3;
		else if (MouseReport.Y < 0)
		  LEDMask |= LEDS_LED4;

		/* Alter status LEDs according to mouse button position */
		if (MouseReport.Button)
		  LEDMask  = LEDS_ALL_LEDS;

		LEDs_SetAllLEDs(LEDMask);

		/* Print mouse report data through the serial port */
		printf_P(PSTR("dX:%2d dY:%2d Button:%d\r\n"), MouseReport.X,
													  MouseReport.Y,
													  MouseReport.Button);
	}

	/* Clear the IN endpoint, ready for next data packet */
	Pipe_ClearIN();

	/* Refreeze mouse data pipe */
	Pipe_Freeze();
}
开发者ID:AmesianX,项目名称:OpenPCR,代码行数:62,代码来源:MouseHost.c

示例4: MIDI_Host_ReceiveEventPacket

bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event)
{
	if ((USB_HostState != HOST_STATE_Configured) || !(MIDIInterfaceInfo->State.IsActive))
	  return HOST_SENDCONTROL_DeviceDisconnected;
	
	Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataINPipeNumber);

	if (!(Pipe_IsReadWriteAllowed()))
	  return false;

	Pipe_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK);

	if (!(Pipe_IsReadWriteAllowed()))
	  Pipe_ClearIN();
	
	return true;
}
开发者ID:dfletcher,项目名称:avr-pca9555,代码行数:17,代码来源:MIDI.c

示例5: ReadNextReport

/** Reads in and processes the next report from the attached device, displaying the report
 *  contents on the board LEDs and via the serial port.
 */
void ReadNextReport(void)
{
	USB_KeyboardReport_Data_t KeyboardReport;
		
	/* Select keyboard data pipe */
	Pipe_SelectPipe(KEYBOARD_DATAPIPE);	

	/* Unfreeze keyboard data pipe */
	Pipe_Unfreeze();

	/* Check to see if a packet has been received */
	if (!(Pipe_IsINReceived()))
	{
		/* Refreeze HID data IN pipe */
		Pipe_Freeze();
			
		return;
	}
	
	/* Ensure pipe contains data before trying to read from it */
	if (Pipe_IsReadWriteAllowed())
	{
		/* Read in keyboard report data */
		Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport));

		/* Indicate if the modifier byte is non-zero (special key such as shift is being pressed) */
		LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0);
		
		/* Check if a key has been pressed */
		if (KeyboardReport.KeyCode)
		{
			/* Toggle status LED to indicate keypress */
			LEDs_ToggleLEDs(LEDS_LED2);
				  
			char PressedKey = 0;

			/* Retrieve pressed key character if alphanumeric */
			if ((KeyboardReport.KeyCode[0] >= 0x04) && (KeyboardReport.KeyCode[0] <= 0x1D))
			  PressedKey = (KeyboardReport.KeyCode[0] - 0x04) + 'A';
			else if ((KeyboardReport.KeyCode[0] >= 0x1E) && (KeyboardReport.KeyCode[0] <= 0x27))
			  PressedKey = (KeyboardReport.KeyCode[0] - 0x1E) + '0';
			else if (KeyboardReport.KeyCode[0] == 0x2C)
			  PressedKey = ' ';						
			else if (KeyboardReport.KeyCode[0] == 0x28)
			  PressedKey = '\n';
				 
			/* Print the pressed key character out through the serial port if valid */
			if (PressedKey)
			  putchar(PressedKey);
		}
	}
		
	/* Clear the IN endpoint, ready for next data packet */
	Pipe_ClearIN();

	/* Refreeze keyboard data pipe */
	Pipe_Freeze();
}
开发者ID:Andrew0Hill,项目名称:keyboard,代码行数:61,代码来源:KeyboardHost.c

示例6: MIDI_Host_ReceiveEventPacket

bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,
                                  MIDI_EventPacket_t* const Event)
{
	uint8_t portnum = MIDIInterfaceInfo->Config.PortNumber;

	if ((USB_HostState[portnum] != HOST_STATE_Configured) || !(MIDIInterfaceInfo->State.IsActive))
	  return HOST_SENDCONTROL_DeviceDisconnected;

	Pipe_SelectPipe(portnum,MIDIInterfaceInfo->Config.DataINPipeNumber);

	if (!(Pipe_IsReadWriteAllowed(portnum)))
	  return false;

	Pipe_Read_Stream_LE(portnum,Event, sizeof(MIDI_EventPacket_t), NULL);

	if (!(Pipe_IsReadWriteAllowed(portnum)))
	  Pipe_ClearIN(portnum);

	return true;
}
开发者ID:JeremyHsiao,项目名称:TinyBlueRat_LPCv1_03,代码行数:20,代码来源:MIDIClassHost.c

示例7: MIDI_Host_SendEventPacket

uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event)
{
	if ((USB_HostState != HOST_STATE_Configured) || !(MIDIInterfaceInfo->State.IsActive))
	  return HOST_SENDCONTROL_DeviceDisconnected;
	
	Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataOUTPipeNumber);

	if (Pipe_IsReadWriteAllowed())
	{
		uint8_t ErrorCode;

		if ((ErrorCode = Pipe_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError)
		  return ErrorCode;

		if (!(Pipe_IsReadWriteAllowed()))
		  Pipe_ClearOUT();
	}
	
	return PIPE_RWSTREAM_NoError;
}
开发者ID:dfletcher,项目名称:avr-pca9555,代码行数:20,代码来源:MIDI.c

示例8: CDCHost_Task

/** Task to read in data received from the attached CDC device and print it to the serial port.
 */
void CDCHost_Task(void)
{
	if (USB_HostState != HOST_STATE_Configured)
	  return;

	/* Select the data IN pipe */
	Pipe_SelectPipe(CDC_DATA_IN_PIPE);
	Pipe_Unfreeze();

	/* Check to see if a packet has been received */
	if (Pipe_IsINReceived())
	{
		/* Re-freeze IN pipe after the packet has been received */
		Pipe_Freeze();

		/* Check if data is in the pipe */
		if (Pipe_IsReadWriteAllowed())
		{
			/* Get the length of the pipe data, and create a new buffer to hold it */
			uint16_t BufferLength = Pipe_BytesInPipe();
			uint8_t  Buffer[BufferLength];

			/* Read in the pipe data to the temporary buffer */
			Pipe_Read_Stream_LE(Buffer, BufferLength, NULL);

			/* Print out the buffer contents to the USART */
			for (uint16_t BufferByte = 0; BufferByte < BufferLength; BufferByte++)
			  putchar(Buffer[BufferByte]);
		}

		/* Clear the pipe after it is read, ready for the next packet */
		Pipe_ClearIN();
	}

	/* Re-freeze IN pipe after use */
	Pipe_Freeze();

	/* Select and unfreeze the notification pipe */
	Pipe_SelectPipe(CDC_NOTIFICATION_PIPE);
	Pipe_Unfreeze();

	/* Check if a packet has been received */
	if (Pipe_IsINReceived())
	{
		/* Discard the unused event notification */
		Pipe_ClearIN();
	}

	/* Freeze notification IN pipe after use */
	Pipe_Freeze();
}
开发者ID:DynamicPerception,项目名称:ArduinoAT90USB,代码行数:53,代码来源:VirtualSerialHost.c

示例9: TEMPLATE_FUNC_NAME

uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
                            uint16_t Length,
                            uint16_t* const BytesProcessed)
{
	uint8_t* DataStream      = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
	uint16_t BytesInTransfer = 0;
	uint8_t  ErrorCode;

	Pipe_SetPipeToken(TEMPLATE_TOKEN);

	if ((ErrorCode = Pipe_WaitUntilReady()))
	  return ErrorCode;

	if (BytesProcessed != NULL)
	{
		Length -= *BytesProcessed;
		TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
	}

	while (Length)
	{
		if (!(Pipe_IsReadWriteAllowed()))
		{
			TEMPLATE_CLEAR_PIPE();

			if (BytesProcessed != NULL)
			{
				*BytesProcessed += BytesInTransfer;
				return PIPE_RWSTREAM_IncompleteTransfer;
			}

			if ((ErrorCode = Pipe_WaitUntilReady()))
			  return ErrorCode;
		}
		else
		{
			TEMPLATE_TRANSFER_BYTE(DataStream);
			TEMPLATE_BUFFER_MOVE(DataStream, 1);
			Length--;
			BytesInTransfer++;
		}
	}

	return PIPE_RWSTREAM_NoError;
}
开发者ID:Codingboy,项目名称:ucuni,代码行数:45,代码来源:Template_Pipe_RW.c

示例10: AndroidHost_Task

/** Task to set the configuration of the attached device after it has been enumerated. */
void AndroidHost_Task(void)
{
    if (USB_HostState != HOST_STATE_Configured)
        return;

    /* Select the data IN pipe */
    Pipe_SelectPipe(ANDROID_DATA_IN_PIPE);
    Pipe_Unfreeze();

    /* Check to see if a packet has been received */
    if (Pipe_IsINReceived())
    {
        /* Re-freeze IN pipe after the packet has been received */
        Pipe_Freeze();

        /* Check if data is in the pipe */
        if (Pipe_IsReadWriteAllowed())
        {
            uint8_t NextReceivedByte = Pipe_Read_8();
            uint8_t LEDMask          = LEDS_NO_LEDS;

            if (NextReceivedByte & 0x01)
                LEDMask |= LEDS_LED1;

            if (NextReceivedByte & 0x02)
                LEDMask |= LEDS_LED2;

            if (NextReceivedByte & 0x04)
                LEDMask |= LEDS_LED3;

            if (NextReceivedByte & 0x08)
                LEDMask |= LEDS_LED4;

            LEDs_SetAllLEDs(LEDMask);
        }
        else
        {
            /* Clear the pipe after all data in the packet has been read, ready for the next packet */
            Pipe_ClearIN();
        }
    }

    /* Re-freeze IN pipe after use */
    Pipe_Freeze();
}
开发者ID:ASHOK1991,项目名称:lb-Arduino-Code,代码行数:46,代码来源:AndroidAccessoryHost.c

示例11: ISR

/** ISR to handle the reloading of the endpoint with the next sample. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
	uint8_t PrevPipe = Pipe_GetCurrentPipe();

	Pipe_SelectPipe(AUDIO_DATA_OUT_PIPE);
	Pipe_Unfreeze();

	/* Check if the current pipe can be written to (device ready for more data) */
	if (Pipe_IsOUTReady())
	{
		int16_t AudioSample;

		#if defined(USE_TEST_TONE)
			static uint8_t SquareWaveSampleCount;
			static int16_t CurrentWaveValue;

			/* In test tone mode, generate a square wave at 1/256 of the sample rate */
			if (SquareWaveSampleCount++ == 0xFF)
			  CurrentWaveValue ^= 0x8000;

			/* Only generate audio if the board button is being pressed */
			AudioSample = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0;
		#else
			/* Audio sample is ADC value scaled to fit the entire range */
			AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());

			#if defined(MICROPHONE_BIASED_TO_HALF_RAIL)
			/* Microphone is biased to half rail voltage, subtract the bias from the sample value */
			AudioSample -= (SAMPLE_MAX_RANGE / 2);
			#endif
		#endif

		Pipe_Write_16_LE(AudioSample);
		Pipe_Write_16_LE(AudioSample);

		if (!(Pipe_IsReadWriteAllowed()))
		  Pipe_ClearOUT();
	}

	Pipe_Freeze();
	Pipe_SelectPipe(PrevPipe);
}
开发者ID:hopfgarten,项目名称:jnode-atmega-dual-firmware,代码行数:43,代码来源:AudioOutputHost.c

示例12: ReadNextReport

/** Reads in and processes the next report from the attached device, displaying the report
 *  contents on the board LEDs and via the serial port.
 */
void ReadNextReport(void)
{
	/* Select and unfreeze HID data IN pipe */
	Pipe_SelectPipe(HID_DATA_IN_PIPE);
	Pipe_Unfreeze();

	/* Check to see if a packet has been received */
	if (!(Pipe_IsINReceived()))
	{
		/* Refreeze HID data IN pipe */
		Pipe_Freeze();

		return;
	}

	/* Ensure pipe contains data before trying to read from it */
	if (Pipe_IsReadWriteAllowed())
	{
		uint8_t ReportINData[Pipe_BytesInPipe()];

		/* Read in HID report data */
		Pipe_Read_Stream_LE(&ReportINData, sizeof(ReportINData));

		/* Print report data through the serial port */
		for (uint16_t CurrByte = 0; CurrByte < sizeof(ReportINData); CurrByte++)
		  printf_P(PSTR("0x%02X "), ReportINData[CurrByte]);

		puts_P(PSTR("\r\n"));
	}

	/* Clear the IN endpoint, ready for next data packet */
	Pipe_ClearIN();

	/* Refreeze HID data IN pipe */
	Pipe_Freeze();
}
开发者ID:AmesianX,项目名称:OpenPCR,代码行数:39,代码来源:GenericHIDHost.c

示例13: CDC_Host_Task

/** Task to set the configuration of the attached device after it has been enumerated, and to read in
 *  data received from the attached CDC device and print it to the serial port.
 */
void CDC_Host_Task(void)
{
	uint8_t ErrorCode;

	switch (USB_HostState)
	{
		case HOST_STATE_Addressed:
			puts_P(PSTR("Getting Config Data.\r\n"));
		
			/* Get and process the configuration descriptor data */
			if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
			{
				if (ErrorCode == ControlError)
				  puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));
				else
				  puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));

				printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
				
				/* Indicate error via status LEDs */
				LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

				/* Wait until USB device disconnected */
				USB_HostState = HOST_STATE_WaitForDeviceRemoval;
				break;
			}
			
			/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
			if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
			{
				printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
				                         " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);

				/* Indicate error via status LEDs */
				LEDs_SetAllLEDs(LEDMASK_USB_ERROR);

				/* Wait until USB device disconnected */
				USB_HostState = HOST_STATE_WaitForDeviceRemoval;
				break;
			}

			puts_P(PSTR("CDC Device Enumerated.\r\n"));

			USB_HostState = HOST_STATE_Configured;
			break;
		case HOST_STATE_Configured:
			/* Select and the data IN pipe */
			Pipe_SelectPipe(CDC_DATAPIPE_IN);
			Pipe_Unfreeze();

			/* Check to see if a packet has been received */
			if (Pipe_IsINReceived())
			{
				/* Re-freeze IN pipe after the packet has been received */
				Pipe_Freeze();

				/* Check if data is in the pipe */
				if (Pipe_IsReadWriteAllowed())
				{
					/* Get the length of the pipe data, and create a new buffer to hold it */
					uint16_t BufferLength = Pipe_BytesInPipe();
					uint8_t  Buffer[BufferLength];
					
					/* Read in the pipe data to the temporary buffer */
					Pipe_Read_Stream_LE(Buffer, BufferLength);
									
					/* Print out the buffer contents to the USART */
					for (uint16_t BufferByte = 0; BufferByte < BufferLength; BufferByte++)
					  putchar(Buffer[BufferByte]);
				}

				/* Clear the pipe after it is read, ready for the next packet */
				Pipe_ClearIN();
			}

			/* Re-freeze IN pipe after use */
			Pipe_Freeze();

			/* Select and unfreeze the notification pipe */
			Pipe_SelectPipe(CDC_NOTIFICATIONPIPE);
			Pipe_Unfreeze();
			
			/* Check if a packet has been received */
			if (Pipe_IsINReceived())
			{
				/* Discard the unused event notification */
				Pipe_ClearIN();
			}
			
			/* Freeze notification IN pipe after use */
			Pipe_Freeze();
						
			break;
	}
}
开发者ID:TomMD,项目名称:teensy,代码行数:98,代码来源:CDCHost.c

示例14: KeyboardHost_Task

/** Task to read in and processes the next report from the attached device, displaying the report
 *  contents on the board LEDs and via the serial port.
 */
void KeyboardHost_Task(void)
{
	if (USB_HostState != HOST_STATE_Configured)
	  return;

	/* Select keyboard data pipe */
	Pipe_SelectPipe(KEYBOARD_DATA_IN_PIPE);

	/* Unfreeze keyboard data pipe */
	Pipe_Unfreeze();

	/* Check to see if a packet has been received */
	if (!(Pipe_IsINReceived()))
	{
		/* Refreeze HID data IN pipe */
		Pipe_Freeze();

		return;
	}

	/* Ensure pipe contains data before trying to read from it */
	if (Pipe_IsReadWriteAllowed())
	{
		USB_KeyboardReport_Data_t KeyboardReport;

		/* Read in keyboard report data */
		Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport), NULL);

		/* Indicate if the modifier byte is non-zero (special key such as shift is being pressed) */
		LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0);

		uint8_t KeyCode = KeyboardReport.KeyCode[0];

		/* Check if a key has been pressed */
		if (KeyCode)
		{
			/* Toggle status LED to indicate keypress */
			LEDs_ToggleLEDs(LEDS_LED2);

			char PressedKey = 0;

			/* Retrieve pressed key character if alphanumeric */
			if ((KeyCode >= HID_KEYBOARD_SC_A) && (KeyCode <= HID_KEYBOARD_SC_Z))
			{
				PressedKey = (KeyCode - HID_KEYBOARD_SC_A) + 'A';
			}
			else if ((KeyCode >= HID_KEYBOARD_SC_1_AND_EXCLAMATION) &
					 (KeyCode  < HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS))
			{
				PressedKey = (KeyCode - HID_KEYBOARD_SC_1_AND_EXCLAMATION) + '1';
			}
			else if (KeyCode == HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS)
			{
				PressedKey = '0';
			}
			else if (KeyCode == HID_KEYBOARD_SC_SPACE)
			{
				PressedKey = ' ';
			}
			else if (KeyCode == HID_KEYBOARD_SC_ENTER)
			{
				PressedKey = '\n';
			}

			/* Print the pressed key character out through the serial port if valid */
			if (PressedKey)
			  putchar(PressedKey);
		}
	}

	/* Clear the IN endpoint, ready for next data packet */
	Pipe_ClearIN();

	/* Refreeze keyboard data pipe */
	Pipe_Freeze();
}
开发者ID:chicagoedt,项目名称:Firmware,代码行数:79,代码来源:KeyboardHost.c

示例15: Android_Host_Task


//.........这里部分代码省略.........
			{
				printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
				                         " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);

				/* Indicate error via status LEDs */
				LEDs_SetAllLEDs(LEDS_LED1);

				/* Wait until USB device disconnected */
				USB_HostState = HOST_STATE_WaitForDeviceRemoval;
				break;
			}

			/* Check if a valid Android device was attached, but it is not current in Accessory mode */
			if (RequiresModeSwitch)
			{
				USB_ControlRequest = (USB_Request_Header_t)
				{
					.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
					.bRequest      = ANDROID_Req_StartAccessoryMode,
					.wValue        = 0,
					.wIndex        = 0,
					.wLength       = 0,
				};

				/* Send the control request for the Android device to switch to accessory mode */
				Pipe_SelectPipe(PIPE_CONTROLPIPE);
				USB_Host_SendControlRequest(NULL);

				/* Wait until USB device disconnected */
				USB_HostState = HOST_STATE_WaitForDeviceRemoval;
				break;
			}

			puts_P(PSTR("Getting Config Data.\r\n"));

			/* Get and process the configuration descriptor data */
			if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
			{
				if (ErrorCode == ControlError)
				  puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));
				else
				  puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));

				printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);

				/* Indicate error via status LEDs */
				LEDs_SetAllLEDs(LEDS_LED1);

				/* Wait until USB device disconnected */
				USB_HostState = HOST_STATE_WaitForDeviceRemoval;
				break;
			}

			puts_P(PSTR("Accessory Mode Android Enumerated.\r\n"));

			USB_HostState = HOST_STATE_Configured;
			break;
		case HOST_STATE_Configured:
			/* Select the data IN pipe */
			Pipe_SelectPipe(ANDROID_DATA_IN_PIPE);
			Pipe_Unfreeze();

			/* Check to see if a packet has been received */
			if (Pipe_IsINReceived())
			{
				/* Re-freeze IN pipe after the packet has been received */
				Pipe_Freeze();

				/* Check if data is in the pipe */
				if (Pipe_IsReadWriteAllowed())
				{
					uint8_t NextReceivedByte = Pipe_BytesInPipe();
					uint8_t LEDMask          = LEDS_NO_LEDS;

					if (NextReceivedByte & 0x01)
						LEDMask |= LEDS_LED1;

					if (NextReceivedByte & 0x02)
						LEDMask |= LEDS_LED2;

					if (NextReceivedByte & 0x04)
						LEDMask |= LEDS_LED3;

					if (NextReceivedByte & 0x08)
						LEDMask |= LEDS_LED4;

					LEDs_SetAllLEDs(LEDMask);
				}
				else
				{
					/* Clear the pipe after all data in the packet has been read, ready for the next packet */
					Pipe_ClearIN();
				}
			}

			/* Re-freeze IN pipe after use */
			Pipe_Freeze();
			break;
	}
}
开发者ID:davidk,项目名称:lufa-lib,代码行数:101,代码来源:AndroidAccessoryHost.c


注:本文中的Pipe_IsReadWriteAllowed函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。