aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/usb/descriptor.go
blob: 6435c2b5d463b588eb9f306a9617b00114d55d9e (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
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, 0x65, 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, 0x73, 0x05, 0x07, 0x19, 0x00, 0x29, 0x73, 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,
		},
	},
}

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, 0x05, 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,
	},
}