-
Notifications
You must be signed in to change notification settings - Fork 31
/
setupdata.go
78 lines (63 loc) · 2.22 KB
/
setupdata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2015-2023 The libusb developers. All rights reserved.
// Project site: https://github.com/gotmc/libusb
// Use of this source code is governed by a MIT-style license that
// can be found in the LICENSE.txt file for the project.
package libusb
// #cgo pkg-config: libusb-1.0
// #include <libusb.h>
import "C"
type transferDirection byte
// Constants to set the transfer direction.
const (
HostToDevice transferDirection = 0x00
DeviceToHost transferDirection = 0x80
)
var transferDirections = map[transferDirection]string{
HostToDevice: "Host-to-device",
DeviceToHost: "Device-to-host",
}
// String implements the Stringer interface for endpointDirection.
func (dir transferDirection) String() string {
return transferDirections[dir]
}
type requestType byte
// Constants representing the libusb request types.
const (
Standard requestType = C.LIBUSB_REQUEST_TYPE_STANDARD
Class requestType = C.LIBUSB_REQUEST_TYPE_CLASS
Vendor requestType = C.LIBUSB_REQUEST_TYPE_VENDOR
Reserved requestType = C.LIBUSB_REQUEST_TYPE_RESERVED
)
var requestTypes = map[requestType]string{
Standard: "Standard",
Class: "Class",
Vendor: "Vendor",
Reserved: "Reserved",
}
func (rt requestType) String() string {
return requestTypes[rt]
}
type requestRecipient byte
// Constants representing the libusb recipient types.
const (
DeviceRecipient requestRecipient = C.LIBUSB_RECIPIENT_DEVICE
InterfaceRecipient requestRecipient = C.LIBUSB_RECIPIENT_INTERFACE
EndpointRecipient requestRecipient = C.LIBUSB_RECIPIENT_ENDPOINT
OtherRecipient requestRecipient = C.LIBUSB_RECIPIENT_OTHER
)
var requestRecipients = map[requestRecipient]string{
DeviceRecipient: "Device",
InterfaceRecipient: "Interface",
EndpointRecipient: "Endpoint",
OtherRecipient: "Other",
}
func (r requestRecipient) String() string {
return requestRecipients[r]
}
// bitmapRequestType returns the Request type. Bits 0:4 determine recipient,
// see libusb_request_recipient. Bits 5:6 determine type, see
// libusb_request_type. Bit 7 determines data transfer direction, see
// libusb_endpoint_direction.
func bitmapRequestType(dir transferDirection, reqType requestType, recipient requestRecipient) byte {
return byte(dir) | byte(reqType) | byte(recipient)
}