USB Composite library

Working libraries, libraries being ported and related hardware
arpruss
Posts: 83
Joined: Sat Dec 21, 2019 10:06 pm

USB Composite library

Post 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
arpruss
Posts: 83
Joined: Sat Dec 21, 2019 10:06 pm

Re: USB Composite library

Post 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());
  } 
}
arpruss
Posts: 83
Joined: Sat Dec 21, 2019 10:06 pm

Re: USB Composite library

Post 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).
madias
Posts: 35
Joined: Thu Dec 26, 2019 11:51 pm
Answers: 1

Re: USB Composite library

Post by madias »

Thanks again to arpruss making (and further developing) the STM32 to a real USB working horse for me!
arpruss
Posts: 83
Joined: Sat Dec 21, 2019 10:06 pm

Re: USB Composite library

Post 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.
arpruss
Posts: 83
Joined: Sat Dec 21, 2019 10:06 pm

Re: USB Composite library

Post 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.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: USB Composite library

Post by BennehBoy »

Sounds great.
Squonk42
Posts: 16
Joined: Sat Dec 21, 2019 8:35 am

Re: USB Composite library

Post by Squonk42 »

This USB composite library would be great to integrate with the driver-level libusb_stm32 library:
https://github.com/dmitrystu/libusb_stm32
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: USB Composite library

Post 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
arpruss
Posts: 83
Joined: Sat Dec 21, 2019 10:06 pm

Re: USB Composite library

Post 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);
  
}
Post Reply

Return to “Libraries & Hardware”