Include a USB VID/PID for Apple MFI controllers
authorSam Lantinga <slouken@libsdl.org>
Wed, 07 Mar 2018 18:09:58 -0800
changeset 1192396f71726c0b2
parent 11922 5b6c54dc89da
child 11924 6aade58208aa
Include a USB VID/PID for Apple MFI controllers
This is just placeholder VID/PID, but allows code that works with VID/PID to identify the MFI controllers easily.
src/joystick/SDL_gamecontrollerdb.h
src/joystick/iphoneos/SDL_sysjoystick.m
     1.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Wed Mar 07 13:30:40 2018 -0800
     1.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Wed Mar 07 18:09:58 2018 -0800
     1.3 @@ -215,9 +215,9 @@
     1.4      "050000005e04000091020000ff073f00,Xbox Wireless Controller,a:b0,b:b1,back:b4,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,", /* The DPAD doesn't seem to work on this controller on Android TV? */
     1.5  #endif
     1.6  #if defined(SDL_JOYSTICK_MFI)
     1.7 -    "4d466947616d65706164010000000000,*,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
     1.8 -    "4d466947616d65706164020000000000,*,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,start:b6,x:b2,y:b3,",
     1.9 -    "4d466947616d65706164030000000000,Remote,a:b0,b:b2,leftx:a0,lefty:a1,",
    1.10 +    "05000000ac0500000100000000006d01,*,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a5,rightx:a3,righty:a4,guide:b6,x:b2,y:b3,",
    1.11 +    "05000000ac0500000200000000006d02,*,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,guide:b6,x:b2,y:b3,",
    1.12 +    "05000000ac0500000300000000006d03,Remote,a:b0,b:b2,leftx:a0,lefty:a1,",
    1.13      "05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
    1.14  #endif
    1.15  #if defined(SDL_JOYSTICK_EMSCRIPTEN)
     2.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Wed Mar 07 13:30:40 2018 -0800
     2.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Wed Mar 07 18:09:58 2018 -0800
     2.3 @@ -83,6 +83,14 @@
     2.4  SDL_SYS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller)
     2.5  {
     2.6  #ifdef SDL_JOYSTICK_MFI
     2.7 +    const Uint16 BUS_BLUETOOTH = 0x05;
     2.8 +	const Uint16 VENDOR_APPLE = 0x05AC;
     2.9 +    Uint16 *guid16 = (Uint16 *)device->guid.data;
    2.10 +	Uint16 vendor = 0;
    2.11 +	Uint16 product = 0;
    2.12 +	Uint16 version = 0;
    2.13 +	Uint8 subtype = 0;
    2.14 +
    2.15      const char *name = NULL;
    2.16      /* Explicitly retain the controller because SDL_JoystickDeviceItem is a
    2.17       * struct, and ARC doesn't work with structs. */
    2.18 @@ -98,40 +106,26 @@
    2.19  
    2.20      device->name = SDL_strdup(name);
    2.21  
    2.22 -    device->guid.data[0] = 'M';
    2.23 -    device->guid.data[1] = 'F';
    2.24 -    device->guid.data[2] = 'i';
    2.25 -    device->guid.data[3] = 'G';
    2.26 -    device->guid.data[4] = 'a';
    2.27 -    device->guid.data[5] = 'm';
    2.28 -    device->guid.data[6] = 'e';
    2.29 -    device->guid.data[7] = 'p';
    2.30 -    device->guid.data[8] = 'a';
    2.31 -    device->guid.data[9] = 'd';
    2.32 -
    2.33      if (controller.extendedGamepad) {
    2.34 -        device->guid.data[10] = 1;
    2.35 -    } else if (controller.gamepad) {
    2.36 -        device->guid.data[10] = 2;
    2.37 -    }
    2.38 -#if TARGET_OS_TV
    2.39 -    else if (controller.microGamepad) {
    2.40 -        device->guid.data[10] = 3;
    2.41 -        device->remote = SDL_TRUE;
    2.42 -    }
    2.43 -#endif /* TARGET_OS_TV */
    2.44 -
    2.45 -    if (controller.extendedGamepad) {
    2.46 +		vendor = VENDOR_APPLE;
    2.47 +		product = 1;
    2.48 +		subtype = 1;
    2.49          device->naxes = 6; /* 2 thumbsticks and 2 triggers */
    2.50          device->nhats = 1; /* d-pad */
    2.51          device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */
    2.52      } else if (controller.gamepad) {
    2.53 +		vendor = VENDOR_APPLE;
    2.54 +		product = 2;
    2.55 +		subtype = 2;
    2.56          device->naxes = 0; /* no traditional analog inputs */
    2.57          device->nhats = 1; /* d-pad */
    2.58          device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */
    2.59      }
    2.60  #if TARGET_OS_TV
    2.61      else if (controller.microGamepad) {
    2.62 +		vendor = VENDOR_APPLE;
    2.63 +		product = 3;
    2.64 +		subtype = 3;
    2.65          device->naxes = 2; /* treat the touch surface as two axes */
    2.66          device->nhats = 0; /* apparently the touch surface-as-dpad is buggy */
    2.67          device->nbuttons = 3; /* AX, pause button */
    2.68 @@ -140,6 +134,21 @@
    2.69      }
    2.70  #endif /* TARGET_OS_TV */
    2.71  
    2.72 +    /* We only need 16 bits for each of these; space them out to fill 128. */
    2.73 +    /* Byteswap so devices get same GUID on little/big endian platforms. */
    2.74 +    *guid16++ = SDL_SwapLE16(BUS_BLUETOOTH);
    2.75 +    *guid16++ = 0;
    2.76 +	*guid16++ = SDL_SwapLE16(vendor);
    2.77 +	*guid16++ = 0;
    2.78 +	*guid16++ = SDL_SwapLE16(product);
    2.79 +	*guid16++ = 0;
    2.80 +	*guid16++ = SDL_SwapLE16(version);
    2.81 +	*guid16++ = 0;
    2.82 +
    2.83 +	/* Note that this is an MFI controller and what subtype it is */
    2.84 +	device->guid.data[14] = 'm';
    2.85 +	device->guid.data[15] = subtype;
    2.86 +
    2.87      /* This will be set when the first button press of the controller is
    2.88       * detected. */
    2.89      controller.playerIndex = -1;