mirror of
https://github.com/libretro/RetroArch
synced 2025-04-17 20:43:10 +00:00
(HID) Move btdynamic/btpad to input/drivers_hid
This commit is contained in:
parent
27fe518ffe
commit
68b4304efd
@ -1,161 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2013-2014 - Jason Fetters
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "../../../dynamic.h"
|
||||
#include <rthreads/rthreads.h>
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CFRunLoop.h>
|
||||
#endif
|
||||
|
||||
#define BUILDING_BTDYNAMIC
|
||||
#include "btdynamic.h"
|
||||
|
||||
#define GRAB(A) {#A, (void**)&A##_ptr}
|
||||
|
||||
static struct
|
||||
{
|
||||
const char* name;
|
||||
void** target;
|
||||
} grabbers[] =
|
||||
{
|
||||
GRAB(bt_open),
|
||||
GRAB(bt_close),
|
||||
GRAB(bt_flip_addr),
|
||||
GRAB(bd_addr_to_str),
|
||||
GRAB(bt_register_packet_handler),
|
||||
GRAB(bt_send_cmd),
|
||||
GRAB(bt_send_l2cap),
|
||||
GRAB(run_loop_init),
|
||||
GRAB(run_loop_execute),
|
||||
|
||||
GRAB(btstack_set_power_mode),
|
||||
GRAB(hci_delete_stored_link_key),
|
||||
GRAB(hci_disconnect),
|
||||
GRAB(hci_read_bd_addr),
|
||||
GRAB(hci_inquiry),
|
||||
GRAB(hci_inquiry_cancel),
|
||||
GRAB(hci_pin_code_request_reply),
|
||||
GRAB(hci_pin_code_request_negative_reply),
|
||||
GRAB(hci_remote_name_request),
|
||||
GRAB(hci_remote_name_request_cancel),
|
||||
GRAB(hci_write_authentication_enable),
|
||||
GRAB(hci_write_inquiry_mode),
|
||||
GRAB(l2cap_create_channel),
|
||||
GRAB(l2cap_register_service),
|
||||
GRAB(l2cap_accept_connection),
|
||||
GRAB(l2cap_decline_connection),
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
extern void btpad_packet_handler(uint8_t packet_type,
|
||||
uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static bool btstack_tested;
|
||||
static bool btstack_loaded;
|
||||
|
||||
static sthread_t *btstack_thread;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static CFRunLoopSourceRef btstack_quit_source;
|
||||
#endif
|
||||
|
||||
bool btstack_try_load(void)
|
||||
{
|
||||
unsigned i;
|
||||
void *handle = NULL;
|
||||
|
||||
if (btstack_tested)
|
||||
return btstack_loaded;
|
||||
|
||||
btstack_tested = true;
|
||||
btstack_loaded = false;
|
||||
|
||||
handle = dylib_load("/usr/lib/libBTstack.dylib");
|
||||
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
for (i = 0; grabbers[i].name; i ++)
|
||||
{
|
||||
*grabbers[i].target = dylib_proc(handle, grabbers[i].name);
|
||||
|
||||
if (!*grabbers[i].target)
|
||||
{
|
||||
dylib_close(handle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
run_loop_init_ptr(RUN_LOOP_COCOA);
|
||||
bt_register_packet_handler_ptr(btpad_packet_handler);
|
||||
|
||||
btstack_loaded = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void btstack_thread_stop(void *data)
|
||||
{
|
||||
(void)data;
|
||||
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_OFF);
|
||||
}
|
||||
|
||||
static void btstack_thread_func(void* data)
|
||||
{
|
||||
RARCH_LOG("[BTstack]: Thread started");
|
||||
|
||||
if (bt_open_ptr())
|
||||
return;
|
||||
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopSourceContext ctx = { 0, 0, 0, 0, 0, 0, 0, 0, 0, btstack_thread_stop };
|
||||
btstack_quit_source = CFRunLoopSourceCreate(0, 0, &ctx);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), btstack_quit_source, kCFRunLoopCommonModes);
|
||||
#endif
|
||||
|
||||
RARCH_LOG("[BTstack]: Turning on...\n");
|
||||
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON);
|
||||
|
||||
RARCH_LOG("BTstack: Thread running...\n");
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopRun();
|
||||
#endif
|
||||
|
||||
RARCH_LOG("[BTstack]: Thread done.\n");
|
||||
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopSourceInvalidate(btstack_quit_source);
|
||||
CFRelease(btstack_quit_source);
|
||||
#endif
|
||||
}
|
||||
|
||||
void btstack_set_poweron(bool on)
|
||||
{
|
||||
if (!btstack_try_load())
|
||||
return;
|
||||
|
||||
if (on && !btstack_thread)
|
||||
btstack_thread = sthread_create(btstack_thread_func, NULL);
|
||||
else if (!on && btstack_thread && btstack_quit_source)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopSourceSignal(btstack_quit_source);
|
||||
#endif
|
||||
sthread_join(btstack_thread);
|
||||
btstack_thread = NULL;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2013-2014 - Jason Fetters
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __IOS_RARCH_BTDYNAMIC_H__
|
||||
#define __IOS_RARCH_BTDYNAMIC_H__
|
||||
|
||||
#include <boolean.h>
|
||||
#include "btstack.h"
|
||||
|
||||
bool btstack_try_load(void);
|
||||
void btstack_set_poweron(bool on);
|
||||
|
||||
#ifndef BUILDING_BTDYNAMIC
|
||||
#define BTDIMPORT extern
|
||||
#else
|
||||
#define BTDIMPORT
|
||||
#endif
|
||||
|
||||
BTDIMPORT int (*bt_open_ptr)(void);
|
||||
BTDIMPORT void (*bt_close_ptr)(void);
|
||||
BTDIMPORT void (*bt_flip_addr_ptr)(bd_addr_t dest, bd_addr_t src);
|
||||
BTDIMPORT char* (*bd_addr_to_str_ptr)(bd_addr_t addr);
|
||||
BTDIMPORT btstack_packet_handler_t (*bt_register_packet_handler_ptr)
|
||||
(btstack_packet_handler_t handler);
|
||||
BTDIMPORT int (*bt_send_cmd_ptr)(const hci_cmd_t *cmd, ...);
|
||||
BTDIMPORT void (*bt_send_l2cap_ptr)(uint16_t local_cid, uint8_t *data, uint16_t len);
|
||||
BTDIMPORT void (*run_loop_init_ptr)(RUN_LOOP_TYPE type);
|
||||
BTDIMPORT void (*run_loop_execute_ptr)(void);
|
||||
|
||||
BTDIMPORT const hci_cmd_t* btstack_set_power_mode_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_delete_stored_link_key_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_disconnect_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_read_bd_addr_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_inquiry_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_inquiry_cancel_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_pin_code_request_reply_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_pin_code_request_negative_reply_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_remote_name_request_ptr;
|
||||
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;
|
||||
BTDIMPORT const hci_cmd_t* l2cap_decline_connection_ptr;
|
||||
|
||||
#endif
|
@ -335,8 +335,6 @@ INPUT
|
||||
#endif
|
||||
|
||||
#ifdef IOS
|
||||
#include "../apple/iOS/bluetooth/btdynamic.c"
|
||||
#include "../apple/iOS/bluetooth/btpad.c"
|
||||
#include "../input/drivers_joypad/ios_joypad.c"
|
||||
#endif
|
||||
|
||||
@ -374,6 +372,8 @@ INPUT (HID)
|
||||
|
||||
#if defined(HAVE_LIBUSB)
|
||||
#include "../input/drivers_hid/libusb_hid.c"
|
||||
#elif defined(__APPLE__) && defined(IOS)
|
||||
#include "../input/drivers_hid/bstack_hid.c"
|
||||
#elif defined(__APPLE__) && !defined(IOS)
|
||||
#include "../input/drivers_hid/apple_hid.c"
|
||||
#endif
|
||||
|
@ -33,12 +33,53 @@
|
||||
#define _BTSTACK_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <boolean.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* btdynamic.h */
|
||||
|
||||
bool btstack_try_load(void);
|
||||
|
||||
void btstack_set_poweron(bool on);
|
||||
|
||||
#ifndef BUILDING_BTDYNAMIC
|
||||
#define BTDIMPORT extern
|
||||
#else
|
||||
#define BTDIMPORT
|
||||
#endif
|
||||
|
||||
BTDIMPORT int (*bt_open_ptr)(void);
|
||||
BTDIMPORT void (*bt_close_ptr)(void);
|
||||
BTDIMPORT void (*bt_flip_addr_ptr)(bd_addr_t dest, bd_addr_t src);
|
||||
BTDIMPORT char* (*bd_addr_to_str_ptr)(bd_addr_t addr);
|
||||
BTDIMPORT btstack_packet_handler_t (*bt_register_packet_handler_ptr)
|
||||
(btstack_packet_handler_t handler);
|
||||
BTDIMPORT int (*bt_send_cmd_ptr)(const hci_cmd_t *cmd, ...);
|
||||
BTDIMPORT void (*bt_send_l2cap_ptr)(uint16_t local_cid, uint8_t *data, uint16_t len);
|
||||
BTDIMPORT void (*run_loop_init_ptr)(RUN_LOOP_TYPE type);
|
||||
BTDIMPORT void (*run_loop_execute_ptr)(void);
|
||||
|
||||
BTDIMPORT const hci_cmd_t* btstack_set_power_mode_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_delete_stored_link_key_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_disconnect_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_read_bd_addr_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_inquiry_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_inquiry_cancel_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_pin_code_request_reply_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_pin_code_request_negative_reply_ptr;
|
||||
BTDIMPORT const hci_cmd_t* hci_remote_name_request_ptr;
|
||||
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;
|
||||
BTDIMPORT const hci_cmd_t* l2cap_decline_connection_ptr;
|
||||
|
||||
/* hci_cmds.h */
|
||||
|
||||
/**
|
@ -21,10 +21,148 @@
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CFRunLoop.h>
|
||||
#endif
|
||||
#include <rthreads/rthreads.h>
|
||||
|
||||
#include "btdynamic.h"
|
||||
#define BUILDING_BTDYNAMIC
|
||||
#include "btstack.h"
|
||||
#include "../input/connect/joypad_connection.h"
|
||||
#include "../../dynamic.h"
|
||||
#include "../connect/joypad_connection.h"
|
||||
|
||||
#define GRAB(A) {#A, (void**)&A##_ptr}
|
||||
|
||||
static struct
|
||||
{
|
||||
const char* name;
|
||||
void** target;
|
||||
} grabbers[] =
|
||||
{
|
||||
GRAB(bt_open),
|
||||
GRAB(bt_close),
|
||||
GRAB(bt_flip_addr),
|
||||
GRAB(bd_addr_to_str),
|
||||
GRAB(bt_register_packet_handler),
|
||||
GRAB(bt_send_cmd),
|
||||
GRAB(bt_send_l2cap),
|
||||
GRAB(run_loop_init),
|
||||
GRAB(run_loop_execute),
|
||||
|
||||
GRAB(btstack_set_power_mode),
|
||||
GRAB(hci_delete_stored_link_key),
|
||||
GRAB(hci_disconnect),
|
||||
GRAB(hci_read_bd_addr),
|
||||
GRAB(hci_inquiry),
|
||||
GRAB(hci_inquiry_cancel),
|
||||
GRAB(hci_pin_code_request_reply),
|
||||
GRAB(hci_pin_code_request_negative_reply),
|
||||
GRAB(hci_remote_name_request),
|
||||
GRAB(hci_remote_name_request_cancel),
|
||||
GRAB(hci_write_authentication_enable),
|
||||
GRAB(hci_write_inquiry_mode),
|
||||
GRAB(l2cap_create_channel),
|
||||
GRAB(l2cap_register_service),
|
||||
GRAB(l2cap_accept_connection),
|
||||
GRAB(l2cap_decline_connection),
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
extern void btpad_packet_handler(uint8_t packet_type,
|
||||
uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static bool btstack_tested;
|
||||
static bool btstack_loaded;
|
||||
|
||||
static sthread_t *btstack_thread;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static CFRunLoopSourceRef btstack_quit_source;
|
||||
#endif
|
||||
|
||||
bool btstack_try_load(void)
|
||||
{
|
||||
unsigned i;
|
||||
void *handle = NULL;
|
||||
|
||||
if (btstack_tested)
|
||||
return btstack_loaded;
|
||||
|
||||
btstack_tested = true;
|
||||
btstack_loaded = false;
|
||||
|
||||
handle = dylib_load("/usr/lib/libBTstack.dylib");
|
||||
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
for (i = 0; grabbers[i].name; i ++)
|
||||
{
|
||||
*grabbers[i].target = dylib_proc(handle, grabbers[i].name);
|
||||
|
||||
if (!*grabbers[i].target)
|
||||
{
|
||||
dylib_close(handle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
run_loop_init_ptr(RUN_LOOP_COCOA);
|
||||
bt_register_packet_handler_ptr(btpad_packet_handler);
|
||||
|
||||
btstack_loaded = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void btstack_thread_stop(void *data)
|
||||
{
|
||||
(void)data;
|
||||
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_OFF);
|
||||
}
|
||||
|
||||
static void btstack_thread_func(void* data)
|
||||
{
|
||||
RARCH_LOG("[BTstack]: Thread started");
|
||||
|
||||
if (bt_open_ptr())
|
||||
return;
|
||||
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopSourceContext ctx = { 0, 0, 0, 0, 0, 0, 0, 0, 0, btstack_thread_stop };
|
||||
btstack_quit_source = CFRunLoopSourceCreate(0, 0, &ctx);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), btstack_quit_source, kCFRunLoopCommonModes);
|
||||
#endif
|
||||
|
||||
RARCH_LOG("[BTstack]: Turning on...\n");
|
||||
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON);
|
||||
|
||||
RARCH_LOG("BTstack: Thread running...\n");
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopRun();
|
||||
#endif
|
||||
|
||||
RARCH_LOG("[BTstack]: Thread done.\n");
|
||||
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopSourceInvalidate(btstack_quit_source);
|
||||
CFRelease(btstack_quit_source);
|
||||
#endif
|
||||
}
|
||||
|
||||
void btstack_set_poweron(bool on)
|
||||
{
|
||||
if (!btstack_try_load())
|
||||
return;
|
||||
|
||||
if (on && !btstack_thread)
|
||||
btstack_thread = sthread_create(btstack_thread_func, NULL);
|
||||
else if (!on && btstack_thread && btstack_quit_source)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
CFRunLoopSourceSignal(btstack_quit_source);
|
||||
#endif
|
||||
sthread_join(btstack_thread);
|
||||
btstack_thread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern joypad_connection_t *slots;
|
||||
|
Loading…
x
Reference in New Issue
Block a user