Add UHID gamepad rumble WIP

This commit is contained in:
Romain Vimont 2024-09-06 23:08:08 +02:00
parent e5c7840530
commit b54b0a6958
5 changed files with 39 additions and 4 deletions

View file

@ -724,6 +724,7 @@ aoa_complete:
#endif
struct sc_keyboard_uhid *uhid_keyboard = NULL;
struct sc_gamepad_uhid *uhid_gamepad = NULL;
if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_SDK) {
sc_keyboard_sdk_init(&s->keyboard_sdk, &s->controller,
@ -758,8 +759,8 @@ aoa_complete:
}
struct sc_uhid_devices *uhid_devices = NULL;
if (uhid_keyboard) {
sc_uhid_devices_init(&s->uhid_devices, uhid_keyboard);
if (uhid_keyboard || uhid_gamepad) {
sc_uhid_devices_init(&s->uhid_devices, uhid_keyboard, uhid_gamepad);
uhid_devices = &s->uhid_devices;
}

View file

@ -3,6 +3,7 @@
#include "hid/hid_gamepad.h"
#include "input_events.h"
#include "util/log.h"
#include "util/str.h"
/** Downcast gamepad processor to sc_gamepad_uhid */
#define DOWNCAST(GP) container_of(GP, struct sc_gamepad_uhid, gamepad_processor)
@ -105,6 +106,22 @@ sc_gamepad_processor_process_gamepad_button(struct sc_gamepad_processor *gp,
}
void
sc_gamepad_uhid_process_hid_output(struct sc_gamepad_uhid *gamepad,
uint16_t hid_id, const uint8_t *data,
size_t size) {
(void) gamepad;
char *hex = sc_str_to_hex_string(data, size);
if (hex) {
LOGI("==== HID output [%" PRIu16 "] %s", hid_id, hex);
free(hex);
} else {
LOGI("==== HID output [%" PRIu16 "]", hid_id);
}
// TODO
}
void
sc_gamepad_uhid_init(struct sc_gamepad_uhid *gamepad,
struct sc_controller *controller) {

View file

@ -20,4 +20,9 @@ void
sc_gamepad_uhid_init(struct sc_gamepad_uhid *mouse,
struct sc_controller *controller);
void
sc_gamepad_uhid_process_hid_output(struct sc_gamepad_uhid *gamepad,
uint16_t hid_id, const uint8_t *data,
size_t size);
#endif

View file

@ -4,12 +4,15 @@
#include <inttypes.h>
#include "uhid/keyboard_uhid.h"
#include "uhid/gamepad_uhid.h"
#include "util/log.h"
void
sc_uhid_devices_init(struct sc_uhid_devices *devices,
struct sc_keyboard_uhid *keyboard) {
struct sc_keyboard_uhid *keyboard,
struct sc_gamepad_uhid *gamepad) {
devices->keyboard = keyboard;
devices->gamepad = gamepad;
}
void
@ -21,6 +24,13 @@ sc_uhid_devices_process_hid_output(struct sc_uhid_devices *devices, uint16_t id,
} else {
LOGW("Unexpected keyboard HID output without UHID keyboard");
}
} else if (id >= SC_HID_ID_GAMEPAD_FIRST && id <= SC_HID_ID_GAMEPAD_LAST) {
if (devices->gamepad) {
sc_gamepad_uhid_process_hid_output(devices->gamepad, id, data,
size);
} else {
LOGW("Unexpected gamepad HID output without UHID gamepad");
}
} else {
LOGW("HID output ignored for id %" PRIu16, id);
}

View file

@ -14,11 +14,13 @@
struct sc_uhid_devices {
struct sc_keyboard_uhid *keyboard;
struct sc_gamepad_uhid *gamepad;
};
void
sc_uhid_devices_init(struct sc_uhid_devices *devices,
struct sc_keyboard_uhid *keyboard);
struct sc_keyboard_uhid *keyboard,
struct sc_gamepad_uhid *gamepad);
void
sc_uhid_devices_process_hid_output(struct sc_uhid_devices *devices, uint16_t id,