2 * @brief Common definitions and declarations for the library USB MIDI Class driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
33 /** @ingroup Group_USBClassMIDI
\r
34 * @defgroup Group_USBClassMIDICommon Common Class Definitions
\r
36 * @section Sec_ModDescription Module Description
\r
37 * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
\r
43 #ifndef _MIDI_CLASS_COMMON_H_
\r
44 #define _MIDI_CLASS_COMMON_H_
\r
47 #define __INCLUDE_FROM_AUDIO_DRIVER
\r
50 #include "../../Core/StdDescriptors.h"
\r
51 #include "AudioClassCommon.h"
\r
53 /* Enable C linkage for C++ Compilers: */
\r
54 #if defined(__cplusplus)
\r
58 /* Preprocessor Checks: */
\r
59 #if !defined(__INCLUDE_FROM_MIDI_DRIVER)
\r
60 #error Do not include this file directly. Include LPCUSBlib/Drivers/USB.h instead.
\r
64 /** @name MIDI Command Values */
\r
66 /** MIDI command for a note on (activation) event. */
\r
67 #define MIDI_COMMAND_NOTE_ON 0x90
\r
69 /** MIDI command for a note off (deactivation) event. */
\r
70 #define MIDI_COMMAND_NOTE_OFF 0x80
\r
73 /** Standard key press velocity value used for all note events. */
\r
74 #define MIDI_STANDARD_VELOCITY 64
\r
76 /** Convenience macro. MIDI channels are numbered from 1-10 (natural numbers) however the logical channel
\r
77 * addresses are zero-indexed. This converts a natural MIDI channel number into the logical channel address.
\r
79 * @param channel MIDI channel number to address.
\r
81 #define MIDI_CHANNEL(channel) ((channel) - 1)
\r
84 /** Enum for the possible MIDI jack types in a MIDI device jack descriptor. */
\r
85 enum MIDI_JackTypes_t
\r
87 MIDI_JACKTYPE_Embedded = 0x01, /**< MIDI class descriptor jack type value for an embedded (logical) MIDI input or output jack. */
\r
88 MIDI_JACKTYPE_External = 0x02, /**< MIDI class descriptor jack type value for an external (physical) MIDI input or output jack. */
\r
92 /** @brief MIDI class-specific Streaming Interface Descriptor (nxpUSBlib naming conventions).
\r
94 * Type define for an Audio class-specific MIDI streaming interface descriptor. This indicates to the host
\r
95 * how MIDI the specification compliance of the device and the total length of the Audio class-specific descriptors.
\r
96 * See the USB Audio specification for more details.
\r
98 * @see @ref USB_MIDI_StdDescriptor_AudioInterface_AS_t for the version of this type with standard element names.
\r
100 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
102 typedef ATTR_IAR_PACKED struct
\r
104 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
\r
105 uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
107 uint16_t AudioSpecification; /**< Binary coded decimal value, indicating the supported Audio Class
\r
108 * specification version.
\r
110 uint16_t TotalLength; /**< Total length of the Audio class-specific descriptors, including this descriptor. */
\r
111 } ATTR_PACKED USB_MIDI_Descriptor_AudioInterface_AS_t;
\r
113 /** @brief MIDI class-specific Streaming Interface Descriptor (USB-IF naming conventions).
\r
115 * Type define for an Audio class-specific MIDI streaming interface descriptor. This indicates to the host
\r
116 * how MIDI the specification compliance of the device and the total length of the Audio class-specific descriptors.
\r
117 * See the USB Audio specification for more details.
\r
119 * @see @ref USB_MIDI_Descriptor_AudioInterface_AS_t for the version of this type with non-standard nxpUSBlib specific
\r
122 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
124 typedef ATTR_IAR_PACKED struct
\r
126 uint8_t bLength; /**< Size of the descriptor, in bytes. */
\r
127 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in @ref USB_DescriptorTypes_t or a value
\r
128 * given by the specific class.
\r
131 uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
133 uint16_t bcdMSC; /**< Binary coded decimal value, indicating the supported MIDI Class specification version. */
\r
134 uint16_t wTotalLength; /**< Total length of the Audio class-specific descriptors, including this descriptor. */
\r
135 } ATTR_PACKED USB_MIDI_StdDescriptor_AudioInterface_AS_t;
\r
137 /** @brief MIDI class-specific Input Jack Descriptor (nxpUSBlib naming conventions).
\r
139 * Type define for an Audio class-specific MIDI IN jack. This gives information to the host on a MIDI input, either
\r
140 * a physical input jack, or a logical jack (receiving input data internally, or from the host via an endpoint).
\r
142 * @see @ref USB_MIDI_StdDescriptor_InputJack_t for the version of this type with standard element names.
\r
144 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
146 typedef ATTR_IAR_PACKED struct
\r
148 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
\r
149 uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
151 uint8_t JackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
\r
152 uint8_t JackID; /**< ID value of this jack - must be a unique value within the device. */
\r
154 uint8_t JackStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
\r
155 } ATTR_PACKED USB_MIDI_Descriptor_InputJack_t;
\r
157 /** @brief MIDI class-specific Input Jack Descriptor (USB-IF naming conventions).
\r
159 * Type define for an Audio class-specific MIDI IN jack. This gives information to the host on a MIDI input, either
\r
160 * a physical input jack, or a logical jack (receiving input data internally, or from the host via an endpoint).
\r
162 * @see @ref USB_MIDI_Descriptor_InputJack_t for the version of this type with non-standard nxpUSBlib specific
\r
165 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
167 typedef ATTR_IAR_PACKED struct
\r
169 uint8_t bLength; /**< Size of the descriptor, in bytes. */
\r
170 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in @ref USB_DescriptorTypes_t or a value
\r
171 * given by the specific class.
\r
174 uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
176 uint8_t bJackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
\r
177 uint8_t bJackID; /**< ID value of this jack - must be a unique value within the device. */
\r
179 uint8_t iJack; /**< Index of a string descriptor describing this descriptor within the device. */
\r
180 } ATTR_PACKED USB_MIDI_StdDescriptor_InputJack_t;
\r
182 /** @brief MIDI class-specific Output Jack Descriptor (nxpUSBlib naming conventions).
\r
184 * Type define for an Audio class-specific MIDI OUT jack. This gives information to the host on a MIDI output, either
\r
185 * a physical output jack, or a logical jack (sending output data internally, or to the host via an endpoint).
\r
187 * @see @ref USB_MIDI_StdDescriptor_OutputJack_t for the version of this type with standard element names.
\r
189 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
191 typedef ATTR_IAR_PACKED struct
\r
193 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
\r
194 uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
196 uint8_t JackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
\r
197 uint8_t JackID; /**< ID value of this jack - must be a unique value within the device. */
\r
199 uint8_t NumberOfPins; /**< Number of output channels within the jack, either physical or logical. */
\r
200 uint8_t SourceJackID[1]; /**< ID of each output pin's source data jack. */
\r
201 uint8_t SourcePinID[1]; /**< Pin number in the input jack of each output pin's source data. */
\r
203 uint8_t JackStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
\r
204 } ATTR_PACKED USB_MIDI_Descriptor_OutputJack_t;
\r
206 /** @brief MIDI class-specific Output Jack Descriptor (USB-IF naming conventions).
\r
208 * Type define for an Audio class-specific MIDI OUT jack. This gives information to the host on a MIDI output, either
\r
209 * a physical output jack, or a logical jack (sending output data internally, or to the host via an endpoint).
\r
211 * @see @ref USB_MIDI_Descriptor_OutputJack_t for the version of this type with non-standard nxpUSBlib specific
\r
214 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
216 typedef ATTR_IAR_PACKED struct
\r
218 uint8_t bLength; /**< Size of the descriptor, in bytes. */
\r
219 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in @ref USB_DescriptorTypes_t or a value
\r
220 * given by the specific class.
\r
223 uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
225 uint8_t bJackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
\r
226 uint8_t bJackID; /**< ID value of this jack - must be a unique value within the device. */
\r
228 uint8_t bNrInputPins; /**< Number of output channels within the jack, either physical or logical. */
\r
229 uint8_t baSourceID[1]; /**< ID of each output pin's source data jack. */
\r
230 uint8_t baSourcePin[1]; /**< Pin number in the input jack of each output pin's source data. */
\r
232 uint8_t iJack; /**< Index of a string descriptor describing this descriptor within the device. */
\r
233 } ATTR_PACKED USB_MIDI_StdDescriptor_OutputJack_t;
\r
235 /** @brief Audio class-specific Jack Endpoint Descriptor (nxpUSBlib naming conventions).
\r
237 * Type define for an Audio class-specific extended MIDI jack endpoint descriptor. This contains extra information
\r
238 * on the usage of MIDI endpoints used to stream MIDI events in and out of the USB Audio device, and follows an Audio
\r
239 * class-specific extended MIDI endpoint descriptor. See the USB Audio specification for more details.
\r
241 * @see @ref USB_MIDI_StdDescriptor_Jack_Endpoint_t for the version of this type with standard element names.
\r
243 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
245 typedef ATTR_IAR_PACKED struct
\r
247 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
\r
248 uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
250 uint8_t TotalEmbeddedJacks; /**< Total number of jacks inside this endpoint. */
\r
251 uint8_t AssociatedJackID[1]; /**< IDs of each jack inside the endpoint. */
\r
252 } ATTR_PACKED USB_MIDI_Descriptor_Jack_Endpoint_t;
\r
254 /** @brief Audio class-specific Jack Endpoint Descriptor (USB-IF naming conventions).
\r
256 * Type define for an Audio class-specific extended MIDI jack endpoint descriptor. This contains extra information
\r
257 * on the usage of MIDI endpoints used to stream MIDI events in and out of the USB Audio device, and follows an Audio
\r
258 * class-specific extended MIDI endpoint descriptor. See the USB Audio specification for more details.
\r
260 * @see @ref USB_MIDI_Descriptor_Jack_Endpoint_t for the version of this type with non-standard nxpUSBlib specific
\r
263 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
265 typedef ATTR_IAR_PACKED struct
\r
267 uint8_t bLength; /**< Size of the descriptor, in bytes. */
\r
268 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in @ref USB_DescriptorTypes_t or a value
\r
269 * given by the specific class.
\r
272 uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
\r
274 uint8_t bNumEmbMIDIJack; /**< Total number of jacks inside this endpoint. */
\r
275 uint8_t bAssocJackID[1]; /**< IDs of each jack inside the endpoint. */
\r
276 } ATTR_PACKED USB_MIDI_StdDescriptor_Jack_Endpoint_t;
\r
278 /** @brief MIDI Class Driver Event Packet.
\r
280 * Type define for a USB MIDI event packet, used to encapsulate sent and received MIDI messages from a USB MIDI interface.
\r
282 * @note Regardless of CPU architecture, these values should be stored as little endian.
\r
284 typedef ATTR_IAR_PACKED struct
\r
286 unsigned Command : 4; /**< Upper nibble of the MIDI command being sent or received in the event packet. */
\r
287 unsigned CableNumber : 4; /**< Virtual cable number of the event being sent or received in the given MIDI interface. */
\r
289 uint8_t Data1; /**< First byte of data in the MIDI event. */
\r
290 uint8_t Data2; /**< Second byte of data in the MIDI event. */
\r
291 uint8_t Data3; /**< Third byte of data in the MIDI event. */
\r
292 } ATTR_PACKED MIDI_EventPacket_t;
\r
294 /* Disable C linkage for C++ Compilers: */
\r
295 #if defined(__cplusplus)
\r