mikroSDK Reference Manual
midi.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
32#ifndef _TUSB_MIDI_H__
33#define _TUSB_MIDI_H__
34
35#include "common/tusb_common.h"
36
37#ifdef __cplusplus
38 extern "C" {
39#endif
40
41//--------------------------------------------------------------------+
42// Class Specific Descriptor
43//--------------------------------------------------------------------+
44
45typedef enum
46{
47 MIDI_CS_INTERFACE_HEADER = 0x01,
48 MIDI_CS_INTERFACE_IN_JACK = 0x02,
49 MIDI_CS_INTERFACE_OUT_JACK = 0x03,
50 MIDI_CS_INTERFACE_ELEMENT = 0x04,
51} midi_cs_interface_subtype_t;
52
53typedef enum
54{
55 MIDI_CS_ENDPOINT_GENERAL = 0x01
56} midi_cs_endpoint_subtype_t;
57
58typedef enum
59{
60 MIDI_JACK_EMBEDDED = 0x01,
61 MIDI_JACK_EXTERNAL = 0x02
62} midi_jack_type_t;
63
64typedef enum
65{
66 MIDI_CIN_MISC = 0,
67 MIDI_CIN_CABLE_EVENT = 1,
68 MIDI_CIN_SYSCOM_2BYTE = 2, // 2 byte system common message e.g MTC, SongSelect
69 MIDI_CIN_SYSCOM_3BYTE = 3, // 3 byte system common message e.g SPP
70 MIDI_CIN_SYSEX_START = 4, // SysEx starts or continue
71 MIDI_CIN_SYSEX_END_1BYTE = 5, // SysEx ends with 1 data, or 1 byte system common message
72 MIDI_CIN_SYSEX_END_2BYTE = 6, // SysEx ends with 2 data
73 MIDI_CIN_SYSEX_END_3BYTE = 7, // SysEx ends with 3 data
74 MIDI_CIN_NOTE_OFF = 8,
75 MIDI_CIN_NOTE_ON = 9,
76 MIDI_CIN_POLY_KEYPRESS = 10,
77 MIDI_CIN_CONTROL_CHANGE = 11,
78 MIDI_CIN_PROGRAM_CHANGE = 12,
79 MIDI_CIN_CHANNEL_PRESSURE = 13,
80 MIDI_CIN_PITCH_BEND_CHANGE = 14,
81 MIDI_CIN_1BYTE_DATA = 15
82} midi_code_index_number_t;
83
84// MIDI 1.0 status byte
85enum
86{
87 //------------- System Exclusive -------------//
88 MIDI_STATUS_SYSEX_START = 0xF0,
89 MIDI_STATUS_SYSEX_END = 0xF7,
90
91 //------------- System Common -------------//
92 MIDI_STATUS_SYSCOM_TIME_CODE_QUARTER_FRAME = 0xF1,
93 MIDI_STATUS_SYSCOM_SONG_POSITION_POINTER = 0xF2,
94 MIDI_STATUS_SYSCOM_SONG_SELECT = 0xF3,
95 // F4, F5 is undefined
96 MIDI_STATUS_SYSCOM_TUNE_REQUEST = 0xF6,
97
98 //------------- System RealTime -------------//
99 MIDI_STATUS_SYSREAL_TIMING_CLOCK = 0xF8,
100 // 0xF9 is undefined
101 MIDI_STATUS_SYSREAL_START = 0xFA,
102 MIDI_STATUS_SYSREAL_CONTINUE = 0xFB,
103 MIDI_STATUS_SYSREAL_STOP = 0xFC,
104 // 0xFD is undefined
105 MIDI_STATUS_SYSREAL_ACTIVE_SENSING = 0xFE,
106 MIDI_STATUS_SYSREAL_SYSTEM_RESET = 0xFF,
107};
108
110typedef struct TU_ATTR_PACKED
111{
112 uint8_t bLength ;
113 uint8_t bDescriptorType ;
114 uint8_t bDescriptorSubType ;
115 uint16_t bcdMSC ;
116 uint16_t wTotalLength ;
118
120typedef struct TU_ATTR_PACKED
121{
122 uint8_t bLength ;
123 uint8_t bDescriptorType ;
124 uint8_t bDescriptorSubType ;
125 uint8_t bJackType ;
126 uint8_t bJackID ;
127 uint8_t iJack ;
129
130
132typedef struct TU_ATTR_PACKED
133{
134 uint8_t bLength ;
135 uint8_t bDescriptorType ;
136 uint8_t bDescriptorSubType ;
137 uint8_t bJackType ;
138 uint8_t bJackID ;
139 uint8_t bNrInputPins;
140
141 uint8_t baSourceID;
142 uint8_t baSourcePin;
143
144 uint8_t iJack ;
146
148#define midi_desc_out_jack_n_t(input_num) \
149 struct TU_ATTR_PACKED { \
150 uint8_t bLength ; \
151 uint8_t bDescriptorType ; \
152 uint8_t bDescriptorSubType ; \
153 uint8_t bJackType ; \
154 uint8_t bJackID ; \
155 uint8_t bNrInputPins ; \
156 struct TU_ATTR_PACKED { \
157 uint8_t baSourceID; \
158 uint8_t baSourcePin; \
159 } pins[input_num]; \
160 uint8_t iJack ; \
161 }
162
164typedef struct TU_ATTR_PACKED
165{
166 uint8_t bLength ;
167 uint8_t bDescriptorType ;
168 uint8_t bDescriptorSubType ;
169 uint8_t bElementID;
170
171 uint8_t bNrInputPins;
172 uint8_t baSourceID;
173 uint8_t baSourcePin;
174
175 uint8_t bNrOutputPins;
176 uint8_t bInTerminalLink;
177 uint8_t bOutTerminalLink;
178 uint8_t bElCapsSize;
179
180 uint16_t bmElementCaps;
181 uint8_t iElement;
183
185#define midi_desc_element_n_t(input_num) \
186 struct TU_ATTR_PACKED { \
187 uint8_t bLength; \
188 uint8_t bDescriptorType; \
189 uint8_t bDescriptorSubType; \
190 uint8_t bElementID; \
191 uint8_t bNrInputPins; \
192 struct TU_ATTR_PACKED { \
193 uint8_t baSourceID; \
194 uint8_t baSourcePin; \
195 } pins[input_num]; \
196 uint8_t bNrOutputPins; \
197 uint8_t bInTerminalLink; \
198 uint8_t bOutTerminalLink; \
199 uint8_t bElCapsSize; \
200 uint16_t bmElementCaps; \
201 uint8_t iElement; \
202 }
203
206#ifdef __cplusplus
207 }
208#endif
209
210#endif
211
uint8_t bDescriptorSubType
Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_HEADER.
Definition audio.h:658
struct TU_ATTR_PACKED midi_desc_header_t
MIDI Interface Header Descriptor.
struct TU_ATTR_PACKED midi_desc_element_t
MIDI Element Descriptor.
struct TU_ATTR_PACKED midi_desc_out_jack_t
MIDI Out Jack Descriptor with single pin.
uint8_t bDescriptorType
Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
Definition audio.h:657
uint8_t bLength
Size of this descriptor in bytes: 9.
Definition audio.h:656
struct TU_ATTR_PACKED midi_desc_in_jack_t
MIDI In Jack Descriptor.
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
uint8_t bJackID
Unique ID for MIDI IN Jack.
Definition midi.h:126
uint16_t bcdMSC
MidiStreaming SubClass release number in Binary-Coded Decimal.
Definition midi.h:115
uint8_t bJackType
Embedded or External.
Definition midi.h:125
uint16_t wTotalLength
Total number of bytes returned for the class-specific AudioControl interface descriptor....
Definition audio.h:661
uint8_t iJack
string descriptor
Definition midi.h:127