Skip to content

hidapi / sysjoystick: Support Santroller devices - #16651

Open
sanjay900 wants to merge 25 commits into
libsdl-org:mainfrom
sanjay900:fetch-subtype-via-udev
Open

sanjay900 wants to merge 25 commits into
libsdl-org:mainfrom
sanjay900:fetch-subtype-via-udev

Conversation

@sanjay900

@sanjay900 sanjay900 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

I created the Santroller firmware, which is used by the rhythm gaming community for emulating various rhythm game related peripherals.

I recently released Santroller 2, which was a complete rewrite and has the ability to emulate a sort of hub, where a user can plug multiple peripherals into it, and it presents itself as a composite USB device that either has multiple HID interfaces or multiple XInput interfaces, depending on what mode the user is using.

This adds support for either mode, via both hidapi and sysjoystick.

The older firmware only supported emulating a single device at a time, so its the simplest case - the joystick type is simply just placed in the usb devices revision so we simply pull that out and use it as is. Bluetooth works like this as well, as Santroller 1 and Santroller 2 only ever emulate a single device over bluetooth.

Since the newer firmware can emulate multiple devices, that wasn't going to work. As a result, I implemented a hid output / input reported based capabilities report that can be requested, which lets you retrieve things like what is device type is in use and what capabilities the device has.

For XInput and hid via sysjoystick, we needed another method to get the joystick type. I took a page from what i had implemented in SDL_hidapi_xbox360.c a while ago, where i simply just parse the usb descriptor to find the vendor descriptor that tells us the subtype. Using udev we can get the sysfs path to the usb descriptor, and then parse that out to figure out the subtype.

This worked so well that i just implemented a vendor descriptor for santroller 2 as well that contains the capabilities, so we can get the device type that way.

I didn't really like having a block hardcoded in multiple places for resolving subtypes / santroller types to their joystick type counterparts, so i pulled out some helper methods so we could handle it all in one place. I also pulled in my list of subtypes that i have built from looking at instruments over the years - there are a bunch of extra subtypes that microsoft has not documented that we can use for matching rhythm game peripherals.

Note that this XInput support extends to any wired XInput device handled via xpad, the subtype is directly pulled from the controller now instead of relying on the vids and pids being in the controller list.

Since i have all these extra types around now, i also added a musical keyboard and turntable joystick type.

@sanjay900
sanjay900 force-pushed the fetch-subtype-via-udev branch 3 times, most recently from a172122 to 6aefb35 Compare November 4, 2026 03:51
@sanjay900 sanjay900 changed the title sysjoystick: Fetch xinput subtypes via udev for xpad based joysticks sysjoystick: Fetch joystick types via udev for some sysjoystick devices on linux Nov 4, 2026
@sanjay900
sanjay900 force-pushed the fetch-subtype-via-udev branch 3 times, most recently from a2eab0c to 72c4871 Compare November 4, 2026 06:53
@sanjay900 sanjay900 changed the title sysjoystick: Fetch joystick types via udev for some sysjoystick devices on linux hidapi / sysjoystick: Support Santroller devices Nov 4, 2026
@sanjay900

Copy link
Copy Markdown
Contributor Author

Only real thing i was unsure about is where to put SDL_SantrollerSubType and SDL_XInputSubType, if we want them to live somewhere else we can certainly move them

Comment thread src/joystick/linux/SDL_sysjoystick.c Resolved
Comment thread src/joystick/SDL_joystick_c.h Resolved
Comment thread src/joystick/SDL_joystick_c.h Resolved
Comment thread src/core/linux/SDL_udev.c
_this->syms.udev_device_unref(dev);

return found;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a very expensive function. Do you know how often it'll be called?

@sanjay900 sanjay900 Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would only get called when MaybeAddDevice is called, since its only used by IsJoystick
The input scanning would bail out early before reaching IsJoystick as well so it should only really happen when a new joystick is plugged in, or at startup when scanning all plugged in joysticks for the first time

It only does the expensive descriptor trawl for new santroller devices via hid or new wired xinput devices via xpad, never other hid devices or wireless xinput devices

Comment thread include/SDL3/SDL_joystick.h Resolved
@sanjay900
sanjay900 force-pushed the fetch-subtype-via-udev branch from c6e94a5 to 95ff1e3 Compare November 7, 2026 18:47
@sanjay900
sanjay900 force-pushed the fetch-subtype-via-udev branch from ff6a315 to a49c53c Compare November 7, 2026 18:50
@sanjay900
sanjay900 requested a review from slouken November 8, 2026 20:54
@slouken slouken added this to the 3.8.0 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants