USBComposite, Some help making a gaming HID...
USBComposite, Some help making a gaming HID...
Hi while I still have the opportunity to I wanted to ask a couple of questions about making a USB HID...
Someone mentioned to me the USBComposite library in the core and this seems like the best option to make my custom game controller i have in mind for a project.
The only trouble is the examples included arent very detailed, and dont really make it clear how to set multiple buttons and inputs.
For instance I want 2 analogue sticks and several buttons.
What is the best way to organise all this?
Is there a more detailed example I can look at to get a better idea how best to organise my program?
So I put all my button and analogue state changes into interrupts? Or do i just run the elements of the hid in the main loop, so with each loop it checks the state of each button and analogue stick?
Also is there a more detailed set of documentation of the USBCompoite library? Googling hasnt really found anything.
Such as all the elements and components and how to use them...
Someone mentioned to me the USBComposite library in the core and this seems like the best option to make my custom game controller i have in mind for a project.
The only trouble is the examples included arent very detailed, and dont really make it clear how to set multiple buttons and inputs.
For instance I want 2 analogue sticks and several buttons.
What is the best way to organise all this?
Is there a more detailed example I can look at to get a better idea how best to organise my program?
So I put all my button and analogue state changes into interrupts? Or do i just run the elements of the hid in the main loop, so with each loop it checks the state of each button and analogue stick?
Also is there a more detailed set of documentation of the USBCompoite library? Googling hasnt really found anything.
Such as all the elements and components and how to use them...
- mrburnette
- Posts: 3001
- Joined: Mon Apr 27, 2015 12:50 pm
- Location: Greater Atlanta
- Contact:
Re: USBComposite, Some help making a gaming HID...
Have you go through the post: http://stm32duinoforum.com/forum/viewtopic.php?f=19&t=4046
It has been years since I have done anything with HID, so long ago it was an 8-bit AVR... But, as I remember, it all distills down to keycode combinations.
It has been years since I have done anything with HID, so long ago it was an 8-bit AVR... But, as I remember, it all distills down to keycode combinations.
Re: USBComposite, Some help making a gaming HID...
I did wonder if it could be done in avr, but I think my googlefu is weak... It was only because someone else mentioned usbcomposite as they used it to control a retro arcade...
I'll look through that post now
I'll look through that post now
Re: USBComposite, Some help making a gaming HID...
hid is a very flexible protocol and because of the protocol design, it is complex.
it would be necessary to get familiar with the protocol and you can start with the specs
https://www.usb.org/hid
core to hid protocol are 'report descriptors' which are capable of describing a whole complex set of buttons, controls etc
https://eleccelerator.com/tutorial-abou ... scriptors/
i'm still trying to learn that though. and to get started with a shorter learning curve i think starting with usb composite as a base would help
and get a usb protocol sniffer and app, as i worked in linux, linux has usbmon built-in and i can use wireshark to look at the packets
https://wiki.wireshark.org/CaptureSetup/USB
^^ for windows the above link mentions USBPcap https://desowin.org/usbpcap/
in addition do get familiar with usb itself if you aren't
http://www.usbmadesimple.co.uk/index.html
i've wanted to make a short cut keypad, the blue pill / maple mini is ideal for it, it is literally just wires and key switches (easily available searching ebay / aliexpress for mechanical key switches), and an idea is to throw in rotrary encoders so that they can be used to scroll the pages vert & horiz
but that means the same learning about usb HID
https://hackaday.com/2017/06/19/diy-shortcut-keyboard/
and these days people do wacky stuff with their keyboards
https://hackaday.com/2014/11/23/sprite_ ... ays-snake/
https://youtu.be/enzU9u328Fc

it would be necessary to get familiar with the protocol and you can start with the specs
https://www.usb.org/hid
core to hid protocol are 'report descriptors' which are capable of describing a whole complex set of buttons, controls etc
https://eleccelerator.com/tutorial-abou ... scriptors/
i'm still trying to learn that though. and to get started with a shorter learning curve i think starting with usb composite as a base would help
and get a usb protocol sniffer and app, as i worked in linux, linux has usbmon built-in and i can use wireshark to look at the packets
https://wiki.wireshark.org/CaptureSetup/USB
^^ for windows the above link mentions USBPcap https://desowin.org/usbpcap/
in addition do get familiar with usb itself if you aren't
http://www.usbmadesimple.co.uk/index.html
i've wanted to make a short cut keypad, the blue pill / maple mini is ideal for it, it is literally just wires and key switches (easily available searching ebay / aliexpress for mechanical key switches), and an idea is to throw in rotrary encoders so that they can be used to scroll the pages vert & horiz

but that means the same learning about usb HID
https://hackaday.com/2017/06/19/diy-shortcut-keyboard/
and these days people do wacky stuff with their keyboards
https://hackaday.com/2014/11/23/sprite_ ... ays-snake/
https://youtu.be/enzU9u328Fc

Re: USBComposite, Some help making a gaming HID...
Look at USBHID.h in the library. The HIDJoystick class defines a lot of axes, so two analog sticks aren't a problem, and I think there are 32 buttons available.
You might also look at my GameCube controller to USB adapter code. It's pretty complex as it lets you emulate USB gamepad, Xbox gamepad, and various keyboard configurations, and it supports input from an exercise machine and a Nunchuck, too.
https://github.com/arpruss/gamecube-usb-adapter
You might also look at my GameCube controller to USB adapter code. It's pretty complex as it lets you emulate USB gamepad, Xbox gamepad, and various keyboard configurations, and it supports input from an exercise machine and a Nunchuck, too.
https://github.com/arpruss/gamecube-usb-adapter
Re: USBComposite, Some help making a gaming HID...
There is also this much simpler example code for an adapter from an analog four axis eight button GamePort joystick to USB:
https://github.com/arpruss/GameControll ... tToUSB.ino
https://github.com/arpruss/GameControll ... tToUSB.ino
Re: USBComposite, Some help making a gaming HID...
Interesting, is there any way to convert from an up/down left/right micro-switched joystick for X & Y rather than an analogue input?arpruss wrote: ↑Fri Mar 08, 2019 2:23 pmThere is also this much simpler example code for an adapter from an analog four axis eight button GamePort joystick to USB:
https://github.com/arpruss/GameControll ... tToUSB.ino
-------------------------------------
https://github.com/BennehBoy
https://github.com/BennehBoy
Re: USBComposite, Some help making a gaming HID...
hi apruss, cool project and
the instructables is awesome
https://www.instructables.com/id/Gamecu ... ng-Starte/
and wow it seem you have already done it in USB composite itself, the sketch merely shows the 'high level' parts of it
i think i should spend some effort to pick up on usb hid too 
the instructables is awesome
https://www.instructables.com/id/Gamecu ... ng-Starte/
and wow it seem you have already done it in USB composite itself, the sketch merely shows the 'high level' parts of it

Code: Select all
#include
#include
USBHID HID;
HIDKeyboard Keyboard(HID);
HIDJoystick Joystick(HID);
HIDMouse Mouse(HID);
void setup() {
USBHID.begin(HID_KEYBOARD_MOUSE_JOYSTICK);
while (!usb_is_connected(USBLIB) || !usb_is_configured(USBLIB)) delay(100);
Keyboard.println("Hello world!");
}
void loop() {
Joystick.X(0);
Joystick.Y(0);
digitalWrite(PB12, 0);
delay(500);
Joystick.X(1023);
Joystick.Y(1023);
delay(500);
digitalWrite(PB12, 1);
}

- mrburnette
- Posts: 3001
- Joined: Mon Apr 27, 2015 12:50 pm
- Location: Greater Atlanta
- Contact:
Re: USBComposite, Some help making a gaming HID...
HID is not just for keyboards and joysticks, one can also do serious data-logging, too:
https://www.hackster.io/rayburne/rpi-da ... ng-usb-hid
https://www.hackster.io/rayburne/arduin ... sing-v-usb
https://www.hackster.io/rayburne/analog ... viewer-usb
Or, a clone of Adafruit's tiny85 Trinket
https://www.hackster.io/rayburne/chachk ... ny85-clone
Or, a tiny85 DigiSpark
https://www.hackster.io/rayburne/trinke ... e-exorcism
From the old arduino.cc forum, some now ancient examples that would be easy to implement with the STM32F1xx HID library:
http://forum.arduino.cc/index.php?topic=135623.0
Point is, HID is a gateway drug to cross over USB.
Ray
https://www.hackster.io/rayburne/rpi-da ... ng-usb-hid
https://www.hackster.io/rayburne/arduin ... sing-v-usb
https://www.hackster.io/rayburne/analog ... viewer-usb
Or, a clone of Adafruit's tiny85 Trinket
https://www.hackster.io/rayburne/chachk ... ny85-clone
Or, a tiny85 DigiSpark
https://www.hackster.io/rayburne/trinke ... e-exorcism
From the old arduino.cc forum, some now ancient examples that would be easy to implement with the STM32F1xx HID library:
http://forum.arduino.cc/index.php?topic=135623.0
Point is, HID is a gateway drug to cross over USB.
Ray
Re: USBComposite, Some help making a gaming HID...
thanks ray, it gives me more incentive to explore hid from there, usb-serial is 'universal' but 'artificially slow', there is little reason not to use the full 10mbps usb-full speed rather than artificially limiting to 115200 bps. i think the main reason usb-serial exist is due to the ubiquitous virtual com: ports, most apps works without programming wizardry and few people wants to venture into 'driver' stuff especially on the desktop 
