USB HID / MIDI / Mass Storage as libraries

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

Re: USB HID / USB MIDI as libraries

Post by arpruss » Tue Dec 12, 2017 8:44 pm

You might also try the solution here:
https://aweirdimagination.net/2015/04/0 ... id-errors/

Also, you can send or post the lsusb output, like in this post: https://bbs.archlinux.org/viewtopic.php ... 2#p1578802

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

Re: USB HID / USB MIDI as libraries

Post by arpruss » Tue Dec 12, 2017 10:57 pm

I've been trying this with an Ubuntu VM on Windows. It works when I turn off the serial in the code (#undef SERIAL_COMPOSITE in composite_usb.h in the current code version), but with serial AND keyboard, it fails.

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

Re: USB HID / USB MIDI as libraries

Post by arpruss » Wed Dec 13, 2017 1:04 am

Now it works under Android and in the Ubuntu VM. The problem was in a descriptor I grabbed from the libarra111 fork.

User avatar
mrburnette
Posts: 2200
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: USB HID / USB MIDI as libraries

Post by mrburnette » Wed Dec 13, 2017 3:41 pm

arpruss wrote:
Wed Dec 13, 2017 1:04 am
Now it works under Android and in the Ubuntu VM. The problem was in a descriptor I grabbed from the libarra111 fork.
This is indeed interesting.

I played much a long time ago with the AVR-specific V-USB implementation. I also played with the ATmega32U4 "micro."

Ray

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

Re: USB HID / USB MIDI as libraries

Post by arpruss » Wed Dec 13, 2017 4:38 pm

What I do need help with is figuring out how to make HID output (host-to-device) reports work. HID feature reports work fine in both directions.

Of course, it's not really needed, except maybe for speed and efficiency. Everything you can do with an output report you can do with a feature report, I think.

anv
Posts: 10
Joined: Mon Dec 11, 2017 1:52 pm

Re: USB HID / USB MIDI as libraries

Post by anv » Wed Dec 13, 2017 6:39 pm

arpruss wrote:
Wed Dec 13, 2017 1:04 am
Now it works under Android and in the Ubuntu VM. The problem was in a descriptor I grabbed from the libarra111 fork.
Yes!! Keyboard now works under linux. If you need tests or USB info from real joysticks, keyboard, mous or midi devices just ask me. I can copy it for you.
I.E. here is the info from a real usb keyboard:

Kernel information (dmesg) when plugging the device:

Code: Select all

[  579.488436] usb 1-4: new low-speed USB device number 7 using xhci_hcd
[  579.663196] usb 1-4: New USB device found, idVendor=0461, idProduct=4e29
[  579.663197] usb 1-4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  579.663198] usb 1-4: Product: Wired USB Keyboard
[  579.663199] usb 1-4: Manufacturer: PRIMAX
[  579.666268] input: PRIMAX Wired USB Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/0003:0461:4E29.0005/input/input19
[  579.717495] hid-generic 0003:0461:4E29.0005: input,hidraw4: USB HID v1.10 Keyboard [PRIMAX Wired USB Keyboard] on usb-0000:00:14.0-4/input0
[  579.723297] input: PRIMAX Wired USB Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.1/0003:0461:4E29.0006/input/input20
[  579.775720] hid-generic 0003:0461:4E29.0006: input,hiddev0,hidraw5: USB HID v1.10 Device [PRIMAX Wired USB Keyboard] on usb-0000:00:14.0-4/input1

USB device information (lsusb -v)

Code: Select all

USB information of the device

Bus 001 Device 008: ID 0461:4e29 Primax Electronics, Ltd 
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x0461 Primax Electronics, Ltd
  idProduct          0x4e29 
  bcdDevice            1.05
  iManufacturer           1 
  iProduct                2 
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           59
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      1 Keyboard
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      65
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     159
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10

anv
Posts: 10
Joined: Mon Dec 11, 2017 1:52 pm

Re: USB HID / USB MIDI as libraries

Post by anv » Wed Dec 13, 2017 6:59 pm

arpruss wrote:
Wed Dec 13, 2017 4:38 pm
What I do need help with is figuring out how to make HID output (host-to-device) reports work. HID feature reports work fine in both directions.

Of course, it's not really needed, except maybe for speed and efficiency. Everything you can do with an output report you can do with a feature report, I think.
May be you could check the HID-project library https://github.com/NicoHood/HID
It works OK reciving data from the host like keyboard leds. See this example (I tested it with an Arduino Leonardo and works ok):

Code: Select all

/*
  Copyright (c) 2014-2015 NicoHood
  See the readme for credit to other people.

  KeyboardLed example

  Press a button to toogle caps lock.
  Caps lock state is represented by the onboard led.
  Leds are only supported on single report HID devices.

  See HID Project documentation for more information.
  https://github.com/NicoHood/HID/wiki/Keyboard-API
*/

#include "HID-Project.h"

const int pinLed = LED_BUILTIN;
const int pinButton = 2;

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(pinButton, INPUT_PULLUP);

  // Sends a clean report to the host. This is important on any Arduino type.
  BootKeyboard.begin();
}


void loop() {
  // Update Led equal to the caps lock state.
  // Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted.
  if (BootKeyboard.getLeds() & LED_CAPS_LOCK)
    digitalWrite(pinLed, HIGH);
  else
    digitalWrite(pinLed, LOW);

  // Trigger caps lock manually via button
  if (!digitalRead(pinButton)) {
    BootKeyboard.write(KEY_CAPS_LOCK);

    // Simple debounce
    delay(300);
  }
}

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

Re: USB HID / USB MIDI as libraries

Post by arpruss » Wed Dec 13, 2017 7:32 pm

anv wrote:
Wed Dec 13, 2017 6:39 pm
arpruss wrote:
Wed Dec 13, 2017 1:04 am
Now it works under Android and in the Ubuntu VM. The problem was in a descriptor I grabbed from the libarra111 fork.
Yes!! Keyboard now works under linux.
But my changes broke feature reports on Windows. I made some more changes and it now seems to work under both Windows and Android. Can you check Linux? (I know Android is Linux, but it might use other USB drivers.)

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

Re: USB HID / USB MIDI as libraries

Post by arpruss » Wed Dec 13, 2017 9:28 pm

Output reports now work. I didn't really have to do anything special once I fixed the descriptors: under the hood, they work just like feature reports. I am learning a bit about USB as I go along.

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

Re: USB HID / USB MIDI as libraries

Post by RogerClark » Wed Dec 13, 2017 10:45 pm

Just a thought, but I noticed someone asking about USB Mass storage...

I recall there was some old code from the leaflabs forum, which I tried a long time ago.

I presume that in theory we could add USB mass storage as a library ???

Post Reply