input_driver.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // input_driver.c — driver registry (see input_driver.h).
  2. //
  3. // SPDX-License-Identifier: AGPL-3.0-or-later
  4. #include "bt/input_driver.h"
  5. #include <stddef.h>
  6. extern const input_driver_t drv_sc2;
  7. extern const input_driver_t drv_xinput;
  8. extern const input_driver_t drv_ds4;
  9. // Future Classic pads (same interface): drv_ds5 (needs CRC32 output + adaptive
  10. // triggers) and drv_switch_pro (needs a subcommand init handshake).
  11. // Most specific first: SC2 (by name/VID) before the generic BLE/Classic matchers.
  12. static const input_driver_t *const REGISTRY[] = {
  13. &drv_sc2,
  14. &drv_xinput,
  15. &drv_ds4,
  16. };
  17. const input_driver_t *input_driver_match(uint16_t vid, uint16_t pid,
  18. const char *devname, bool is_ble)
  19. {
  20. for (size_t i = 0; i < sizeof(REGISTRY) / sizeof(REGISTRY[0]); i++) {
  21. const input_driver_t *d = REGISTRY[i];
  22. if (d->match && d->match(vid, pid, devname, is_ble))
  23. return d;
  24. }
  25. // Safety net: a BLE HOGP device we still can't name (GATT name read failed)
  26. // is almost certainly the gamepad the user paired — the Xbox layout is the
  27. // most common. SC2 is routed separately by the host, so it won't reach here.
  28. if (is_ble)
  29. return &drv_xinput;
  30. return NULL;
  31. }