input_driver.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // input_driver.h — per-controller decode/rumble interface.
  2. //
  3. // A driver claims a connected controller (by VID/PID/name/transport), decodes
  4. // its HID input reports into a puck_input_t, and builds a rumble output report.
  5. // hids_client (BLE) and the Classic HID host both deliver reports as
  6. // (report_id, data, len), so drivers key off report_id directly.
  7. //
  8. // SPDX-License-Identifier: AGPL-3.0-or-later
  9. #ifndef PICOPUCK_INPUT_DRIVER_H
  10. #define PICOPUCK_INPUT_DRIVER_H
  11. #include <stdint.h>
  12. #include <stdbool.h>
  13. #include "puck/triton.h"
  14. typedef struct input_driver {
  15. const char *name;
  16. uint8_t kind; // matches bt_control kind: 1 SC2, 2 BLE gamepad, 3 Classic gamepad
  17. // Claim this device? `is_ble` distinguishes BLE from Classic transports.
  18. bool (*match)(uint16_t vid, uint16_t pid, const char *devname, bool is_ble);
  19. // Decode one input report into `io` (accumulating). Returns true if `io`
  20. // changed and should be presented.
  21. bool (*decode)(uint8_t report_id, const uint8_t *d, uint16_t len,
  22. puck_input_t *io);
  23. // Build a rumble output report from 16-bit magnitudes. Returns its length
  24. // (0 = no rumble); the report id to send it on is `rumble_report_id`.
  25. uint8_t (*build_rumble)(uint16_t lo, uint16_t hi, uint8_t *out, uint8_t max);
  26. uint8_t rumble_report_id;
  27. } input_driver_t;
  28. // First driver whose match() accepts the device, or NULL.
  29. const input_driver_t *input_driver_match(uint16_t vid, uint16_t pid,
  30. const char *devname, bool is_ble);
  31. #endif // PICOPUCK_INPUT_DRIVER_H