本文整理汇总了C++中USB_Host_SendControlRequest函数的典型用法代码示例。如果您正苦于以下问题:C++ USB_Host_SendControlRequest函数的具体用法?C++ USB_Host_SendControlRequest怎么用?C++ USB_Host_SendControlRequest使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USB_Host_SendControlRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Bluetooth_SendHCICommand
static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength)
{
/* Need to reserve the amount of bytes given in the header for the complete payload */
uint8_t CommandBuffer[sizeof(HCICommandHeader) + HCICommandHeader.ParameterLength];
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),
.bRequest = 0,
.wValue = 0,
.wIndex = 0,
.wLength = sizeof(CommandBuffer)
};
/* Copy over the HCI command header to the allocated buffer */
memcpy(CommandBuffer, &HCICommandHeader, sizeof(HCICommandHeader));
/* Zero out the parameter section of the response to ensure that any padding bytes do not expose private RAM contents */
memset(&CommandBuffer[sizeof(HCICommandHeader)], 0x00, HCICommandHeader.ParameterLength);
/* Copy over the command parameters (if any) to the command buffer - note, the number of actual source parameter bytes
may differ to those in the header; any difference in length is filled with 0x00 padding bytes */
memcpy(&CommandBuffer[sizeof(HCICommandHeader)], Parameters, ParameterLength);
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(CommandBuffer);
}
示例2: Bluetooth_SendHCICommand
static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint8_t ParamLength)
{
uint8_t CommandBuffer[sizeof(HCICommandHeader) + HCICommandHeader.ParameterLength];
USB_HostRequest = (USB_Host_Request_Header_t)
{
bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),
bRequest: 0,
wValue: 0,
wIndex: 0,
wLength: sizeof(CommandBuffer)
};
memset(CommandBuffer, 0x00, sizeof(CommandBuffer));
memcpy(CommandBuffer, &HCICommandHeader, sizeof(HCICommandHeader));
if (ParamLength)
memcpy(&CommandBuffer[sizeof(HCICommandHeader)], Parameters, ParamLength);
return USB_Host_SendControlRequest(CommandBuffer);
}
static bool Bluetooth_GetNextHCIEventHeader(void)
{
Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);
Pipe_Unfreeze();
if (!(Pipe_ReadWriteAllowed()))
return false;
Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));
return true;
}
示例3: Audio_Host_GetSetEndpointProperty
uint8_t Audio_Host_GetSetEndpointProperty(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
const uint8_t DataPipeIndex,
const uint8_t EndpointProperty,
const uint8_t EndpointControl,
const uint16_t DataLength,
void* const Data)
{
if (!(AudioInterfaceInfo->State.IsActive))
return HOST_SENDCONTROL_DeviceDisconnected;
uint8_t RequestType;
uint8_t EndpointAddress;
if (EndpointProperty & 0x80)
RequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT);
else
RequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT);
Pipe_SelectPipe(DataPipeIndex);
EndpointAddress = Pipe_GetBoundEndpointAddress();
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = RequestType,
.bRequest = EndpointProperty,
.wValue = ((uint16_t)EndpointControl << 8),
.wIndex = EndpointAddress,
.wLength = DataLength,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(Data);
}
示例4: WriteNextReport
/** Writes a report to the attached device.
*
* \param[in] ReportOUTData Buffer containing the report to send to the device
* \param[in] ReportLength Length of the report to send
*/
void WriteNextReport(uint8_t* const ReportOUTData,
const uint16_t ReportLength)
{
if (USB_HostState != HOST_STATE_Configured)
return;
/* Select and unfreeze HID data OUT pipe */
Pipe_SelectPipe(HID_DATA_OUT_PIPE);
/* Not all HID devices have an OUT endpoint (some require OUT reports to be sent over the
* control endpoint instead) - check to see if the OUT endpoint has been initialized */
if (Pipe_IsConfigured())
{
Pipe_Unfreeze();
/* Ensure pipe is ready to be written to before continuing */
if (!(Pipe_IsOUTReady()))
{
/* Refreeze the data OUT pipe */
Pipe_Freeze();
return;
}
/* Write out HID report data */
Pipe_Write_Stream_LE(ReportOUTData, ReportLength, NULL);
/* Clear the OUT endpoint, send last data packet */
Pipe_ClearOUT();
/* Refreeze the data OUT pipe */
Pipe_Freeze();
}
else
{
/* Class specific request to send a HID report to the device */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = HID_REQ_SetReport,
.wValue = 0x02,
.wIndex = 0x01,
.wLength = ReportLength,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send the request to the device */
USB_Host_SendControlRequest(ReportOUTData);
}
}
示例5: GetHIDReportData
/** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read
* structures via the HID parser routines in the LUFA library.
*
* \return A value from the \ref KeyboardHostWithParser_GetHIDReportDataCodes_t enum
*/
uint8_t GetHIDReportData(void)
{
/* Create a buffer big enough to hold the entire returned HID report */
uint8_t HIDReportData[HIDReportSize];
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_GetDescriptor,
.wValue = (HID_DTYPE_Report << 8),
.wIndex = 0,
.wLength = HIDReportSize,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send control request to retrieve the HID report from the attached device */
if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)
return ParseControlError;
/* Send the HID report to the parser for processing */
if (USB_ProcessHIDReport(HIDReportData, HIDReportSize, &HIDReportInfo) != HID_PARSE_Successful)
return ParseError;
return ParseSuccessful;
}
/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
* an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
* we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
* have occupied).
*
* \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
*
* \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded
*/
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem)
{
/* Check the attributes of the current item - see if we are interested in it or not;
* only store KEYBOARD usage page items into the Processed HID Report structure to
* save RAM and ignore the rest
*/
return (CurrentItem->Attributes.Usage.Page == USAGE_PAGE_KEYBOARD);
}
示例6: CALLBACK_Bluetooth_SendPacket
void CALLBACK_Bluetooth_SendPacket(BT_StackConfig_t* const StackState,
const uint8_t Type,
const uint16_t Length)
{
/* Determine the type of packet being sent, use appropriate pipe */
switch (Type)
{
case BLUETOOTH_PACKET_HCICommand:
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),
.bRequest = 0,
.wValue = 0,
.wIndex = 0,
.wLength = Length
};
/* HCI commands must be sent over the Control pipe */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
USB_Host_SendControlRequest(StackState->Config.PacketBuffer);
break;
case BLUETOOTH_PACKET_HCIData:
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
/* HCI data packets must be sent over the Data OUT pipe */
Pipe_Unfreeze();
Pipe_Write_Stream_LE(StackState->Config.PacketBuffer, Length, NULL);
Pipe_ClearOUT();
Pipe_Freeze();
break;
}
// RGB_SetColour(RGB_ALIAS_Connected);
}
void EVENT_Bluetooth_InitComplete(BT_StackConfig_t* const StackState)
{
/* Save the local BDADDR of the connected Bluetooth adapter for later use */
// eeprom_update_block(BluetoothAdapter_Stack.State.HCI.LocalBDADDR, BluetoothAdapter_LastLocalBDADDR, sizeof(BDADDR_t));
}
示例7: PRNT_Host_SetBidirectionalMode
uint8_t PRNT_Host_SetBidirectionalMode(USB_ClassInfo_PRNT_Host_t* const PRNTInterfaceInfo)
{
if (PRNTInterfaceInfo->State.AlternateSetting)
{
uint8_t ErrorCode;
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_SetInterface,
.wValue = PRNTInterfaceInfo->State.AlternateSetting,
.wIndex = PRNTInterfaceInfo->State.InterfaceNumber,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
}
return HOST_SENDCONTROL_Successful;
}
示例8: GetHIDReportData
/** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read
* structures via the HID parser routines in the LUFA library.
*
* \return A value from the MouseHostWithParser_GetHIDReportDataCodes_t enum
*/
uint8_t GetHIDReportData(void)
{
/* Create a buffer big enough to hold the entire returned HID report */
uint8_t HIDReportData[HIDReportSize];
USB_HostRequest = (USB_Host_Request_Header_t)
{
bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
bRequest: REQ_GetDescriptor,
wValue: (DTYPE_Report << 8),
wIndex: 0,
wLength: HIDReportSize,
};
/* Send control request to retrieve the HID report from the attached device */
if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)
return ParseControlError;
/* Send the HID report to the parser for processing */
if (ProcessHIDReport(HIDReportData, HIDReportSize, &HIDReportInfo) != HID_PARSE_Successful)
return ParseError;
return ParseSuccessful;
}
示例9: USB_Host_GetDeviceConfigDescriptor
uint8_t USB_Host_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr,
void* BufferPtr, uint16_t BufferSize)
{
uint8_t ErrorCode;
uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),
.wIndex = 0,
.wLength = sizeof(USB_Descriptor_Configuration_Header_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
if ((ErrorCode = USB_Host_SendControlRequest(ConfigHeader)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
*ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).TotalConfigurationSize;
if (*ConfigSizePtr > BufferSize)
return HOST_GETCONFIG_BuffOverflow;
USB_ControlRequest.wLength = *ConfigSizePtr;
if ((ErrorCode = USB_Host_SendControlRequest(BufferPtr)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)
return HOST_GETCONFIG_InvalidData;
return HOST_GETCONFIG_Successful;
}
#endif
void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type)
{
while (*BytesRem)
{
USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
return;
}
}
void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type,
const uint8_t BeforeType)
{
while (*BytesRem)
{
USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
{
return;
}
else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)
{
*BytesRem = 0;
return;
}
}
}
void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type,
const uint8_t AfterType)
{
USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);
if (*BytesRem)
USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);
}
示例10: USB_Printer_Host
/** Task to set the configuration of the attached device after it has been enumerated, and to send some test page
* data to the attached printer.
*/
void USB_Printer_Host(void)
{
uint8_t ErrorCode;
switch (USB_HostState)
{
case HOST_STATE_Addressed:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* 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"), 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;
}
/* Some printers use alternate settings to determine the communication protocol used - if so, send a SetInterface
* request to switch to the interface alternate setting with the Bidirectional protocol */
if (PrinterAltSetting)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_SetInterface,
.wValue = PrinterAltSetting,
.wIndex = PrinterInterfaceNumber,
.wLength = 0,
};
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
{
printf_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\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("Retrieving Device ID...\r\n"));
char DeviceIDString[300];
if ((ErrorCode = Printer_GetDeviceID(DeviceIDString, sizeof(DeviceIDString))) != HOST_SENDCONTROL_Successful)
{
printf_P(PSTR(ESC_FG_RED "Control Error (Get Device ID).\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;
}
printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString);
puts_P(PSTR("Printer Enumerated.\r\n"));
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
/* Indicate device busy via the status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
//.........这里部分代码省略.........
示例11: GetHIDReportData
/** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read
* structures via the HID parser routines in the LUFA library.
*
* \return A value from the \ref MouseHostWithParser_GetHIDReportDataCodes_t enum
*/
uint8_t GetHIDReportData(void)
{
/* Create a buffer big enough to hold the entire returned HID report */
uint8_t HIDReportData[HIDReportSize];
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_GetDescriptor,
.wValue = (HID_DTYPE_Report << 8),
.wIndex = 0,
.wLength = HIDReportSize,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send control request to retrieve the HID report from the attached device */
if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)
return ParseControlError;
/* Send the HID report to the parser for processing */
if (USB_ProcessHIDReport(HIDReportData, HIDReportSize, &HIDReportInfo) != HID_PARSE_Successful)
return ParseError;
return ParseSuccessful;
}
/** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store
* an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items
* we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would
* have occupied).
*
* \param[in] CurrentItem Pointer to the item the HID report parser is currently working with
*
* \return Boolean true if the item should be stored into the HID report structure, false if it should be discarded
*/
bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem)
{
bool IsMouse = false;
/* Iterate through the item's collection path, until either the root collection node or a collection with the
* Mouse Usage is found - this prevents Joysticks, which use identical descriptors except for the Joystick usage
* parent node, from being erroneously treated as a mouse
*/
for (HID_CollectionPath_t* CurrPath = CurrentItem->CollectionPath; CurrPath != NULL; CurrPath = CurrPath->Parent)
{
if ((CurrPath->Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&
(CurrPath->Usage.Usage == USAGE_MOUSE))
{
IsMouse = true;
break;
}
}
/* If a collection with the mouse usage was not found, indicate that we are not interested in this item */
if (!IsMouse)
return false;
/* Check the attributes of the current mouse item - see if we are interested in it or not;
* only store BUTTON and GENERIC_DESKTOP_CONTROL items into the Processed HID Report
* structure to save RAM and ignore the rest
*/
return ((CurrentItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) ||
(CurrentItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL));
}
示例12: Printer_GetDeviceID
/** Issues a Printer class Get Device ID command to the attached device, to retrieve the device ID string (which indicates
* the accepted printer languages, the printer's model and other pertinent information).
*
* \param[out] DeviceIDString Pointer to the destination where the returned string should be stored
* \param[in] BufferSize Size in bytes of the allocated buffer for the returned Device ID string
*
* \return A value from the USB_Host_SendControlErrorCodes_t enum
*/
uint8_t Printer_GetDeviceID(char* DeviceIDString,
const uint16_t BufferSize)
{
uint8_t ErrorCode;
uint16_t DeviceIDStringLength = 0;
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = PRNT_REQ_GetDeviceID,
.wValue = 0,
.wIndex = PrinterInterfaceNumber,
.wLength = sizeof(DeviceIDStringLength),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
if ((ErrorCode = USB_Host_SendControlRequest(&DeviceIDStringLength)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
if (!(DeviceIDStringLength))
{
DeviceIDString[0] = 0x00;
return HOST_SENDCONTROL_Successful;
}
DeviceIDStringLength = SwapEndian_16(DeviceIDStringLength);
if (DeviceIDStringLength > BufferSize)
DeviceIDStringLength = BufferSize;
USB_ControlRequest.wLength = DeviceIDStringLength;
if ((ErrorCode = USB_Host_SendControlRequest(DeviceIDString)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
/* Move string back two characters to remove the string length value from the start of the array */
memmove(&DeviceIDString[0], &DeviceIDString[2], DeviceIDStringLength - 2);
DeviceIDString[DeviceIDStringLength - 2] = 0x00;
return HOST_SENDCONTROL_Successful;
}
/** Issues a Printer class Get Port Status command to the attached device, to retrieve the current status flags of the
* printer.
*
* \param[out] PortStatus Pointer to the destination where the printer's status flag values should be stored
*
* \return A value from the USB_Host_SendControlErrorCodes_t enum
*/
uint8_t Printer_GetPortStatus(uint8_t* const PortStatus)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = PRNT_REQ_GetPortStatus,
.wValue = 0,
.wIndex = PrinterInterfaceNumber,
.wLength = sizeof(uint8_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(PortStatus);
}
/** Issues a Printer class Soft Reset command to the attached device, to reset the printer ready for new input without
* physically cycling the printer's power.
*
* \return A value from the USB_Host_SendControlErrorCodes_t enum
*/
uint8_t Printer_SoftReset(void)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = PRNT_REQ_SoftReset,
.wValue = 0,
.wIndex = PrinterInterfaceNumber,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
示例13: WriteNextReport
/** Writes a report to the attached device.
*
* \param[in] ReportOUTData Buffer containing the report to send to the device
* \param[in] ReportIndex Index of the report in the device (zero if the device does not use multiple reports)
* \param[in] ReportType Type of report to send, either REPORT_TYPE_OUT or REPORT_TYPE_FEATURE
* \param[in] ReportLength Length of the report to send
*/
void WriteNextReport(uint8_t* ReportOUTData,
const uint8_t ReportIndex,
const uint8_t ReportType,
uint16_t ReportLength)
{
/* Select the HID data OUT pipe */
Pipe_SelectPipe(HID_DATA_OUT_PIPE);
/* Not all HID devices have an OUT endpoint (some require OUT reports to be sent over the
* control endpoint instead) - check to see if the OUT endpoint has been initialized */
if (Pipe_IsConfigured() && (ReportType == REPORT_TYPE_OUT))
{
Pipe_Unfreeze();
/* Ensure pipe is ready to be written to before continuing */
if (!(Pipe_IsOUTReady()))
{
/* Refreeze the data OUT pipe */
Pipe_Freeze();
return;
}
/* If the report index is used, send it before the report data */
if (ReportIndex)
Pipe_Write_Byte(ReportIndex);
/* Write out HID report data */
Pipe_Write_Stream_LE(ReportOUTData, ReportLength);
/* Clear the OUT endpoint, send last data packet */
Pipe_ClearOUT();
/* Refreeze the data OUT pipe */
Pipe_Freeze();
}
else
{
/* Class specific request to send a HID report to the device */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = HID_REQ_SetReport,
.wValue = ((ReportType << 8) | ReportIndex),
.wIndex = 0,
.wLength = ReportLength,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send the request to the device */
USB_Host_SendControlRequest(ReportOUTData);
}
}
/** Task to set the configuration of the attached device after it has been enumerated, and to read and process
* HID reports from the device and to send reports if desired.
*/
void HID_Host_Task(void)
{
uint8_t ErrorCode;
/* Switch to determine what user-application handled host state the host state machine is in */
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 status */
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);
//.........这里部分代码省略.........
示例14: Keyboard_HID_Task
/** Task to set the configuration of the attached device after it has been enumerated, and to read and process
* HID reports from the device and display the results onto the board LEDs.
*/
void Keyboard_HID_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 status */
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 status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
/* HID class request to set the keyboard protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = REQ_SetProtocol,
.wValue = 0,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
{
printf_P(PSTR(ESC_FG_RED "Control Error (Set Protocol).\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
puts_P(PSTR("Keyboard Enumerated.\r\n"));
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
/* If a report has been received, read and process it */
ReadNextReport();
break;
}
}
示例15: USB_Host_SetDeviceConfiguration
uint8_t USB_Host_SetDeviceConfiguration(const uint8_t corenum, const uint8_t ConfigNumber)
{
uint8_t ErrorCode;
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = ConfigNumber,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(corenum, PIPE_CONTROLPIPE);
if ((ErrorCode = USB_Host_SendControlRequest(corenum, NULL)) == HOST_SENDCONTROL_Successful)
{
USB_Host_ConfigurationNumber = ConfigNumber;
USB_HostState[corenum] = (ConfigNumber) ? HOST_STATE_Configured : HOST_STATE_Addressed;
}
return ErrorCode;
}
uint8_t USB_Host_GetDeviceDescriptor(const uint8_t corenum, void* const DeviceDescriptorPtr)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = (DTYPE_Device << 8),
.wIndex = 0,
.wLength = sizeof(USB_Descriptor_Device_t),
};
Pipe_SelectPipe(corenum, PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(corenum,DeviceDescriptorPtr);
}
uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t corenum,
const uint8_t Index,
void* const Buffer,
const uint8_t BufferLength)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = (DTYPE_String << 8) | Index,
.wIndex = 0,
.wLength = BufferLength,
};
Pipe_SelectPipe(corenum, PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(corenum,Buffer);
}
uint8_t USB_Host_GetDeviceStatus(const uint8_t corenum, uint8_t* const FeatureStatus)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetStatus,
.wValue = 0,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(corenum, PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(corenum, FeatureStatus);
}
uint8_t USB_Host_ClearEndpointStall(const uint8_t corenum, const uint8_t EndpointAddress)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
.bRequest = REQ_ClearFeature,
.wValue = FEATURE_SEL_EndpointHalt,
.wIndex = EndpointAddress,
.wLength = 0,
};
Pipe_SelectPipe(corenum, PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(corenum,NULL);
}
uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t corenum,
const uint8_t InterfaceIndex,
const uint8_t AltSetting)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_SetInterface,
.wValue = AltSetting,
//.........这里部分代码省略.........