aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/usb/descriptor.go
blob: d57d0bd8a9b4f9cc766679d92d2d5cade590f49f (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package usb

import "runtime/volatile"

// DeviceDescBank is the USB device endpoint descriptor.
type DeviceDescBank struct {
	ADDR      volatile.Register32
	PCKSIZE   volatile.Register32
	EXTREG    volatile.Register16
	STATUS_BK volatile.Register8
	_reserved [5]volatile.Register8
}

type DeviceDescriptor struct {
	DeviceDescBank [2]DeviceDescBank
}

type Descriptor struct {
	Device        []byte
	Configuration []byte
	HID           map[uint16][]byte
}

func (d *Descriptor) Configure(idVendor, idProduct uint16) {
	d.Device[8] = byte(idVendor)
	d.Device[9] = byte(idVendor >> 8)
	d.Device[10] = byte(idProduct)
	d.Device[11] = byte(idProduct >> 8)

	d.Configuration[2] = byte(len(d.Configuration))
	d.Configuration[3] = byte(len(d.Configuration) >> 8)
}

var DescriptorCDC = Descriptor{
	Device: []byte{
		0x12, 0x01, 0x00, 0x02, 0xef, 0x02, 0x01, 0x40, 0x86, 0x28, 0x2d, 0x80, 0x00, 0x01, 0x01, 0x02, 0x03, 0x01,
	},
	Configuration: []byte{
		0x09, 0x02, 0x4b, 0x00, 0x02, 0x01, 0x00, 0xa0, 0x32,
		0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
		0x09, 0x04, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00,
		0x05, 0x24, 0x00, 0x10, 0x01,
		0x04, 0x24, 0x02, 0x06,
		0x05, 0x24, 0x06, 0x00, 0x01,
		0x05, 0x24, 0x01, 0x01, 0x01,
		0x07, 0x05, 0x81, 0x03, 0x10, 0x00, 0x10,
		0x09, 0x04, 0x01, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00,
		0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00,
		0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00,
	},
}

var DescriptorCDCHID = Descriptor{
	Device: []byte{
		0x12, 0x01, 0x00, 0x02, 0xef, 0x02, 0x01, 0x40, 0x86, 0x28, 0x2d, 0x80, 0x00, 0x01, 0x01, 0x02, 0x03, 0x01,
	},
	Configuration: []byte{
		0x09, 0x02, 0x64, 0x00, 0x03, 0x01, 0x00, 0xa0, 0x32,
		0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
		0x09, 0x04, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00,
		0x05, 0x24, 0x00, 0x10, 0x01,
		0x04, 0x24, 0x02, 0x06,
		0x05, 0x24, 0x06, 0x00, 0x01,
		0x05, 0x24, 0x01, 0x01, 0x01,
		0x07, 0x05, 0x81, 0x03, 0x10, 0x00, 0x10,
		0x09, 0x04, 0x01, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00,
		0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00,
		0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00,
		0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00,
		0x09, 0x21, 0x01, 0x01, 0x00, 0x01, 0x22, 0x7E, 0x00,
		0x07, 0x05, 0x84, 0x03, 0x40, 0x00, 0x01,
	},
	HID: map[uint16][]byte{
		2: []byte{
			// keyboard and mouse
			0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x85, 0x02, 0x05, 0x07, 0x19, 0xe0, 0x29, 0xe7, 0x15, 0x00,
			0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, 0x01, 0x75, 0x08, 0x81, 0x03, 0x95, 0x06,
			0x75, 0x08, 0x15, 0x00, 0x25, 0xFF, 0x05, 0x07, 0x19, 0x00, 0x29, 0xFF, 0x81, 0x00, 0xc0, 0x05,
			0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x85, 0x01, 0x05, 0x09, 0x19, 0x01, 0x29,
			0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81,
			0x03, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95,
			0x03, 0x81, 0x06, 0xc0, 0xc0,

			0x05, 0x0C, //       Usage Page (Consumer)
			0x09, 0x01, //       Usage (Consumer Control)
			0xA1, 0x01, //       Collection (Application)
			0x85, 0x03, //         Report ID (3)
			0x15, 0x00, //         Logical Minimum (0)
			0x26, 0xFF, 0x1F, //   Logical Maximum (8191)
			0x19, 0x00, //         Usage Minimum (Unassigned)
			0x2A, 0xFF, 0x1F, //   Usage Maximum (0x1FFF)
			0x75, 0x10, //         Report Size (16)
			0x95, 0x01, //         Report Count (1)
			0x81, 0x00, //         Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
			0xC0, //             End       Collection
		},
	},
}

var DescriptorCDCMIDI = Descriptor{
	Device: []byte{
		0x12, 0x01, 0x00, 0x02, 0xef, 0x02, 0x01, 0x40, 0x86, 0x28, 0x2d, 0x80, 0x00, 0x01, 0x01, 0x02, 0x03, 0x01,
	},
	Configuration: []byte{
		0x09, 0x02, 0xaf, 0x00, 0x04, 0x01, 0x00, 0xa0, 0x32,
		0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
		0x09, 0x04, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00,
		0x05, 0x24, 0x00, 0x10, 0x01,
		0x04, 0x24, 0x02, 0x06,
		0x05, 0x24, 0x06, 0x00, 0x01,
		0x05, 0x24, 0x01, 0x01, 0x01,
		0x07, 0x05, 0x81, 0x03, 0x10, 0x00, 0x10,
		0x09, 0x04, 0x01, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00,
		0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00,
		0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00,
		0x08, 0x0b, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00,
		0x09, 0x04, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
		0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x03,
		0x09, 0x04, 0x03, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00,
		0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00,
		0x06, 0x24, 0x02, 0x01, 0x01, 0x00,
		0x06, 0x24, 0x02, 0x02, 0x02, 0x00,
		0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00,
		0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x01, 0x01, 0x00,
		0x09, 0x05, 0x07, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
		0x05, 0x25, 0x01, 0x01, 0x01,
		0x09, 0x05, 0x86, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
		0x05, 0x25, 0x01, 0x01, 0x03,
	},
}

var DescriptorCDCJoystick = Descriptor{
	Device: []byte{
		0x12, 0x01, 0x00, 0x02, 0xef, 0x02, 0x01, 0x40,
		0x41, 0x23, 0x36, 0x80, 0x00, 0x01, 0x01, 0x02,
		0x03, 0x01,
	},
	Configuration: []byte{
		// Configuration Descriptor Header
		0x09, 0x02,
		0x6b, 0x00, // Total Length: 0x006b(107)
		0x03, 0x01, 0x00, 0xa0, 0xfa,
		// InterfaceAssociation Descriptoy
		0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
		// InterfaceSescriptor(CDC-Ctrl)
		0x09, 0x04, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00,
		// Communication Descriptor
		0x05, 0x24, 0x00, 0x10, 0x01,
		// Communication Descriptor
		0x05, 0x24, 0x01, 0x01, 0x01,
		// Communication Descriptor
		0x04, 0x24, 0x02, 0x06,
		// Communication Descriptor
		0x05, 0x24, 0x06, 0x00, 0x01,
		// ENDPOINT Descriptor
		0x07, 0x05, 0x81, 0x03, 0x10, 0x00, 0x40,
		// InterfaceSescriptor(CDC-Data)
		0x09, 0x04, 0x01, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00,
		// ENDPOINT Descriptor
		0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00,
		// ENDPOINT Descriptor
		0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00,
		// InterfaceSescriptor(HID)
		0x09, 0x04, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00,
		// HID Descriptor
		0x09,       // bLength: 9
		0x21,       // bDescriptorType: 0x21(HID)
		0x11, 0x01, // bcdHID: 0x111
		0x00,       // bCountryCode: Not Supported
		0x01,       // bNumDescriptors: 1
		0x22,       // Type: HID Report
		0x00, 0x00, // Length
		// ENDPOINT Descriptor
		0x07, 0x05, 0x84, 0x03, 0x40, 0x00, 0x01,
		// ENDPOINT Descriptor
		0x07, 0x05, 0x05, 0x03, 0x40, 0x00, 0x01,
	},
	HID: map[uint16][]byte{},
}