Comments (5)
Yeah, i am experiencing this too. It seems like too much data clogs the pipes. Aftertouch and pitch bend especially.
from usb_host_library_samd.
SAMD Host library does a good job of enumerating devices, even through a hub (at least through the hub that I have).
The enumeration is carried out by repeated calls to UsbH.Task() within loop() in the ino.
Once the enumeration is done, however, the only way to get data from the devices is by polling them, and each poll reconfigures the device pipe. It's unnecessary, and since SAMD USB host hardware will poll for you, there is no need to do it this way. In any case, the polling drops messages on occasion, probably due to race condition, or delays in polling.
Not only this, but repeated calls to Task() after enumeration result in periodic polling of the hub (if present), which is unnecessary unless USB hot swap is needed.
So once enumeration is done using UsbH.Task(), you can stop calling UsbH.Task(), and configure the device pipe one time, and enable interrupts on it.
The upshot is that your code now does nothing unless a USB event occurs.
The downside is that you lose USB hot swap, and also you make assumptions about the endpoint config. In the case of supporting MIDI only, those assumptions are okay.
I plan to publish an interrupt example using a pull request this week. There is only one small addition to usbh_midi.h.
from usb_host_library_samd.
This example should work with a SINGLE midi device by itself without a hub.
https://github.com/studiohsoftware/USB_Host_Library_SAMD/tree/master/examples/USBH_MIDI/USB_MIDI_Using_Interrupts
Note there is one change to the USBHost libarary here (inline function GetEpAddress added at the bottom):
https://github.com/studiohsoftware/USB_Host_Library_SAMD/blob/master/src/usbh_midi.h
The interrupt approach requires a fixed EP address on the host side, and that EP must match the EP on the device side. Further, the pipes are a pairing of device address and EP address, so you can't have two pipes using the same EP. So this means that interrupts can not be used to monitor more than one thing (hub or device) if the devices share EP addresses (determined in the devices, not the host).
The current library gets around this because it does not require a fixed EP on the host side. Each time it polls, it configures the pipe for the device address and EP, and then polls the device. Pretty sure this overhead is leading to the dropped messages. If the host re-configures the pipe at the wrong moment, it seems a pending message from the device would be lost.
Feedback is encouraged if it seems anything I have written here is false.
I have added a pull request here:
#15
from usb_host_library_samd.
I've been experiencing MIDI message losses too and looking into it. Curiously there is this comment in Usb.cpp in InTransfer (line 321) related to reading in more data than was expected:
// This can happen. Use of assert on Arduino locks up the Arduino.
// So I will trim the value, and hope for the best.
Does anyone know which circumstances might trigger this? I've been following through the buffer handling, the use of MIDI_EVENT_PACKET_SIZE (64) to set up buffers, how maxPktSize is set from the device descriptor endpoints (which in the case of my "minikeys" seems to be 64 again, from examining the device descriptors), and so on, but I haven't spotted anything where this might occur unless the underlying SAMD21 hardware can return more data in response to a "dispatch packet"?
But I also haven't found anywhere else in the code where there is a hint that the data handling might stall or data get lost unless Release is called somehow whilst in use (which reset everything). But I don't know ultimately what determines the host transfer rates. If it doesn't ask for packets quick enough could data actually be lost at the minikeys end?
I'm pretty new to USB hosts, so apologies for the confused understanding, but I'm trying to learn how some of this works :)
Kevin
from usb_host_library_samd.
from usb_host_library_samd.
Related Issues (20)
- Capturing and transmitting arrow key presses (directional keys: up down left right) for Arduino USB Host
- Recvbuf needs to be aligned HOT 2
- USB Not starting on Adafruit QTPy w/USB-C->USB-A (3.0) Adapter HOT 3
- delay.h issue HOT 1
- USBH_MIDI : Failing to get device descriptor with some devices. HOT 1
- Disable USB Host mode
- incompatibility with Adafruit_SSD1306.h?
- feather m0 bluetooth le + 3.7v lipo run 3.3v mcu keeb?
- Using PTP to control camera never retrieves any data
- SparkFun SAMD51 MicroMod Not Showing Up on the COM Port After Example Sketch HOT 2
- delay.h not found HOT 1
- The data received with Arduino MKR 1010 is missing HOT 1
- Works on Nano 33 iOT but cannot compile for RP2040 connect
- Does this work with USBC boards?
- Seeeduino Xiao
- USB Host with a SAMD21: receiving and sending data issues HOT 8
- Problem with USBH_MIDI with Zoom G3. HOT 7
- KeyboardController HOT 1
- MKR WiFi 1010 pairing issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usb_host_library_samd.