From e3b4cb9a2db53172a8639da0bee470ba750fe09f Mon Sep 17 00:00:00 2001 From: meancoot Date: Sat, 23 Mar 2013 19:25:09 -0400 Subject: [PATCH] (iOS) Add disabled draft of SixAxis support. --- ios/RetroArch/input/BTStack/WiiMoteHelper.m | 72 ++++++++++++++++++++- ios/RetroArch/input/BTStack/btdynamic.c | 2 + ios/RetroArch/input/BTStack/btdynamic.h | 2 + ios/RetroArch/input/ios_joypad.c | 5 ++ ios/RetroArch/settings/RAButtonGetter.m | 13 ++++ 5 files changed, 92 insertions(+), 2 deletions(-) diff --git a/ios/RetroArch/input/BTStack/WiiMoteHelper.m b/ios/RetroArch/input/BTStack/WiiMoteHelper.m index d2d66616b9..9888883d46 100644 --- a/ios/RetroArch/input/BTStack/WiiMoteHelper.m +++ b/ios/RetroArch/input/BTStack/WiiMoteHelper.m @@ -44,9 +44,15 @@ static bool btstackOpen; static bool btOK; static BTDevice* discoveredDevice; +static bd_addr_t address; +static uint32_t handle[2]; +static uint32_t remote_cid[2]; +static uint32_t local_cid[2]; +uint8_t psdata_buffer[512]; void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +#if 1 // WiiMote bd_addr_t event_addr; switch (packet_type) @@ -232,10 +238,72 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint break; } } +#else // SixAxis + switch (packet_type) + { + // Connection + case HCI_EVENT_PACKET: + { + switch (packet[0]) + { + // Bluetooth is active, search for remote + case BTSTACK_EVENT_STATE: + { + if (packet[2] == HCI_STATE_WORKING) + bt_send_cmd_ptr(l2cap_register_service_ptr, 0x11, 672); + break; + } + + case L2CAP_EVENT_SERVICE_REGISTERED: + { + if (READ_BT_16(packet, 3) == 0x11) + bt_send_cmd_ptr(l2cap_register_service_ptr, 0x13, 672); + break; + } + + case L2CAP_EVENT_INCOMING_CONNECTION: + { + const uint32_t psm = READ_BT_16(packet, 10); + const bool second = (psm == 0x11) ? 0 : 1; + + handle[second] = READ_BT_16(packet, 8); + local_cid[second] = READ_BT_16(packet, 12); + remote_cid[second] = READ_BT_16(packet, 14); + + bt_flip_addr_ptr(address, &packet[2]); + bt_send_cmd_ptr(l2cap_accept_connection_ptr, local_cid[second]); + + break; + } + + case L2CAP_EVENT_CHANNEL_OPENED: + { + if (READ_BT_16(packet, 11) == PSM_HID_INTERRUPT) + { + uint8_t data[] = {0x53, 0xF4, 0x42, 0x03, 0x00, 0x00}; + bt_send_l2cap_ptr(local_cid[0], data, 6); + set_ps3_data(0); + } + + break; + } + + break; + } + + break; + } + + case L2CAP_DATA_PACKET: + { + if (packet[0] == 0xA1) + memcpy(psdata_buffer, packet, size); + break; + } + } +#endif } - - @implementation WiiMoteHelper + (BOOL)haveBluetooth { diff --git a/ios/RetroArch/input/BTStack/btdynamic.c b/ios/RetroArch/input/BTStack/btdynamic.c index fd159aa16d..7d8168e7ab 100644 --- a/ios/RetroArch/input/BTStack/btdynamic.c +++ b/ios/RetroArch/input/BTStack/btdynamic.c @@ -47,6 +47,8 @@ static struct GRAB(hci_write_authentication_enable), GRAB(hci_write_inquiry_mode), GRAB(l2cap_create_channel), + GRAB(l2cap_register_service), + GRAB(l2cap_accept_connection), {0, 0} }; diff --git a/ios/RetroArch/input/BTStack/btdynamic.h b/ios/RetroArch/input/BTStack/btdynamic.h index 8b52a30eb1..95818ab724 100644 --- a/ios/RetroArch/input/BTStack/btdynamic.h +++ b/ios/RetroArch/input/BTStack/btdynamic.h @@ -46,5 +46,7 @@ BTDIMPORT const hci_cmd_t* hci_remote_name_request_cancel_ptr; BTDIMPORT const hci_cmd_t* hci_write_authentication_enable_ptr; BTDIMPORT const hci_cmd_t* hci_write_inquiry_mode_ptr; BTDIMPORT const hci_cmd_t* l2cap_create_channel_ptr; +BTDIMPORT const hci_cmd_t* l2cap_register_service_ptr; +BTDIMPORT const hci_cmd_t* l2cap_accept_connection_ptr; #endif diff --git a/ios/RetroArch/input/ios_joypad.c b/ios/RetroArch/input/ios_joypad.c index 929544a380..e8693a8017 100644 --- a/ios/RetroArch/input/ios_joypad.c +++ b/ios/RetroArch/input/ios_joypad.c @@ -61,6 +61,11 @@ static void ios_joypad_poll(void) g_buttons[i] |= (joys[i].exp.type == EXP_CLASSIC) ? (joys[i].exp.classic.btns << 16) : 0; } } + + // HACK: SixAxis + extern uint8_t psdata_buffer[512]; + if (myosd_num_of_joys == 0) + g_buttons[0] = psdata_buffer[3] | (psdata_buffer[4] << 8); } const rarch_joypad_driver_t ios_joypad = { diff --git a/ios/RetroArch/settings/RAButtonGetter.m b/ios/RetroArch/settings/RAButtonGetter.m index e3ac4cb7a6..d2acde1f15 100644 --- a/ios/RetroArch/settings/RAButtonGetter.m +++ b/ios/RetroArch/settings/RAButtonGetter.m @@ -151,6 +151,19 @@ static const struct } } } + + // SixAxis + extern uint8_t psdata_buffer[512]; + uint32_t buttons = psdata_buffer[3] | (psdata_buffer[4] << 8); + for (int i = 0; i != 32; i ++) + { + if (buttons & (1 << i)) + { + _value.msubValues[1] = [NSString stringWithFormat:@"%d", i]; + [self finish]; + return; + } + } } @end