Skip to content

Migrate to TinyUSB native support#14

Open
DisasterAreaDesigns wants to merge 2 commits intorppicomidi:mainfrom
DisasterAreaDesigns:TinyUSB-native
Open

Migrate to TinyUSB native support#14
DisasterAreaDesigns wants to merge 2 commits intorppicomidi:mainfrom
DisasterAreaDesigns:TinyUSB-native

Conversation

@DisasterAreaDesigns
Copy link

Initial commit to add TinyUSB native support.

Important note: tested on RP2040 hardware. Adafruit_TinyUSB 3.7.3 does not have USB Host MIDI support enabled, so you must add the following lines to /src/arduino/ports/rp2040/tusb_config_rp2040.h:

// enable MIDI Host
#define CFG_TUH_MIDI (CFG_TUH_DEVICE_MAX)

Migrate to built-in TinyUSB functions
Copy link
Owner

@rppicomidi rppicomidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thank you for the pull request. I have not tried this yet, but I did have a chance to look at the code a bit. I have a design question for you.

I get that tuh_midih_define_limits() is not in the TinyUSB USB version of the MIDI host class driver. How do you propose to support the user who needs to adjust the buffer sizes in an Arduino environment? I am afraid not supporting the additional settings may break someone's application. You cannot just define the buffer sizes and number of cables in the sketch using compiler macros. The only things I could think of is to require the user to edit the tusb_config_[your processor here].h for the Adafruit_TinyUSB_Arduino library or to modify the platform.txt file. I suppose you will have to do that anyway to support USB MIDI Host for now. But eventually, hopefully, the Adafruit_TinyUSB_Arduino library will support MIDI host out of the box.

Copy link
Owner

@rppicomidi rppicomidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md file's Library Configuration and Implementation Details section needs to be revised to match how you configure the code to work prior to release of the native TinyUSB MIDI Host driver in the Adafruit_TinyUSB_Arduino library. Also, it needs to reference how to configure buffer sizes to work around problems given you can't do it in the settings class.

@DisasterAreaDesigns
Copy link
Author

DisasterAreaDesigns commented Nov 7, 2025

First, thank you for the pull request. I have not tried this yet, but I did have a chance to look at the code a bit. I have a design question for you.

I get that tuh_midih_define_limits() is not in the TinyUSB USB version of the MIDI host class driver. How do you propose to support the user who needs to adjust the buffer sizes in an Arduino environment? I am afraid not supporting the additional settings may break someone's application. You cannot just define the buffer sizes and number of cables in the sketch using compiler macros. The only things I could think of is to require the user to edit the tusb_config_[your processor here].h for the Adafruit_TinyUSB_Arduino library or to modify the platform.txt file. I suppose you will have to do that anyway to support USB MIDI Host for now. But eventually, hopefully, the Adafruit_TinyUSB_Arduino library will support MIDI host out of the box.

You're totally correct about the removal of tuh_midih_define_limits() - there isn't a clean way to do this using TinyUSB. What other options would we have, without usb_midi_host.h as the man in the middle? I would be fine with using it but TinyUSB works much better with USB hub support.

How about adding a tusb_config.h in the sketch folder and including that? I'm using Arduino so I'm not sure how that affects the C++ side, but I think this might be a workaround. The TinyUSB library does need to be modified to allow for USB host support anyway, so changing that might not be a deal-breaker.

// tusb_config.h header file for USB settings
#ifndef _TUSB_CONFIG_H_
#define _TUSB_CONFIG_H_

// Enable USB Host MIDI
#define CFG_TUH_MIDI                    1

// Buffer sizes (equivalent to MidiRxBufsize/MidiTxBufsize)
#define CFG_TUH_MIDI_RX_BUFSIZE         512  // Your mycustomsettings::MidiRxBufsize
#define CFG_TUH_MIDI_TX_BUFSIZE         512  // Your mycustomsettings::MidiTxBufsize

// Endpoint buffer size
#define CFG_TUH_MIDI_EP_BUFSIZE         64

// Enable stream API (required for this library)
#define CFG_TUH_MIDI_STREAM_API         1

// Maximum number of MIDI devices
#define CFG_TUH_DEVICE_MAX              4    // Max USB devices total

#endif

As for updating the readme.md, I'm working on that now as indicated by the WIP statement at the top.

@rppicomidi
Copy link
Owner

@DisasterAreaDesigns I am sorry for the delay. Am very busy this week. I will try to catch up next week. In the meantime, if you have updates to the README, please feel free to submit them, too.

@rppicomidi
Copy link
Owner

@DisasterAreaDesigns I plan to fully test and likely merge this pull request if my pull request to Adafruit_TinyUSB_Arduino gets merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants