diff --git a/input/connect/connect_nesusb.c b/input/connect/connect_nesusb.c index bf21fbb901..43f1f2d51b 100644 --- a/input/connect/connect_nesusb.c +++ b/input/connect/connect_nesusb.c @@ -30,7 +30,7 @@ struct hidpad_nesusb_data uint32_t buttons; }; -static void* hidpad_nesusb_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_nesusb_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_nesusb_data* device = (struct hidpad_nesusb_data*) diff --git a/input/connect/connect_ps2adapter.c b/input/connect/connect_ps2adapter.c index 87b174bd4e..c805cb85e2 100644 --- a/input/connect/connect_ps2adapter.c +++ b/input/connect/connect_ps2adapter.c @@ -30,7 +30,7 @@ struct hidpad_ps2adapter_data uint32_t buttons; }; -static void* hidpad_ps2adapter_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_ps2adapter_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_ps2adapter_data* device = (struct hidpad_ps2adapter_data*) diff --git a/input/connect/connect_ps3.c b/input/connect/connect_ps3.c index 7e96e5a7f4..b87c5e4ea6 100644 --- a/input/connect/connect_ps3.c +++ b/input/connect/connect_ps3.c @@ -25,7 +25,7 @@ struct hidpad_ps3_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; uint8_t data[512]; uint32_t slot; uint32_t buttons; @@ -54,13 +54,13 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) report_buffer[6] = device->motors[0] >> 8; #ifdef HAVE_WIIUSB_HID report_buffer[1] = 0x03; /* send control message type */ - device->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1); + device->driver->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1); #else - device->send_control(device->connection, report_buffer, sizeof(report_buffer)); + device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); #endif } -static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_ps3_init(void *data, uint32_t slot, hid_driver_t *driver) { #ifdef HAVE_WIIUSB_HID /* Special command to enable Sixaxis, first byte defines the message type */ @@ -82,12 +82,12 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr) return NULL; } - device->connection = connection; - device->slot = slot; - device->send_control = ptr; + device->connection = connection; + device->slot = slot; + device->driver = driver; #if defined(IOS) || defined(HAVE_WIIUSB_HID) - device->send_control(device->connection, magic_data, sizeof(magic_data)); + device->driver->send_control(device->connection, magic_data, sizeof(magic_data)); #endif #ifndef HAVE_WIIUSB_HID diff --git a/input/connect/connect_ps4.c b/input/connect/connect_ps4.c index ee5ead5c32..0356a91537 100644 --- a/input/connect/connect_ps4.c +++ b/input/connect/connect_ps4.c @@ -98,7 +98,7 @@ struct ps4 struct hidpad_ps4_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; struct ps4 data; uint32_t slot; bool have_led; @@ -119,11 +119,11 @@ static void hidpad_ps4_send_control(struct hidpad_ps4_data* device) report_buffer[11] = rgb[(device->slot % 4)][2]; #endif - device->send_control(device->connection, + device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); } -static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_ps4_init(void *data, uint32_t slot, hid_driver_t *driver) { #if 0 uint8_t magic_data[0x25]; @@ -138,14 +138,14 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr) if (!connection) goto error; - device->connection = connection; - device->slot = slot; - device->send_control = ptr; + device->connection = connection; + device->slot = slot; + device->driver = driver; #if 0 /* TODO - unsure of this */ /* This is needed to get full input packet over bluetooth. */ - device->send_control(device->connection, magic_data, 0x2); + device->driver->send_control(device->connection, magic_data, 0x2); (void)magic_data; #endif diff --git a/input/connect/connect_psxadapter.c b/input/connect/connect_psxadapter.c index b9d2e7f9ba..68f921b0b6 100644 --- a/input/connect/connect_psxadapter.c +++ b/input/connect/connect_psxadapter.c @@ -30,7 +30,7 @@ struct hidpad_psxadapter_data uint32_t buttons; }; -static void* hidpad_psxadapter_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_psxadapter_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_psxadapter_data* device = (struct hidpad_psxadapter_data*) diff --git a/input/connect/connect_snesusb.c b/input/connect/connect_snesusb.c index 62759b51fb..bdc9b16a05 100644 --- a/input/connect/connect_snesusb.c +++ b/input/connect/connect_snesusb.c @@ -31,7 +31,7 @@ struct hidpad_snesusb_data uint32_t buttons; }; -static void* hidpad_snesusb_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_snesusb_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_snesusb_data* device = (struct hidpad_snesusb_data*) diff --git a/input/connect/connect_wii.c b/input/connect/connect_wii.c index 83ac50d736..f02e1735be 100644 --- a/input/connect/connect_wii.c +++ b/input/connect/connect_wii.c @@ -145,7 +145,7 @@ typedef struct connect_wii_wiimote_t int unid; struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; /* Various state flags. */ uint32_t state; @@ -195,7 +195,7 @@ static int wiimote_send(struct connect_wii_wiimote_t* wm, printf("\n"); #endif - wm->send_control(wm->connection, buf, len + 2); + wm->driver->send_control(wm->connection, buf, len + 2); return 1; } @@ -616,7 +616,7 @@ static void hidpad_wii_deinit(void *data) } static void* hidpad_wii_init(void *data, uint32_t slot, - send_control_t ptr) + hid_driver_t *driver) { struct pad_connection *connection = (struct pad_connection*)data; struct connect_wii_wiimote_t *device = (struct connect_wii_wiimote_t*) @@ -628,11 +628,11 @@ static void* hidpad_wii_init(void *data, uint32_t slot, if (!connection) goto error; - device->connection = connection; - device->unid = slot; - device->state = WIIMOTE_STATE_CONNECTED; - device->exp.type = EXP_NONE; - device->send_control = ptr; + device->connection = connection; + device->unid = slot; + device->state = WIIMOTE_STATE_CONNECTED; + device->exp.type = EXP_NONE; + device->driver = driver; wiimote_handshake(device, -1, NULL, -1); diff --git a/input/connect/connect_wiiugca.c b/input/connect/connect_wiiugca.c index 5705a7acdf..92423481f4 100644 --- a/input/connect/connect_wiiugca.c +++ b/input/connect/connect_wiiugca.c @@ -25,13 +25,13 @@ struct hidpad_wiiugca_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; uint8_t data[64]; uint32_t slot; uint32_t buttons; }; -static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_wiiugca_init(void *data, uint32_t slot, hid_driver_t *driver) { static uint8_t magic_data[] = {0x01, 0x13}; /* Special command to enable reading */ struct pad_connection* connection = (struct pad_connection*)data; @@ -47,10 +47,11 @@ static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr) return NULL; } - device->connection = connection; - device->slot = slot; - device->send_control = ptr; - device->send_control(device->connection, magic_data, sizeof(magic_data)); + device->connection = connection; + device->slot = slot; + device->driver = driver; + + device->driver->send_control(device->connection, magic_data, sizeof(magic_data)); return device; } diff --git a/input/connect/connect_wiiupro.c b/input/connect/connect_wiiupro.c index c3787bbe3c..836f17856e 100644 --- a/input/connect/connect_wiiupro.c +++ b/input/connect/connect_wiiupro.c @@ -62,7 +62,7 @@ struct wiiupro_calib struct hidpad_wiiupro_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; struct wiiupro data; uint32_t slot; bool have_led; @@ -75,12 +75,12 @@ static void hidpad_wiiupro_send_control(struct hidpad_wiiupro_data* device) { /* 0x12 = Set data report; 0x34 = All buttons and analogs */ static uint8_t report_buffer[4] = { 0xA2, 0x12, 0x00, 0x34 }; - device->send_control(device->connection, + device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); } static void* hidpad_wiiupro_init(void *data, - uint32_t slot, send_control_t ptr) + uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_wiiupro_data* device = (struct hidpad_wiiupro_data*) @@ -94,9 +94,9 @@ static void* hidpad_wiiupro_init(void *data, if (!connection) goto error; - device->connection = connection; - device->slot = slot; - device->send_control = ptr; + device->connection = connection; + device->slot = slot; + device->driver = driver; calib_data->calib_round = 0; /* Without this, the digital buttons won't be reported. */ diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index 62bb850ce0..a74847ed5a 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -64,7 +64,7 @@ joypad_connection_t *pad_connection_init(unsigned pads) int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char *name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr) + void *data, hid_driver_t *driver) { static const struct @@ -120,7 +120,7 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) { s->iface = pad_map[i].iface; - s->data = s->iface->init(data, pad, ptr); + s->data = s->iface->init(data, pad, driver); s->connected = true; #if 0 RARCH_LOG("%s found \n", pad_map[i].name); diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 75b6dbb633..07f221fd29 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -23,7 +23,7 @@ #include #include -typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size); +#include "../input_driver.h" struct joypad_connection { @@ -34,7 +34,7 @@ struct joypad_connection typedef struct pad_connection_interface { - void* (*init)(void *data, uint32_t slot, send_control_t ptr); + void* (*init)(void *data, uint32_t slot, hid_driver_t *driver); void (*deinit)(void* device); void (*packet_handler)(void* device, uint8_t *packet, uint16_t size); void (*set_rumble)(void* device, enum retro_rumble_effect effect, @@ -58,7 +58,7 @@ extern pad_connection_interface_t pad_connection_psxadapter; int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr); + void *data, hid_driver_t *driver); joypad_connection_t *pad_connection_init(unsigned pads); diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index 6c9d4a4ee8..4dee87a4bb 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -127,7 +127,7 @@ static void wiiu_input_poll(void *data) if(wiiu->joypad) wiiu->joypad->poll(); if(wiiu->hid_joypad) - wiiu->hid_joypad->poll(); + wiiu->hid_joypad->poll(hid_driver_get_data()); } static bool wiiu_key_pressed(int key) diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index 9946e1f6dc..f5bf2abe0e 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -1210,7 +1210,7 @@ static void btpad_packet_handler(uint8_t packet_type, RARCH_LOG("[BTpad]: Got %.200s.\n", (char*)&packet[9]); connection->slot = pad_connection_pad_init(&slots[connection->slot], - (char*)packet + 9, 0, 0, connection, &btpad_connection_send_control); + (char*)packet + 9, 0, 0, connection, &btstack_hid); connection->state = BTPAD_CONNECTED; } break; diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index ec8ec6cbd8..12c06a0157 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -510,7 +510,7 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result, adapter->slot = pad_connection_pad_init(hid->slots, adapter->name, dev_vid, dev_pid, adapter, - &iohidmanager_hid_device_send_control); + &iohidmanager_hid); if (adapter->slot == -1) goto error; diff --git a/input/drivers_hid/libusb_hid.c b/input/drivers_hid/libusb_hid.c index c03004b395..32a3a99dcd 100644 --- a/input/drivers_hid/libusb_hid.c +++ b/input/drivers_hid/libusb_hid.c @@ -308,7 +308,7 @@ static int add_adapter(void *data, struct libusb_device *dev) adapter->slot = pad_connection_pad_init(hid->slots, device_name, desc.idVendor, desc.idProduct, - adapter, &libusb_hid_device_send_control); + adapter, &libusb_hid); if (adapter->slot == -1) goto error; diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 20b9cde356..6e1f8923b8 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -258,13 +258,6 @@ static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32 } -static int32_t wiiu_hid_pad_init(joypad_connection_t *joyconn, - const char *name, uint16_t vid, uint16_t pid, void *data, - send_control_t ptr) { - int pad = pad_connection_find_vacant_pad_max(joyconn, MAX_HID_PADS); - return pad_connection_pad_init_with_slot(joyconn, name, vid, pid, - data, ptr, pad); -} static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event) { } @@ -280,9 +273,9 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { adapter->hid = hid; adapter->handle = event->handle; - adapter->slot = wiiu_hid_pad_init(hid->connections, + adapter->slot = pad_connection_pad_init(hid->connections, "hid", event->vendor_id, event->product_id, adapter, - &wiiu_hid_device_send_control); + &wiiu_hid); if(adapter->slot < 0) { RARCH_ERR("[hid]: No available slots.\n"); diff --git a/input/drivers_hid/wiiu_hid.h b/input/drivers_hid/wiiu_hid.h index ce72c29702..d2f4bc0715 100644 --- a/input/drivers_hid/wiiu_hid.h +++ b/input/drivers_hid/wiiu_hid.h @@ -81,9 +81,6 @@ static int wiiu_hid_polling_thread(int argc, const char **argv); static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); static wiiu_attach_event *synchronized_get_events_list(void); static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list); -static int32_t wiiu_hid_pad_init(joypad_connection_t *joyconn, - const char *name, uint16_t vid, uint16_t pid, void *data, - send_control_t ptr); static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event); static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event); static void synchronized_add_to_adapters_list(struct wiiu_adapter *adapter); diff --git a/input/drivers_hid/wiiusb_hid.c b/input/drivers_hid/wiiusb_hid.c index e50657c64d..f4ded13ba3 100644 --- a/input/drivers_hid/wiiusb_hid.c +++ b/input/drivers_hid/wiiusb_hid.c @@ -322,7 +322,7 @@ static int wiiusb_hid_add_adapter(void *data, usb_device_entry *dev) * control name until we get its interface */ adapter->slot = pad_connection_pad_init(hid->connections, "hid", desc.idVendor, desc.idProduct, - adapter, &wiiusb_hid_device_send_control); + adapter, &wiiusb_hid); if (adapter->slot == -1) goto error; diff --git a/input/input_driver.h b/input/input_driver.h index b30436410f..22df4b1c60 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -193,6 +193,7 @@ struct hid_driver bool (*set_rumble)(void *, unsigned, enum retro_rumble_effect, uint16_t); const char *(*name)(void *, unsigned); const char *ident; + void (*send_control)(void *data, uint8_t *buf, size_t size); int32_t (*set_report)(void *, uint8_t, uint8_t, void *, uint32_t); int32_t (*set_idle)(void *, uint8_t, uint8_t); int32_t (*set_protocol)(void *, uint8_t, uint8_t);