Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
PluggableUSBMIDI-descr.cpp
Go to the documentation of this file.
1// Based on https://github.com/ARMmbed/mbed-os/blob/eff0d4c8b93c5a165af9f2e5e42c321a7f83eed9/drivers/usb/source/USBMIDI.cpp#L261
2
3/*
4 * Copyright (c) 2018-2019, Arm Limited and affiliates.
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#if defined(ARDUINO_ARCH_MBED)
21
22#include "PluggableUSBMIDI.hpp"
23
24#include <cstring> // memcpy
25
27
29 // clang-format off
30 static const uint8_t string_iinterface_descriptor[] {
31 0x0c, // bLength
32 STRING_DESCRIPTOR, // bDescriptorType 0x03
33 'A', 0, 'u', 0, 'd', 0, 'i', 0, 'o', 0 // bString iInterface - Audio
34 };
35 // clang-format on
36 return string_iinterface_descriptor;
37}
38
39const uint8_t *PluggableUSBMIDI::configuration_desc(uint8_t index) {
40 if (index != 0) {
41 return nullptr;
42 }
43
44 const uint8_t wmaxpkt_L = (get_packet_size() >> 0) & 0xFF;
45 const uint8_t wmaxpkt_M = (get_packet_size() >> 8) & 0xFF;
46
47 // clang-format off
48 uint8_t config_descriptor_temp[] {
49 // configuration descriptor
50 0x09, 0x02, 0x65, 0x00, 0x02, 0x01, 0x00, 0xc0, 0x50,
51
52 // The Audio Interface Collection
53 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, // Standard AC Interface Descriptor
54 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, // Class-specific AC Interface Descriptor
55 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // MIDIStreaming Interface Descriptors
56 0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // Class-Specific MS Interface Header Descriptor
57
58 // MIDI IN JACKS
59 0x06, 0x24, 0x02, 0x01, 0x01, 0x00,
60 0x06, 0x24, 0x02, 0x02, 0x02, 0x00,
61
62 // MIDI OUT JACKS
63 0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00,
64 0x09, 0x24, 0x03, 0x02, 0x06, 0x01, 0x01, 0x01, 0x00,
65
66 // OUT endpoint - Standard MS Bulk Data Endpoint Descriptor
67 0x09, // bLength
68 0x05, // bDescriptorType
69 bulk_out_ep, // bEndpointAddress
70 0x02, // bmAttributes
71 wmaxpkt_L, // wMaxPacketSize (LSB)
72 wmaxpkt_M, // wMaxPacketSize (MSB)
73 0x00, // bInterval (milliseconds)
74 0x00, // bRefresh
75 0x00, // bSynchAddress
76
77 0x05, 0x25, 0x01, 0x01, 0x01,
78
79 // IN endpoint - Standard MS Bulk Data Endpoint Descriptor
80 0x09, // bLength
81 0x05, // bDescriptorType
82 bulk_in_ep, // bEndpointAddress
83 0x02, // bmAttributes
84 wmaxpkt_L, // wMaxPacketSize (LSB)
85 wmaxpkt_M, // wMaxPacketSize (MSB)
86 0x00, // bInterval (milliseconds)
87 0x00, // bRefresh
88 0x00, // bSynchAddress
89
90 0x05, 0x25, 0x01, 0x01, 0x03,
91 };
92 // clang-format on
93 static_assert(sizeof(config_descriptor_temp) == sizeof(config_descriptor),
94 "Descriptor size error");
95 memcpy(config_descriptor, config_descriptor_temp,
96 sizeof(config_descriptor_temp));
97 return config_descriptor;
98}
99
101
102#endif
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
const uint8_t * configuration_desc(uint8_t index) override
uint8_t config_descriptor[0x65]
const uint8_t * string_iinterface_desc() override
static constexpr uint32_t get_packet_size()