Skip to content

Commit b1d6252

Browse files
titouanckartben
authored andcommitted
samples: subsys: usb: midi: demonstrate usage of UMP Stream responder
Update the USB-MIDI2.0 sample to use the newly introduced UMP Stream Responder library. This allows the host to discover the topology and function block names (if supported by the host OS). Signed-off-by: Titouan Christophe <[email protected]>
1 parent 5d71669 commit b1d6252

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

samples/subsys/usb/midi/app.overlay

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
status = "okay";
1111
#address-cells = <1>;
1212
#size-cells = <1>;
13+
label = "Zephyr USB-MIDI Sample";
1314

1415
midi_in_out@0 {
1516
reg = <0 1>;
1617
protocol = "midi1-up-to-128b";
18+
label = "MIDI-IN-OUT";
1719
};
1820
};
1921
};

samples/subsys/usb/midi/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ CONFIG_INPUT=y
1010
CONFIG_LOG=y
1111
CONFIG_USBD_LOG_LEVEL_WRN=y
1212
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
13+
14+
CONFIG_MIDI2_UMP_STREAM_RESPONDER=y

samples/subsys/usb/midi/src/main.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
#include <zephyr/input/input.h>
1515
#include <zephyr/usb/class/usbd_midi2.h>
1616

17+
#include <ump_stream_responder.h>
18+
1719
#include <zephyr/logging/log.h>
1820
LOG_MODULE_REGISTER(sample_usb_midi, LOG_LEVEL_INF);
1921

20-
static const struct device *const midi = DEVICE_DT_GET(DT_NODELABEL(usb_midi));
22+
#define USB_MIDI_DT_NODE DT_NODELABEL(usb_midi)
23+
24+
static const struct device *const midi = DEVICE_DT_GET(USB_MIDI_DT_NODE);
2125

2226
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, {0});
2327

@@ -38,15 +42,29 @@ static void key_press(struct input_event *evt, void *user_data)
3842
}
3943
INPUT_CALLBACK_DEFINE(NULL, key_press, NULL);
4044

45+
static const struct ump_endpoint_dt_spec ump_ep_dt =
46+
UMP_ENDPOINT_DT_SPEC_GET(USB_MIDI_DT_NODE);
47+
48+
const struct ump_stream_responder_cfg responder_cfg = {
49+
.dev = midi,
50+
.send = (void (*)(void *, const struct midi_ump)) usbd_midi_send,
51+
.ep_spec = &ump_ep_dt,
52+
};
53+
4154
static void on_midi_packet(const struct device *dev, const struct midi_ump ump)
4255
{
4356
LOG_INF("Received MIDI packet (MT=%X)", UMP_MT(ump));
4457

45-
/* Only send MIDI1 channel voice messages back to the host */
46-
if (UMP_MT(ump) == UMP_MT_MIDI1_CHANNEL_VOICE) {
58+
switch (UMP_MT(ump)) {
59+
case UMP_MT_MIDI1_CHANNEL_VOICE:
60+
/* Only send MIDI1 channel voice messages back to the host */
4761
LOG_INF("Send back MIDI1 message %02X %02X %02X", UMP_MIDI_STATUS(ump),
4862
UMP_MIDI1_P1(ump), UMP_MIDI1_P2(ump));
4963
usbd_midi_send(dev, ump);
64+
break;
65+
case UMP_MT_UMP_STREAM:
66+
ump_stream_respond(&responder_cfg, ump);
67+
break;
5068
}
5169
}
5270

0 commit comments

Comments
 (0)