(Apple) Change apple_pad_connection to pad_connection

This commit is contained in:
twinaphex 2014-10-04 18:31:37 +02:00
parent d2367b9342
commit c2c73c02b6
8 changed files with 38 additions and 48 deletions

View File

@ -33,7 +33,7 @@ enum btpad_state
BTPAD_CONNECTED BTPAD_CONNECTED
}; };
struct apple_pad_connection struct pad_connection
{ {
uint32_t slot; uint32_t slot;
@ -48,12 +48,11 @@ struct apple_pad_connection
static bool inquiry_off; static bool inquiry_off;
static bool inquiry_running; static bool inquiry_running;
static struct apple_pad_connection g_connections[MAX_PLAYERS]; static struct pad_connection g_connections[MAX_PLAYERS];
void apple_pad_send_control(void *data, uint8_t* data_buf, size_t size) void apple_pad_send_control(void *data, uint8_t* data_buf, size_t size)
{ {
struct apple_pad_connection *connection = struct pad_connection *connection = (struct pad_connection*)data;
(struct apple_pad_connection*)data;
if (connection) if (connection)
bt_send_l2cap_ptr(connection->channels[0], data_buf, size); bt_send_l2cap_ptr(connection->channels[0], data_buf, size);
@ -68,7 +67,7 @@ void btpad_set_inquiry_state(bool on)
} }
/* Internal interface. */ /* Internal interface. */
static struct apple_pad_connection* btpad_find_empty_connection(void) static struct pad_connection* btpad_find_empty_connection(void)
{ {
int i; int i;
for (i = 0; i != MAX_PLAYERS; i ++) for (i = 0; i != MAX_PLAYERS; i ++)
@ -78,7 +77,7 @@ static struct apple_pad_connection* btpad_find_empty_connection(void)
return 0; return 0;
} }
static struct apple_pad_connection* btpad_find_connection_for( static struct pad_connection* btpad_find_connection_for(
uint16_t handle, bd_addr_t address) uint16_t handle, bd_addr_t address)
{ {
int i; int i;
@ -101,8 +100,7 @@ static struct apple_pad_connection* btpad_find_connection_for(
return 0; return 0;
} }
static void btpad_close_connection( static void btpad_close_connection(struct pad_connection* connection)
struct apple_pad_connection* connection)
{ {
if (!connection) if (!connection)
return; return;
@ -110,7 +108,7 @@ static void btpad_close_connection(
if (connection->handle) if (connection->handle)
btpad_queue_hci_disconnect(connection->handle, 0x15); btpad_queue_hci_disconnect(connection->handle, 0x15);
memset(connection, 0, sizeof(struct apple_pad_connection)); memset(connection, 0, sizeof(struct pad_connection));
} }
static void btpad_close_all_connections(void) static void btpad_close_all_connections(void)
@ -131,8 +129,8 @@ void btpad_packet_handler(uint8_t packet_type,
case L2CAP_DATA_PACKET: case L2CAP_DATA_PACKET:
for (i = 0; i < MAX_PLAYERS; i ++) for (i = 0; i < MAX_PLAYERS; i ++)
{ {
struct apple_pad_connection* connection = struct pad_connection* connection =
(struct apple_pad_connection*)&g_connections[i]; (struct pad_connection*)&g_connections[i];
if (connection && connection->state == BTPAD_CONNECTED if (connection && connection->state == BTPAD_CONNECTED
&& (connection->channels[0] == channel || && (connection->channels[0] == channel ||
@ -198,14 +196,14 @@ void btpad_packet_handler(uint8_t packet_type,
{ {
bt_flip_addr_ptr(event_addr, &packet[3]); bt_flip_addr_ptr(event_addr, &packet[3]);
struct apple_pad_connection* connection = struct pad_connection* connection =
(struct apple_pad_connection*)btpad_find_empty_connection(); (struct pad_connection*)btpad_find_empty_connection();
if (!connection) if (!connection)
return; return;
RARCH_LOG("BTpad: Inquiry found device\n"); RARCH_LOG("BTpad: Inquiry found device\n");
memset(connection, 0, sizeof(struct apple_pad_connection)); memset(connection, 0, sizeof(struct pad_connection));
memcpy(connection->address, event_addr, sizeof(bd_addr_t)); memcpy(connection->address, event_addr, sizeof(bd_addr_t));
connection->has_address = true; connection->has_address = true;
@ -235,8 +233,8 @@ void btpad_packet_handler(uint8_t packet_type,
const uint16_t psm = READ_BT_16(packet, 11); const uint16_t psm = READ_BT_16(packet, 11);
const uint16_t channel_id = READ_BT_16(packet, 13); const uint16_t channel_id = READ_BT_16(packet, 13);
struct apple_pad_connection* connection = struct pad_connection* connection =
(struct apple_pad_connection*)btpad_find_connection_for( (struct pad_connection*)btpad_find_connection_for(
handle, event_addr); handle, event_addr);
if (!packet[2]) if (!packet[2])
@ -277,8 +275,8 @@ void btpad_packet_handler(uint8_t packet_type,
const uint32_t psm = READ_BT_16(packet, 10); const uint32_t psm = READ_BT_16(packet, 10);
const uint32_t channel_id = READ_BT_16(packet, 12); const uint32_t channel_id = READ_BT_16(packet, 12);
struct apple_pad_connection* connection = struct pad_connection* connection =
(struct apple_pad_connection*)btpad_find_connection_for( (struct pad_connection*)btpad_find_connection_for(
handle, event_addr); handle, event_addr);
if (!connection) if (!connection)
@ -290,7 +288,7 @@ void btpad_packet_handler(uint8_t packet_type,
RARCH_LOG("BTpad: Got new incoming connection\n"); RARCH_LOG("BTpad: Got new incoming connection\n");
memset(connection, 0, memset(connection, 0,
sizeof(struct apple_pad_connection)); sizeof(struct pad_connection));
memcpy(connection->address, event_addr, memcpy(connection->address, event_addr,
sizeof(bd_addr_t)); sizeof(bd_addr_t));
@ -309,8 +307,8 @@ void btpad_packet_handler(uint8_t packet_type,
{ {
bt_flip_addr_ptr(event_addr, &packet[3]); bt_flip_addr_ptr(event_addr, &packet[3]);
struct apple_pad_connection* connection = struct pad_connection* connection =
(struct apple_pad_connection*)btpad_find_connection_for( (struct pad_connection*)btpad_find_connection_for(
0, event_addr); 0, event_addr);
if (!connection) if (!connection)
@ -340,8 +338,8 @@ void btpad_packet_handler(uint8_t packet_type,
if (!packet[2]) if (!packet[2])
{ {
struct apple_pad_connection* connection = struct pad_connection* connection =
(struct apple_pad_connection*)btpad_find_connection_for( (struct pad_connection*)btpad_find_connection_for(
handle, 0); handle, 0);
if (connection) if (connection)

View File

@ -51,7 +51,7 @@ typedef struct
const rarch_joypad_driver_t *joypad; const rarch_joypad_driver_t *joypad;
} apple_input_data_t; } apple_input_data_t;
struct apple_pad_connection; struct pad_connection;
struct apple_pad_interface struct apple_pad_interface
{ {

View File

@ -31,7 +31,7 @@ typedef struct
static joypad_slot_t slots[MAX_PLAYERS]; static joypad_slot_t slots[MAX_PLAYERS];
struct apple_pad_connection struct pad_connection
{ {
int v_id; int v_id;
int p_id; int p_id;
@ -44,8 +44,7 @@ static IOHIDManagerRef g_hid_manager;
void apple_pad_send_control(void *data, uint8_t* data_buf, size_t size) void apple_pad_send_control(void *data, uint8_t* data_buf, size_t size)
{ {
struct apple_pad_connection* connection = struct pad_connection* connection = (struct pad_connection*)data;
(struct apple_pad_connection*)data;
if (connection) if (connection)
IOHIDDeviceSetReport(connection->device_handle, IOHIDDeviceSetReport(connection->device_handle,
@ -59,8 +58,7 @@ static void hid_device_input_callback(void* context, IOReturn result,
void* sender, IOHIDValueRef value) void* sender, IOHIDValueRef value)
{ {
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
struct apple_pad_connection* connection = (struct apple_pad_connection*) struct pad_connection* connection = (struct pad_connection*)context;
context;
IOHIDElementRef element = IOHIDValueGetElement(value); IOHIDElementRef element = IOHIDValueGetElement(value);
uint32_t type = IOHIDElementGetType(element); uint32_t type = IOHIDElementGetType(element);
uint32_t page = IOHIDElementGetUsagePage(element); uint32_t page = IOHIDElementGetUsagePage(element);
@ -134,8 +132,7 @@ static void hid_device_input_callback(void* context, IOReturn result,
static void remove_device(void* context, IOReturn result, void* sender) static void remove_device(void* context, IOReturn result, void* sender)
{ {
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
struct apple_pad_connection* connection = (struct apple_pad_connection*) struct pad_connection* connection = (struct pad_connection*)context;
context;
if (connection && connection->slot < MAX_PLAYERS) if (connection && connection->slot < MAX_PLAYERS)
{ {
@ -159,8 +156,7 @@ static void hid_device_report(void* context, IOReturn result, void *sender,
IOHIDReportType type, uint32_t reportID, uint8_t *report, IOHIDReportType type, uint32_t reportID, uint8_t *report,
CFIndex reportLength) CFIndex reportLength)
{ {
struct apple_pad_connection* connection = (struct apple_pad_connection*) struct pad_connection* connection = (struct pad_connection*)context;
context;
if (connection) if (connection)
apple_joypad_packet(connection->slot, connection->data, reportLength + 1); apple_joypad_packet(connection->slot, connection->data, reportLength + 1);
@ -172,7 +168,7 @@ static void add_device(void* context, IOReturn result,
char device_name[PATH_MAX]; char device_name[PATH_MAX];
CFStringRef device_name_ref; CFStringRef device_name_ref;
CFNumberRef vendorID, productID; CFNumberRef vendorID, productID;
struct apple_pad_connection* connection = (struct apple_pad_connection*) struct pad_connection* connection = (struct pad_connection*)
calloc(1, sizeof(*connection)); calloc(1, sizeof(*connection));
connection->device_handle = device; connection->device_handle = device;
@ -255,8 +251,7 @@ static int find_vacant_pad(void)
int32_t apple_joypad_connect(const char* name, void *data) int32_t apple_joypad_connect(const char* name, void *data)
{ {
struct apple_pad_connection* connection = struct pad_connection* connection = (struct pad_connection*)data;
(struct apple_pad_connection*)data;
int pad = find_vacant_pad(); int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS) if (pad >= 0 && pad < MAX_PLAYERS)

View File

@ -51,8 +51,7 @@ static int find_vacant_pad(void)
int32_t apple_joypad_connect(const char* name, void *data) int32_t apple_joypad_connect(const char* name, void *data)
{ {
struct apple_pad_connection* connection = struct pad_connection* connection = (struct pad_connection*)data;
(struct apple_pad_connection*)data;
int pad = find_vacant_pad(); int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS) if (pad >= 0 && pad < MAX_PLAYERS)

View File

@ -22,7 +22,7 @@
struct hidpad_ps3_data struct hidpad_ps3_data
{ {
struct apple_pad_connection* connection; struct pad_connection* connection;
uint8_t data[512]; uint8_t data[512];
uint32_t slot; uint32_t slot;
bool have_led; bool have_led;
@ -55,8 +55,7 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
static void* hidpad_ps3_connect(void *connect_data, uint32_t slot) static void* hidpad_ps3_connect(void *connect_data, uint32_t slot)
{ {
struct apple_pad_connection* connection = struct pad_connection* connection = (struct pad_connection*)connect_data;
(struct apple_pad_connection*)connect_data;
struct hidpad_ps3_data* device = (struct hidpad_ps3_data*) struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)
calloc(1, sizeof(struct hidpad_ps3_data)); calloc(1, sizeof(struct hidpad_ps3_data));

View File

@ -22,7 +22,7 @@
struct hidpad_ps4_data struct hidpad_ps4_data
{ {
struct apple_pad_connection* connection; struct pad_connection* connection;
uint8_t data[512]; uint8_t data[512];
uint32_t slot; uint32_t slot;
bool have_led; bool have_led;
@ -49,8 +49,7 @@ static void hidpad_ps4_send_control(struct hidpad_ps4_data* device)
static void* hidpad_ps4_connect(void *connect_data, uint32_t slot) static void* hidpad_ps4_connect(void *connect_data, uint32_t slot)
{ {
struct apple_pad_connection* connection = struct pad_connection* connection = (struct pad_connection*)connect_data;
(struct apple_pad_connection*)connect_data;
struct hidpad_ps4_data* device = (struct hidpad_ps4_data*) struct hidpad_ps4_data* device = (struct hidpad_ps4_data*)
calloc(1, sizeof(struct hidpad_ps4_data)); calloc(1, sizeof(struct hidpad_ps4_data));

View File

@ -22,8 +22,7 @@
static void* hidpad_wii_connect(void *data, uint32_t slot) static void* hidpad_wii_connect(void *data, uint32_t slot)
{ {
struct apple_pad_connection *connection = struct pad_connection *connection = (struct pad_connection*)data;
(struct apple_pad_connection*)data;
struct wiimote_t *device = (struct wiimote_t*) struct wiimote_t *device = (struct wiimote_t*)
calloc(1, sizeof(struct wiimote_t)); calloc(1, sizeof(struct wiimote_t));

View File

@ -171,8 +171,9 @@ typedef struct wiimote_t
{ {
/* User specified ID. */ /* User specified ID. */
int unid; int unid;
/* TODO/FIXME - refactor */
struct apple_pad_connection* connection; struct pad_connection* connection;
/* Various state flags. */ /* Various state flags. */
int state; int state;
/* Currently lit LEDs. */ /* Currently lit LEDs. */