Skip to content

Commit 2bab7d0

Browse files
committed
update tinyusb to better support midi
1 parent 1f433a9 commit 2bab7d0

File tree

15 files changed

+383
-121
lines changed

15 files changed

+383
-121
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/audio/audio.h

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* Currently only MIDI subclass is supported
3030
* @{ */
3131

32-
#ifndef _TUSB_CDC_H__
33-
#define _TUSB_CDC_H__
32+
#ifndef _TUSB_AUDIO_H__
33+
#define _TUSB_AUDIO_H__
3434

3535
#include "common/tusb_common.h"
3636

@@ -41,9 +41,9 @@
4141
/// Audio Interface Subclass Codes
4242
typedef enum
4343
{
44-
AUDIO_SUBCLASS_AUDIO_CONTROL = 0x01 , ///< Audio Control
45-
AUDIO_SUBCLASS_AUDIO_STREAMING , ///< Audio Streaming
46-
AUDIO_SUBCLASS_MIDI_STREAMING , ///< MIDI Streaming
44+
AUDIO_SUBCLASS_CONTROL = 0x01 , ///< Audio Control
45+
AUDIO_SUBCLASS_STREAMING , ///< Audio Streaming
46+
AUDIO_SUBCLASS_MIDI_STREAMING , ///< MIDI Streaming
4747
} audio_subclass_type_t;
4848

4949
/// Audio Protocol Codes
@@ -54,6 +54,40 @@ typedef enum
5454
AUDIO_PROTOCOL_V3 = 0x30, ///< Version 3.0
5555
} audio_protocol_type_t;
5656

57+
/// Audio Function Category Codes
58+
typedef enum
59+
{
60+
AUDIO_FUNC_DESKTOP_SPEAKER = 0x01,
61+
AUDIO_FUNC_HOME_THEATER = 0x02,
62+
AUDIO_FUNC_MICROPHONE = 0x03,
63+
AUDIO_FUNC_HEADSET = 0x04,
64+
AUDIO_FUNC_TELEPHONE = 0x05,
65+
AUDIO_FUNC_CONVERTER = 0x06,
66+
AUDIO_FUNC_SOUND_RECODER = 0x07,
67+
AUDIO_FUNC_IO_BOX = 0x08,
68+
AUDIO_FUNC_MUSICAL_INSTRUMENT = 0x09,
69+
AUDIO_FUNC_PRO_AUDIO = 0x0A,
70+
AUDIO_FUNC_AUDIO_VIDEO = 0x0B,
71+
AUDIO_FUNC_CONTROL_PANEL = 0x0C
72+
} audio_function_t;
73+
74+
/// Audio Class-Specific AC Interface Descriptor Subtypes
75+
typedef enum
76+
{
77+
AUDIO_CS_INTERFACE_HEADER = 0x01,
78+
AUDIO_CS_INTERFACE_INPUT_TERMINAL = 0x02,
79+
AUDIO_CS_INTERFACE_OUTPUT_TERMINAL = 0x03,
80+
AUDIO_CS_INTERFACE_MIXER_UNIT = 0x04,
81+
AUDIO_CS_INTERFACE_SELECTOR_UNIT = 0x05,
82+
AUDIO_CS_INTERFACE_FEATURE_UNIT = 0x06,
83+
AUDIO_CS_INTERFACE_EFFECT_UNIT = 0x07,
84+
AUDIO_CS_INTERFACE_PROCESSING_UNIT = 0x08,
85+
AUDIO_CS_INTERFACE_EXTENSION_UNIT = 0x09,
86+
AUDIO_CS_INTERFACE_CLOCK_SOURCE = 0x0A,
87+
AUDIO_CS_INTERFACE_CLOCK_SELECTOR = 0x0B,
88+
AUDIO_CS_INTERFACE_CLOCK_MULTIPLIER = 0x0C,
89+
AUDIO_CS_INTERFACE_SAMPLE_RATE_CONVERTER = 0x0D,
90+
} audio_cs_interface_subtype_t;
5791

5892
/** @} */
5993

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
/** \defgroup ClassDriver_CDC_Common Common Definitions
4242
* @{ */
4343

44-
44+
// TODO remove
4545
/// CDC Pipe ID, used to indicate which pipe the API is addressing to (Notification, Out, In)
4646
typedef enum
4747
{
@@ -52,8 +52,9 @@ typedef enum
5252
}cdc_pipeid_t;
5353

5454
//--------------------------------------------------------------------+
55-
// CDC COMMUNICATION INTERFACE CLASS
55+
// CDC Communication Interface Class
5656
//--------------------------------------------------------------------+
57+
5758
/// Communication Interface Subclass Codes
5859
typedef enum
5960
{
@@ -117,7 +118,7 @@ typedef enum
117118
}cdc_func_desc_type_t;
118119

119120
//--------------------------------------------------------------------+
120-
// CDC DATA INTERFACE CLASS
121+
// CDC Data Interface Class
121122
//--------------------------------------------------------------------+
122123

123124
// SUBCLASS code of Data Interface is not used and should/must be zero
@@ -138,8 +139,9 @@ typedef enum{
138139
}cdc_data_protocol_type_t;
139140

140141
//--------------------------------------------------------------------+
141-
// MANAGEMENT ELEMENT REQUEST (CONTROL ENDPOINT)
142+
// Management Element Request (Control Endpoint)
142143
//--------------------------------------------------------------------+
144+
143145
/// Communication Interface Management Element Request Codes
144146
typedef enum
145147
{
@@ -189,8 +191,9 @@ typedef enum
189191
}cdc_management_request_t;
190192

191193
//--------------------------------------------------------------------+
192-
// MANAGEMENT ELEMENENT NOTIFICATION (NOTIFICATION ENDPOINT)
194+
// Management Elemenent Notification (Notification Endpoint)
193195
//--------------------------------------------------------------------+
196+
194197
/// Communication Interface Management Element Notification Codes
195198
typedef enum
196199
{
@@ -209,14 +212,15 @@ typedef enum
209212
}cdc_notification_request_t;
210213

211214
//--------------------------------------------------------------------+
212-
// FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE)
215+
// Class Specific Functional Descriptor (Communication Interface)
213216
//--------------------------------------------------------------------+
217+
214218
/// Header Functional Descriptor (Communication Interface)
215219
typedef struct TU_ATTR_PACKED
216220
{
217221
uint8_t bLength ; ///< Size of this descriptor in bytes.
218222
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
219-
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
223+
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUNC_DESC_
220224
uint16_t bcdCDC ; ///< CDC release number in Binary-Coded Decimal
221225
}cdc_desc_func_header_t;
222226

@@ -246,7 +250,7 @@ typedef struct TU_ATTR_PACKED
246250
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
247251
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
248252
uint8_t iCountryCodeRelDate ; ///< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
249-
uint16_t wCountryCode[] ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
253+
uint16_t wCountryCode ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
250254
}cdc_desc_func_country_selection_t;
251255

252256
#define cdc_desc_func_country_selection_n_t(no_country) \

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,18 @@ typedef struct
7373
//--------------------------------------------------------------------+
7474
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
7575

76-
//bool pending_read_from_host; TODO remove
7776
static void _prep_out_transaction (uint8_t itf)
7877
{
7978
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
8079

8180
// skip if previous transfer not complete
8281
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
83-
//if (pending_read_from_host) return;
8482

8583
// Prepare for incoming data but only allow what we can store in the ring buffer.
8684
uint16_t max_read = tu_fifo_remaining(&p_cdc->rx_ff);
8785
if ( max_read >= CFG_TUD_CDC_EPSIZE )
8886
{
8987
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
90-
// pending_read_from_host = true;
9188
}
9289
}
9390

@@ -265,7 +262,7 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
265262
(*p_length) = sizeof(tusb_desc_interface_t);
266263

267264
// Communication Functional Descriptors
268-
while ( TUSB_DESC_CLASS_SPECIFIC == tu_desc_type(p_desc) )
265+
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) )
269266
{
270267
(*p_length) += tu_desc_len(p_desc);
271268
p_desc = tu_desc_next(p_desc);
@@ -296,7 +293,6 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
296293
}
297294

298295
// Prepare for incoming data
299-
// pending_read_from_host = false;
300296
_prep_out_transaction(cdc_id);
301297

302298
return true;
@@ -392,11 +388,16 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
392388
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
393389

394390
// prepare for OUT transaction
395-
// pending_read_from_host = false;
396391
_prep_out_transaction(itf);
397392
}
398393

399-
// nothing to do with in and notif endpoint for now
394+
// sent data
395+
// if ( ep_addr == p_cdc->ep_in )
396+
// {
397+
//
398+
// }
399+
400+
// nothing to do with notif endpoint for now
400401

401402
return true;
402403
}

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* @{ */
4949

5050
//--------------------------------------------------------------------+
51-
// APPLICATION API (Multiple Interfaces)
51+
// Application API (Multiple Interfaces)
5252
// CFG_TUD_CDC > 1
5353
//--------------------------------------------------------------------+
5454
bool tud_cdc_n_connected (uint8_t itf);
@@ -68,26 +68,26 @@ uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str);
6868
bool tud_cdc_n_write_flush (uint8_t itf);
6969

7070
//--------------------------------------------------------------------+
71-
// APPLICATION API (Interface0)
71+
// Application API (Interface0)
7272
//--------------------------------------------------------------------+
73-
static inline bool tud_cdc_connected (void) { return tud_cdc_n_connected(0); }
74-
static inline uint8_t tud_cdc_get_line_state (void) { return tud_cdc_n_get_line_state(0); }
75-
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding) { return tud_cdc_n_get_line_coding(0, coding);}
76-
static inline void tud_cdc_set_wanted_char (char wanted) { tud_cdc_n_set_wanted_char(0, wanted); }
77-
78-
static inline uint32_t tud_cdc_available (void) { return tud_cdc_n_available(0); }
79-
static inline signed char tud_cdc_read_char (void) { return tud_cdc_n_read_char(0); }
80-
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize) { return tud_cdc_n_read(0, buffer, bufsize); }
81-
static inline void tud_cdc_read_flush (void) { tud_cdc_n_read_flush(0); }
82-
static inline signed char tud_cdc_peek (int pos) { return tud_cdc_n_peek(0, pos); }
83-
84-
static inline uint32_t tud_cdc_write_char (char ch) { return tud_cdc_n_write_char(0, ch); }
85-
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize) { return tud_cdc_n_write(0, buffer, bufsize); }
86-
static inline uint32_t tud_cdc_write_str (char const* str) { return tud_cdc_n_write_str(0, str); }
87-
static inline bool tud_cdc_write_flush (void) { return tud_cdc_n_write_flush(0); }
73+
static inline bool tud_cdc_connected (void);
74+
static inline uint8_t tud_cdc_get_line_state (void);
75+
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding);
76+
static inline void tud_cdc_set_wanted_char (char wanted);
77+
78+
static inline uint32_t tud_cdc_available (void);
79+
static inline signed char tud_cdc_read_char (void);
80+
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize);
81+
static inline void tud_cdc_read_flush (void);
82+
static inline signed char tud_cdc_peek (int pos);
83+
84+
static inline uint32_t tud_cdc_write_char (char ch);
85+
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize);
86+
static inline uint32_t tud_cdc_write_str (char const* str);
87+
static inline bool tud_cdc_write_flush (void);
8888

8989
//--------------------------------------------------------------------+
90-
// APPLICATION CALLBACK API (WEAK is optional)
90+
// Application Callback API (weak is optional)
9191
//--------------------------------------------------------------------+
9292

9393
// Invoked when received new data
@@ -102,6 +102,74 @@ TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
102102
// Invoked when line coding is change via SET_LINE_CODING
103103
TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
104104

105+
//--------------------------------------------------------------------+
106+
// Inline Functions
107+
//--------------------------------------------------------------------+
108+
static inline bool tud_cdc_connected (void)
109+
{
110+
return tud_cdc_n_connected(0);
111+
}
112+
113+
static inline uint8_t tud_cdc_get_line_state (void)
114+
{
115+
return tud_cdc_n_get_line_state(0);
116+
}
117+
118+
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding)
119+
{
120+
return tud_cdc_n_get_line_coding(0, coding);
121+
}
122+
123+
static inline void tud_cdc_set_wanted_char (char wanted)
124+
{
125+
tud_cdc_n_set_wanted_char(0, wanted);
126+
}
127+
128+
static inline uint32_t tud_cdc_available (void)
129+
{
130+
return tud_cdc_n_available(0);
131+
}
132+
133+
static inline signed char tud_cdc_read_char (void)
134+
{
135+
return tud_cdc_n_read_char(0);
136+
}
137+
138+
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize)
139+
{
140+
return tud_cdc_n_read(0, buffer, bufsize);
141+
}
142+
143+
static inline void tud_cdc_read_flush (void)
144+
{
145+
tud_cdc_n_read_flush(0);
146+
}
147+
148+
static inline signed char tud_cdc_peek (int pos)
149+
{
150+
return tud_cdc_n_peek(0, pos);
151+
}
152+
153+
static inline uint32_t tud_cdc_write_char (char ch)
154+
{
155+
return tud_cdc_n_write_char(0, ch);
156+
}
157+
158+
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize)
159+
{
160+
return tud_cdc_n_write(0, buffer, bufsize);
161+
}
162+
163+
static inline uint32_t tud_cdc_write_str (char const* str)
164+
{
165+
return tud_cdc_n_write_str(0, str);
166+
}
167+
168+
static inline bool tud_cdc_write_flush (void)
169+
{
170+
return tud_cdc_n_write_flush(0);
171+
}
172+
105173
/** @} */
106174
/** @} */
107175

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/custom/custom_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_
7070
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
7171

7272
// TODO Prepare for incoming data
73-
// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
73+
// TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
7474

7575
return true;
7676
}

0 commit comments

Comments
 (0)