SDL2 drivers for Playdate? Yes!

I assume this needs an ifdef, like Emscripten does; I haven't looked closely.

SDL3 has a better solution for this generally, though:

1 Like

Using a fresh pull from Eric's branch with the custom Makefile specified in the pull request, it seems to get part way through the compile, then chokes on an undeclared variable partway through SDL joystick.

user@user-reks:~/Projects/VVVVVV/third_party$ make
detected_OS is "Linux"
mkdir -p build
mkdir -p build/dep
mkdir -p `dirname build/SDL/src/joystick/playdate/SDL_sysjoystick.o`
/usr/bin/arm-none-eabi-gcc -g3 -c -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__FPU_USED=1 -O2 -falign-functions=16 -fomit-frame-pointer -gdwarf-2 -Wall -Wno-unused -Wstrict-prototypes -Wno-unknown-pragmas -fverbose-asm -Wdouble-promotion -mword-relocations -fno-common -ffunction-sections -fdata-sections -Wa,-ahlms=build/SDL_sysjoystick.lst -DTARGET_PLAYDATE=1 -DTARGET_EXTENSION=1  -MD -MP -MF build/dep/SDL_sysjoystick.o.d -I . -I . -I /home/user/Downloads/PlaydateSDK-2.4.2/C_API -I SDL/include SDL/src/joystick/playdate/SDL_sysjoystick.c -o build/SDL/src/joystick/playdate/SDL_sysjoystick.o
SDL/src/joystick/playdate/SDL_sysjoystick.c: In function 'PLAYDATE_JoystickUpdate':
SDL/src/joystick/playdate/SDL_sysjoystick.c:54:9: error: 'pd' undeclared (first use in this function)
   54 |         pd->system->getButtonState(&current, NULL, NULL);
      |         ^~
SDL/src/joystick/playdate/SDL_sysjoystick.c:54:9: note: each undeclared identifier is reported only once for each function it appears in
SDL/src/joystick/playdate/SDL_sysjoystick.c: At top level:
SDL/src/joystick/playdate/SDL_sysjoystick.c:198:5: warning: initialization of 'const char * (*)(int)' from incompatible pointer type 'int (*)(int)' [-Wincompatible-pointer-types]
  198 |     PLAYDATE_JoystickGetDevicePlayerIndex,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:198:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.GetDevicePath')
SDL/src/joystick/playdate/SDL_sysjoystick.c:199:5: warning: initialization of 'int (*)(int)' from incompatible pointer type 'void (*)(int,  int)' [-Wincompatible-pointer-types]
  199 |     PLAYDATE_JoystickSetDevicePlayerIndex,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:199:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.GetDeviceSteamVirtualGamepadSlot')
SDL/src/joystick/playdate/SDL_sysjoystick.c:200:5: warning: initialization of 'int (*)(int)' from incompatible pointer type 'SDL_JoystickGUID (*)(int)' {aka 'SDL_GUID (*)(int)'} [-Wincompatible-pointer-types]
  200 |     PLAYDATE_JoystickGetDeviceGUID,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:200:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.GetDevicePlayerIndex')
SDL/src/joystick/playdate/SDL_sysjoystick.c:201:5: warning: initialization of 'void (*)(int,  int)' from incompatible pointer type 'SDL_JoystickID (*)(int)' {aka 'long int (*)(int)'} [-Wincompatible-pointer-types]
  201 |     PLAYDATE_JoystickGetDeviceInstanceID,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:201:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.SetDevicePlayerIndex')
SDL/src/joystick/playdate/SDL_sysjoystick.c:202:5: warning: initialization of 'SDL_JoystickGUID (*)(int)' {aka 'SDL_GUID (*)(int)'} from incompatible pointer type 'int (*)(SDL_Joystick *, int)' {aka 'int (*)(struct _SDL_Joystick *, int)'} [-Wincompatible-pointer-types]
  202 |     PLAYDATE_JoystickOpen,
      |     ^~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:202:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.GetDeviceGUID')
SDL/src/joystick/playdate/SDL_sysjoystick.c:203:5: warning: initialization of 'SDL_JoystickID (*)(int)' {aka 'long int (*)(int)'} from incompatible pointer type 'int (*)(SDL_Joystick *, Uint16,  Uint16)' {aka 'int (*)(struct _SDL_Joystick *, short unsigned int,  short unsigned int)'} [-Wincompatible-pointer-types]
  203 |     PLAYDATE_JoystickRumble,
      |     ^~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:203:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.GetDeviceInstanceID')
SDL/src/joystick/playdate/SDL_sysjoystick.c:204:5: warning: initialization of 'int (*)(SDL_Joystick *, int)' {aka 'int (*)(struct _SDL_Joystick *, int)'} from incompatible pointer type 'int (*)(SDL_Joystick *, Uint16,  Uint16)' {aka 'int (*)(struct _SDL_Joystick *, short unsigned int,  short unsigned int)'} [-Wincompatible-pointer-types]
  204 |     PLAYDATE_JoystickRumbleTriggers,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:204:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.Open')
SDL/src/joystick/playdate/SDL_sysjoystick.c:205:5: warning: initialization of 'int (*)(SDL_Joystick *, Uint16,  Uint16)' {aka 'int (*)(struct _SDL_Joystick *, short unsigned int,  short unsigned int)'} from incompatible pointer type 'Uint32 (*)(SDL_Joystick *)' {aka 'long unsigned int (*)(struct _SDL_Joystick *)'} [-Wincompatible-pointer-types]
  205 |     PLAYDATE_JoystickGetCapabilities,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:205:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.Rumble')
SDL/src/joystick/playdate/SDL_sysjoystick.c:206:5: warning: initialization of 'int (*)(SDL_Joystick *, Uint16,  Uint16)' {aka 'int (*)(struct _SDL_Joystick *, short unsigned int,  short unsigned int)'} from incompatible pointer type 'int (*)(SDL_Joystick *, Uint8,  Uint8,  Uint8)' {aka 'int (*)(struct _SDL_Joystick *, unsigned char,  unsigned char,  unsigned char)'} [-Wincompatible-pointer-types]
  206 |     PLAYDATE_JoystickSetLED,
      |     ^~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:206:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.RumbleTriggers')
SDL/src/joystick/playdate/SDL_sysjoystick.c:207:5: warning: initialization of 'Uint32 (*)(SDL_Joystick *)' {aka 'long unsigned int (*)(struct _SDL_Joystick *)'} from incompatible pointer type 'int (*)(SDL_Joystick *, const void *, int)' {aka 'int (*)(struct _SDL_Joystick *, const void *, int)'} [-Wincompatible-pointer-types]
  207 |     PLAYDATE_JoystickSendEffect,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:207:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.GetCapabilities')
SDL/src/joystick/playdate/SDL_sysjoystick.c:208:5: warning: initialization of 'int (*)(SDL_Joystick *, Uint8,  Uint8,  Uint8)' {aka 'int (*)(struct _SDL_Joystick *, unsigned char,  unsigned char,  unsigned char)'} from incompatible pointer type 'int (*)(SDL_Joystick *, SDL_bool)' {aka 'int (*)(struct _SDL_Joystick *, SDL_bool)'} [-Wincompatible-pointer-types]
  208 |     PLAYDATE_JoystickSetSensorsEnabled,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:208:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.SetLED')
SDL/src/joystick/playdate/SDL_sysjoystick.c:209:5: warning: initialization of 'int (*)(SDL_Joystick *, const void *, int)' {aka 'int (*)(struct _SDL_Joystick *, const void *, int)'} from incompatible pointer type 'void (*)(SDL_Joystick *)' {aka 'void (*)(struct _SDL_Joystick *)'} [-Wincompatible-pointer-types]
  209 |     PLAYDATE_JoystickUpdate,
      |     ^~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:209:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.SendEffect')
SDL/src/joystick/playdate/SDL_sysjoystick.c:210:5: warning: initialization of 'int (*)(SDL_Joystick *, SDL_bool)' {aka 'int (*)(struct _SDL_Joystick *, SDL_bool)'} from incompatible pointer type 'void (*)(SDL_Joystick *)' {aka 'void (*)(struct _SDL_Joystick *)'} [-Wincompatible-pointer-types]
  210 |     PLAYDATE_JoystickClose,
      |     ^~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:210:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.SetSensorsEnabled')
SDL/src/joystick/playdate/SDL_sysjoystick.c:211:5: warning: initialization of 'void (*)(SDL_Joystick *)' {aka 'void (*)(struct _SDL_Joystick *)'} from incompatible pointer type 'void (*)(void)' [-Wincompatible-pointer-types]
  211 |     PLAYDATE_JoystickQuit,
      |     ^~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:211:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.Update')
SDL/src/joystick/playdate/SDL_sysjoystick.c:212:5: warning: initialization of 'void (*)(SDL_Joystick *)' {aka 'void (*)(struct _SDL_Joystick *)'} from incompatible pointer type 'SDL_bool (*)(int,  SDL_GamepadMapping *)' {aka 'SDL_bool (*)(int,  struct _SDL_GamepadMapping *)'} [-Wincompatible-pointer-types]
  212 |     PLAYDATE_JoystickGetGamepadMapping
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDL/src/joystick/playdate/SDL_sysjoystick.c:212:5: note: (near initialization for 'SDL_PLAYDATE_JoystickDriver.Close')
make: *** [/home/user/Downloads/PlaydateSDK-2.4.2/C_API/buildsupport/common.mk:149: build/SDL/src/joystick/playdate/SDL_sysjoystick.o] Error 1

Is this an issue on my local setup, or is the custom makefile no longer needed, or something deeper going on?

Figured it out, had to add extern PlaydateAPI* pd to the required files and tie up loose ends. I still have to use the temp makefile and would like to add support for building the libraries the intended workflow, but it's progress. Here's what I have so far. Playdate support by moocow1452 · Pull Request #4 · ericlewis/SDL · GitHub

user@user-reks:~$ make
detected_OS is "Linux"
mkdir -p build
mkdir -p build/dep
cp build/pdex.elf Source
cp build/pdex.so Source
/home/user/Downloads/PlaydateSDK-2.4.2/bin/pdc -sdkpath /home/user/Downloads/PlaydateSDK-2.4.2 Source gnu.pdx
make: *** [/home/user/Downloads/PlaydateSDK-2.4.2/C_API/buildsupport/common.mk:115: all] Segmentation fault (core dumped)

Looking over the most current output, it looks like the pdc is giving trouble trying to create the pdx file giving me a segmentation fault. Granted, I'm just using my best guess on what the main.c was provided, so something is probably failing there.

Is this something we would want to revisit or rebase around SDL3? I was considering revisiting this, and want to know if 3 was where all the work was going, so trying to get 2 running would be of limited use?