• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ Pipe_IsReadWriteAllowed函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Bluetooth_HCITask

void Bluetooth_HCITask(void)
{
	switch (Bluetooth_HCIProcessingState)
	{
		case Bluetooth_ProcessEvents:
			Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);
			Pipe_Unfreeze();
			
			if (Pipe_IsReadWriteAllowed())
			{
				BT_HCIEvent_Header_t HCIEventHeader;

				/* Read in the event header to fetch the event code and payload length */
				Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));
				
				/* Create a temporary buffer for the event parameters */
				uint8_t EventParams[HCIEventHeader.ParameterLength];

				/* Read in the event parameters into the temporary buffer */
				Pipe_Read_Stream_LE(&EventParams, HCIEventHeader.ParameterLength);
				Pipe_ClearIN();

				switch (HCIEventHeader.EventCode)
				{
					case EVENT_COMMAND_COMPLETE:
						Bluetooth_HCIProcessingState = Bluetooth_HCINextState;
						break;
					case EVENT_COMMAND_STATUS:
						/* If the execution of a command failed, reset the stack */
						if (((BT_HCIEvent_CommandStatus_t*)&EventParams)->Status)
						  Bluetooth_HCIProcessingState = Bluetooth_Init;
						break;
					case EVENT_CONNECTION_REQUEST:
						/* Need to store the remote device's BT address in a temporary buffer for later use */
						memcpy(Bluetooth_TempDeviceAddress,
						       &((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->RemoteAddress,
						       sizeof(Bluetooth_TempDeviceAddress));
							   
						bool IsACLConnection = (((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType == 0x01);

						/* Only accept the connection if it is a ACL (data) connection, a device is not already connected
						   and the user application has indicated that the connection should be allowed */
						Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected || !(IsACLConnection) ||
													    !(Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ?
													   Bluetooth_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection;
						break;
					case EVENT_PIN_CODE_REQUEST:
						/* Need to store the remote device's BT address in a temporary buffer for later use */
						memcpy(Bluetooth_TempDeviceAddress,
						       &((BT_HCIEvent_PinCodeReq_t*)&EventParams)->RemoteAddress,
						       sizeof(Bluetooth_TempDeviceAddress));

						Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;
						break;
					case EVENT_CONNECTION_COMPLETE:
						/* Need to store the remote device's BT address in a temporary buffer for later use */
						memcpy(Bluetooth_Connection.RemoteAddress,
						       &((BT_HCIEvent_ConnectionComplete_t*)&EventParams)->RemoteAddress,
						       sizeof(Bluetooth_TempDeviceAddress));

						/* Store the created connection handle and indicate that the connection has been established */
						Bluetooth_Connection.ConnectionHandle = ((BT_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle;
						Bluetooth_Connection.IsConnected      = true;
						
						Bluetooth_ConnectionComplete();						
						break;
					case EVENT_DISCONNECTION_COMPLETE:
						/* Device disconnected, indicate connection information no longer valid */
						Bluetooth_Connection.IsConnected = false;
						
						Bluetooth_DisconnectionComplete();
						
						Bluetooth_HCIProcessingState = Bluetooth_Init;
						break;					
				}
			}
			
			Pipe_Freeze();
			
			break;
		case Bluetooth_Init:
			/* Reset the connection information structure to destroy any previous connection state */
			memset(&Bluetooth_Connection, 0x00, sizeof(Bluetooth_Connection));

			Bluetooth_HCIProcessingState = Bluetooth_Init_Reset; 
			break;
		case Bluetooth_Init_Reset:
			HCICommandHeader = (BT_HCICommand_Header_t)
			{
				OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_RESET},
				ParameterLength: 0,
			};

			/* Send the command to reset the bluetooth dongle controller */
			Bluetooth_SendHCICommand(NULL, 0);
			
			Bluetooth_HCINextState       = Bluetooth_Init_SetLocalName;
			Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;
			break;
		case Bluetooth_Init_SetLocalName:
//.........这里部分代码省略.........
开发者ID:ivarho,项目名称:lufa-lib,代码行数:101,代码来源:BluetoothHCICommands.c


示例17: Bluetooth_HCITask

/** Bluetooth HCI processing task. This task should be called repeatedly the main Bluetooth
 *  stack task to manage the HCI processing state.
 */
void Bluetooth_HCITask(void)
{
	BT_HCICommand_Header_t HCICommandHeader;

	switch (Bluetooth_State.CurrentHCIState)
	{
		case Bluetooth_ProcessEvents:
			Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);
			Pipe_Unfreeze();

			if (Pipe_IsReadWriteAllowed())
			{
				BT_HCIEvent_Header_t HCIEventHeader;

				/* Read in the event header to fetch the event code and payload length */
				Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));

				/* Create a temporary buffer for the event parameters */
				uint8_t EventParams[HCIEventHeader.ParameterLength];

				/* Read in the event parameters into the temporary buffer */
				Pipe_Read_Stream_LE(&EventParams, HCIEventHeader.ParameterLength);
				Pipe_ClearIN();

				BT_HCI_DEBUG(1, "Event Received (0x%02X)", HCIEventHeader.EventCode);

				switch (HCIEventHeader.EventCode)
				{
					case EVENT_COMMAND_COMPLETE:
						BT_HCI_DEBUG(1, "<< Command Complete");

						/* Check which operation was completed in case we need to process the even parameters */
						switch (((BT_HCIEvent_CommandComplete_t*)&EventParams)->Opcode)
						{
							case (OGF_CTRLR_INFORMATIONAL | OCF_CTRLR_INFORMATIONAL_READBDADDR):
								/* A READ BDADDR command completed, copy over the local device's BDADDR from the response */
								memcpy(Bluetooth_State.LocalBDADDR,
								       &((BT_HCIEvent_CommandComplete_t*)&EventParams)->ReturnParams[1],
								       sizeof(Bluetooth_State.LocalBDADDR));
								break;
						}

						Bluetooth_State.CurrentHCIState = Bluetooth_State.NextHCIState;
						break;
					case EVENT_COMMAND_STATUS:
						BT_HCI_DEBUG(1, "<< Command Status");
						BT_HCI_DEBUG(2, "-- Status Code: 0x%02X", (((BT_HCIEvent_CommandStatus_t*)&EventParams)->Status));

						/* If the execution of a command failed, reset the stack */
						if (((BT_HCIEvent_CommandStatus_t*)&EventParams)->Status)
						  Bluetooth_State.CurrentHCIState = Bluetooth_Init;
						break;
					case EVENT_CONNECTION_REQUEST:
						BT_HCI_DEBUG(1, "<< Connection Request");
						BT_HCI_DEBUG(2, "-- Link Type: 0x%02X", (((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType));

						/* Need to store the remote device's BT address in a temporary buffer for later use */
						memcpy(Bluetooth_TempDeviceAddress,
						       &((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->RemoteAddress,
						       sizeof(Bluetooth_TempDeviceAddress));

						bool IsACLConnection = (((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType == 0x01);

						/* Only accept the connection if it is a ACL (data) connection, a device is not already connected
						   and the user application has indicated that the connection should be allowed */
						Bluetooth_State.CurrentHCIState = (Bluetooth_Connection.IsConnected || !(IsACLConnection) ||
													      !(Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ?
													      Bluetooth_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection;

						BT_HCI_DEBUG(2, "-- Connection %S", (Bluetooth_State.CurrentHCIState == Bluetooth_Conn_RejectConnection) ?
						                                     PSTR("REJECTED") : PSTR("ACCEPTED"));

						break;
					case EVENT_PIN_CODE_REQUEST:
						BT_HCI_DEBUG(1, "<< Pin Code Request");

						/* Need to store the remote device's BT address in a temporary buffer for later use */
						memcpy(Bluetooth_TempDeviceAddress,
						       &((BT_HCIEvent_PinCodeReq_t*)&EventParams)->RemoteAddress,
						       sizeof(Bluetooth_TempDeviceAddress));

						Bluetooth_State.CurrentHCIState = Bluetooth_Conn_SendPINCode;
						break;
					case EVENT_LINK_KEY_REQUEST:
						BT_HCI_DEBUG(1, "<< Link Key Request");

						/* Need to store the remote device's BT address in a temporary buffer for later use */
						memcpy(Bluetooth_TempDeviceAddress,
						       &((BT_HCIEvent_LinkKeyReq_t*)&EventParams)->RemoteAddress,
						       sizeof(Bluetooth_TempDeviceAddress));

						Bluetooth_State.CurrentHCIState = Bluetooth_Conn_SendLinkKeyNAK;
						break;
					case EVENT_CONNECTION_COMPLETE:
						BT_HCI_DEBUG(1, "<< Connection Complete");
						BT_HCI_DEBUG(2, "-- Handle: 0x%04X", ((BT_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle);

//.........这里部分代码省略.........
开发者ID:Dzenik,项目名称:RF-Pirate,代码行数:101,代码来源:BluetoothHCICommands.c


示例18: SImage_Host_ReceiveBlockHeader

static uint8_t SImage_Host_ReceiveBlockHeader(USB_ClassInfo_SI_Host_t* const SIInterfaceInfo, SI_PIMA_Container_t* const PIMAHeader)
{
	uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS;

	Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);
	Pipe_Unfreeze();
	
	while (!(Pipe_IsReadWriteAllowed()))
	{
		if (USB_INT_HasOccurred(USB_INT_HSOFI))
		{
			USB_INT_Clear(USB_INT_HSOFI);
			TimeoutMSRem--;

			if (!(TimeoutMSRem))
			{
				return PIPE_RWSTREAM_Timeout;
			}
		}
		
		Pipe_Freeze();
		Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);
		Pipe_Unfreeze();

		if (Pipe_IsStalled())
		{
			USB_Host_ClearPipeStall(SIInterfaceInfo->Config.DataOUTPipeNumber);
			return PIPE_RWSTREAM_PipeStalled;
		}

		Pipe_Freeze();
		Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);
		Pipe_Unfreeze();

		if (Pipe_IsStalled())
		{
			USB_Host_ClearPipeStall(SIInterfaceInfo->Config.DataINPipeNumber);
			return PIPE_RWSTREAM_PipeStalled;
		}
		  
		if (USB_HostState == HOST_STATE_Unattached)
		  return PIPE_RWSTREAM_DeviceDisconnected;
	}
	
	Pipe_Read_Stream_LE(PIMAHeader, PIMA_COMMAND_SIZE(0), NO_STREAM_CALLBACK);
	
	if (PIMAHeader->Type == CType_ResponseBlock)
	{
		uint8_t ParamBytes = (PIMAHeader->DataLength - PIMA_COMMAND_SIZE(0));

		if (ParamBytes)
		  Pipe_Read_Stream_LE(&PIMAHeader->Params, ParamBytes, NO_STREAM_CALLBACK);
		
		Pipe_ClearIN();
		
		PIMAHeader->Code &= 0x0000000F;
	}
	
	Pipe_Freeze();
	
	return PIPE_RWSTREAM_NoError;
}
开发者ID:andrew-taylor,项目名称:bowerbird-avr,代码行数:62,代码来源:StillImage.c


示例19: AOA_Host_StartAccessoryMode


//.........这里部分代码省略.........
	Pipe_Freeze();

	return ErrorCode;
}

uint8_t AOA_Host_SendString(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
                            const char* const String)
{
	if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
	  return PIPE_READYWAIT_DeviceDisconnected;

	uint8_t ErrorCode;

	Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipeNumber);

	Pipe_Unfreeze();
	ErrorCode = Pipe_Write_Stream_LE(String, strlen(String), NULL);
	Pipe_Freeze();

	return ErrorCode;
}

uint8_t AOA_Host_SendByte(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo,
                          const uint8_t Data)
{
	if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
	  return PIPE_READYWAIT_DeviceDisconnected;

	uint8_t ErrorCode;

	Pipe_SelectPipe(AOAInterfaceInfo->Config.DataOUTPipeNumber);
	Pipe_Unfreeze();

	if (!(Pipe_IsReadWriteAllowed()))
	{
		Pipe_ClearOUT();

		if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError)
		  return ErrorCode;
	}

	Pipe_Write_8(Data);
	Pipe_Freeze();

	return PIPE_READYWAIT_NoError;
}

uint16_t AOA_Host_BytesReceived(USB_ClassInfo_AOA_Host_t* const AOAInterfaceInfo)
{
	if ((USB_HostState != HOST_STATE_Configured) || !(AOAInterfaceInfo->State.IsActive))
	  return 0;

	Pipe_SelectPipe(AOAInterfaceInfo->Config.DataINPipeNumber);
	Pipe_Unfreeze();

	if (Pipe_IsINReceived())
	{
		if (!(Pipe_BytesInPipe()))
		{
			Pipe_ClearIN();
			Pipe_Freeze();
			return 0;
		}
		else
		{
			Pipe_Freeze();
开发者ID:AdjacentReality,项目名称:lufa-lib,代码行数:67,代码来源:AndroidAccessoryClassHost.c


示例20: Bluetooth_ProcessIncomingACLPackets

/** Incoming ACL packet processing task. This task is called by the main ACL processing task to read in and process
 *  any incoming ACL packets to the device, handling signal requests as they are received or passing along channel
 *  data to the user application.
 */
static void Bluetooth_ProcessIncomingACLPackets(void)
{
	BT_ACL_Header_t        ACLPacketHeader;
	BT_DataPacket_Header_t DataHeader;

	Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);
	Pipe_Unfreeze();

	if (!(Pipe_IsReadWriteAllowed()))
	{
		Pipe_Freeze();
		return;
	}

	/* Read in the received ACL packet headers when it has been discovered that a packet has been received */
	Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
	Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));

	BT_ACL_DEBUG(2, "");
	BT_ACL_DEBUG(2, "Packet Received");
	BT_ACL_DEBUG(2, "-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF));
	BT_ACL_DEBUG(2, "-- Data Length: 0x%04X", ACLPacketHeader.DataLength);
	BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", DataHeader.DestinationChannel);
	BT_ACL_DEBUG(2, "-- Payload Length: 0x%04X", DataHeader.PayloadLength);

	/* Check the packet's destination channel - signaling channel should be processed by the stack internally */
	if (DataHeader.DestinationChannel == BT_CHANNEL_SIGNALING)
	{
		/* Read in the Signal Command header of the incoming packet */
		BT_Signal_Header_t SignalCommandHeader;
		Pipe_Read_Stream_LE(&SignalCommandHeader, sizeof(SignalCommandHeader));

		/* Dispatch to the appropriate handler function based on the Signal message code */
		switch (SignalCommandHeader.Code)
		{
			case BT_SIGNAL_CONNECTION_REQUEST:
				Bluetooth_Signal_ConnectionReq(&SignalCommandHeader);
				break;
			case BT_SIGNAL_CONNECTION_RESPONSE:
				Bluetooth_Signal_ConnectionResp(&SignalCommandHeader);
				break;
			case BT_SIGNAL_CONFIGURATION_REQUEST:
				Bluetooth_Signal_ConfigurationReq(&SignalCommandHeader);
				break;
			case BT_SIGNAL_CONFIGURATION_RESPONSE:
				Bluetooth_Signal_ConfigurationResp(&SignalCommandHeader);
				break;
			case BT_SIGNAL_DISCONNECTION_REQUEST:
				Bluetooth_Signal_DisconnectionReq(&SignalCommandHeader);
				break;
			case BT_SIGNAL_DISCONNECTION_RESPONSE:
				Bluetooth_Signal_DisconnectionResp(&SignalCommandHeader);
				break;
			case BT_SIGNAL_ECHO_REQUEST:
				Bluetooth_Signal_EchoReq(&SignalCommandHeader);
				break;
			case BT_SIGNAL_INFORMATION_REQUEST:
				Bluetooth_Signal_InformationReq(&SignalCommandHeader);
				break;
			case BT_SIGNAL_COMMAND_REJECT:
				BT_ACL_DEBUG(1, "<< Command Reject");

				uint16_t RejectReason;
				Pipe_Read_Stream_LE(&RejectReason, sizeof(RejectReason));
				Pipe_Discard_Stream(ACLPacketHeader.DataLength - sizeof(RejectReason));
				Pipe_ClearIN();
				Pipe_Freeze();

				BT_ACL_DEBUG(2, "-- Reason: %d", RejectReason);
				break;
			default:
				BT_ACL_DEBUG(1, "<< Unknown Signaling Command 0x%02X", SignalCommandHeader.Code);

				Pipe_Discard_Stream(ACLPacketHeader.DataLength);
				Pipe_ClearIN();
				Pipe_Freeze();
				break;
		}
	}
	else
	{
		/* Non-signaling packet received, read in the packet contents and pass to the user application */
		uint8_t PacketData[DataHeader.PayloadLength];
		Pipe_Read_Stream_LE(PacketData, DataHeader.PayloadLength);
		Pipe_ClearIN();
		Pipe_Freeze();

		Bluetooth_PacketReceived(PacketData, DataHeader.PayloadLength,
		                         Bluetooth_GetChannelData(DataHeader.DestinationChannel, CHANNEL_SEARCH_LOCALNUMBER));
	}
}
开发者ID:Dzenik,项目名称:RF-Pirate,代码行数:95,代码来源:Blu

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Pipe_Read_Stream_LE函数代码示例发布时间:2022-05-30
下一篇:
C++ Pipe_IsINReceived函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap