1#ifndef USB_MIDI_H
2#define USB_MIDI_H
3
4#include <usb/USB_audio.h>
5
6// (Partial) USB Class Definitions for MIDI Devices, version 1.0
7// Reference: http://www.usb.org/developers/devclass_docs/midi10.pdf
8
9#define USB_MIDI_CLASS_VERSION		0x0100	// Class specification version 1.0
10
11// USB MIDI Event Packet
12
13// ... as clean structure:
14typedef struct {	// USB MIDI Event Packet
15	uint8	cin:4;	// Code Index Number
16	uint8	cn:4;	// Cable Number
17	uint8	midi[3];
18} _PACKED usb_midi_event_packet;
19
20
21// MIDIStreaming (ms) interface descriptors (p20)
22
23enum { // MIDI Streaming descriptors subtypes
24	USB_MS_HEADER_DESCRIPTOR = 0x01,
25	USB_MS_MIDI_IN_JACK_DESCRIPTOR,
26	USB_MS_MIDI_OUT_JACK_DESCRIPTOR,
27	USB_MS_ELEMENT_DESCRIPTOR
28};
29
30typedef struct usb_midi_interface_header_descriptor {
31	uint8	length;
32	uint8	descriptor_type;
33	uint8	descriptor_subtype;	// USB_MS_HEADER_DESCRIPTOR
34	uint16	ms_version;
35	uint16	total_length;
36} _PACKED usb_midi_interface_header_descriptor;
37
38
39enum {
40	USB_MIDI_EMBEDDED_JACK = 0x01,
41	USB_MIDI_EXTERNAL_JACK
42};
43
44typedef struct usb_midi_in_jack_descriptor {
45	uint8	length;
46	uint8	descriptor_type;
47	uint8	descriptor_subtype;	// USB_MS_MIDI_IN_JACK_DESCRIPTOR
48	uint8	type;	// USB_MIDI_{EMBEDDED | EXTERNAL}_JACK
49	uint8	id;
50	uint8	string_descriptor;
51} _PACKED usb_ms_midi_in_jack_descriptor;
52
53
54typedef struct usb_midi_source {
55	uint8	source_id;
56	uint8	source_pin;
57} _PACKED usb_midi_source;
58
59typedef struct usb_midi_out_jack_descriptor {
60	uint8	length;
61	uint8	descriptor_type;
62	uint8	descriptor_subtype;	// USB_MS_MIDI_OUT_JACK_DESCRIPTOR
63	uint8	type;	// USB_MIDI_{EMBEDDED | EXTERNAL}_JACK
64	uint8	id;
65	uint8	inputs_count;
66	usb_midi_source input_source[0];	// inputs_count times
67	// uint8	string_descriptor;
68} _PACKED usb_midi_out_jack_descriptor;
69
70
71enum { // USB Element Capabilities bitmap (p23,25)
72	USB_MS_ELEMENT_CUSTOM_UNDEFINED		= 0x0001,
73	USB_MS_ELEMENT_MIDI_CLOCK			= 0x0002,
74	USB_MS_ELEMENT_MIDI_TIME_CODE		= 0x0004,
75	USB_MS_ELEMENT_MTC	= USB_MS_ELEMENT_MIDI_TIME_CODE,
76	USB_MS_ELEMENT_MIDI_MACHINE_CONTROL	= 0x0008,
77	USB_MS_ELEMENT_MMC	= USB_MS_ELEMENT_MIDI_MACHINE_CONTROL,
78	// General MIDI System Level 1 compatible
79	USB_MS_ELEMENT_GM1					= 0x0010,
80	// General MIDI System Level 2 compatible
81	USB_MS_ELEMENT_GM2					= 0x0020,
82	// GS Format compatible (Roland)
83	USB_MS_ELEMENT_GS					= 0x0040,
84	// XG compatible (Yamaha)
85	USB_MS_ELEMENT_XG					= 0x0080,
86	USB_MS_ELEMENT_EFX					= 0x0100,
87	// internal MIDI Patcher or Router
88	USB_MS_ELEMENT_MIDI_PATCH_BAY		= 0x0200,
89	// Downloadable Sounds Standards Level 1 compatible
90	USB_MS_ELEMENT_DLS1					= 0x0400,
91	// Downloadable Sounds Standards Level 2 compatible
92	USB_MS_ELEMENT_DLS2					= 0x0800
93};
94
95typedef struct usb_midi_element_descriptor {
96	uint8	length;
97	uint8	descriptor_type;
98	uint8	descriptor_subtype;	// USB_MS_ELEMENT_DESCRIPTOR
99	uint8	id;
100	uint8	inputs_count;
101	usb_midi_source input_source[0];	// inputs_count times
102	// uint8	outputs_count;
103	// uint8	input_terminal_id;
104	// uint8	output_terminal_id;
105	// uint8	capabilities_size;
106	// uint8	capabilities[0];	// capabilities_size bytes
107	// uint8	string_descriptor;	// see USB_MS_ELEMENT_* enum above
108} _PACKED usb_midi_element_descriptor;
109
110// Class-Specific MIDIStream Bulk Data Endpoint descriptor (p26)
111
112#define USB_MS_GENERAL_DESCRIPTOR	0x01
113
114typedef struct usb_midi_endpoint_descriptor {
115	uint8	length;
116	uint8	descriptor_type;	// USB_DESCRIPTOR_CS_ENDPOINT
117	uint8	descriptor_subtype;	// USB_MS_GENERAL_DESCRIPTOR
118	uint8	jacks_count;
119	uint8	jacks_id[0];		// jacks_count times
120} _PACKED usb_midi_endpoint_descriptor;
121
122
123#endif	// USB_MIDI_H
124