USB HID / MIDI / Mass Storage as libraries

Please do not post requests
arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: USB HID / USB MIDI as libraries

Post by arpruss » Sat Dec 09, 2017 6:39 pm

The HID RAW stuff is frustrating. USB MIDI works in both directions just fine, and I don't see any significant difference in the code. I tried sending HID RAW data both from PyWinUSB and Android HID Terminal. The oscilloscope shows that there is data on the line, but I don't know how to interpret the data.

If anybody has ideas on how to get HID RAW host-to-device working, I would welcome input. Not that I really need it for anything -- just would be a nice completion to the library.

User avatar
RogerClark
Posts: 7683
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID / USB MIDI as libraries

Post by RogerClark » Sat Dec 09, 2017 7:56 pm

BTW.

Re: USB power enable and disable

If Serial.end disables power in your PR, Serial.begin should enable power, as it should be possible to all end() and then call begin()

I agree that moving the USB reset to Serial.begin() should be investigated, but I have not had time to look at the existing code to see if there are any pitfalls with this.

arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: USB HID / USB MIDI as libraries

Post by arpruss » Sat Dec 09, 2017 9:30 pm

Serial.begin() calls usb_cdcacm_enable() which calls usb_init_usblib() which calls (via a callback) usbInit() which powers up the USB peripheral.

Serial.end() currently calls usb_cdcacm_disable() which I think should power down the USB peripheral (it does that in my PR).

I am inclined to think the best place for the GENERIC_BOOTLOADER usb reset code for serial is usb_cdcacm_enable(), because that's where the disconnect code is for devices that have disconnect hardware. The only issue I foresee with that is that if a user has an explicit Serial.begin(), then there will be two calls to the usb reset code. I don't know if that's a problem or not.

User avatar
RogerClark
Posts: 7683
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID / USB MIDI as libraries

Post by RogerClark » Sat Dec 09, 2017 11:32 pm

Serial.begin() has some code to prevent it doing anything if its already been called

Code: Select all

    if (_hasBegun)
        return;
Serial.end() has

Code: Select all

	_hasBegun = false;

arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: USB HID / USB MIDI as libraries

Post by arpruss » Sun Dec 10, 2017 1:12 am

Oh, good. So putting the reset code into usb_cdcacm_enable() should work fine.

User avatar
RogerClark
Posts: 7683
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID / USB MIDI as libraries

Post by RogerClark » Sun Dec 10, 2017 5:32 am

I'm not comfortable with a function to power down the USB with no obvious way to power it back up again

I understand its done elsewhere, its just not obvious to anyone looking in the code.

Perhaps we could have a function that can do both enable and disable the USB power, or have separate functions.

arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: USB HID / USB MIDI as libraries

Post by arpruss » Sun Dec 10, 2017 6:46 am

Maybe some comments should just be added. The power up only happens in a call back to the serial device code, after a bunch of configuration things are done by the USBLIB. I wouldn't want to risk moving that elsewhere.

OK.
I didnt mean to move the function. So perhaps some comments would be useful, for anyone else who investigates the USB

arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: USB HID / USB MIDI as libraries

Post by arpruss » Mon Dec 11, 2017 3:44 am

I've added comments about the powerdown and powerup to the PR.

By the way, I still can't get RAWHID host-to-device to work, but host-to-device feature settings now work in the featuresetting branch of the library.

(In theory, one could use host-to-device feature setting to implement a software-forced reset.)

User avatar
RogerClark
Posts: 7683
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID / USB MIDI as libraries

Post by RogerClark » Mon Dec 11, 2017 6:36 am

Re: Host To Host

A few weeks ago, I did try to find if it was possible to send a command via HID, as its supposed to be bi-directional, but did not find anything useful

There was a post on AVRFreaks where someone was using VUSB for HID and wanted to send commands to the AVR but he seemed to have a roadblock with the default HID drivers on Windows, and custom drivers may be required for that functionality

arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: USB HID / USB MIDI as libraries

Post by arpruss » Mon Dec 11, 2017 2:32 pm

No custom drivers seem to be needed. I am using a simple python script and pywinusb to send a feature report from Windows.

Post Reply