Skip to content

Commit

Permalink
Revert some changes.
Browse files Browse the repository at this point in the history
Makefile and code refactor/cleanup.
  • Loading branch information
Wolf3s committed Dec 3, 2024
1 parent da77f00 commit 2f8e42c
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 111 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ clean: download_lwNBD
echo " -ds34bt"
$(MAKE) -C modules/ds34bt clean
echo " -pademu"
$(MAKE) -C modules/pademu USE_DS3USB=1 USE_DS3BT=1 USE_DS4USB=1 USE_DS4BT=1 clean
$(MAKE) -C modules/pademu USE_DS3=1 USE_DS4=1 clean
echo "-pc tools"
$(MAKE) -C pc clean

Expand Down Expand Up @@ -521,7 +521,7 @@ $(EE_ASM_DIR)ds34usb.c: modules/ds34usb/iop/ds34usb.irx | $(EE_ASM_DIR)
$(BIN2C) $< $@ $(*F)_irx

modules/pademu/pademu.irx: modules/pademu
$(MAKE) USE_DS3USB=1 USE_DS3BT=1 USE_DS4USB=1 USE_DS4BT=1 -C $< all
$(MAKE) USE_DS3=1 USE_DS4=1 -C $< all

$(EE_ASM_DIR)pademu.c: modules/pademu/pademu.irx
$(BIN2C) $< $@ $(*F)_irx
Expand Down
22 changes: 6 additions & 16 deletions modules/pademu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ IOP_OBJS = pademu_common.o pademu.o sys_utils.o imports.o exports.o padmacro.o

IOP_BIN = pademu.irx

ifeq ($(USE_DS3USB),1)
IOP_CFLAGS += -DDS3USB
IOP_OBJS += ds3usb.o
ifeq ($(USE_DS3),1)
IOP_CFLAGS += -DUSE_DS3
IOP_OBJS += ds3usb.o ds3bt.o
endif

ifeq ($(USE_DS3BT),1)
IOP_CFLAGS += -DDS3BT
IOP_OBJS += ds3bt.o
endif

ifeq ($(USE_DS4USB),1)
IOP_CFLAGS += -DDS4USB
IOP_OBJS += ds4usb.o
endif

ifeq ($(USE_DS4BT),1)
IOP_CFLAGS += -DDS4BT
IOP_OBJS += ds4bt.o
ifeq ($(USE_DS4),1)
IOP_CFLAGS += -DUSE_DS4
IOP_OBJS += ds4usb.o ds4bt.o
endif

ifeq ($(VMC),1)
Expand Down
70 changes: 42 additions & 28 deletions modules/pademu/ds3bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ static int bt_disconnect(int devId)
return 0;
}


#define OUTPUT_01_REPORT_SIZE 48
static const u8 hid_cmd_payload_led_arguments[] = {0xff, 0x27, 0x10, 0x00, 0x32};

Expand Down Expand Up @@ -514,7 +513,7 @@ static void HCI_event_task(int result)
if (i >= MAX_PADS) {
break;
}
pad_status_set(DS3BT_STATE_CONNECTED, i);
ds3pad_status_set(DS3BT_STATE_CONNECTED, i);
hci_remote_name(ds3pad[i].bdaddr);
} else {
DPRINTF("\t Error 0x%02X \n", hci_buf[2]);
Expand Down Expand Up @@ -588,9 +587,9 @@ 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(DS3BT_STATE_RUNNING, i) && ds3pad[i].enabled) {
if (pad_status_check(DS3BT_STATE_CONNECTED, i)) {
if (pad_status_check(DS3BT_STATE_DISCONNECTING, i)) // if we're waiting for hci disconnect event
if (!ds3pad_status_check(DS3BT_STATE_RUNNING, i) && ds3pad[i].enabled) {
if (ds3pad_status_check(DS3BT_STATE_CONNECTED, i)) {
if (ds3pad_status_check(DS3BT_STATE_DISCONNECTING, i)) // if we're waiting for hci disconnect event
continue;
else
hci_disconnect(ds3pad[i].hci_handle); // try to disconnect
Expand All @@ -616,9 +615,9 @@ static void HCI_event_task(int result)
}
}
}
pad_status_clear(DS3BT_STATE_CONNECTED, pad);
pad_status_clear(DS3BT_STATE_RUNNING, pad);
pad_status_clear(DS3BT_STATE_DISCONNECTING, pad);
ds3pad_status_clear(DS3BT_STATE_CONNECTED, pad);
ds3pad_status_clear(DS3BT_STATE_RUNNING, pad);
ds3pad_status_clear(DS3BT_STATE_DISCONNECTING, pad);
hci_accept_connection(ds3pad[pad].bdaddr);
break;

Expand Down Expand Up @@ -706,16 +705,16 @@ static void hci_event_cb(int resultCode, int bytes, void *arg)
/* L2CAP Commands */
/************************************************************/

static int L2CAP_Command(u16 handle, u16 scid, u8 *data, u8 length)
static int L2CAP_Command(u16 handle, 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);
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); // L2CAP Signalling channel over ACL-U logical link
l2cap_cmd_buf[6] = 0x01; // L2CAP header: Channel ID
l2cap_cmd_buf[7] = 0x00; // L2CAP Signalling channel over ACL-U logical link

mips_memcpy(&l2cap_cmd_buf[8], data, length);

Expand Down Expand Up @@ -743,7 +742,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, 1, cmd_buf, 12);
return L2CAP_Command(handle, cmd_buf, 12);
}

static int l2cap_config_request(u16 handle, u8 rxid, u16 dcid)
Expand All @@ -767,7 +766,7 @@ static int l2cap_config_request(u16 handle, u8 rxid, u16 dcid)
cmd_buf[10] = 0xFF; // Config Opt: data
cmd_buf[11] = 0xFF;

return L2CAP_Command(handle, 1, cmd_buf, 12);
return L2CAP_Command(handle, cmd_buf, 12);
}

static int l2cap_config_response(u16 handle, u8 rxid, u16 scid)
Expand All @@ -789,7 +788,7 @@ static int l2cap_config_response(u16 handle, u8 rxid, u16 scid)
cmd_buf[12] = 0xA0;
cmd_buf[13] = 0x02;

return L2CAP_Command(handle, 1, cmd_buf, 14);
return L2CAP_Command(handle, cmd_buf, 14);
}

static int l2cap_disconnection_request(u16 handle, u8 rxid, u16 dcid, u16 scid)
Expand All @@ -805,7 +804,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, 1, cmd_buf, 8);
return L2CAP_Command(handle, cmd_buf, 8);
}

static int l2cap_disconnection_response(u16 handle, u8 rxid, u16 scid, u16 dcid)
Expand All @@ -821,7 +820,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, 1, cmd_buf, 8);
return L2CAP_Command(handle, cmd_buf, 8);
}

#define CMD_DELAY 2
Expand Down Expand Up @@ -923,7 +922,7 @@ static int L2CAP_event_task(int result, int bytes)
ds3pad[pad].oldled[3] = 0;
DelayThread(CMD_DELAY);
hid_LEDRumbleCommand(ds3pad[pad].oldled, 0, 0, pad);
pad_status_set(DS3BT_STATE_RUNNING, pad);
ds3pad_status_set(DS3BT_STATE_RUNNING, pad);
pademu_connect(&padf[pad]);
}
ds3pad[pad].btn_delay = 0xFF;
Expand All @@ -933,10 +932,10 @@ static int L2CAP_event_task(int result, int bytes)
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(DS3BT_STATE_DISCONNECTING, pad);
ds3pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
l2cap_disconnection_response(ds3pad[pad].hci_handle, l2cap_buf[9], control_dcid, ds3pad[pad].control_scid);
} else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == interrupt_dcid) {
pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
ds3pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
l2cap_disconnection_response(ds3pad[pad].hci_handle, l2cap_buf[9], interrupt_dcid, ds3pad[pad].interrupt_scid);
}
break;
Expand All @@ -945,10 +944,10 @@ static int L2CAP_event_task(int result, int bytes)
DPRINTF("Disconnect Response SCID = 0x%04X \n", (l2cap_buf[12] | (l2cap_buf[13] << 8)));

if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == ds3pad[pad].control_scid) {
pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
ds3pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
hci_disconnect(ds3pad[pad].hci_handle);
} else if ((l2cap_buf[12] | (l2cap_buf[13] << 8)) == ds3pad[pad].interrupt_scid) {
pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
ds3pad_status_set(DS3BT_STATE_DISCONNECTING, pad);
identifier++;
l2cap_disconnection_request(ds3pad[pad].hci_handle, identifier, ds3pad[pad].control_scid, control_dcid);
}
Expand Down Expand Up @@ -979,15 +978,15 @@ static void l2cap_event_cb(int resultCode, int bytes, void *arg)
ret = L2CAP_event_task(resultCode, bytes);

if (ret < MAX_PADS) {
if (pad_status_check(DS3BT_STATE_RUNNING, ret)) {
if (pad_status_check(DS3BT_STATE_DISCONNECT_REQUEST, ret)) {
if (ds3pad_status_check(DS3BT_STATE_RUNNING, ret)) {
if (ds3pad_status_check(DS3BT_STATE_DISCONNECT_REQUEST, ret)) {
if (!ds3pad[ret].isfake) {
identifier++;
l2cap_disconnection_request(ds3pad[ret].hci_handle, identifier, ds3pad[ret].interrupt_scid, interrupt_dcid);
} else {
hci_disconnect(ds3pad[ret].hci_handle);
}
pad_status_clear(DS3BT_STATE_DISCONNECT_REQUEST, ret);
ds3pad_status_clear(DS3BT_STATE_DISCONNECT_REQUEST, ret);
} else if (ds3pad[ret].update_rum) {
hid_LEDRumbleCommand(ds3pad[ret].oldled, ds3pad[ret].lrum, ds3pad[ret].rrum, ret);
ds3pad[ret].update_rum = 0;
Expand All @@ -1006,6 +1005,21 @@ static void l2cap_event_cb(int resultCode, int bytes, void *arg)
/* HID Commands */
/************************************************************/

static int HID_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);
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 sceUsbdBulkTransfer(bt_dev.outEndp, l2cap_cmd_buf, (8 + length), NULL, NULL);
}

static int hid_initDS34(int pad)
{
u8 init_buf[PS3_F4_REPORT_LEN + 2];
Expand All @@ -1019,7 +1033,7 @@ static int hid_initDS34(int pad)
init_buf[5] = 0x00;
size += PS3_F4_REPORT_LEN;

return L2CAP_Command(ds3pad[pad].hci_handle, ds3pad[pad].control_scid, init_buf, size);
return HID_command(ds3pad[pad].hci_handle, ds3pad[pad].control_scid, init_buf, size);
}

/**
Expand Down Expand Up @@ -1071,7 +1085,7 @@ static int hid_LEDRumbleCommand(u8 *led, u8 lrum, u8 rrum, int pad)
ds3pad[pad].oldled[2] = led[2];
ds3pad[pad].oldled[3] = led[3];

return L2CAP_Command(ds3pad[pad].hci_handle, ds3pad[pad].control_scid, led_buf, size);
return HID_command(ds3pad[pad].hci_handle, ds3pad[pad].control_scid, led_buf, size);
}

static void hid_readReport(u8 *data, int bytes, int pad_idx)
Expand Down Expand Up @@ -1248,12 +1262,12 @@ void ds3bt_reset()
if (bt_dev.status & DS3BT_STATE_USB_AUTHORIZED) {
for (pad = 0; pad < MAX_PADS; pad++) {
WaitSema(bt_dev.hid_sema);
pad_status_set(DS3BT_STATE_DISCONNECT_REQUEST, pad);
ds3pad_status_set(DS3BT_STATE_DISCONNECT_REQUEST, pad);
SignalSema(bt_dev.hid_sema);
while (1) {
DelayThread(500);
WaitSema(bt_dev.hid_sema);
if (!pad_status_check(DS3BT_STATE_RUNNING, pad)) {
if (!ds3pad_status_check(DS3BT_STATE_RUNNING, pad)) {
SignalSema(bt_dev.hid_sema);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions modules/pademu/ds3bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ enum eDS34BTStatus {
DS3BT_STATE_DISCONNECT_REQUEST = 0x20,
};

#define pad_status_clear(flag, pad) ds3pad[pad].status &= ~flag
#define pad_status_set(flag, pad) ds3pad[pad].status |= flag
#define pad_status_check(flag, pad) (ds3pad[pad].status & flag)
#define ds3pad_status_clear(flag, pad) ds3pad[pad].status &= ~flag
#define ds3pad_status_set(flag, pad) ds3pad[pad].status |= flag
#define ds3pad_status_check(flag, pad) (ds3pad[pad].status & flag)

#define hci_event_flag_clear(flag) hci_event_flag &= ~flag
#define hci_event_flag_set(flag) hci_event_flag |= flag
Expand Down
7 changes: 3 additions & 4 deletions modules/pademu/ds3usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int usb_probe(int devId)
return 1;
}

if (device->idVendor == DS34_VID && (device->idProduct == DS3_PID))
if (device->idVendor == DS_VID && (device->idProduct == DS3_PID))
return 1;

return 0;
Expand Down Expand Up @@ -146,7 +146,7 @@ static int usb_connect(int devId)

endpoint = (UsbEndpointDescriptor *)sceUsbdScanStaticDescriptor(devId, NULL, USB_DT_ENDPOINT);

do {
while (epCount-- > 0) {
if (endpoint->bmAttributes == USB_ENDPOINT_XFER_INT) {
if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN && ds3pad[pad].interruptEndp < 0) {
ds3pad[pad].interruptEndp = sceUsbdOpenPipe(devId, endpoint);
Expand All @@ -159,8 +159,7 @@ static int usb_connect(int devId)
}

endpoint = (UsbEndpointDescriptor *)((char *)endpoint + endpoint->bLength);

} while (epCount--);
}

if (ds3pad[pad].interruptEndp < 0 || ds3pad[pad].outEndp < 0) {
usb_release(pad);
Expand Down
Loading

0 comments on commit 2f8e42c

Please sign in to comment.