upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/gameinput.md
diff options
context:
space:
mode:
authorBora Sevim <sevimbora@gmail.com>2026-11-22 22:35:50 +0300
committerBora Sevim <sevimbora@gmail.com>2026-11-22 22:35:50 +0300
commit364fdcbd28feb1708fd28b4727b3cc8f4a1ad1a7 (patch)
treeacce8da5f81d727993a9cbc8bb11400d89fecda9 /docs/gameinput.md
parent162821017ea3c286c8bec860f3ff94f037912061 (diff)
gameinput: raw HID reports and raw device I/O through SDL's hidapi (RT-175)
The shim opens each pad's HID device with SDL_hid_* (by SDL's device path, else the one game-pad collection with the pad's vendor and product id) and reads its report descriptor for every input, output and feature report's id and size. Such a pad reports GameInputKindRawDeviceReport and GameInputDeviceRawIoEnabled and fills inputReportInfo, outputReportInfo and featureReportInfo (no item tables). Readings carry the newest raw input report, and IGameInputReading::GetRawReport returns it as an IGameInputRawDeviceReport. CreateRawDeviceReport, GetRawDeviceFeature, SetRawDeviceFeature and SendRawDeviceOutput work through the backend; an undeclared id or kind is E_INVALIDARG, a failed transfer E_FAIL, and a pad without a HID device keeps E_NOTIMPL. gameinput_abi.h declares IGameInputRawDeviceReport, GameInputRawDeviceReportKind and the three raw report info structs, checked against Microsoft's v0 header (offsetof for every field, the 12 vtable slots, the IID). Xbox pads on Windows go through XInput, whose HID interface SDL's hidapi skips, so they have no raw I/O; the log says so. gameinput_test covers the descriptor parser and the whole path with a fake HID backend (24 checks); gameinput_probe prints each pad's report tables and newest raw input report. docs/gameinput.md: "Raw HID".
Diffstat (limited to 'docs/gameinput.md')
-rw-r--r--docs/gameinput.md67
1 files changed, 63 insertions, 4 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md
index ab5fa2feb..4496820e6 100644
--- a/docs/gameinput.md
+++ b/docs/gameinput.md
@@ -201,14 +201,56 @@ The API surface:
201| interface | implemented | not implemented | 201| interface | implemented | not implemented |
202|---|---|---| 202|---|---|---|
203| `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `GetPreviousReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetTemporalReading` (`E_NOTIMPL`, as in GameInput v0 itself; see below), `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | 203| `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `GetPreviousReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetTemporalReading` (`E_NOTIMPL`, as in GameInput v0 itself; see below), `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` |
204| `IGameInputReading` | kind, sequence number, timestamp, device, gamepad state, UI navigation state, controller axes and buttons, motion state | raw report, keyboard, mouse, touch, arcade/flight stick, racing wheel (all return nothing) | 204| `IGameInputReading` | kind, sequence number, timestamp, device, gamepad state, UI navigation state, controller axes and buttons, motion state, raw report (pads opened through HID, see [Raw HID](#raw-hid)) | keyboard, mouse, touch, arcade/flight stick, racing wheel (all return nothing) |
205| `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | 205| `IGameInputDevice` | device info, status, battery, `SetRumbleState`, `CreateRawDeviceReport`, `GetRawDeviceFeature`, `SetRawDeviceFeature`, `SendRawDeviceOutput` (pads opened through HID) | force feedback and haptic motors (none reported), `SendRawDeviceOutputWithResponse`, `ExecuteRawDeviceIoControl`, exclusive raw access, power off, input synchronization (no-ops) |
206| `IGameInputRawDeviceReport` | device, report info (kind, id, size), raw data size, get and set raw data | item values (`Get/Set/ResetItemValue`, `ResetAllItems` answer false: no item tables) |
206| `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | 207| `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) |
207 208
208A device object stays alive for the whole process. When a pad is unplugged its status drops to 209A device object stays alive for the whole process. When a pad is unplugged its status drops to
209`GameInputDeviceNoStatus` and its device callback runs; when the same pad is plugged in again (matched by SDL GUID and 210`GameInputDeviceNoStatus` and its device callback runs; when the same pad is plugged in again (matched by SDL GUID and
210serial or device path) the title gets the same object back, connected again. 211serial or device path) the title gets the same object back, connected again.
211 212
213## Raw HID
214
215A title can read a pad's raw HID input reports and send it output and feature reports (RT-175). The shim opens each
216pad's HID device through SDL's hidapi (`SDL_hid_*`), by the device path SDL reports for the pad. When that path is not
217a HID path, it falls back to the pad's vendor and product id, but only when exactly one game-pad collection (usage page
2181, usage 5) has them, so twins never mix. It reads the report descriptor to find every input, output and feature
219report: its id (0 when the descriptor declares none) and its payload size in bytes, without the id byte.
220
221A pad opened this way gets the following:
222
223- `GameInputKindRawDeviceReport` in `supportedInput` and `GameInputDeviceRawIoEnabled` in its status.
224- `inputReportInfo`, `outputReportInfo` and `featureReportInfo` tables with their counts. Every report has `itemCount`
225 0: the descriptor's items (usages, logical ranges, units) are not decoded.
226- Readings that carry the newest raw input report. Each poll drains the reports that arrived, the last declared one
227 wins, and a report with new bytes makes a reading of its own. Before the first report, a reading carries none.
228- These device calls, each on any `IGameInputRawDeviceReport` of the right kind whose id the pad declares:
229 - `CreateRawDeviceReport(id, kind)` makes a zeroed report.
230 - `GetRawDeviceFeature(id)` reads a feature report.
231 - `SetRawDeviceFeature` sends one.
232 - `SendRawDeviceOutput` writes an output report.
233
234 An undeclared id or kind is `E_INVALIDARG`, and a failed transfer `E_FAIL`.
235
236`SetRawData` takes a buffer of exactly the report's size and refuses any other size, so a report is never half old and
237half new. The item calls answer false. `SendRawDeviceOutputWithResponse`, `ExecuteRawDeviceIoControl` and exclusive
238access still return `E_NOTIMPL` / false.
239
240A pad without such a HID device keeps the old answers: no raw kind, no tables, `E_NOTIMPL` from the raw calls.
241
242- **Xbox pads on Windows** are read by SDL through XInput (path `XInput#n`). SDL's hidapi skips their XInput HID
243 interface (`&IG_` in the path), noting that it carries no full HID reports. So they have no raw I/O here, and the log
244 says so.
245- **SDL virtual joysticks and the keyboard pad** have no path, so no HID device either.
246- **Pads SDL reads through hidapi** can have raw I/O: DualSense, DualShock 4, Switch Pro, and most others in DirectInput
247 mode.
248
249`rt::gameinput::set_hid_backend` replaces the hidapi backend (tests). `rt::gameinput::parse_report_descriptor` is the
250descriptor walk: main items Input, Output and Feature add Report Size × Report Count bits to the current Report ID, Push
251and Pop save and restore the globals, and long items are skipped. It refuses a truncated item, Report ID 0 or above
252255, a Pop without a Push, and a report over 64 KiB.
253
212## Reading history 254## Reading history
213 255
214Each pad keeps the readings the poll took for it, one per change it saw, so `GetNextReading` and `GetPreviousReading` 256Each pad keeps the readings the poll took for it, one per change it saw, so `GetNextReading` and `GetPreviousReading`
@@ -280,8 +322,16 @@ shim fills (`GameInputDeviceInfo` 320 bytes with `deviceFamily` at 96 and the in
280 binding, two keys at once, each WASD direction, opposite keys cancelling, diagonals, the mouse moving the right 322 binding, two keys at once, each WASD direction, opposite keys cancelling, diagonals, the mouse moving the right
281 stick, clamping and decaying to 0, the mouse-button triggers, no input out of focus, release of buttons, sticks and 323 stick, clamping and decaying to 0, the mouse-button triggers, no input out of focus, release of buttons, sticks and
282 triggers on focus loss, the `always` mode, and turning it off and on again. 324 triggers on focus loss, the `always` mode, and turning it off and on again.
283- `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and 325 Raw HID (RT-175) is tested in two ways:
284 trigger for a second with `--rumble`, then prints the live reading. 326 - `parse_report_descriptor` runs on synthetic descriptors: report ids, none, Push/Pop, a long item, and the refused
327 forms.
328 - A fake backend (`set_hid_backend`) stands behind a virtual pad with pid.codes test ids. The test checks the report
329 tables, the kind and status bits, a reading's raw report (newest declared id, without the id byte, an undeclared id
330 ignored), creating, sending and reading back output and feature reports with their id byte, `SetRawData`'s exact
331 size, the item calls, `E_INVALIDARG` / `E_FAIL` / `E_NOTIMPL`, and the HID device closing on unplug.
332- `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads with each one's raw HID
333 report tables (or why it has none), plays each motor and trigger for a second with `--rumble`, then prints the live
334 reading and the newest raw input report.
285 335
286## VERIFY 336## VERIFY
287 337
@@ -323,3 +373,12 @@ These need the game executable or a test on hardware:
323 near center or jumpy. 373 near center or jumpy.
324- **DualSense effect parameters**: the `06` (vibration) and `01` (resistance) byte meanings follow SDL's 374- **DualSense effect parameters**: the `06` (vibration) and `01` (resistance) byte meanings follow SDL's
325 `testcontroller.c`; how strong 255 feels and what frequency suits the Xbox signal needs a session on a real pad. 375 `testcontroller.c`; how strong 255 feels and what frequency suits the Xbox signal needs a session on a real pad.
376- **Raw HID on a real pad**: only the synthetic tests and the XInput refusal have run.
377 - What ran: an Xbox Series X controller over Bluetooth on Windows 11 connects and plays normally, with no raw I/O,
378 and the log names the reason.
379 - Still to confirm: a DualSense, DualShock 4 or Switch Pro through `gameinput_probe`, which should print the
380 descriptor's reports and changing raw input bytes.
381 - Size convention: report sizes exclude the id byte, and `GetRawData` returns the payload without it. What
382 Microsoft's runtime does for a device with report ids is not documented on the reference pages.
383 - Readings: a pad that streams reports makes a reading for each changed one, like the runtime's
384 `GameInputKindRawDeviceReport` stream, but whether the title asks for raw reports at all is unknown.