mikroSDK Reference Manual
midi_device.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_MIDI_DEVICE_H_
28#define _TUSB_MIDI_DEVICE_H_
29
30#include "class/audio/audio.h"
31#include "midi.h"
32
33//--------------------------------------------------------------------+
34// Class Driver Configuration
35//--------------------------------------------------------------------+
36
37#if !defined(CFG_TUD_MIDI_EP_BUFSIZE) && defined(CFG_TUD_MIDI_EPSIZE)
38 #warning CFG_TUD_MIDI_EPSIZE is renamed to CFG_TUD_MIDI_EP_BUFSIZE, please update to use the new name
39 #define CFG_TUD_MIDI_EP_BUFSIZE CFG_TUD_MIDI_EPSIZE
40#endif
41
42#ifndef CFG_TUD_MIDI_EP_BUFSIZE
43 #define CFG_TUD_MIDI_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
44#endif
45
46#ifdef __cplusplus
47 extern "C" {
48#endif
49
55//--------------------------------------------------------------------+
56// Application API (Multiple Interfaces)
57// CFG_TUD_MIDI > 1
58//--------------------------------------------------------------------+
59
60// Check if midi interface is mounted
61bool tud_midi_n_mounted (uint8_t itf);
62
63// Get the number of bytes available for reading
64uint32_t tud_midi_n_available (uint8_t itf, uint8_t cable_num);
65
66// Read byte stream (legacy)
67uint32_t tud_midi_n_stream_read (uint8_t itf, uint8_t cable_num, void* buffer, uint32_t bufsize);
68
69// Write byte Stream (legacy)
70uint32_t tud_midi_n_stream_write (uint8_t itf, uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize);
71
72// Read event packet (4 bytes)
73bool tud_midi_n_packet_read (uint8_t itf, uint8_t packet[4]);
74
75// Write event packet (4 bytes)
76bool tud_midi_n_packet_write (uint8_t itf, uint8_t const packet[4]);
77
78//--------------------------------------------------------------------+
79// Application API (Single Interface)
80//--------------------------------------------------------------------+
81static inline bool tud_midi_mounted (void);
82static inline uint32_t tud_midi_available (void);
83
84static inline uint32_t tud_midi_stream_read (void* buffer, uint32_t bufsize);
85static inline uint32_t tud_midi_stream_write (uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize);
86
87static inline bool tud_midi_packet_read (uint8_t packet[4]);
88static inline bool tud_midi_packet_write (uint8_t const packet[4]);
89
90//------------- Deprecated API name -------------//
91// TODO remove after 0.10.0 release
92
93TU_ATTR_DEPRECATED("tud_midi_read() is renamed to tud_midi_stream_read()")
94static inline uint32_t tud_midi_read (void* buffer, uint32_t bufsize)
95{
96 return tud_midi_stream_read(buffer, bufsize);
97}
98
99TU_ATTR_DEPRECATED("tud_midi_write() is renamed to tud_midi_stream_write()")
100static inline uint32_t tud_midi_write(uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
101{
102 return tud_midi_stream_write(cable_num, buffer, bufsize);
103}
104
105
106TU_ATTR_DEPRECATED("tud_midi_send() is renamed to tud_midi_packet_write()")
107static inline bool tud_midi_send(uint8_t packet[4])
108{
109 return tud_midi_packet_write(packet);
110}
111
112TU_ATTR_DEPRECATED("tud_midi_receive() is renamed to tud_midi_packet_read()")
113static inline bool tud_midi_receive(uint8_t packet[4])
114{
115 return tud_midi_packet_read(packet);
116}
117
118//--------------------------------------------------------------------+
119// Application Callback API (weak is optional)
120//--------------------------------------------------------------------+
121TU_ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
122
123//--------------------------------------------------------------------+
124// Inline Functions
125//--------------------------------------------------------------------+
126
127static inline bool tud_midi_mounted (void)
128{
129 return tud_midi_n_mounted(0);
130}
131
132static inline uint32_t tud_midi_available (void)
133{
134 return tud_midi_n_available(0, 0);
135}
136
137static inline uint32_t tud_midi_stream_read (void* buffer, uint32_t bufsize)
138{
139 return tud_midi_n_stream_read(0, 0, buffer, bufsize);
140}
141
142static inline uint32_t tud_midi_stream_write (uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
143{
144 return tud_midi_n_stream_write(0, cable_num, buffer, bufsize);
145}
146
147static inline bool tud_midi_packet_read (uint8_t packet[4])
148{
149 return tud_midi_n_packet_read(0, packet);
150}
151
152static inline bool tud_midi_packet_write (uint8_t const packet[4])
153{
154 return tud_midi_n_packet_write(0, packet);
155}
156
157//--------------------------------------------------------------------+
158// Internal Class Driver API
159//--------------------------------------------------------------------+
160void midid_init (void);
161void midid_reset (uint8_t rhport);
162uint16_t midid_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
163bool midid_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
164bool midid_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
165
166#ifdef __cplusplus
167 }
168#endif
169
170#endif /* _TUSB_MIDI_DEVICE_H_ */
171
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647