-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RP2040 MIDI Host #1627
base: master
Are you sure you want to change the base?
RP2040 MIDI Host #1627
Conversation
About my above comments, since there wasn't an example included in this PR, I took the previous PR's examples/host/midi and tried compiling it. |
Still having problems compiling this. include ../../../tools/top.mk
include ../../make.mk
INC += \
src \
$(TOP)/hw \
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
include ../../rules.mk And then I could follow the standard tinyusb build steps but with this PR. Specifically I did: git clone https://github.com/hathach/tinyusb tinyusb-testmidihost
cd tinyusb-testmidihost
gh pr checkout 1627
git submodule update --init lib
cd examples/host/midi_rx
make BOARD=raspberry_pi_pico get-deps
make BOARD=raspberry_pi_pico all This fails because all of the unused variables in make BOARD=raspberry_pi_pico clean && make BOARD=raspberry_pi_pico LOG=1 all and get the error: [...]
Scanning dependencies of target midi_rx
make[3]: Leaving directory '/Users/tod/projects/tinyusb/tinyusb-testmidihost/examples/host/midi_rx/_build/raspberry_pi_pico'
make[3]: Entering directory '/Users/tod/projects/tinyusb/tinyusb-testmidihost/examples/host/midi_rx/_build/raspberry_pi_pico'
[ 16%] Building C object CMakeFiles/midi_rx.dir/src/main.c.obj
<command-line>: error: no macro name given in #define directive
compilation terminated due to -Wfatal-errors.
make[3]: *** [CMakeFiles/midi_rx.dir/build.make:76: CMakeFiles/midi_rx.dir/src/main.c.obj] Error 1 Any clues as to what I'm doing wrong? |
Thanks for being persistent on this one. I'm new at this and was not even aware of the standard way to build TinyUSB. |
Do you have a specific recommended build process for this PR? I have tried both using standard Pico build process inside of cd tinyusb-testmidihost/examples/host/midi_rx
mkdir build
cd build
cmake .. And I have tried: cd pico_examples
cp -a ../tinyusb-testmidihost/examples/host/midi_rx .
echo "add_subdirectory(midi_rx)" >> CMakeLists.txt
mkdir build
cd build
cmake .. |
Generally I'm following this guide: https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf and building from CLion IDE, but the commands it's running are:
(I ommited the env variables specifying the paths to compilers for the second command) For any other example it would be as simple as: But the TinyUSB examples are pulled in from outside of project root and I don't know where to look for CMake outputs of those. |
Seems odd to me you're not following standard |
In the meantime (while waiting for #1434 to be merged) I started on adding a nice-looking MIDI API. Turns out the simplest way is to reuse https://github.com/FortySevenEffects/arduino_midi_library. Fortunately it does not depend on Arduino itself and has a transport plug-in architecture. I wrote a TinyUSB based tramsport plugin for it: https://github.com/atoktoto/pico-midi-usb-transport void onNote(Channel channel, byte note, byte velocity) {
printf("Note ON ch=%d, note=%d, vel=%d\n", channel, note, velocity);
}
MIDI.setHandleNoteOn(onNote); |
@todbot On my machine (Windows, under WSL2) the example now builds with I also verified that the example works as intended when the resulting uf2 is dropped onto RP2040. I did not get the |
@atoktoto, I also can get it to compile now (with similar Makefile and changes as your commits, though I had to also fix casts on int -> uint conversion errors The pico-midi-usb-transport library is great! The 47effects MIDI library is wonderful. The CMake files of
Where does the |
That's a naming inconsistency on my side. The key fact here is the name of the project is not important. AFAIK |
I am keen to get this in the master branch so I can use it properly - is this stuck somehow, and can I help? Seems a failure on this:
I can't really tell why it converts two uint8_t into an int, but wouldn't this fix it?
|
@atoktoto I found a fix for hubs not working with this. I made the error in my original pull request. Would you consider adding this change to your pull request?
|
Sure, I will to that tonight.
|
- rename midi_stream_t to midi_driver_stream_t and move to midi.h (common for device and host)
@hathach Set |
@hathach I recommend that you reference the usb_midi_host project when merging this pull request. I have been maintaining it for quite a while and have fixed a number of issues since this pull request was submitted. |
Ah thank you for the head up, I will try to merge this first, then do compare and update later with follow-up PR afterwards. I don't own/use any midi comercial at all, therefore it is all up to you and others to fix its issues. I mostly make sure it is up-to-date with stack API, compiling with other ports and working with simple examples (like midi_rx).
Thank you for explanation |
- add tuh_midi_packet_read_n() and tuh_midi_packet_write_n() - add CFG_TUH_MIDI_STREAM_API to opt out stream API
PS: I made more changes to the API and its signature and feeling good for now. I will check the string thing later, need to switch to other works for now. So the string is mostly for displaying the label ? Besides that does it has any behavior or setting impact ? |
@hathach Yes, Many MIDI devices do not implement Jack Descriptor strings. Some implement them, but do it poorly. An example RP2040 device that uses Jack Descriptor strings is midi-multistream2usbdev. You may find that project useful to test the Jack Strings when you get to that. |
# Conflicts: # src/host/usbh.c
@rppicomidi thank you for your explanation, if string is only used for displaying label. I think we can
Making that change now |
…cation to parse/extract this information if needed rename tuh_midi_configure() to mounted() for consistency
…t more than 1 midi per device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much everyone for putting time and effort for this PR. Especially @atoktoto and @rppicomidi for getting most of the work done. I am sorry for being super late, I have to constant switching works and haven't worked much with rp2040 until now.
Though since there is lots of changes since this PR is created, I have update and also make lots of changes, notably:
- lost of API rename and signature changes to match other class driver consistency e.g num_rx_cables --> rx_cable_count
- remove the devstring and added tuh_midi_descriptor_cb() along with callback data to leave extracting midi jack info to application if needed
- use the new endpoint stream API for streamging data
- allow to turn off stream API
CFG_TUH_MIDI_STREAM_API=0
(which consume lots of logic/footprint). Since more recent high level MIDI library can support multiple cables and can parse 4-byte usb packet natively - change the API input from dev_addr --> interface index, consistency with cdc, but also allow to support more than 1 midi interface per device (rare case).
It is quite a bit of changes, and may break compatible with existing host driver from application space, @rppicomidi let me know what you think and how you want to chagne/resolve the confict. I am open to all feedback, thank you.
change tuh_midi_rx/tx_cb() to have xferred_bytes rename tuh_midi_get_num_rx/tx_cables() to tuh_midi_get_rx/tx_cable_count() use default empty callback instead of weak null to be compatible with keil compiler
@hathach I am just back from travel. I may need a few days to get you feedback. Sorry for the delay. |
no problems, please take your time. |
The It does not build for two reasons:
Are these known issues? I did not see bugs filed, but it may be my search. People who follow the Raspberry Pi Pico build workflow from current Raspberry Pi Pico C/C++ documentation will have trouble here and may give up. I will try to get to a test on hardware and a review of the actual driver when I am able. |
@rppicomidi how to do build the example, I normally just go to tinyusb/exmaples/ and cmake there. I surely can try to make it backward compatible. PS: if you create an empty board.h inside the hw/bsp/rp2040/boards/pico_sdk, will it fix the compile issue ? |
Also need to fix 3 CMakeList.txt files. I added command line steps to reproduce to #3004. |
This pull request replaces the previous draft: #1605
This PR adds MIDI host support for RP2040 boards based on work done by @rppicomidi here: https://github.com/rppicomidi/tinyusb/tree/pio-midihost and @Skyler84 in #1434.
It seems to work pretty OK and has no issue with hot-plugging (re-plugging) the device that #1605 had.