Skip to content

Commit 352ac1b

Browse files
committed
lib: midi2: new UMP Stream responder library
Add a new top-level, transport independent library to respond to UMP Stream Discovery messages. This allows MIDI2.0 clients to discover UMP endpoints hosted on Zephyr over the UMP protocol. The endpoint specification can be gathered from the device tree, so that the same information used to generate USB descriptors in usb-midi2.0 can be delivered over UMP Stream. Signed-off-by: Titouan Christophe <[email protected]>
1 parent 1e85837 commit 352ac1b

File tree

9 files changed

+579
-1
lines changed

9 files changed

+579
-1
lines changed

doc/zephyr.doxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ INPUT = @ZEPHYR_BASE@/doc/_doxygen/mainpage.md \
10171017
@ZEPHYR_BASE@/include/zephyr/sys/atomic.h \
10181018
@ZEPHYR_BASE@/include/ \
10191019
@ZEPHYR_BASE@/lib/libc/minimal/include/ \
1020+
@ZEPHYR_BASE@/lib/midi2/ \
10201021
@ZEPHYR_BASE@/subsys/testsuite/include/ \
10211022
@ZEPHYR_BASE@/subsys/testsuite/ztest/include/ \
10221023
@ZEPHYR_BASE@/subsys/secure_storage/include/ \

dts/bindings/usb/zephyr,midi2-device.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ properties:
1414
type: int
1515
const: 1
1616

17+
label:
18+
type: string
19+
description: Name of the UMP (MIDI 2.0) endpoint
20+
1721
child-binding:
1822
description: |
1923
MIDI2 Group terminal block.
2024
This represent a set of contiguous MIDI2 groups through which the
2125
device exchange Universal MIDI Packets with the host.
2226
2327
properties:
28+
label:
29+
type: string
30+
description: Name of the corresponding UMP Function block
31+
2432
reg:
2533
type: array
2634
required: true
@@ -49,3 +57,9 @@ child-binding:
4957
- "output-only"
5058
description: |
5159
Type (data direction) of Group Terminals in this Block.
60+
61+
serial-31250bps:
62+
type: boolean
63+
description: |
64+
This represent a physical MIDI1 serial port, which is limited
65+
to a transmission speed of 31.25kb/s.

include/zephyr/audio/midi.h

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ struct midi_ump {
6363
#define UMP_MT_DATA_128 0x05
6464
/** Flex Data Messages */
6565
#define UMP_MT_FLEX_DATA 0x0d
66-
/** UMP Stream Message */
66+
/**
67+
* UMP Stream Message
68+
* @see midi_ump_stream
69+
*/
6770
#define UMP_MT_UMP_STREAM 0x0f
6871
/** @} */
6972

@@ -208,6 +211,149 @@ struct midi_ump {
208211
#define UMP_SYS_RESET 0xff /**< Reset (no param) */
209212
/** @} */
210213

214+
215+
/**
216+
* @defgroup midi_ump_stream UMP Stream specific fields
217+
* @ingroup midi_ump
218+
* @see ump112: 7.1 UMP Stream Messages
219+
*
220+
* @{
221+
*/
222+
223+
/**
224+
* @brief Format of a UMP Stream message
225+
* @param[in] ump Universal MIDI Packet (containing a UMP Stream message)
226+
* @see midi_ump_stream_format
227+
*/
228+
#define UMP_STREAM_FORMAT(ump) \
229+
(((ump).data[0] >> 26) & BIT_MASK(2))
230+
231+
/**
232+
* @defgroup midi_ump_stream_format UMP Stream format
233+
* @ingroup midi_ump_stream
234+
* @see ump112: 7.1 UMP Stream Messages: Format
235+
* @remark When UMP_MT(x)=UMP_MT_UMP_STREAM,
236+
* then UMP_STREAM_FORMAT(x) may be one of:
237+
* @{
238+
*/
239+
240+
/** Complete message in one UMP */
241+
#define UMP_STREAM_FORMAT_COMPLETE 0x00
242+
/** Start of a message which spans two or more UMPs */
243+
#define UMP_STREAM_FORMAT_START 0x01
244+
/** Continuing a message which spans three or more UMPs.
245+
* There might be multiple Continue UMPs in a single message
246+
*/
247+
#define UMP_STREAM_FORMAT_CONTINUE 0x02
248+
/** End of message which spans two or more UMPs */
249+
#define UMP_STREAM_FORMAT_END 0x03
250+
251+
/** @} */
252+
253+
/**
254+
* @brief Status field of a UMP Stream message
255+
* @param[in] ump Universal MIDI Packet (containing a UMP Stream message)
256+
* @see midi_ump_stream_status
257+
*/
258+
#define UMP_STREAM_STATUS(ump) \
259+
(((ump).data[0] >> 16) & BIT_MASK(10))
260+
261+
/**
262+
* @defgroup midi_ump_stream_status UMP Stream status
263+
* @ingroup midi_ump_stream
264+
* @see ump112: 7.1 UMP Stream Messages
265+
* @remark When UMP_MT(x)=UMP_MT_UMP_STREAM,
266+
* then UMP_STREAM_STATUS(x) may be one of:
267+
* @{
268+
*/
269+
270+
/** Endpoint Discovery Message */
271+
#define UMP_STREAM_STATUS_EP_DISCOVERY 0x00
272+
/** Endpoint Info Notification Message */
273+
#define UMP_STREAM_STATUS_EP_INFO 0x01
274+
/** Device Identity Notification Message */
275+
#define UMP_STREAM_STATUS_DEVICE_IDENT 0x02
276+
/** Endpoint Name Notification */
277+
#define UMP_STREAM_STATUS_EP_NAME 0x03
278+
/** Product Instance Id Notification Message */
279+
#define UMP_STREAM_STATUS_PROD_ID 0x04
280+
/** Stream Configuration Request Message */
281+
#define UMP_STREAM_STATUS_CONF_REQ 0x05
282+
/** Stream Configuration Notification Message */
283+
#define UMP_STREAM_STATUS_CONF_NOTIF 0x06
284+
/** Function Block Discovery Message */
285+
#define UMP_STREAM_STATUS_FB_DISCOVERY 0x10
286+
/** Function Block Info Notification */
287+
#define UMP_STREAM_STATUS_FB_INFO 0x11
288+
/** Function Block Name Notification */
289+
#define UMP_STREAM_STATUS_FB_NAME 0x12
290+
/** @} */
291+
292+
/**
293+
* @brief Filter bitmap of an Endpoint Discovery message
294+
* @param[in] ump Universal MIDI Packet (containing an Endpoint Discovery message)
295+
* @see ump112: 7.1.1 Endpoint Discovery Message
296+
* @see midi_ump_ep_disc
297+
*/
298+
#define UMP_STREAM_EP_DISCOVERY_FILTER(ump) \
299+
((ump).data[1] & BIT_MASK(8))
300+
301+
/**
302+
* @defgroup midi_ump_ep_disc UMP Stream endpoint discovery message filter bits
303+
* @ingroup midi_ump_stream
304+
* @see ump112: 7.1.1 Fig. 12: Endpoint Discovery Message Filter Bitmap Field
305+
* @remark When UMP_MT(x)=UMP_MT_UMP_STREAM and
306+
* UMP_STREAM_STATUS(x)=UMP_STREAM_STATUS_EP_DISCOVERY,
307+
* then UMP_STREAM_EP_DISCOVERY_FILTER(x) may be an ORed combination of:
308+
* @{
309+
*/
310+
311+
/** Requesting an Endpoint Info Notification */
312+
#define UMP_EP_DISC_FILTER_EP_INFO BIT(0)
313+
/** Requesting a Device Identity Notification */
314+
#define UMP_EP_DISC_FILTER_DEVICE_ID BIT(1)
315+
/** Requesting an Endpoint Name Notification */
316+
#define UMP_EP_DISC_FILTER_EP_NAME BIT(2)
317+
/** Requesting a Product Instance Id Notification */
318+
#define UMP_EP_DISC_FILTER_PRODUCT_ID BIT(3)
319+
/** Requesting a Stream Configuration Notification */
320+
#define UMP_EP_DISC_FILTER_STREAM_CFG BIT(4)
321+
/** @} */
322+
323+
/**
324+
* @brief Filter bitmap of a Function Block Discovery message
325+
* @param[in] ump Universal MIDI Packet (containing a Function Block Discovery message)
326+
* @see ump112: 7.1.7 Function Block Discovery Message
327+
* @see midi_ump_fb_disc
328+
*/
329+
#define UMP_STREAM_FB_DISCOVERY_FILTER(ump) \
330+
((ump).data[0] & BIT_MASK(8))
331+
332+
/**
333+
* @brief Block number requested in a Function Block Discovery message
334+
* @param[in] ump Universal MIDI Packet (containing a Function Block Discovery message)
335+
* @see ump112: 7.1.7 Function Block Discovery Message
336+
*/
337+
#define UMP_STREAM_FB_DISCOVERY_NUM(ump) \
338+
(((ump).data[0] >> 8) & BIT_MASK(8))
339+
340+
/**
341+
* @defgroup midi_ump_fb_disc UMP Stream Function Block discovery message filter bits
342+
* @ingroup midi_ump_stream
343+
* @see ump112: 7.1.7 Fig. 21: Function Block Discovery Filter Bitmap Field Format
344+
* @remark When UMP_MT(x)=UMP_MT_UMP_STREAM and
345+
* UMP_STREAM_STATUS(x)=UMP_STREAM_STATUS_FB_DISCOVERY,
346+
* then UMP_STREAM_FB_DISCOVERY_FILTER(x) may be an ORed combination of:
347+
* @{
348+
*/
349+
/** Requesting a Function Block Info Notification */
350+
#define UMP_FB_DISC_FILTER_INFO BIT(0)
351+
/** Requesting a Function Block Name Notification */
352+
#define UMP_FB_DISC_FILTER_NAME BIT(1)
353+
/** @} */
354+
355+
/** @} */
356+
211357
/** @} */
212358

213359
#ifdef __cplusplus

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_subdirectory_ifdef(CONFIG_CPP cpp)
1414
add_subdirectory(hash)
1515
add_subdirectory(heap)
1616
add_subdirectory(mem_blocks)
17+
add_subdirectory(midi2)
1718
add_subdirectory_ifdef(CONFIG_NET_BUF net_buf)
1819
add_subdirectory(os)
1920
add_subdirectory(utils)

lib/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ source "lib/heap/Kconfig"
1717

1818
source "lib/mem_blocks/Kconfig"
1919

20+
source "lib/midi2/Kconfig"
21+
2022
source "lib/net_buf/Kconfig"
2123

2224
source "lib/os/Kconfig"

lib/midi2/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Titouan Christophe
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_include_directories(.)
5+
6+
if(CONFIG_MIDI2_UMP_STREAM_RESPONDER)
7+
zephyr_sources(ump_stream_responder.c)
8+
endif()

lib/midi2/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Titouan Christophe
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
menu "MIDI2"
5+
6+
config MIDI2_UMP_STREAM_RESPONDER
7+
bool "MIDI2 UMP Stream responder"
8+
help
9+
Library to respond to UMP Stream discovery messages, as specified
10+
in "Universal MIDI Packet (UMP) Format and MIDI 2.0 Protocol"
11+
version 1.1.2 section 7.1: "UMP Stream Messages"
12+
13+
endmenu

0 commit comments

Comments
 (0)