1 /*
2  * Copyright (c) 2024 Titouan Christophe
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_USB_CLASS_USBD_MIDI_H_
8 #define ZEPHYR_INCLUDE_USB_CLASS_USBD_MIDI_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /**
15  * @brief USB MIDI 2.0 class device API
16  * @defgroup usbd_midi2 USB MIDI 2.0 Class device API
17  * @ingroup usb
18  * @since 4.1
19  * @version 0.1.0
20  * @see midi20: "Universal Serial Bus Device Class Definition for MIDI Devices"
21  *              Document Release 2.0 (May 5, 2020)
22  * @{
23  */
24 
25 #include <zephyr/device.h>
26 #include <zephyr/audio/midi.h>
27 
28 /**
29  * @brief      MIDI2 application event handlers
30  */
31 struct usbd_midi_ops {
32 	/**
33 	 * @brief Callback type for incoming Universal MIDI Packets from host
34 	 * @param[in]  dev   The MIDI2 device receiving the packet
35 	 * @param[in]  ump   The received packet in Universal MIDI Packet format
36 	 */
37 	void (*rx_packet_cb)(const struct device *dev, const struct midi_ump ump);
38 
39 	/**
40 	 * @brief Callback type for MIDI2 interface runtime status change
41 	 * @param[in]  dev    The MIDI2 device
42 	 * @param[in]  ready  True if the interface is enabled by the host
43 	 */
44 	void (*ready_cb)(const struct device *dev, const bool ready);
45 };
46 
47 /**
48  * @brief      Send a Universal MIDI Packet to the host
49  * @param[in]  dev   The MIDI2 device
50  * @param[in]  ump   The packet to send, in Universal MIDI Packet format
51  * @return     0 on success, all other values should be treated as error
52  *             -EIO if USB MIDI 2.0 is not enabled by the host
53  *             -ENOBUFS if there is no space in the TX buffer
54  */
55 int usbd_midi_send(const struct device *dev, const struct midi_ump ump);
56 
57 /**
58  * @brief Set the application event handlers on a USB MIDI device
59  * @param[in]  dev   The MIDI2 device
60  * @param[in]  ops   The event handlers. Pass NULL to reset all callbacks
61  */
62 void usbd_midi_set_ops(const struct device *dev, const struct usbd_midi_ops *ops);
63 
64 /**
65  * @}
66  */
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif
73