要在objective-c中设置USB请求类型,我使用:#define USBmakebmRequestType
例如:
IOUSBDevRequest request;
request.bmRequestType = USBmakebmRequestType(kUSBOut, kUSBVendor, kUSBDevice);
我如何快速使用它? swift 中没有功能 USBmakebmRequestType
最佳答案
我自己实现了:
func USBmakebmRequestType(direction:Int, type:Int, recipient:Int) -> UInt8 {
return UInt8((direction & kUSBRqDirnMask) << kUSBRqDirnShift)|UInt8((type & kUSBRqTypeMask) << kUSBRqTypeShift)|UInt8(recipient & kUSBRqRecipientMask)
}
用法:
USBmakebmRequestType(direction: kUSBIn, type: kUSBDevice, recipient: kUSBStandard)