2014-10-04 18:41:23 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2016-02-04 17:01:03 -05:00
|
|
|
*
|
2014-10-04 18:41:23 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _JOYPAD_CONNECTION_H
|
|
|
|
#define _JOYPAD_CONNECTION_H
|
|
|
|
|
2014-10-04 19:14:04 +02:00
|
|
|
#include <stdint.h>
|
2014-10-04 19:07:59 +02:00
|
|
|
#include <stddef.h>
|
2015-11-28 02:31:19 +01:00
|
|
|
|
2016-05-10 19:03:53 +02:00
|
|
|
#include <libretro.h>
|
2017-11-28 10:04:34 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2017-12-24 18:29:00 -08:00
|
|
|
#include <retro_endianness.h>
|
2017-12-12 22:55:10 -08:00
|
|
|
#include "../input_driver.h"
|
2014-10-04 22:05:38 +02:00
|
|
|
|
2022-09-04 02:02:51 +02:00
|
|
|
/* Gekko (NGC/Wii) has PID/VID already swapped by USB_GetDescriptors from libogc, so skip bigendian byteswap */
|
|
|
|
#if defined(MSB_FIRST) && !defined(GEKKO)
|
|
|
|
#define SWAP_IF_BIG(val) ((((val) & 0x00ff) << 8) | (((val) & 0xff00) >> 8))
|
2019-07-12 17:05:24 +02:00
|
|
|
#else
|
2022-09-04 02:02:51 +02:00
|
|
|
#define SWAP_IF_BIG(val) (val)
|
2019-07-12 17:05:24 +02:00
|
|
|
#endif
|
|
|
|
|
2017-12-27 15:15:01 -08:00
|
|
|
#define VID_NONE 0x0000
|
2019-07-12 17:05:24 +02:00
|
|
|
#define VID_NINTENDO SWAP_IF_BIG(0x057e)
|
|
|
|
#define VID_SONY SWAP_IF_BIG(0x054c)
|
|
|
|
#define VID_MICRONTEK SWAP_IF_BIG(0x0079)
|
|
|
|
#define VID_PCS SWAP_IF_BIG(0x0810)
|
|
|
|
#define VID_PS3_CLONE SWAP_IF_BIG(0x0313)
|
|
|
|
#define VID_SNES_CLONE SWAP_IF_BIG(0x081f)
|
2019-08-09 13:42:15 +02:00
|
|
|
#define VID_RETRODE SWAP_IF_BIG(0x0403)
|
2020-09-04 17:50:10 +06:00
|
|
|
#define VID_HORI_1 SWAP_IF_BIG(0x0f0d)
|
2022-11-02 23:00:42 -03:00
|
|
|
#define VID_KADE SWAP_IF_BIG(0x10c4)
|
|
|
|
#define VID_DRAGONRISE SWAP_IF_BIG(0x0079)
|
2017-12-24 18:29:00 -08:00
|
|
|
|
2017-12-27 15:15:01 -08:00
|
|
|
#define PID_NONE 0x0000
|
2019-07-12 17:05:24 +02:00
|
|
|
#define PID_NINTENDO_PRO SWAP_IF_BIG(0x0330)
|
|
|
|
#define PID_SONY_DS3 SWAP_IF_BIG(0x0268)
|
|
|
|
#define PID_SONY_DS4 SWAP_IF_BIG(0x05c4)
|
Fix some HID bugs (#14435)
* Fix Sixaxis gamepad operation
== DETAILS
It looks like commit 78e7d23c144c862d65ae1bf7ee41a1228bdfa380 broke
the DualShock. Sorry, @revvv, but this is probably going to break the
Retrode driver. We'll need to figure out a different solution.
* Fix a bunch of HID implementations
== DETAILS
As mentioned in the previous commit, the thing that broke the DS3
driver was a change to the wiiu HID handler, which did some pointer
math on the data buffer.
The thing is.. there's no reason to do that pointer math. Yet, I found
the same thing on almost every other HID driver: OSX, libusb, wiiusb.
The only other HID driver that did not do this was the Bluetooth
HID driver.
It doesn't make any sense. The only reason it doesn't crash is because
the memory right before the buffer is valid memory.
Change summary:
- remove the weird pointer math from all HID controllers
- remove the `#ifdef apple ...` in the ds3 and gamecube adapter
drivers, because it's no longer needed.
- in the pad packet handlers, decrement data buffer offset references
to account for the removal of the buffer manipulation.
* Fix DualShock 4
== DETAILS
Should've only subtracted 1, not 2; and now the pad works.
Also, added a PID to cover newer model DS4s. I picked "R2" out of the air
for the constant.
Tested on Mac OS
* Really really fix iohidmanager_set_report
A huge apology to @23rd for insulting your fix. I was wrong to call you
wrong.
That left the question: why did that change break the DS3?
Well, it's because `IOHIDDeviceSetReport` expects the report buffer to be
just the report. All of RA's HID SetReport calls include the report number
in the first byte, so we have to trim that off.
We actually do this in a different invocation of `IOHIDDeviceSetReport`
elsewhere in the file! This commit applies that same logic to
`iohidmanager_set_report`
This has two benefits:
1. The DS3 works
2. The DS3 no longer requres the user to press the PS button to activate
it the first time. You plug it in and it Just Works, just like on Wii U.
2022-09-26 05:32:49 -07:00
|
|
|
#define PID_SONY_DS4_R2 SWAP_IF_BIG(0x09cc)
|
2019-07-12 17:05:24 +02:00
|
|
|
#define PID_DS3_CLONE SWAP_IF_BIG(0x20d6)
|
|
|
|
#define PID_SNES_CLONE SWAP_IF_BIG(0xe401)
|
|
|
|
#define PID_MICRONTEK_NES SWAP_IF_BIG(0x0011)
|
|
|
|
#define PID_NINTENDO_GCA SWAP_IF_BIG(0x0337)
|
|
|
|
#define PID_PCS_PS2PSX SWAP_IF_BIG(0x0001)
|
|
|
|
#define PID_PCS_PSX2PS3 SWAP_IF_BIG(0x0003)
|
2019-08-09 13:42:15 +02:00
|
|
|
#define PID_RETRODE SWAP_IF_BIG(0x97c1)
|
2020-09-04 17:50:10 +06:00
|
|
|
#define PID_HORI_MINI_WIRED_PS4 SWAP_IF_BIG(0x00ee)
|
2022-11-02 23:00:42 -03:00
|
|
|
#define PID_KADE SWAP_IF_BIG(0x82c0)
|
|
|
|
#define PID_DRAGONRISE SWAP_IF_BIG(0x0006)
|
2017-12-24 18:29:00 -08:00
|
|
|
|
2015-11-17 06:54:59 +01:00
|
|
|
struct joypad_connection
|
|
|
|
{
|
|
|
|
struct pad_connection_interface *iface;
|
2021-10-03 23:27:07 +00:00
|
|
|
input_device_driver_t *input_driver;
|
2015-11-17 06:54:59 +01:00
|
|
|
void* data;
|
2021-08-06 22:02:43 -05:00
|
|
|
void* connection;
|
2020-08-15 02:55:29 +02:00
|
|
|
bool connected;
|
2015-11-17 06:54:59 +01:00
|
|
|
};
|
|
|
|
|
2021-10-03 23:27:07 +00:00
|
|
|
#define PAD_CONNECT_OFFLINE 0x00 /* the pad is offline and cannot be used */
|
|
|
|
#define PAD_CONNECT_READY 0x01 /* the pad is ready but is not bound to a RA slot */
|
|
|
|
#define PAD_CONNECT_BOUND 0x02 /* the pad is offline and is bound to a RA slot */
|
|
|
|
#define PAD_CONNECT_IN_USE 0x03 /* the pad is ready and is bound to a RA slot */
|
|
|
|
|
|
|
|
#define SLOT_AUTO -1
|
|
|
|
|
2014-10-04 19:14:04 +02:00
|
|
|
typedef struct pad_connection_interface
|
2014-10-04 19:07:59 +02:00
|
|
|
{
|
2017-12-12 22:55:10 -08:00
|
|
|
void* (*init)(void *data, uint32_t slot, hid_driver_t *driver);
|
2016-02-04 17:01:03 -05:00
|
|
|
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,
|
|
|
|
uint16_t strength);
|
2018-04-08 20:21:12 +02:00
|
|
|
void (*get_buttons)(void *data, input_bits_t *state);
|
2016-02-04 17:01:03 -05:00
|
|
|
int16_t (*get_axis)(void *data, unsigned axis);
|
|
|
|
const char* (*get_name)(void *data);
|
2021-10-01 22:22:11 -07:00
|
|
|
int32_t (*button)(void *data, uint16_t joykey);
|
2021-10-03 23:27:07 +00:00
|
|
|
/* all fields/methods below this point are only required for multi-pad devices */
|
|
|
|
bool multi_pad; /* does the device provide multiple pads? */
|
|
|
|
int8_t max_pad; /* number of pads this device can provide */
|
|
|
|
void* (*pad_init)(void *data, int pad_index, joypad_connection_t *joyconn);
|
|
|
|
void (*pad_deinit)(void *pad_data);
|
|
|
|
/* pad_index is a number from 0 to max_pad-1 */
|
|
|
|
int8_t (*status)(void *data, int pad_index); /* returns a PAD_CONNECT_* state */
|
|
|
|
joypad_connection_t* (*joypad)(void *device_data, int pad_index);
|
2014-10-04 19:14:04 +02:00
|
|
|
} pad_connection_interface_t;
|
|
|
|
|
2021-10-01 22:22:11 -07:00
|
|
|
typedef struct joypad_connection_entry {
|
|
|
|
const char* name;
|
|
|
|
uint16_t vid;
|
|
|
|
uint16_t pid;
|
|
|
|
pad_connection_interface_t *iface;
|
|
|
|
} joypad_connection_entry_t;
|
|
|
|
|
2014-10-04 21:10:59 +02:00
|
|
|
extern pad_connection_interface_t pad_connection_wii;
|
2015-12-12 18:30:17 +01:00
|
|
|
extern pad_connection_interface_t pad_connection_wiiupro;
|
2014-10-04 21:10:59 +02:00
|
|
|
extern pad_connection_interface_t pad_connection_ps3;
|
2015-03-31 19:23:06 +02:00
|
|
|
extern pad_connection_interface_t pad_connection_ps4;
|
2016-02-04 17:01:03 -05:00
|
|
|
extern pad_connection_interface_t pad_connection_snesusb;
|
|
|
|
extern pad_connection_interface_t pad_connection_nesusb;
|
|
|
|
extern pad_connection_interface_t pad_connection_wiiugca;
|
2016-04-16 19:33:17 -05:00
|
|
|
extern pad_connection_interface_t pad_connection_ps2adapter;
|
2017-06-17 14:19:09 -07:00
|
|
|
extern pad_connection_interface_t pad_connection_psxadapter;
|
2019-08-09 13:42:15 +02:00
|
|
|
extern pad_connection_interface_t pad_connection_retrode;
|
2020-09-04 17:50:10 +06:00
|
|
|
extern pad_connection_interface_t pad_connection_ps4_hori_mini;
|
2022-11-02 23:00:42 -03:00
|
|
|
extern pad_connection_interface_t pad_connection_kade;
|
|
|
|
extern pad_connection_interface_t pad_connection_dragonrise;
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2014-10-22 07:59:52 +02:00
|
|
|
int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
|
2015-04-03 23:30:39 +02:00
|
|
|
const char* name, uint16_t vid, uint16_t pid,
|
2017-12-12 22:55:10 -08:00
|
|
|
void *data, hid_driver_t *driver);
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2015-06-13 01:40:55 +02:00
|
|
|
joypad_connection_t *pad_connection_init(unsigned pads);
|
2014-10-04 22:32:14 +02:00
|
|
|
|
2014-10-06 01:49:00 +02:00
|
|
|
void pad_connection_destroy(joypad_connection_t *joyconn);
|
2014-10-04 22:32:14 +02:00
|
|
|
|
2014-10-22 07:59:52 +02:00
|
|
|
void pad_connection_pad_deinit(joypad_connection_t *joyconn,
|
2017-01-20 18:23:45 -05:00
|
|
|
uint32_t idx);
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2014-10-06 01:49:00 +02:00
|
|
|
void pad_connection_packet(joypad_connection_t *joyconn,
|
2017-01-20 18:23:45 -05:00
|
|
|
uint32_t idx, uint8_t* data, uint32_t length);
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2017-11-28 10:04:34 +00:00
|
|
|
void pad_connection_get_buttons(joypad_connection_t *joyconn,
|
2018-04-08 20:21:12 +02:00
|
|
|
unsigned idx, input_bits_t* state);
|
2014-10-04 20:53:58 +02:00
|
|
|
|
2014-10-06 01:49:00 +02:00
|
|
|
int16_t pad_connection_get_axis(joypad_connection_t *joyconn,
|
2014-10-20 20:32:41 +02:00
|
|
|
unsigned idx, unsigned i);
|
2014-10-04 20:53:58 +02:00
|
|
|
|
2014-10-04 19:07:59 +02:00
|
|
|
/* Determine if connected joypad is a hidpad backed device.
|
|
|
|
* If false, pad_connection_packet cannot be used */
|
|
|
|
|
2014-10-06 01:49:00 +02:00
|
|
|
bool pad_connection_has_interface(joypad_connection_t *joyconn,
|
2014-10-20 20:32:41 +02:00
|
|
|
unsigned idx);
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2015-04-04 23:34:04 +02:00
|
|
|
int pad_connection_find_vacant_pad(joypad_connection_t *joyconn);
|
|
|
|
|
2014-10-14 19:01:52 +02:00
|
|
|
bool pad_connection_rumble(joypad_connection_t *s,
|
|
|
|
unsigned pad, enum retro_rumble_effect effect, uint16_t strength);
|
|
|
|
|
2016-02-04 17:01:03 -05:00
|
|
|
const char* pad_connection_get_name(joypad_connection_t *joyconn,
|
|
|
|
unsigned idx);
|
|
|
|
|
2022-03-15 15:35:18 +01:00
|
|
|
joypad_connection_entry_t *find_connection_entry(uint16_t vid, uint16_t pid, const char *name);
|
2021-10-03 23:27:07 +00:00
|
|
|
int32_t pad_connection_pad_init_entry(joypad_connection_t *joyconn, joypad_connection_entry_t *entry, void *data, hid_driver_t *driver);
|
|
|
|
void pad_connection_pad_register(joypad_connection_t *joyconn, pad_connection_interface_t *iface, void *pad_data, void *handle, input_device_driver_t *input_driver, int slot);
|
|
|
|
void pad_connection_pad_deregister(joypad_connection_t *joyconn, pad_connection_interface_t *iface, void *pad_data);
|
|
|
|
void pad_connection_pad_refresh(joypad_connection_t *joyconn, pad_connection_interface_t *iface, void *device_data, void *handle, input_device_driver_t *input_driver);
|
2014-10-04 18:41:23 +02:00
|
|
|
#endif
|