Skip to content

Commit 4e2b030

Browse files
Add MIDIUSB/arduino_midi_library-compatible library (#3194)
Runs arduino_midi_library and MIDIUSB native applications on the RP2040 and RP2350 over USB
1 parent 8ad4d49 commit 4e2b030

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@
5252
[submodule "FreeRTOS-Kernel"]
5353
path = FreeRTOS-Kernel
5454
url = https://github.com/earlephilhower/FreeRTOS-Kernel.git
55+
[submodule "libraries/MIDIUSB"]
56+
path = libraries/MIDIUSB
57+
url = https://github.com/earlephilhower/MIDIUSB.git

cores/rp2040/SerialUSB.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ void SerialUSB::end() {
8080
_running = false;
8181
USB.connect();
8282
}
83-
8483
}
8584

8685
int SerialUSB::peek() {

cores/rp2040/USB.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ USBClass USB;
6262
uint8_t _picotool_itf_num;
6363
#endif
6464

65-
6665
int usb_hid_poll_interval __attribute__((weak)) = 10;
6766

6867
uint8_t USBClass::registerEndpointIn() {
@@ -91,7 +90,7 @@ void USBClass::unregisterEndpointOut(int ep) {
9190
_endpointOut |= (1 << (ep - 0x80));
9291
}
9392

94-
uint8_t USBClass::addEntry(Entry **head, int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *param), const void *param, size_t len, int ordering, uint32_t vidMask) {
93+
uint8_t USBClass::addEntry(Entry **head, int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *param), const void *param, size_t len, int ordering, uint32_t pidMask) {
9594
static uint8_t id = 1;
9695

9796
Entry *n = (Entry *)malloc(sizeof(Entry));
@@ -101,7 +100,7 @@ uint8_t USBClass::addEntry(Entry **head, int interfaces, void (*cb)(int itf, uin
101100
n->interfaces = interfaces;
102101
n->order = ordering;
103102
n->localid = id++;
104-
n->mask = vidMask;
103+
n->mask = pidMask;
105104
n->next = nullptr;
106105

107106
// Go down list until we hit the end or an entry with ordering >= our level
@@ -163,17 +162,17 @@ uint8_t USBClass::findInterfaceID(unsigned int localid) {
163162
}
164163

165164
// Called by a HID device to register a report. Returns the *local* ID which must be mapped to the HID report ID
166-
uint8_t USBClass::registerHIDDevice(const uint8_t *descriptor, size_t len, int ordering, uint32_t vidMask) {
167-
return addEntry(&_hids, 0, nullptr, (const void *)descriptor, len, ordering, vidMask);
165+
uint8_t USBClass::registerHIDDevice(const uint8_t *descriptor, size_t len, int ordering, uint32_t pidMask) {
166+
return addEntry(&_hids, 0, nullptr, (const void *)descriptor, len, ordering, pidMask);
168167
}
169168

170169
void USBClass::unregisterHIDDevice(unsigned int localid) {
171170
removeEntry(&_hids, localid);
172171
}
173172

174173
// Called by an object at global init time to add a new interface (non-HID, like CDC or Picotool)
175-
uint8_t USBClass::registerInterface(int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *), void *param, size_t len, int ordering, uint32_t vidMask) {
176-
return addEntry(&_interfaces, interfaces, cb, param, len, ordering, vidMask);
174+
uint8_t USBClass::registerInterface(int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *), void *param, size_t len, int ordering, uint32_t pidMask) {
175+
return addEntry(&_interfaces, interfaces, cb, param, len, ordering, pidMask);
177176
}
178177

179178
void USBClass::unregisterInterface(unsigned int localid) {

cores/rp2040/USB.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ class USBClass {
3131
USBClass() { }
3232

3333
// Called by an object at global init time to register a HID device, returns a localID to be mapped using findHIDReportID
34-
// vidMask is the bits in the VID that should be XOR'd when this device is present.
34+
// pidMask is the bits in the PID that should be XOR'd when this device is present.
3535
// 0 means don't invert anything, OTW select a single bitmask 1<<n.
36-
uint8_t registerHIDDevice(const uint8_t *descriptor, size_t len, int ordering, uint32_t vidMask);
36+
uint8_t registerHIDDevice(const uint8_t *descriptor, size_t len, int ordering, uint32_t pidMask);
3737

3838
// Remove a HID device from the USB descriptor. Only call after usbDisconnect or results could be unpredictable!
3939
void unregisterHIDDevice(unsigned int localid);
4040

4141
// Called by an object at global init time to add a new interface (non-HID, like CDC or Picotool)
42-
uint8_t registerInterface(int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *param), void *param, size_t len, int ordering, uint32_t vidMask);
42+
uint8_t registerInterface(int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *param), void *param, size_t len, int ordering, uint32_t pidMask);
4343

4444
// Remove a USB interface from the USB descriptor. Only call after usbDisconnect or results could be unpredictable!
4545
void unregisterInterface(unsigned int localid);
@@ -118,7 +118,7 @@ class USBClass {
118118
} Entry;
119119

120120
// Add or remove Entry in a linked list, keeping things ordered by ordering
121-
uint8_t addEntry(Entry **head, int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *param), const void *param, size_t len, int ordering, uint32_t vidMask);
121+
uint8_t addEntry(Entry **head, int interfaces, void (*cb)(int itf, uint8_t *dst, int len, void *param), const void *param, size_t len, int ordering, uint32_t pidMask);
122122
void removeEntry(Entry **head, unsigned int localid);
123123

124124
// Find the index (HID report ID or USB interface) of a given localid

libraries/MIDIUSB

Submodule MIDIUSB added at 9be8b7c

tests/restyle.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ for dir in ./cores/rp2040 ./libraries/EEPROM ./libraries/I2S ./libraries/SingleF
1717
./libraries/SPISlave ./libraries/lwIP_ESPHost ./libraries/FatFS\
1818
./libraries/FatFSUSB ./libraries/BluetoothAudio ./libraries/BluetoothHCI \
1919
./libraries/BluetoothHIDMaster ./libraries/NetBIOS ./libraries/Ticker \
20-
./libraries/VFS ./libraries/rp2350 ./libraries/SimpleMDNS ./libraries/SoftwareSPI ; do
20+
./libraries/VFS ./libraries/rp2350 ./libraries/SimpleMDNS ./libraries/SoftwareSPI \
21+
./libraries/MIDIUSB ; do
2122
find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" \) -a \! -path '*api*' -exec astyle --suffix=none --options=./tests/astyle_core.conf \{\} \;
2223
find $dir -type f -name "*.ino" -exec astyle --suffix=none --options=./tests/astyle_examples.conf \{\} \;
2324
done

0 commit comments

Comments
 (0)