From eed8a56193e1b81d19da4aeb7a336c53def280d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Fri, 9 Dec 2022 11:52:21 -0300 Subject: [PATCH 01/37] Create Clang-PR.yml --- .github/workflows/Clang-PR.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/Clang-PR.yml diff --git a/.github/workflows/Clang-PR.yml b/.github/workflows/Clang-PR.yml new file mode 100644 index 000000000..fe556e0e8 --- /dev/null +++ b/.github/workflows/Clang-PR.yml @@ -0,0 +1,30 @@ +name: CI-format-pull-request + +# only perform this workflow if a developer manually triggers it from the actions tab +on: + workflow_dispatch: + +jobs: + check-format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.12 + with: + source: '.' + extensions: 'h,c' + clangFormatVersion: 12 + inplace: true + + - name: Create Pull Request + id: prmaker + uses: peter-evans/create-pull-request@v4 + with: + commit-message: "Format source code" + body: "clang-format" + title: "clang-format" + delete-branch: true + branch-suffix: random + add-paths: | + * From cd69672a605269264f5d55307095bdc76105de24 Mon Sep 17 00:00:00 2001 From: belek666 Date: Sun, 24 May 2020 12:55:07 +0200 Subject: [PATCH 02/37] Modular pademu, prototypes of xbox modules and hid joystick module --- Makefile | 72 +- ee_core/include/modules.h | 8 + ee_core/src/iopmgr.c | 31 + ee_core/src/main.c | 2 +- include/config.h | 1 + include/dialogs.h | 5 +- include/extern_irx.h | 20 + include/opl.h | 1 + lng_tmpl/_base.yml | 6 + modules/pademu/Makefile | 17 +- modules/pademu/btstack/Makefile | 22 + .../pademu/{ds34bt.c => btstack/btstack.c} | 892 ++++++------------ .../pademu/{ds34bt.h => btstack/btstack.h} | 194 ++-- modules/pademu/btstack/exports.tab | 12 + modules/pademu/btstack/imports.lst | 68 ++ modules/pademu/btstack/irx_imports.h | 40 + modules/pademu/ds34usb.c | 575 ----------- modules/pademu/ds34usb.h | 84 -- modules/pademu/ds3bt/Makefile | 22 + modules/pademu/ds3bt/ds3bt.c | 220 +++++ modules/pademu/ds3bt/ds3bt.h | 94 ++ modules/pademu/ds3bt/imports.lst | 74 ++ modules/pademu/ds3bt/irx_imports.h | 41 + modules/pademu/ds3usb/Makefile | 22 + modules/pademu/ds3usb/ds3usb.c | 429 +++++++++ modules/pademu/ds3usb/ds3usb.h | 133 +++ modules/pademu/ds3usb/imports.lst | 68 ++ modules/pademu/ds3usb/irx_imports.h | 40 + modules/pademu/ds4bt/Makefile | 22 + modules/pademu/ds4bt/ds4bt.c | 215 +++++ modules/pademu/ds4bt/ds4bt.h | 88 ++ modules/pademu/ds4bt/imports.lst | 74 ++ modules/pademu/ds4bt/irx_imports.h | 41 + modules/pademu/ds4usb/Makefile | 22 + modules/pademu/ds4usb/ds4usb.c | 479 ++++++++++ modules/pademu/ds4usb/ds4usb.h | 110 +++ modules/pademu/ds4usb/imports.lst | 68 ++ modules/pademu/ds4usb/irx_imports.h | 40 + modules/pademu/exports.tab | 2 + modules/pademu/hidusb/Makefile | 22 + modules/pademu/hidusb/hidusb.c | 511 ++++++++++ modules/pademu/hidusb/hidusb.h | 61 ++ modules/pademu/hidusb/imports.lst | 68 ++ modules/pademu/hidusb/irx_imports.h | 40 + modules/pademu/pademu.c | 104 +- modules/pademu/pademu.h | 35 +- modules/pademu/sys_utils.c | 13 + modules/pademu/sys_utils.h | 2 +- modules/pademu/xbox360usb/Makefile | 22 + modules/pademu/xbox360usb/imports.lst | 68 ++ modules/pademu/xbox360usb/irx_imports.h | 40 + modules/pademu/xbox360usb/xbox360usb.c | 388 ++++++++ modules/pademu/xbox360usb/xbox360usb.h | 140 +++ modules/pademu/xboxoneusb/Makefile | 22 + modules/pademu/xboxoneusb/imports.lst | 68 ++ modules/pademu/xboxoneusb/irx_imports.h | 40 + modules/pademu/xboxoneusb/xboxoneusb.c | 380 ++++++++ modules/pademu/xboxoneusb/xboxoneusb.h | 171 ++++ src/dialogs.c | 6 +- src/guigame.c | 146 ++- src/supportbase.c | 3 + src/system.c | 50 +- 62 files changed, 5221 insertions(+), 1533 deletions(-) create mode 100644 modules/pademu/btstack/Makefile rename modules/pademu/{ds34bt.c => btstack/btstack.c} (51%) rename modules/pademu/{ds34bt.h => btstack/btstack.h} (50%) create mode 100644 modules/pademu/btstack/exports.tab create mode 100644 modules/pademu/btstack/imports.lst create mode 100644 modules/pademu/btstack/irx_imports.h delete mode 100644 modules/pademu/ds34usb.c delete mode 100644 modules/pademu/ds34usb.h create mode 100644 modules/pademu/ds3bt/Makefile create mode 100644 modules/pademu/ds3bt/ds3bt.c create mode 100644 modules/pademu/ds3bt/ds3bt.h create mode 100644 modules/pademu/ds3bt/imports.lst create mode 100644 modules/pademu/ds3bt/irx_imports.h create mode 100644 modules/pademu/ds3usb/Makefile create mode 100644 modules/pademu/ds3usb/ds3usb.c create mode 100644 modules/pademu/ds3usb/ds3usb.h create mode 100644 modules/pademu/ds3usb/imports.lst create mode 100644 modules/pademu/ds3usb/irx_imports.h create mode 100644 modules/pademu/ds4bt/Makefile create mode 100644 modules/pademu/ds4bt/ds4bt.c create mode 100644 modules/pademu/ds4bt/ds4bt.h create mode 100644 modules/pademu/ds4bt/imports.lst create mode 100644 modules/pademu/ds4bt/irx_imports.h create mode 100644 modules/pademu/ds4usb/Makefile create mode 100644 modules/pademu/ds4usb/ds4usb.c create mode 100644 modules/pademu/ds4usb/ds4usb.h create mode 100644 modules/pademu/ds4usb/imports.lst create mode 100644 modules/pademu/ds4usb/irx_imports.h create mode 100644 modules/pademu/hidusb/Makefile create mode 100644 modules/pademu/hidusb/hidusb.c create mode 100644 modules/pademu/hidusb/hidusb.h create mode 100644 modules/pademu/hidusb/imports.lst create mode 100644 modules/pademu/hidusb/irx_imports.h create mode 100644 modules/pademu/xbox360usb/Makefile create mode 100644 modules/pademu/xbox360usb/imports.lst create mode 100644 modules/pademu/xbox360usb/irx_imports.h create mode 100644 modules/pademu/xbox360usb/xbox360usb.c create mode 100644 modules/pademu/xbox360usb/xbox360usb.h create mode 100644 modules/pademu/xboxoneusb/Makefile create mode 100644 modules/pademu/xboxoneusb/imports.lst create mode 100644 modules/pademu/xboxoneusb/irx_imports.h create mode 100644 modules/pademu/xboxoneusb/xboxoneusb.c create mode 100644 modules/pademu/xboxoneusb/xboxoneusb.h diff --git a/Makefile b/Makefile index 8e6649d7a..5d6c8dae1 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,8 @@ else endif ifeq ($(PADEMU),1) - IOP_OBJS += bt_pademu.o usb_pademu.o ds34usb.o ds34bt.o libds34usb.a libds34bt.a + IOP_OBJS += pademu.o btstack.o ds3usb.o ds4usb.o xbox360usb.o xboxoneusb.o \ + ds3bt.o ds4bt.o hidusb.o ds34usb.o ds34bt.o libds34usb.a libds34bt.a EE_CFLAGS += -DPADEMU EE_INCS += -Imodules/ds34bt/ee -Imodules/ds34usb/ee PADEMU_FLAGS = PADEMU=1 @@ -297,8 +298,15 @@ clean: download_lwNBD echo " -ds34bt" $(MAKE) -C modules/ds34bt clean echo " -pademu" - $(MAKE) -C modules/pademu USE_BT=1 clean - $(MAKE) -C modules/pademu USE_USB=1 clean + $(MAKE) -C modules/pademu clean + $(MAKE) -C modules/pademu/btstack clean + $(MAKE) -C modules/pademu/ds3usb clean + $(MAKE) -C modules/pademu/ds4usb clean + $(MAKE) -C modules/pademu/xbox360usb clean + $(MAKE) -C modules/pademu/xboxoneusb clean + $(MAKE) -C modules/pademu/ds3bt clean + $(MAKE) -C modules/pademu/ds4bt clean + $(MAKE) -C modules/pademu/hidusb clean echo "-pc tools" $(MAKE) -C pc clean @@ -490,17 +498,59 @@ modules/ds34usb/iop/ds34usb.irx: modules/ds34usb/iop $(EE_ASM_DIR)ds34usb.s: modules/ds34usb/iop/ds34usb.irx | $(EE_ASM_DIR) $(BIN2S) $< $@ ds34usb_irx -modules/pademu/bt_pademu.irx: modules/pademu - $(MAKE) -C $< USE_BT=1 +modules/pademu/pademu.irx: modules/pademu + $(MAKE) -C $< + +$(EE_ASM_DIR)pademu.s: modules/pademu/pademu.irx + $(BIN2S) $< $@ pademu_irx + +modules/pademu/btstack/btstack.irx: modules/pademu/btstack + $(MAKE) -C $< + +$(EE_ASM_DIR)btstack.s: modules/pademu/btstack/btstack.irx + $(BIN2S) $< $@ btstack_irx + +modules/pademu/ds3usb/ds3usb.irx: modules/pademu/ds3usb + $(MAKE) -C $< + +$(EE_ASM_DIR)ds3usb.s: modules/pademu/ds3usb/ds3usb.irx + $(BIN2S) $< $@ ds3usb_irx + +modules/pademu/ds4usb/ds4usb.irx: modules/pademu/ds4usb + $(MAKE) -C $< + +$(EE_ASM_DIR)ds4usb.s: modules/pademu/ds4usb/ds4usb.irx + $(BIN2S) $< $@ ds4usb_irx -$(EE_ASM_DIR)bt_pademu.s: modules/pademu/bt_pademu.irx - $(BIN2S) $< $@ bt_pademu_irx +modules/pademu/xbox360usb/xbox360usb.irx: modules/pademu/xbox360usb + $(MAKE) -C $< -modules/pademu/usb_pademu.irx: modules/pademu - $(MAKE) -C $< USE_USB=1 +$(EE_ASM_DIR)xbox360usb.s: modules/pademu/xbox360usb/xbox360usb.irx + $(BIN2S) $< $@ xbox360usb_irx + +modules/pademu/xboxoneusb/xboxoneusb.irx: modules/pademu/xboxoneusb + $(MAKE) -C $< + +$(EE_ASM_DIR)xboxoneusb.s: modules/pademu/xboxoneusb/xboxoneusb.irx + $(BIN2S) $< $@ xboxoneusb_irx + +modules/pademu/ds3bt/ds3bt.irx: modules/pademu/ds3bt + $(MAKE) -C $< + +$(EE_ASM_DIR)ds3bt.s: modules/pademu/ds3bt/ds3bt.irx + $(BIN2S) $< $@ ds3bt_irx + +modules/pademu/ds4bt/ds4bt.irx: modules/pademu/ds4bt + $(MAKE) -C $< + +$(EE_ASM_DIR)ds4bt.s: modules/pademu/ds4bt/ds4bt.irx + $(BIN2S) $< $@ ds4bt_irx + +modules/pademu/hidusb/hidusb.irx: modules/pademu/hidusb + $(MAKE) -C $< -$(EE_ASM_DIR)usb_pademu.s: modules/pademu/usb_pademu.irx - $(BIN2S) $< $@ usb_pademu_irx +$(EE_ASM_DIR)hidusb.s: modules/pademu/hidusb/hidusb.irx + $(BIN2S) $< $@ hidusb_irx $(EE_ASM_DIR)bdm.s: $(PS2SDK)/iop/irx/bdm.irx | $(EE_ASM_DIR) $(BIN2S) $< $@ bdm_irx diff --git a/ee_core/include/modules.h b/ee_core/include/modules.h index 11a8f82d0..3037723b1 100644 --- a/ee_core/include/modules.h +++ b/ee_core/include/modules.h @@ -25,6 +25,14 @@ enum OPL_MODULE_ID { OPL_MODULE_ID_MCEMU, OPL_MODULE_ID_PADEMU, + OPL_MODULE_ID_BTSTACK, + OPL_MODULE_ID_DS3USB, + OPL_MODULE_ID_DS4USB, + OPL_MODULE_ID_XBOX360USB, + OPL_MODULE_ID_XBOXONEUSB, + OPL_MODULE_ID_DS3BT, + OPL_MODULE_ID_DS4BT, + OPL_MODULE_ID_HIDUSB, // Debugging modules OPL_MODULE_ID_UDPTTY, diff --git a/ee_core/src/iopmgr.c b/ee_core/src/iopmgr.c index b7adffbcc..df71d5649 100644 --- a/ee_core/src/iopmgr.c +++ b/ee_core/src/iopmgr.c @@ -184,11 +184,42 @@ int New_Reset_Iop(const char *arg, int arglen) } #ifdef PADEMU + int btstack_loaded = 0; if (iop_reboot_count >= 2 && EnablePadEmuOp) { char args_for_pademu[8]; memcpy(args_for_pademu, &PadEmuSettings, 4); memcpy(args_for_pademu + 4, &PadMacroSettings, 4); LoadOPLModule(OPL_MODULE_ID_PADEMU, 0, sizeof(args_for_pademu), args_for_pademu); + LoadOPLModule(OPL_MODULE_ID_PADEMU, 0, 4, (char *)&PadEmuSettings); + if (PadEmuModules & (1 << 0)) { + LoadOPLModule(OPL_MODULE_ID_DS3USB, 0, sizeof(args_for_pademu), args_for_pademu); + } + if (PadEmuModules & (1 << 1)) { + if (!btstack_loaded) { + LoadOPLModule(OPL_MODULE_ID_BTSTACK, 0, sizeof(args_for_pademu), args_for_pademu); + btstack_loaded = 1; + } + LoadOPLModule(OPL_MODULE_ID_DS3BT, 0, sizeof(args_for_pademu), args_for_pademu); + } + if (PadEmuModules & (1 << 2)) { + LoadOPLModule(OPL_MODULE_ID_DS4USB, 0, sizeof(args_for_pademu), args_for_pademu); + } + if (PadEmuModules & (1 << 3)) { + if (!btstack_loaded) { + LoadOPLModule(OPL_MODULE_ID_BTSTACK, 0, 0, NULL); + btstack_loaded = 1; + } + LoadOPLModule(OPL_MODULE_ID_DS4BT, 0, sizeof(args_for_pademu), args_for_pademu); + } + if (PadEmuModules & (1 << 4)) { + LoadOPLModule(OPL_MODULE_ID_XBOX360USB, 0, sizeof(args_for_pademu), args_for_pademu); + } + if (PadEmuModules & (1 << 5)) { + LoadOPLModule(OPL_MODULE_ID_XBOXONEUSB, 0, sizeof(args_for_pademu), args_for_pademu); + } + if (PadEmuModules & (1 << 6)) { + LoadOPLModule(OPL_MODULE_ID_HIDUSB, 0, sizeof(args_for_pademu), args_for_pademu); + } } #endif diff --git a/ee_core/src/main.c b/ee_core/src/main.c index d1baf85b1..cbb871caa 100644 --- a/ee_core/src/main.c +++ b/ee_core/src/main.c @@ -108,8 +108,8 @@ static int eecoreInit(int argc, char **argv) DPRINTF("PADEMU = %s\n", EnablePadEmuOp == 0 ? "Disabled" : "Enabled"); PadEmuSettings = _strtoi(_strtok(NULL, " ")); - PadMacroSettings = _strtoi(_strtok(NULL, " ")); + PadEmuModules = _strtoi(_strtok(NULL, " ")); #endif CustomOSDConfigParam.spdifMode = _strtoi(_strtok(NULL, " ")); CustomOSDConfigParam.screenType = _strtoi(_strtok(NULL, " ")); diff --git a/include/config.h b/include/config.h index 4cd7f1f80..81aba815b 100644 --- a/include/config.h +++ b/include/config.h @@ -58,6 +58,7 @@ enum CONFIG_INDEX { #define CONFIG_ITEM_PADEMUSOURCE "$PADEMUSource" #define CONFIG_ITEM_ENABLEPADEMU "$EnablePadEmu" #define CONFIG_ITEM_PADEMUSETTINGS "$PadEmuSettings" +#define CONFIG_ITEM_PADEMUMODULES "$PadEmuModules" #define CONFIG_ITEM_PADMACROSETTINGS "$PadMacroSettings" #define CONFIG_ITEM_PADMACROSOURCE "$PadMacroSource" diff --git a/include/dialogs.h b/include/dialogs.h index ba0efb2dd..4ed1c4514 100644 --- a/include/dialogs.h +++ b/include/dialogs.h @@ -147,7 +147,7 @@ enum UI_ITEMS { PADCFG_PADEMU_SOURCE, PADCFG_PADEMU_CONFIG, PADCFG_PADEMU_ENABLE, - PADCFG_PADEMU_MODE, + PADCFG_PADEMU_MODULES_LIST, PADCFG_PADEMU_PORT, PADCFG_PADEMU_VIB, PADCFG_PADPORT, @@ -171,6 +171,7 @@ enum UI_ITEMS { PADCFG_PADEMU_MTAP_PORT, PADCFG_PADEMU_WORKAROUND, PADCFG_PADEMU_WORKAROUND_STR, + PADCFG_PADEMU_MODULES_SET, PADMACRO_GLOBAL_BUTTON, PADMACRO_CFG_SOURCE, @@ -184,7 +185,7 @@ enum UI_ITEMS { PADMACRO_INVERT_RY, PADMACRO_TURBO_SPEED, - COMPAT_MODE_BASE = 250, + COMPAT_MODE_BASE = 251, #else COMPAT_MODE_BASE = 200, #endif diff --git a/include/extern_irx.h b/include/extern_irx.h index 04bea09b1..09017ff1e 100644 --- a/include/extern_irx.h +++ b/include/extern_irx.h @@ -12,6 +12,8 @@ IMPORT_BIN2C(audsrv_irx); IMPORT_BIN2C(bdm_irx); +IMPORT_BIN2C(btstack_irx); + IMPORT_BIN2C(bdm_cdvdman_irx); IMPORT_BIN2C(bdm_mcemu_irx); @@ -28,6 +30,14 @@ IMPORT_BIN2C(cleareffects_irx); IMPORT_BIN2C(deci2_img); +IMPORT_BIN2C(ds3bt_irx); + +IMPORT_BIN2C(ds3usb_irx); + +IMPORT_BIN2C(ds4bt_irx); + +IMPORT_BIN2C(ds4usb_irx); + IMPORT_BIN2C(drvtif_irx); IMPORT_BIN2C(drvtif_ingame_irx); @@ -42,6 +52,8 @@ IMPORT_BIN2C(genvmc_irx); IMPORT_BIN2C(hdd_cdvdman_irx); +IMPORT_BIN2C(hidusb_irx); + IMPORT_BIN2C(hdd_hdpro_cdvdman_irx); IMPORT_BIN2C(lwnbdsvr_irx); @@ -68,6 +80,10 @@ IMPORT_BIN2C(isofs_irx); IMPORT_BIN2C(iremsndpatch_irx); +IMPORT_BIN2C(pademu_irx); + +IMPORT_BIN2C(padman_irx); + IMPORT_BIN2C(libsd_irx); IMPORT_BIN2C(mcman_irx); @@ -126,6 +142,10 @@ IMPORT_BIN2C(udptty_irx); IMPORT_BIN2C(udptty_ingame_irx); +IMPORT_BIN2C(xbox360usb_irx); + +IMPORT_BIN2C(xboxoneusb_irx); + IMPORT_BIN2C(udnl_irx); IMPORT_BIN2C(usbd_irx); diff --git a/include/opl.h b/include/opl.h index c77e96dd8..aead40714 100644 --- a/include/opl.h +++ b/include/opl.h @@ -165,6 +165,7 @@ extern int showCfgPopup; #ifdef PADEMU extern int gEnablePadEmu; extern int gPadEmuSettings; +extern int gPadEmuModules; extern int gPadMacroSource; extern int gPadMacroSettings; #endif diff --git a/lng_tmpl/_base.yml b/lng_tmpl/_base.yml index f2b29e0ff..81d2c4f28 100644 --- a/lng_tmpl/_base.yml +++ b/lng_tmpl/_base.yml @@ -670,3 +670,9 @@ gui_strings: string: Default Theme Music - label: DEF_BGM_PATH_HINT string: Set path to stream music for internal theme. +- label: PADEMU_MODULES + string: Select modules to load +- label: HINT_PADEMU_MODULES + string: Select which pademu modules to load. +- label: HINT_PADEMU_MODULES_SET + string: Select/Unselect pademu module. \ No newline at end of file diff --git a/modules/pademu/Makefile b/modules/pademu/Makefile index be4cd1e68..f59a3b000 100644 --- a/modules/pademu/Makefile +++ b/modules/pademu/Makefile @@ -1,18 +1,7 @@ -IOP_OBJS = pademu.o sys_utils.o imports.o exports.o padmacro.o ds34common.o -ifeq ($(USE_USB),1) -IOP_BIN = usb_pademu.irx -IOP_CFLAGS += -DUSB -IOP_OBJS_DIR = obj.usb/ -IOP_OBJS += ds34usb.o -endif - -ifeq ($(USE_BT),1) -IOP_BIN = bt_pademu.irx -IOP_CFLAGS += -DBT -IOP_OBJS_DIR = obj.bt/ -IOP_OBJS += ds34bt.o -endif +IOP_BIN = pademu.irx +IOP_OBJS = pademu.o sys_utils.o padmacro.o imports.o exports.o +IOP_OBJS_DIR = obj.pademu/ ifeq ($(VMC),1) IOP_CFLAGS += -DVMC diff --git a/modules/pademu/btstack/Makefile b/modules/pademu/btstack/Makefile new file mode 100644 index 000000000..751a40e93 --- /dev/null +++ b/modules/pademu/btstack/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = btstack.irx +IOP_OBJS = btstack.o imports.o exports.o +IOP_OBJS_DIR = obj.btstack/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/ds34bt.c b/modules/pademu/btstack/btstack.c similarity index 51% rename from modules/pademu/ds34bt.c rename to modules/pademu/btstack/btstack.c index 202e0012b..ef22d29c3 100644 --- a/modules/pademu/ds34bt.c +++ b/modules/pademu/btstack/btstack.c @@ -4,6 +4,7 @@ #include "types.h" #include "loadcore.h" +#include "xloadcore.h" #include "stdio.h" #include "sifrpc.h" #include "sysclib.h" @@ -11,9 +12,9 @@ #include "usbd_macro.h" #include "thbase.h" #include "thsemap.h" -#include "ds34bt.h" -#include "sys_utils.h" -#include "padmacro.h" +#include "../pademu.h" +#include "../sys_utils.h" +#include "btstack.h" //#define DPRINTF(x...) printf(x) #define DPRINTF(x...) @@ -23,18 +24,12 @@ static int bt_connect(int devId); static int bt_disconnect(int devId); static void bt_config_set(int result, int count, void *arg); -static UsbDriver bt_driver = {NULL, NULL, "ds34bt", bt_probe, bt_connect, bt_disconnect}; -static bt_device bt_dev = {-1, -1, -1, -1, -1, -1, DS34BT_STATE_USB_DISCONNECTED}; +static UsbDriver bt_driver = {NULL, NULL, "btstack", bt_probe, bt_connect, bt_disconnect}; +static bt_adapter_t bt_adp = {-1, -1, -1, -1, -1, -1}; -static int chrg_probe(int devId); -static int chrg_connect(int devId); -static int chrg_disconnect(int devId); -static int chrg_dev = -1; - -static UsbDriver chrg_driver = {NULL, NULL, "ds34chrg", chrg_probe, chrg_connect, chrg_disconnect}; - -static void ds34pad_clear(int pad); -static void ds34pad_init(); +static void dev_clear(int pad); +static void dev_init(); +static void disconnect_all(); static int bt_probe(int devId) { @@ -42,16 +37,16 @@ static int bt_probe(int devId) UsbConfigDescriptor *config = NULL; UsbInterfaceDescriptor *intf = NULL; - DPRINTF("DS34BT: probe: devId=%i\n", devId); + DPRINTF("BTSTACK: probe: devId=%i\n", devId); - if ((bt_dev.devId > 0) && (bt_dev.status & DS34BT_STATE_USB_AUTHORIZED)) { - DPRINTF("DS34BT: Error - only one device allowed !\n"); + if (bt_adp.devId != -1) { + DPRINTF("BTSTACK: Error - only one device allowed !\n"); return 0; } device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); if (device == NULL) { - DPRINTF("DS34BT: Error - Couldn't get device descriptor\n"); + DPRINTF("BTSTACK: Error - Couldn't get device descriptor\n"); return 0; } @@ -60,18 +55,18 @@ static int bt_probe(int devId) config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); if (config == NULL) { - DPRINTF("DS34BT: Error - Couldn't get configuration descriptor\n"); + DPRINTF("BTSTACK: Error - Couldn't get configuration descriptor\n"); return 0; } if ((config->bNumInterfaces < 1) || (config->wTotalLength < (sizeof(UsbConfigDescriptor) + sizeof(UsbInterfaceDescriptor)))) { - DPRINTF("DS34BT: Error - No interfaces available\n"); + DPRINTF("BTSTACK: Error - No interfaces available\n"); return 0; } intf = (UsbInterfaceDescriptor *)((char *)config + config->bLength); - DPRINTF("DS34BT: bInterfaceClass %X bInterfaceSubClass %X bInterfaceProtocol %X\n", intf->bInterfaceClass, intf->bInterfaceSubClass, intf->bInterfaceProtocol); + DPRINTF("BTSTACK: bInterfaceClass %X bInterfaceSubClass %X bInterfaceProtocol %X\n", intf->bInterfaceClass, intf->bInterfaceSubClass, intf->bInterfaceProtocol); if ((intf->bInterfaceClass != USB_CLASS_WIRELESS_CONTROLLER) || (intf->bInterfaceSubClass != USB_SUBCLASS_RF_CONTROLLER) || @@ -91,20 +86,18 @@ static int bt_connect(int devId) UsbInterfaceDescriptor *interface; UsbEndpointDescriptor *endpoint; - DPRINTF("DS34BT: connect: devId=%i\n", devId); + DPRINTF("BTSTACK: connect: devId=%i\n", devId); - if (bt_dev.devId != -1) { - DPRINTF("DS34BT: Error - only one device allowed !\n"); + if (bt_adp.devId != -1) { + DPRINTF("BTSTACK: Error - only one device allowed !\n"); return 1; } - bt_dev.status = DS34BT_STATE_USB_DISCONNECTED; + bt_adp.interruptEndp = -1; + bt_adp.inEndp = -1; + bt_adp.outEndp = -1; - bt_dev.interruptEndp = -1; - bt_dev.inEndp = -1; - bt_dev.outEndp = -1; - - bt_dev.controlEndp = UsbOpenEndpoint(devId, NULL); + bt_adp.controlEndp = UsbOpenEndpoint(devId, NULL); device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); @@ -112,24 +105,24 @@ static int bt_connect(int devId) epCount = interface->bNumEndpoints - 1; - DPRINTF("DS34BT: Endpoint Count %d \n", epCount + 1); + DPRINTF("BTSTACK: Endpoint Count %d \n", epCount + 1); endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); do { if (endpoint->bmAttributes == USB_ENDPOINT_XFER_BULK) { - if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && bt_dev.outEndp < 0) { - bt_dev.outEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("DS34BT: register Output endpoint id =%i addr=%02X packetSize=%i\n", bt_dev.outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); - } else if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && bt_dev.inEndp < 0) { - bt_dev.inEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("DS34BT: register Input endpoint id =%i addr=%02X packetSize=%i\n", bt_dev.inEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && bt_adp.outEndp < 0) { + bt_adp.outEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("BTSTACK: register Output endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } else if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && bt_adp.inEndp < 0) { + bt_adp.inEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("BTSTACK: register Input endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.inEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } else if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { - if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && bt_dev.interruptEndp < 0) { - bt_dev.interruptEndp = UsbOpenEndpoint(devId, endpoint); - DPRINTF("DS34BT: register Interrupt endpoint id =%i addr=%02X packetSize=%i\n", bt_dev.interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && bt_adp.interruptEndp < 0) { + bt_adp.interruptEndp = UsbOpenEndpoint(devId, endpoint); + DPRINTF("BTSTACK: register Interrupt endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } @@ -137,128 +130,48 @@ static int bt_connect(int devId) } while (epCount--); - if (bt_dev.interruptEndp < 0 || bt_dev.inEndp < 0 || bt_dev.outEndp < 0) { - DPRINTF("DS34BT: Error - connect failed: not enough endpoints! \n"); + if (bt_adp.interruptEndp < 0 || bt_adp.inEndp < 0 || bt_adp.outEndp < 0) { + DPRINTF("BTSTACK: Error - connect failed: not enough endpoints! \n"); return -1; } - bt_dev.devId = devId; - bt_dev.status = DS34BT_STATE_USB_AUTHORIZED; + bt_adp.devId = devId; - UsbSetDeviceConfiguration(bt_dev.controlEndp, config->bConfigurationValue, bt_config_set, NULL); + UsbSetDeviceConfiguration(bt_adp.controlEndp, config->bConfigurationValue, bt_config_set, NULL); return 0; } static int bt_disconnect(int devId) { - DPRINTF("DS34BT: disconnect: devId=%i\n", devId); - - if (bt_dev.status & DS34BT_STATE_USB_AUTHORIZED) { + DPRINTF("BTSTACK: disconnect: devId=%i\n", devId); - if (bt_dev.interruptEndp >= 0) - UsbCloseEndpoint(bt_dev.interruptEndp); + if (bt_adp.devId != -1) { - if (bt_dev.inEndp >= 0) - UsbCloseEndpoint(bt_dev.inEndp); + disconnect_all(); - if (bt_dev.outEndp >= 0) - UsbCloseEndpoint(bt_dev.outEndp); - - bt_dev.devId = -1; - bt_dev.interruptEndp = -1; - bt_dev.inEndp = -1; - bt_dev.outEndp = -1; - bt_dev.controlEndp = -1; - bt_dev.status = DS34BT_STATE_USB_DISCONNECTED; - - ds34pad_init(); - SignalSema(bt_dev.hid_sema); - } - - return 0; -} - -int chrg_probe(int devId) -{ - UsbDeviceDescriptor *device = NULL; + if (bt_adp.interruptEndp >= 0) + UsbCloseEndpoint(bt_adp.interruptEndp); - DPRINTF("DS34CHRG: probe: devId=%i\n", devId); + if (bt_adp.inEndp >= 0) + UsbCloseEndpoint(bt_adp.inEndp); - device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); - if (device == NULL) { - DPRINTF("DS34CHRG: Error - Couldn't get device descriptor\n"); - return 0; - } - - if (device->idVendor == DS34_VID && (device->idProduct == DS3_PID || device->idProduct == DS4_PID || device->idProduct == DS4_PID_SLIM)) - return 1; - - return 0; -} - -int chrg_connect(int devId) -{ - int chrg_end; - UsbDeviceDescriptor *device; - UsbConfigDescriptor *config; + if (bt_adp.outEndp >= 0) + UsbCloseEndpoint(bt_adp.outEndp); - DPRINTF("DS34CHRG: connect: devId=%i\n", devId); + bt_adp.devId = -1; + bt_adp.interruptEndp = -1; + bt_adp.inEndp = -1; + bt_adp.outEndp = -1; + bt_adp.controlEndp = -1; - if (chrg_dev != -1) { - DPRINTF("DS34CHRG: Error - only one device allowed !\n"); - return 1; + dev_init(); + SignalSema(bt_adp.hid_sema); } - chrg_dev = devId; - - chrg_end = UsbOpenEndpoint(devId, NULL); - - device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); - config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); - - UsbSetDeviceConfiguration(chrg_end, config->bConfigurationValue, NULL, NULL); - return 0; } -int chrg_disconnect(int devId) -{ - DPRINTF("DS34CHRG: disconnect: devId=%i\n", devId); - - chrg_dev = -1; - - return 0; -} - -#define OUTPUT_01_REPORT_SIZE 48 -static const u8 hid_cmd_payload_led_arguments[] = {0xff, 0x27, 0x10, 0x00, 0x32}; - -static u8 led_patterns[][2] = - { - {0x1C, 0x02}, - {0x1A, 0x04}, - {0x16, 0x08}, - {0x0E, 0x10}, -}; - -static u8 power_level[] = - { - 0x00, 0x00, 0x02, 0x06, 0x0E, 0x1E}; - -static u8 rgbled_patterns[][2][3] = - { - {{0x00, 0x00, 0x10}, {0x00, 0x00, 0x7F}}, // light blue/blue - {{0x00, 0x10, 0x00}, {0x00, 0x7F, 0x00}}, // light green/green/ - {{0x10, 0x10, 0x00}, {0x7F, 0x7F, 0x00}}, // light yellow/yellow - {{0x00, 0x10, 0x10}, {0x00, 0x7F, 0x7F}}, // light cyan/cyan -}; - -static u8 link_key[] = // for ds4 authorisation - { - 0x56, 0xE8, 0x81, 0x38, 0x08, 0x06, 0x51, 0x41, - 0xC0, 0x7F, 0x12, 0xAA, 0xD9, 0x66, 0x3C, 0xCE}; - // Taken from nefarius' SCPToolkit // https://github.com/nefarius/ScpToolkit/blob/master/ScpControl/ScpControl.ini // Valid MAC addresses used by Sony @@ -321,13 +234,18 @@ static u8 GenuineMacAddress[][3] = {0x00, 0x24, 0x23}, {0x00, 0x22, 0x43}, {0x00, 0x15, 0xAF}, - // fake with AirohaTechnologyCorp's Chip + //fake with AirohaTechnologyCorp's Chip {0x0C, 0xFC, 0x83}}; -#define REQ_HCI_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_DEVICE) +static u8 link_key[] = //for ds4 authorisation + { + 0x56, 0xE8, 0x81, 0x38, 0x08, 0x06, 0x51, 0x41, + 0xC0, 0x7F, 0x12, 0xAA, 0xD9, 0x66, 0x3C, 0xCE}; + +#define REQ_HCI_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_DEVICE) #define HCI_COMMAND_REQ 0 -#define MAX_PADS 4 +#define MAX_PADS 4 #define MAX_DELAY 10 static u8 hci_buf[MAX_BUFFER_SIZE] __attribute((aligned(4))) = {0}; @@ -336,32 +254,27 @@ static u8 hci_cmd_buf[MAX_BUFFER_SIZE] __attribute((aligned(4))) = {0}; static u8 l2cap_cmd_buf[MAX_BUFFER_SIZE + 32] __attribute((aligned(4))) = {0}; static u8 identifier = 0; -static u8 g_press_emu = 0; -static u8 enable_fake = 0; -static ds34bt_pad_t ds34pad[MAX_PADS]; +static bt_dev_t dev[MAX_PADS]; +static bt_paddrv_t *btpad[MAX_PADS]; static void hci_event_cb(int resultCode, int bytes, void *arg); static void l2cap_event_cb(int resultCode, int bytes, void *arg); -static int hid_initDS34(int pad); -static int hid_LEDRumbleCommand(u8 *led, u8 lrum, u8 rrum, int pad); -static void hid_readReport(u8 *data, int bytes, int pad); - static int l2cap_connection_request(u16 handle, u8 rxid, u16 scid, u16 psm); static int hci_reset(); static void bt_config_set(int result, int count, void *arg) { - PollSema(bt_dev.hid_sema); + PollSema(bt_adp.hid_sema); - UsbInterruptTransfer(bt_dev.interruptEndp, hci_buf, MAX_BUFFER_SIZE, hci_event_cb, NULL); - UsbBulkTransfer(bt_dev.inEndp, l2cap_buf, MAX_BUFFER_SIZE, l2cap_event_cb, NULL); + UsbInterruptTransfer(bt_adp.interruptEndp, hci_buf, MAX_BUFFER_SIZE, hci_event_cb, NULL); + UsbBulkTransfer(bt_adp.inEndp, l2cap_buf, MAX_BUFFER_SIZE, l2cap_event_cb, NULL); - ds34pad_init(); + dev_init(); hci_reset(); - SignalSema(bt_dev.hid_sema); + SignalSema(bt_adp.hid_sema); } /************************************************************/ @@ -370,7 +283,7 @@ static void bt_config_set(int result, int count, void *arg) static int HCI_Command(int nbytes, u8 *dataptr) { - return UsbControlTransfer(bt_dev.controlEndp, REQ_HCI_OUT, HCI_COMMAND_REQ, 0, 0, nbytes, dataptr, NULL, NULL); + return UsbControlTransfer(bt_adp.controlEndp, REQ_HCI_OUT, HCI_COMMAND_REQ, 0, 0, nbytes, dataptr, NULL, NULL); } static int hci_reset() @@ -403,7 +316,7 @@ static int hci_accept_connection(u8 *bdaddr) hci_cmd_buf[6] = *(bdaddr + 3); hci_cmd_buf[7] = *(bdaddr + 4); hci_cmd_buf[8] = *(bdaddr + 5); - hci_cmd_buf[9] = 0x01; // switch role to (slave = 1 / master = 0) + hci_cmd_buf[9] = 0x01; //switch role to (slave = 1 / master = 0) return HCI_Command(10, hci_cmd_buf); } @@ -438,7 +351,7 @@ static int hci_reject_connection(u8 *bdaddr) hci_cmd_buf[6] = *(bdaddr + 3); hci_cmd_buf[7] = *(bdaddr + 4); hci_cmd_buf[8] = *(bdaddr + 5); - hci_cmd_buf[9] = 0x09; // reason max connection + hci_cmd_buf[9] = 0x09; //reason max connection return HCI_Command(10, hci_cmd_buf); } @@ -506,9 +419,7 @@ static void HCI_event_task(int result) hci_reset(); } } else if ((hci_buf[3] == HCI_OCF_WRITE_SCAN_ENABLE) && (hci_buf[4] == HCI_OGF_CTRL_BBAND)) { - if (hci_buf[5] == 0) { - bt_dev.status |= DS34BT_STATE_USB_CONFIGURED; - } else { + if (hci_buf[5] != 0) { DelayThread(500); hci_reset(); } @@ -536,17 +447,17 @@ static void HCI_event_task(int result) } DPRINTF("\n"); for (i = 0; i < MAX_PADS; i++) { - if (memcmp(ds34pad[i].bdaddr, hci_buf + 5, 6) == 0) { + if (strncmp(dev[i].bdaddr, hci_buf + 5, 6) == 0) { // store the handle for the ACL connection - ds34pad[i].hci_handle = hci_buf[3] | ((hci_buf[4] & 0x0F) << 8); + dev[i].hci_handle = hci_buf[3] | ((hci_buf[4] & 0x0F) << 8); break; } } - if (i >= MAX_PADS) { + if (i == MAX_PADS) { break; } - pad_status_set(DS34BT_STATE_CONNECTED, i); - hci_remote_name(ds34pad[i].bdaddr); + btdev_status_set(BTDEV_STATE_CONNECTED, i); + hci_remote_name(dev[i].bdaddr); } else { DPRINTF("\t Error 0x%02X \n", hci_buf[2]); } @@ -568,12 +479,16 @@ static void HCI_event_task(int result) DPRINTF("\t Status = 0x%02X \n", hci_buf[2]); DPRINTF("\t Connection_Handle = 0x%04X \n", (hci_buf[3] | ((hci_buf[4] & 0x0F) << 8))); DPRINTF("\t Reason = 0x%02X \n", hci_buf[5]); - for (i = 0; i < MAX_PADS; i++) { // detect pad - if (ds34pad[i].hci_handle == (hci_buf[3] | ((hci_buf[4] & 0x0F) << 8))) { + for (i = 0; i < MAX_PADS; i++) { //detect pad + if (dev[i].hci_handle == (hci_buf[3] | ((hci_buf[4] & 0x0F) << 8))) { break; } } - ds34pad_clear(i); + if (i == MAX_PADS) { + break; + } + pademu_disconnect(&dev[i].dev); + dev_clear(i); break; case HCI_EVENT_AUTHENTICATION_COMPLETE: @@ -592,25 +507,26 @@ static void HCI_event_task(int result) DPRINTF("\t Status = 0x%02X \n", hci_buf[2]); if (!hci_buf[2]) { for (i = 0; i < MAX_PADS; i++) { - if (memcmp(ds34pad[i].bdaddr, hci_buf + 3, 6) == 0) { + if (strncmp(dev[i].bdaddr, hci_buf + 3, 6) == 0) { break; } } - if (i >= MAX_PADS) { + if (i == MAX_PADS) { break; } - if (memcmp(hci_buf + 9, "Wireless Controller", 19) == 0) { - ds34pad[i].type = DS4; - ds34pad[i].isfake = 0; - DPRINTF("\t Type: Dualshock 4 \n"); - } else { - ds34pad[i].type = DS3; - DPRINTF("\t Type: Dualshock 3 \n"); + for (pad = 0; pad < MAX_PADS; pad++) { + if (btpad[pad] != NULL && btpad[pad]->pad_connect(&dev[i].data, hci_buf + 9, 32 - 9)) { + break; + } } - hci_change_connection_type(ds34pad[i].hci_handle); - if (ds34pad[i].type == DS4) { + if (pad == MAX_PADS) { + break; + } + dev[i].pad = btpad[pad]; + hci_change_connection_type(dev[i].hci_handle); + if (dev[i].pad->control_dcid == 0x0070) { identifier++; - l2cap_connection_request(ds34pad[i].hci_handle, identifier, 0x0070, L2CAP_PSM_CTRL); + l2cap_connection_request(dev[i].hci_handle, identifier, dev[i].pad->control_dcid, L2CAP_PSM_CTRL); } } break; @@ -631,39 +547,37 @@ static void HCI_event_task(int result) } DPRINTF("\n\t Link = 0x%02X \n", hci_buf[11]); DPRINTF("\t Class = 0x%02X 0x%02X 0x%02X \n", hci_buf[8], hci_buf[9], hci_buf[10]); - for (i = 0; i < MAX_PADS; i++) { // find free slot - if (!pad_status_check(DS34BT_STATE_RUNNING, i) && ds34pad[i].enabled) { - if (pad_status_check(DS34BT_STATE_CONNECTED, i)) { - if (pad_status_check(DS34BT_STATE_DISCONNECTING, i)) // if we're waiting for hci disconnect event + for (i = 0; i < MAX_PADS; i++) { //find free slot + if (dev[i].pad == NULL && !btdev_status_check(BTDEV_STATE_RUNNING, i)) { + if (btdev_status_check(BTDEV_STATE_CONNECTED, i)) { + if (btdev_status_check(BTDEV_STATE_DISCONNECTING, i)) //if we're waiting for hci disconnect event continue; else - hci_disconnect(ds34pad[i].hci_handle); // try to disconnect + hci_disconnect(dev[i].hci_handle); //try to disconnect } break; } } - if (i >= MAX_PADS) { // no free slot + if (i == MAX_PADS) { //no free slot + DPRINTF("\t No free slot! \n"); hci_reject_connection(hci_buf + 2); break; } pad = i; - mips_memcpy(ds34pad[pad].bdaddr, hci_buf + 2, 6); - ds34pad[pad].isfake = 0; - if (enable_fake) { - ds34pad[pad].isfake = 1; // fake ds3 - for (i = 0; i < sizeof(GenuineMacAddress) / 3; i++) { // check if ds3 is genuine - if (ds34pad[pad].bdaddr[5] == GenuineMacAddress[i][0] && - ds34pad[pad].bdaddr[4] == GenuineMacAddress[i][1] && - ds34pad[pad].bdaddr[3] == GenuineMacAddress[i][2]) { - ds34pad[pad].isfake = 0; - break; - } + mips_memcpy(dev[pad].bdaddr, hci_buf + 2, 6); + dev[pad].data.fix = 1; + for (i = 0; i < sizeof(GenuineMacAddress) / 3; i++) { //check if ds3 is genuine + if (dev[pad].bdaddr[5] == GenuineMacAddress[i][0] && + dev[pad].bdaddr[4] == GenuineMacAddress[i][1] && + dev[pad].bdaddr[3] == GenuineMacAddress[i][2]) { + dev[pad].data.fix = 0; + break; } } - pad_status_clear(DS34BT_STATE_CONNECTED, pad); - pad_status_clear(DS34BT_STATE_RUNNING, pad); - pad_status_clear(DS34BT_STATE_DISCONNECTING, pad); - hci_accept_connection(ds34pad[pad].bdaddr); + btdev_status_clear(BTDEV_STATE_CONNECTED, pad); + btdev_status_clear(BTDEV_STATE_RUNNING, pad); + btdev_status_clear(BTDEV_STATE_DISCONNECTING, pad); + hci_accept_connection(dev[pad].bdaddr); break; case HCI_EVENT_ROLE_CHANGED: @@ -714,51 +628,37 @@ static void HCI_event_task(int result) } } -static void ds34pad_clear(int pad) +static void dev_init() { - if (pad >= MAX_PADS) - return; - - ds34pad[pad].hci_handle = 0x0FFF; - ds34pad[pad].control_scid = 0; - ds34pad[pad].interrupt_scid = 0; - mips_memset(ds34pad[pad].bdaddr, 0, 6); - ds34pad[pad].status = bt_dev.status; - ds34pad[pad].status |= DS34BT_STATE_USB_CONFIGURED; - ds34pad[pad].isfake = 0; - ds34pad[pad].type = 0; - ds34pad[pad].btn_delay = 0; - ds34pad[pad].data[0] = 0xFF; - ds34pad[pad].data[1] = 0xFF; - mips_memset(&ds34pad[pad].data[2], 0x7F, 4); - mips_memset(&ds34pad[pad].data[6], 0x00, 12); + int i; + + for (i = 0; i < MAX_PADS; i++) { + dev_clear(i); + } + identifier = 0; } -static void ds34pad_init() +static void disconnect_all() { int i; - for (i = 0; i < MAX_PADS; i++) { - ds34pad_clear(i); + pademu_disconnect(&dev[i].dev); } - - g_press_emu = 0; - identifier = 0; } static void hci_event_cb(int resultCode, int bytes, void *arg) { - PollSema(bt_dev.hid_sema); + PollSema(bt_adp.hid_sema); HCI_event_task(resultCode); - UsbInterruptTransfer(bt_dev.interruptEndp, hci_buf, MAX_BUFFER_SIZE, hci_event_cb, NULL); - SignalSema(bt_dev.hid_sema); + UsbInterruptTransfer(bt_adp.interruptEndp, hci_buf, MAX_BUFFER_SIZE, hci_event_cb, NULL); + SignalSema(bt_adp.hid_sema); } /************************************************************/ /* L2CAP Commands */ /************************************************************/ -static int L2CAP_Command(u16 handle, u8 *data, u8 length) +static int L2CAP_Command(u16 handle, u16 scid, u8 *data, u8 length) { l2cap_cmd_buf[0] = (u8)(handle & 0xff); // HCI handle with PB,BC flag l2cap_cmd_buf[1] = (u8)(((handle >> 8) & 0x0f) | 0x20); @@ -766,13 +666,13 @@ static int L2CAP_Command(u16 handle, u8 *data, u8 length) l2cap_cmd_buf[3] = (u8)((4 + length) >> 8); l2cap_cmd_buf[4] = (u8)(length & 0xff); // L2CAP header: Length l2cap_cmd_buf[5] = (u8)(length >> 8); - l2cap_cmd_buf[6] = 0x01; // L2CAP header: Channel ID - l2cap_cmd_buf[7] = 0x00; // L2CAP Signalling channel over ACL-U logical link + l2cap_cmd_buf[6] = (u8)(scid & 0xff); // L2CAP header: Channel ID + l2cap_cmd_buf[7] = (u8)(scid >> 8); mips_memcpy(&l2cap_cmd_buf[8], data, length); // output on endpoint 2 - return UsbBulkTransfer(bt_dev.outEndp, l2cap_cmd_buf, (8 + length), NULL, NULL); + return UsbBulkTransfer(bt_adp.outEndp, l2cap_cmd_buf, (8 + length), NULL, NULL); } static int l2cap_connection_request(u16 handle, u8 rxid, u16 scid, u16 psm) @@ -788,7 +688,7 @@ static int l2cap_connection_request(u16 handle, u8 rxid, u16 scid, u16 psm) cmd_buf[6] = (u8)(scid & 0xff); // Source CID (PS Remote) cmd_buf[7] = (u8)(scid >> 8); - return L2CAP_Command(handle, cmd_buf, 8); + return L2CAP_Command(handle, 0x0001, cmd_buf, 8); } static int l2cap_connection_response(u16 handle, u8 rxid, u16 dcid, u16 scid, u8 result) @@ -811,7 +711,7 @@ static int l2cap_connection_response(u16 handle, u8 rxid, u16 dcid, u16 scid, u8 if (result != 0) cmd_buf[10] = 0x01; // Authentication pending - return L2CAP_Command(handle, cmd_buf, 12); + return L2CAP_Command(handle, 0x0001, cmd_buf, 12); } static int l2cap_config_request(u16 handle, u8 rxid, u16 dcid) @@ -828,14 +728,14 @@ static int l2cap_config_request(u16 handle, u8 rxid, u16 dcid) cmd_buf[7] = 0x00; cmd_buf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) cmd_buf[9] = 0x02; // Config Opt: length - // cmd_buf[10] = 0x96; // Config Opt: data - // cmd_buf[11] = 0x00; + //cmd_buf[10] = 0x96; // Config Opt: data + //cmd_buf[11] = 0x00; - // this setting disable hid cmd reports from ds3 + //this setting disable hid cmd reports from ds3 cmd_buf[10] = 0xFF; // Config Opt: data cmd_buf[11] = 0xFF; - return L2CAP_Command(handle, cmd_buf, 12); + return L2CAP_Command(handle, 0x0001, cmd_buf, 12); } static int l2cap_config_response(u16 handle, u8 rxid, u16 scid) @@ -857,7 +757,7 @@ static int l2cap_config_response(u16 handle, u8 rxid, u16 scid) cmd_buf[12] = 0xA0; cmd_buf[13] = 0x02; - return L2CAP_Command(handle, cmd_buf, 14); + return L2CAP_Command(handle, 0x0001, cmd_buf, 14); } static int l2cap_disconnection_request(u16 handle, u8 rxid, u16 dcid, u16 scid) @@ -873,7 +773,7 @@ static int l2cap_disconnection_request(u16 handle, u8 rxid, u16 dcid, u16 scid) cmd_buf[6] = (u8)(scid & 0xff); // Source CID cmd_buf[7] = (u8)(scid >> 8); - return L2CAP_Command(handle, cmd_buf, 8); + return L2CAP_Command(handle, 0x0001, cmd_buf, 8); } static int l2cap_disconnection_response(u16 handle, u8 rxid, u16 scid, u16 dcid) @@ -889,7 +789,7 @@ static int l2cap_disconnection_response(u16 handle, u8 rxid, u16 scid, u16 dcid) cmd_buf[6] = (u8)(scid & 0xff); // Source CID cmd_buf[7] = (u8)(scid >> 8); - return L2CAP_Command(handle, cmd_buf, 8); + return L2CAP_Command(handle, 0x0001, cmd_buf, 8); } #define CMD_DELAY 2 @@ -897,26 +797,19 @@ static int l2cap_disconnection_response(u16 handle, u8 rxid, u16 scid, u16 dcid) static int L2CAP_event_task(int result, int bytes) { int pad = -1; - u16 control_dcid = 0x0040; // Channel endpoint on command source - u16 interrupt_dcid = 0x0041; // Channel endpoint on interrupt source if (!result) { for (pad = 0; pad < MAX_PADS; pad++) { - if (l2cap_handle_ok(ds34pad[pad].hci_handle)) + if (l2cap_handle_ok(dev[pad].hci_handle)) break; } - if (pad >= MAX_PADS) { + if (pad == MAX_PADS) { DPRINTF("L2CAP Wrong Handle = 0x%04X\n", ((l2cap_buf[0] | (l2cap_buf[1] << 8)))); return pad; } - if (l2cap_handle_ok(ds34pad[pad].hci_handle)) { - if (ds34pad[pad].type == DS4) { - control_dcid = 0x0070; - interrupt_dcid = 0x0071; - } - + if (l2cap_handle_ok(dev[pad].hci_handle)) { if (l2cap_control_channel) { DPRINTF("L2CAP Signaling Command = 0x%02X, pad %d \n", l2cap_buf[8], pad); @@ -933,21 +826,21 @@ static int L2CAP_event_task(int result, int bytes) DPRINTF("\t SCID = 0x%04X \n", (l2cap_buf[14] | (l2cap_buf[15] << 8))); if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == L2CAP_PSM_CTRL) { - ds34pad[pad].control_scid = l2cap_buf[14] | (l2cap_buf[15] << 8); - l2cap_connection_response(ds34pad[pad].hci_handle, l2cap_buf[9], control_dcid, ds34pad[pad].control_scid, PENDING); + dev[pad].control_scid = l2cap_buf[14] | (l2cap_buf[15] << 8); + l2cap_connection_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].pad->control_dcid, dev[pad].control_scid, PENDING); DelayThread(CMD_DELAY); - l2cap_connection_response(ds34pad[pad].hci_handle, l2cap_buf[9], control_dcid, ds34pad[pad].control_scid, SUCCESSFUL); + l2cap_connection_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].pad->control_dcid, dev[pad].control_scid, SUCCESSFUL); DelayThread(CMD_DELAY); identifier++; - l2cap_config_request(ds34pad[pad].hci_handle, identifier, ds34pad[pad].control_scid); + l2cap_config_request(dev[pad].hci_handle, identifier, dev[pad].control_scid); } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == L2CAP_PSM_INTR) { - ds34pad[pad].interrupt_scid = l2cap_buf[14] | (l2cap_buf[15] << 8); - l2cap_connection_response(ds34pad[pad].hci_handle, l2cap_buf[9], interrupt_dcid, ds34pad[pad].interrupt_scid, PENDING); + dev[pad].interrupt_scid = l2cap_buf[14] | (l2cap_buf[15] << 8); + l2cap_connection_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].pad->interrupt_dcid, dev[pad].interrupt_scid, PENDING); DelayThread(CMD_DELAY); - l2cap_connection_response(ds34pad[pad].hci_handle, l2cap_buf[9], interrupt_dcid, ds34pad[pad].interrupt_scid, SUCCESSFUL); + l2cap_connection_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].pad->interrupt_dcid, dev[pad].interrupt_scid, SUCCESSFUL); DelayThread(CMD_DELAY); identifier++; - l2cap_config_request(ds34pad[pad].hci_handle, identifier, ds34pad[pad].interrupt_scid); + l2cap_config_request(dev[pad].hci_handle, identifier, dev[pad].interrupt_scid); } break; @@ -958,14 +851,14 @@ static int L2CAP_event_task(int result, int bytes) DPRINTF("\t RESULT = 0x%04X \n", (l2cap_buf[16] | (l2cap_buf[17] << 8))); if (((l2cap_buf[16] | (l2cap_buf[17] << 8)) == 0x0000) && ((l2cap_buf[18] | (l2cap_buf[19] << 8)) == 0x0000)) { - if ((l2cap_buf[14] | (l2cap_buf[15] << 8)) == control_dcid) { - ds34pad[pad].control_scid = l2cap_buf[12] | (l2cap_buf[13] << 8); + if ((l2cap_buf[14] | (l2cap_buf[15] << 8)) == dev[pad].pad->control_dcid) { + dev[pad].control_scid = l2cap_buf[12] | (l2cap_buf[13] << 8); identifier++; - l2cap_config_request(ds34pad[pad].hci_handle, identifier, ds34pad[pad].control_scid); - } else if ((l2cap_buf[14] | (l2cap_buf[15] << 8)) == interrupt_dcid) { - ds34pad[pad].interrupt_scid = l2cap_buf[12] | (l2cap_buf[13] << 8); + l2cap_config_request(dev[pad].hci_handle, identifier, dev[pad].control_scid); + } else if ((l2cap_buf[14] | (l2cap_buf[15] << 8)) == dev[pad].pad->interrupt_dcid) { + dev[pad].interrupt_scid = l2cap_buf[12] | (l2cap_buf[13] << 8); identifier++; - l2cap_config_request(ds34pad[pad].hci_handle, identifier, ds34pad[pad].interrupt_scid); + l2cap_config_request(dev[pad].hci_handle, identifier, dev[pad].interrupt_scid); } } break; @@ -976,10 +869,10 @@ static int L2CAP_event_task(int result, int bytes) DPRINTF("\t SCID = 0x%04X \n", (l2cap_buf[12] | (l2cap_buf[13] << 8))); DPRINTF("\t FLAG = 0x%04X \n", (l2cap_buf[14] | (l2cap_buf[15] << 8))); - if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == control_dcid) { - l2cap_config_response(ds34pad[pad].hci_handle, l2cap_buf[9], ds34pad[pad].control_scid); - } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == interrupt_dcid) { - l2cap_config_response(ds34pad[pad].hci_handle, l2cap_buf[9], ds34pad[pad].interrupt_scid); + if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].pad->control_dcid) { + l2cap_config_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].control_scid); + } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].pad->interrupt_dcid) { + l2cap_config_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].interrupt_scid); } break; @@ -990,51 +883,40 @@ static int L2CAP_event_task(int result, int bytes) DPRINTF("\t FLAG = 0x%04X \n", (l2cap_buf[14] | (l2cap_buf[15] << 8))); DPRINTF("\t RESULT = 0x%04X \n", (l2cap_buf[16] | (l2cap_buf[17] << 8))); - if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == control_dcid) { - if (ds34pad[pad].type == DS4) { + if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].pad->control_dcid) { + if (dev[pad].pad->interrupt_dcid == 0x0071) { identifier++; - l2cap_connection_request(ds34pad[pad].hci_handle, identifier, interrupt_dcid, L2CAP_PSM_INTR); + l2cap_connection_request(dev[pad].hci_handle, identifier, dev[pad].pad->interrupt_dcid, L2CAP_PSM_INTR); } - } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == interrupt_dcid) { - hid_initDS34(pad); - if (ds34pad[pad].type == DS3) { - ds34pad[pad].oldled[0] = led_patterns[pad][1]; - ds34pad[pad].oldled[3] = 0; - } else if (ds34pad[pad].type == DS4) { - ds34pad[pad].oldled[0] = rgbled_patterns[pad][1][0]; - ds34pad[pad].oldled[1] = rgbled_patterns[pad][1][1]; - ds34pad[pad].oldled[2] = rgbled_patterns[pad][1][2]; - ds34pad[pad].oldled[3] = 0; - } - DelayThread(CMD_DELAY); - hid_LEDRumbleCommand(ds34pad[pad].oldled, 0, 0, pad); - pad_status_set(DS34BT_STATE_RUNNING, pad); + } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].pad->interrupt_dcid) { + dev[pad].pad->pad_init(&dev[pad].data, dev[pad].dev.id); + pademu_connect(&dev[pad].dev); + btdev_status_set(BTDEV_STATE_RUNNING, pad); } - ds34pad[pad].btn_delay = 0xFF; break; case L2CAP_CMD_DISCONNECT_REQUEST: DPRINTF("Disconnect Request SCID = 0x%04X \n", (l2cap_buf[12] | (l2cap_buf[13] << 8))); - if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == control_dcid) { - pad_status_set(DS34BT_STATE_DISCONNECTING, pad); - l2cap_disconnection_response(ds34pad[pad].hci_handle, l2cap_buf[9], control_dcid, ds34pad[pad].control_scid); - } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == interrupt_dcid) { - pad_status_set(DS34BT_STATE_DISCONNECTING, pad); - l2cap_disconnection_response(ds34pad[pad].hci_handle, l2cap_buf[9], interrupt_dcid, ds34pad[pad].interrupt_scid); + if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].pad->control_dcid) { + btdev_status_set(BTDEV_STATE_DISCONNECTING, pad); + l2cap_disconnection_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].pad->control_dcid, dev[pad].control_scid); + } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].pad->interrupt_dcid) { + btdev_status_set(BTDEV_STATE_DISCONNECTING, pad); + l2cap_disconnection_response(dev[pad].hci_handle, l2cap_buf[9], dev[pad].pad->interrupt_dcid, dev[pad].interrupt_scid); } break; case L2CAP_CMD_DISCONNECT_RESPONSE: DPRINTF("Disconnect Response SCID = 0x%04X \n", (l2cap_buf[12] | (l2cap_buf[13] << 8))); - if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == ds34pad[pad].control_scid) { - pad_status_set(DS34BT_STATE_DISCONNECTING, pad); - hci_disconnect(ds34pad[pad].hci_handle); - } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == ds34pad[pad].interrupt_scid) { - pad_status_set(DS34BT_STATE_DISCONNECTING, pad); + if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].control_scid) { + btdev_status_set(BTDEV_STATE_DISCONNECTING, pad); + hci_disconnect(dev[pad].hci_handle); + } else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == dev[pad].interrupt_scid) { + btdev_status_set(BTDEV_STATE_DISCONNECTING, pad); identifier++; - l2cap_disconnection_request(ds34pad[pad].hci_handle, identifier, ds34pad[pad].control_scid, control_dcid); + l2cap_disconnection_request(dev[pad].hci_handle, identifier, dev[pad].control_scid, dev[pad].pad->control_dcid); } break; @@ -1042,7 +924,7 @@ static int L2CAP_event_task(int result, int bytes) break; } } else if (l2cap_interrupt_channel) { - hid_readReport(l2cap_buf, bytes, pad); + dev[pad].pad->pad_read_report(&dev[pad].data, l2cap_buf, bytes); } else if (l2cap_command_channel) { DPRINTF("HID command status 0x%02X \n", l2cap_buf[8]); pad = MAX_PADS; @@ -1056,370 +938,188 @@ static int L2CAP_event_task(int result, int bytes) static void l2cap_event_cb(int resultCode, int bytes, void *arg) { int ret; - u16 interrupt_dcid = 0x0041; - PollSema(bt_dev.hid_sema); + PollSema(bt_adp.hid_sema); ret = L2CAP_event_task(resultCode, bytes); if (ret < MAX_PADS) { - if (pad_status_check(DS34BT_STATE_RUNNING, ret)) { - if (pad_status_check(DS34BT_STATE_DISCONNECT_REQUEST, ret)) { - if (!ds34pad[ret].isfake) { - if (ds34pad[ret].type == DS4) { - interrupt_dcid = 0x0071; - } + if (btdev_status_check(BTDEV_STATE_RUNNING, ret)) { + if (btdev_status_check(BTDEV_STATE_DISCONNECT_REQUEST, ret)) { + if (!dev[ret].data.fix) { identifier++; - l2cap_disconnection_request(ds34pad[ret].hci_handle, identifier, ds34pad[ret].interrupt_scid, interrupt_dcid); + l2cap_disconnection_request(dev[ret].hci_handle, identifier, dev[ret].interrupt_scid, dev[ret].pad->interrupt_dcid); } else { - hci_disconnect(ds34pad[ret].hci_handle); + hci_disconnect(dev[ret].hci_handle); } - pad_status_clear(DS34BT_STATE_DISCONNECT_REQUEST, ret); - } else if (ds34pad[ret].update_rum) { - hid_LEDRumbleCommand(ds34pad[ret].oldled, ds34pad[ret].lrum, ds34pad[ret].rrum, ret); - ds34pad[ret].update_rum = 0; + btdev_status_clear(BTDEV_STATE_DISCONNECT_REQUEST, ret); + } else if (dev[ret].data.update_rum) { + dev[ret].pad->pad_rumble(&dev[ret].data); + dev[ret].data.update_rum = 0; } } else { - if (!ds34pad[ret].isfake && ds34pad[ret].type == DS3) - DelayThread(42000); // fix for some bt adapters + if (!dev[ret].data.fix) { + DelayThread(42000); //fix for some bt adapters + } } } - UsbBulkTransfer(bt_dev.inEndp, l2cap_buf, MAX_BUFFER_SIZE + 23, l2cap_event_cb, arg); - SignalSema(bt_dev.hid_sema); + UsbBulkTransfer(bt_adp.inEndp, l2cap_buf, MAX_BUFFER_SIZE + 23, l2cap_event_cb, arg); + SignalSema(bt_adp.hid_sema); } -/************************************************************/ -/* HID Commands */ -/************************************************************/ - -static int HID_command(u16 handle, u16 scid, u8 *data, u8 length, int pad) +void btstack_register(bt_paddrv_t *pad) { - l2cap_cmd_buf[0] = (u8)(handle & 0xff); // HCI handle with PB,BC flag - l2cap_cmd_buf[1] = (u8)(((handle >> 8) & 0x0f) | 0x20); - l2cap_cmd_buf[2] = (u8)((4 + length) & 0xff); // HCI ACL total data length - l2cap_cmd_buf[3] = (u8)((4 + length) >> 8); - l2cap_cmd_buf[4] = (u8)(length & 0xff); // L2CAP header: Length - l2cap_cmd_buf[5] = (u8)(length >> 8); - l2cap_cmd_buf[6] = (u8)(scid & 0xff); // L2CAP header: Channel ID - l2cap_cmd_buf[7] = (u8)(scid >> 8); - - mips_memcpy(&l2cap_cmd_buf[8], data, length); - - // output on endpoint 2 - return UsbBulkTransfer(bt_dev.outEndp, l2cap_cmd_buf, (8 + length), NULL, NULL); + int i; + for (i = 0; i < MAX_PADS; i++) { + if (btpad[i] == NULL) { + btpad[i] = pad; + break; + } + } } -static int hid_initDS34(int pad) +void btstack_unregister(bt_paddrv_t *pad) { - u8 init_buf[PS3_F4_REPORT_LEN + 2]; - u8 size = 2; - - if (ds34pad[pad].type == DS3) { - init_buf[0] = HID_THDR_SET_REPORT_FEATURE; // THdr - init_buf[1] = PS3_F4_REPORT_ID; // Report ID - init_buf[2] = 0x42; - init_buf[3] = 0x03; - init_buf[4] = 0x00; - init_buf[5] = 0x00; - size += PS3_F4_REPORT_LEN; - } else if (ds34pad[pad].type == DS4) { - init_buf[0] = HID_THDR_GET_REPORT_FEATURE; // THdr - init_buf[1] = PS4_02_REPORT_ID; // Report ID + int i; + for (i = 0; i < MAX_PADS; i++) { + if (btpad[i] == pad) { + btpad[i] = NULL; + break; + } } - - return HID_command(ds34pad[pad].hci_handle, ds34pad[pad].control_scid, init_buf, size, pad); } -/** - * Send a HID command with LED and rumble status - * @param led 4 bytes describing LED state. - * For DS3, first byte is bitfield of LEDs switched on - (1 << n) for LED indicator number n (1 ~ 4) - * For DS4, first three bytes are R, G, B values of the front light - * Fourth byte indicates whether light should be blinking (1) or solid (0). - * @param lrum Strength of left rumble motor - * @param lrum Strength of right rumble motor - * @param pad Which pad the command should be sent to - */ -static int hid_LEDRumbleCommand(u8 *led, u8 lrum, u8 rrum, int pad) +int btstack_hid_command(bt_paddrv_t *pad, u8 *data, u8 length, int id) { - u8 led_buf[PS4_11_REPORT_LEN + 2]; - u8 size = 2; - u8 led_bit, i; - - if (ds34pad[pad].type == DS3) { - led_buf[0] = HID_THDR_SET_REPORT_OUTPUT; // THdr - led_buf[1] = PS3_01_REPORT_ID; // Report ID - - u8 *command = &led_buf[size]; - mips_memset(command, 0, OUTPUT_01_REPORT_SIZE); - - if (ds34pad[pad].isfake) { - if (rrum < 5) { - rrum = 0; - } - } - - command[1] = 0xFE; // rt - command[2] = rrum; // rp - command[3] = 0xFE; // lt - command[4] = lrum; // lp - command[9] = led[0] & 0x1F; // LED Conf - for (led_bit = 0x10, i = 0; i < 4; i++, led_bit >>= 1) { - if (led[0] & led_bit) { - mips_memcpy(&command[10 + (i * 5)], hid_cmd_payload_led_arguments, sizeof(hid_cmd_payload_led_arguments)); - if (led[3]) { - command[10 + (i * 5) + 3] = 0x32; - } - } - } - - size += OUTPUT_01_REPORT_SIZE; - } else if (ds34pad[pad].type == DS4) { - mips_memset(led_buf, 0, PS3_01_REPORT_LEN + 2); - - led_buf[0] = HID_THDR_SET_REPORT_OUTPUT; // THdr - led_buf[1] = PS4_11_REPORT_ID; // Report ID - led_buf[2] = 0x80; // update rate 1000Hz - led_buf[4] = 0xFF; - - led_buf[7] = rrum * 255; - led_buf[8] = lrum; - - led_buf[9] = led[0]; // r - led_buf[10] = led[1]; // g - led_buf[11] = led[2]; // b - - if (led[3]) { // means charging, so blink - led_buf[12] = 0x80; // Time to flash bright (255 = 2.5 seconds) - led_buf[13] = 0x80; // Time to flash dark (255 = 2.5 seconds) + int i; + for (i = 0; i < MAX_PADS; i++) { + if (dev[i].pad == pad && dev[i].data.id == id) { + break; } - - size += PS4_11_REPORT_LEN; } - ds34pad[pad].oldled[0] = led[0]; - ds34pad[pad].oldled[1] = led[1]; - ds34pad[pad].oldled[2] = led[2]; - ds34pad[pad].oldled[3] = led[3]; + if (i == MAX_PADS) { + return 0; + } - return HID_command(ds34pad[pad].hci_handle, ds34pad[pad].control_scid, led_buf, size, pad); + return L2CAP_Command(dev[i].hci_handle, dev[i].control_scid, data, length); } -static void hid_readReport(u8 *data, int bytes, int pad_idx) +void btstack_exit(int mode) { - ds34bt_pad_t *pad = &ds34pad[pad_idx]; - if (data[8] == HID_THDR_DATA_INPUT) { - if (data[9] == PS3_01_REPORT_ID) { - if (bytes < 19) { - // Too small - return; - } - - u8 press_emu; - if (bytes < sizeof(struct ds3report)) { - // Too small for full report - press_emu = 1; - } else { - press_emu = g_press_emu; - } - - struct ds3report *report = (struct ds3report *)&data[11]; - - if (report->RightStickX == 0 && report->RightStickY == 0) // ledrumble cmd causes null report sometime - return; - - - translate_pad_ds3(report, &pad->ds2, press_emu); - padMacroPerform(&pad->ds2, report->PSButton); - - u8 reported_power = 0; - if (press_emu) { - reported_power = 0x05; - } else { - reported_power = report->Power; - } - - if (report->PSButton) { // display battery level - if (report->Select && (pad->btn_delay == MAX_DELAY)) { // PS + SELECT - if (pad->analog_btn < 2) // unlocked mode - pad->analog_btn = !pad->analog_btn; - - pad->oldled[0] = led_patterns[pad_idx][(pad->analog_btn & 1)]; - pad->btn_delay = 1; - } else { - if (reported_power <= 0x05) - pad->oldled[0] = power_level[reported_power]; - - if (pad->btn_delay < MAX_DELAY) - pad->btn_delay++; - } - } else { - pad->oldled[0] = led_patterns[pad_idx][(pad->analog_btn & 1)]; - - if (pad->btn_delay > 0) { - pad->btn_delay--; - } - } - - // If charging or about to die - if (reported_power == 0xEE || reported_power == 0x01) { - // Blink for the next update frame (but this executes every frame) - pad->oldled[3] = 1; - } - - } else if (data[9] == PS4_11_REPORT_ID) { - struct ds4report *report = (struct ds4report *)&data[11]; - translate_pad_ds4(report, &pad->ds2, bytes > 63); - padMacroPerform(&pad->ds2, report->PSButton); - - if (report->PSButton) { // display battery level - if (report->Share && (pad->btn_delay == MAX_DELAY)) { // PS + Share - if (pad->analog_btn < 2) { // unlocked mode - pad->analog_btn = !pad->analog_btn; - } - - pad->oldled[0] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][0]; - pad->oldled[1] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][1]; - pad->oldled[2] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][2]; - pad->btn_delay = 1; - } else { - pad->oldled[0] = report->Battery; - pad->oldled[1] = 0; - pad->oldled[2] = 0; - - if (pad->btn_delay < MAX_DELAY) { - pad->btn_delay++; - } - } - } else { - pad->oldled[0] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][0]; - pad->oldled[1] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][1]; - pad->oldled[2] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][2]; + int pad; - if (pad->btn_delay > 0) { - pad->btn_delay--; + if (bt_adp.devId != -1) { + for (pad = 0; pad < MAX_PADS; pad++) { + WaitSema(bt_adp.hid_sema); + btdev_status_set(BTDEV_STATE_DISCONNECT_REQUEST, pad); + SignalSema(bt_adp.hid_sema); + while (1) { + DelayThread(500); + WaitSema(bt_adp.hid_sema); + if (!btdev_status_check(BTDEV_STATE_RUNNING, pad)) { + SignalSema(bt_adp.hid_sema); + break; } + SignalSema(bt_adp.hid_sema); } - - if (report->Power != 0xB && report->Usb_plugged) { // charging - pad->oldled[3] = 1; - } - } - - if (pad->btn_delay > 0) { - pad->update_rum = 1; } - } else { - DPRINTF("Unmanaged Input Report: THDR 0x%02X ", data[8]); - DPRINTF(" ID 0x%02X \n", data[9]); + DelayThread(1000000); + bt_disconnect(bt_adp.devId); } } -/************************************************************/ -/* DS34BT Commands */ -/************************************************************/ - -void ds34bt_set_rumble(u8 lrum, u8 rrum, int port) -{ - WaitSema(bt_dev.hid_sema); - - ds34pad[port].update_rum = 1; - ds34pad[port].lrum = lrum; - ds34pad[port].rrum = rrum; - - SignalSema(bt_dev.hid_sema); -} - -int ds34bt_get_data(u8 *dst, int size, int port) +int btpad_get_data(u8 *dst, int size, int port) { int ret; - WaitSema(bt_dev.hid_sema); + WaitSema(bt_adp.hid_sema); - mips_memcpy(dst, ds34pad[port].data, size); - ret = ds34pad[port].analog_btn & 1; + //DPRINTF("BTSTACK: Get data\n"); + mips_memcpy(dst, dev[port].data.data, size); + ret = dev[port].data.analog_btn & 1; - SignalSema(bt_dev.hid_sema); + SignalSema(bt_adp.hid_sema); return ret; } -void ds34bt_set_mode(int mode, int lock, int port) +void btpad_set_rumble(u8 lrum, u8 rrum, int port) { - WaitSema(bt_dev.hid_sema); + WaitSema(bt_adp.hid_sema); - if (lock == 3) - ds34pad[port].analog_btn = 3; - else - ds34pad[port].analog_btn = mode; + //DPRINTF("BTSTACK: Rumble\n"); + dev[port].data.update_rum = 1; + dev[port].data.lrum = lrum; + dev[port].data.rrum = rrum; - SignalSema(bt_dev.hid_sema); + SignalSema(bt_adp.hid_sema); } -int ds34bt_get_status(int port) +void btpad_set_mode(int mode, int lock, int port) { - int ret; - - WaitSema(bt_dev.hid_sema); + WaitSema(bt_adp.hid_sema); - ret = ds34pad[port].status; + //DPRINTF("BTSTACK: Set mode\n"); + if (lock == 3) + dev[port].data.analog_btn = 3; + else + dev[port].data.analog_btn = mode; - SignalSema(bt_dev.hid_sema); + SignalSema(bt_adp.hid_sema); +} - return ret; +static void dev_clear(int pad) +{ + dev[pad].pad = NULL; + dev[pad].hci_handle = 0x0FFF; + dev[pad].control_scid = 0; + dev[pad].interrupt_scid = 0; + dev[pad].data.lrum = 0; + dev[pad].data.rrum = 0; + dev[pad].data.update_rum = 1; + dev[pad].data.data[0] = 0xFF; + dev[pad].data.data[1] = 0xFF; + dev[pad].data.analog_btn = 0; + dev[pad].status = BTDEV_STATE_USB_CONFIGURED; + dev[pad].dev.id = pad; + dev[pad].dev.pad_get_data = btpad_get_data; + dev[pad].dev.pad_set_rumble = btpad_set_rumble; + dev[pad].dev.pad_set_mode = btpad_set_mode; + + mips_memset(&dev[pad].data.data[2], 0x7F, 4); + mips_memset(&dev[pad].data.data[6], 0x00, 12); + mips_memset(dev[pad].bdaddr, 0, 6); } -int ds34bt_init(u8 pads, u8 options) +extern struct irx_export_table _exp_btstack; + +int _start(int argc, char *argv[]) { - int ret, i; + int ret; - for (i = 0; i < MAX_PADS; i++) - ds34pad[i].enabled = (pads >> i) & 1; + dev_init(); - ds34pad_init(); + if (RegisterLibraryEntries(&_exp_btstack) != 0) { + return MODULE_NO_RESIDENT_END; + } - enable_fake = options & 1; + SetRebootTimeLibraryHandlingMode(&_exp_btstack, 2); - bt_dev.hid_sema = CreateMutex(IOP_MUTEX_UNLOCKED); + bt_adp.hid_sema = CreateMutex(IOP_MUTEX_UNLOCKED); - if (bt_dev.hid_sema < 0) { - DPRINTF("DS34BT: Failed to allocate semaphore.\n"); - return 0; + if (bt_adp.hid_sema < 0) { + DPRINTF("BTSTACK: Failed to allocate semaphore.\n"); + return MODULE_NO_RESIDENT_END; } ret = UsbRegisterDriver(&bt_driver); if (ret != USB_RC_OK) { - DPRINTF("DS34BT: Error registering USB devices: %02X\n", ret); - return 0; + DPRINTF("BTSTACK: Error registering USB devices: %02X\n", ret); + return MODULE_NO_RESIDENT_END; } - UsbRegisterDriver(&chrg_driver); - - return 1; -} - -void ds34bt_reset() -{ - int pad; - - if (bt_dev.status & DS34BT_STATE_USB_AUTHORIZED) { - for (pad = 0; pad < MAX_PADS; pad++) { - WaitSema(bt_dev.hid_sema); - pad_status_set(DS34BT_STATE_DISCONNECT_REQUEST, pad); - SignalSema(bt_dev.hid_sema); - while (1) { - DelayThread(500); - WaitSema(bt_dev.hid_sema); - if (!pad_status_check(DS34BT_STATE_RUNNING, pad)) { - SignalSema(bt_dev.hid_sema); - break; - } - SignalSema(bt_dev.hid_sema); - } - } - DelayThread(1000000); - bt_disconnect(bt_dev.devId); - } + return MODULE_RESIDENT_END; } diff --git a/modules/pademu/ds34bt.h b/modules/pademu/btstack/btstack.h similarity index 50% rename from modules/pademu/ds34bt.h rename to modules/pademu/btstack/btstack.h index 19ec86f02..cce9742b8 100644 --- a/modules/pademu/ds34bt.h +++ b/modules/pademu/btstack/btstack.h @@ -1,16 +1,13 @@ -#ifndef _DS34BT_H_ -#define _DS34BT_H_ +#ifndef _BTSTACK_H_ +#define _BTSTACK_H_ -#include "irx.h" - -#include - -#define DS3 0 -#define DS4 1 +#define USB_CLASS_WIRELESS_CONTROLLER 0xE0 +#define USB_SUBCLASS_RF_CONTROLLER 0x01 +#define USB_PROTOCOL_BLUETOOTH_PROG 0x01 #define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer -#define PENDING 1 +#define PENDING 1 #define SUCCESSFUL 0 typedef struct @@ -21,49 +18,56 @@ typedef struct int interruptEndp; int inEndp; int outEndp; - u8 status; -} bt_device; +} bt_adapter_t; typedef struct { - u16 hci_handle; // hci connection handle - u16 control_scid; // Channel endpoint on command destination - u16 interrupt_scid; // Channel endpoint on interrupt destination - u8 bdaddr[6]; - u8 enabled; - u8 status; - u8 isfake; - u8 type; // 0 - ds3, 1 - ds4 - u8 oldled[4]; // rgb for ds4 and blink + int id; + u8 fix; u8 lrum; u8 rrum; u8 update_rum; - union - { - struct ds2report ds2; - u8 data[18]; - }; u8 analog_btn; + u8 data[18]; + u8 led[4]; u8 btn_delay; -} ds34bt_pad_t; - -enum eDS34BTStatus { - DS34BT_STATE_USB_DISCONNECTED = 0x00, - DS34BT_STATE_USB_AUTHORIZED = 0x01, - DS34BT_STATE_USB_CONFIGURED = 0x02, - DS34BT_STATE_CONNECTED = 0x04, - DS34BT_STATE_RUNNING = 0x08, - DS34BT_STATE_DISCONNECTING = 0x10, - DS34BT_STATE_DISCONNECT_REQUEST = 0x20, -}; +} bt_paddata_t; -#define pad_status_clear(flag, pad) ds34pad[pad].status &= ~flag -#define pad_status_set(flag, pad) ds34pad[pad].status |= flag -#define pad_status_check(flag, pad) (ds34pad[pad].status & flag) +typedef struct +{ + u16 control_dcid; + u16 interrupt_dcid; + int (*pad_connect)(bt_paddata_t *data, u8 *str, int size); + void (*pad_init)(bt_paddata_t *data, int id); + void (*pad_read_report)(bt_paddata_t *data, u8 *in, int bytes); + void (*pad_rumble)(bt_paddata_t *data); +} bt_paddrv_t; -#define hci_event_flag_clear(flag) hci_event_flag &= ~flag -#define hci_event_flag_set(flag) hci_event_flag |= flag -#define hci_event_flag_check(flag) (hci_event_flag & flag) +typedef struct +{ + u16 hci_handle; // hci connection handle + u16 control_scid; // Channel endpoint on command destination + u16 interrupt_scid; // Channel endpoint on interrupt destination + u8 bdaddr[6]; + bt_paddata_t data; + bt_paddrv_t *pad; + pad_device_t dev; + u8 status; +} bt_dev_t; + +enum eBTDEVStatus { + BTDEV_STATE_USB_DISCONNECTED = 0x00, + BTDEV_STATE_USB_AUTHORIZED = 0x01, + BTDEV_STATE_USB_CONFIGURED = 0x02, + BTDEV_STATE_CONNECTED = 0x04, + BTDEV_STATE_RUNNING = 0x08, + BTDEV_STATE_DISCONNECTING = 0x10, + BTDEV_STATE_DISCONNECT_REQUEST = 0x20, +}; + +#define btdev_status_clear(flag, pad) dev[pad].status &= ~flag +#define btdev_status_set(flag, pad) dev[pad].status |= flag +#define btdev_status_check(flag, pad) (dev[pad].status & flag) enum eHCI { // {{{ @@ -84,24 +88,24 @@ enum eHCI { HCI_OGF_INFO_PARAM = (0x04 << 2), // OGF: Informational Parameters /* HCI OpCode Command Field (OCF) */ - HCI_OCF_DISCONNECT = 0x06, // OGF = 0x01 + HCI_OCF_DISCONNECT = 0x06, // OGF = 0x01 HCI_OCF_ACCEPT_CONNECTION = 0x09, // OGF = 0x01 HCI_OCF_REJECT_CONNECTION = 0x0A, // OGF = 0x01 HCI_OCF_CHANGE_CONNECTION_TYPE = 0x0F, // OGF = 0x01 - HCI_OCF_REMOTE_NAME = 0x19, // OGF = 0x01 + HCI_OCF_REMOTE_NAME = 0x19, // OGF = 0x01 HCI_OCF_LINK_KEY_REQUEST_REPLY = 0x0B, // OGF = 0x01 - - HCI_OCF_RESET = 0x03, // OGF = 0x03 - HCI_OCF_WRITE_ACCEPT_TIMEOUT = 0x16, // OGF = 0x03 - HCI_OCF_WRITE_SCAN_ENABLE = 0x1A, // OGF = 0x03 - - HCI_OCF_READ_BDADDR = 0x09, // OGF = 0x04 + + HCI_OCF_RESET = 0x03, // OGF = 0x03 + HCI_OCF_WRITE_ACCEPT_TIMEOUT = 0x16, // OGF = 0x03 + HCI_OCF_WRITE_SCAN_ENABLE = 0x1A, // OGF = 0x03 + + HCI_OCF_READ_BDADDR = 0x09, // OGF = 0x04 /* HCI events managed */ HCI_EVENT_CONNECT_COMPLETE = 0x03, HCI_EVENT_CONNECT_REQUEST = 0x04, HCI_EVENT_DISCONN_COMPLETE = 0x05, - HCI_EVENT_AUTHENTICATION_COMPLETE = 0x06, + HCI_EVENT_AUTHENTICATION_COMPLETE= 0x06, HCI_EVENT_REMOTE_NAME_COMPLETE = 0x07, HCI_EVENT_ENCRYPTION_CHANGE = 0x08, HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE = 0x0B, @@ -114,7 +118,7 @@ enum eHCI { HCI_EVENT_LINK_KEY_REQUEST = 0x17, HCI_EVENT_CHANGED_CONNECTION_TYPE = 0x1D, HCI_EVENT_PAGE_SR_CHANGED = 0x20, - HCI_EVENT_MAX_SLOT_CHANGE = 0x1B, // Max Slots Change event + HCI_EVENT_MAX_SLOT_CHANGE = 0x1B, //Max Slots Change event /* HCI event flags for hci_event_flag */ HCI_FLAG_COMMAND_COMPLETE = 0x01, @@ -138,7 +142,7 @@ enum eL2CAP { /* Bluetooth L2CAP PSM */ L2CAP_PSM_SDP = 0x01, L2CAP_PSM_CTRL = 0x11, // HID_Control - L2CAP_PSM_INTR = 0x13, // HID_Interrupt + L2CAP_PSM_INTR = 0x13, // HID_Interrupt /* Bluetooth L2CAP states for L2CAP_task() */ L2CAP_DOWN_STATE = 0, @@ -174,67 +178,45 @@ enum eL2CAP { L2CAP_CMD_DISCONNECT_REQUEST = 0x06, L2CAP_CMD_DISCONNECT_RESPONSE = 0x07, - /* HCI ACL Data Packet - * - * buf[0] buf[1] buf[2] buf[3] - * 0 4 8 11 12 16 24 31 MSB - * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. - * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet - * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. - * - * buf[4] buf[5] buf[6] buf[7] - * 0 8 16 31 MSB - * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. - * | Length | Channel ID | Basic L2CAP header - * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. - * - * buf[8] buf[9] buf[10] buf[11] - * 0 8 16 31 MSB - * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. - * | Code | Identifier | Length | Control frame (C-frame) - * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format) - */ +/* HCI ACL Data Packet + * + * buf[0] buf[1] buf[2] buf[3] + * 0 4 8 11 12 16 24 31 MSB + * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. + * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet + * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. + * + * buf[4] buf[5] buf[6] buf[7] + * 0 8 16 31 MSB + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. + * | Length | Channel ID | Basic L2CAP header + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. + * + * buf[8] buf[9] buf[10] buf[11] + * 0 8 16 31 MSB + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. + * | Code | Identifier | Length | Control frame (C-frame) + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format) + */ // }}} }; #define l2cap_handle_ok(handle) (((u16)(l2cap_buf[0] | (l2cap_buf[1] << 8)) & 0x0FFF) == (u16)(handle & 0x0FFF)) -#define l2cap_control_channel ((l2cap_buf[6] | (l2cap_buf[7] << 8)) == 0x0001) // Channel ID for ACL-U -#define l2cap_interrupt_channel ((l2cap_buf[6] | (l2cap_buf[7] << 8)) == interrupt_dcid) -#define l2cap_command_channel ((l2cap_buf[6] | (l2cap_buf[7] << 8)) == control_dcid) - -enum eHID { - // {{{ - /* HID event flag */ - HID_FLAG_STATUS_REPORTED = 0x01, - HID_FLAG_BUTTONS_CHANGED = 0x02, - HID_FLAG_EXTENSION = 0x04, - HID_FLAG_COMMAND_SUCCESS = 0x08, +#define l2cap_control_channel ((l2cap_buf[6] | (l2cap_buf[7] << 8)) == 0x0001) // Channel ID for ACL-U +#define l2cap_interrupt_channel ((l2cap_buf[6] | (l2cap_buf[7] << 8)) == dev[pad].pad->interrupt_dcid) +#define l2cap_command_channel ((l2cap_buf[6] | (l2cap_buf[7] << 8)) == dev[pad].pad->control_dcid) - /* Bluetooth HID Transaction Header (THdr) */ - HID_THDR_GET_REPORT_FEATURE = 0x43, - HID_THDR_SET_REPORT_OUTPUT = 0x52, - HID_THDR_SET_REPORT_FEATURE = 0x53, - HID_THDR_DATA_INPUT = 0xa1, +#define btstack_IMPORTS_start DECLARE_IMPORT_TABLE(btstack, 1, 1) - /* Defines of various parameters for PS3 Game controller reports */ - PS3_F4_REPORT_ID = 0xF4, - PS3_F4_REPORT_LEN = 0x04, +void btstack_register(bt_paddrv_t *pad); +#define I_btstack_register DECLARE_IMPORT(4, btstack_register) - PS3_01_REPORT_ID = 0x01, - PS3_01_REPORT_LEN = 0x30, +void btstack_unregister(bt_paddrv_t *pad); +#define I_btstack_unregister DECLARE_IMPORT(5, btstack_unregister) - PS4_02_REPORT_ID = 0x02, - PS4_11_REPORT_ID = 0x11, - PS4_11_REPORT_LEN = 0x4D, - - // }}} -}; +int btstack_hid_command(bt_paddrv_t *pad, u8 *data, u8 length, int id); +#define I_btstack_hid_command DECLARE_IMPORT(6, btstack_hid_command) -int ds34bt_init(u8 pads, u8 options); -int ds34bt_get_status(int port); -void ds34bt_reset(); -int ds34bt_get_data(u8 *dst, int size, int port); -void ds34bt_set_rumble(u8 lrum, u8 rrum, int port); -void ds34bt_set_mode(int mode, int lock, int port); +#define btstack_IMPORTS_end END_IMPORT_TABLE #endif diff --git a/modules/pademu/btstack/exports.tab b/modules/pademu/btstack/exports.tab new file mode 100644 index 000000000..7dec25ab5 --- /dev/null +++ b/modules/pademu/btstack/exports.tab @@ -0,0 +1,12 @@ + +DECLARE_EXPORT_TABLE(btstack, 1, 1) + DECLARE_EXPORT(_start) + DECLARE_EXPORT(_retonly) + DECLARE_EXPORT(btstack_exit) + DECLARE_EXPORT(_retonly) + DECLARE_EXPORT(btstack_register) + DECLARE_EXPORT(btstack_unregister) + DECLARE_EXPORT(btstack_hid_command) +END_EXPORT_TABLE + +void _retonly() {} diff --git a/modules/pademu/btstack/imports.lst b/modules/pademu/btstack/imports.lst new file mode 100644 index 000000000..e36f592dd --- /dev/null +++ b/modules/pademu/btstack/imports.lst @@ -0,0 +1,68 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end diff --git a/modules/pademu/btstack/irx_imports.h b/modules/pademu/btstack/irx_imports.h new file mode 100644 index 000000000..280115628 --- /dev/null +++ b/modules/pademu/btstack/irx_imports.h @@ -0,0 +1,40 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/ds34usb.c b/modules/pademu/ds34usb.c deleted file mode 100644 index 96f180fcd..000000000 --- a/modules/pademu/ds34usb.c +++ /dev/null @@ -1,575 +0,0 @@ -#include "types.h" -#include "loadcore.h" -#include "stdio.h" -#include "sifrpc.h" -#include "sysclib.h" -#include "usbd.h" -#include "usbd_macro.h" -#include "thbase.h" -#include "thsemap.h" -#include "ds34usb.h" -#include "sys_utils.h" -#include "padmacro.h" - -// #define DPRINTF(x...) printf(x) -#define DPRINTF(x...) - -#define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) -#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) - -#define MAX_PADS 4 - -static u8 output_01_report[] = - { - 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00}; - -static u8 led_patterns[][2] = - { - {0x1C, 0x02}, - {0x1A, 0x04}, - {0x16, 0x08}, - {0x0E, 0x10}, -}; - -static u8 power_level[] = - { - 0x00, 0x00, 0x02, 0x06, 0x0E, 0x1E}; - -static u8 rgbled_patterns[][2][3] = - { - {{0x00, 0x00, 0x10}, {0x00, 0x00, 0x7F}}, // light blue/blue - {{0x00, 0x10, 0x00}, {0x00, 0x7F, 0x00}}, // light green/green - {{0x10, 0x10, 0x00}, {0x7F, 0x7F, 0x00}}, // light yellow/yellow - {{0x00, 0x10, 0x10}, {0x00, 0x7F, 0x7F}}, // light cyan/cyan -}; - -static u8 usb_buf[MAX_BUFFER_SIZE + 32] __attribute((aligned(4))) = {0}; - -int usb_probe(int devId); -int usb_connect(int devId); -int usb_disconnect(int devId); - -static void usb_release(int pad); -static void usb_config_set(int result, int count, void *arg); - -UsbDriver usb_driver = {NULL, NULL, "ds34usb", usb_probe, usb_connect, usb_disconnect}; - -static void DS3USB_init(int pad); -static void readReport(u8 *data, int pad); -static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); - -ds34usb_device ds34pad[MAX_PADS]; - -int usb_probe(int devId) -{ - UsbDeviceDescriptor *device = NULL; - - DPRINTF("DS34USB: probe: devId=%i\n", devId); - - device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); - if (device == NULL) { - DPRINTF("DS34USB: Error - Couldn't get device descriptor\n"); - return 0; - } - - if (device->idVendor == SONY_VID && (device->idProduct == GUITAR_HERO_PS3_PID || device->idProduct == ROCK_BAND_PS3_PID)) { - return 1; - } - - if (device->idVendor == DS34_VID && (device->idProduct == DS3_PID || device->idProduct == DS4_PID || device->idProduct == DS4_PID_SLIM)) - return 1; - - return 0; -} - -int usb_connect(int devId) -{ - int pad, epCount; - UsbDeviceDescriptor *device; - UsbConfigDescriptor *config; - UsbInterfaceDescriptor *interface; - UsbEndpointDescriptor *endpoint; - - DPRINTF("DS34USB: connect: devId=%i\n", devId); - - for (pad = 0; pad < MAX_PADS; pad++) { - if (ds34pad[pad].devId == -1 && ds34pad[pad].enabled) - break; - } - - if (pad >= MAX_PADS) { - DPRINTF("DS34USB: Error - only %d device allowed !\n", MAX_PADS); - return 1; - } - - PollSema(ds34pad[pad].sema); - - ds34pad[pad].devId = devId; - - ds34pad[pad].status = DS34USB_STATE_AUTHORIZED; - - ds34pad[pad].controlEndp = UsbOpenEndpoint(devId, NULL); - - device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); - config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); - interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); - - if (device->idProduct == DS3_PID) { - ds34pad[pad].type = DS3; - epCount = interface->bNumEndpoints - 1; - } else if (device->idProduct == GUITAR_HERO_PS3_PID) { - ds34pad[pad].type = GUITAR_GH; - epCount = interface->bNumEndpoints - 1; - } else if (device->idProduct == ROCK_BAND_PS3_PID) { - ds34pad[pad].type = GUITAR_RB; - epCount = interface->bNumEndpoints - 1; - } else { - ds34pad[pad].type = DS4; - epCount = 20; // ds4 v2 returns interface->bNumEndpoints as 0 - } - - endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); - - do { - if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { - if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && ds34pad[pad].interruptEndp < 0) { - ds34pad[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("DS34USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", ds34pad[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); - } - if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && ds34pad[pad].outEndp < 0) { - ds34pad[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("DS34USB: register Output endpoint id =%i addr=%02X packetSize=%i\n", ds34pad[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); - } - } - - endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength); - - } while (epCount--); - - if (ds34pad[pad].interruptEndp < 0 || ds34pad[pad].outEndp < 0) { - usb_release(pad); - return 1; - } - - ds34pad[pad].status |= DS34USB_STATE_CONNECTED; - - UsbSetDeviceConfiguration(ds34pad[pad].controlEndp, config->bConfigurationValue, usb_config_set, (void *)pad); - SignalSema(ds34pad[pad].sema); - - return 0; -} - -int usb_disconnect(int devId) -{ - u8 pad; - - DPRINTF("DS34USB: disconnect: devId=%i\n", devId); - - for (pad = 0; pad < MAX_PADS; pad++) { - if (ds34pad[pad].devId == devId) - break; - } - - if (pad < MAX_PADS) - usb_release(pad); - - return 0; -} - -static void usb_release(int pad) -{ - PollSema(ds34pad[pad].sema); - - if (ds34pad[pad].interruptEndp >= 0) - UsbCloseEndpoint(ds34pad[pad].interruptEndp); - - if (ds34pad[pad].outEndp >= 0) - UsbCloseEndpoint(ds34pad[pad].outEndp); - - ds34pad[pad].controlEndp = -1; - ds34pad[pad].interruptEndp = -1; - ds34pad[pad].outEndp = -1; - ds34pad[pad].devId = -1; - ds34pad[pad].status = DS34USB_STATE_DISCONNECTED; - - SignalSema(ds34pad[pad].sema); -} - -static int usb_resulCode; - -static void usb_data_cb(int resultCode, int bytes, void *arg) -{ - int pad = (int)arg; - - // DPRINTF("DS34USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); - - usb_resulCode = resultCode; - - SignalSema(ds34pad[pad].sema); -} - -static void usb_cmd_cb(int resultCode, int bytes, void *arg) -{ - int pad = (int)arg; - - // DPRINTF("DS34USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); - - SignalSema(ds34pad[pad].cmd_sema); -} - -static void usb_config_set(int result, int count, void *arg) -{ - int pad = (int)arg; - u8 led[4]; - - PollSema(ds34pad[pad].sema); - - ds34pad[pad].status |= DS34USB_STATE_CONFIGURED; - - if (ds34pad[pad].type == DS3) { - DS3USB_init(pad); - DelayThread(10000); - led[0] = led_patterns[pad][1]; - led[3] = 0; - } else if (ds34pad[pad].type == DS4) { - led[0] = rgbled_patterns[pad][1][0]; - led[1] = rgbled_patterns[pad][1][1]; - led[2] = rgbled_patterns[pad][1][2]; - led[3] = 0; - } - - LEDRumble(led, 0, 0, pad); - - ds34pad[pad].status |= DS34USB_STATE_RUNNING; - - SignalSema(ds34pad[pad].sema); -} - -static void DS3USB_init(int pad) -{ - usb_buf[0] = 0x42; - usb_buf[1] = 0x0c; - usb_buf[2] = 0x00; - usb_buf[3] = 0x00; - - UsbControlTransfer(ds34pad[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_GET_REPORT_FEATURE << 8) | 0xF4, 0, 4, usb_buf, NULL, NULL); -} - -#define MAX_DELAY 10 - -static void readReport(u8 *data, int pad_idx) -{ - ds34usb_device *pad = &ds34pad[pad_idx]; - if (pad->type == GUITAR_GH || pad->type == GUITAR_RB) { - struct ds3guitarreport *report; - - report = (struct ds3guitarreport *)data; - - translate_pad_guitar(report, &pad->ds2, pad->type == GUITAR_GH); - padMacroPerform(&pad->ds2, report->PSButton); - } - if (data[0]) { - - if (pad->type == DS3) { - struct ds3report *report; - - report = (struct ds3report *)&data[2]; - - if (report->RightStickX == 0 && report->RightStickY == 0) // ledrumble cmd causes null report sometime - return; - - pad->data[0] = ~report->ButtonStateL; - pad->data[1] = ~report->ButtonStateH; - - translate_pad_ds3(report, &pad->ds2, 0); - padMacroPerform(&pad->ds2, report->PSButton); - if (report->PSButton) { // display battery level - if (report->Select && (pad->btn_delay == MAX_DELAY)) { // PS + SELECT - if (pad->analog_btn < 2) // unlocked mode - pad->analog_btn = !pad->analog_btn; - - pad->oldled[0] = led_patterns[pad_idx][(pad->analog_btn & 1)]; - pad->btn_delay = 1; - } else { - if (report->Power <= 0x05) - pad->oldled[0] = power_level[report->Power]; - - if (pad->btn_delay < MAX_DELAY) - pad->btn_delay++; - } - } else { - pad->oldled[0] = led_patterns[pad_idx][(pad->analog_btn & 1)]; - - if (pad->btn_delay > 0) - pad->btn_delay--; - } - - if (report->Power == 0xEE) // charging - pad->oldled[3] = 1; - else - pad->oldled[3] = 0; - - } else if (pad->type == DS4) { - struct ds4report *report; - report = (struct ds4report *)data; - translate_pad_ds4(report, &pad->ds2, 1); - padMacroPerform(&pad->ds2, report->PSButton); - - if (report->PSButton) { // display battery level - if (report->Share && (pad->btn_delay == MAX_DELAY)) { // PS + Share - if (pad->analog_btn < 2) // unlocked mode - pad->analog_btn = !pad->analog_btn; - - pad->oldled[0] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][0]; - pad->oldled[1] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][1]; - pad->oldled[2] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][2]; - pad->btn_delay = 1; - } else { - pad->oldled[0] = report->Battery; - pad->oldled[1] = 0; - pad->oldled[2] = 0; - - if (pad->btn_delay < MAX_DELAY) - pad->btn_delay++; - } - } else { - pad->oldled[0] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][0]; - pad->oldled[1] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][1]; - pad->oldled[2] = rgbled_patterns[pad_idx][(pad->analog_btn & 1)][2]; - - if (pad->btn_delay > 0) - pad->btn_delay--; - } - - if (report->Power != 0xB && report->Usb_plugged) // charging - pad->oldled[3] = 1; - else - pad->oldled[3] = 0; - } - if (pad->btn_delay > 0) { - pad->update_rum = 1; - } - } -} - -static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) -{ - int ret = 0; - - PollSema(ds34pad[pad].cmd_sema); - - mips_memset(usb_buf, 0, sizeof(usb_buf)); - - if (ds34pad[pad].type == DS3) { - mips_memcpy(usb_buf, output_01_report, sizeof(output_01_report)); - - usb_buf[1] = 0xFE; // rt - usb_buf[2] = rrum; // rp - usb_buf[3] = 0xFE; // lt - usb_buf[4] = lrum; // lp - - usb_buf[9] = led[0] & 0x7F; // LED Conf - - if (led[3]) // means charging, so blink - { - usb_buf[13] = 0x32; - usb_buf[18] = 0x32; - usb_buf[23] = 0x32; - usb_buf[28] = 0x32; - } - - ret = UsbControlTransfer(ds34pad[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_SET_REPORT_OUTPUT << 8) | 0x01, 0, sizeof(output_01_report), usb_buf, usb_cmd_cb, (void *)pad); - } else if (ds34pad[pad].type == DS4) { - usb_buf[0] = 0x05; - usb_buf[1] = 0xFF; - - usb_buf[4] = rrum * 255; // ds4 has full control - usb_buf[5] = lrum; - - usb_buf[6] = led[0]; // r - usb_buf[7] = led[1]; // g - usb_buf[8] = led[2]; // b - - if (led[3]) // means charging, so blink - { - usb_buf[9] = 0x80; // Time to flash bright (255 = 2.5 seconds) - usb_buf[10] = 0x80; // Time to flash dark (255 = 2.5 seconds) - } - - ret = UsbInterruptTransfer(ds34pad[pad].outEndp, usb_buf, 32, usb_cmd_cb, (void *)pad); - } - - ds34pad[pad].oldled[0] = led[0]; - ds34pad[pad].oldled[1] = led[1]; - ds34pad[pad].oldled[2] = led[2]; - ds34pad[pad].oldled[3] = led[3]; - - return ret; -} - -static unsigned int timeout(void *arg) -{ - int sema = (int)arg; - iSignalSema(sema); - return 0; -} - -static void TransferWait(int sema) -{ - iop_sys_clock_t cmd_timeout; - - cmd_timeout.lo = 200000; - cmd_timeout.hi = 0; - - if (SetAlarm(&cmd_timeout, timeout, (void *)sema) == 0) { - WaitSema(sema); - CancelAlarm(timeout, NULL); - } -} - -void ds34usb_set_rumble(u8 lrum, u8 rrum, int port) -{ - WaitSema(ds34pad[port].sema); - - ds34pad[port].update_rum = 1; - ds34pad[port].lrum = lrum; - ds34pad[port].rrum = rrum; - - SignalSema(ds34pad[port].sema); -} - -int ds34usb_get_data(u8 *dst, int size, int port) -{ - int ret = 0; - - WaitSema(ds34pad[port].sema); - - PollSema(ds34pad[port].sema); - - ret = UsbInterruptTransfer(ds34pad[port].interruptEndp, usb_buf, MAX_BUFFER_SIZE, usb_data_cb, (void *)port); - - if (ret == USB_RC_OK) { - TransferWait(ds34pad[port].sema); - if (!usb_resulCode) - readReport(usb_buf, port); - - usb_resulCode = 1; - } else { - DPRINTF("DS34USB: ds34usb_get_data usb transfer error %d\n", ret); - } - - mips_memcpy(dst, ds34pad[port].data, size); - ret = ds34pad[port].analog_btn & 1; - - if (ds34pad[port].update_rum) { - ret = LEDRumble(ds34pad[port].oldled, ds34pad[port].lrum, ds34pad[port].rrum, port); - if (ret == USB_RC_OK) - TransferWait(ds34pad[port].cmd_sema); - else - DPRINTF("DS34USB: LEDRumble usb transfer error %d\n", ret); - - ds34pad[port].update_rum = 0; - } - - SignalSema(ds34pad[port].sema); - - return ret; -} - -void ds34usb_set_mode(int mode, int lock, int port) -{ - if (lock == 3) - ds34pad[port].analog_btn = 3; - else - ds34pad[port].analog_btn = mode; -} - -void ds34usb_reset() -{ - int pad; - - for (pad = 0; pad < MAX_PADS; pad++) - usb_release(pad); -} - -int ds34usb_get_status(int port) -{ - int ret; - - WaitSema(ds34pad[port].sema); - ret = ds34pad[port].status; - SignalSema(ds34pad[port].sema); - - return ret; -} - -int ds34usb_get_model(int port) -{ - int ret; - - WaitSema(ds34pad[port].sema); - if (ds34pad[port].type == GUITAR_GH || ds34pad[port].type == GUITAR_RB) { - ret = MODEL_GUITAR; - } else { - ret = MODEL_PS2; - } - SignalSema(ds34pad[port].sema); - - return ret; -} - -int ds34usb_init(u8 pads, u8 options) -{ - int pad; - - for (pad = 0; pad < MAX_PADS; pad++) { - ds34pad[pad].status = 0; - ds34pad[pad].devId = -1; - ds34pad[pad].oldled[0] = 0; - ds34pad[pad].oldled[1] = 0; - ds34pad[pad].oldled[2] = 0; - ds34pad[pad].oldled[3] = 0; - ds34pad[pad].lrum = 0; - ds34pad[pad].rrum = 0; - ds34pad[pad].update_rum = 1; - ds34pad[pad].sema = -1; - ds34pad[pad].cmd_sema = -1; - ds34pad[pad].controlEndp = -1; - ds34pad[pad].interruptEndp = -1; - ds34pad[pad].enabled = (pads >> pad) & 1; - ds34pad[pad].type = 0; - - ds34pad[pad].data[0] = 0xFF; - ds34pad[pad].data[1] = 0xFF; - ds34pad[pad].analog_btn = 0; - - mips_memset(&ds34pad[pad].data[2], 0x7F, 4); - mips_memset(&ds34pad[pad].data[6], 0x00, 12); - - ds34pad[pad].sema = CreateMutex(IOP_MUTEX_UNLOCKED); - ds34pad[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); - - if (ds34pad[pad].sema < 0 || ds34pad[pad].cmd_sema < 0) { - DPRINTF("DS34USB: Failed to allocate I/O semaphore.\n"); - return 0; - } - } - - if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { - DPRINTF("DS34USB: Error registering USB devices\n"); - return 0; - } - - return 1; -} diff --git a/modules/pademu/ds34usb.h b/modules/pademu/ds34usb.h deleted file mode 100644 index 8bbc965c8..000000000 --- a/modules/pademu/ds34usb.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _DS34USB_H_ -#define _DS34USB_H_ - -#include "irx.h" - -#include - -#define DS3 0 -#define DS4 1 -#define GUITAR_GH 2 -#define GUITAR_RB 3 - -#define MODEL_GUITAR 1 -#define MODEL_PS2 3 - -#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer - -typedef struct _usb_ds34 -{ - int devId; - int sema; - int cmd_sema; - int controlEndp; - int interruptEndp; - int outEndp; - u8 enabled; - u8 status; - u8 type; // 0 - ds3, 1 - ds4, 2 - guitar hero guitar, 3 - rock band guitar - u8 oldled[4]; // rgb for ds4 and blink - u8 lrum; - u8 rrum; - u8 update_rum; - union - { - struct ds2report ds2; - u8 data[18]; - }; - u8 analog_btn; - u8 btn_delay; -} ds34usb_device; - -enum eDS34USBStatus { - DS34USB_STATE_DISCONNECTED = 0x00, - DS34USB_STATE_AUTHORIZED = 0x01, - DS34USB_STATE_CONFIGURED = 0x02, - DS34USB_STATE_CONNECTED = 0x04, - DS34USB_STATE_RUNNING = 0x08, -}; - -enum eHID { - // {{{ - /* HID event flag */ - HID_FLAG_STATUS_REPORTED = 0x01, - HID_FLAG_BUTTONS_CHANGED = 0x02, - HID_FLAG_EXTENSION = 0x04, - HID_FLAG_COMMAND_SUCCESS = 0x08, - - /* USB HID Transaction Header (THdr) */ - HID_USB_GET_REPORT_FEATURE = 0x03, - HID_USB_SET_REPORT_OUTPUT = 0x02, - HID_USB_DATA_INPUT = 0x01, - - /* Defines of various parameters for PS3 Game controller reports */ - PS3_F4_REPORT_ID = 0xF4, - PS3_F4_REPORT_LEN = 0x04, - - PS3_01_REPORT_ID = 0x01, - PS3_01_REPORT_LEN = 0x30, - - PS4_02_REPORT_ID = 0x02, - PS4_11_REPORT_ID = 0x11, - PS4_11_REPORT_LEN = 0x4D, - // }}} -}; - -int ds34usb_init(u8 pads, u8 options); -int ds34usb_get_status(int port); -int ds34usb_get_model(int port); -void ds34usb_reset(); -int ds34usb_get_data(u8 *dst, int size, int port); -void ds34usb_set_rumble(u8 lrum, u8 rrum, int port); -void ds34usb_set_mode(int mode, int lock, int port); - -#endif diff --git a/modules/pademu/ds3bt/Makefile b/modules/pademu/ds3bt/Makefile new file mode 100644 index 000000000..7147be201 --- /dev/null +++ b/modules/pademu/ds3bt/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = ds3bt.irx +IOP_OBJS = ds3bt.o imports.o +IOP_OBJS_DIR = obj.ds3bt/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/ds3bt/ds3bt.c b/modules/pademu/ds3bt/ds3bt.c new file mode 100644 index 000000000..4640cb61d --- /dev/null +++ b/modules/pademu/ds3bt/ds3bt.c @@ -0,0 +1,220 @@ +#include "irx.h" +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "thbase.h" +#include "thsemap.h" +#include "../pademu.h" +#include "../btstack/btstack.h" +#include "ds3bt.h" + +#define DPRINTF(x...) printf(x) +//#define DPRINTF(x...) + +static u8 output_01_report[] = + { + 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x02, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00}; + +static u8 led_patterns[][2] = + { + {0x1C, 0x02}, + {0x1A, 0x04}, + {0x16, 0x08}, + {0x0E, 0x10}, +}; + +static u8 power_level[] = + { + 0x00, 0x00, 0x02, 0x06, 0x0E, 0x1E}; + +int ds3bt_connect(bt_paddata_t *data, u8 *str, int size); +void ds3bt_init(bt_paddata_t *data, int id); +void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes); +void ds3bt_rumble(bt_paddata_t *data); + +bt_paddrv_t ds3btdrv = {0x0040, 0x0041, ds3bt_connect, ds3bt_init, ds3bt_read_report, ds3bt_rumble}; + +static u8 press_emu = 0; + +#define MAX_DELAY 10 +#define CMD_DELAY 2 + +int ds3bt_connect(bt_paddata_t *data, u8 *str, int size) +{ + DPRINTF("BS3BT: %s \n", str); //PLAYSTATION(R)3 Controller + + if (strncmp(str, "PLAYSTATION(R)3 Controller", 26) != 0) { + return 0; + } + + return 1; +} + +void ds3bt_init(bt_paddata_t *data, int id) +{ + u8 init_buf[PS3_F4_REPORT_LEN + 2]; + + init_buf[0] = HID_THDR_SET_REPORT_FEATURE; // THdr + init_buf[1] = PS3_F4_REPORT_ID; // Report ID + init_buf[2] = 0x42; + init_buf[3] = 0x03; + init_buf[4] = 0x00; + init_buf[5] = 0x00; + + btstack_hid_command(&ds3btdrv, init_buf, PS3_F4_REPORT_LEN + 2, data->id); + + data->id = id; + data->led[0] = led_patterns[id][1]; + data->led[1] = 0; + DelayThread(CMD_DELAY); + ds3bt_rumble(data); + data->btn_delay = 0xFF; + press_emu = 0; +} + +void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes) +{ + if (in[8] == HID_THDR_DATA_INPUT) { + ds3report_t *report = (ds3report_t *)(in + 9); + if (report->ReportID == PS3_01_REPORT_ID) { + + if (report->RightStickX == 0 && report->RightStickY == 0) // ledrumble cmd causes null report sometime + return; + + data->data[0] = ~report->ButtonStateL; + data->data[1] = ~report->ButtonStateH; + + data->data[2] = report->RightStickX; //rx + data->data[3] = report->RightStickY; //ry + data->data[4] = report->LeftStickX; //lx + data->data[5] = report->LeftStickY; //ly + + if (bytes == 21 && !press_emu) + press_emu = 1; + + if (press_emu) { //needs emulating pressure buttons + data->data[6] = report->Right * 255; //right + data->data[7] = report->Left * 255; //left + data->data[8] = report->Up * 255; //up + data->data[9] = report->Down * 255; //down + + data->data[10] = report->Triangle * 255; //triangle + data->data[11] = report->Circle * 255; //circle + data->data[12] = report->Cross * 255; //cross + data->data[13] = report->Square * 255; //square + + data->data[14] = report->L1 * 255; //L1 + data->data[15] = report->R1 * 255; //R1 + data->data[16] = report->L2 * 255; //L2 + data->data[17] = report->R2 * 255; //R2 + + report->Power = 0x05; + } else { + data->data[6] = report->PressureRight; //right + data->data[7] = report->PressureLeft; //left + data->data[8] = report->PressureUp; //up + data->data[9] = report->PressureDown; //down + + data->data[10] = report->PressureTriangle; //triangle + data->data[11] = report->PressureCircle; //circle + data->data[12] = report->PressureCross; //cross + data->data[13] = report->PressureSquare; //square + + data->data[14] = report->PressureL1; //L1 + data->data[15] = report->PressureR1; //R1 + data->data[16] = report->PressureL2; //L2 + data->data[17] = report->PressureR2; //R2 + } + + if (report->PSButtonState) { //display battery level + if (report->Select && (data->btn_delay == MAX_DELAY)) { //PS + SELECT + if (data->analog_btn < 2) //unlocked mode + data->analog_btn = !data->analog_btn; + + data->led[0] = led_patterns[data->id][(data->analog_btn & 1)]; + data->btn_delay = 1; + } else { + if (report->Power != 0xEE) + data->led[0] = power_level[report->Power]; + + if (data->btn_delay < MAX_DELAY) + data->btn_delay++; + } + } else { + data->led[0] = led_patterns[data->id][(data->analog_btn & 1)]; + + if (data->btn_delay > 0) + data->btn_delay--; + } + + if (report->Power == 0xEE) //charging + data->led[1] = 1; + else + data->led[1] = 0; + + if (data->btn_delay > 0) { + data->update_rum = 1; + } + } + } else { + DPRINTF("BS3BT: Unmanaged Input Report: THDR 0x%02X ", in[8]); + DPRINTF("BS3BT: ID 0x%02X \n", in[9]); + } +} + +void ds3bt_rumble(bt_paddata_t *data) +{ + u8 led_buf[PS3_01_REPORT_LEN + 2]; + mips_memset(led_buf, 0, sizeof(led_buf)); + mips_memcpy(led_buf + 2, output_01_report, sizeof(output_01_report)); + + if (data->fix) + led_buf[0] = 0xA2; // THdr + else + led_buf[0] = HID_THDR_SET_REPORT_OUTPUT; // THdr + + led_buf[1] = PS3_01_REPORT_ID; // Report ID + + mips_memcpy(&led_buf[2], output_01_report, sizeof(output_01_report)); // PS3_01_REPORT_LEN); + + if (data->fix) { + if (data->rrum < 5) + data->rrum = 0; + } + + led_buf[3] = 0xFE; //rt + led_buf[4] = data->rrum; //rp + led_buf[5] = 0xFE; //lt + led_buf[6] = data->lrum; //lp + + led_buf[11] = data->led[0] & 0x7F; //LED Conf + + if (data->led[1]) { //means charging, so blink + led_buf[15] = 0x32; + led_buf[20] = 0x32; + led_buf[25] = 0x32; + led_buf[30] = 0x32; + } + + btstack_hid_command(&ds3btdrv, led_buf, sizeof(output_01_report) + 2, data->id); +} + +int _start(int argc, char *argv[]) +{ + btstack_register(&ds3btdrv); + + return MODULE_RESIDENT_END; +} diff --git a/modules/pademu/ds3bt/ds3bt.h b/modules/pademu/ds3bt/ds3bt.h new file mode 100644 index 000000000..52441df28 --- /dev/null +++ b/modules/pademu/ds3bt/ds3bt.h @@ -0,0 +1,94 @@ +#ifndef _DS3BT_H_ +#define _DS3BT_H_ + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +enum eHID { + // {{{ + /* HID event flag */ + HID_FLAG_STATUS_REPORTED = 0x01, + HID_FLAG_BUTTONS_CHANGED = 0x02, + HID_FLAG_EXTENSION = 0x04, + HID_FLAG_COMMAND_SUCCESS = 0x08, + + /* Bluetooth HID Transaction Header (THdr) */ + HID_THDR_GET_REPORT_FEATURE = 0x43, + HID_THDR_SET_REPORT_OUTPUT = 0x52, + HID_THDR_SET_REPORT_FEATURE = 0x53, + HID_THDR_DATA_INPUT = 0xa1, + + /* Defines of various parameters for PS3 Game controller reports */ + PS3_F4_REPORT_ID = 0xF4, + PS3_F4_REPORT_LEN = 0x04, + + PS3_01_REPORT_ID = 0x01, + PS3_01_REPORT_LEN = 0x30, + + PS4_02_REPORT_ID = 0x02, + PS4_11_REPORT_ID = 0x11, + PS4_11_REPORT_LEN = 0x4D, + + // }}} +}; + +typedef struct { + u8 ReportID; + u8 Zero; + union { + u8 ButtonStateL; // Main buttons Low + struct { + u8 Select : 1; + u8 L3 : 1; + u8 R3 : 1; + u8 Start : 1; + u8 Up : 1; + u8 Right : 1; + u8 Down : 1; + u8 Left : 1; + }; + }; + union { + u8 ButtonStateH; // Main buttons High + struct { + u8 L2 : 1; + u8 R2 : 1; + u8 L1 : 1; + u8 R1 : 1; + u8 Triangle : 1; + u8 Circle : 1; + u8 Cross : 1; + u8 Square : 1; + }; + }; + u8 PSButtonState; // PS button + u8 Reserved1; // Unknown + u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid + u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid + u8 RightStickX; // right Joystick X axis 0 - 255, 128 is mid + u8 RightStickY; // right Joystick Y axis 0 - 255, 128 is mid + u8 Reserved2[4]; // Unknown + u8 PressureUp; // digital Pad Up button Pressure 0 - 255 + u8 PressureRight; // digital Pad Right button Pressure 0 - 255 + u8 PressureDown; // digital Pad Down button Pressure 0 - 255 + u8 PressureLeft; // digital Pad Left button Pressure 0 - 255 + u8 PressureL2; // digital Pad L2 button Pressure 0 - 255 + u8 PressureR2; // digital Pad R2 button Pressure 0 - 255 + u8 PressureL1; // digital Pad L1 button Pressure 0 - 255 + u8 PressureR1; // digital Pad R1 button Pressure 0 - 255 + u8 PressureTriangle; // digital Pad Triangle button Pressure 0 - 255 + u8 PressureCircle; // digital Pad Circle button Pressure 0 - 255 + u8 PressureCross; // digital Pad Cross button Pressure 0 - 255 + u8 PressureSquare; // digital Pad Square button Pressure 0 - 255 + u8 Reserved3[3]; // Unknown + u8 Charge; // charging status ? 02 = charge, 03 = normal + u8 Power; // Battery status ? 05=full - 02=dying, 01=just before shutdown, EE=charging + u8 Connection; // Connection Type ? 14 when operating by bluetooth, 10 when operating by bluetooth with cable plugged in, 16 when bluetooh and rumble + u8 Reserved4[9]; // Unknown + s16 AccelX; + s16 AccelY; + s16 AccelZ; + s16 GyroZ; + +} __attribute__((packed)) ds3report_t; + +#endif diff --git a/modules/pademu/ds3bt/imports.lst b/modules/pademu/ds3bt/imports.lst new file mode 100644 index 000000000..b0de84ee7 --- /dev/null +++ b/modules/pademu/ds3bt/imports.lst @@ -0,0 +1,74 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end + +btstack_IMPORTS_start +I_btstack_register +I_btstack_unregister +I_btstack_hid_command +btstack_IMPORTS_end diff --git a/modules/pademu/ds3bt/irx_imports.h b/modules/pademu/ds3bt/irx_imports.h new file mode 100644 index 000000000..c0508fecb --- /dev/null +++ b/modules/pademu/ds3bt/irx_imports.h @@ -0,0 +1,41 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" +#include "../btstack/btstack.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/ds3usb/Makefile b/modules/pademu/ds3usb/Makefile new file mode 100644 index 000000000..49b5ceb95 --- /dev/null +++ b/modules/pademu/ds3usb/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = ds3usb.irx +IOP_OBJS = ds3usb.o imports.o +IOP_OBJS_DIR = obj.ds3usb/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/ds3usb/ds3usb.c b/modules/pademu/ds3usb/ds3usb.c new file mode 100644 index 000000000..dc5bbbfb2 --- /dev/null +++ b/modules/pademu/ds3usb/ds3usb.c @@ -0,0 +1,429 @@ +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "usbd.h" +#include "usbd_macro.h" +#include "thbase.h" +#include "thsemap.h" +#include "ds3usb.h" + +//#define DPRINTF(x...) printf(x) +#define DPRINTF(x...) + +#define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) + +#define MAX_PADS 4 + +static u8 output_01_report[] = + { + 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x02, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00}; + +static u8 led_patterns[][2] = + { + {0x1C, 0x02}, + {0x1A, 0x04}, + {0x16, 0x08}, + {0x0E, 0x10}, +}; + +static u8 power_level[] = + { + 0x00, 0x00, 0x02, 0x06, 0x0E, 0x1E}; + +static u8 usb_buf[MAX_BUFFER_SIZE] __attribute((aligned(4))) = {0}; + +int usb_probe(int devId); +int usb_connect(int devId); +int usb_disconnect(int devId); + +static void usb_release(int pad); +static void usb_config_set(int result, int count, void *arg); + +UsbDriver usb_driver = {NULL, NULL, "ds3usb", usb_probe, usb_connect, usb_disconnect}; + +static void readReport(u8 *data, int pad); +static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); + +ds3usb_device ds3dev[MAX_PADS]; + +int usb_probe(int devId) +{ + UsbDeviceDescriptor *device = NULL; + + DPRINTF("DS3USB: probe: devId=%i\n", devId); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + if (device == NULL) { + DPRINTF("DS3USB: Error - Couldn't get device descriptor\n"); + return 0; + } + + if (device->idVendor == SONY_VID && device->idProduct == DS3_PID) + return 1; + + return 0; +} + +int usb_connect(int devId) +{ + int pad, epCount; + UsbDeviceDescriptor *device; + UsbConfigDescriptor *config; + UsbInterfaceDescriptor *interface; + UsbEndpointDescriptor *endpoint; + + DPRINTF("DS3USB: connect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (ds3dev[pad].usb_id == -1) + break; + } + + if (pad >= MAX_PADS) { + DPRINTF("DS3USB: Error - only %d device allowed !\n", MAX_PADS); + return 1; + } + + PollSema(ds3dev[pad].sema); + + ds3dev[pad].dev.id = pad; + ds3dev[pad].usb_id = devId; + ds3dev[pad].controlEndp = UsbOpenEndpoint(devId, NULL); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); + interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); + epCount = interface->bNumEndpoints - 1; + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + + do { + if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && ds3dev[pad].interruptEndp < 0) { + ds3dev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("DS3USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", ds3dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + } + + endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength); + + } while (epCount--); + + if (ds3dev[pad].interruptEndp < 0) { + usb_release(pad); + return 1; + } + + UsbSetDeviceConfiguration(ds3dev[pad].controlEndp, config->bConfigurationValue, usb_config_set, (void *)pad); + SignalSema(ds3dev[pad].sema); + + return 0; +} + +int usb_disconnect(int devId) +{ + u8 pad; + + DPRINTF("DS3USB: disconnect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (ds3dev[pad].usb_id == devId) { + pademu_disconnect(&ds3dev[pad].dev); + break; + } + } + + if (pad < MAX_PADS) + usb_release(pad); + + return 0; +} + +static void usb_release(int pad) +{ + PollSema(ds3dev[pad].sema); + + if (ds3dev[pad].interruptEndp >= 0) + UsbCloseEndpoint(ds3dev[pad].interruptEndp); + + ds3dev[pad].controlEndp = -1; + ds3dev[pad].interruptEndp = -1; + ds3dev[pad].usb_id = -1; + + SignalSema(ds3dev[pad].sema); +} + +static void usb_data_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("DS3USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + ds3dev[pad].usb_resultcode = resultCode; + + SignalSema(ds3dev[pad].sema); +} + +static void usb_cmd_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("DS3USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + SignalSema(ds3dev[pad].cmd_sema); +} + +static void usb_config_set(int result, int count, void *arg) +{ + int pad = (int)arg; + u8 led[2]; + + PollSema(ds3dev[pad].sema); + + usb_buf[0] = 0x42; + usb_buf[1] = 0x0C; + usb_buf[2] = 0x00; + usb_buf[3] = 0x00; + + UsbControlTransfer(ds3dev[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_GET_REPORT_FEATURE << 8) | 0xF4, 0, 4, usb_buf, NULL, NULL); + DelayThread(10000); + pademu_connect(&ds3dev[pad].dev); + led[0] = led_patterns[ds3dev[pad].dev.id][1]; + led[1] = 0; + + LEDRumble(led, 0, 0, pad); + SignalSema(ds3dev[pad].sema); +} + +#define MAX_DELAY 10 + +static void readReport(u8 *data, int pad) +{ + ds3report_t *report = (ds3report_t *)data; + if (report->ReportID == 0x01) { + if (report->RightStickX == 0 && report->RightStickY == 0) // ledrumble cmd causes null report sometime + return; + + ds3dev[pad].data[0] = ~report->ButtonStateL; + ds3dev[pad].data[1] = ~report->ButtonStateH; + + ds3dev[pad].data[2] = report->RightStickX; //rx + ds3dev[pad].data[3] = report->RightStickY; //ry + ds3dev[pad].data[4] = report->LeftStickX; //lx + ds3dev[pad].data[5] = report->LeftStickY; //ly + + ds3dev[pad].data[6] = report->PressureRight; //right + ds3dev[pad].data[7] = report->PressureLeft; //left + ds3dev[pad].data[8] = report->PressureUp; //up + ds3dev[pad].data[9] = report->PressureDown; //down + + ds3dev[pad].data[10] = report->PressureTriangle; //triangle + ds3dev[pad].data[11] = report->PressureCircle; //circle + ds3dev[pad].data[12] = report->PressureCross; //cross + ds3dev[pad].data[13] = report->PressureSquare; //square + + ds3dev[pad].data[14] = report->PressureL1; //L1 + ds3dev[pad].data[15] = report->PressureR1; //R1 + ds3dev[pad].data[16] = report->PressureL2; //L2 + ds3dev[pad].data[17] = report->PressureR2; //R2 + + if (report->PSButtonState) { //display battery level + if (report->Select && (ds3dev[pad].btn_delay == MAX_DELAY)) { //PS + SELECT + if (ds3dev[pad].analog_btn < 2) //unlocked mode + ds3dev[pad].analog_btn = !ds3dev[pad].analog_btn; + + ds3dev[pad].oldled[0] = led_patterns[pad][(ds3dev[pad].analog_btn & 1)]; + ds3dev[pad].btn_delay = 1; + } else { + if (report->Power != 0xEE) + ds3dev[pad].oldled[0] = power_level[report->Power]; + + if (ds3dev[pad].btn_delay < MAX_DELAY) + ds3dev[pad].btn_delay++; + } + } else { + ds3dev[pad].oldled[0] = led_patterns[pad][(ds3dev[pad].analog_btn & 1)]; + + if (ds3dev[pad].btn_delay > 0) + ds3dev[pad].btn_delay--; + } + + if (report->Power == 0xEE) //charging + ds3dev[pad].oldled[1] = 1; + else + ds3dev[pad].oldled[1] = 0; + + if (ds3dev[pad].btn_delay > 0) { + ds3dev[pad].update_rum = 1; + } + } +} + +static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) +{ + PollSema(ds3dev[pad].cmd_sema); + + mips_memset(usb_buf, 0, sizeof(usb_buf)); + mips_memcpy(usb_buf, output_01_report, sizeof(output_01_report)); + + usb_buf[1] = 0xFE; //rt + usb_buf[2] = rrum; //rp + usb_buf[3] = 0xFE; //lt + usb_buf[4] = lrum; //lp + usb_buf[9] = led[0] & 0x7F; //LED Conf + + if (led[1]) { //means charging, so blink + usb_buf[13] = 0x32; + usb_buf[18] = 0x32; + usb_buf[23] = 0x32; + usb_buf[28] = 0x32; + } + + ds3dev[pad].oldled[0] = led[0]; + ds3dev[pad].oldled[1] = led[1]; + + return UsbControlTransfer(ds3dev[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_SET_REPORT_OUTPUT << 8) | 0x01, 0, sizeof(output_01_report), usb_buf, usb_cmd_cb, (void *)pad); +} + +static unsigned int timeout(void *arg) +{ + int sema = (int)arg; + iSignalSema(sema); + return 0; +} + +static void TransferWait(int sema) +{ + iop_sys_clock_t cmd_timeout; + + cmd_timeout.lo = 200000; + cmd_timeout.hi = 0; + + if (SetAlarm(&cmd_timeout, timeout, (void *)sema) == 0) { + WaitSema(sema); + CancelAlarm(timeout, NULL); + } +} + +void ds3usb_set_rumble(u8 lrum, u8 rrum, int port) +{ + WaitSema(ds3dev[port].sema); + + ds3dev[port].update_rum = 1; + ds3dev[port].lrum = lrum; + ds3dev[port].rrum = rrum; + + SignalSema(ds3dev[port].sema); +} + +int ds3usb_get_data(u8 *dst, int size, int port) +{ + int ret = 0; + + WaitSema(ds3dev[port].sema); + + PollSema(ds3dev[port].sema); + + ret = UsbInterruptTransfer(ds3dev[port].interruptEndp, usb_buf, MAX_BUFFER_SIZE, usb_data_cb, (void *)port); + + if (ret == USB_RC_OK) { + TransferWait(ds3dev[port].sema); + if (!ds3dev[port].usb_resultcode) + readReport(usb_buf, port); + + ds3dev[port].usb_resultcode = 1; + } else { + DPRINTF("DS3USB: DS3USB_get_data usb transfer error %d\n", ret); + } + + mips_memcpy(dst, ds3dev[port].data, size); + ret = ds3dev[port].analog_btn & 1; + + if (ds3dev[port].update_rum) { + ret = LEDRumble(ds3dev[port].oldled, ds3dev[port].lrum, ds3dev[port].rrum, port); + if (ret == USB_RC_OK) + TransferWait(ds3dev[port].cmd_sema); + else + DPRINTF("DS3USB: LEDRumble usb transfer error %d\n", ret); + + ds3dev[port].update_rum = 0; + } + + SignalSema(ds3dev[port].sema); + + return ret; +} + +void ds3usb_set_mode(int mode, int lock, int port) +{ + if (lock == 3) + ds3dev[port].analog_btn = 3; + else + ds3dev[port].analog_btn = mode; +} + +void ds3usb_reset() +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) + usb_release(pad); +} + +int _start(int argc, char *argv[]) +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) { + ds3dev[pad].usb_id = -1; + ds3dev[pad].dev.id = -1; + ds3dev[pad].dev.pad_get_data = ds3usb_get_data; + ds3dev[pad].dev.pad_set_rumble = ds3usb_set_rumble; + ds3dev[pad].dev.pad_set_mode = ds3usb_set_mode; + + ds3dev[pad].oldled[0] = 0; + ds3dev[pad].oldled[1] = 0; + ds3dev[pad].lrum = 0; + ds3dev[pad].rrum = 0; + ds3dev[pad].update_rum = 1; + ds3dev[pad].sema = -1; + ds3dev[pad].cmd_sema = -1; + ds3dev[pad].controlEndp = -1; + ds3dev[pad].interruptEndp = -1; + + ds3dev[pad].data[0] = 0xFF; + ds3dev[pad].data[1] = 0xFF; + ds3dev[pad].analog_btn = 0; + + mips_memset(&ds3dev[pad].data[2], 0x7F, 4); + mips_memset(&ds3dev[pad].data[6], 0x00, 12); + + ds3dev[pad].sema = CreateMutex(IOP_MUTEX_UNLOCKED); + ds3dev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); + + if (ds3dev[pad].sema < 0 || ds3dev[pad].cmd_sema < 0) { + DPRINTF("DS3USB: Failed to allocate I/O semaphore.\n"); + return MODULE_NO_RESIDENT_END; + } + } + + if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { + DPRINTF("DS3USB: Error registering USB devices\n"); + return MODULE_NO_RESIDENT_END; + } + + return MODULE_RESIDENT_END; +} diff --git a/modules/pademu/ds3usb/ds3usb.h b/modules/pademu/ds3usb/ds3usb.h new file mode 100644 index 000000000..99911e3d6 --- /dev/null +++ b/modules/pademu/ds3usb/ds3usb.h @@ -0,0 +1,133 @@ +#ifndef _DS3USB_H_ +#define _DS3USB_H_ + +#include "irx.h" +#include "../pademu.h" + +//#include + +#define DS3 0 +#define DS4 1 +#define GUITAR_GH 2 +#define GUITAR_RB 3 + +#define MODEL_GUITAR 1 +#define MODEL_PS2 3 +#define SONY_VID 0x054C // Sony Corporation +#define DS3_PID 0x0268 // PS3 Controller + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +typedef struct +{ + pad_device_t dev; + int usb_id; + int sema; + int cmd_sema; + int controlEndp; + int interruptEndp; + int outEndp; + u8 enabled; + u8 status; + u8 type; // 0 - ds3, 1 - ds4, 2 - guitar hero guitar, 3 - rock band guitar + u8 oldled[4]; // rgb for ds4 and blink + int usb_resultcode; + u8 lrum; + u8 rrum; + u8 update_rum; + union + { + struct ds2report ds2; + u8 data[18]; + }; + u8 analog_btn; + u8 btn_delay; +} ds3usb_device; + +enum eHID { + // {{{ + /* HID event flag */ + HID_FLAG_STATUS_REPORTED = 0x01, + HID_FLAG_BUTTONS_CHANGED = 0x02, + HID_FLAG_EXTENSION = 0x04, + HID_FLAG_COMMAND_SUCCESS = 0x08, + + /* USB HID Transaction Header (THdr) */ + HID_USB_GET_REPORT_FEATURE = 0x03, + HID_USB_SET_REPORT_OUTPUT = 0x02, + HID_USB_DATA_INPUT = 0x01, + + /* Defines of various parameters for PS3 Game controller reports */ + PS3_F4_REPORT_ID = 0xF4, + PS3_F4_REPORT_LEN = 0x04, + + PS3_01_REPORT_ID = 0x01, + PS3_01_REPORT_LEN = 0x30, + + PS4_02_REPORT_ID = 0x02, + PS4_11_REPORT_ID = 0x11, + PS4_11_REPORT_LEN = 0x4D, + // }}} +}; + +typedef struct { + u8 ReportID; + u8 Zero; + union { + u8 ButtonStateL; // Main buttons Low + struct { + u8 Select : 1; + u8 L3 : 1; + u8 R3 : 1; + u8 Start : 1; + u8 Up : 1; + u8 Right : 1; + u8 Down : 1; + u8 Left : 1; + }; + }; + union { + u8 ButtonStateH; // Main buttons High + struct { + u8 L2 : 1; + u8 R2 : 1; + u8 L1 : 1; + u8 R1 : 1; + u8 Triangle : 1; + u8 Circle : 1; + u8 Cross : 1; + u8 Square : 1; + }; + }; + u8 PSButtonState; // PS button + u8 Reserved1; // Unknown + u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid + u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid + u8 RightStickX; // right Joystick X axis 0 - 255, 128 is mid + u8 RightStickY; // right Joystick Y axis 0 - 255, 128 is mid + u8 Reserved2[4]; // Unknown + u8 PressureUp; // digital Pad Up button Pressure 0 - 255 + u8 PressureRight; // digital Pad Right button Pressure 0 - 255 + u8 PressureDown; // digital Pad Down button Pressure 0 - 255 + u8 PressureLeft; // digital Pad Left button Pressure 0 - 255 + u8 PressureL2; // digital Pad L2 button Pressure 0 - 255 + u8 PressureR2; // digital Pad R2 button Pressure 0 - 255 + u8 PressureL1; // digital Pad L1 button Pressure 0 - 255 + u8 PressureR1; // digital Pad R1 button Pressure 0 - 255 + u8 PressureTriangle; // digital Pad Triangle button Pressure 0 - 255 + u8 PressureCircle; // digital Pad Circle button Pressure 0 - 255 + u8 PressureCross; // digital Pad Cross button Pressure 0 - 255 + u8 PressureSquare; // digital Pad Square button Pressure 0 - 255 + u8 Reserved3[3]; // Unknown + u8 Charge; // charging status ? 02 = charge, 03 = normal + u8 Power; // Battery status ? 05=full - 02=dying, 01=just before shutdown, EE=charging + u8 Connection; // Connection Type ? 14 when operating by bluetooth, 10 when operating by bluetooth with cable plugged in, 16 when bluetooh and rumble + u8 Reserved4[9]; // Unknown + s16 AccelX; + s16 AccelY; + s16 AccelZ; + s16 GyroZ; + +} __attribute__((packed)) ds3report_t; + +#endif diff --git a/modules/pademu/ds3usb/imports.lst b/modules/pademu/ds3usb/imports.lst new file mode 100644 index 000000000..e36f592dd --- /dev/null +++ b/modules/pademu/ds3usb/imports.lst @@ -0,0 +1,68 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end diff --git a/modules/pademu/ds3usb/irx_imports.h b/modules/pademu/ds3usb/irx_imports.h new file mode 100644 index 000000000..280115628 --- /dev/null +++ b/modules/pademu/ds3usb/irx_imports.h @@ -0,0 +1,40 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/ds4bt/Makefile b/modules/pademu/ds4bt/Makefile new file mode 100644 index 000000000..163fa6bca --- /dev/null +++ b/modules/pademu/ds4bt/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = ds4bt.irx +IOP_OBJS = ds4bt.o imports.o +IOP_OBJS_DIR = obj.ds4bt/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/ds4bt/ds4bt.c b/modules/pademu/ds4bt/ds4bt.c new file mode 100644 index 000000000..3ad27a01c --- /dev/null +++ b/modules/pademu/ds4bt/ds4bt.c @@ -0,0 +1,215 @@ +#include "irx.h" +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "thbase.h" +#include "thsemap.h" +#include "../pademu.h" +#include "../btstack/btstack.h" +#include "ds4bt.h" + +//#define DPRINTF(x...) printf(x) +#define DPRINTF(x...) + +static u8 rgbled_patterns[][2][3] = + { + {{0x00, 0x00, 0x10}, {0x00, 0x00, 0x7F}}, // light blue/blue + {{0x00, 0x10, 0x00}, {0x00, 0x7F, 0x00}}, // light green/green/ + {{0x10, 0x10, 0x00}, {0x7F, 0x7F, 0x00}}, // light yellow/yellow + {{0x00, 0x10, 0x10}, {0x00, 0x7F, 0x7F}}, // light cyan/cyan +}; + +int ds4bt_connect(bt_paddata_t *data, u8 *str, int size); +void ds4bt_init(bt_paddata_t *data, int id); +void ds4bt_read_report(bt_paddata_t *data, u8 *in, int bytes); +void ds4bt_rumble(bt_paddata_t *data); + +bt_paddrv_t ds4btdrv = {0x0070, 0x0071, ds4bt_connect, ds4bt_init, ds4bt_read_report, ds4bt_rumble}; + +#define MAX_DELAY 10 +#define CMD_DELAY 2 + +int ds4bt_connect(bt_paddata_t *data, u8 *str, int size) +{ + if (strncmp(str, "Wireless Controller", 19) == 0) { + DPRINTF("BS4BT: %s \n", str); + return 1; + } + return 0; +} + +void ds4bt_init(bt_paddata_t *data, int id) +{ + u8 init_buf[2]; + + init_buf[0] = HID_THDR_GET_REPORT_FEATURE; // THdr + init_buf[1] = PS4_02_REPORT_ID; // Report ID + + btstack_hid_command(&ds4btdrv, init_buf, 2, data->id); + + data->id = id; + data->led[0] = rgbled_patterns[id][1][0]; + data->led[1] = rgbled_patterns[id][1][1]; + data->led[2] = rgbled_patterns[id][1][2]; + data->led[3] = 0; + DelayThread(CMD_DELAY); + ds4bt_rumble(data); + data->btn_delay = 0xFF; +} + +void ds4bt_read_report(bt_paddata_t *data, u8 *in, int bytes) +{ + if (in[8] == HID_THDR_DATA_INPUT) { + ds4report_t *report = (ds4report_t *)(in + 9); + if (report->ReportID == PS4_11_REPORT_ID) { + u8 up = 0, down = 0, left = 0, right = 0; + switch (report->Dpad) { + case 0: + up = 1; + break; + case 1: + up = 1; + right = 1; + break; + case 2: + right = 1; + break; + case 3: + down = 1; + right = 1; + break; + case 4: + down = 1; + break; + case 5: + down = 1; + left = 1; + break; + case 6: + left = 1; + break; + case 7: + up = 1; + left = 1; + break; + case 8: + up = 0; + down = 0; + left = 0; + right = 0; + break; + } + + if (bytes > 63 && report->TPad) { + if (!report->Finger1Active) { + if (report->Finger1X < 960) + report->Share = 1; + else + report->Option = 1; + } + + if (!report->Finger2Active) { + if (report->Finger2X < 960) + report->Share = 1; + else + report->Option = 1; + } + } + + data->data[0] = ~(report->Share | report->L3 << 1 | report->R3 << 2 | report->Option << 3 | up << 4 | right << 5 | down << 6 | left << 7); + data->data[1] = ~(report->L2 | report->R2 << 1 | report->L1 << 2 | report->R1 << 3 | report->Triangle << 4 | report->Circle << 5 | report->Cross << 6 | report->Square << 7); + + data->data[2] = report->RightStickX; //rx + data->data[3] = report->RightStickY; //ry + data->data[4] = report->LeftStickX; //lx + data->data[5] = report->LeftStickY; //ly + + data->data[6] = right * 255; //right + data->data[7] = left * 255; //left + data->data[8] = up * 255; //up + data->data[9] = down * 255; //down + + data->data[10] = report->Triangle * 255; //triangle + data->data[11] = report->Circle * 255; //circle + data->data[12] = report->Cross * 255; //cross + data->data[13] = report->Square * 255; //square + + data->data[14] = report->L1 * 255; //L1 + data->data[15] = report->R1 * 255; //R1 + data->data[16] = report->PressureL2; //L2 + data->data[17] = report->PressureR2; //R2 + + if (report->PSButton) { //display battery level + if (report->Share && (data->btn_delay == MAX_DELAY)) { //PS + SELECT + if (data->analog_btn < 2) //unlocked mode + data->analog_btn = !data->analog_btn; + + data->led[0] = rgbled_patterns[data->id][(data->analog_btn & 1)][0]; + data->led[1] = rgbled_patterns[data->id][(data->analog_btn & 1)][1]; + data->led[2] = rgbled_patterns[data->id][(data->analog_btn & 1)][2]; + data->btn_delay = 1; + } else { + data->led[0] = report->Battery; + data->led[1] = 0; + data->led[2] = 0; + + if (data->btn_delay < MAX_DELAY) + data->btn_delay++; + } + } else { + data->led[0] = rgbled_patterns[data->id][(data->analog_btn & 1)][0]; + data->led[1] = rgbled_patterns[data->id][(data->analog_btn & 1)][1]; + data->led[2] = rgbled_patterns[data->id][(data->analog_btn & 1)][2]; + + if (data->btn_delay > 0) + data->btn_delay--; + } + + if (report->Power != 0xB && report->Usb_plugged) //charging + data->led[3] = 1; + else + data->led[3] = 0; + + if (data->btn_delay > 0) { + data->update_rum = 1; + } + } + } else { + DPRINTF("BS4BT: Unmanaged Input Report: THDR 0x%02X ", in[8]); + DPRINTF("BS4BT: ID 0x%02X \n", in[9]); + } +} + +void ds4bt_rumble(bt_paddata_t *data) +{ + u8 led_buf[PS4_11_REPORT_LEN + 2]; + mips_memset(led_buf, 0, sizeof(led_buf)); + + led_buf[0] = HID_THDR_SET_REPORT_OUTPUT; // THdr + led_buf[1] = PS4_11_REPORT_ID; // Report ID + led_buf[2] = 0x80; //update rate 1000Hz + led_buf[4] = 0xFF; + + led_buf[7] = data->rrum * 255; + led_buf[8] = data->lrum; + + led_buf[9] = data->led[0]; //r + led_buf[10] = data->led[1]; //g + led_buf[11] = data->led[2]; //b + + if (data->led[3]) { //means charging, so blink + led_buf[12] = 0x80; // Time to flash bright (255 = 2.5 seconds) + led_buf[13] = 0x80; // Time to flash dark (255 = 2.5 seconds) + } + + btstack_hid_command(&ds4btdrv, led_buf, PS4_11_REPORT_LEN + 2, data->id); +} + +int _start(int argc, char *argv[]) +{ + btstack_register(&ds4btdrv); + + return MODULE_RESIDENT_END; +} diff --git a/modules/pademu/ds4bt/ds4bt.h b/modules/pademu/ds4bt/ds4bt.h new file mode 100644 index 000000000..22873b3c3 --- /dev/null +++ b/modules/pademu/ds4bt/ds4bt.h @@ -0,0 +1,88 @@ +#ifndef _DS4BT_H_ +#define _DS4BT_H_ + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +enum eHID { + // {{{ + /* HID event flag */ + HID_FLAG_STATUS_REPORTED = 0x01, + HID_FLAG_BUTTONS_CHANGED = 0x02, + HID_FLAG_EXTENSION = 0x04, + HID_FLAG_COMMAND_SUCCESS = 0x08, + + /* Bluetooth HID Transaction Header (THdr) */ + HID_THDR_GET_REPORT_FEATURE = 0x43, + HID_THDR_SET_REPORT_OUTPUT = 0x52, + HID_THDR_SET_REPORT_FEATURE = 0x53, + HID_THDR_DATA_INPUT = 0xa1, + + /* Defines of various parameters for PS3 Game controller reports */ + PS3_F4_REPORT_ID = 0xF4, + PS3_F4_REPORT_LEN = 0x04, + + PS3_01_REPORT_ID = 0x01, + PS3_01_REPORT_LEN = 0x30, + + PS4_02_REPORT_ID = 0x02, + PS4_11_REPORT_ID = 0x11, + PS4_11_REPORT_LEN = 0x4D, + + // }}} +}; + +typedef struct { + u8 ReportID; + u8 Unk; + u8 ReportID2; + u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid + u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid + u8 RightStickX; // right Joystick X axis 0 - 255, 128 is mid + u8 RightStickY; // right Joystick Y axis 0 - 255, 128 is mid + u8 Dpad : 4; // hat format, 0x08 is released, 0=N, 1=NE, 2=E, 3=SE, 4=S, 5=SW, 6=W, 7=NW + u8 Square : 1; + u8 Cross : 1; + u8 Circle : 1; + u8 Triangle : 1; + u8 L1 : 1; + u8 R1 : 1; + u8 L2 : 1; + u8 R2 : 1; + u8 Share : 1; + u8 Option : 1; + u8 L3 : 1; + u8 R3 : 1; + u8 PSButton : 1; + u8 TPad : 1; + u8 Counter1 : 6; // counts up by 1 per report + u8 PressureL2; // digital Pad L2 button Pressure 0 - 255 + u8 PressureR2; // digital Pad R2 button Pressure 0 - 255 + u8 Counter2; + u8 Counter3; + u8 Battery; // battery level from 0x00 to 0xff + s16 AccelX; + s16 AccelY; + s16 AccelZ; + s16 GyroZ; + s16 GyroY; + s16 GyroX; + u8 Reserved1[5]; // Unknown + u8 Power : 4; // from 0x0 to 0xA - charging, 0xB - charged + u8 Usb_plugged : 1; + u8 Headphones : 1; + u8 Microphone : 1; + u8 Padding : 1; + u8 Reserved2[2]; // Unknown + u8 TPpack; // number of trackpad packets (0x00 to 0x04) + u8 PackCounter; // packet counter + u8 Finger1ID : 7; // counter + u8 Finger1Active : 1; // 0 - active, 1 - unactive + u16 Finger1X : 12; // finger 1 coordinates resolution 1920x943 + u16 Finger1Y : 12; + u8 Finger2ID : 7; + u8 Finger2Active : 1; + u16 Finger2X : 12; // finger 2 coordinates resolution 1920x943 + u16 Finger2Y : 12; +} __attribute__((packed)) ds4report_t; + +#endif diff --git a/modules/pademu/ds4bt/imports.lst b/modules/pademu/ds4bt/imports.lst new file mode 100644 index 000000000..b0de84ee7 --- /dev/null +++ b/modules/pademu/ds4bt/imports.lst @@ -0,0 +1,74 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end + +btstack_IMPORTS_start +I_btstack_register +I_btstack_unregister +I_btstack_hid_command +btstack_IMPORTS_end diff --git a/modules/pademu/ds4bt/irx_imports.h b/modules/pademu/ds4bt/irx_imports.h new file mode 100644 index 000000000..c0508fecb --- /dev/null +++ b/modules/pademu/ds4bt/irx_imports.h @@ -0,0 +1,41 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" +#include "../btstack/btstack.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/ds4usb/Makefile b/modules/pademu/ds4usb/Makefile new file mode 100644 index 000000000..1b8f1980b --- /dev/null +++ b/modules/pademu/ds4usb/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = ds4usb.irx +IOP_OBJS = ds4usb.o imports.o +IOP_OBJS_DIR = obj.ds4usb/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/ds4usb/ds4usb.c b/modules/pademu/ds4usb/ds4usb.c new file mode 100644 index 000000000..fde017739 --- /dev/null +++ b/modules/pademu/ds4usb/ds4usb.c @@ -0,0 +1,479 @@ +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "usbd.h" +#include "usbd_macro.h" +#include "thbase.h" +#include "thsemap.h" +#include "ds4usb.h" + +//#define DPRINTF(x...) printf(x) +#define DPRINTF(x...) + +#define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) + +#define MAX_PADS 4 + +static u8 rgbled_patterns[][2][3] = + { + {{0x00, 0x00, 0x10}, {0x00, 0x00, 0x7F}}, // light blue/blue + {{0x00, 0x10, 0x00}, {0x00, 0x7F, 0x00}}, // light green/green + {{0x10, 0x10, 0x00}, {0x7F, 0x7F, 0x00}}, // light yellow/yellow + {{0x00, 0x10, 0x10}, {0x00, 0x7F, 0x7F}}, // light cyan/cyan +}; + +static u8 usb_buf[MAX_BUFFER_SIZE + 32] __attribute((aligned(4))) = {0}; + +int usb_probe(int devId); +int usb_connect(int devId); +int usb_disconnect(int devId); + +static void usb_release(int pad); +static void usb_config_set(int result, int count, void *arg); + +UsbDriver usb_driver = {NULL, NULL, "ds4usb", usb_probe, usb_connect, usb_disconnect}; + +static void readReport(u8 *data, int pad); +static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); + +ds4usb_device ds4dev[MAX_PADS]; + +int usb_probe(int devId) +{ + UsbDeviceDescriptor *device = NULL; + + DPRINTF("DS4USB: probe: devId=%i\n", devId); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + if (device == NULL) { + DPRINTF("DS4USB: Error - Couldn't get device descriptor\n"); + return 0; + } + + if (device->idVendor == SONY_VID && (device->idProduct == DS4_PID || device->idProduct == DS4_PID_SLIM)) + return 1; + + return 0; +} + +int usb_connect(int devId) +{ + int pad, epCount; + UsbDeviceDescriptor *device; + UsbConfigDescriptor *config; + UsbInterfaceDescriptor *interface; + UsbEndpointDescriptor *endpoint; + + DPRINTF("DS4USB: connect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (ds4dev[pad].usb_id == -1) + break; + } + + if (pad >= MAX_PADS) { + DPRINTF("DS4USB: Error - only %d device allowed !\n", MAX_PADS); + return 1; + } + + PollSema(ds4dev[pad].sema); + + ds4dev[pad].dev.id = pad; + ds4dev[pad].usb_id = devId; + ds4dev[pad].controlEndp = UsbOpenEndpoint(devId, NULL); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); + interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); + epCount = interface->bNumEndpoints - 1; + + if (device->idProduct == DS4_PID_SLIM) { + epCount = 20; // ds4 v2 returns interface->bNumEndpoints as 0 + } + + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + + do { + if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && ds4dev[pad].interruptEndp < 0) { + ds4dev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("DS4USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", ds4dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && ds4dev[pad].outEndp < 0) { + ds4dev[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("DS34USB: register Output endpoint id =%i addr=%02X packetSize=%i\n", ds4pad[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + } + + endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength); + + } while (epCount--); + + if (ds4dev[pad].interruptEndp < 0 || ds4dev[pad].outEndp < 0) { + usb_release(pad); + return 1; + } + + UsbSetDeviceConfiguration(ds4dev[pad].controlEndp, config->bConfigurationValue, usb_config_set, (void *)pad); + SignalSema(ds4dev[pad].sema); + + return 0; +} + +int usb_disconnect(int devId) +{ + u8 pad; + + DPRINTF("DS4USB: disconnect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (ds4dev[pad].usb_id == devId) { + pademu_disconnect(&ds4dev[pad].dev); + break; + } + } + + if (pad < MAX_PADS) + usb_release(pad); + + return 0; +} + +static void usb_release(int pad) +{ + PollSema(ds4dev[pad].sema); + + if (ds4dev[pad].interruptEndp >= 0) + UsbCloseEndpoint(ds4dev[pad].interruptEndp); + + if (ds4dev[pad].outEndp >= 0) + UsbCloseEndpoint(ds4dev[pad].outEndp); + + ds4dev[pad].controlEndp = -1; + ds4dev[pad].interruptEndp = -1; + ds4dev[pad].outEndp = -1; + ds4dev[pad].usb_id = -1; + + SignalSema(ds4dev[pad].sema); +} + +static void usb_data_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("DS4USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + ds4dev[pad].usb_resultcode = resultCode; + + SignalSema(ds4dev[pad].sema); +} + +static void usb_cmd_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("DS4USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + SignalSema(ds4dev[pad].cmd_sema); +} + +static void usb_config_set(int result, int count, void *arg) +{ + int pad = (int)arg; + u8 led[4]; + + PollSema(ds4dev[pad].sema); + + pademu_connect(&ds4dev[pad].dev); + + led[0] = rgbled_patterns[ds4dev[pad].dev.id][1][0]; + led[1] = rgbled_patterns[ds4dev[pad].dev.id][1][1]; + led[2] = rgbled_patterns[ds4dev[pad].dev.id][1][2]; + led[3] = 0; + + LEDRumble(led, 0, 0, pad); + SignalSema(ds4dev[pad].sema); +} + +#define MAX_DELAY 10 + +static void readReport(u8 *data, int pad) +{ + ds4report_t *report = (ds4report_t *)data; + if (report->ReportID == 0x01) { + u8 up = 0, down = 0, left = 0, right = 0; + + switch (report->Dpad) { + case 0: + up = 1; + break; + case 1: + up = 1; + right = 1; + break; + case 2: + right = 1; + break; + case 3: + down = 1; + right = 1; + break; + case 4: + down = 1; + break; + case 5: + down = 1; + left = 1; + break; + case 6: + left = 1; + break; + case 7: + up = 1; + left = 1; + break; + case 8: + up = 0; + down = 0; + left = 0; + right = 0; + break; + } + + if (report->TPad) { + if (!report->Finger1Active) { + if (report->Finger1X < 960) + report->Share = 1; + else + report->Option = 1; + } + + if (!report->Finger2Active) { + if (report->Finger2X < 960) + report->Share = 1; + else + report->Option = 1; + } + } + + ds4dev[pad].data[0] = ~(report->Share | report->L3 << 1 | report->R3 << 2 | report->Option << 3 | up << 4 | right << 5 | down << 6 | left << 7); + ds4dev[pad].data[1] = ~(report->L2 | report->R2 << 1 | report->L1 << 2 | report->R1 << 3 | report->Triangle << 4 | report->Circle << 5 | report->Cross << 6 | report->Square << 7); + + ds4dev[pad].data[2] = report->RightStickX; //rx + ds4dev[pad].data[3] = report->RightStickY; //ry + ds4dev[pad].data[4] = report->LeftStickX; //lx + ds4dev[pad].data[5] = report->LeftStickY; //ly + + ds4dev[pad].data[6] = right * 255; //right + ds4dev[pad].data[7] = left * 255; //left + ds4dev[pad].data[8] = up * 255; //up + ds4dev[pad].data[9] = down * 255; //down + + ds4dev[pad].data[10] = report->Triangle * 255; //triangle + ds4dev[pad].data[11] = report->Circle * 255; //circle + ds4dev[pad].data[12] = report->Cross * 255; //cross + ds4dev[pad].data[13] = report->Square * 255; //square + + ds4dev[pad].data[14] = report->L1 * 255; //L1 + ds4dev[pad].data[15] = report->R1 * 255; //R1 + ds4dev[pad].data[16] = report->PressureL2; //L2 + ds4dev[pad].data[17] = report->PressureR2; //R2 + + if (report->PSButton) { //display battery level + if (report->Share && (ds4dev[pad].btn_delay == MAX_DELAY)) { //PS + Share + if (ds4dev[pad].analog_btn < 2) //unlocked mode + ds4dev[pad].analog_btn = !ds4dev[pad].analog_btn; + + ds4dev[pad].oldled[0] = rgbled_patterns[pad][(ds4dev[pad].analog_btn & 1)][0]; + ds4dev[pad].oldled[1] = rgbled_patterns[pad][(ds4dev[pad].analog_btn & 1)][1]; + ds4dev[pad].oldled[2] = rgbled_patterns[pad][(ds4dev[pad].analog_btn & 1)][2]; + ds4dev[pad].btn_delay = 1; + } else { + ds4dev[pad].oldled[0] = report->Battery; + ds4dev[pad].oldled[1] = 0; + ds4dev[pad].oldled[2] = 0; + + if (ds4dev[pad].btn_delay < MAX_DELAY) + ds4dev[pad].btn_delay++; + } + } else { + ds4dev[pad].oldled[0] = rgbled_patterns[pad][(ds4dev[pad].analog_btn & 1)][0]; + ds4dev[pad].oldled[1] = rgbled_patterns[pad][(ds4dev[pad].analog_btn & 1)][1]; + ds4dev[pad].oldled[2] = rgbled_patterns[pad][(ds4dev[pad].analog_btn & 1)][2]; + + if (ds4dev[pad].btn_delay > 0) + ds4dev[pad].btn_delay--; + } + + if (report->Power != 0xB && report->Usb_plugged) //charging + ds4dev[pad].oldled[3] = 1; + else + ds4dev[pad].oldled[3] = 0; + + if (ds4dev[pad].btn_delay > 0) { + ds4dev[pad].update_rum = 1; + } + } +} + +static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) +{ + PollSema(ds4dev[pad].cmd_sema); + + usb_buf[0] = 0x05; + usb_buf[1] = 0xFF; + + usb_buf[4] = rrum * 255; //ds4 has full control + usb_buf[5] = lrum; + + usb_buf[6] = led[0]; //r + usb_buf[7] = led[1]; //g + usb_buf[8] = led[2]; //b + + if (led[3]) //means charging, so blink + { + usb_buf[9] = 0x80; // Time to flash bright (255 = 2.5 seconds) + usb_buf[10] = 0x80; // Time to flash dark (255 = 2.5 seconds) + } + + ds4dev[pad].oldled[0] = led[0]; + ds4dev[pad].oldled[1] = led[1]; + ds4dev[pad].oldled[2] = led[2]; + ds4dev[pad].oldled[3] = led[3]; + + return UsbInterruptTransfer(ds4dev[pad].outEndp, usb_buf, 32, usb_cmd_cb, (void *)pad); +} + +static unsigned int timeout(void *arg) +{ + int sema = (int)arg; + iSignalSema(sema); + return 0; +} + +static void TransferWait(int sema) +{ + iop_sys_clock_t cmd_timeout; + + cmd_timeout.lo = 200000; + cmd_timeout.hi = 0; + + if (SetAlarm(&cmd_timeout, timeout, (void *)sema) == 0) { + WaitSema(sema); + CancelAlarm(timeout, NULL); + } +} + +void ds4usb_set_rumble(u8 lrum, u8 rrum, int port) +{ + WaitSema(ds4dev[port].sema); + + ds4dev[port].update_rum = 1; + ds4dev[port].lrum = lrum; + ds4dev[port].rrum = rrum; + + SignalSema(ds4dev[port].sema); +} + +int ds4usb_get_data(u8 *dst, int size, int port) +{ + int ret = 0; + + WaitSema(ds4dev[port].sema); + + PollSema(ds4dev[port].sema); + + ret = UsbInterruptTransfer(ds4dev[port].interruptEndp, usb_buf, MAX_BUFFER_SIZE, usb_data_cb, (void *)port); + + if (ret == USB_RC_OK) { + TransferWait(ds4dev[port].sema); + if (!ds4dev[port].usb_resultcode) + readReport(usb_buf, port); + + ds4dev[port].usb_resultcode = 1; + } else { + DPRINTF("DS4USB: DS4USB_get_data usb transfer error %d\n", ret); + } + + mips_memcpy(dst, ds4dev[port].data, size); + ret = ds4dev[port].analog_btn & 1; + + if (ds4dev[port].update_rum) { + ret = LEDRumble(ds4dev[port].oldled, ds4dev[port].lrum, ds4dev[port].rrum, port); + if (ret == USB_RC_OK) + TransferWait(ds4dev[port].cmd_sema); + else + DPRINTF("DS4USB: LEDRumble usb transfer error %d\n", ret); + + ds4dev[port].update_rum = 0; + } + + SignalSema(ds4dev[port].sema); + + return ret; +} + +void ds4usb_set_mode(int mode, int lock, int port) +{ + if (lock == 3) + ds4dev[port].analog_btn = 3; + else + ds4dev[port].analog_btn = mode; +} + +void ds4usb_reset() +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) + usb_release(pad); +} + +int _start(int argc, char *argv[]) +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) { + ds4dev[pad].usb_id = -1; + ds4dev[pad].dev.id = -1; + ds4dev[pad].dev.pad_get_data = ds4usb_get_data; + ds4dev[pad].dev.pad_set_rumble = ds4usb_set_rumble; + ds4dev[pad].dev.pad_set_mode = ds4usb_set_mode; + + ds4dev[pad].oldled[0] = 0; + ds4dev[pad].oldled[1] = 0; + ds4dev[pad].lrum = 0; + ds4dev[pad].rrum = 0; + ds4dev[pad].update_rum = 1; + ds4dev[pad].sema = -1; + ds4dev[pad].cmd_sema = -1; + ds4dev[pad].controlEndp = -1; + ds4dev[pad].interruptEndp = -1; + ds4dev[pad].outEndp = -1; + + ds4dev[pad].data[0] = 0xFF; + ds4dev[pad].data[1] = 0xFF; + ds4dev[pad].analog_btn = 0; + + mips_memset(&ds4dev[pad].data[2], 0x7F, 4); + mips_memset(&ds4dev[pad].data[6], 0x00, 12); + + ds4dev[pad].sema = CreateMutex(IOP_MUTEX_UNLOCKED); + ds4dev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); + + if (ds4dev[pad].sema < 0 || ds4dev[pad].cmd_sema < 0) { + DPRINTF("DS4USB: Failed to allocate I/O semaphore.\n"); + return MODULE_NO_RESIDENT_END; + } + } + + if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { + DPRINTF("DS4USB: Error registering USB devices\n"); + return MODULE_NO_RESIDENT_END; + } + + return MODULE_RESIDENT_END; +} diff --git a/modules/pademu/ds4usb/ds4usb.h b/modules/pademu/ds4usb/ds4usb.h new file mode 100644 index 000000000..334d9e4aa --- /dev/null +++ b/modules/pademu/ds4usb/ds4usb.h @@ -0,0 +1,110 @@ +#ifndef _DS3USB_H_ +#define _DS3USB_H_ + +#include "irx.h" +#include "../pademu.h" + +#define SONY_VID 0x054C // Sony Corporation +#define DS4_PID 0x05C4 // PS4 Controller +#define DS4_PID_SLIM 0x09CC // PS4 Slim Controller + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +typedef struct +{ + pad_device_t dev; + int usb_id; + int sema; + int cmd_sema; + int controlEndp; + int interruptEndp; + int outEndp; + int usb_resultcode; + u8 oldled[4]; + u8 lrum; + u8 rrum; + u8 update_rum; + u8 data[18]; + u8 analog_btn; + u8 btn_delay; +} ds4usb_device; + +enum eHID { + // {{{ + /* HID event flag */ + HID_FLAG_STATUS_REPORTED = 0x01, + HID_FLAG_BUTTONS_CHANGED = 0x02, + HID_FLAG_EXTENSION = 0x04, + HID_FLAG_COMMAND_SUCCESS = 0x08, + + /* USB HID Transaction Header (THdr) */ + HID_USB_GET_REPORT_FEATURE = 0x03, + HID_USB_SET_REPORT_OUTPUT = 0x02, + HID_USB_DATA_INPUT = 0x01, + + /* Defines of various parameters for PS3 Game controller reports */ + PS3_F4_REPORT_ID = 0xF4, + PS3_F4_REPORT_LEN = 0x04, + + PS3_01_REPORT_ID = 0x01, + PS3_01_REPORT_LEN = 0x30, + + PS4_02_REPORT_ID = 0x02, + PS4_11_REPORT_ID = 0x11, + PS4_11_REPORT_LEN = 0x4D, + // }}} +}; + +typedef struct { + u8 ReportID; + u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid + u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid + u8 RightStickX; // right Joystick X axis 0 - 255, 128 is mid + u8 RightStickY; // right Joystick Y axis 0 - 255, 128 is mid + u8 Dpad : 4; // hat format, 0x08 is released, 0=N, 1=NE, 2=E, 3=SE, 4=S, 5=SW, 6=W, 7=NW + u8 Square : 1; + u8 Cross : 1; + u8 Circle : 1; + u8 Triangle : 1; + u8 L1 : 1; + u8 R1 : 1; + u8 L2 : 1; + u8 R2 : 1; + u8 Share : 1; + u8 Option : 1; + u8 L3 : 1; + u8 R3 : 1; + u8 PSButton : 1; + u8 TPad : 1; + u8 Counter1 : 6; // counts up by 1 per report + u8 PressureL2; // digital Pad L2 button Pressure 0 - 255 + u8 PressureR2; // digital Pad R2 button Pressure 0 - 255 + u8 Counter2; + u8 Counter3; + u8 Battery; // battery level from 0x00 to 0xff + s16 AccelX; + s16 AccelY; + s16 AccelZ; + s16 GyroZ; + s16 GyroY; + s16 GyroX; + u8 Reserved1[5]; // Unknown + u8 Power : 4; // from 0x0 to 0xA - charging, 0xB - charged + u8 Usb_plugged : 1; + u8 Headphones : 1; + u8 Microphone : 1; + u8 Padding : 1; + u8 Reserved2[2]; // Unknown + u8 TPpack; // number of trackpad packets (0x00 to 0x04) + u8 PackCounter; // packet counter + u8 Finger1ID : 7; // counter + u8 Finger1Active : 1; // 0 - active, 1 - unactive + u16 Finger1X : 12; // finger 1 coordinates resolution 1920x943 + u16 Finger1Y : 12; + u8 Finger2ID : 7; + u8 Finger2Active : 1; + u16 Finger2X : 12; // finger 2 coordinates resolution 1920x943 + u16 Finger2Y : 12; +} __attribute__((packed)) ds4report_t; + +#endif diff --git a/modules/pademu/ds4usb/imports.lst b/modules/pademu/ds4usb/imports.lst new file mode 100644 index 000000000..e36f592dd --- /dev/null +++ b/modules/pademu/ds4usb/imports.lst @@ -0,0 +1,68 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end diff --git a/modules/pademu/ds4usb/irx_imports.h b/modules/pademu/ds4usb/irx_imports.h new file mode 100644 index 000000000..280115628 --- /dev/null +++ b/modules/pademu/ds4usb/irx_imports.h @@ -0,0 +1,40 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/exports.tab b/modules/pademu/exports.tab index 40c6386e9..aab538ad3 100644 --- a/modules/pademu/exports.tab +++ b/modules/pademu/exports.tab @@ -5,6 +5,8 @@ DECLARE_EXPORT_TABLE(pademu, 1, 1) DECLARE_EXPORT(_exit) DECLARE_EXPORT(_retonly) DECLARE_EXPORT(pademu_hookSio2man) + DECLARE_EXPORT(pademu_connect) + DECLARE_EXPORT(pademu_disconnect) END_EXPORT_TABLE void _retonly() {} diff --git a/modules/pademu/hidusb/Makefile b/modules/pademu/hidusb/Makefile new file mode 100644 index 000000000..a1de4238d --- /dev/null +++ b/modules/pademu/hidusb/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = hidusb.irx +IOP_OBJS = hidusb.o imports.o +IOP_OBJS_DIR = obj.hidusb/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/hidusb/hidusb.c b/modules/pademu/hidusb/hidusb.c new file mode 100644 index 000000000..e9b7a8770 --- /dev/null +++ b/modules/pademu/hidusb/hidusb.c @@ -0,0 +1,511 @@ +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "usbd.h" +#include "usbd_macro.h" +#include "thbase.h" +#include "thsemap.h" +#include "hidusb.h" + +//#define DPRINTF(x...) printf(x) +#define DPRINTF(x...) + +#define MAX_PADS 4 + +static u8 usb_buf[MAX_BUFFER_SIZE] __attribute((aligned(4))) = {0}; + +int usb_probe(int devId); +int usb_connect(int devId); +int usb_disconnect(int devId); + +static void usb_release(int pad); +static void usb_config_set(int result, int count, void *arg); + +UsbDriver usb_driver = {NULL, NULL, "hidusb", usb_probe, usb_connect, usb_disconnect}; + +int read_report_descriptor(u8 *data, int size, hidreport_t *report); +static void read_report(u8 *data, int pad); + +hidusb_device hiddev[MAX_PADS]; + +int usb_probe(int devId) +{ + UsbDeviceDescriptor *device; + UsbConfigDescriptor *config; + UsbInterfaceDescriptor *interface; + + DPRINTF("HIDUSB: probe: devId=%i\n", devId); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); + interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); + + if (interface->bInterfaceClass != USB_CLASS_HID) + return 0; + + return 1; +} + +int usb_connect(int devId) +{ + int pad, epCount, hid_report_size; + UsbDeviceDescriptor *device; + UsbConfigDescriptor *config; + UsbInterfaceDescriptor *interface; + UsbEndpointDescriptor *endpoint; + UsbHidDescriptor *hid; + u8 buf[512]; + + DPRINTF("HIDUSB: connect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (hiddev[pad].usb_id == -1) + break; + } + + if (pad >= MAX_PADS) { + DPRINTF("HIDUSB: Error - only %d device allowed !\n", MAX_PADS); + return 1; + } + + PollSema(hiddev[pad].sema); + + hiddev[pad].dev.id = pad; + hiddev[pad].usb_id = devId; + hiddev[pad].controlEndp = UsbOpenEndpoint(devId, NULL); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); + interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); + hid = (UsbHidDescriptor *)UsbGetDeviceStaticDescriptor(devId, interface, USB_DT_HID); + epCount = interface->bNumEndpoints - 1; + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + + do { + if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && hiddev[pad].interruptEndp < 0) { + hiddev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("DS3USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", hiddev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + } + + endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength); + + } while (epCount--); + + if (hiddev[pad].interruptEndp < 0) { + usb_release(pad); + return 1; + } + hid_report_size = (hid->Sub[0].wDescriptorLengthL | hid->Sub[0].wDescriptorLengthH << 8); + UsbControlTransfer(hiddev[pad].controlEndp, (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE), USB_REQ_GET_DESCRIPTOR, (hid->Sub[0].bDescriptorType << 8), interface->bInterfaceNumber, 512, buf, NULL, NULL); + DelayThread(10000); + read_report_descriptor(buf, hid_report_size, &hiddev[pad].rep); + UsbSetDeviceConfiguration(hiddev[pad].controlEndp, config->bConfigurationValue, usb_config_set, (void *)pad); + SignalSema(hiddev[pad].sema); + + return 0; +} + +int usb_disconnect(int devId) +{ + u8 pad; + + DPRINTF("DS3USB: disconnect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (hiddev[pad].usb_id == devId) { + pademu_disconnect(&hiddev[pad].dev); + break; + } + } + + if (pad < MAX_PADS) + usb_release(pad); + + return 0; +} + +static void usb_release(int pad) +{ + PollSema(hiddev[pad].sema); + + if (hiddev[pad].interruptEndp >= 0) + UsbCloseEndpoint(hiddev[pad].interruptEndp); + + hiddev[pad].controlEndp = -1; + hiddev[pad].interruptEndp = -1; + hiddev[pad].usb_id = -1; + hiddev[pad].lrum = 0; + hiddev[pad].rrum = 0; + hiddev[pad].update_rum = 1; + hiddev[pad].data[0] = 0xFF; + hiddev[pad].data[1] = 0xFF; + hiddev[pad].analog_btn = 0; + + mips_memset(&hiddev[pad].data[2], 0x7F, 4); + mips_memset(&hiddev[pad].data[6], 0x00, 12); + + SignalSema(hiddev[pad].sema); +} + +static void usb_data_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("DS3USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + hiddev[pad].usb_resultcode = resultCode; + + SignalSema(hiddev[pad].sema); +} + +static void usb_cmd_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("DS3USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + SignalSema(hiddev[pad].cmd_sema); +} + +static void usb_config_set(int result, int count, void *arg) +{ + int pad = (int)arg; + PollSema(hiddev[pad].sema); + DelayThread(10000); + pademu_connect(&hiddev[pad].dev); + SignalSema(hiddev[pad].sema); +} + +#define MAX_DELAY 10 + +static void read_report(u8 *data, int pad) +{ + int i, count, pos, bits; + u8 up = 0, down = 0, left = 0, right = 0, mask; + + + if (data[0] == 0x01) { + hiddev[pad].data[0] = 0x00; + hiddev[pad].data[1] = 0x00; + count = 4; + if (hiddev[pad].rep.axes.count < 4) + count = hiddev[pad].rep.axes.count; + + for (i = 0; i < count; i++) { + hiddev[pad].data[2 + i] = data[1 + (hiddev[pad].rep.axes.start_pos + hiddev[pad].rep.axes.size * i) / 8]; + } + + count = 16; + bits = 8; + if (hiddev[pad].rep.hats.count > 0) { + pos = hiddev[pad].rep.hats.start_pos; + switch ((data[1 + pos / 8] >> pos % 8) & 0x0F) { + case 0: + up = 1; + break; + case 1: + up = 1; + right = 1; + break; + case 2: + right = 1; + break; + case 3: + down = 1; + right = 1; + break; + case 4: + down = 1; + break; + case 5: + down = 1; + left = 1; + break; + case 6: + left = 1; + break; + case 7: + up = 1; + left = 1; + break; + case 8: + up = 0; + down = 0; + left = 0; + right = 0; + break; + } + hiddev[pad].data[0] = ~(up << 4 | right << 5 | down << 6 | left << 7 | 0x0F); + hiddev[pad].data[6] = right * 255; //right + hiddev[pad].data[7] = left * 255; //left + hiddev[pad].data[8] = up * 255; //up + hiddev[pad].data[9] = down * 255; //down + + count = 12; + bits = 4; + } + + if (hiddev[pad].rep.buttons.count < count) + count = hiddev[pad].rep.buttons.count; + + for (i = 0; i < count; i++) { + pos = hiddev[pad].rep.buttons.start_pos + hiddev[pad].rep.buttons.size * i; + if (i >= bits) { + //mask = ~(1 << (i - bits)); + //hiddev[pad].data[1] &= mask | (((data[1 + pos / 8] >> pos % 8) & 1) << (i - bits)); + hiddev[pad].data[1] |= (((data[1 + pos / 8] >> pos % 8) & 1) << (i - bits)); + } else { + //mask = ~(1 << i); + //hiddev[pad].data[0] &= mask | (((data[1 + pos / 8] >> pos % 8) & 1) << i); + hiddev[pad].data[0] |= (((data[1 + pos / 8] >> pos % 8) & 1) << i); + } + } + + //(report->Share | report->L3 << 1 | report->R3 << 2 | report->Option << 3 | up << 4 | right << 5 | down << 6 | left << 7); + //(report->L2 | report->R2 << 1 | report->L1 << 2 | report->R1 << 3 | report->Triangle << 4 | report->Circle << 5 | report->Cross << 6 | report->Square << 7); + + /* + hiddev[pad].data[10] = report->PressureTriangle; //triangle + hiddev[pad].data[11] = report->PressureCircle; //circle + hiddev[pad].data[12] = report->PressureCross; //cross + hiddev[pad].data[13] = report->PressureSquare; //square + + hiddev[pad].data[14] = report->PressureL1; //L1 + hiddev[pad].data[15] = report->PressureR1; //R1 + hiddev[pad].data[16] = report->PressureL2; //L2 + hiddev[pad].data[17] = report->PressureR2; //R2*/ + + /*hiddev[pad].data[0] = ~hiddev[pad].data[0]; + hiddev[pad].data[1] = ~hiddev[pad].data[1];*/ + } +} + +static unsigned int timeout(void *arg) +{ + int sema = (int)arg; + iSignalSema(sema); + return 0; +} + +static void TransferWait(int sema) +{ + iop_sys_clock_t cmd_timeout; + + cmd_timeout.lo = 200000; + cmd_timeout.hi = 0; + + if (SetAlarm(&cmd_timeout, timeout, (void *)sema) == 0) { + WaitSema(sema); + CancelAlarm(timeout, NULL); + } +} + +void hidusb_set_rumble(u8 lrum, u8 rrum, int port) +{ + WaitSema(hiddev[port].sema); + + hiddev[port].update_rum = 1; + hiddev[port].lrum = lrum; + hiddev[port].rrum = rrum; + + SignalSema(hiddev[port].sema); +} + +int hidusb_get_data(u8 *dst, int size, int port) +{ + int ret = 0; + + WaitSema(hiddev[port].sema); + + PollSema(hiddev[port].sema); + + ret = UsbInterruptTransfer(hiddev[port].interruptEndp, usb_buf, MAX_BUFFER_SIZE, usb_data_cb, (void *)port); + + if (ret == USB_RC_OK) { + TransferWait(hiddev[port].sema); + if (!hiddev[port].usb_resultcode) + read_report(usb_buf, port); + + hiddev[port].usb_resultcode = 1; + } else { + DPRINTF("HIDUSB: hidusb_get_data usb transfer error %d\n", ret); + } + + mips_memcpy(dst, hiddev[port].data, size); + ret = hiddev[port].analog_btn & 1; + + /*if (hiddev[port].update_rum) { + ret = LEDRumble(hiddev[port].oldled, hiddev[port].lrum, hiddev[port].rrum, port); + if (ret == USB_RC_OK) + TransferWait(hiddev[port].cmd_sema); + else + DPRINTF("DS3USB: LEDRumble usb transfer error %d\n", ret); + + hiddev[port].update_rum = 0; + }*/ + + SignalSema(hiddev[port].sema); + + return ret; +} + +void hidusb_set_mode(int mode, int lock, int port) +{ + if (lock == 3) + hiddev[port].analog_btn = 3; + else + hiddev[port].analog_btn = mode; +} + +void hidusb_reset() +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) + usb_release(pad); +} + +int _start(int argc, char *argv[]) +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) { + hiddev[pad].usb_id = -1; + hiddev[pad].dev.id = -1; + hiddev[pad].dev.pad_get_data = hidusb_get_data; + hiddev[pad].dev.pad_set_rumble = hidusb_set_rumble; + hiddev[pad].dev.pad_set_mode = hidusb_set_mode; + + hiddev[pad].lrum = 0; + hiddev[pad].rrum = 0; + hiddev[pad].update_rum = 1; + hiddev[pad].sema = -1; + hiddev[pad].cmd_sema = -1; + hiddev[pad].controlEndp = -1; + hiddev[pad].interruptEndp = -1; + + hiddev[pad].data[0] = 0xFF; + hiddev[pad].data[1] = 0xFF; + hiddev[pad].analog_btn = 0; + + mips_memset(&hiddev[pad].data[2], 0x7F, 4); + mips_memset(&hiddev[pad].data[6], 0x00, 12); + + hiddev[pad].sema = CreateMutex(IOP_MUTEX_UNLOCKED); + hiddev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); + + if (hiddev[pad].sema < 0 || hiddev[pad].cmd_sema < 0) { + DPRINTF("HIDUSB: Failed to allocate I/O semaphore.\n"); + return MODULE_NO_RESIDENT_END; + } + } + + if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { + DPRINTF("HIDUSB: Error registering USB devices\n"); + return MODULE_NO_RESIDENT_END; + } + + return MODULE_RESIDENT_END; +} + +int read_report_descriptor(u8 *data, int size, hidreport_t *report) +{ + u8 bSize, bType, bTag, bDataSize, bLongItemTag; + int dSize; + unsigned int dVal; + u8 *dPtr; + int i; + int rPos, rSize, rCount, rUsage; + + dPtr = data; + dSize = size; + + rPos = 0; + rSize = 0; + rCount = 0; + rUsage = 0; + + report->buttons.count = 0; + report->axes.count = 0; + report->hats.count = 0; + + while (dSize > 0) { + if (*dPtr != 0xFE) { //short item tag + + bSize = *dPtr & 3; + + if (bSize == 3) + bSize = 4; + + bType = (*dPtr >> 2) & 3; + bTag = (*dPtr >> 4) & 0x0F; + + for (i = 0, dVal = 0; i < bSize; i++) + dVal |= *(dPtr + 1 + i) << (8 * i); + + if (*dPtr == 0x85 && dVal == 2) //ReportID + break; + + if (*dPtr == 0x95) + rCount = dVal; + + if (*dPtr == 0x75) + rSize = dVal; + + if (*dPtr == 0x09 || *dPtr == 0x05) + rUsage = dVal; + + if (*dPtr == 0x81) { //Input + + switch (rUsage) { + case 0x09: //buttons + report->buttons.count = rCount; + report->buttons.size = rSize; + report->buttons.start_pos = rPos; + printf("Usage buttons: rCount %d rSize %d rPos %d\n", rCount, rSize, rPos); + break; + case 0x30: //x + case 0x31: //y + case 0x32: //z + case 0x33: //rx + case 0x34: //ry + case 0x35: //rz + report->axes.count = rCount; + report->axes.size = rSize; + report->axes.start_pos = rPos; + printf("Usage axes: rCount %d rSize %d rPos %d\n", rCount, rSize, rPos); + break; + case 0x39: //hats + report->hats.count = rCount; + report->hats.size = rSize; + report->hats.start_pos = rPos; + printf("Usage hats: rCount %d rSize %d rPos %d\n", rCount, rSize, rPos); + break; + } + + rPos += rSize * rCount; + rSize = 0; + rCount = 0; + rUsage = 0; + } + + dSize -= bSize + 1; + dPtr += bSize + 1; + } else { //long item tag + + bDataSize = *(dPtr + 1); + bLongItemTag = *(dPtr + 2); + + for (i = 0; i < bDataSize + 3; i++) { + dPtr++; + dSize--; + } + } + } + + return rPos; +} diff --git a/modules/pademu/hidusb/hidusb.h b/modules/pademu/hidusb/hidusb.h new file mode 100644 index 000000000..c8ff32861 --- /dev/null +++ b/modules/pademu/hidusb/hidusb.h @@ -0,0 +1,61 @@ +#ifndef _HIDUSB_H_ +#define _HIDUSB_H_ + +#include "irx.h" +#include "../pademu.h" + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +#define USB_DT_HID 0x21 + +/* HID Descriptor (Class Specific Descriptor) */ +typedef struct +{ + u8 bDescriptorType; + u8 wDescriptorLengthL; + u8 wDescriptorLengthH; +} UsbHidSubDescriptorInfo; + +typedef struct +{ + u8 bLength; + u8 bDescriptorType; + u16 bcdHID; + u8 bCountryCode; + u8 bNumDescriptors; /* Number of SubDescriptor */ + UsbHidSubDescriptorInfo Sub[0]; +} UsbHidDescriptor; + +typedef struct +{ + u16 count; + u16 size; //in bits + int start_pos; //position in report +} hiddata_t; + +typedef struct +{ + hiddata_t axes; + hiddata_t hats; + hiddata_t buttons; +} hidreport_t; + +typedef struct +{ + pad_device_t dev; + hidreport_t rep; + int usb_id; + int sema; + int cmd_sema; + int controlEndp; + int interruptEndp; + int usb_resultcode; + u8 lrum; + u8 rrum; + u8 update_rum; + u8 data[18]; + u8 analog_btn; + u8 btn_delay; +} hidusb_device; + +#endif diff --git a/modules/pademu/hidusb/imports.lst b/modules/pademu/hidusb/imports.lst new file mode 100644 index 000000000..e36f592dd --- /dev/null +++ b/modules/pademu/hidusb/imports.lst @@ -0,0 +1,68 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end diff --git a/modules/pademu/hidusb/irx_imports.h b/modules/pademu/hidusb/irx_imports.h new file mode 100644 index 000000000..280115628 --- /dev/null +++ b/modules/pademu/hidusb/irx_imports.h @@ -0,0 +1,40 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index 875208a02..d4c8ce3bd 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -6,39 +6,24 @@ Review OpenUsbLd README & LICENSE files for further details. */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "pademu.h" #include "padmacro.h" -#ifdef BT - -#include "ds34bt.h" - -#define PAD_INIT ds34bt_init -#define PAD_GET_STATUS ds34bt_get_status -#define PAD_RESET ds34bt_reset -#define PAD_GET_DATA ds34bt_get_data -#define PAD_SET_RUMBLE ds34bt_set_rumble -#define PAD_SET_MODE ds34bt_set_mode -#define PAD_GET_MODEL(port) 3 - -#elif defined(USB) - -#include "ds34usb.h" - -#define PAD_INIT ds34usb_init -#define PAD_GET_STATUS ds34usb_get_status -#define PAD_RESET ds34usb_reset -#define PAD_GET_DATA ds34usb_get_data -#define PAD_GET_MODEL ds34usb_get_model -#define PAD_SET_RUMBLE ds34usb_set_rumble -#define PAD_SET_MODE ds34usb_set_mode - -#else -#error "must define mode" -#endif - -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) +#define DPRINTF(x...) printf(x) +//#define DPRINTF(x...) typedef struct { @@ -52,6 +37,7 @@ typedef struct u8 lrum; u8 rrum; u8 mask[4]; + pad_device_t *dev; } pad_status_t; #define DIGITAL_MODE 0x41 @@ -61,15 +47,12 @@ typedef struct #define MAX_PORTS 4 -#define PAD_STATE_RUNNING 0x08 - IRX_ID("pademu", 1, 1); PtrRegisterLibraryEntires pRegisterLibraryEntires; /* Pointer to RegisterLibraryEntires routine */ Sio2McProc pSio2man25, pSio2man51; /* Pointers to SIO2MAN routines */ pad_status_t pad[MAX_PORTS]; -static u8 pad_inited = 0; static u8 pad_enable = 0; static u8 pad_options = 0; @@ -92,6 +75,9 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size); void pademu_mtap(sio2_transfer_data_t *td); +void pademu_connect(pad_device_t *dev); +void pademu_disconnect(pad_device_t *dev); + extern struct irx_export_table _exp_pademu; int _start(int argc, char *argv[]) @@ -147,7 +133,7 @@ int _start(int argc, char *argv[]) void _exit(int mode) { - PAD_RESET(); + } int install_sio2hook() @@ -157,7 +143,7 @@ int install_sio2hook() /* looking for LOADCORE's library entry table */ exp = GetExportTable("loadcore", 0x100); if (exp == NULL) { - DPRINTF("Unable to find loadcore exports.\n"); + DPRINTF("PADEMU: Unable to find loadcore exports.\n"); return 0; } @@ -170,7 +156,7 @@ int install_sio2hook() /* hooking SIO2MAN's routines */ InstallSio2manHook(exp, 1); } else { - DPRINTF("SIO2MAN exports not found.\n"); + DPRINTF("PADEMU: SIO2MAN exports not found.\n"); } return 1; @@ -178,6 +164,7 @@ int install_sio2hook() void InstallSio2manHook(void *exp, int ver) { + DPRINTF("PADEMU: Install sio2man hooks \n"); /* hooking SIO2MAN entry #25 (used by MCMAN and old PADMAN) */ pSio2man25 = HookExportEntry(exp, 25, hookSio2man25); /* hooking SIO2MAN entry #51 (used by MC2_* modules and PADMAN) */ @@ -196,12 +183,12 @@ int hookRegisterLibraryEntires(iop_library_t *lib) /* hooking SIO2MAN's routines */ InstallSio2manHook(&lib[1], GetExportTableSize(&lib[1]) >= 61); } else { - DPRINTF("registering library %s failed, error %d\n", lib->name, ret); + DPRINTF("PADEMU: registering library %s failed, error %d\n", lib->name, ret); return ret; } } - DPRINTF("registering library %s\n", lib->name); + DPRINTF("PADEMU: registering library %s\n", lib->name); return pRegisterLibraryEntires(lib); } @@ -300,6 +287,33 @@ void pademu_setup(u8 ports, u8 vib) pad[i].lrum = 2; pad[i].rrum = 2; + + pad[i].dev = NULL; + } +} + +void pademu_connect(pad_device_t *dev) +{ + int i; + for (i = 0; i < MAX_PORTS; i++) { + if (pad[i].enabled && pad[i].dev == NULL) { + pad[i].dev = dev; + pad[i].dev->id = i; + DPRINTF("PADEMU: Device connected\n"); + break; + } + } +} + +void pademu_disconnect(pad_device_t *dev) +{ + int i; + for (i = 0; i < MAX_PORTS; i++) { + if (pad[i].dev == dev) { + pad[i].dev = NULL; + DPRINTF("PADEMU: Device disconnected\n"); + break; + } } } @@ -324,10 +338,6 @@ void pademu(sio2_transfer_data_t *td) td->stat6c = 0x1100; //? td->stat70 = 0x0F; //? - if (!pad_inited) { - pad_inited = PAD_INIT(pad_enable, pad_options); - } - if (port2 == 1) { // find next cmd for (cmd_size = 5; cmd_size < td->in_size - 3; cmd_size++) { @@ -340,7 +350,7 @@ void pademu(sio2_transfer_data_t *td) } if (cmd_size + 3 == td->in_size) { - DPRINTF("Second cmd not found!\n"); + DPRINTF("PADEMU: Second cmd not found!\n"); return; } @@ -389,9 +399,11 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) { u8 i; + //DPRINTF("PADEMU: sio cmd %02x port %d\n", in[1], port); + mips_memset(out, 0x00, out_size); - if (!(PAD_GET_STATUS(port) & PAD_STATE_RUNNING)) { + if (pad[port].dev == NULL) { pad[port].lrum = 2; pad[port].rrum = 2; return; @@ -431,7 +443,7 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) } } - i = PAD_GET_DATA(&out[3], out_size - 3, port); + i = pad[port].dev->pad_get_data(&out[3], out_size - 3, pad[port].dev->id); if (pad[port].mode_lock == 0) { // mode unlocked if (pad[port].mode != i) { @@ -459,7 +471,7 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) } else { pad[port].mode_id = DIGITAL_MODE; } - PAD_SET_MODE(pad[port].mode, pad[port].mode_lock, port); + pad[port].dev->pad_set_mode(pad[port].mode, pad[port].mode_lock, pad[port].dev->id); break; case 0x45: // query model and mode diff --git a/modules/pademu/pademu.h b/modules/pademu/pademu.h index 0be94e786..61860c4b0 100644 --- a/modules/pademu/pademu.h +++ b/modules/pademu/pademu.h @@ -5,19 +5,6 @@ Review OpenUsbLd README & LICENSE files for further details. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "sys_utils.h" /* type for a pointer to LOADCORE's entry RegisterLibraryEntires */ @@ -52,9 +39,31 @@ typedef struct struct _sio2_dma_arg out_dma; } sio2_transfer_data_t; +typedef struct +{ + int id; + int (*pad_get_data)(u8 *dst, int size, int id); + void (*pad_set_rumble)(u8 lrum, u8 rrum, int id); + void (*pad_set_mode)(int mode, int lock, int id); +} pad_device_t; + typedef void (*Sio2McProc)(sio2_transfer_data_t *arg); void *GetExportTable(char *libname, int version); u32 GetExportTableSize(void *table); void *GetExportEntry(void *table, u32 entry); void *HookExportEntry(void *table, u32 entry, void *func); + + +#define pademu_IMPORTS_start DECLARE_IMPORT_TABLE(pademu, 1, 1) + +void pademu_hookSio2man(sio2_transfer_data_t *td, Sio2McProc sio2proc); +#define I_pademu_hookSio2man DECLARE_IMPORT(4, pademu_hookSio2man) + +void pademu_connect(pad_device_t *dev); +#define I_pademu_connect DECLARE_IMPORT(5, pademu_connect) + +void pademu_disconnect(pad_device_t *dev); +#define I_pademu_disconnect DECLARE_IMPORT(6, pademu_disconnect) + +#define pademu_IMPORTS_end END_IMPORT_TABLE diff --git a/modules/pademu/sys_utils.c b/modules/pademu/sys_utils.c index 31cbf66c5..c66e206b2 100644 --- a/modules/pademu/sys_utils.c +++ b/modules/pademu/sys_utils.c @@ -6,6 +6,19 @@ Review OpenUsbLd README & LICENSE files for further details. */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "pademu.h" /* prototype for LOADCORE's function */ diff --git a/modules/pademu/sys_utils.h b/modules/pademu/sys_utils.h index 66ff9cd26..b389e17de 100644 --- a/modules/pademu/sys_utils.h +++ b/modules/pademu/sys_utils.h @@ -32,4 +32,4 @@ void mips_memset(void *, int, unsigned); #define mips_memcpy memcpy #endif -#endif /* __MCEMU_UTILS_H */ +#endif diff --git a/modules/pademu/xbox360usb/Makefile b/modules/pademu/xbox360usb/Makefile new file mode 100644 index 000000000..8eba8e8cf --- /dev/null +++ b/modules/pademu/xbox360usb/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = xbox360usb.irx +IOP_OBJS = xbox360usb.o imports.o +IOP_OBJS_DIR = obj.xbox360usb/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/xbox360usb/imports.lst b/modules/pademu/xbox360usb/imports.lst new file mode 100644 index 000000000..e36f592dd --- /dev/null +++ b/modules/pademu/xbox360usb/imports.lst @@ -0,0 +1,68 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end diff --git a/modules/pademu/xbox360usb/irx_imports.h b/modules/pademu/xbox360usb/irx_imports.h new file mode 100644 index 000000000..280115628 --- /dev/null +++ b/modules/pademu/xbox360usb/irx_imports.h @@ -0,0 +1,40 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/xbox360usb/xbox360usb.c b/modules/pademu/xbox360usb/xbox360usb.c new file mode 100644 index 000000000..4072ed3eb --- /dev/null +++ b/modules/pademu/xbox360usb/xbox360usb.c @@ -0,0 +1,388 @@ +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "usbd.h" +#include "usbd_macro.h" +#include "thbase.h" +#include "thsemap.h" +#include "xbox360usb.h" + +//#define DPRINTF(x...) printf(x) +#define DPRINTF(x...) + +#define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) + +#define MAX_PADS 4 + +static u8 usb_buf[MAX_BUFFER_SIZE] __attribute((aligned(4))) = {0}; + +int usb_probe(int devId); +int usb_connect(int devId); +int usb_disconnect(int devId); + +static void usb_release(int pad); +static void usb_config_set(int result, int count, void *arg); + +UsbDriver usb_driver = {NULL, NULL, "xbox360usb", usb_probe, usb_connect, usb_disconnect}; + +static void readReport(u8 *data, int pad); +static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); + +xbox360usb_device xbox360dev[MAX_PADS]; + +int usb_probe(int devId) +{ + UsbDeviceDescriptor *device = NULL; + + DPRINTF("XBOX360USB: probe: devId=%i\n", devId); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + if (device == NULL) { + DPRINTF("XBOX360USB: Error - Couldn't get device descriptor\n"); + return 0; + } + + if ((device->idVendor == XBOX_VID || device->idVendor == MADCATZ_VID || device->idVendor == JOYTECH_VID || device->idVendor == GAMESTOP_VID) && + (device->idProduct == XBOX_WIRED_PID || device->idProduct == MADCATZ_WIRED_PID || device->idProduct == GAMESTOP_WIRED_PID || + device->idProduct == AFTERGLOW_WIRED_PID || device->idProduct == JOYTECH_WIRED_PID)) + return 1; + + return 0; +} + +int usb_connect(int devId) +{ + int pad, epCount; + UsbDeviceDescriptor *device; + UsbConfigDescriptor *config; + UsbInterfaceDescriptor *interface; + UsbEndpointDescriptor *endpoint; + + DPRINTF("XBOX360USB: connect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (xbox360dev[pad].usb_id == -1) + break; + } + + if (pad >= MAX_PADS) { + DPRINTF("XBOX360USB: Error - only %d device allowed !\n", MAX_PADS); + return 1; + } + + PollSema(xbox360dev[pad].sema); + + xbox360dev[pad].dev.id = pad; + xbox360dev[pad].usb_id = devId; + xbox360dev[pad].controlEndp = UsbOpenEndpoint(devId, NULL); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); + interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); + epCount = interface->bNumEndpoints - 1; + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + + do { + if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && xbox360dev[pad].interruptEndp < 0) { + xbox360dev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); + DPRINTF("XBOX360USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", xbox360dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + } + + endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength); + + } while (epCount--); + + if (xbox360dev[pad].interruptEndp < 0) { + usb_release(pad); + return 1; + } + + UsbSetDeviceConfiguration(xbox360dev[pad].controlEndp, config->bConfigurationValue, usb_config_set, (void *)pad); + SignalSema(xbox360dev[pad].sema); + + return 0; +} + +int usb_disconnect(int devId) +{ + u8 pad; + + DPRINTF("XBOX360USB: disconnect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (xbox360dev[pad].usb_id == devId) { + pademu_disconnect(&xbox360dev[pad].dev); + break; + } + } + + if (pad < MAX_PADS) + usb_release(pad); + + return 0; +} + +static void usb_release(int pad) +{ + PollSema(xbox360dev[pad].sema); + + if (xbox360dev[pad].interruptEndp >= 0) + UsbCloseEndpoint(xbox360dev[pad].interruptEndp); + + xbox360dev[pad].controlEndp = -1; + xbox360dev[pad].interruptEndp = -1; + xbox360dev[pad].usb_id = -1; + + SignalSema(xbox360dev[pad].sema); +} + +static void usb_data_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("XBOX360USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + xbox360dev[pad].usb_resultcode = resultCode; + + SignalSema(xbox360dev[pad].sema); +} + +static void usb_cmd_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("XBOX360USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + SignalSema(xbox360dev[pad].cmd_sema); +} + +static void usb_config_set(int result, int count, void *arg) +{ + int pad = (int)arg; + u8 led[2]; + + PollSema(xbox360dev[pad].sema); + + led[0] = 0x02 + pad; + led[1] = 0; + + LEDRumble(led, 0, 0, pad); + SignalSema(xbox360dev[pad].sema); + + pademu_connect(&xbox360dev[pad].dev); +} + +#define MAX_DELAY 10 + +static void readReport(u8 *data, int pad) +{ + xbox360report_t *report = (xbox360report_t *)data; + if (report->ReportID == 0x00 && report->Length == 0x14) { + xbox360dev[pad].data[0] = ~(report->Back | report->LS << 1 | report->RS << 2 | report->Start << 3 | report->Up << 4 | report->Right << 5 | report->Down << 6 | report->Left << 7); + xbox360dev[pad].data[1] = ~((report->LeftTrigger != 0) | (report->RightTrigger != 0) << 1 | report->LB << 2 | report->RB << 3 | report->Y << 4 | report->B << 5 | report->A << 6 | report->X << 7); + + xbox360dev[pad].data[2] = report->RightStickXH; //rx + xbox360dev[pad].data[3] = report->RightStickYH; //ry + xbox360dev[pad].data[4] = report->LeftStickXH; //lx + xbox360dev[pad].data[5] = report->LeftStickYH; //ly + + xbox360dev[pad].data[6] = report->Right * 255; //right + xbox360dev[pad].data[7] = report->Left * 255; //left + xbox360dev[pad].data[8] = report->Up * 255; //up + xbox360dev[pad].data[9] = report->Down * 255; //down + + xbox360dev[pad].data[10] = report->Y * 255; //triangle + xbox360dev[pad].data[11] = report->B * 255; //circle + xbox360dev[pad].data[12] = report->A * 255; //cross + xbox360dev[pad].data[13] = report->X * 255; //square + + xbox360dev[pad].data[14] = report->LB * 255; //L1 + xbox360dev[pad].data[15] = report->RB * 255; //R1 + xbox360dev[pad].data[16] = report->LeftTrigger; //L2 + xbox360dev[pad].data[17] = report->RightTrigger; //R2 + + if (report->XBOX) { //display battery level + if (report->Back && (xbox360dev[pad].btn_delay == MAX_DELAY)) { //XBOX + BACK + if (xbox360dev[pad].analog_btn < 2) //unlocked mode + xbox360dev[pad].analog_btn = !xbox360dev[pad].analog_btn; + + //xbox360dev[pad].oldled[0] = led_patterns[pad][(xbox360dev[pad].analog_btn & 1)]; + xbox360dev[pad].btn_delay = 1; + } else { + //if (report->Power != 0xEE) + // xbox360dev[pad].oldled[0] = power_level[report->Power]; + + if (xbox360dev[pad].btn_delay < MAX_DELAY) + xbox360dev[pad].btn_delay++; + } + } else { + //xbox360dev[pad].oldled[0] = led_patterns[pad][(xbox360dev[pad].analog_btn & 1)]; + + if (xbox360dev[pad].btn_delay > 0) + xbox360dev[pad].btn_delay--; + } + } +} + +static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) +{ + int ret; + PollSema(xbox360dev[pad].cmd_sema); + + usb_buf[0] = 0x00; + usb_buf[1] = 0x08; + usb_buf[2] = 0x00; + usb_buf[3] = lrum; // big weight + usb_buf[4] = rrum; // small weight + usb_buf[5] = 0x00; + usb_buf[6] = 0x00; + usb_buf[7] = 0x00; + + ret = UsbControlTransfer(xbox360dev[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_SET_REPORT_OUTPUT << 8) | 0x01, 0, 8, usb_buf, usb_cmd_cb, (void *)pad); + if (ret == USB_RC_OK) { + usb_buf[0] = 0x01; + usb_buf[1] = 0x03; + usb_buf[2] = led[0]; + ret = UsbControlTransfer(xbox360dev[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_SET_REPORT_OUTPUT << 8) | 0x01, 0, 3, usb_buf, usb_cmd_cb, (void *)pad); + } + + xbox360dev[pad].oldled[0] = led[0]; + xbox360dev[pad].oldled[1] = led[1]; + + return ret; +} + +static unsigned int timeout(void *arg) +{ + int sema = (int)arg; + iSignalSema(sema); + return 0; +} + +static void TransferWait(int sema) +{ + iop_sys_clock_t cmd_timeout; + + cmd_timeout.lo = 200000; + cmd_timeout.hi = 0; + + if (SetAlarm(&cmd_timeout, timeout, (void *)sema) == 0) { + WaitSema(sema); + CancelAlarm(timeout, NULL); + } +} + +void xbox360usb_set_rumble(u8 lrum, u8 rrum, int port) +{ + WaitSema(xbox360dev[port].sema); + + xbox360dev[port].update_rum = 1; + xbox360dev[port].lrum = lrum; + xbox360dev[port].rrum = rrum; + + SignalSema(xbox360dev[port].sema); +} + +int xbox360usb_get_data(u8 *dst, int size, int port) +{ + int ret = 0; + + WaitSema(xbox360dev[port].sema); + + PollSema(xbox360dev[port].sema); + + ret = UsbInterruptTransfer(xbox360dev[port].interruptEndp, usb_buf, MAX_BUFFER_SIZE, usb_data_cb, (void *)port); + + if (ret == USB_RC_OK) { + TransferWait(xbox360dev[port].sema); + if (!xbox360dev[port].usb_resultcode) + readReport(usb_buf, port); + + xbox360dev[port].usb_resultcode = 1; + } else { + DPRINTF("XBOX360USB: XBOX360USB_get_data usb transfer error %d\n", ret); + } + + mips_memcpy(dst, xbox360dev[port].data, size); + ret = xbox360dev[port].analog_btn & 1; + + if (xbox360dev[port].update_rum) { + ret = LEDRumble(xbox360dev[port].oldled, xbox360dev[port].lrum, xbox360dev[port].rrum, port); + if (ret == USB_RC_OK) + TransferWait(xbox360dev[port].cmd_sema); + else + DPRINTF("XBOX360USB: LEDRumble usb transfer error %d\n", ret); + + xbox360dev[port].update_rum = 0; + } + + SignalSema(xbox360dev[port].sema); + + return ret; +} + +void xbox360usb_set_mode(int mode, int lock, int port) +{ + if (lock == 3) + xbox360dev[port].analog_btn = 3; + else + xbox360dev[port].analog_btn = mode; +} + +void xbox360usb_reset() +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) + usb_release(pad); +} + +int _start(int argc, char *argv[]) +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) { + xbox360dev[pad].usb_id = -1; + xbox360dev[pad].dev.id = -1; + xbox360dev[pad].dev.pad_get_data = xbox360usb_get_data; + xbox360dev[pad].dev.pad_set_rumble = xbox360usb_set_rumble; + xbox360dev[pad].dev.pad_set_mode = xbox360usb_set_mode; + + xbox360dev[pad].oldled[0] = 0; + xbox360dev[pad].oldled[1] = 0; + xbox360dev[pad].lrum = 0; + xbox360dev[pad].rrum = 0; + xbox360dev[pad].update_rum = 1; + xbox360dev[pad].sema = -1; + xbox360dev[pad].cmd_sema = -1; + xbox360dev[pad].controlEndp = -1; + xbox360dev[pad].interruptEndp = -1; + + xbox360dev[pad].data[0] = 0xFF; + xbox360dev[pad].data[1] = 0xFF; + xbox360dev[pad].analog_btn = 0; + + mips_memset(&xbox360dev[pad].data[2], 0x7F, 4); + mips_memset(&xbox360dev[pad].data[6], 0x00, 12); + + xbox360dev[pad].sema = CreateMutex(IOP_MUTEX_UNLOCKED); + xbox360dev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); + + if (xbox360dev[pad].sema < 0 || xbox360dev[pad].cmd_sema < 0) { + DPRINTF("XBOX360USB: Failed to allocate I/O semaphore.\n"); + return MODULE_NO_RESIDENT_END; + } + } + + if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { + DPRINTF("XBOX360USB: Error registering USB devices\n"); + return MODULE_NO_RESIDENT_END; + } + + return MODULE_RESIDENT_END; +} diff --git a/modules/pademu/xbox360usb/xbox360usb.h b/modules/pademu/xbox360usb/xbox360usb.h new file mode 100644 index 000000000..b32412f9e --- /dev/null +++ b/modules/pademu/xbox360usb/xbox360usb.h @@ -0,0 +1,140 @@ +#ifndef _XBOX360USB_H_ +#define _XBOX360USB_H_ + +#include "irx.h" +#include "../pademu.h" + +#define XBOX_VID 0x045E // Microsoft Corporation +#define MADCATZ_VID 0x1BAD // For unofficial Mad Catz controllers +#define JOYTECH_VID 0x162E // For unofficial Joytech controllers +#define GAMESTOP_VID 0x0E6F // Gamestop controller + +#define XBOX_WIRED_PID 0x028E // Microsoft 360 Wired controller +#define XBOX_WIRELESS_PID 0x028F // Wireless controller only support charging +#define XBOX_WIRELESS_RECEIVER_PID 0x0719 // Microsoft Wireless Gaming Receiver +#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID 0x0291 // Third party Wireless Gaming Receiver +#define MADCATZ_WIRED_PID 0xF016 // Mad Catz wired controller +#define JOYTECH_WIRED_PID 0xBEEF // For Joytech wired controller +#define GAMESTOP_WIRED_PID 0x0401 // Gamestop wired controller +#define AFTERGLOW_WIRED_PID 0x0213 // Afterglow wired controller - it uses the same VID as a Gamestop controller + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +typedef struct +{ + pad_device_t dev; + int usb_id; + int sema; + int cmd_sema; + int controlEndp; + int interruptEndp; + int usb_resultcode; + u8 oldled[2]; + u8 lrum; + u8 rrum; + u8 update_rum; + u8 data[18]; + u8 analog_btn; + u8 btn_delay; +} xbox360usb_device; + +enum eHID { + // {{{ + /* HID event flag */ + HID_FLAG_STATUS_REPORTED = 0x01, + HID_FLAG_BUTTONS_CHANGED = 0x02, + HID_FLAG_EXTENSION = 0x04, + HID_FLAG_COMMAND_SUCCESS = 0x08, + + /* USB HID Transaction Header (THdr) */ + HID_USB_GET_REPORT_FEATURE = 0x03, + HID_USB_SET_REPORT_OUTPUT = 0x02, + HID_USB_DATA_INPUT = 0x01, + + /* Defines of various parameters for PS3 Game controller reports */ + PS3_F4_REPORT_ID = 0xF4, + PS3_F4_REPORT_LEN = 0x04, + + PS3_01_REPORT_ID = 0x01, + PS3_01_REPORT_LEN = 0x30, + + PS4_02_REPORT_ID = 0x02, + PS4_11_REPORT_ID = 0x11, + PS4_11_REPORT_LEN = 0x4D, + // }}} +}; + +typedef struct { + u8 ReportID; + u8 Length; //0x14 + union + { + u8 ButtonStateL; // Main buttons Low + struct + { + u8 Up : 1; + u8 Down : 1; + u8 Left : 1; + u8 Right : 1; + u8 Start : 1; + u8 Back : 1; + u8 LS : 1; + u8 RS : 1; + }; + }; + union + { + u8 ButtonStateH; // Main buttons High + struct + { + u8 LB : 1; + u8 RB : 1; + u8 XBOX : 1; + u8 Dummy1 : 1; + u8 A : 1; + u8 B : 1; + u8 X : 1; + u8 Y : 1; + }; + }; + u8 LeftTrigger; + u8 RightTrigger; + union + { + u16 LeftStickX; + struct + { + u8 LeftStickXL; + u8 LeftStickXH; + }; + }; + union + { + u16 LeftStickY; + struct + { + u8 LeftStickYL; + u8 LeftStickYH; + }; + }; + union + { + u16 RightStickX; + struct + { + u8 RightStickXL; + u8 RightStickXH; + }; + }; + union + { + u16 RightStickY; + struct + { + u8 RightStickYL; + u8 RightStickYH; + }; + }; +} __attribute__((packed)) xbox360report_t; + +#endif diff --git a/modules/pademu/xboxoneusb/Makefile b/modules/pademu/xboxoneusb/Makefile new file mode 100644 index 000000000..fa6c97469 --- /dev/null +++ b/modules/pademu/xboxoneusb/Makefile @@ -0,0 +1,22 @@ + +IOP_BIN = xboxoneusb.irx +IOP_OBJS = xboxoneusb.o imports.o +IOP_OBJS_DIR = obj.xboxoneusb/ + +IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) + +IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS +IOP_LDFLAGS += -s + +all: OBJ_DIR $(IOP_BIN) + +clean: + rm -f $(IOP_BIN) $(IOP_OBJS) + +rebuild: clean all + +OBJ_DIR: + mkdir -p $(IOP_OBJS_DIR) + +include $(PS2SDK)/Defs.make +include ../Rules.make diff --git a/modules/pademu/xboxoneusb/imports.lst b/modules/pademu/xboxoneusb/imports.lst new file mode 100644 index 000000000..e36f592dd --- /dev/null +++ b/modules/pademu/xboxoneusb/imports.lst @@ -0,0 +1,68 @@ +loadcore_IMPORTS_start +I_RegisterLibraryEntries +I_ReleaseLibraryEntries +I_GetLoadcoreInternalData +I_QueryLibraryEntryTable +I_SetRebootTimeLibraryHandlingMode +loadcore_IMPORTS_end + +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + +thsemap_IMPORTS_start +I_CreateSema +I_SignalSema +I_WaitSema +I_PollSema +I_DeleteSema +I_iSignalSema +thsemap_IMPORTS_end + +thbase_IMPORTS_start +I_StartThread +I_CreateThread +I_DeleteThread +I_DelayThread +I_GetThreadId +I_SleepThread +I_WakeupThread +I_TerminateThread +I_SetAlarm +I_CancelAlarm +thbase_IMPORTS_end + +intrman_IMPORTS_start +I_CpuSuspendIntr +I_CpuResumeIntr +intrman_IMPORTS_end + +usbd_IMPORTS_start +I_sceUsbdScanStaticDescriptor +I_sceUsbdOpenPipe +I_sceUsbdClosePipe +I_sceUsbdOpenPipeAligned +I_sceUsbdSetPrivateData +I_sceUsbdTransferPipe +I_sceUsbdRegisterLdd +usbd_IMPORTS_end + +sysclib_IMPORTS_start +I_strncmp +#ifndef USE_SMSUTILS +I_memset +I_memcpy +#endif +sysclib_IMPORTS_end + +#ifdef USE_SMSUTILS +smsutils_IMPORTS_start +I_mips_memset +I_mips_memcpy +smsutils_IMPORTS_end +#endif + +pademu_IMPORTS_start +I_pademu_connect +I_pademu_disconnect +pademu_IMPORTS_end diff --git a/modules/pademu/xboxoneusb/irx_imports.h b/modules/pademu/xboxoneusb/irx_imports.h new file mode 100644 index 000000000..280115628 --- /dev/null +++ b/modules/pademu/xboxoneusb/irx_imports.h @@ -0,0 +1,40 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# $Id$ +# Defines all IRX imports. +*/ + +#ifndef IOP_IRX_IMPORTS_H +#define IOP_IRX_IMPORTS_H + +#include "irx.h" + +/* Please keep these in alphabetical order! */ +#include "dmacman.h" +#include "intrman.h" +#include "iomanX.h" +#include "libsd.h" +#include "loadcore.h" +#include "sifcmd.h" +#include "sifman.h" +#include "stdio.h" +#include "sysclib.h" +#include "sysmem.h" +#include "thbase.h" +#include "thevent.h" +#include "thmsgbx.h" +#include "thsemap.h" +#include "usbd.h" +#include "vblank.h" +#include "xloadcore.h" + +#include "../pademu.h" + +#endif /* IOP_IRX_IMPORTS_H */ diff --git a/modules/pademu/xboxoneusb/xboxoneusb.c b/modules/pademu/xboxoneusb/xboxoneusb.c new file mode 100644 index 000000000..ac0581851 --- /dev/null +++ b/modules/pademu/xboxoneusb/xboxoneusb.c @@ -0,0 +1,380 @@ +#include "types.h" +#include "loadcore.h" +#include "stdio.h" +#include "sifrpc.h" +#include "sysclib.h" +#include "usbd.h" +#include "usbd_macro.h" +#include "thbase.h" +#include "thsemap.h" +#include "xboxoneusb.h" + +//#define DPRINTF(x...) printf(x) +#define DPRINTF(x...) + +#define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) + +#define MAX_PADS 4 + +static u8 usb_buf[MAX_BUFFER_SIZE + 32] __attribute((aligned(4))) = {0}; + +int usb_probe(int devId); +int usb_connect(int devId); +int usb_disconnect(int devId); + +static void usb_release(int pad); +static void usb_config_set(int result, int count, void *arg); + +UsbDriver usb_driver = {NULL, NULL, "xboxoneusb", usb_probe, usb_connect, usb_disconnect}; + +static void readReport(u8 *data, int pad); +static int Rumble(u8 lrum, u8 rrum, int pad); + +xboxoneusb_device xboxonedev[MAX_PADS]; +static u8 cmdcnt = 0; + +int usb_probe(int devId) +{ + UsbDeviceDescriptor *device = NULL; + + DPRINTF("XBOXONEUSB: probe: devId=%i\n", devId); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + if (device == NULL) { + DPRINTF("XBOXONEUSB: Error - Couldn't get device descriptor\n"); + return 0; + } + + if ((device->idVendor == XBOX_VID || device->idVendor == XBOX_VID2 || device->idVendor == XBOX_VID3 || device->idVendor == XBOX_VID4 || device->idVendor == XBOX_VID5 || device->idVendor == XBOX_VID6) && + (device->idProduct == XBOX_ONE_PID1 || device->idProduct == XBOX_ONE_PID2 || device->idProduct == XBOX_ONE_PID3 || device->idProduct == XBOX_ONE_PID4 || + device->idProduct == XBOX_ONE_PID5 || device->idProduct == XBOX_ONE_PID6 || device->idProduct == XBOX_ONE_PID7 || device->idProduct == XBOX_ONE_PID8 || + device->idProduct == XBOX_ONE_PID9 || device->idProduct == XBOX_ONE_PID10 || device->idProduct == XBOX_ONE_PID11 || device->idProduct == XBOX_ONE_PID12 || device->idProduct == XBOX_ONE_PID13)) + return 1; + + return 0; +} + +int usb_connect(int devId) +{ + int pad, epCount; + UsbDeviceDescriptor *device; + UsbConfigDescriptor *config; + UsbInterfaceDescriptor *interface; + UsbEndpointDescriptor *endpoint; + + DPRINTF("XBOXONEUSB: connect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (xboxonedev[pad].usb_id == -1) + break; + } + + if (pad >= MAX_PADS) { + DPRINTF("XBOXONEUSB: Error - only %d device allowed !\n", MAX_PADS); + return 1; + } + + PollSema(xboxonedev[pad].sema); + + xboxonedev[pad].dev.id = pad; + xboxonedev[pad].usb_id = devId; + xboxonedev[pad].controlEndp = UsbOpenEndpoint(devId, NULL); + + device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); + config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); + interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); + epCount = interface->bNumEndpoints - 1; + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + + do { + if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && xboxonedev[pad].interruptEndp < 0) { + xboxonedev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); + xboxonedev[pad].endin = endpoint; + DPRINTF("XBOXONEUSB: register Event endpoint id =%i addr=%02X packetSize=%i\n", xboxonedev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && xboxonedev[pad].outEndp < 0) { + xboxonedev[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); + xboxonedev[pad].endout = endpoint; + DPRINTF("DS34USB: register Output endpoint id =%i addr=%02X packetSize=%i\n", xboxonepad[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + } + } + + endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength); + + } while (epCount--); + + if (xboxonedev[pad].interruptEndp < 0 || xboxonedev[pad].outEndp < 0) { + usb_release(pad); + return 1; + } + + UsbSetDeviceConfiguration(xboxonedev[pad].controlEndp, config->bConfigurationValue, usb_config_set, (void *)pad); + SignalSema(xboxonedev[pad].sema); + + return 0; +} + +int usb_disconnect(int devId) +{ + u8 pad; + + DPRINTF("XBOXONEUSB: disconnect: devId=%i\n", devId); + + for (pad = 0; pad < MAX_PADS; pad++) { + if (xboxonedev[pad].usb_id == devId) { + pademu_disconnect(&xboxonedev[pad].dev); + break; + } + } + + if (pad < MAX_PADS) + usb_release(pad); + + return 0; +} + +static void usb_release(int pad) +{ + PollSema(xboxonedev[pad].sema); + + if (xboxonedev[pad].interruptEndp >= 0) + UsbCloseEndpoint(xboxonedev[pad].interruptEndp); + + if (xboxonedev[pad].outEndp >= 0) + UsbCloseEndpoint(xboxonedev[pad].outEndp); + + xboxonedev[pad].controlEndp = -1; + xboxonedev[pad].interruptEndp = -1; + xboxonedev[pad].outEndp = -1; + xboxonedev[pad].usb_id = -1; + + SignalSema(xboxonedev[pad].sema); +} + +static void usb_data_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("XBOXONEUSB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + xboxonedev[pad].usb_resultcode = resultCode; + + SignalSema(xboxonedev[pad].sema); +} + +static void usb_cmd_cb(int resultCode, int bytes, void *arg) +{ + int pad = (int)arg; + + //DPRINTF("XBOXONEUSB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + + SignalSema(xboxonedev[pad].cmd_sema); +} + +static void usb_config_set(int result, int count, void *arg) +{ + int pad = (int)arg; + + PollSema(xboxonedev[pad].sema); + + cmdcnt = 0; + usb_buf[0] = 0x05; + usb_buf[1] = 0x20; + usb_buf[2] = cmdcnt++; + usb_buf[3] = 0x01; + usb_buf[4] = 0x00; + UsbInterruptTransfer(xboxonedev[pad].outEndp, usb_buf, 5, NULL, NULL); + DelayThread(10000); + + SignalSema(xboxonedev[pad].sema); + + pademu_connect(&xboxonedev[pad].dev); +} + +#define MAX_DELAY 10 + +static void readReport(u8 *data, int pad) +{ + xboxonereport_t *report = (xboxonereport_t *)data; + if (report->ReportID == 0x20) { + xboxonedev[pad].data[0] = ~(report->Back | report->LS << 1 | report->RS << 2 | report->Start << 3 | report->Up << 4 | report->Right << 5 | report->Down << 6 | report->Left << 7); + xboxonedev[pad].data[1] = ~((report->LeftTriggerH != 0) | (report->RightTriggerH != 0) << 1 | report->LB << 2 | report->RB << 3 | report->Y << 4 | report->B << 5 | report->A << 6 | report->X << 7); + + xboxonedev[pad].data[2] = report->RightStickXH + 128; //rx + xboxonedev[pad].data[3] = ~(report->RightStickYH + 128); //ry + xboxonedev[pad].data[4] = report->LeftStickXH + 128; //lx + xboxonedev[pad].data[5] = ~(report->LeftStickYH + 128); //ly + + xboxonedev[pad].data[6] = report->Right * 255; //right + xboxonedev[pad].data[7] = report->Left * 255; //left + xboxonedev[pad].data[8] = report->Up * 255; //up + xboxonedev[pad].data[9] = report->Down * 255; //down + + xboxonedev[pad].data[10] = report->Y * 255; //triangle + xboxonedev[pad].data[11] = report->B * 255; //circle + xboxonedev[pad].data[12] = report->A * 255; //cross + xboxonedev[pad].data[13] = report->X * 255; //square + + xboxonedev[pad].data[14] = report->LB * 255; //L1 + xboxonedev[pad].data[15] = report->RB * 255; //R1 + xboxonedev[pad].data[16] = report->LeftTriggerH; //L2 + xboxonedev[pad].data[17] = report->RightTriggerH; //R2 + } +} + +static int Rumble(u8 lrum, u8 rrum, int pad) +{ + PollSema(xboxonedev[pad].cmd_sema); + + usb_buf[0] = 0x09; + usb_buf[1] = 0x00; + usb_buf[2] = cmdcnt++; + usb_buf[3] = 0x09; // Substructure (what substructure rest of this packet has) + usb_buf[4] = 0x00; // Mode + usb_buf[5] = 0x0F; // Rumble mask (what motors are activated) (0000 lT rT L R) + usb_buf[6] = 0x00; // lT force + usb_buf[7] = 0x00; // rT force + usb_buf[8] = lrum; // L force + usb_buf[9] = rrum; // R force + usb_buf[10] = 0x80; // Length of pulse + usb_buf[11] = 0x00; // Off period + usb_buf[12] = 0x00; // Repeat count + + return UsbInterruptTransfer(xboxonedev[pad].outEndp, usb_buf, 13, usb_cmd_cb, (void *)pad); +} + +static unsigned int timeout(void *arg) +{ + int sema = (int)arg; + iSignalSema(sema); + return 0; +} + +static void TransferWait(int sema) +{ + iop_sys_clock_t cmd_timeout; + + cmd_timeout.lo = 200000; + cmd_timeout.hi = 0; + + if (SetAlarm(&cmd_timeout, timeout, (void *)sema) == 0) { + WaitSema(sema); + CancelAlarm(timeout, NULL); + } +} + +void xboxoneusb_set_rumble(u8 lrum, u8 rrum, int port) +{ + WaitSema(xboxonedev[port].sema); + + xboxonedev[port].update_rum = 1; + xboxonedev[port].lrum = lrum; + xboxonedev[port].rrum = rrum; + + SignalSema(xboxonedev[port].sema); +} + +int xboxoneusb_get_data(u8 *dst, int size, int port) +{ + int ret = 0; + + WaitSema(xboxonedev[port].sema); + + PollSema(xboxonedev[port].sema); + + ret = UsbInterruptTransfer(xboxonedev[port].interruptEndp, usb_buf, MAX_BUFFER_SIZE, usb_data_cb, (void *)port); + + if (ret == USB_RC_OK) { + TransferWait(xboxonedev[port].sema); + if (!xboxonedev[port].usb_resultcode) + readReport(usb_buf, port); + + xboxonedev[port].usb_resultcode = 1; + } else { + UsbCloseEndpoint(xboxonedev[port].interruptEndp); + xboxonedev[port].interruptEndp = UsbOpenEndpointAligned(xboxonedev[port].usb_id, xboxonedev[port].endin); + DPRINTF("XBOXONEUSB: XBOXONEUSB_get_data usb transfer error %d\n", ret); + } + + mips_memcpy(dst, xboxonedev[port].data, size); + ret = xboxonedev[port].analog_btn & 1; + + if (xboxonedev[port].update_rum) { + ret = Rumble(xboxonedev[port].lrum, xboxonedev[port].rrum, port); + if (ret == USB_RC_OK) { + TransferWait(xboxonedev[port].cmd_sema); + } else { + UsbCloseEndpoint(xboxonedev[port].outEndp); + xboxonedev[port].outEndp = UsbOpenEndpointAligned(xboxonedev[port].usb_id, xboxonedev[port].endout); + DPRINTF("XBOXONEUSB: LEDRumble usb transfer error %d\n", ret); + } + + xboxonedev[port].update_rum = 0; + } + + SignalSema(xboxonedev[port].sema); + + return ret; +} + +void xboxoneusb_set_mode(int mode, int lock, int port) +{ + if (lock == 3) + xboxonedev[port].analog_btn = 3; + else + xboxonedev[port].analog_btn = mode; +} + +void xboxoneusb_reset() +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) + usb_release(pad); +} + +int _start(int argc, char *argv[]) +{ + int pad; + + for (pad = 0; pad < MAX_PADS; pad++) { + xboxonedev[pad].usb_id = -1; + xboxonedev[pad].dev.id = -1; + xboxonedev[pad].dev.pad_get_data = xboxoneusb_get_data; + xboxonedev[pad].dev.pad_set_rumble = xboxoneusb_set_rumble; + xboxonedev[pad].dev.pad_set_mode = xboxoneusb_set_mode; + + xboxonedev[pad].lrum = 0; + xboxonedev[pad].rrum = 0; + xboxonedev[pad].update_rum = 1; + xboxonedev[pad].sema = -1; + xboxonedev[pad].cmd_sema = -1; + xboxonedev[pad].controlEndp = -1; + xboxonedev[pad].interruptEndp = -1; + xboxonedev[pad].outEndp = -1; + + xboxonedev[pad].data[0] = 0xFF; + xboxonedev[pad].data[1] = 0xFF; + xboxonedev[pad].analog_btn = 0; + + mips_memset(&xboxonedev[pad].data[2], 0x7F, 4); + mips_memset(&xboxonedev[pad].data[6], 0x00, 12); + + xboxonedev[pad].sema = CreateMutex(IOP_MUTEX_UNLOCKED); + xboxonedev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); + + if (xboxonedev[pad].sema < 0 || xboxonedev[pad].cmd_sema < 0) { + DPRINTF("XBOXONEUSB: Failed to allocate I/O semaphore.\n"); + return MODULE_NO_RESIDENT_END; + } + } + + if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { + DPRINTF("XBOXONEUSB: Error registering USB devices\n"); + return MODULE_NO_RESIDENT_END; + } + + return MODULE_RESIDENT_END; +} diff --git a/modules/pademu/xboxoneusb/xboxoneusb.h b/modules/pademu/xboxoneusb/xboxoneusb.h new file mode 100644 index 000000000..7f6d89ec9 --- /dev/null +++ b/modules/pademu/xboxoneusb/xboxoneusb.h @@ -0,0 +1,171 @@ +#ifndef _DS3USB_H_ +#define _DS3USB_H_ + +#include "irx.h" +#include "usbd.h" +#include "../pademu.h" + +#define XBOX_VID 0x045E // Microsoft Corporation + +#define XBOX_ONE_PID1 0x02D1 // Microsoft X-Box One pad +#define XBOX_ONE_PID2 0x02DD // Microsoft X-Box One pad (Firmware 2015) +#define XBOX_ONE_PID3 0x02E3 // Microsoft X-Box One Elite pad +#define XBOX_ONE_PID4 0x02EA // Microsoft X-Box One S pad +#define XBOX_ONE_PID13 0x0B0A // Microsoft X-Box One Adaptive Controller + +// Unofficial controllers +#define XBOX_VID2 0x0738 // Mad Catz +#define XBOX_VID3 0x0E6F // Afterglow +#define XBOX_VID4 0x0F0D // HORIPAD ONE +#define XBOX_VID5 0x1532 // Razer +#define XBOX_VID6 0x24C6 // PowerA + +#define XBOX_ONE_PID5 0x4A01 // Mad Catz FightStick TE 2 - might have different mapping for triggers? +#define XBOX_ONE_PID6 0x0139 // Afterglow Prismatic Wired Controller +#define XBOX_ONE_PID7 0x0146 // Rock Candy Wired Controller for Xbox One +#define XBOX_ONE_PID8 0x0067 // HORIPAD ONE +#define XBOX_ONE_PID9 0x0A03 // Razer Wildcat +#define XBOX_ONE_PID10 0x541A // PowerA Xbox One Mini Wired Controller +#define XBOX_ONE_PID11 0x542A // Xbox ONE spectra +#define XBOX_ONE_PID12 0x543A // PowerA Xbox One wired controller + +#define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer + +typedef struct +{ + pad_device_t dev; + int usb_id; + int sema; + int cmd_sema; + int controlEndp; + int interruptEndp; + int outEndp; + int usb_resultcode; + UsbEndpointDescriptor *endin; + UsbEndpointDescriptor *endout; + u8 lrum; + u8 rrum; + u8 update_rum; + u8 data[18]; + u8 analog_btn; + u8 btn_delay; +} xboxoneusb_device; + +enum eHID { + // {{{ + /* HID event flag */ + HID_FLAG_STATUS_REPORTED = 0x01, + HID_FLAG_BUTTONS_CHANGED = 0x02, + HID_FLAG_EXTENSION = 0x04, + HID_FLAG_COMMAND_SUCCESS = 0x08, + + /* USB HID Transaction Header (THdr) */ + HID_USB_GET_REPORT_FEATURE = 0x03, + HID_USB_SET_REPORT_OUTPUT = 0x02, + HID_USB_DATA_INPUT = 0x01, + + /* Defines of various parameters for PS3 Game controller reports */ + PS3_F4_REPORT_ID = 0xF4, + PS3_F4_REPORT_LEN = 0x04, + + PS3_01_REPORT_ID = 0x01, + PS3_01_REPORT_LEN = 0x30, + + PS4_02_REPORT_ID = 0x02, + PS4_11_REPORT_ID = 0x11, + PS4_11_REPORT_LEN = 0x4D, + // }}} +}; + +typedef struct { + u8 ReportID; // 0x20 + u8 Zero; + u16 id; + + union + { + u8 ButtonStateL; // Main buttons Low + struct + { + u8 Sync : 1; + u8 Dummy1 : 1; + u8 Start : 1; + u8 Back : 1; + u8 A : 1; + u8 B : 1; + u8 X : 1; + u8 Y : 1; + }; + }; + union + { + u8 ButtonStateH; // Main buttons High + struct + { + u8 Up : 1; + u8 Down : 1; + u8 Left : 1; + u8 Right : 1; + u8 LB : 1; + u8 RB : 1; + u8 LS : 1; + u8 RS : 1; + }; + }; + union + { + u16 LeftTrigger; + struct + { + u8 LeftTriggerL; + u8 LeftTriggerH; + }; + }; + union + { + u16 RightTrigger; + struct + { + u8 RightTriggerL; + u8 RightTriggerH; + }; + }; + union + { + s16 LeftStickX; + struct + { + u8 LeftStickXL; + u8 LeftStickXH; + }; + }; + union + { + s16 LeftStickY; + struct + { + u8 LeftStickYL; + u8 LeftStickYH; + }; + }; + union + { + s16 RightStickX; + struct + { + u8 RightStickXL; + u8 RightStickXH; + }; + }; + union + { + s16 RightStickY; + struct + { + u8 RightStickYL; + u8 RightStickYH; + }; + }; +} __attribute__((packed)) xboxonereport_t; + +#endif diff --git a/src/dialogs.c b/src/dialogs.c index 7f478e95c..c95943e5e 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -559,9 +559,11 @@ struct UIItem diaPadEmuConfig[] = { {UI_BOOL, PADCFG_PADEMU_ENABLE, 1, 1, _STR_HINT_PADEMU_ENABLE, 0, 0, {.intvalue = {1, 1}}}, {UI_BREAK}, - {UI_LABEL, 0, 1, 1, -1, -50, 0, {.label = {NULL, _STR_PADEMU_MODE}}}, + {UI_LABEL, 0, 1, 1, -1, -45, 0, {.label = {NULL, _STR_PADEMU_MODULES}}}, {UI_SPACER}, - {UI_ENUM, PADCFG_PADEMU_MODE, 1, 1, _STR_HINT_PADEMU_MODE, 0, 0, {.intvalue = {1, 1}}}, + {UI_ENUM, PADCFG_PADEMU_MODULES_LIST, 1, 1, _STR_HINT_PADEMU_MODULES, 0, 0, {.intvalue = {1, 1}}}, + {UI_SPACER}, + {UI_BOOL, PADCFG_PADEMU_MODULES_SET, 1, 1, _STR_HINT_PADEMU_MODULES_SET, 0, 0, {.intvalue = {1, 1}}}, {UI_BREAK}, {UI_LABEL, 0, 1, 1, -1, -50, 0, {.label = {NULL, _STR_MTAP_ENABLE}}}, diff --git a/src/guigame.c b/src/guigame.c index 664527bb1..63ae5da0a 100644 --- a/src/guigame.c +++ b/src/guigame.c @@ -60,6 +60,7 @@ static union }; int raw; } PadMacroSettings; +static int PadEmuModules; #endif static char hexid[32]; @@ -576,8 +577,8 @@ static char *ver_to_str(char *str, u8 ma, u16 mi) static int guiGamePadEmuUpdater(int modified) { - int PadEmuMode, PadPort, PadEmuVib, PadEmuPort, PadEmuMtap, PadEmuMtapPort, PadEmuWorkaround; - static int oldPadPort; + int PadEmuModulesList, PadPort, PadEmuVib, PadEmuPort, PadEmuMtap, PadEmuMtapPort, PadEmuWorkaround, PadEmuModulesSet; + static int oldPadPort, oldPadEmuModulesList; int previousSource = gPadEmuSource; diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_SOURCE, &gPadEmuSource); @@ -594,7 +595,8 @@ static int guiGamePadEmuUpdater(int modified) } diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_ENABLE, &EnablePadEmu); - diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_MODE, &PadEmuMode); + diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_MODULES_LIST, &PadEmuModulesList); + diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_MODULES_SET, &PadEmuModulesSet); diaGetInt(diaPadEmuConfig, PADCFG_PADPORT, &PadPort); diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_PORT, &PadEmuPort); diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_VIB, &PadEmuVib); @@ -606,32 +608,23 @@ static int guiGamePadEmuUpdater(int modified) diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_MTAP, EnablePadEmu); diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_MTAP_PORT, PadEmuMtap); - diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_MODE, EnablePadEmu); + diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_MODULES_LIST, EnablePadEmu); + diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_MODULES_SET, EnablePadEmu); diaSetEnabled(diaPadEmuConfig, PADCFG_PADPORT, EnablePadEmu); diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_VIB, PadEmuPort & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC, (PadEmuMode == 1) & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC, (PadEmuMode == 1) & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAIR, (PadEmuMode == 1) & EnablePadEmu); - - diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC_STR, (PadEmuMode == 1) & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC_STR, (PadEmuMode == 1) & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAIR_STR, (PadEmuMode == 1) & EnablePadEmu); - - diaSetVisible(diaPadEmuConfig, PADCFG_BTINFO, (PadEmuMode == 1) & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, (PadEmuMode == 1) & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND_STR, (PadEmuMode == 1) & EnablePadEmu); + diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, EnablePadEmu); if (modified) { if (PadEmuMtap) { diaSetEnum(diaPadEmuConfig, PADCFG_PADPORT, PadEmuPorts_enums[PadEmuMtapPort]); diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_PORT, (PadPort == 0) & EnablePadEmu); - PadEmuSettings |= 0x00000E00; + PadEmuSettings |= 0x0000000E; } else { diaSetEnum(diaPadEmuConfig, PADCFG_PADPORT, PadEmuPorts_enums[0]); diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_PORT, EnablePadEmu); - PadEmuSettings &= 0xFFFF03FF; + PadEmuSettings &= 0xFFFFFF03; if (PadPort > 1) { PadPort = 0; diaSetInt(diaPadEmuConfig, PADCFG_PADPORT, PadPort); @@ -639,51 +632,58 @@ static int guiGamePadEmuUpdater(int modified) } if (PadPort != oldPadPort) { - diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_PORT, (PadEmuSettings >> (8 + PadPort)) & 1); - diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_VIB, (PadEmuSettings >> (16 + PadPort)) & 1); + diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_PORT, (PadEmuSettings >> (PadPort)) & 1); + diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_VIB, (PadEmuSettings >> (8 + PadPort)) & 1); oldPadPort = PadPort; } + + if (PadEmuModulesList != oldPadEmuModulesList) { + diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_MODULES_SET, (PadEmuModules >> PadEmuModulesList) & 1); + + oldPadEmuModulesList = PadEmuModulesList; + } } - PadEmuSettings |= PadEmuMode | (PadEmuPort << (8 + PadPort)) | (PadEmuVib << (16 + PadPort)) | (PadEmuMtap << 24) | ((PadEmuMtapPort - 1) << 25) | (PadEmuWorkaround << 26); - PadEmuSettings &= (~(PadEmuMode ? 0 : 1) & ~(!PadEmuPort << (8 + PadPort)) & ~(!PadEmuVib << (16 + PadPort)) & ~(!PadEmuMtap << 24) & ~(!(PadEmuMtapPort - 1) << 25) & ~(!PadEmuWorkaround << 26)); + PadEmuSettings |= (PadEmuPort << (PadPort)) | (PadEmuVib << (8 + PadPort)) | (PadEmuMtap << 16) | ((PadEmuMtapPort - 1) << 17) | (PadEmuWorkaround << 18); + PadEmuSettings &= (~(!PadEmuPort << (PadPort)) & ~(!PadEmuVib << (8 + PadPort)) & ~(!PadEmuMtap << 16) & ~(!(PadEmuMtapPort - 1) << 17) & ~(!PadEmuWorkaround << 18)); + + PadEmuModules |= PadEmuModulesSet << PadEmuModulesList; + PadEmuModules &= ~(!PadEmuModulesSet << PadEmuModulesList); - if (PadEmuMode == 1) { - if (ds34bt_get_status(0) & DS34BT_STATE_USB_CONFIGURED) { - if (dg_discon) { + if (ds34bt_get_status(0) & DS34BT_STATE_USB_CONFIGURED) { + if (dg_discon) { + dgmacset = 0; + dg_discon = 0; + } + if (!dgmacset) { + if (ds34bt_get_bdaddr(dg_mac)) { + dgmacset = 1; + diaSetLabel(diaPadEmuConfig, PADCFG_USBDG_MAC, bdaddr_to_str(dg_mac, dg_str)); + } else { dgmacset = 0; - dg_discon = 0; } - if (!dgmacset) { - if (ds34bt_get_bdaddr(dg_mac)) { - dgmacset = 1; - diaSetLabel(diaPadEmuConfig, PADCFG_USBDG_MAC, bdaddr_to_str(dg_mac, dg_str)); - } else { - dgmacset = 0; - } - } - } else { - dg_discon = 1; } + } else { + dg_discon = 1; + } - if (!dgmacset) { - diaSetLabel(diaPadEmuConfig, PADCFG_USBDG_MAC, _l(_STR_NOT_CONNECTED)); - } + if (!dgmacset) { + diaSetLabel(diaPadEmuConfig, PADCFG_USBDG_MAC, _l(_STR_NOT_CONNECTED)); + } - if (ds34usb_get_status(0) & DS34USB_STATE_RUNNING) { - if (!ds3macset) { - if (ds34usb_get_bdaddr(0, ds3_mac)) { - ds3macset = 1; - diaSetLabel(diaPadEmuConfig, PADCFG_PAD_MAC, bdaddr_to_str(ds3_mac, ds3_str)); - } else { - ds3macset = 0; - } + if (ds34usb_get_status(0) & DS34USB_STATE_RUNNING) { + if (!ds3macset) { + if (ds34usb_get_bdaddr(0, ds3_mac)) { + ds3macset = 1; + diaSetLabel(diaPadEmuConfig, PADCFG_PAD_MAC, bdaddr_to_str(ds3_mac, ds3_str)); + } else { + ds3macset = 0; } - } else { - diaSetLabel(diaPadEmuConfig, PADCFG_PAD_MAC, _l(_STR_NOT_CONNECTED)); - ds3macset = 0; } + } else { + diaSetLabel(diaPadEmuConfig, PADCFG_PAD_MAC, _l(_STR_NOT_CONNECTED)); + ds3macset = 0; } return 0; @@ -744,7 +744,7 @@ static int guiGamePadEmuInfoUpdater(int modified) void guiGameShowPadEmuConfig(int forceGlobal) { const char *settingsSource[] = {_l(_STR_GLOBAL_SETTINGS), _l(_STR_PERGAME_SETTINGS), NULL}; - const char *PadEmuModes[] = {_l(_STR_DS34USB_MODE), _l(_STR_DS34BT_MODE), NULL}; + const char *PadEmuModulesList[] = {"DualShock 3 USB", "DualShock 3 BT", "DualShock 4 USB", "DualShock 4 BT", "XBOX 360 USB", "XBOX ONE USB", "HID USB", NULL}; int PadEmuMtap, PadEmuMtapPort, i; @@ -755,31 +755,19 @@ void guiGameShowPadEmuConfig(int forceGlobal) guiGameLoadPadEmuConfig(NULL, configGetByType(CONFIG_GAME)); diaSetEnum(diaPadEmuConfig, PADCFG_PADEMU_SOURCE, settingsSource); - diaSetEnum(diaPadEmuConfig, PADCFG_PADEMU_MODE, PadEmuModes); + diaSetEnum(diaPadEmuConfig, PADCFG_PADEMU_MODULES_LIST, PadEmuModulesList); - PadEmuMtap = (PadEmuSettings >> 24) & 1; - PadEmuMtapPort = ((PadEmuSettings >> 25) & 1) + 1; + PadEmuMtap = (PadEmuSettings >> 16) & 1; + PadEmuMtapPort = ((PadEmuSettings >> 17) & 1) + 1; diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_PORT, EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC, PadEmuSettings & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC, PadEmuSettings & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAIR, PadEmuSettings & EnablePadEmu); - - diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC_STR, PadEmuSettings & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC_STR, PadEmuSettings & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PAIR_STR, PadEmuSettings & EnablePadEmu); - - diaSetVisible(diaPadEmuConfig, PADCFG_BTINFO, PadEmuSettings & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, PadEmuSettings & EnablePadEmu); - diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND_STR, PadEmuSettings & EnablePadEmu); - if (PadEmuMtap) { diaSetEnum(diaPadEmuConfig, PADCFG_PADPORT, PadEmuPorts_enums[PadEmuMtapPort]); - PadEmuSettings |= 0x00000E00; + PadEmuSettings |= 0x0000000E; } else { diaSetEnum(diaPadEmuConfig, PADCFG_PADPORT, PadEmuPorts_enums[0]); - PadEmuSettings &= 0xFFFF03FF; + PadEmuSettings &= 0xFFFFFF03; } int result = -1; @@ -906,6 +894,11 @@ static int guiGameSavePadEmuGameConfig(config_set_t *configSet, int result) result = configSetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, PadEmuSettings); else configRemoveKey(configSet, CONFIG_ITEM_PADEMUSETTINGS); + + if (PadEmuModules != 0) + result = configSetInt(configSet, CONFIG_ITEM_PADEMUMODULES, PadEmuModules); + else + configRemoveKey(configSet, CONFIG_ITEM_PADEMUMODULES); } return result; @@ -931,6 +924,7 @@ void guiGameSavePadEmuGlobalConfig(config_set_t *configGame) configSetInt(configGame, CONFIG_ITEM_ENABLEPADEMU, EnablePadEmu); configSetInt(configGame, CONFIG_ITEM_PADEMUSETTINGS, PadEmuSettings); + configSetInt(configGame, CONFIG_ITEM_PADEMUMODULES, PadEmuModules); } } @@ -1069,7 +1063,6 @@ int guiGameSaveConfig(config_set_t *configSet, item_list_t *support) } #ifdef PADEMU - /// PADEMU /// result = guiGameSavePadEmuGameConfig(configSet, result); guiGameSavePadEmuGlobalConfig(configGame); result = guiGameSavePadMacroGameConfig(configSet, result); @@ -1118,6 +1111,7 @@ void guiGameRemoveGlobalSettings(config_set_t *configGame) configRemoveKey(configGame, CONFIG_ITEM_ENABLEPADEMU); configRemoveKey(configGame, CONFIG_ITEM_PADEMUSETTINGS); configRemoveKey(configGame, CONFIG_ITEM_PADMACROSETTINGS); + configRemoveKey(configGame, CONFIG_ITEM_PADEMUMODULES); #endif saveConfig(CONFIG_GAME, 0); } @@ -1157,6 +1151,7 @@ void guiGameRemoveSettings(config_set_t *configSet) configRemoveKey(configSet, CONFIG_ITEM_PADEMUSETTINGS); configRemoveKey(configSet, CONFIG_ITEM_PADMACROSETTINGS); configRemoveKey(configSet, CONFIG_ITEM_PADMACROSOURCE); + configRemoveKey(configSet, CONFIG_ITEM_PADEMUMODULES); #endif // VMC configRemoveVMC(configSet, 0); @@ -1242,11 +1237,13 @@ static void guiGameLoadPadEmuConfig(config_set_t *configSet, config_set_t *confi { EnablePadEmu = 0; PadEmuSettings = 0; + PadEmuModules = 0; // set global settings. gPadEmuSource = 0; configGetInt(configGame, CONFIG_ITEM_ENABLEPADEMU, &EnablePadEmu); configGetInt(configGame, CONFIG_ITEM_PADEMUSETTINGS, &PadEmuSettings); + configGetInt(configGame, CONFIG_ITEM_PADEMUMODULES, &PadEmuModules); // override global with per-game settings if available and selected. if (!forceGlobalPadEmu) { @@ -1256,22 +1253,23 @@ static void guiGameLoadPadEmuConfig(config_set_t *configSet, config_set_t *confi EnablePadEmu = 0; if (!configGetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, &PadEmuSettings)) PadEmuSettings = 0; + if (!configGetInt(configSet, CONFIG_ITEM_PADEMUMODULES, &PadEmuModules)) + PadEmuModules = 0; } } // set gui settings. - int PadEmuMtap = (PadEmuSettings >> 24) & 1; - int PadEmuMtapPort = ((PadEmuSettings >> 25) & 1) + 1; + int PadEmuMtap = (PadEmuSettings >> 16) & 1; + int PadEmuMtapPort = ((PadEmuSettings >> 17) & 1) + 1; diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_SOURCE, gPadEmuSource); diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_ENABLE, EnablePadEmu); - diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_MODE, PadEmuSettings & 0xFF); diaSetInt(diaPadEmuConfig, PADCFG_PADPORT, 0); - diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_PORT, (PadEmuSettings >> 8) & 1); - diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_VIB, (PadEmuSettings >> 16) & 1); + diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_PORT, (PadEmuSettings)&1); + diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_VIB, (PadEmuSettings >> 8) & 1); diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_MTAP, PadEmuMtap); diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_MTAP_PORT, PadEmuMtapPort); - diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, ((PadEmuSettings >> 26) & 1)); + diaSetInt(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, ((PadEmuSettings >> 18) & 1)); } static void guiGameLoadPadMacroConfig(config_set_t *configSet, config_set_t *configGame) diff --git a/src/supportbase.c b/src/supportbase.c index 462607e6a..ab2a9e2fb 100644 --- a/src/supportbase.c +++ b/src/supportbase.c @@ -643,13 +643,16 @@ int sbPrepare(base_game_info_t *game, config_set_t *configSet, int size_cdvdman, gPadEmuSettings = 0; gPadMacroSource = 0; gPadMacroSettings = 0; + gPadEmuModules = 0; if (configGetInt(configSet, CONFIG_ITEM_PADEMUSOURCE, &gPadEmuSource)) { configGetInt(configSet, CONFIG_ITEM_ENABLEPADEMU, &gEnablePadEmu); configGetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, &gPadEmuSettings); + configGetInt(configSet, CONFIG_ITEM_PADEMUMODULES, &gPadEmuModules); } else { configGetInt(configGame, CONFIG_ITEM_ENABLEPADEMU, &gEnablePadEmu); configGetInt(configGame, CONFIG_ITEM_PADEMUSETTINGS, &gPadEmuSettings); + configGetInt(configGame, CONFIG_ITEM_PADEMUMODULES, &gPadEmuModules); } if (configGetInt(configSet, CONFIG_ITEM_PADMACROSOURCE, &gPadMacroSource)) { diff --git a/src/system.c b/src/system.c index ddf06352b..7a2ef5e52 100644 --- a/src/system.c +++ b/src/system.c @@ -522,13 +522,47 @@ static unsigned int sendIrxKernelRAM(const char *startup, const char *mode_str, } #ifdef PADEMU + int btstack_loaded = 0; if (gEnablePadEmu) { - if (gPadEmuSettings & 0xFF) { - irxptr_tab[modcount].info = size_bt_pademu_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_PADEMU); - irxptr_tab[modcount++].ptr = (void *)&bt_pademu_irx; - } else { - irxptr_tab[modcount].info = size_usb_pademu_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_PADEMU); - irxptr_tab[modcount++].ptr = (void *)&usb_pademu_irx; + irxptr_tab[modcount].info = size_pademu_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_PADEMU); + irxptr_tab[modcount++].ptr = (void *)&pademu_irx; + if (gPadEmuModules & (1 << 0)) { + irxptr_tab[modcount].info = size_ds3usb_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_DS3USB); + irxptr_tab[modcount++].ptr = (void *)&ds3usb_irx; + } + if (gPadEmuModules & (1 << 1)) { + if (!btstack_loaded) { + irxptr_tab[modcount].info = size_btstack_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_BTSTACK); + irxptr_tab[modcount++].ptr = (void *)&btstack_irx; + btstack_loaded = 1; + } + irxptr_tab[modcount].info = size_ds3bt_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_DS3BT); + irxptr_tab[modcount++].ptr = (void *)&ds3bt_irx; + } + if (gPadEmuModules & (1 << 2)) { + irxptr_tab[modcount].info = size_ds4usb_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_DS4USB); + irxptr_tab[modcount++].ptr = (void *)&ds4usb_irx; + } + if (gPadEmuModules & (1 << 3)) { + if (!btstack_loaded) { + irxptr_tab[modcount].info = size_btstack_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_BTSTACK); + irxptr_tab[modcount++].ptr = (void *)&btstack_irx; + btstack_loaded = 1; + } + irxptr_tab[modcount].info = size_ds4bt_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_DS4BT); + irxptr_tab[modcount++].ptr = (void *)&ds4bt_irx; + } + if (gPadEmuModules & (1 << 4)) { + irxptr_tab[modcount].info = size_xbox360usb_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_XBOX360USB); + irxptr_tab[modcount++].ptr = (void *)&xbox360usb_irx; + } + if (gPadEmuModules & (1 << 5)) { + irxptr_tab[modcount].info = size_xboxoneusb_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_XBOXONEUSB); + irxptr_tab[modcount++].ptr = (void *)&xboxoneusb_irx; + } + if (gPadEmuModules & (1 << 6)) { + irxptr_tab[modcount].info = size_hidusb_irx | SET_OPL_MOD_ID(OPL_MODULE_ID_HIDUSB); + irxptr_tab[modcount++].ptr = (void *)&hidusb_irx; } } #endif @@ -817,8 +851,8 @@ void sysLaunchLoaderElf(const char *filename, const char *mode_str, int size_cdv sprintf(KernelConfig, "%u %u", (unsigned int)eeloadCopy, (unsigned int)initUserMemory); #ifdef PADEMU -#define PADEMU_SPECIFIER " %d %u %u" -#define PADEMU_ARGUMENT , gEnablePadEmu, (unsigned int)(gPadEmuSettings >> 8), (unsigned int)(gPadMacroSettings) +#define PADEMU_SPECIFIER " %d %u %u %u" +#define PADEMU_ARGUMENT , gEnablePadEmu, (unsigned int)(gPadEmuSettings >> 8), (unsigned int)(gPadMacroSettings), (unsigned int)gPadEmuModules #else #define PADEMU_SPECIFIER #define PADEMU_ARGUMENT From 52ec95a277fbccf6110764d57542eefd29d03548 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 12:08:20 -0300 Subject: [PATCH 03/37] Fixed the screwed analog inputs in the xbox360usb module --- modules/pademu/xbox360usb/xbox360usb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/pademu/xbox360usb/xbox360usb.c b/modules/pademu/xbox360usb/xbox360usb.c index 4072ed3eb..d05f71f37 100644 --- a/modules/pademu/xbox360usb/xbox360usb.c +++ b/modules/pademu/xbox360usb/xbox360usb.c @@ -186,10 +186,10 @@ static void readReport(u8 *data, int pad) xbox360dev[pad].data[0] = ~(report->Back | report->LS << 1 | report->RS << 2 | report->Start << 3 | report->Up << 4 | report->Right << 5 | report->Down << 6 | report->Left << 7); xbox360dev[pad].data[1] = ~((report->LeftTrigger != 0) | (report->RightTrigger != 0) << 1 | report->LB << 2 | report->RB << 3 | report->Y << 4 | report->B << 5 | report->A << 6 | report->X << 7); - xbox360dev[pad].data[2] = report->RightStickXH; //rx - xbox360dev[pad].data[3] = report->RightStickYH; //ry - xbox360dev[pad].data[4] = report->LeftStickXH; //lx - xbox360dev[pad].data[5] = report->LeftStickYH; //ly + xbox360dev[pad].data[2] = report->RightStickXH + 128; //rx + xbox360dev[pad].data[3] = ~(report->RightStickYH + 128); //ry + xbox360dev[pad].data[4] = report->LeftStickXH + 128; //lx + xbox360dev[pad].data[5] = ~(report->LeftStickYH + 128); //ly xbox360dev[pad].data[6] = report->Right * 255; //right xbox360dev[pad].data[7] = report->Left * 255; //left From a81912fdbd49fb50e59ac4d926906cdb2a88d7ff Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 14:07:41 -0300 Subject: [PATCH 04/37] Added compatibility list. --- COMPATIBILITY.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 COMPATIBILITY.md diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md new file mode 100644 index 000000000..91f0bd7e0 --- /dev/null +++ b/COMPATIBILITY.md @@ -0,0 +1,5 @@ +Ape Escape 2 - Tested with X360 pad - works +Serious Sam Next Encounter - Tested with X360 pad - works +SpongeBob Battle for Bikini Bottom - Tested with X360 pad - works +Timesplitters 2 - X360 pad - works +Ratchet and Clank - X360 pad - works From cc43437fc47f1f4def15a21d447ac9c09697e42b Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 14:19:05 -0300 Subject: [PATCH 05/37] Deleted current compatibilty list for poor formatting. Will make a better one later. --- COMPATIBILITY.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 COMPATIBILITY.md diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md deleted file mode 100644 index 91f0bd7e0..000000000 --- a/COMPATIBILITY.md +++ /dev/null @@ -1,5 +0,0 @@ -Ape Escape 2 - Tested with X360 pad - works -Serious Sam Next Encounter - Tested with X360 pad - works -SpongeBob Battle for Bikini Bottom - Tested with X360 pad - works -Timesplitters 2 - X360 pad - works -Ratchet and Clank - X360 pad - works From 7f87f8aca060379faee1972817547c0543d783e0 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 14:35:27 -0300 Subject: [PATCH 06/37] Added a better compatibility list. --- COMPATIBILITY.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 COMPATIBILITY.md diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md new file mode 100644 index 000000000..0b80b947b --- /dev/null +++ b/COMPATIBILITY.md @@ -0,0 +1,12 @@ +| Game tested | Module(s) tested | Status | Notes | +|--------------------------------------------------|------------------------|---------|-------| +| Ape Escape 2 | xbox360usb, xboxoneusb | Perfect | | +| Serious Sam: Next Encounter | xbox360usb, xboxoneusb | Perfect | | +| Contra: Shattered Soldier | xboxoneusb | Perfect | | +| SpongeBob Squarepants - Battle for Bikini Bottom | xbox360usb | Perfect | | +| Timesplitters 2 | xbox360usb | Perfect | | +| Kingdom Hearts 2 Final Mix | xbox360usb | Perfect | | +| Crash Bandicoot - Wrath of Cortex | xboxoneusb, xbox360usb | Perfect | | +| Ratchet and Clank | xbox360usb | Perfect | | + +Feel free to add your own test entries. From db7f2a4b3456809a86b638d0a7eabf37dff60416 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 17:07:39 -0300 Subject: [PATCH 07/37] Compatibility list updated. Crazy Taxi confirmed to work --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 0b80b947b..4261e09fa 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -8,5 +8,6 @@ | Kingdom Hearts 2 Final Mix | xbox360usb | Perfect | | | Crash Bandicoot - Wrath of Cortex | xboxoneusb, xbox360usb | Perfect | | | Ratchet and Clank | xbox360usb | Perfect | | +| Crazy Taxi | xbox360usb | Perfect | | Feel free to add your own test entries. From ebf5017a1cb57f7cf1b52a43a445d4aff1e15bac Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 17:28:53 -0300 Subject: [PATCH 08/37] Megaman X Collection confirmed to work with PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 4261e09fa..3e896756e 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -9,5 +9,6 @@ | Crash Bandicoot - Wrath of Cortex | xboxoneusb, xbox360usb | Perfect | | | Ratchet and Clank | xbox360usb | Perfect | | | Crazy Taxi | xbox360usb | Perfect | | +| Megaman X Collection | xbox360usb | Perfect | | Feel free to add your own test entries. From f45088c5839f8c0bb33414f317fe8ddd4d6e6d8e Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 17:57:37 -0300 Subject: [PATCH 09/37] Klonoa 2 works with PADEMU but it will infinite load sometimes. --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 3e896756e..9f6efc913 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -10,5 +10,6 @@ | Ratchet and Clank | xbox360usb | Perfect | | | Crazy Taxi | xbox360usb | Perfect | | | Megaman X Collection | xbox360usb | Perfect | | +| Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| Feel free to add your own test entries. From 32af27361a984e62d697b17b526df8d7751d4391 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 18:12:01 -0300 Subject: [PATCH 10/37] Jak and Daxter doesn't work with PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 9f6efc913..b9bdfecf7 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -11,5 +11,6 @@ | Crazy Taxi | xbox360usb | Perfect | | | Megaman X Collection | xbox360usb | Perfect | | | Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| +| Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | All Jak games need Unhook Syscalls to work, thus making PADEMU non-functional by default | Feel free to add your own test entries. From 17235cb1f1b4b3737c76d7e15614fdbe8669c0c2 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 18:15:28 -0300 Subject: [PATCH 11/37] Update COMPATIBILITY.md --- COMPATIBILITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index b9bdfecf7..4900cc742 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -11,6 +11,6 @@ | Crazy Taxi | xbox360usb | Perfect | | | Megaman X Collection | xbox360usb | Perfect | | | Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| -| Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | All Jak games need Unhook Syscalls to work, thus making PADEMU non-functional by default | +| Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Needs Unhook Syscalls to work, thus making PADEMU non-functional by default | Feel free to add your own test entries. From fb580558f5e4ed0206010004dd62bbb3d09e3c98 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Sat, 19 Sep 2020 18:30:10 -0300 Subject: [PATCH 12/37] Update COMPATIBILITY.md --- COMPATIBILITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 4900cc742..7e19ab9d0 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -11,6 +11,6 @@ | Crazy Taxi | xbox360usb | Perfect | | | Megaman X Collection | xbox360usb | Perfect | | | Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| -| Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Needs Unhook Syscalls to work, thus making PADEMU non-functional by default | +| Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Gets stuck on copyright screen | Feel free to add your own test entries. From 8104443a799cb43f9bc68ae80141cf699e5ee873 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Wed, 23 Sep 2020 16:09:30 -0300 Subject: [PATCH 13/37] Nights Into Dreams confirmed to work with Xbox PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 7e19ab9d0..46596f9a4 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -12,5 +12,6 @@ | Megaman X Collection | xbox360usb | Perfect | | | Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| | Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Gets stuck on copyright screen | +| Nights Into Dreams | xbox360usb | Perfect | | Feel free to add your own test entries. From dc6596206070099b019a72b3e8deee53e6a7ab5d Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Wed, 23 Sep 2020 19:45:52 -0300 Subject: [PATCH 14/37] Alien Hominid works with Xbox PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 46596f9a4..3849a8670 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -13,5 +13,6 @@ | Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| | Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Gets stuck on copyright screen | | Nights Into Dreams | xbox360usb | Perfect | | +| Alien Hominid | xbox360usb | Perfect | | Feel free to add your own test entries. From b52c341e8e9fa6b4fe7d33ab6c5857905f6d034b Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 00:39:26 -0300 Subject: [PATCH 15/37] 3 more games confirmed to work with Xbox PADEMU --- COMPATIBILITY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 3849a8670..67999ae82 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -14,5 +14,8 @@ | Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Gets stuck on copyright screen | | Nights Into Dreams | xbox360usb | Perfect | | | Alien Hominid | xbox360usb | Perfect | | +| God of War II | xbox360usb | Perfect | | +| Tak and the Power of Juju | xbox360usb | Perfect | | +| Wipeout Fusion | xbox360usb | Perfect | | Feel free to add your own test entries. From 10ca0d7ed0e3e52f859495a26f6268c636670b89 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 00:50:22 -0300 Subject: [PATCH 16/37] RaC 2 confirmed to work with Xbox PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 67999ae82..d89170bf9 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -17,5 +17,6 @@ | God of War II | xbox360usb | Perfect | | | Tak and the Power of Juju | xbox360usb | Perfect | | | Wipeout Fusion | xbox360usb | Perfect | | +| Ratchet and Clank - Going Commando | xbox360usb | Perfect | | Feel free to add your own test entries. From cbe0ca14473d284fd58fc9313bd99f336b914756 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 00:53:47 -0300 Subject: [PATCH 17/37] Added some info --- COMPATIBILITY.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index d89170bf9..b89b430dc 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -19,4 +19,11 @@ | Wipeout Fusion | xbox360usb | Perfect | | | Ratchet and Clank - Going Commando | xbox360usb | Perfect | | +Perfect - No problems whatsoever +Works - Playable with some issues +Borked - Non-functional + +Keep in mind that multiplayer with 2 Xbox controllers doesn't work properly right now. + Feel free to add your own test entries. + From 8de0446f5ab1466c032439161be76a4e9d74f9cc Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 00:54:03 -0300 Subject: [PATCH 18/37] Update COMPATIBILITY.md --- COMPATIBILITY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index b89b430dc..e9ab00b3e 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -20,7 +20,9 @@ | Ratchet and Clank - Going Commando | xbox360usb | Perfect | | Perfect - No problems whatsoever + Works - Playable with some issues + Borked - Non-functional Keep in mind that multiplayer with 2 Xbox controllers doesn't work properly right now. From d6e8a90ec5471bf57cb76e4c20292d07069519e5 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 01:07:28 -0300 Subject: [PATCH 19/37] Red Faction confirmed to work with Xbox PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index e9ab00b3e..1a53613fc 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -18,6 +18,7 @@ | Tak and the Power of Juju | xbox360usb | Perfect | | | Wipeout Fusion | xbox360usb | Perfect | | | Ratchet and Clank - Going Commando | xbox360usb | Perfect | | +| Red Faction | xbox360usb | Perfect | | Perfect - No problems whatsoever From c7715e6b091a31cb57171ad16d271e7b063af58d Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 16:28:01 -0300 Subject: [PATCH 20/37] THPS4 works with Xbox PADEMU. --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 1a53613fc..bd66c53cd 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -19,6 +19,7 @@ | Wipeout Fusion | xbox360usb | Perfect | | | Ratchet and Clank - Going Commando | xbox360usb | Perfect | | | Red Faction | xbox360usb | Perfect | | +| Tony Hawk's Pro Skater 4 | xbox360usb | Perfect | | Perfect - No problems whatsoever From 7541275608f59669aac8dbbc8d783d777a7a3912 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 16:33:51 -0300 Subject: [PATCH 21/37] Warriors Orochi 2 works with Xbox PADEMU. --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index bd66c53cd..22893445a 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -20,6 +20,7 @@ | Ratchet and Clank - Going Commando | xbox360usb | Perfect | | | Red Faction | xbox360usb | Perfect | | | Tony Hawk's Pro Skater 4 | xbox360usb | Perfect | | +| Warriors Orochi 2 | xbox360usb | Perfect | | Perfect - No problems whatsoever From 9c93c20a724daf75d4a9aeb1f9a8a35ba51ded4c Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 16:58:00 -0300 Subject: [PATCH 22/37] Burnout 2 works with Xbox PADEMU. --- COMPATIBILITY.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 22893445a..28593f119 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -21,6 +21,7 @@ | Red Faction | xbox360usb | Perfect | | | Tony Hawk's Pro Skater 4 | xbox360usb | Perfect | | | Warriors Orochi 2 | xbox360usb | Perfect | | +| Burnout 2 | xbox360usb | Perfect | | Perfect - No problems whatsoever @@ -30,5 +31,7 @@ Borked - Non-functional Keep in mind that multiplayer with 2 Xbox controllers doesn't work properly right now. -Feel free to add your own test entries. +Also, vibration doesn't work either. + +Feel free to add your own test entries via a pull request. From 3deae19e50aa1c236f45e0c7e2af3e83fe2e4648 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 17:16:44 -0300 Subject: [PATCH 23/37] Sonic Mega Collection Plus works with Xbox PADEMU. --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 28593f119..2f3c94234 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -22,6 +22,7 @@ | Tony Hawk's Pro Skater 4 | xbox360usb | Perfect | | | Warriors Orochi 2 | xbox360usb | Perfect | | | Burnout 2 | xbox360usb | Perfect | | +| Sonic Mega Collection Plus | xbox360usb | Perfect | | Perfect - No problems whatsoever From 29c8f504949a649068901ce2e5d4f5dafd99192c Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Mon, 5 Oct 2020 21:30:12 -0300 Subject: [PATCH 24/37] Jak II confirmed to work with Xbox PADEMU --- COMPATIBILITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 2f3c94234..c486a6621 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -23,6 +23,7 @@ | Warriors Orochi 2 | xbox360usb | Perfect | | | Burnout 2 | xbox360usb | Perfect | | | Sonic Mega Collection Plus | xbox360usb | Perfect | | +| Jak II | xbox360usb | Perfect | | Perfect - No problems whatsoever From e10b56f391156ee82d47d8a3d725cb1054879b62 Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Wed, 21 Oct 2020 16:26:14 -0300 Subject: [PATCH 25/37] Added devices to compatibility list. --- COMPATIBILITY.md | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index c486a6621..639127c3b 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -1,35 +1,35 @@ -| Game tested | Module(s) tested | Status | Notes | -|--------------------------------------------------|------------------------|---------|-------| -| Ape Escape 2 | xbox360usb, xboxoneusb | Perfect | | -| Serious Sam: Next Encounter | xbox360usb, xboxoneusb | Perfect | | -| Contra: Shattered Soldier | xboxoneusb | Perfect | | -| SpongeBob Squarepants - Battle for Bikini Bottom | xbox360usb | Perfect | | -| Timesplitters 2 | xbox360usb | Perfect | | -| Kingdom Hearts 2 Final Mix | xbox360usb | Perfect | | -| Crash Bandicoot - Wrath of Cortex | xboxoneusb, xbox360usb | Perfect | | -| Ratchet and Clank | xbox360usb | Perfect | | -| Crazy Taxi | xbox360usb | Perfect | | -| Megaman X Collection | xbox360usb | Perfect | | -| Klonoa 2 - Lunatea's Veil | xbox360usb | Works | Game will sometimes infinite load| -| Jak and Daxter - The Precursor Legacy | xbox360usb | Borked | Gets stuck on copyright screen | -| Nights Into Dreams | xbox360usb | Perfect | | -| Alien Hominid | xbox360usb | Perfect | | -| God of War II | xbox360usb | Perfect | | -| Tak and the Power of Juju | xbox360usb | Perfect | | -| Wipeout Fusion | xbox360usb | Perfect | | -| Ratchet and Clank - Going Commando | xbox360usb | Perfect | | -| Red Faction | xbox360usb | Perfect | | -| Tony Hawk's Pro Skater 4 | xbox360usb | Perfect | | -| Warriors Orochi 2 | xbox360usb | Perfect | | -| Burnout 2 | xbox360usb | Perfect | | -| Sonic Mega Collection Plus | xbox360usb | Perfect | | -| Jak II | xbox360usb | Perfect | | +| Game tested | Device | Module(s) tested | Status | Notes | +|-------------------------------------------------|-|------------------------|---------|-------| +| Ape Escape 2 | HDD | xbox360usb, xboxoneusb | Perfect | | +| Serious Sam: Next Encounter | HDD | xbox360usb, xboxoneusb | Perfect | | +| Contra: Shattered Soldier | HDD | xboxoneusb | Perfect | | +| SpongeBob Squarepants - Battle for Bikini Bottom| HDD | xbox360usb | Perfect | | +| Timesplitters 2 | HDD | xbox360usb | Perfect | | +| Kingdom Hearts 2 Final Mix | HDD | xbox360usb | Perfect | | +| Crash Bandicoot - Wrath of Cortex | HDD | xboxoneusb, xbox360usb | Perfect | | +| Ratchet and Clank | HDD | xbox360usb | Perfect | | +| Crazy Taxi | HDD | xbox360usb | Perfect | | +| Megaman X Collection | HDD | xbox360usb | Perfect | | +| Klonoa 2 - Lunatea's Veil | HDD | xbox360usb | Works | Game will sometimes infinite load| +| Jak and Daxter - The Precursor Legacy | HDD | xbox360usb | Borked | Gets stuck on copyright screen | +| Nights Into Dreams | HDD | xbox360usb | Perfect | | +| Alien Hominid | HDD | xbox360usb | Perfect | | +| God of War II | HDD | xbox360usb | Perfect | | +| Tak and the Power of Juju | HDD | xbox360usb | Perfect | | +| Wipeout Fusion | HDD | xbox360usb | Perfect | | +| Ratchet and Clank - Going Commando | HDD | xbox360usb | Perfect | | +| Red Faction | HDD | xbox360usb | Perfect | | +| Tony Hawk's Pro Skater 4 | HDD | xbox360usb | Perfect | | +| Warriors Orochi 2 | HDD | xbox360usb | Perfect | | +| Burnout 2 | HDD | xbox360usb | Perfect | | +| Sonic Mega Collection Plus | HDD | xbox360usb | Perfect | | +| Jak II | HDD | xbox360usb | Perfect | | -Perfect - No problems whatsoever +__Perfect__ - No problems whatsoever -Works - Playable with some issues +__Works__ - Playable with some issues -Borked - Non-functional +__Borked__ - Non-functional Keep in mind that multiplayer with 2 Xbox controllers doesn't work properly right now. From 3f901c6698f75e0db6c72bbcb98c8b030928e4df Mon Sep 17 00:00:00 2001 From: RoloDeOvo Date: Wed, 21 Oct 2020 16:39:27 -0300 Subject: [PATCH 26/37] Delete compatibility list from master branch --- COMPATIBILITY.md | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 COMPATIBILITY.md diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md deleted file mode 100644 index 639127c3b..000000000 --- a/COMPATIBILITY.md +++ /dev/null @@ -1,39 +0,0 @@ -| Game tested | Device | Module(s) tested | Status | Notes | -|-------------------------------------------------|-|------------------------|---------|-------| -| Ape Escape 2 | HDD | xbox360usb, xboxoneusb | Perfect | | -| Serious Sam: Next Encounter | HDD | xbox360usb, xboxoneusb | Perfect | | -| Contra: Shattered Soldier | HDD | xboxoneusb | Perfect | | -| SpongeBob Squarepants - Battle for Bikini Bottom| HDD | xbox360usb | Perfect | | -| Timesplitters 2 | HDD | xbox360usb | Perfect | | -| Kingdom Hearts 2 Final Mix | HDD | xbox360usb | Perfect | | -| Crash Bandicoot - Wrath of Cortex | HDD | xboxoneusb, xbox360usb | Perfect | | -| Ratchet and Clank | HDD | xbox360usb | Perfect | | -| Crazy Taxi | HDD | xbox360usb | Perfect | | -| Megaman X Collection | HDD | xbox360usb | Perfect | | -| Klonoa 2 - Lunatea's Veil | HDD | xbox360usb | Works | Game will sometimes infinite load| -| Jak and Daxter - The Precursor Legacy | HDD | xbox360usb | Borked | Gets stuck on copyright screen | -| Nights Into Dreams | HDD | xbox360usb | Perfect | | -| Alien Hominid | HDD | xbox360usb | Perfect | | -| God of War II | HDD | xbox360usb | Perfect | | -| Tak and the Power of Juju | HDD | xbox360usb | Perfect | | -| Wipeout Fusion | HDD | xbox360usb | Perfect | | -| Ratchet and Clank - Going Commando | HDD | xbox360usb | Perfect | | -| Red Faction | HDD | xbox360usb | Perfect | | -| Tony Hawk's Pro Skater 4 | HDD | xbox360usb | Perfect | | -| Warriors Orochi 2 | HDD | xbox360usb | Perfect | | -| Burnout 2 | HDD | xbox360usb | Perfect | | -| Sonic Mega Collection Plus | HDD | xbox360usb | Perfect | | -| Jak II | HDD | xbox360usb | Perfect | | - -__Perfect__ - No problems whatsoever - -__Works__ - Playable with some issues - -__Borked__ - Non-functional - -Keep in mind that multiplayer with 2 Xbox controllers doesn't work properly right now. - -Also, vibration doesn't work either. - -Feel free to add your own test entries via a pull request. - From 1ec6e0912fa18a813ead5d8463c0b761007cd142 Mon Sep 17 00:00:00 2001 From: belek666 Date: Fri, 23 Oct 2020 19:27:44 +0200 Subject: [PATCH 27/37] clang format --- modules/pademu/btstack/btstack.c | 4 +-- modules/pademu/btstack/btstack.h | 28 ++++++++--------- modules/pademu/ds3bt/ds3bt.c | 20 ++++++------ modules/pademu/ds3bt/ds3bt.h | 17 +++++++---- modules/pademu/ds3usb/ds3usb.c | 28 ++++++++--------- modules/pademu/ds3usb/ds3usb.h | 8 +++-- modules/pademu/ds4bt/ds4bt.c | 14 ++++----- modules/pademu/ds4bt/ds4bt.h | 3 +- modules/pademu/ds4usb/ds4usb.c | 42 +++++++++++++------------- modules/pademu/ds4usb/ds4usb.h | 7 +++-- modules/pademu/hidusb/hidusb.c | 16 +++++----- modules/pademu/pademu.c | 3 +- modules/pademu/xbox360usb/xbox360usb.c | 32 ++++++++++---------- modules/pademu/xbox360usb/xbox360usb.h | 3 +- modules/pademu/xboxoneusb/xboxoneusb.c | 22 +++++++------- modules/pademu/xboxoneusb/xboxoneusb.h | 13 ++++---- 16 files changed, 136 insertions(+), 124 deletions(-) diff --git a/modules/pademu/btstack/btstack.c b/modules/pademu/btstack/btstack.c index ef22d29c3..0eef308df 100644 --- a/modules/pademu/btstack/btstack.c +++ b/modules/pademu/btstack/btstack.c @@ -148,7 +148,7 @@ static int bt_disconnect(int devId) if (bt_adp.devId != -1) { - disconnect_all(); + disconnect_all(); if (bt_adp.interruptEndp >= 0) UsbCloseEndpoint(bt_adp.interruptEndp); @@ -165,7 +165,7 @@ static int bt_disconnect(int devId) bt_adp.outEndp = -1; bt_adp.controlEndp = -1; - dev_init(); + dev_init(); SignalSema(bt_adp.hid_sema); } diff --git a/modules/pademu/btstack/btstack.h b/modules/pademu/btstack/btstack.h index cce9742b8..047ff5978 100644 --- a/modules/pademu/btstack/btstack.h +++ b/modules/pademu/btstack/btstack.h @@ -1,9 +1,9 @@ #ifndef _BTSTACK_H_ #define _BTSTACK_H_ -#define USB_CLASS_WIRELESS_CONTROLLER 0xE0 -#define USB_SUBCLASS_RF_CONTROLLER 0x01 -#define USB_PROTOCOL_BLUETOOTH_PROG 0x01 +#define USB_CLASS_WIRELESS_CONTROLLER 0xE0 +#define USB_SUBCLASS_RF_CONTROLLER 0x01 +#define USB_PROTOCOL_BLUETOOTH_PROG 0x01 #define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer @@ -88,24 +88,24 @@ enum eHCI { HCI_OGF_INFO_PARAM = (0x04 << 2), // OGF: Informational Parameters /* HCI OpCode Command Field (OCF) */ - HCI_OCF_DISCONNECT = 0x06, // OGF = 0x01 + HCI_OCF_DISCONNECT = 0x06, // OGF = 0x01 HCI_OCF_ACCEPT_CONNECTION = 0x09, // OGF = 0x01 HCI_OCF_REJECT_CONNECTION = 0x0A, // OGF = 0x01 HCI_OCF_CHANGE_CONNECTION_TYPE = 0x0F, // OGF = 0x01 - HCI_OCF_REMOTE_NAME = 0x19, // OGF = 0x01 + HCI_OCF_REMOTE_NAME = 0x19, // OGF = 0x01 HCI_OCF_LINK_KEY_REQUEST_REPLY = 0x0B, // OGF = 0x01 - - HCI_OCF_RESET = 0x03, // OGF = 0x03 - HCI_OCF_WRITE_ACCEPT_TIMEOUT = 0x16, // OGF = 0x03 - HCI_OCF_WRITE_SCAN_ENABLE = 0x1A, // OGF = 0x03 - - HCI_OCF_READ_BDADDR = 0x09, // OGF = 0x04 + + HCI_OCF_RESET = 0x03, // OGF = 0x03 + HCI_OCF_WRITE_ACCEPT_TIMEOUT = 0x16, // OGF = 0x03 + HCI_OCF_WRITE_SCAN_ENABLE = 0x1A, // OGF = 0x03 + + HCI_OCF_READ_BDADDR = 0x09, // OGF = 0x04 /* HCI events managed */ HCI_EVENT_CONNECT_COMPLETE = 0x03, HCI_EVENT_CONNECT_REQUEST = 0x04, HCI_EVENT_DISCONN_COMPLETE = 0x05, - HCI_EVENT_AUTHENTICATION_COMPLETE= 0x06, + HCI_EVENT_AUTHENTICATION_COMPLETE = 0x06, HCI_EVENT_REMOTE_NAME_COMPLETE = 0x07, HCI_EVENT_ENCRYPTION_CHANGE = 0x08, HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE = 0x0B, @@ -142,7 +142,7 @@ enum eL2CAP { /* Bluetooth L2CAP PSM */ L2CAP_PSM_SDP = 0x01, L2CAP_PSM_CTRL = 0x11, // HID_Control - L2CAP_PSM_INTR = 0x13, // HID_Interrupt + L2CAP_PSM_INTR = 0x13, // HID_Interrupt /* Bluetooth L2CAP states for L2CAP_task() */ L2CAP_DOWN_STATE = 0, @@ -178,7 +178,7 @@ enum eL2CAP { L2CAP_CMD_DISCONNECT_REQUEST = 0x06, L2CAP_CMD_DISCONNECT_RESPONSE = 0x07, -/* HCI ACL Data Packet + /* HCI ACL Data Packet * * buf[0] buf[1] buf[2] buf[3] * 0 4 8 11 12 16 24 31 MSB diff --git a/modules/pademu/ds3bt/ds3bt.c b/modules/pademu/ds3bt/ds3bt.c index 4640cb61d..213427be7 100644 --- a/modules/pademu/ds3bt/ds3bt.c +++ b/modules/pademu/ds3bt/ds3bt.c @@ -55,8 +55,8 @@ static u8 press_emu = 0; int ds3bt_connect(bt_paddata_t *data, u8 *str, int size) { DPRINTF("BS3BT: %s \n", str); //PLAYSTATION(R)3 Controller - - if (strncmp(str, "PLAYSTATION(R)3 Controller", 26) != 0) { + + if (strncmp(str, "PLAYSTATION(R)3 Controller", 26) != 0) { return 0; } @@ -76,8 +76,8 @@ void ds3bt_init(bt_paddata_t *data, int id) btstack_hid_command(&ds3btdrv, init_buf, PS3_F4_REPORT_LEN + 2, data->id); - data->id = id; - data->led[0] = led_patterns[id][1]; + data->id = id; + data->led[0] = led_patterns[id][1]; data->led[1] = 0; DelayThread(CMD_DELAY); ds3bt_rumble(data); @@ -105,7 +105,7 @@ void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes) if (bytes == 21 && !press_emu) press_emu = 1; - if (press_emu) { //needs emulating pressure buttons + if (press_emu) { //needs emulating pressure buttons data->data[6] = report->Right * 255; //right data->data[7] = report->Left * 255; //left data->data[8] = report->Up * 255; //up @@ -139,7 +139,7 @@ void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes) data->data[17] = report->PressureR2; //R2 } - if (report->PSButtonState) { //display battery level + if (report->PSButtonState) { //display battery level if (report->Select && (data->btn_delay == MAX_DELAY)) { //PS + SELECT if (data->analog_btn < 2) //unlocked mode data->analog_btn = !data->analog_btn; @@ -165,7 +165,7 @@ void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes) else data->led[1] = 0; - if (data->btn_delay > 0) { + if (data->btn_delay > 0) { data->update_rum = 1; } } @@ -177,7 +177,7 @@ void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes) void ds3bt_rumble(bt_paddata_t *data) { - u8 led_buf[PS3_01_REPORT_LEN + 2]; + u8 led_buf[PS3_01_REPORT_LEN + 2]; mips_memset(led_buf, 0, sizeof(led_buf)); mips_memcpy(led_buf + 2, output_01_report, sizeof(output_01_report)); @@ -195,9 +195,9 @@ void ds3bt_rumble(bt_paddata_t *data) data->rrum = 0; } - led_buf[3] = 0xFE; //rt + led_buf[3] = 0xFE; //rt led_buf[4] = data->rrum; //rp - led_buf[5] = 0xFE; //lt + led_buf[5] = 0xFE; //lt led_buf[6] = data->lrum; //lp led_buf[11] = data->led[0] & 0x7F; //LED Conf diff --git a/modules/pademu/ds3bt/ds3bt.h b/modules/pademu/ds3bt/ds3bt.h index 52441df28..bb27de303 100644 --- a/modules/pademu/ds3bt/ds3bt.h +++ b/modules/pademu/ds3bt/ds3bt.h @@ -31,12 +31,15 @@ enum eHID { // }}} }; -typedef struct { +typedef struct +{ u8 ReportID; u8 Zero; - union { + union + { u8 ButtonStateL; // Main buttons Low - struct { + struct + { u8 Select : 1; u8 L3 : 1; u8 R3 : 1; @@ -47,9 +50,11 @@ typedef struct { u8 Left : 1; }; }; - union { - u8 ButtonStateH; // Main buttons High - struct { + union + { + u8 ButtonStateH; // Main buttons High + struct + { u8 L2 : 1; u8 R2 : 1; u8 L1 : 1; diff --git a/modules/pademu/ds3usb/ds3usb.c b/modules/pademu/ds3usb/ds3usb.c index dc5bbbfb2..e8bc0d20c 100644 --- a/modules/pademu/ds3usb/ds3usb.c +++ b/modules/pademu/ds3usb/ds3usb.c @@ -13,7 +13,7 @@ #define DPRINTF(x...) #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) -#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define MAX_PADS 4 @@ -155,14 +155,14 @@ int usb_disconnect(int devId) static void usb_release(int pad) { PollSema(ds3dev[pad].sema); - + if (ds3dev[pad].interruptEndp >= 0) UsbCloseEndpoint(ds3dev[pad].interruptEndp); ds3dev[pad].controlEndp = -1; ds3dev[pad].interruptEndp = -1; ds3dev[pad].usb_id = -1; - + SignalSema(ds3dev[pad].sema); } @@ -275,14 +275,14 @@ static void readReport(u8 *data, int pad) static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) { PollSema(ds3dev[pad].cmd_sema); - + mips_memset(usb_buf, 0, sizeof(usb_buf)); mips_memcpy(usb_buf, output_01_report, sizeof(output_01_report)); - usb_buf[1] = 0xFE; //rt - usb_buf[2] = rrum; //rp - usb_buf[3] = 0xFE; //lt - usb_buf[4] = lrum; //lp + usb_buf[1] = 0xFE; //rt + usb_buf[2] = rrum; //rp + usb_buf[3] = 0xFE; //lt + usb_buf[4] = lrum; //lp usb_buf[9] = led[0] & 0x7F; //LED Conf if (led[1]) { //means charging, so blink @@ -291,8 +291,8 @@ static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) usb_buf[23] = 0x32; usb_buf[28] = 0x32; } - - ds3dev[pad].oldled[0] = led[0]; + + ds3dev[pad].oldled[0] = led[0]; ds3dev[pad].oldled[1] = led[1]; return UsbControlTransfer(ds3dev[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_SET_REPORT_OUTPUT << 8) | 0x01, 0, sizeof(output_01_report), usb_buf, usb_cmd_cb, (void *)pad); @@ -321,11 +321,11 @@ static void TransferWait(int sema) void ds3usb_set_rumble(u8 lrum, u8 rrum, int port) { WaitSema(ds3dev[port].sema); - + ds3dev[port].update_rum = 1; ds3dev[port].lrum = lrum; ds3dev[port].rrum = rrum; - + SignalSema(ds3dev[port].sema); } @@ -351,7 +351,7 @@ int ds3usb_get_data(u8 *dst, int size, int port) mips_memcpy(dst, ds3dev[port].data, size); ret = ds3dev[port].analog_btn & 1; - + if (ds3dev[port].update_rum) { ret = LEDRumble(ds3dev[port].oldled, ds3dev[port].lrum, ds3dev[port].rrum, port); if (ret == USB_RC_OK) @@ -389,7 +389,7 @@ int _start(int argc, char *argv[]) for (pad = 0; pad < MAX_PADS; pad++) { ds3dev[pad].usb_id = -1; - ds3dev[pad].dev.id = -1; + ds3dev[pad].dev.id = -1; ds3dev[pad].dev.pad_get_data = ds3usb_get_data; ds3dev[pad].dev.pad_set_rumble = ds3usb_set_rumble; ds3dev[pad].dev.pad_set_mode = ds3usb_set_mode; diff --git a/modules/pademu/ds3usb/ds3usb.h b/modules/pademu/ds3usb/ds3usb.h index 99911e3d6..1cdf650a8 100644 --- a/modules/pademu/ds3usb/ds3usb.h +++ b/modules/pademu/ds3usb/ds3usb.h @@ -15,6 +15,8 @@ #define MODEL_PS2 3 #define SONY_VID 0x054C // Sony Corporation #define DS3_PID 0x0268 // PS3 Controller +#define SONY_VID 0x054C // Sony Corporation +#define DS3_PID 0x0268 // PS3 Controller #define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer @@ -70,10 +72,12 @@ enum eHID { // }}} }; -typedef struct { +typedef struct +{ u8 ReportID; u8 Zero; - union { + union + { u8 ButtonStateL; // Main buttons Low struct { u8 Select : 1; diff --git a/modules/pademu/ds4bt/ds4bt.c b/modules/pademu/ds4bt/ds4bt.c index 3ad27a01c..f8cd5bab9 100644 --- a/modules/pademu/ds4bt/ds4bt.c +++ b/modules/pademu/ds4bt/ds4bt.c @@ -33,7 +33,7 @@ bt_paddrv_t ds4btdrv = {0x0070, 0x0071, ds4bt_connect, ds4bt_init, ds4bt_read_re int ds4bt_connect(bt_paddata_t *data, u8 *str, int size) { - if (strncmp(str, "Wireless Controller", 19) == 0) { + if (strncmp(str, "Wireless Controller", 19) == 0) { DPRINTF("BS4BT: %s \n", str); return 1; } @@ -49,7 +49,7 @@ void ds4bt_init(bt_paddata_t *data, int id) btstack_hid_command(&ds4btdrv, init_buf, 2, data->id); - data->id = id; + data->id = id; data->led[0] = rgbled_patterns[id][1][0]; data->led[1] = rgbled_patterns[id][1][1]; data->led[2] = rgbled_patterns[id][1][2]; @@ -141,15 +141,15 @@ void ds4bt_read_report(bt_paddata_t *data, u8 *in, int bytes) data->data[16] = report->PressureL2; //L2 data->data[17] = report->PressureR2; //R2 - if (report->PSButton) { //display battery level + if (report->PSButton) { //display battery level if (report->Share && (data->btn_delay == MAX_DELAY)) { //PS + SELECT - if (data->analog_btn < 2) //unlocked mode + if (data->analog_btn < 2) //unlocked mode data->analog_btn = !data->analog_btn; data->led[0] = rgbled_patterns[data->id][(data->analog_btn & 1)][0]; data->led[1] = rgbled_patterns[data->id][(data->analog_btn & 1)][1]; data->led[2] = rgbled_patterns[data->id][(data->analog_btn & 1)][2]; - data->btn_delay = 1; + data->btn_delay = 1; } else { data->led[0] = report->Battery; data->led[1] = 0; @@ -172,7 +172,7 @@ void ds4bt_read_report(bt_paddata_t *data, u8 *in, int bytes) else data->led[3] = 0; - if (data->btn_delay > 0) { + if (data->btn_delay > 0) { data->update_rum = 1; } } @@ -199,7 +199,7 @@ void ds4bt_rumble(bt_paddata_t *data) led_buf[10] = data->led[1]; //g led_buf[11] = data->led[2]; //b - if (data->led[3]) { //means charging, so blink + if (data->led[3]) { //means charging, so blink led_buf[12] = 0x80; // Time to flash bright (255 = 2.5 seconds) led_buf[13] = 0x80; // Time to flash dark (255 = 2.5 seconds) } diff --git a/modules/pademu/ds4bt/ds4bt.h b/modules/pademu/ds4bt/ds4bt.h index 22873b3c3..7a116285d 100644 --- a/modules/pademu/ds4bt/ds4bt.h +++ b/modules/pademu/ds4bt/ds4bt.h @@ -31,7 +31,8 @@ enum eHID { // }}} }; -typedef struct { +typedef struct +{ u8 ReportID; u8 Unk; u8 ReportID2; diff --git a/modules/pademu/ds4usb/ds4usb.c b/modules/pademu/ds4usb/ds4usb.c index fde017739..a4c1441c6 100644 --- a/modules/pademu/ds4usb/ds4usb.c +++ b/modules/pademu/ds4usb/ds4usb.c @@ -13,7 +13,7 @@ #define DPRINTF(x...) #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) -#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define MAX_PADS 4 @@ -89,12 +89,12 @@ int usb_connect(int devId) config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); epCount = interface->bNumEndpoints - 1; - - if (device->idProduct == DS4_PID_SLIM) { - epCount = 20; // ds4 v2 returns interface->bNumEndpoints as 0 - } - - endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + + if (device->idProduct == DS4_PID_SLIM) { + epCount = 20; // ds4 v2 returns interface->bNumEndpoints as 0 + } + + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); do { if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { @@ -145,18 +145,18 @@ int usb_disconnect(int devId) static void usb_release(int pad) { PollSema(ds4dev[pad].sema); - + if (ds4dev[pad].interruptEndp >= 0) UsbCloseEndpoint(ds4dev[pad].interruptEndp); - if (ds4dev[pad].outEndp >= 0) + if (ds4dev[pad].outEndp >= 0) UsbCloseEndpoint(ds4dev[pad].outEndp); ds4dev[pad].controlEndp = -1; ds4dev[pad].interruptEndp = -1; ds4dev[pad].outEndp = -1; ds4dev[pad].usb_id = -1; - + SignalSema(ds4dev[pad].sema); } @@ -187,7 +187,7 @@ static void usb_config_set(int result, int count, void *arg) PollSema(ds4dev[pad].sema); - pademu_connect(&ds4dev[pad].dev); + pademu_connect(&ds4dev[pad].dev); led[0] = rgbled_patterns[ds4dev[pad].dev.id][1][0]; led[1] = rgbled_patterns[ds4dev[pad].dev.id][1][1]; @@ -282,7 +282,7 @@ static void readReport(u8 *data, int pad) ds4dev[pad].data[16] = report->PressureL2; //L2 ds4dev[pad].data[17] = report->PressureR2; //R2 - if (report->PSButton) { //display battery level + if (report->PSButton) { //display battery level if (report->Share && (ds4dev[pad].btn_delay == MAX_DELAY)) { //PS + Share if (ds4dev[pad].analog_btn < 2) //unlocked mode ds4dev[pad].analog_btn = !ds4dev[pad].analog_btn; @@ -313,7 +313,7 @@ static void readReport(u8 *data, int pad) else ds4dev[pad].oldled[3] = 0; - if (ds4dev[pad].btn_delay > 0) { + if (ds4dev[pad].btn_delay > 0) { ds4dev[pad].update_rum = 1; } } @@ -322,7 +322,7 @@ static void readReport(u8 *data, int pad) static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) { PollSema(ds4dev[pad].cmd_sema); - + usb_buf[0] = 0x05; usb_buf[1] = 0xFF; @@ -339,12 +339,12 @@ static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) usb_buf[10] = 0x80; // Time to flash dark (255 = 2.5 seconds) } - ds4dev[pad].oldled[0] = led[0]; + ds4dev[pad].oldled[0] = led[0]; ds4dev[pad].oldled[1] = led[1]; ds4dev[pad].oldled[2] = led[2]; ds4dev[pad].oldled[3] = led[3]; - - return UsbInterruptTransfer(ds4dev[pad].outEndp, usb_buf, 32, usb_cmd_cb, (void *)pad); + + return UsbInterruptTransfer(ds4dev[pad].outEndp, usb_buf, 32, usb_cmd_cb, (void *)pad); } static unsigned int timeout(void *arg) @@ -370,11 +370,11 @@ static void TransferWait(int sema) void ds4usb_set_rumble(u8 lrum, u8 rrum, int port) { WaitSema(ds4dev[port].sema); - + ds4dev[port].update_rum = 1; ds4dev[port].lrum = lrum; ds4dev[port].rrum = rrum; - + SignalSema(ds4dev[port].sema); } @@ -400,7 +400,7 @@ int ds4usb_get_data(u8 *dst, int size, int port) mips_memcpy(dst, ds4dev[port].data, size); ret = ds4dev[port].analog_btn & 1; - + if (ds4dev[port].update_rum) { ret = LEDRumble(ds4dev[port].oldled, ds4dev[port].lrum, ds4dev[port].rrum, port); if (ret == USB_RC_OK) @@ -438,7 +438,7 @@ int _start(int argc, char *argv[]) for (pad = 0; pad < MAX_PADS; pad++) { ds4dev[pad].usb_id = -1; - ds4dev[pad].dev.id = -1; + ds4dev[pad].dev.id = -1; ds4dev[pad].dev.pad_get_data = ds4usb_get_data; ds4dev[pad].dev.pad_set_rumble = ds4usb_set_rumble; ds4dev[pad].dev.pad_set_mode = ds4usb_set_mode; diff --git a/modules/pademu/ds4usb/ds4usb.h b/modules/pademu/ds4usb/ds4usb.h index 334d9e4aa..b9f0272d7 100644 --- a/modules/pademu/ds4usb/ds4usb.h +++ b/modules/pademu/ds4usb/ds4usb.h @@ -4,8 +4,8 @@ #include "irx.h" #include "../pademu.h" -#define SONY_VID 0x054C // Sony Corporation -#define DS4_PID 0x05C4 // PS4 Controller +#define SONY_VID 0x054C // Sony Corporation +#define DS4_PID 0x05C4 // PS4 Controller #define DS4_PID_SLIM 0x09CC // PS4 Slim Controller #define MAX_BUFFER_SIZE 64 // Size of general purpose data buffer @@ -55,7 +55,8 @@ enum eHID { // }}} }; -typedef struct { +typedef struct +{ u8 ReportID; u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid diff --git a/modules/pademu/hidusb/hidusb.c b/modules/pademu/hidusb/hidusb.c index e9b7a8770..0356c95c5 100644 --- a/modules/pademu/hidusb/hidusb.c +++ b/modules/pademu/hidusb/hidusb.c @@ -199,11 +199,11 @@ static void read_report(u8 *data, int pad) hiddev[pad].data[2 + i] = data[1 + (hiddev[pad].rep.axes.start_pos + hiddev[pad].rep.axes.size * i) / 8]; } - count = 16; + count = 16; bits = 8; if (hiddev[pad].rep.hats.count > 0) { pos = hiddev[pad].rep.hats.start_pos; - switch ((data[1 + pos / 8] >> pos % 8) & 0x0F) { + switch ((data[1 + pos / 8] >> pos % 8) & 0x0F) { case 0: up = 1; break; @@ -239,11 +239,11 @@ static void read_report(u8 *data, int pad) right = 0; break; } - hiddev[pad].data[0] = ~(up << 4 | right << 5 | down << 6 | left << 7 | 0x0F); + hiddev[pad].data[0] = ~(up << 4 | right << 5 | down << 6 | left << 7 | 0x0F); hiddev[pad].data[6] = right * 255; //right - hiddev[pad].data[7] = left * 255; //left - hiddev[pad].data[8] = up * 255; //up - hiddev[pad].data[9] = down * 255; //down + hiddev[pad].data[7] = left * 255; //left + hiddev[pad].data[8] = up * 255; //up + hiddev[pad].data[9] = down * 255; //down count = 12; bits = 4; @@ -265,10 +265,10 @@ static void read_report(u8 *data, int pad) } } - //(report->Share | report->L3 << 1 | report->R3 << 2 | report->Option << 3 | up << 4 | right << 5 | down << 6 | left << 7); + //(report->Share | report->L3 << 1 | report->R3 << 2 | report->Option << 3 | up << 4 | right << 5 | down << 6 | left << 7); //(report->L2 | report->R2 << 1 | report->L1 << 2 | report->R1 << 3 | report->Triangle << 4 | report->Circle << 5 | report->Cross << 6 | report->Square << 7); - /* + /* hiddev[pad].data[10] = report->PressureTriangle; //triangle hiddev[pad].data[11] = report->PressureCircle; //circle hiddev[pad].data[12] = report->PressureCross; //cross diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index d4c8ce3bd..63179cb31 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -133,7 +133,6 @@ int _start(int argc, char *argv[]) void _exit(int mode) { - } int install_sio2hook() @@ -399,7 +398,7 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) { u8 i; - //DPRINTF("PADEMU: sio cmd %02x port %d\n", in[1], port); + //DPRINTF("PADEMU: sio cmd %02x port %d\n", in[1], port); mips_memset(out, 0x00, out_size); diff --git a/modules/pademu/xbox360usb/xbox360usb.c b/modules/pademu/xbox360usb/xbox360usb.c index d05f71f37..28b90a344 100644 --- a/modules/pademu/xbox360usb/xbox360usb.c +++ b/modules/pademu/xbox360usb/xbox360usb.c @@ -13,7 +13,7 @@ #define DPRINTF(x...) #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) -#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define MAX_PADS 4 @@ -47,7 +47,7 @@ int usb_probe(int devId) if ((device->idVendor == XBOX_VID || device->idVendor == MADCATZ_VID || device->idVendor == JOYTECH_VID || device->idVendor == GAMESTOP_VID) && (device->idProduct == XBOX_WIRED_PID || device->idProduct == MADCATZ_WIRED_PID || device->idProduct == GAMESTOP_WIRED_PID || - device->idProduct == AFTERGLOW_WIRED_PID || device->idProduct == JOYTECH_WIRED_PID)) + device->idProduct == AFTERGLOW_WIRED_PID || device->idProduct == JOYTECH_WIRED_PID)) return 1; return 0; @@ -83,7 +83,7 @@ int usb_connect(int devId) config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); epCount = interface->bNumEndpoints - 1; - endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); do { if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { @@ -130,14 +130,14 @@ int usb_disconnect(int devId) static void usb_release(int pad) { PollSema(xbox360dev[pad].sema); - + if (xbox360dev[pad].interruptEndp >= 0) UsbCloseEndpoint(xbox360dev[pad].interruptEndp); xbox360dev[pad].controlEndp = -1; xbox360dev[pad].interruptEndp = -1; xbox360dev[pad].usb_id = -1; - + SignalSema(xbox360dev[pad].sema); } @@ -174,7 +174,7 @@ static void usb_config_set(int result, int count, void *arg) LEDRumble(led, 0, 0, pad); SignalSema(xbox360dev[pad].sema); - pademu_connect(&xbox360dev[pad].dev); + pademu_connect(&xbox360dev[pad].dev); } #define MAX_DELAY 10 @@ -186,9 +186,9 @@ static void readReport(u8 *data, int pad) xbox360dev[pad].data[0] = ~(report->Back | report->LS << 1 | report->RS << 2 | report->Start << 3 | report->Up << 4 | report->Right << 5 | report->Down << 6 | report->Left << 7); xbox360dev[pad].data[1] = ~((report->LeftTrigger != 0) | (report->RightTrigger != 0) << 1 | report->LB << 2 | report->RB << 3 | report->Y << 4 | report->B << 5 | report->A << 6 | report->X << 7); - xbox360dev[pad].data[2] = report->RightStickXH + 128; //rx + xbox360dev[pad].data[2] = report->RightStickXH + 128; //rx xbox360dev[pad].data[3] = ~(report->RightStickYH + 128); //ry - xbox360dev[pad].data[4] = report->LeftStickXH + 128; //lx + xbox360dev[pad].data[4] = report->LeftStickXH + 128; //lx xbox360dev[pad].data[5] = ~(report->LeftStickYH + 128); //ly xbox360dev[pad].data[6] = report->Right * 255; //right @@ -206,7 +206,7 @@ static void readReport(u8 *data, int pad) xbox360dev[pad].data[16] = report->LeftTrigger; //L2 xbox360dev[pad].data[17] = report->RightTrigger; //R2 - if (report->XBOX) { //display battery level + if (report->XBOX) { //display battery level if (report->Back && (xbox360dev[pad].btn_delay == MAX_DELAY)) { //XBOX + BACK if (xbox360dev[pad].analog_btn < 2) //unlocked mode xbox360dev[pad].analog_btn = !xbox360dev[pad].analog_btn; @@ -233,7 +233,7 @@ static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) { int ret; PollSema(xbox360dev[pad].cmd_sema); - + usb_buf[0] = 0x00; usb_buf[1] = 0x08; usb_buf[2] = 0x00; @@ -251,10 +251,10 @@ static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) ret = UsbControlTransfer(xbox360dev[pad].controlEndp, REQ_USB_OUT, USB_REQ_SET_REPORT, (HID_USB_SET_REPORT_OUTPUT << 8) | 0x01, 0, 3, usb_buf, usb_cmd_cb, (void *)pad); } - xbox360dev[pad].oldled[0] = led[0]; + xbox360dev[pad].oldled[0] = led[0]; xbox360dev[pad].oldled[1] = led[1]; - return ret; + return ret; } static unsigned int timeout(void *arg) @@ -280,11 +280,11 @@ static void TransferWait(int sema) void xbox360usb_set_rumble(u8 lrum, u8 rrum, int port) { WaitSema(xbox360dev[port].sema); - + xbox360dev[port].update_rum = 1; xbox360dev[port].lrum = lrum; xbox360dev[port].rrum = rrum; - + SignalSema(xbox360dev[port].sema); } @@ -310,7 +310,7 @@ int xbox360usb_get_data(u8 *dst, int size, int port) mips_memcpy(dst, xbox360dev[port].data, size); ret = xbox360dev[port].analog_btn & 1; - + if (xbox360dev[port].update_rum) { ret = LEDRumble(xbox360dev[port].oldled, xbox360dev[port].lrum, xbox360dev[port].rrum, port); if (ret == USB_RC_OK) @@ -348,7 +348,7 @@ int _start(int argc, char *argv[]) for (pad = 0; pad < MAX_PADS; pad++) { xbox360dev[pad].usb_id = -1; - xbox360dev[pad].dev.id = -1; + xbox360dev[pad].dev.id = -1; xbox360dev[pad].dev.pad_get_data = xbox360usb_get_data; xbox360dev[pad].dev.pad_set_rumble = xbox360usb_set_rumble; xbox360dev[pad].dev.pad_set_mode = xbox360usb_set_mode; diff --git a/modules/pademu/xbox360usb/xbox360usb.h b/modules/pademu/xbox360usb/xbox360usb.h index b32412f9e..50ff796cc 100644 --- a/modules/pademu/xbox360usb/xbox360usb.h +++ b/modules/pademu/xbox360usb/xbox360usb.h @@ -64,7 +64,8 @@ enum eHID { // }}} }; -typedef struct { +typedef struct +{ u8 ReportID; u8 Length; //0x14 union diff --git a/modules/pademu/xboxoneusb/xboxoneusb.c b/modules/pademu/xboxoneusb/xboxoneusb.c index ac0581851..89c02e827 100644 --- a/modules/pademu/xboxoneusb/xboxoneusb.c +++ b/modules/pademu/xboxoneusb/xboxoneusb.c @@ -13,7 +13,7 @@ #define DPRINTF(x...) #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) -#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) +#define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define MAX_PADS 4 @@ -85,7 +85,7 @@ int usb_connect(int devId) config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); interface = (UsbInterfaceDescriptor *)((char *)config + config->bLength); epCount = interface->bNumEndpoints - 1; - endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); + endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); do { if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { @@ -138,18 +138,18 @@ int usb_disconnect(int devId) static void usb_release(int pad) { PollSema(xboxonedev[pad].sema); - + if (xboxonedev[pad].interruptEndp >= 0) UsbCloseEndpoint(xboxonedev[pad].interruptEndp); - if (xboxonedev[pad].outEndp >= 0) + if (xboxonedev[pad].outEndp >= 0) UsbCloseEndpoint(xboxonedev[pad].outEndp); xboxonedev[pad].controlEndp = -1; xboxonedev[pad].interruptEndp = -1; xboxonedev[pad].outEndp = -1; xboxonedev[pad].usb_id = -1; - + SignalSema(xboxonedev[pad].sema); } @@ -190,7 +190,7 @@ static void usb_config_set(int result, int count, void *arg) SignalSema(xboxonedev[pad].sema); - pademu_connect(&xboxonedev[pad].dev); + pademu_connect(&xboxonedev[pad].dev); } #define MAX_DELAY 10 @@ -227,7 +227,7 @@ static void readReport(u8 *data, int pad) static int Rumble(u8 lrum, u8 rrum, int pad) { PollSema(xboxonedev[pad].cmd_sema); - + usb_buf[0] = 0x09; usb_buf[1] = 0x00; usb_buf[2] = cmdcnt++; @@ -268,11 +268,11 @@ static void TransferWait(int sema) void xboxoneusb_set_rumble(u8 lrum, u8 rrum, int port) { WaitSema(xboxonedev[port].sema); - + xboxonedev[port].update_rum = 1; xboxonedev[port].lrum = lrum; xboxonedev[port].rrum = rrum; - + SignalSema(xboxonedev[port].sema); } @@ -300,7 +300,7 @@ int xboxoneusb_get_data(u8 *dst, int size, int port) mips_memcpy(dst, xboxonedev[port].data, size); ret = xboxonedev[port].analog_btn & 1; - + if (xboxonedev[port].update_rum) { ret = Rumble(xboxonedev[port].lrum, xboxonedev[port].rrum, port); if (ret == USB_RC_OK) { @@ -341,7 +341,7 @@ int _start(int argc, char *argv[]) for (pad = 0; pad < MAX_PADS; pad++) { xboxonedev[pad].usb_id = -1; - xboxonedev[pad].dev.id = -1; + xboxonedev[pad].dev.id = -1; xboxonedev[pad].dev.pad_get_data = xboxoneusb_get_data; xboxonedev[pad].dev.pad_set_rumble = xboxoneusb_set_rumble; xboxonedev[pad].dev.pad_set_mode = xboxoneusb_set_mode; diff --git a/modules/pademu/xboxoneusb/xboxoneusb.h b/modules/pademu/xboxoneusb/xboxoneusb.h index 7f6d89ec9..72c95b6b2 100644 --- a/modules/pademu/xboxoneusb/xboxoneusb.h +++ b/modules/pademu/xboxoneusb/xboxoneusb.h @@ -14,11 +14,11 @@ #define XBOX_ONE_PID13 0x0B0A // Microsoft X-Box One Adaptive Controller // Unofficial controllers -#define XBOX_VID2 0x0738 // Mad Catz -#define XBOX_VID3 0x0E6F // Afterglow -#define XBOX_VID4 0x0F0D // HORIPAD ONE -#define XBOX_VID5 0x1532 // Razer -#define XBOX_VID6 0x24C6 // PowerA +#define XBOX_VID2 0x0738 // Mad Catz +#define XBOX_VID3 0x0E6F // Afterglow +#define XBOX_VID4 0x0F0D // HORIPAD ONE +#define XBOX_VID5 0x1532 // Razer +#define XBOX_VID6 0x24C6 // PowerA #define XBOX_ONE_PID5 0x4A01 // Mad Catz FightStick TE 2 - might have different mapping for triggers? #define XBOX_ONE_PID6 0x0139 // Afterglow Prismatic Wired Controller @@ -77,7 +77,8 @@ enum eHID { // }}} }; -typedef struct { +typedef struct +{ u8 ReportID; // 0x20 u8 Zero; u16 id; From 61853631ea852d10462a8fa535f02b28d7e64b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 22 Jun 2023 22:35:19 -0300 Subject: [PATCH 28/37] first crude success on getting it compiling... --- ee_core/include/ee_core.h | 1 + ee_core/src/main.c | 1 + include/{ds34common.h => pademu_common.h} | 4 ++-- modules/ds34bt/iop/ds34bt.h | 2 +- modules/ds34usb/iop/ds34usb.h | 2 +- modules/pademu/btstack/Makefile | 4 +--- modules/pademu/ds34common.c | 2 +- modules/pademu/ds3bt/Makefile | 4 +--- modules/pademu/ds3usb/Makefile | 4 +--- modules/pademu/ds3usb/ds3usb.h | 2 +- modules/pademu/ds4bt/Makefile | 4 +--- modules/pademu/ds4usb/Makefile | 4 +--- modules/pademu/hidusb/Makefile | 4 +--- modules/pademu/imports.lst | 4 ++++ modules/pademu/pademu.c | 6 ++++-- modules/pademu/padmacro.h | 2 +- modules/pademu/xbox360usb/Makefile | 4 +--- modules/pademu/xboxoneusb/Makefile | 4 +--- src/guigame.c | 2 +- src/opl.c | 1 + 20 files changed, 27 insertions(+), 34 deletions(-) rename include/{ds34common.h => pademu_common.h} (99%) diff --git a/ee_core/include/ee_core.h b/ee_core/include/ee_core.h index 75fc186ce..e8ba808d0 100644 --- a/ee_core/include/ee_core.h +++ b/ee_core/include/ee_core.h @@ -87,6 +87,7 @@ extern int EnableCheatOp; extern int EnablePadEmuOp; extern int PadEmuSettings; extern int PadMacroSettings; +extern int PadEmuModules; #endif extern int EnableDebug; diff --git a/ee_core/src/main.c b/ee_core/src/main.c index cbb871caa..f49ee7b3d 100644 --- a/ee_core/src/main.c +++ b/ee_core/src/main.c @@ -37,6 +37,7 @@ int EnableCheatOp; int EnablePadEmuOp; int PadEmuSettings; int PadMacroSettings; +int PadEmuModules; #endif int EnableDebug; int *gCheatList; // Store hooks/codes addr+val pairs diff --git a/include/ds34common.h b/include/pademu_common.h similarity index 99% rename from include/ds34common.h rename to include/pademu_common.h index e5daa3cc9..b942ed864 100644 --- a/include/ds34common.h +++ b/include/pademu_common.h @@ -1,5 +1,5 @@ -#ifndef _DS34COMMON_H_ -#define _DS34COMMON_H_ +#ifndef _PADEMU_COMMON_ +#define _PADEMU_COMMON_ #include #define USB_CLASS_WIRELESS_CONTROLLER 0xE0 diff --git a/modules/ds34bt/iop/ds34bt.h b/modules/ds34bt/iop/ds34bt.h index 950198295..ee95862c2 100644 --- a/modules/ds34bt/iop/ds34bt.h +++ b/modules/ds34bt/iop/ds34bt.h @@ -3,7 +3,7 @@ #include "irx.h" -#include +#include #define DS3 0 #define DS4 1 diff --git a/modules/ds34usb/iop/ds34usb.h b/modules/ds34usb/iop/ds34usb.h index 68589c6de..10c01f0c1 100644 --- a/modules/ds34usb/iop/ds34usb.h +++ b/modules/ds34usb/iop/ds34usb.h @@ -3,7 +3,7 @@ #include "irx.h" -#include +#include #define DS3 0 #define DS4 1 diff --git a/modules/pademu/btstack/Makefile b/modules/pademu/btstack/Makefile index 751a40e93..863eae198 100644 --- a/modules/pademu/btstack/Makefile +++ b/modules/pademu/btstack/Makefile @@ -3,8 +3,6 @@ IOP_BIN = btstack.irx IOP_OBJS = btstack.o imports.o exports.o IOP_OBJS_DIR = obj.btstack/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal \ No newline at end of file diff --git a/modules/pademu/ds34common.c b/modules/pademu/ds34common.c index 2bbf9333b..f3e25b6f6 100644 --- a/modules/pademu/ds34common.c +++ b/modules/pademu/ds34common.c @@ -1,4 +1,4 @@ -#include "ds34common.h" +#include "pademu_common.h" #include "loadcore.h" #include "sysclib.h" diff --git a/modules/pademu/ds3bt/Makefile b/modules/pademu/ds3bt/Makefile index 7147be201..19e98c970 100644 --- a/modules/pademu/ds3bt/Makefile +++ b/modules/pademu/ds3bt/Makefile @@ -3,8 +3,6 @@ IOP_BIN = ds3bt.irx IOP_OBJS = ds3bt.o imports.o IOP_OBJS_DIR = obj.ds3bt/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal diff --git a/modules/pademu/ds3usb/Makefile b/modules/pademu/ds3usb/Makefile index 49b5ceb95..1a37b11b6 100644 --- a/modules/pademu/ds3usb/Makefile +++ b/modules/pademu/ds3usb/Makefile @@ -3,8 +3,6 @@ IOP_BIN = ds3usb.irx IOP_OBJS = ds3usb.o imports.o IOP_OBJS_DIR = obj.ds3usb/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal diff --git a/modules/pademu/ds3usb/ds3usb.h b/modules/pademu/ds3usb/ds3usb.h index 1cdf650a8..8b31e6aa7 100644 --- a/modules/pademu/ds3usb/ds3usb.h +++ b/modules/pademu/ds3usb/ds3usb.h @@ -4,7 +4,7 @@ #include "irx.h" #include "../pademu.h" -//#include +#include <../../../include/pademu_common.h> #define DS3 0 #define DS4 1 diff --git a/modules/pademu/ds4bt/Makefile b/modules/pademu/ds4bt/Makefile index 163fa6bca..cefb7cb3b 100644 --- a/modules/pademu/ds4bt/Makefile +++ b/modules/pademu/ds4bt/Makefile @@ -3,8 +3,6 @@ IOP_BIN = ds4bt.irx IOP_OBJS = ds4bt.o imports.o IOP_OBJS_DIR = obj.ds4bt/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal diff --git a/modules/pademu/ds4usb/Makefile b/modules/pademu/ds4usb/Makefile index 1b8f1980b..db60c4c7a 100644 --- a/modules/pademu/ds4usb/Makefile +++ b/modules/pademu/ds4usb/Makefile @@ -3,8 +3,6 @@ IOP_BIN = ds4usb.irx IOP_OBJS = ds4usb.o imports.o IOP_OBJS_DIR = obj.ds4usb/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal diff --git a/modules/pademu/hidusb/Makefile b/modules/pademu/hidusb/Makefile index a1de4238d..57bdd5dad 100644 --- a/modules/pademu/hidusb/Makefile +++ b/modules/pademu/hidusb/Makefile @@ -3,8 +3,6 @@ IOP_BIN = hidusb.irx IOP_OBJS = hidusb.o imports.o IOP_OBJS_DIR = obj.hidusb/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal diff --git a/modules/pademu/imports.lst b/modules/pademu/imports.lst index 114a009be..7e403fce9 100644 --- a/modules/pademu/imports.lst +++ b/modules/pademu/imports.lst @@ -13,6 +13,10 @@ I_PollSema I_iSignalSema thsemap_IMPORTS_end +stdio_IMPORTS_start +I_printf +stdio_IMPORTS_end + thbase_IMPORTS_start I_DelayThread I_SetAlarm diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index 63179cb31..99455c297 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -438,7 +438,8 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) case 0x42: // read data if (in[1] == 0x42) { if (pad[port].vibration) { // disable/enable vibration - PAD_SET_RUMBLE(in[pad[port].lrum], in[pad[port].rrum], port); + pad[port].dev->pad_set_rumble(in[pad[port].lrum], in[pad[port].rrum], pad[port].dev->id); + //PAD_SET_RUMBLE(in[pad[port].lrum], in[pad[port].rrum], port); } } @@ -476,7 +477,8 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) case 0x45: // query model and mode mips_memcpy(&out[3], &pademu_data[1], 6); out[5] = pad[port].mode; - out[3] = PAD_GET_MODEL(port); + /// TODO: Check if the next line is needed + // out[3] = PAD_GET_MODEL(port); break; case 0x46: // query act diff --git a/modules/pademu/padmacro.h b/modules/pademu/padmacro.h index 6f4f2d4af..d5e8def6d 100644 --- a/modules/pademu/padmacro.h +++ b/modules/pademu/padmacro.h @@ -3,7 +3,7 @@ #include "stdbool.h" #include "types.h" -#include "ds34common.h" +#include "pademu_common.h" enum PadMacroAxes { PadMacroAxisLX = 0, diff --git a/modules/pademu/xbox360usb/Makefile b/modules/pademu/xbox360usb/Makefile index 8eba8e8cf..0eea4d701 100644 --- a/modules/pademu/xbox360usb/Makefile +++ b/modules/pademu/xbox360usb/Makefile @@ -3,8 +3,6 @@ IOP_BIN = xbox360usb.irx IOP_OBJS = xbox360usb.o imports.o IOP_OBJS_DIR = obj.xbox360usb/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal diff --git a/modules/pademu/xboxoneusb/Makefile b/modules/pademu/xboxoneusb/Makefile index fa6c97469..c3a605dad 100644 --- a/modules/pademu/xboxoneusb/Makefile +++ b/modules/pademu/xboxoneusb/Makefile @@ -3,8 +3,6 @@ IOP_BIN = xboxoneusb.irx IOP_OBJS = xboxoneusb.o imports.o IOP_OBJS_DIR = obj.xboxoneusb/ -IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%) - IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s @@ -19,4 +17,4 @@ OBJ_DIR: mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include ../Rules.make +include $(PS2SDK)/samples/Makefile.iopglobal \ No newline at end of file diff --git a/src/guigame.c b/src/guigame.c index 63ae5da0a..60dc2c1bd 100644 --- a/src/guigame.c +++ b/src/guigame.c @@ -14,7 +14,7 @@ #include "include/cheatman.h" #include "include/system.h" #include "include/guigame.h" -#include "include/ds34common.h" +#include "include/pademu_common.h" #ifdef PADEMU #include diff --git a/src/opl.c b/src/opl.c index dfada6d34..32d55be44 100644 --- a/src/opl.c +++ b/src/opl.c @@ -170,6 +170,7 @@ char gDefaultBGMPath[128]; int gCheatSource; int gGSMSource; int gPadEmuSource; +int gPadEmuModules; int gFadeDelay; int toggleSfx; int showCfgPopup; From 5a742cd7839724fd6d850778194c045e44a4e80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Thu, 22 Jun 2023 23:11:18 -0300 Subject: [PATCH 29/37] rectify `IRX_ID`, printf and `MODNAME` macros --- modules/pademu/btstack/btstack.c | 53 +++++++++++++++----------- modules/pademu/ds3bt/ds3bt.c | 21 +++++++--- modules/pademu/ds3usb/ds3usb.c | 41 ++++++++++++-------- modules/pademu/ds4bt/ds4bt.c | 21 +++++++--- modules/pademu/ds4usb/ds4usb.c | 41 ++++++++++++-------- modules/pademu/hidusb/hidusb.c | 29 +++++++++----- modules/pademu/pademu.c | 35 ++++++++++------- modules/pademu/xbox360usb/xbox360usb.c | 37 +++++++++++------- modules/pademu/xboxoneusb/xboxoneusb.c | 41 ++++++++++++-------- 9 files changed, 206 insertions(+), 113 deletions(-) diff --git a/modules/pademu/btstack/btstack.c b/modules/pademu/btstack/btstack.c index 0eef308df..d76509181 100644 --- a/modules/pademu/btstack/btstack.c +++ b/modules/pademu/btstack/btstack.c @@ -16,15 +16,24 @@ #include "../sys_utils.h" #include "btstack.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + +#define MODNAME "btstack" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + static int bt_probe(int devId); static int bt_connect(int devId); static int bt_disconnect(int devId); static void bt_config_set(int result, int count, void *arg); -static UsbDriver bt_driver = {NULL, NULL, "btstack", bt_probe, bt_connect, bt_disconnect}; +static UsbDriver bt_driver = {NULL, NULL, MODNAME, bt_probe, bt_connect, bt_disconnect}; static bt_adapter_t bt_adp = {-1, -1, -1, -1, -1, -1}; static void dev_clear(int pad); @@ -37,16 +46,16 @@ static int bt_probe(int devId) UsbConfigDescriptor *config = NULL; UsbInterfaceDescriptor *intf = NULL; - DPRINTF("BTSTACK: probe: devId=%i\n", devId); + DPRINTF("probe: devId=%i\n", devId); if (bt_adp.devId != -1) { - DPRINTF("BTSTACK: Error - only one device allowed !\n"); + DPRINTF("Error - only one device allowed !\n"); return 0; } device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); if (device == NULL) { - DPRINTF("BTSTACK: Error - Couldn't get device descriptor\n"); + DPRINTF("Error - Couldn't get device descriptor\n"); return 0; } @@ -55,18 +64,18 @@ static int bt_probe(int devId) config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); if (config == NULL) { - DPRINTF("BTSTACK: Error - Couldn't get configuration descriptor\n"); + DPRINTF("Error - Couldn't get configuration descriptor\n"); return 0; } if ((config->bNumInterfaces < 1) || (config->wTotalLength < (sizeof(UsbConfigDescriptor) + sizeof(UsbInterfaceDescriptor)))) { - DPRINTF("BTSTACK: Error - No interfaces available\n"); + DPRINTF("Error - No interfaces available\n"); return 0; } intf = (UsbInterfaceDescriptor *)((char *)config + config->bLength); - DPRINTF("BTSTACK: bInterfaceClass %X bInterfaceSubClass %X bInterfaceProtocol %X\n", intf->bInterfaceClass, intf->bInterfaceSubClass, intf->bInterfaceProtocol); + DPRINTF("bInterfaceClass %X bInterfaceSubClass %X bInterfaceProtocol %X\n", intf->bInterfaceClass, intf->bInterfaceSubClass, intf->bInterfaceProtocol); if ((intf->bInterfaceClass != USB_CLASS_WIRELESS_CONTROLLER) || (intf->bInterfaceSubClass != USB_SUBCLASS_RF_CONTROLLER) || @@ -86,10 +95,10 @@ static int bt_connect(int devId) UsbInterfaceDescriptor *interface; UsbEndpointDescriptor *endpoint; - DPRINTF("BTSTACK: connect: devId=%i\n", devId); + DPRINTF("connect: devId=%i\n", devId); if (bt_adp.devId != -1) { - DPRINTF("BTSTACK: Error - only one device allowed !\n"); + DPRINTF("Error - only one device allowed !\n"); return 1; } @@ -105,7 +114,7 @@ static int bt_connect(int devId) epCount = interface->bNumEndpoints - 1; - DPRINTF("BTSTACK: Endpoint Count %d \n", epCount + 1); + DPRINTF("Endpoint Count %d \n", epCount + 1); endpoint = (UsbEndpointDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT); @@ -114,15 +123,15 @@ static int bt_connect(int devId) if (endpoint->bmAttributes == USB_ENDPOINT_XFER_BULK) { if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && bt_adp.outEndp < 0) { bt_adp.outEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("BTSTACK: register Output endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Output endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } else if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && bt_adp.inEndp < 0) { bt_adp.inEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("BTSTACK: register Input endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.inEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Input endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.inEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } else if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && bt_adp.interruptEndp < 0) { bt_adp.interruptEndp = UsbOpenEndpoint(devId, endpoint); - DPRINTF("BTSTACK: register Interrupt endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Interrupt endpoint id =%i addr=%02X packetSize=%i\n", bt_adp.interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } @@ -131,7 +140,7 @@ static int bt_connect(int devId) } while (epCount--); if (bt_adp.interruptEndp < 0 || bt_adp.inEndp < 0 || bt_adp.outEndp < 0) { - DPRINTF("BTSTACK: Error - connect failed: not enough endpoints! \n"); + DPRINTF("Error - connect failed: not enough endpoints! \n"); return -1; } @@ -144,7 +153,7 @@ static int bt_connect(int devId) static int bt_disconnect(int devId) { - DPRINTF("BTSTACK: disconnect: devId=%i\n", devId); + DPRINTF("disconnect: devId=%i\n", devId); if (bt_adp.devId != -1) { @@ -1036,7 +1045,7 @@ int btpad_get_data(u8 *dst, int size, int port) WaitSema(bt_adp.hid_sema); - //DPRINTF("BTSTACK: Get data\n"); + //DPRINTF("Get data\n"); mips_memcpy(dst, dev[port].data.data, size); ret = dev[port].data.analog_btn & 1; @@ -1049,7 +1058,7 @@ void btpad_set_rumble(u8 lrum, u8 rrum, int port) { WaitSema(bt_adp.hid_sema); - //DPRINTF("BTSTACK: Rumble\n"); + //DPRINTF("Rumble\n"); dev[port].data.update_rum = 1; dev[port].data.lrum = lrum; dev[port].data.rrum = rrum; @@ -1061,7 +1070,7 @@ void btpad_set_mode(int mode, int lock, int port) { WaitSema(bt_adp.hid_sema); - //DPRINTF("BTSTACK: Set mode\n"); + //DPRINTF("Set mode\n"); if (lock == 3) dev[port].data.analog_btn = 3; else @@ -1110,14 +1119,14 @@ int _start(int argc, char *argv[]) bt_adp.hid_sema = CreateMutex(IOP_MUTEX_UNLOCKED); if (bt_adp.hid_sema < 0) { - DPRINTF("BTSTACK: Failed to allocate semaphore.\n"); + DPRINTF("Failed to allocate semaphore.\n"); return MODULE_NO_RESIDENT_END; } ret = UsbRegisterDriver(&bt_driver); if (ret != USB_RC_OK) { - DPRINTF("BTSTACK: Error registering USB devices: %02X\n", ret); + DPRINTF("Error registering USB devices: %02X\n", ret); return MODULE_NO_RESIDENT_END; } diff --git a/modules/pademu/ds3bt/ds3bt.c b/modules/pademu/ds3bt/ds3bt.c index 213427be7..41aa25470 100644 --- a/modules/pademu/ds3bt/ds3bt.c +++ b/modules/pademu/ds3bt/ds3bt.c @@ -10,8 +10,19 @@ #include "../btstack/btstack.h" #include "ds3bt.h" -#define DPRINTF(x...) printf(x) -//#define DPRINTF(x...) + + +#define MODNAME "ds3bt" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + static u8 output_01_report[] = { @@ -54,7 +65,7 @@ static u8 press_emu = 0; int ds3bt_connect(bt_paddata_t *data, u8 *str, int size) { - DPRINTF("BS3BT: %s \n", str); //PLAYSTATION(R)3 Controller + DPRINTF("%s \n", str); //PLAYSTATION(R)3 Controller if (strncmp(str, "PLAYSTATION(R)3 Controller", 26) != 0) { return 0; @@ -170,8 +181,8 @@ void ds3bt_read_report(bt_paddata_t *data, u8 *in, int bytes) } } } else { - DPRINTF("BS3BT: Unmanaged Input Report: THDR 0x%02X ", in[8]); - DPRINTF("BS3BT: ID 0x%02X \n", in[9]); + DPRINTF("Unmanaged Input Report: THDR 0x%02X ", in[8]); + DPRINTF("ID 0x%02X \n", in[9]); } } diff --git a/modules/pademu/ds3usb/ds3usb.c b/modules/pademu/ds3usb/ds3usb.c index e8bc0d20c..cdebe62e7 100644 --- a/modules/pademu/ds3usb/ds3usb.c +++ b/modules/pademu/ds3usb/ds3usb.c @@ -9,8 +9,19 @@ #include "thsemap.h" #include "ds3usb.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + + +#define MODNAME "ds3usb" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) @@ -53,7 +64,7 @@ int usb_disconnect(int devId); static void usb_release(int pad); static void usb_config_set(int result, int count, void *arg); -UsbDriver usb_driver = {NULL, NULL, "ds3usb", usb_probe, usb_connect, usb_disconnect}; +UsbDriver usb_driver = {NULL, NULL, MODNAME, usb_probe, usb_connect, usb_disconnect}; static void readReport(u8 *data, int pad); static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); @@ -64,11 +75,11 @@ int usb_probe(int devId) { UsbDeviceDescriptor *device = NULL; - DPRINTF("DS3USB: probe: devId=%i\n", devId); + DPRINTF("probe: devId=%i\n", devId); device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); if (device == NULL) { - DPRINTF("DS3USB: Error - Couldn't get device descriptor\n"); + DPRINTF("Error - Couldn't get device descriptor\n"); return 0; } @@ -86,7 +97,7 @@ int usb_connect(int devId) UsbInterfaceDescriptor *interface; UsbEndpointDescriptor *endpoint; - DPRINTF("DS3USB: connect: devId=%i\n", devId); + DPRINTF("connect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (ds3dev[pad].usb_id == -1) @@ -94,7 +105,7 @@ int usb_connect(int devId) } if (pad >= MAX_PADS) { - DPRINTF("DS3USB: Error - only %d device allowed !\n", MAX_PADS); + DPRINTF("Error - only %d device allowed !\n", MAX_PADS); return 1; } @@ -114,7 +125,7 @@ int usb_connect(int devId) if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && ds3dev[pad].interruptEndp < 0) { ds3dev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("DS3USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", ds3dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Event endpoint id =%i addr=%02X packetSize=%i\n", ds3dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } @@ -137,7 +148,7 @@ int usb_disconnect(int devId) { u8 pad; - DPRINTF("DS3USB: disconnect: devId=%i\n", devId); + DPRINTF("disconnect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (ds3dev[pad].usb_id == devId) { @@ -170,7 +181,7 @@ static void usb_data_cb(int resultCode, int bytes, void *arg) { int pad = (int)arg; - //DPRINTF("DS3USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + //DPRINTF("usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); ds3dev[pad].usb_resultcode = resultCode; @@ -181,7 +192,7 @@ static void usb_cmd_cb(int resultCode, int bytes, void *arg) { int pad = (int)arg; - //DPRINTF("DS3USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + //DPRINTF("usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); SignalSema(ds3dev[pad].cmd_sema); } @@ -346,7 +357,7 @@ int ds3usb_get_data(u8 *dst, int size, int port) ds3dev[port].usb_resultcode = 1; } else { - DPRINTF("DS3USB: DS3USB_get_data usb transfer error %d\n", ret); + DPRINTF("DS3USB_get_data usb transfer error %d\n", ret); } mips_memcpy(dst, ds3dev[port].data, size); @@ -357,7 +368,7 @@ int ds3usb_get_data(u8 *dst, int size, int port) if (ret == USB_RC_OK) TransferWait(ds3dev[port].cmd_sema); else - DPRINTF("DS3USB: LEDRumble usb transfer error %d\n", ret); + DPRINTF("LEDRumble usb transfer error %d\n", ret); ds3dev[port].update_rum = 0; } @@ -415,13 +426,13 @@ int _start(int argc, char *argv[]) ds3dev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); if (ds3dev[pad].sema < 0 || ds3dev[pad].cmd_sema < 0) { - DPRINTF("DS3USB: Failed to allocate I/O semaphore.\n"); + DPRINTF("Failed to allocate I/O semaphore.\n"); return MODULE_NO_RESIDENT_END; } } if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { - DPRINTF("DS3USB: Error registering USB devices\n"); + DPRINTF("Error registering USB devices\n"); return MODULE_NO_RESIDENT_END; } diff --git a/modules/pademu/ds4bt/ds4bt.c b/modules/pademu/ds4bt/ds4bt.c index f8cd5bab9..a5b7433ba 100644 --- a/modules/pademu/ds4bt/ds4bt.c +++ b/modules/pademu/ds4bt/ds4bt.c @@ -10,8 +10,19 @@ #include "../btstack/btstack.h" #include "ds4bt.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + + +#define MODNAME "ds4bt" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + static u8 rgbled_patterns[][2][3] = { @@ -34,7 +45,7 @@ bt_paddrv_t ds4btdrv = {0x0070, 0x0071, ds4bt_connect, ds4bt_init, ds4bt_read_re int ds4bt_connect(bt_paddata_t *data, u8 *str, int size) { if (strncmp(str, "Wireless Controller", 19) == 0) { - DPRINTF("BS4BT: %s \n", str); + DPRINTF("%s \n", str); return 1; } return 0; @@ -177,8 +188,8 @@ void ds4bt_read_report(bt_paddata_t *data, u8 *in, int bytes) } } } else { - DPRINTF("BS4BT: Unmanaged Input Report: THDR 0x%02X ", in[8]); - DPRINTF("BS4BT: ID 0x%02X \n", in[9]); + DPRINTF("Unmanaged Input Report: THDR 0x%02X ", in[8]); + DPRINTF("ID 0x%02X \n", in[9]); } } diff --git a/modules/pademu/ds4usb/ds4usb.c b/modules/pademu/ds4usb/ds4usb.c index a4c1441c6..f3f991bab 100644 --- a/modules/pademu/ds4usb/ds4usb.c +++ b/modules/pademu/ds4usb/ds4usb.c @@ -9,8 +9,19 @@ #include "thsemap.h" #include "ds4usb.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + + +#define MODNAME "ds4usb" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) @@ -34,7 +45,7 @@ int usb_disconnect(int devId); static void usb_release(int pad); static void usb_config_set(int result, int count, void *arg); -UsbDriver usb_driver = {NULL, NULL, "ds4usb", usb_probe, usb_connect, usb_disconnect}; +UsbDriver usb_driver = {NULL, NULL, MODNAME, usb_probe, usb_connect, usb_disconnect}; static void readReport(u8 *data, int pad); static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); @@ -45,11 +56,11 @@ int usb_probe(int devId) { UsbDeviceDescriptor *device = NULL; - DPRINTF("DS4USB: probe: devId=%i\n", devId); + DPRINTF("probe: devId=%i\n", devId); device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); if (device == NULL) { - DPRINTF("DS4USB: Error - Couldn't get device descriptor\n"); + DPRINTF("Error - Couldn't get device descriptor\n"); return 0; } @@ -67,7 +78,7 @@ int usb_connect(int devId) UsbInterfaceDescriptor *interface; UsbEndpointDescriptor *endpoint; - DPRINTF("DS4USB: connect: devId=%i\n", devId); + DPRINTF("connect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (ds4dev[pad].usb_id == -1) @@ -75,7 +86,7 @@ int usb_connect(int devId) } if (pad >= MAX_PADS) { - DPRINTF("DS4USB: Error - only %d device allowed !\n", MAX_PADS); + DPRINTF("Error - only %d device allowed !\n", MAX_PADS); return 1; } @@ -100,7 +111,7 @@ int usb_connect(int devId) if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && ds4dev[pad].interruptEndp < 0) { ds4dev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("DS4USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", ds4dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Event endpoint id =%i addr=%02X packetSize=%i\n", ds4dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && ds4dev[pad].outEndp < 0) { ds4dev[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); @@ -127,7 +138,7 @@ int usb_disconnect(int devId) { u8 pad; - DPRINTF("DS4USB: disconnect: devId=%i\n", devId); + DPRINTF("disconnect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (ds4dev[pad].usb_id == devId) { @@ -164,7 +175,7 @@ static void usb_data_cb(int resultCode, int bytes, void *arg) { int pad = (int)arg; - //DPRINTF("DS4USB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + //DPRINTF("usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); ds4dev[pad].usb_resultcode = resultCode; @@ -175,7 +186,7 @@ static void usb_cmd_cb(int resultCode, int bytes, void *arg) { int pad = (int)arg; - //DPRINTF("DS4USB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + //DPRINTF("usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); SignalSema(ds4dev[pad].cmd_sema); } @@ -395,7 +406,7 @@ int ds4usb_get_data(u8 *dst, int size, int port) ds4dev[port].usb_resultcode = 1; } else { - DPRINTF("DS4USB: DS4USB_get_data usb transfer error %d\n", ret); + DPRINTF("DS4USB_get_data usb transfer error %d\n", ret); } mips_memcpy(dst, ds4dev[port].data, size); @@ -406,7 +417,7 @@ int ds4usb_get_data(u8 *dst, int size, int port) if (ret == USB_RC_OK) TransferWait(ds4dev[port].cmd_sema); else - DPRINTF("DS4USB: LEDRumble usb transfer error %d\n", ret); + DPRINTF("LEDRumble usb transfer error %d\n", ret); ds4dev[port].update_rum = 0; } @@ -465,13 +476,13 @@ int _start(int argc, char *argv[]) ds4dev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); if (ds4dev[pad].sema < 0 || ds4dev[pad].cmd_sema < 0) { - DPRINTF("DS4USB: Failed to allocate I/O semaphore.\n"); + DPRINTF("Failed to allocate I/O semaphore.\n"); return MODULE_NO_RESIDENT_END; } } if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { - DPRINTF("DS4USB: Error registering USB devices\n"); + DPRINTF("Error registering USB devices\n"); return MODULE_NO_RESIDENT_END; } diff --git a/modules/pademu/hidusb/hidusb.c b/modules/pademu/hidusb/hidusb.c index 0356c95c5..c9791c420 100644 --- a/modules/pademu/hidusb/hidusb.c +++ b/modules/pademu/hidusb/hidusb.c @@ -9,8 +9,19 @@ #include "thsemap.h" #include "hidusb.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + + +#define MODNAME "hidusb" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + #define MAX_PADS 4 @@ -23,7 +34,7 @@ int usb_disconnect(int devId); static void usb_release(int pad); static void usb_config_set(int result, int count, void *arg); -UsbDriver usb_driver = {NULL, NULL, "hidusb", usb_probe, usb_connect, usb_disconnect}; +UsbDriver usb_driver = {NULL, NULL, MODNAME, usb_probe, usb_connect, usb_disconnect}; int read_report_descriptor(u8 *data, int size, hidreport_t *report); static void read_report(u8 *data, int pad); @@ -36,7 +47,7 @@ int usb_probe(int devId) UsbConfigDescriptor *config; UsbInterfaceDescriptor *interface; - DPRINTF("HIDUSB: probe: devId=%i\n", devId); + DPRINTF("probe: devId=%i\n", devId); device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); config = (UsbConfigDescriptor *)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG); @@ -58,7 +69,7 @@ int usb_connect(int devId) UsbHidDescriptor *hid; u8 buf[512]; - DPRINTF("HIDUSB: connect: devId=%i\n", devId); + DPRINTF("connect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (hiddev[pad].usb_id == -1) @@ -66,7 +77,7 @@ int usb_connect(int devId) } if (pad >= MAX_PADS) { - DPRINTF("HIDUSB: Error - only %d device allowed !\n", MAX_PADS); + DPRINTF("Error - only %d device allowed !\n", MAX_PADS); return 1; } @@ -332,7 +343,7 @@ int hidusb_get_data(u8 *dst, int size, int port) hiddev[port].usb_resultcode = 1; } else { - DPRINTF("HIDUSB: hidusb_get_data usb transfer error %d\n", ret); + DPRINTF("hidusb_get_data usb transfer error %d\n", ret); } mips_memcpy(dst, hiddev[port].data, size); @@ -399,13 +410,13 @@ int _start(int argc, char *argv[]) hiddev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); if (hiddev[pad].sema < 0 || hiddev[pad].cmd_sema < 0) { - DPRINTF("HIDUSB: Failed to allocate I/O semaphore.\n"); + DPRINTF("Failed to allocate I/O semaphore.\n"); return MODULE_NO_RESIDENT_END; } } if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { - DPRINTF("HIDUSB: Error registering USB devices\n"); + DPRINTF("Error registering USB devices\n"); return MODULE_NO_RESIDENT_END; } diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index 99455c297..3179c3d98 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -22,8 +22,18 @@ #include "pademu.h" #include "padmacro.h" -#define DPRINTF(x...) printf(x) -//#define DPRINTF(x...) + + +#define MODNAME "pademu" +IRX_ID(MODNAME, 1, 1); +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + typedef struct { @@ -44,11 +54,8 @@ typedef struct #define ANALOG_MODE 0x73 #define ANALOGP_MODE 0x79 #define CONFIG_MODE 0xF3 - #define MAX_PORTS 4 -IRX_ID("pademu", 1, 1); - PtrRegisterLibraryEntires pRegisterLibraryEntires; /* Pointer to RegisterLibraryEntires routine */ Sio2McProc pSio2man25, pSio2man51; /* Pointers to SIO2MAN routines */ pad_status_t pad[MAX_PORTS]; @@ -142,7 +149,7 @@ int install_sio2hook() /* looking for LOADCORE's library entry table */ exp = GetExportTable("loadcore", 0x100); if (exp == NULL) { - DPRINTF("PADEMU: Unable to find loadcore exports.\n"); + DPRINTF("Unable to find loadcore exports.\n"); return 0; } @@ -155,7 +162,7 @@ int install_sio2hook() /* hooking SIO2MAN's routines */ InstallSio2manHook(exp, 1); } else { - DPRINTF("PADEMU: SIO2MAN exports not found.\n"); + DPRINTF("SIO2MAN exports not found.\n"); } return 1; @@ -163,7 +170,7 @@ int install_sio2hook() void InstallSio2manHook(void *exp, int ver) { - DPRINTF("PADEMU: Install sio2man hooks \n"); + DPRINTF("Install sio2man hooks \n"); /* hooking SIO2MAN entry #25 (used by MCMAN and old PADMAN) */ pSio2man25 = HookExportEntry(exp, 25, hookSio2man25); /* hooking SIO2MAN entry #51 (used by MC2_* modules and PADMAN) */ @@ -182,12 +189,12 @@ int hookRegisterLibraryEntires(iop_library_t *lib) /* hooking SIO2MAN's routines */ InstallSio2manHook(&lib[1], GetExportTableSize(&lib[1]) >= 61); } else { - DPRINTF("PADEMU: registering library %s failed, error %d\n", lib->name, ret); + DPRINTF("registering library %s failed, error %d\n", lib->name, ret); return ret; } } - DPRINTF("PADEMU: registering library %s\n", lib->name); + DPRINTF("registering library %s\n", lib->name); return pRegisterLibraryEntires(lib); } @@ -298,7 +305,7 @@ void pademu_connect(pad_device_t *dev) if (pad[i].enabled && pad[i].dev == NULL) { pad[i].dev = dev; pad[i].dev->id = i; - DPRINTF("PADEMU: Device connected\n"); + DPRINTF("Device connected\n"); break; } } @@ -310,7 +317,7 @@ void pademu_disconnect(pad_device_t *dev) for (i = 0; i < MAX_PORTS; i++) { if (pad[i].dev == dev) { pad[i].dev = NULL; - DPRINTF("PADEMU: Device disconnected\n"); + DPRINTF("Device disconnected\n"); break; } } @@ -349,7 +356,7 @@ void pademu(sio2_transfer_data_t *td) } if (cmd_size + 3 == td->in_size) { - DPRINTF("PADEMU: Second cmd not found!\n"); + DPRINTF("Second cmd not found!\n"); return; } @@ -398,7 +405,7 @@ void pademu_cmd(int port, u8 *in, u8 *out, u8 out_size) { u8 i; - //DPRINTF("PADEMU: sio cmd %02x port %d\n", in[1], port); + //DPRINTF("sio cmd %02x port %d\n", in[1], port); mips_memset(out, 0x00, out_size); diff --git a/modules/pademu/xbox360usb/xbox360usb.c b/modules/pademu/xbox360usb/xbox360usb.c index 28b90a344..06eb8eefe 100644 --- a/modules/pademu/xbox360usb/xbox360usb.c +++ b/modules/pademu/xbox360usb/xbox360usb.c @@ -9,8 +9,19 @@ #include "thsemap.h" #include "xbox360usb.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + + +#define MODNAME "xbox360usb" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) @@ -26,7 +37,7 @@ int usb_disconnect(int devId); static void usb_release(int pad); static void usb_config_set(int result, int count, void *arg); -UsbDriver usb_driver = {NULL, NULL, "xbox360usb", usb_probe, usb_connect, usb_disconnect}; +UsbDriver usb_driver = {NULL, NULL, MODNAME, usb_probe, usb_connect, usb_disconnect}; static void readReport(u8 *data, int pad); static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad); @@ -37,11 +48,11 @@ int usb_probe(int devId) { UsbDeviceDescriptor *device = NULL; - DPRINTF("XBOX360USB: probe: devId=%i\n", devId); + DPRINTF("probe: devId=%i\n", devId); device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); if (device == NULL) { - DPRINTF("XBOX360USB: Error - Couldn't get device descriptor\n"); + DPRINTF("Error - Couldn't get device descriptor\n"); return 0; } @@ -61,7 +72,7 @@ int usb_connect(int devId) UsbInterfaceDescriptor *interface; UsbEndpointDescriptor *endpoint; - DPRINTF("XBOX360USB: connect: devId=%i\n", devId); + DPRINTF("connect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (xbox360dev[pad].usb_id == -1) @@ -69,7 +80,7 @@ int usb_connect(int devId) } if (pad >= MAX_PADS) { - DPRINTF("XBOX360USB: Error - only %d device allowed !\n", MAX_PADS); + DPRINTF("Error - only %d device allowed !\n", MAX_PADS); return 1; } @@ -89,7 +100,7 @@ int usb_connect(int devId) if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) { if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && xbox360dev[pad].interruptEndp < 0) { xbox360dev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); - DPRINTF("XBOX360USB: register Event endpoint id =%i addr=%02X packetSize=%i\n", xbox360dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Event endpoint id =%i addr=%02X packetSize=%i\n", xbox360dev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } @@ -112,7 +123,7 @@ int usb_disconnect(int devId) { u8 pad; - DPRINTF("XBOX360USB: disconnect: devId=%i\n", devId); + DPRINTF("disconnect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (xbox360dev[pad].usb_id == devId) { @@ -305,7 +316,7 @@ int xbox360usb_get_data(u8 *dst, int size, int port) xbox360dev[port].usb_resultcode = 1; } else { - DPRINTF("XBOX360USB: XBOX360USB_get_data usb transfer error %d\n", ret); + DPRINTF("XBOX360USB_get_data usb transfer error %d\n", ret); } mips_memcpy(dst, xbox360dev[port].data, size); @@ -316,7 +327,7 @@ int xbox360usb_get_data(u8 *dst, int size, int port) if (ret == USB_RC_OK) TransferWait(xbox360dev[port].cmd_sema); else - DPRINTF("XBOX360USB: LEDRumble usb transfer error %d\n", ret); + DPRINTF("LEDRumble usb transfer error %d\n", ret); xbox360dev[port].update_rum = 0; } @@ -374,13 +385,13 @@ int _start(int argc, char *argv[]) xbox360dev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); if (xbox360dev[pad].sema < 0 || xbox360dev[pad].cmd_sema < 0) { - DPRINTF("XBOX360USB: Failed to allocate I/O semaphore.\n"); + DPRINTF("Failed to allocate I/O semaphore.\n"); return MODULE_NO_RESIDENT_END; } } if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { - DPRINTF("XBOX360USB: Error registering USB devices\n"); + DPRINTF("Error registering USB devices\n"); return MODULE_NO_RESIDENT_END; } diff --git a/modules/pademu/xboxoneusb/xboxoneusb.c b/modules/pademu/xboxoneusb/xboxoneusb.c index 89c02e827..f9bf9bb0d 100644 --- a/modules/pademu/xboxoneusb/xboxoneusb.c +++ b/modules/pademu/xboxoneusb/xboxoneusb.c @@ -9,8 +9,19 @@ #include "thsemap.h" #include "xboxoneusb.h" -//#define DPRINTF(x...) printf(x) -#define DPRINTF(x...) + + +#define MODNAME "xboxoneusb" +IRX_ID(MODNAME, 1, 1); + +#ifdef DEBUG +#define DPRINTF(format, args...) \ + printf(MODNAME ": " format, ##args) +#else +#define DPRINTF(args...) +#endif + + #define REQ_USB_OUT (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) #define REQ_USB_IN (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) @@ -26,7 +37,7 @@ int usb_disconnect(int devId); static void usb_release(int pad); static void usb_config_set(int result, int count, void *arg); -UsbDriver usb_driver = {NULL, NULL, "xboxoneusb", usb_probe, usb_connect, usb_disconnect}; +UsbDriver usb_driver = {NULL, NULL, MODNAME, usb_probe, usb_connect, usb_disconnect}; static void readReport(u8 *data, int pad); static int Rumble(u8 lrum, u8 rrum, int pad); @@ -38,11 +49,11 @@ int usb_probe(int devId) { UsbDeviceDescriptor *device = NULL; - DPRINTF("XBOXONEUSB: probe: devId=%i\n", devId); + DPRINTF("probe: devId=%i\n", devId); device = (UsbDeviceDescriptor *)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); if (device == NULL) { - DPRINTF("XBOXONEUSB: Error - Couldn't get device descriptor\n"); + DPRINTF("Error - Couldn't get device descriptor\n"); return 0; } @@ -63,7 +74,7 @@ int usb_connect(int devId) UsbInterfaceDescriptor *interface; UsbEndpointDescriptor *endpoint; - DPRINTF("XBOXONEUSB: connect: devId=%i\n", devId); + DPRINTF("connect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (xboxonedev[pad].usb_id == -1) @@ -71,7 +82,7 @@ int usb_connect(int devId) } if (pad >= MAX_PADS) { - DPRINTF("XBOXONEUSB: Error - only %d device allowed !\n", MAX_PADS); + DPRINTF("Error - only %d device allowed !\n", MAX_PADS); return 1; } @@ -92,7 +103,7 @@ int usb_connect(int devId) if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && xboxonedev[pad].interruptEndp < 0) { xboxonedev[pad].interruptEndp = UsbOpenEndpointAligned(devId, endpoint); xboxonedev[pad].endin = endpoint; - DPRINTF("XBOXONEUSB: register Event endpoint id =%i addr=%02X packetSize=%i\n", xboxonedev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Event endpoint id =%i addr=%02X packetSize=%i\n", xboxonedev[pad].interruptEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && xboxonedev[pad].outEndp < 0) { xboxonedev[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); @@ -120,7 +131,7 @@ int usb_disconnect(int devId) { u8 pad; - DPRINTF("XBOXONEUSB: disconnect: devId=%i\n", devId); + DPRINTF("disconnect: devId=%i\n", devId); for (pad = 0; pad < MAX_PADS; pad++) { if (xboxonedev[pad].usb_id == devId) { @@ -157,7 +168,7 @@ static void usb_data_cb(int resultCode, int bytes, void *arg) { int pad = (int)arg; - //DPRINTF("XBOXONEUSB: usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + //DPRINTF("usb_data_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); xboxonedev[pad].usb_resultcode = resultCode; @@ -168,7 +179,7 @@ static void usb_cmd_cb(int resultCode, int bytes, void *arg) { int pad = (int)arg; - //DPRINTF("XBOXONEUSB: usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); + //DPRINTF("usb_cmd_cb: res %d, bytes %d, arg %p \n", resultCode, bytes, arg); SignalSema(xboxonedev[pad].cmd_sema); } @@ -295,7 +306,7 @@ int xboxoneusb_get_data(u8 *dst, int size, int port) } else { UsbCloseEndpoint(xboxonedev[port].interruptEndp); xboxonedev[port].interruptEndp = UsbOpenEndpointAligned(xboxonedev[port].usb_id, xboxonedev[port].endin); - DPRINTF("XBOXONEUSB: XBOXONEUSB_get_data usb transfer error %d\n", ret); + DPRINTF("XBOXONEUSB_get_data usb transfer error %d\n", ret); } mips_memcpy(dst, xboxonedev[port].data, size); @@ -308,7 +319,7 @@ int xboxoneusb_get_data(u8 *dst, int size, int port) } else { UsbCloseEndpoint(xboxonedev[port].outEndp); xboxonedev[port].outEndp = UsbOpenEndpointAligned(xboxonedev[port].usb_id, xboxonedev[port].endout); - DPRINTF("XBOXONEUSB: LEDRumble usb transfer error %d\n", ret); + DPRINTF("LEDRumble usb transfer error %d\n", ret); } xboxonedev[port].update_rum = 0; @@ -366,13 +377,13 @@ int _start(int argc, char *argv[]) xboxonedev[pad].cmd_sema = CreateMutex(IOP_MUTEX_UNLOCKED); if (xboxonedev[pad].sema < 0 || xboxonedev[pad].cmd_sema < 0) { - DPRINTF("XBOXONEUSB: Failed to allocate I/O semaphore.\n"); + DPRINTF("Failed to allocate I/O semaphore.\n"); return MODULE_NO_RESIDENT_END; } } if (UsbRegisterDriver(&usb_driver) != USB_RC_OK) { - DPRINTF("XBOXONEUSB: Error registering USB devices\n"); + DPRINTF("Error registering USB devices\n"); return MODULE_NO_RESIDENT_END; } From 1296264d467162441a91c813befd3f5b73f743f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 10:21:23 -0300 Subject: [PATCH 30/37] Update xboxoneusb.c --- modules/pademu/xboxoneusb/xboxoneusb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pademu/xboxoneusb/xboxoneusb.c b/modules/pademu/xboxoneusb/xboxoneusb.c index f9bf9bb0d..0b39448dd 100644 --- a/modules/pademu/xboxoneusb/xboxoneusb.c +++ b/modules/pademu/xboxoneusb/xboxoneusb.c @@ -108,7 +108,7 @@ int usb_connect(int devId) if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && xboxonedev[pad].outEndp < 0) { xboxonedev[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); xboxonedev[pad].endout = endpoint; - DPRINTF("DS34USB: register Output endpoint id =%i addr=%02X packetSize=%i\n", xboxonepad[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Output endpoint id =%i addr=%02X packetSize=%i\n", xboxonepad[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } @@ -306,7 +306,7 @@ int xboxoneusb_get_data(u8 *dst, int size, int port) } else { UsbCloseEndpoint(xboxonedev[port].interruptEndp); xboxonedev[port].interruptEndp = UsbOpenEndpointAligned(xboxonedev[port].usb_id, xboxonedev[port].endin); - DPRINTF("XBOXONEUSB_get_data usb transfer error %d\n", ret); + DPRINTF("%s: usb transfer error %d\n", __FUNCTION__, ret); } mips_memcpy(dst, xboxonedev[port].data, size); From 74a6ccad638f67ba782d1caf7413aeca1c798bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 10:46:37 -0300 Subject: [PATCH 31/37] represent pademu modules ID as macros --- ee_core/src/iopmgr.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/ee_core/src/iopmgr.c b/ee_core/src/iopmgr.c index df71d5649..fd0ea721e 100644 --- a/ee_core/src/iopmgr.c +++ b/ee_core/src/iopmgr.c @@ -7,6 +7,13 @@ Some parts of the code are taken from HD Project by Polo */ +#define PADEMU_MODULES_ID_DS3USB (1 << 0) +#define PADEMU_MODULES_ID_DS3BT (1 << 1) +#define PADEMU_MODULES_ID_DS4USB (1 << 2) +#define PADEMU_MODULES_ID_DS4BT (1 << 3) +#define PADEMU_MODULES_ID_XBOX360USB (1 << 4) +#define PADEMU_MODULES_ID_XBOXONEUSB (1 << 5) +#define PADEMU_MODULES_ID_HIDUSB (1 << 6) #include #include "ee_core.h" @@ -190,39 +197,37 @@ int New_Reset_Iop(const char *arg, int arglen) memcpy(args_for_pademu, &PadEmuSettings, 4); memcpy(args_for_pademu + 4, &PadMacroSettings, 4); LoadOPLModule(OPL_MODULE_ID_PADEMU, 0, sizeof(args_for_pademu), args_for_pademu); - LoadOPLModule(OPL_MODULE_ID_PADEMU, 0, 4, (char *)&PadEmuSettings); - if (PadEmuModules & (1 << 0)) { - LoadOPLModule(OPL_MODULE_ID_DS3USB, 0, sizeof(args_for_pademu), args_for_pademu); + if (PadEmuModules & PADEMU_MODULES_ID_DS3USB) { + LoadOPLModule(OPL_MODULE_ID_DS3USB, 0, 0, NULL); } - if (PadEmuModules & (1 << 1)) { + if (PadEmuModules & PADEMU_MODULES_ID_DS3BT) { if (!btstack_loaded) { - LoadOPLModule(OPL_MODULE_ID_BTSTACK, 0, sizeof(args_for_pademu), args_for_pademu); + LoadOPLModule(OPL_MODULE_ID_BTSTACK, 0, 0, NULL); btstack_loaded = 1; } - LoadOPLModule(OPL_MODULE_ID_DS3BT, 0, sizeof(args_for_pademu), args_for_pademu); + LoadOPLModule(OPL_MODULE_ID_DS3BT, 0, 0, NULL); } - if (PadEmuModules & (1 << 2)) { - LoadOPLModule(OPL_MODULE_ID_DS4USB, 0, sizeof(args_for_pademu), args_for_pademu); + if (PadEmuModules & PADEMU_MODULES_ID_DS4USB) { + LoadOPLModule(OPL_MODULE_ID_DS4USB, 0, 0, NULL); } - if (PadEmuModules & (1 << 3)) { + if (PadEmuModules & PADEMU_MODULES_ID_DS4BT) { if (!btstack_loaded) { LoadOPLModule(OPL_MODULE_ID_BTSTACK, 0, 0, NULL); btstack_loaded = 1; } - LoadOPLModule(OPL_MODULE_ID_DS4BT, 0, sizeof(args_for_pademu), args_for_pademu); + LoadOPLModule(OPL_MODULE_ID_DS4BT, 0, 0, NULL); } - if (PadEmuModules & (1 << 4)) { - LoadOPLModule(OPL_MODULE_ID_XBOX360USB, 0, sizeof(args_for_pademu), args_for_pademu); + if (PadEmuModules & PADEMU_MODULES_ID_XBOX360USB) { + LoadOPLModule(OPL_MODULE_ID_XBOX360USB, 0, 0, NULL); } - if (PadEmuModules & (1 << 5)) { - LoadOPLModule(OPL_MODULE_ID_XBOXONEUSB, 0, sizeof(args_for_pademu), args_for_pademu); + if (PadEmuModules & PADEMU_MODULES_ID_XBOXONEUSB) { + LoadOPLModule(OPL_MODULE_ID_XBOXONEUSB, 0, 0, NULL); } - if (PadEmuModules & (1 << 6)) { - LoadOPLModule(OPL_MODULE_ID_HIDUSB, 0, sizeof(args_for_pademu), args_for_pademu); + if (PadEmuModules & PADEMU_MODULES_ID_HIDUSB) { + LoadOPLModule(OPL_MODULE_ID_HIDUSB, 0, 0, NULL); } } #endif - DPRINTF("Exiting services...\n"); SifExitIopHeap(); LoadFileExit(); From 59364a48542eb2633561416ae275cf1b7793e42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:02:56 -0300 Subject: [PATCH 32/37] printf PADEMU args --- modules/pademu/pademu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index 3179c3d98..f6f8e1bb3 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -106,6 +106,11 @@ int _start(int argc, char *argv[]) pad_enable = 0x03; if (argc > 1) { +#ifdef DEBUG + int x; + for (x = 0; x < argc; x++) + DPRINTF("argv[%d]: %s\n", x, argv[x]); +#endif mips_memcpy(&PadEmuSettings_local.raw, argv[1], 4); pad_enable = PadEmuSettings_local.pad_enable; pad_vibration = PadEmuSettings_local.pad_vibration; @@ -118,6 +123,7 @@ int _start(int argc, char *argv[]) } if (RegisterLibraryEntries(&_exp_pademu) != 0) { + DPRINTF("RegisterLibraryEntries Failed\n") return MODULE_NO_RESIDENT_END; } From 6f3f3bfd4b64727897d021fb289dbdf77ad173bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:24:57 -0300 Subject: [PATCH 33/37] add "hello" printf to PADEMU modules --- modules/pademu/btstack/btstack.c | 1 + modules/pademu/ds3bt/ds3bt.c | 1 + modules/pademu/ds3usb/ds3usb.c | 1 + modules/pademu/ds4bt/ds4bt.c | 1 + modules/pademu/ds4usb/ds4usb.c | 1 + modules/pademu/hidusb/hidusb.c | 1 + modules/pademu/pademu.c | 3 ++- modules/pademu/xbox360usb/xbox360usb.c | 1 + modules/pademu/xboxoneusb/xboxoneusb.c | 1 + 9 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/pademu/btstack/btstack.c b/modules/pademu/btstack/btstack.c index d76509181..2e32f522d 100644 --- a/modules/pademu/btstack/btstack.c +++ b/modules/pademu/btstack/btstack.c @@ -1106,6 +1106,7 @@ extern struct irx_export_table _exp_btstack; int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); int ret; dev_init(); diff --git a/modules/pademu/ds3bt/ds3bt.c b/modules/pademu/ds3bt/ds3bt.c index 41aa25470..6773d516f 100644 --- a/modules/pademu/ds3bt/ds3bt.c +++ b/modules/pademu/ds3bt/ds3bt.c @@ -225,6 +225,7 @@ void ds3bt_rumble(bt_paddata_t *data) int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); btstack_register(&ds3btdrv); return MODULE_RESIDENT_END; diff --git a/modules/pademu/ds3usb/ds3usb.c b/modules/pademu/ds3usb/ds3usb.c index cdebe62e7..572d7dd1e 100644 --- a/modules/pademu/ds3usb/ds3usb.c +++ b/modules/pademu/ds3usb/ds3usb.c @@ -396,6 +396,7 @@ void ds3usb_reset() int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); int pad; for (pad = 0; pad < MAX_PADS; pad++) { diff --git a/modules/pademu/ds4bt/ds4bt.c b/modules/pademu/ds4bt/ds4bt.c index a5b7433ba..e91e862c0 100644 --- a/modules/pademu/ds4bt/ds4bt.c +++ b/modules/pademu/ds4bt/ds4bt.c @@ -220,6 +220,7 @@ void ds4bt_rumble(bt_paddata_t *data) int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); btstack_register(&ds4btdrv); return MODULE_RESIDENT_END; diff --git a/modules/pademu/ds4usb/ds4usb.c b/modules/pademu/ds4usb/ds4usb.c index f3f991bab..7eac24cb6 100644 --- a/modules/pademu/ds4usb/ds4usb.c +++ b/modules/pademu/ds4usb/ds4usb.c @@ -445,6 +445,7 @@ void ds4usb_reset() int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); int pad; for (pad = 0; pad < MAX_PADS; pad++) { diff --git a/modules/pademu/hidusb/hidusb.c b/modules/pademu/hidusb/hidusb.c index c9791c420..11f48155b 100644 --- a/modules/pademu/hidusb/hidusb.c +++ b/modules/pademu/hidusb/hidusb.c @@ -382,6 +382,7 @@ void hidusb_reset() int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); int pad; for (pad = 0; pad < MAX_PADS; pad++) { diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index f6f8e1bb3..d6347f552 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -89,6 +89,7 @@ extern struct irx_export_table _exp_pademu; int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); union { struct @@ -109,7 +110,7 @@ int _start(int argc, char *argv[]) #ifdef DEBUG int x; for (x = 0; x < argc; x++) - DPRINTF("argv[%d]: %s\n", x, argv[x]); + DPRINTF("\targv[%d]: %s\n", x, argv[x]); #endif mips_memcpy(&PadEmuSettings_local.raw, argv[1], 4); pad_enable = PadEmuSettings_local.pad_enable; diff --git a/modules/pademu/xbox360usb/xbox360usb.c b/modules/pademu/xbox360usb/xbox360usb.c index 06eb8eefe..9b41a6299 100644 --- a/modules/pademu/xbox360usb/xbox360usb.c +++ b/modules/pademu/xbox360usb/xbox360usb.c @@ -355,6 +355,7 @@ void xbox360usb_reset() int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); int pad; for (pad = 0; pad < MAX_PADS; pad++) { diff --git a/modules/pademu/xboxoneusb/xboxoneusb.c b/modules/pademu/xboxoneusb/xboxoneusb.c index 0b39448dd..de02f4425 100644 --- a/modules/pademu/xboxoneusb/xboxoneusb.c +++ b/modules/pademu/xboxoneusb/xboxoneusb.c @@ -348,6 +348,7 @@ void xboxoneusb_reset() int _start(int argc, char *argv[]) { + DPRINTF("Start\n"); int pad; for (pad = 0; pad < MAX_PADS; pad++) { From 9e925ac338046c576e1340358b6da84629d57e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:25:09 -0300 Subject: [PATCH 34/37] xboxone: fix printf --- modules/pademu/xboxoneusb/xboxoneusb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pademu/xboxoneusb/xboxoneusb.c b/modules/pademu/xboxoneusb/xboxoneusb.c index de02f4425..91298d07b 100644 --- a/modules/pademu/xboxoneusb/xboxoneusb.c +++ b/modules/pademu/xboxoneusb/xboxoneusb.c @@ -108,7 +108,7 @@ int usb_connect(int devId) if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT && xboxonedev[pad].outEndp < 0) { xboxonedev[pad].outEndp = UsbOpenEndpointAligned(devId, endpoint); xboxonedev[pad].endout = endpoint; - DPRINTF("register Output endpoint id =%i addr=%02X packetSize=%i\n", xboxonepad[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); + DPRINTF("register Output endpoint id =%i addr=%02X packetSize=%i\n", xboxonedev[pad].outEndp, endpoint->bEndpointAddress, (unsigned short int)endpoint->wMaxPacketSizeHB << 8 | endpoint->wMaxPacketSizeLB); } } From b9fd41faf5899f023fb3e1f58ae2b468e646d88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:26:30 -0300 Subject: [PATCH 35/37] PADEMU: dont import printf if no debug --- modules/pademu/btstack/imports.lst | 2 ++ modules/pademu/ds3bt/imports.lst | 2 ++ modules/pademu/ds3usb/imports.lst | 2 ++ modules/pademu/ds4bt/imports.lst | 2 ++ modules/pademu/ds4usb/imports.lst | 2 ++ modules/pademu/hidusb/imports.lst | 2 ++ modules/pademu/xbox360usb/imports.lst | 2 ++ modules/pademu/xboxoneusb/imports.lst | 2 ++ 8 files changed, 16 insertions(+) diff --git a/modules/pademu/btstack/imports.lst b/modules/pademu/btstack/imports.lst index e36f592dd..9b784535b 100644 --- a/modules/pademu/btstack/imports.lst +++ b/modules/pademu/btstack/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/ds3bt/imports.lst b/modules/pademu/ds3bt/imports.lst index b0de84ee7..e8c608e66 100644 --- a/modules/pademu/ds3bt/imports.lst +++ b/modules/pademu/ds3bt/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/ds3usb/imports.lst b/modules/pademu/ds3usb/imports.lst index e36f592dd..9b784535b 100644 --- a/modules/pademu/ds3usb/imports.lst +++ b/modules/pademu/ds3usb/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/ds4bt/imports.lst b/modules/pademu/ds4bt/imports.lst index b0de84ee7..e8c608e66 100644 --- a/modules/pademu/ds4bt/imports.lst +++ b/modules/pademu/ds4bt/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/ds4usb/imports.lst b/modules/pademu/ds4usb/imports.lst index e36f592dd..9b784535b 100644 --- a/modules/pademu/ds4usb/imports.lst +++ b/modules/pademu/ds4usb/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/hidusb/imports.lst b/modules/pademu/hidusb/imports.lst index e36f592dd..9b784535b 100644 --- a/modules/pademu/hidusb/imports.lst +++ b/modules/pademu/hidusb/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/xbox360usb/imports.lst b/modules/pademu/xbox360usb/imports.lst index e36f592dd..9b784535b 100644 --- a/modules/pademu/xbox360usb/imports.lst +++ b/modules/pademu/xbox360usb/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema diff --git a/modules/pademu/xboxoneusb/imports.lst b/modules/pademu/xboxoneusb/imports.lst index e36f592dd..9b784535b 100644 --- a/modules/pademu/xboxoneusb/imports.lst +++ b/modules/pademu/xboxoneusb/imports.lst @@ -6,9 +6,11 @@ I_QueryLibraryEntryTable I_SetRebootTimeLibraryHandlingMode loadcore_IMPORTS_end +#ifdef DEBUG stdio_IMPORTS_start I_printf stdio_IMPORTS_end +#endif thsemap_IMPORTS_start I_CreateSema From d2315af138a92d5019808c7329ecb89345654e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:26:44 -0300 Subject: [PATCH 36/37] PADEMU: simplify makefiles --- modules/Rules.bin.make | 5 +++++ modules/pademu/btstack/Makefile | 13 ++----------- modules/pademu/ds3bt/Makefile | 11 +---------- modules/pademu/ds3usb/Makefile | 11 +---------- modules/pademu/ds4bt/Makefile | 11 +---------- modules/pademu/ds4usb/Makefile | 11 +---------- modules/pademu/hidusb/Makefile | 11 +---------- modules/pademu/xbox360usb/Makefile | 11 +---------- modules/pademu/xboxoneusb/Makefile | 12 ++---------- 9 files changed, 15 insertions(+), 81 deletions(-) diff --git a/modules/Rules.bin.make b/modules/Rules.bin.make index f5429465c..faafd0ecf 100644 --- a/modules/Rules.bin.make +++ b/modules/Rules.bin.make @@ -12,3 +12,8 @@ rebuild: clean all run: ps2client -t 1 execiop host:$(IOP_BIN) + +ifdef DEBUG +$(info debug enabled) +IOP_CFLAGS += -DDEBUG=$(DEBUG) +endif \ No newline at end of file diff --git a/modules/pademu/btstack/Makefile b/modules/pademu/btstack/Makefile index 863eae198..4ff3ee664 100644 --- a/modules/pademu/btstack/Makefile +++ b/modules/pademu/btstack/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.btstack/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make -include $(PS2SDK)/samples/Makefile.iopglobal \ No newline at end of file +include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make \ No newline at end of file diff --git a/modules/pademu/ds3bt/Makefile b/modules/pademu/ds3bt/Makefile index 19e98c970..f39a4dbca 100644 --- a/modules/pademu/ds3bt/Makefile +++ b/modules/pademu/ds3bt/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.ds3bt/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make diff --git a/modules/pademu/ds3usb/Makefile b/modules/pademu/ds3usb/Makefile index 1a37b11b6..b1f2fb1d9 100644 --- a/modules/pademu/ds3usb/Makefile +++ b/modules/pademu/ds3usb/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.ds3usb/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make diff --git a/modules/pademu/ds4bt/Makefile b/modules/pademu/ds4bt/Makefile index cefb7cb3b..344b5bf00 100644 --- a/modules/pademu/ds4bt/Makefile +++ b/modules/pademu/ds4bt/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.ds4bt/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make diff --git a/modules/pademu/ds4usb/Makefile b/modules/pademu/ds4usb/Makefile index db60c4c7a..31eff74b7 100644 --- a/modules/pademu/ds4usb/Makefile +++ b/modules/pademu/ds4usb/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.ds4usb/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make diff --git a/modules/pademu/hidusb/Makefile b/modules/pademu/hidusb/Makefile index 57bdd5dad..9f6cf44b9 100644 --- a/modules/pademu/hidusb/Makefile +++ b/modules/pademu/hidusb/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.hidusb/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make diff --git a/modules/pademu/xbox360usb/Makefile b/modules/pademu/xbox360usb/Makefile index 0eea4d701..abe3c34b4 100644 --- a/modules/pademu/xbox360usb/Makefile +++ b/modules/pademu/xbox360usb/Makefile @@ -6,15 +6,6 @@ IOP_OBJS_DIR = obj.xbox360usb/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) - include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make diff --git a/modules/pademu/xboxoneusb/Makefile b/modules/pademu/xboxoneusb/Makefile index c3a605dad..3f715204d 100644 --- a/modules/pademu/xboxoneusb/Makefile +++ b/modules/pademu/xboxoneusb/Makefile @@ -6,15 +6,7 @@ IOP_OBJS_DIR = obj.xboxoneusb/ IOP_CFLAGS += -Wall -fno-builtin -DUSE_SMSUTILS IOP_LDFLAGS += -s -all: OBJ_DIR $(IOP_BIN) - -clean: - rm -f $(IOP_BIN) $(IOP_OBJS) - -rebuild: clean all - -OBJ_DIR: - mkdir -p $(IOP_OBJS_DIR) include $(PS2SDK)/Defs.make -include $(PS2SDK)/samples/Makefile.iopglobal \ No newline at end of file +include $(PS2SDK)/samples/Makefile.iopglobal +include ../../Rules.bin.make \ No newline at end of file From ffb3e9fab7b39773c695db66edcf8a149ee2e71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:32:50 -0300 Subject: [PATCH 37/37] Update pademu.c --- modules/pademu/pademu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index d6347f552..a8542e78a 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -124,7 +124,7 @@ int _start(int argc, char *argv[]) } if (RegisterLibraryEntries(&_exp_pademu) != 0) { - DPRINTF("RegisterLibraryEntries Failed\n") + DPRINTF("RegisterLibraryEntries Failed\n"); return MODULE_NO_RESIDENT_END; }