2024-12-22 04:48 AM
Hello ST community,
I have a question regarding the HID functionality of an STM32 controller.
I have realised a (driverless!) joystick with an STM32 controller. So far everything works fine.
However, I would like to write additional PC software that can set some properties of my joystick from the PC side. For example, I would like to trigger a calibration of my axes or set the axis sensitivity or define the LED lighting (static!) of my joystick.
Do you have any tips on the best way to do this?
My thoughts:
- Custom HID class ?
Should I create a custom HID class with my own commands?
I had already found a good tutorial here on the ST site, but a type of communication for microcontroller-side calibration or communication with the controller for exchanging settings & data seems to be different?. This method would not make sense for a standard joystick? [As far as I understand it]
- Serial USB connection ? (USB-CDC?)
Since the microcontroller can also be used for serial communication via USB:
Is it possible or useful to implement a serial communication in addition to the HID joystick functionality?
- another method?
Is there a better method than these two to realise this?
I would be grateful for any food for thought here. :)
Best regards
Greg
Solved! Go to Solution.
2025-01-18 06:08 AM
Great project! It sounds like you've already made good progress with your joystick. For adding PC-side configurability, you have a few solid options:
Custom HID Class: This is a clean way to go if you want to stick with a driverless solution. You can extend your HID descriptor to include vendor-defined commands for calibration, sensitivity, or LED settings. However, it adds complexity, as you'll need to ensure both sides (PC and microcontroller) understand the custom protocol.
USB-CDC (Serial): This is a popular choice for additional communication alongside HID. With USB-CDC, you can set up a virtual COM port on the PC, allowing you to send commands and receive responses easily. It's versatile and often simpler to implement for non-standard data like settings or calibration parameters.
Combined Approach: You can implement both HID for joystick functionality and USB-CDC for configuration. Many STM32 controllers support composite USB devices, which let you use multiple interfaces simultaneously.
Alternative Protocols: If you're open to other options, implementing USB-MIDI or even using a different communication bus like I2C or SPI (if supported by your PC setup) could be interesting depending on your goals.
If you're aiming for simplicity and flexibility, I’d lean toward USB-CDC for configurability while keeping HID for the joystick functionality. Just like how the best shakes at Cookout keep things exciting, these methods can enhance your joystick project and make it more enjoyable. Good luck, and let us know how it turns out!
2024-12-22 03:28 PM - edited 2024-12-22 04:37 PM
Implement so called "feature reports" to send commands from host to your HID device.
For Windows: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/hidsdi/nf-hidsdi-hidd_setfeature
(though docum refers to drivers, HidD_SetFeature() is usermode API. Here's a small simple example).
2024-12-23 05:20 AM
Thanks for the advice.
I will take a look at this. :)
2025-01-18 06:08 AM
Great project! It sounds like you've already made good progress with your joystick. For adding PC-side configurability, you have a few solid options:
Custom HID Class: This is a clean way to go if you want to stick with a driverless solution. You can extend your HID descriptor to include vendor-defined commands for calibration, sensitivity, or LED settings. However, it adds complexity, as you'll need to ensure both sides (PC and microcontroller) understand the custom protocol.
USB-CDC (Serial): This is a popular choice for additional communication alongside HID. With USB-CDC, you can set up a virtual COM port on the PC, allowing you to send commands and receive responses easily. It's versatile and often simpler to implement for non-standard data like settings or calibration parameters.
Combined Approach: You can implement both HID for joystick functionality and USB-CDC for configuration. Many STM32 controllers support composite USB devices, which let you use multiple interfaces simultaneously.
Alternative Protocols: If you're open to other options, implementing USB-MIDI or even using a different communication bus like I2C or SPI (if supported by your PC setup) could be interesting depending on your goals.
If you're aiming for simplicity and flexibility, I’d lean toward USB-CDC for configurability while keeping HID for the joystick functionality. Just like how the best shakes at Cookout keep things exciting, these methods can enhance your joystick project and make it more enjoyable. Good luck, and let us know how it turns out!
2025-01-21 01:19 AM
That was detailed, thank you very much. :)