Page 1 of 2

USB Composite library

Posted: Sun Dec 22, 2019 4:37 am
by arpruss
I've reworked how my USB Composite library allocates endpoints to allow for more devices to be composited together.

Previously, RX and TX endpoints weren't allowed to share the same number. But there is no reason why they can't do that. So, now they can, though only within the same plugin.

I also reworked the xbox360 plugin so it can be composited better.

https://github.com/arpruss/USBComposite_stm32f1

Re: USB Composite library

Posted: Wed Dec 25, 2019 4:03 am
by arpruss
I added a USBMultiSerial plugin which allows for up to three USB serial ports.

Code: Select all

#include <USBComposite.h>

USBMultiSerial<2> ms;

void setup() {
  ms.begin();
}

void loop() {
  while(ms.ports[1].available()) {
    ms.ports[0].write(ms.ports[1].read());
  }
  while(ms.ports[0].available()) {
    ms.ports[1].write(ms.ports[0].read());
  } 
}

Re: USB Composite library

Posted: Thu Dec 26, 2019 8:45 pm
by arpruss
I rewrote USBXBox360 to allow for multiple controllers, with a backwards-compatible USBXBox360 class and a new template USBMultiXBox360<n>, which allows up to four controllers. Example code: https://github.com/arpruss/USBComposite ... box360.ino

If you want more than four controllers (the hardware should support up to seven), you can try to just change a define in usb_multi_x360.h (untested).

Re: USB Composite library

Posted: Fri Dec 27, 2019 12:23 am
by madias
Thanks again to arpruss making (and further developing) the STM32 to a real USB working horse for me!

Re: USB Composite library

Posted: Sat Dec 28, 2019 4:06 pm
by arpruss
I just added emulation of XBox 360 wireless. The battery status messages are currently static and fake, and I haven't tested everything.

The advantage of the XBox 360 wireless plugin over the wired multi XBox 360 controller plugin is that with wireless you can send connect/disconnect messages for the controllers.

Re: USB Composite library

Posted: Thu Jan 09, 2020 7:56 pm
by arpruss
I am working on making HID support easier to use. If it all works out, then two joysticks, a mouse and a keyboard could be put in one device as follows:

Code: Select all

#include <USBComposite.h>

USBHID HID;
HIDJoystick Joystick1(HID);
HIDJoystick Joystick2(HID);
HIDKeyboard Keyboard(HID);
HIDMouse Mouse(HID);

setup() {
  USBHID.begin();
}
The current code would require putting together a custom device report descriptor and passing it to USBHID.begin().

I am trying to keep full backwards compatibility, which makes things more complicated.

Re: USB Composite library

Posted: Thu Jan 09, 2020 11:24 pm
by BennehBoy
Sounds great.

Re: USB Composite library

Posted: Fri Jan 10, 2020 5:42 am
by Squonk42
This USB composite library would be great to integrate with the driver-level libusb_stm32 library:
https://github.com/dmitrystu/libusb_stm32

Re: USB Composite library

Posted: Fri Jan 10, 2020 6:11 am
by ag123
it sounds like we can have different 'usb libraries' even if things like tiny-usb is adopted.
the reason is that tiny-usb seem to be aimed as 'cross platform' this would likely have a 'lowest common denominator' limitation for the api
while usb composite can be made into a more 'stm32 fitted' one, with additional features etc. (e.g. combo stacks) i need to spend a little time playing with it
have not really started on it yet

Re: USB Composite library

Posted: Wed Jan 15, 2020 4:58 pm
by arpruss
I've just merged my abstracted branch.

Now, all the hardware dependent code is in usb_generic.c.

Also, the simplified USB HID profile code is in place, so you can do things like this:

Code: Select all

#include <USBComposite.h>

USBHID HID;
HIDMouse mouse(HID);
HIDJoystick joystick(HID);
HIDJoystick joystick2(HID);

void setup() {
  HID.begin();
}

void loop() {
  mouse.move(0,5);
  joystick.X(0);
  joystick2.Y(0);
  delay(1000);
  mouse.move(0,-5);
  joystick.X(151);
  joystick2.Y(199);
  delay(1000);
  
}