Skip to content

Commit b12c8a9

Browse files
committed
remove CFG_MIDI_HOST_DEVSTRINGS support, we will leave that for application to parse/extract this information if needed
rename tuh_midi_configure() to mounted() for consistency
1 parent 6ebd362 commit b12c8a9

File tree

4 files changed

+117
-286
lines changed

4 files changed

+117
-286
lines changed

examples/host/midi_rx/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void led_blinking_task(void) {
8989
//--------------------------------------------------------------------+
9090
void midi_host_rx_task(void) {
9191
// device must be attached and have at least one endpoint ready to receive a message
92-
if (!midi_dev_addr || !tuh_midi_configured(midi_dev_addr)) {
92+
if (!midi_dev_addr || !tuh_midi_mounted(midi_dev_addr)) {
9393
return;
9494
}
9595
if (tuh_midi_get_num_rx_cables(midi_dev_addr) < 1) {

src/class/midi/midi.h

Lines changed: 59 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,29 @@
3636
//--------------------------------------------------------------------+
3737
// Constants
3838
//--------------------------------------------------------------------+
39+
enum {
40+
MIDI_VERSION_1_0 = 0x0100,
41+
MIDI_VERSION_2_0 = 0x0200,
42+
};
3943

40-
typedef enum
41-
{
44+
typedef enum {
4245
MIDI_CS_INTERFACE_HEADER = 0x01,
4346
MIDI_CS_INTERFACE_IN_JACK = 0x02,
4447
MIDI_CS_INTERFACE_OUT_JACK = 0x03,
4548
MIDI_CS_INTERFACE_ELEMENT = 0x04,
4649
} midi_cs_interface_subtype_t;
4750

48-
typedef enum
49-
{
50-
MIDI_CS_ENDPOINT_GENERAL = 0x01
51+
typedef enum {
52+
MIDI_CS_ENDPOINT_GENERAL = 0x01,
53+
MIDI_CS_ENDPOINT_GENERAL_2_0 = 0x02,
5154
} midi_cs_endpoint_subtype_t;
5255

53-
typedef enum
54-
{
56+
typedef enum {
5557
MIDI_JACK_EMBEDDED = 0x01,
5658
MIDI_JACK_EXTERNAL = 0x02
5759
} midi_jack_type_t;
5860

59-
typedef enum
60-
{
61+
typedef enum {
6162
MIDI_CIN_MISC = 0,
6263
MIDI_CIN_CABLE_EVENT = 1,
6364
MIDI_CIN_SYSCOM_2BYTE = 2, // 2 byte system common message e.g MTC, SongSelect
@@ -77,8 +78,7 @@ typedef enum
7778
} midi_code_index_number_t;
7879

7980
// MIDI 1.0 status byte
80-
enum
81-
{
81+
enum {
8282
//------------- System Exclusive -------------//
8383
MIDI_STATUS_SYSEX_START = 0xF0,
8484
MIDI_STATUS_SYSEX_END = 0xF7,
@@ -101,8 +101,7 @@ enum
101101
MIDI_STATUS_SYSREAL_SYSTEM_RESET = 0xFF,
102102
};
103103

104-
enum
105-
{
104+
enum {
106105
MIDI_MAX_DATA_VAL = 0x7F,
107106
};
108107

@@ -111,62 +110,48 @@ enum
111110
//--------------------------------------------------------------------+
112111

113112
/// MIDI Interface Header Descriptor
114-
typedef struct TU_ATTR_PACKED
115-
{
116-
uint8_t bLength ; ///< Size of this descriptor in bytes.
117-
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
118-
uint8_t bDescriptorSubType ; ///< Descriptor SubType
119-
uint16_t bcdMSC ; ///< MidiStreaming SubClass release number in Binary-Coded Decimal
120-
uint16_t wTotalLength ;
113+
typedef struct TU_ATTR_PACKED {
114+
uint8_t bLength; ///< Size of this descriptor in bytes.
115+
uint8_t bDescriptorType; ///< must be TUSB_DESC_CS_INTERFACE
116+
uint8_t bDescriptorSubType;///< Descriptor SubType
117+
uint16_t bcdMSC; ///< MidiStreaming SubClass release number in Binary-Coded Decimal
118+
uint16_t wTotalLength;
121119
} midi_desc_header_t;
120+
TU_VERIFY_STATIC(sizeof(midi_desc_header_t) == 7, "size is not correct");
122121

123122
/// MIDI In Jack Descriptor
124-
typedef struct TU_ATTR_PACKED
125-
{
126-
uint8_t bLength ; ///< Size of this descriptor in bytes.
127-
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
128-
uint8_t bDescriptorSubType ; ///< Descriptor SubType
129-
uint8_t bJackType ; ///< Embedded or External
130-
uint8_t bJackID ; ///< Unique ID for MIDI IN Jack
131-
uint8_t iJack ; ///< string descriptor
123+
typedef struct TU_ATTR_PACKED {
124+
uint8_t bLength; ///< Size of this descriptor in bytes.
125+
uint8_t bDescriptorType; ///< Descriptor Type, must be Class-Specific
126+
uint8_t bDescriptorSubType;///< Descriptor SubType
127+
uint8_t bJackType; ///< Embedded or External
128+
uint8_t bJackID; ///< Unique ID for MIDI IN Jack
129+
uint8_t iJack; ///< string descriptor
132130
} midi_desc_in_jack_t;
131+
TU_VERIFY_STATIC(sizeof(midi_desc_in_jack_t) == 6, "size is not correct");
133132

134-
135-
/// MIDI Out Jack Descriptor with single pin
136-
typedef struct TU_ATTR_PACKED
137-
{
138-
uint8_t bLength ; ///< Size of this descriptor in bytes.
139-
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
140-
uint8_t bDescriptorSubType ; ///< Descriptor SubType
141-
uint8_t bJackType ; ///< Embedded or External
142-
uint8_t bJackID ; ///< Unique ID for MIDI IN Jack
143-
uint8_t bNrInputPins;
144-
145-
uint8_t baSourceID;
146-
uint8_t baSourcePin;
147-
148-
uint8_t iJack ; ///< string descriptor
149-
} midi_desc_out_jack_t ;
150-
151-
/// MIDI Out Jack Descriptor with multiple pins
133+
/// MIDI Out Jack Descriptor with multiple input pins
152134
#define midi_desc_out_jack_n_t(input_num) \
153-
struct TU_ATTR_PACKED { \
154-
uint8_t bLength ; \
155-
uint8_t bDescriptorType ; \
156-
uint8_t bDescriptorSubType ; \
157-
uint8_t bJackType ; \
158-
uint8_t bJackID ; \
159-
uint8_t bNrInputPins ; \
160-
struct TU_ATTR_PACKED { \
161-
uint8_t baSourceID; \
162-
uint8_t baSourcePin; \
163-
} pins[input_num]; \
164-
uint8_t iJack ; \
135+
struct TU_ATTR_PACKED { \
136+
uint8_t bLength; \
137+
uint8_t bDescriptorType; \
138+
uint8_t bDescriptorSubType; \
139+
uint8_t bJackType; \
140+
uint8_t bJackID; \
141+
uint8_t bNrInputPins; \
142+
struct TU_ATTR_PACKED { \
143+
uint8_t baSourceID; \
144+
uint8_t baSourcePin; \
145+
} input[input_num]; \
146+
uint8_t iJack; \
165147
}
166148

149+
typedef midi_desc_out_jack_n_t(1) midi_desc_out_jack_1in_t; // 1 input
150+
typedef midi_desc_out_jack_1in_t midi_desc_out_jack_t; // backward compatible
151+
TU_VERIFY_STATIC(sizeof(midi_desc_out_jack_1in_t) == 7 + 2 * 1, "size is not correct");
152+
167153
/// MIDI Element Descriptor
168-
typedef struct TU_ATTR_PACKED
169-
{
154+
typedef struct TU_ATTR_PACKED {
170155
uint8_t bLength ; ///< Size of this descriptor in bytes.
171156
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
172157
uint8_t bDescriptorSubType ; ///< Descriptor SubType
@@ -184,6 +169,7 @@ typedef struct TU_ATTR_PACKED
184169
uint16_t bmElementCaps;
185170
uint8_t iElement;
186171
} midi_desc_element_t;
172+
TU_VERIFY_STATIC(sizeof(midi_desc_element_t) == 14, "size is not correct");
187173

188174
/// MIDI Element Descriptor with multiple pins
189175
#define midi_desc_element_n_t(input_num) \
@@ -206,14 +192,19 @@ typedef struct TU_ATTR_PACKED
206192
}
207193

208194
// This descriptor follows the standard bulk data endpoint descriptor
209-
typedef struct
210-
{
211-
uint8_t bLength ; ///< Size of this descriptor in bytes (4+bNumEmbMIDIJack)
212-
uint8_t bDescriptorType ; ///< Descriptor Type, must be CS_ENDPOINT
213-
uint8_t bDescriptorSubType ; ///< Descriptor SubType, must be MS_GENERAL
214-
uint8_t bNumEmbMIDIJack; ; ///< Number of embedded MIDI jacks associated with this endpoint
215-
uint8_t baAssocJackID[]; ; ///< A list of associated jacks
216-
} midi_cs_desc_endpoint_t;
195+
#define midi_desc_cs_endpoint_n_t(jack_num) \
196+
struct TU_ATTR_PACKED { \
197+
uint8_t bLength; \
198+
uint8_t bDescriptorType; \
199+
uint8_t bDescriptorSubType; \
200+
uint8_t bNumEmbMIDIJack; \
201+
uint8_t baAssocJackID[jack_num]; \
202+
}
203+
204+
typedef midi_desc_cs_endpoint_n_t() midi_desc_cs_endpoint_t; // empty/flexible jack list
205+
typedef midi_desc_cs_endpoint_n_t(1) midi_desc_cs_endpoint_1jack_t;
206+
207+
TU_VERIFY_STATIC(sizeof(midi_desc_cs_endpoint_1jack_t) == 4+1, "size is not correct");
217208

218209
//--------------------------------------------------------------------+
219210
// For Internal Driver Use

0 commit comments

Comments
 (0)