mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-18 16:28:51 +00:00
Simplify, add logging, revert some of the changes
== DETAILS The old code was crashing; I did a minimalized branch and the crash went away, so I'm bringing that over here. Meaning I'll have to redo some of the other work I'd put in, but oh well. (now watch it start crashing again) == TESTING Can confirm it builds. Wii U is busy ATM so I can't test.
This commit is contained in:
parent
1beba28d02
commit
192f5875b9
@ -10,8 +10,8 @@ ifneq ($(V), 1)
|
||||
Q := @
|
||||
endif
|
||||
|
||||
PC_DEVELOPMENT_IP_ADDRESS ?=
|
||||
PC_DEVELOPMENT_TCP_PORT ?=
|
||||
PC_DEVELOPMENT_IP_ADDRESS ?=192.168.29.137
|
||||
PC_DEVELOPMENT_TCP_PORT ?=4405
|
||||
|
||||
OBJ :=
|
||||
OBJ += input/drivers_hid/wiiu_hid.o
|
||||
|
@ -641,16 +641,7 @@ void _start(int argc, char **argv)
|
||||
memoryInitialize();
|
||||
__init();
|
||||
fsdev_init();
|
||||
#ifdef HAVE_HID
|
||||
HIDSetup();
|
||||
#endif
|
||||
|
||||
main(argc, argv);
|
||||
|
||||
#ifdef HAVE_HID
|
||||
HIDTeardown();
|
||||
#endif
|
||||
|
||||
fsdev_exit();
|
||||
|
||||
/* TODO: fix elf2rpl so it doesn't error with "Could not find matching symbol
|
||||
|
@ -14,19 +14,17 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wiiu/os.h>
|
||||
#include <wiiu/syshid.h>
|
||||
|
||||
#include "../input_defines.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../connect/joypad_connection.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
<<<<<<< HEAD
|
||||
#define POLL_THREAD_SLEEP 10000
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
@ -78,17 +76,21 @@ struct wiiu_hid_user
|
||||
uint32_t transfersize;
|
||||
uint32_t handle;
|
||||
};
|
||||
=======
|
||||
#define DEVICE_UNUSED 0
|
||||
#define DEVICE_USED 1
|
||||
#define ALIGN_POINTER sizeof(void *)
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
|
||||
typedef struct wiiu_hid
|
||||
{
|
||||
HIDClient *client;
|
||||
OSThread *polling_thread;
|
||||
// memory accounting; keep a pointer to the stack buffer so we can clean up later.
|
||||
void *polling_thread_stack;
|
||||
// setting this to true tells the polling thread to quit
|
||||
volatile bool polling_thread_quit;
|
||||
HIDClient *client;
|
||||
OSThread *polling_thread;
|
||||
void *polling_thread_stack;
|
||||
volatile bool polling_thread_quit;
|
||||
} wiiu_hid_t;
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> More progress on the HID driver
|
||||
/*
|
||||
@ -102,11 +104,15 @@ static wiiu_hid_t *new_wiiu_hid_t(void);
|
||||
static void delete_wiiu_hid_t(wiiu_hid_t *hid);
|
||||
static wiiu_hid_user_t *new_wiiu_hid_user_t(void);
|
||||
static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user);
|
||||
=======
|
||||
void *alloc_zeroed(size_t alignment, size_t size);
|
||||
static wiiu_hid_t *new_hid(void);
|
||||
static void delete_hid(wiiu_hid_t *hid);
|
||||
static void delete_hidclient(HIDClient *client);
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
static HIDClient *new_hidclient(void);
|
||||
static void delete_hidclient(HIDClient *hid);
|
||||
static OSFastMutex *new_fastmutex(const char *name);
|
||||
static void delete_fastmutex(OSFastMutex *mutex);
|
||||
|
||||
<<<<<<< HEAD
|
||||
static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach);
|
||||
=======
|
||||
//static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach);
|
||||
@ -129,6 +135,12 @@ void delete_hid(wiiu_hid_t *hid);
|
||||
/**
|
||||
* HID driver entrypoints registered with hid_driver_t
|
||||
*/
|
||||
=======
|
||||
static void start_polling_thread(wiiu_hid_t *hid);
|
||||
static void stop_polling_thread(wiiu_hid_t *hid);
|
||||
static int wiiu_hid_polling_thread(int argc, const char **argv);
|
||||
static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach);
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
|
||||
static bool wiiu_hid_joypad_query(void *data, unsigned pad)
|
||||
{
|
||||
@ -137,15 +149,19 @@ static bool wiiu_hid_joypad_query(void *data, unsigned pad)
|
||||
|
||||
static const char *wiiu_hid_joypad_name(void *data, unsigned pad)
|
||||
{
|
||||
return NULL;
|
||||
/* TODO/FIXME - implement properly */
|
||||
if (pad >= MAX_USERS)
|
||||
return NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint64_t wiiu_hid_joypad_get_buttons(void *data, unsigned port)
|
||||
static void wiiu_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
|
||||
{
|
||||
(void)data;
|
||||
(void)port;
|
||||
|
||||
return 0;
|
||||
BIT256_CLEAR_ALL_PTR(state);
|
||||
}
|
||||
|
||||
static bool wiiu_hid_joypad_button(void *data, unsigned port, uint16_t joykey)
|
||||
@ -179,6 +195,7 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis)
|
||||
|
||||
static void *wiiu_hid_init(void)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
wiiu_hid_t *hid = new_hid();
|
||||
// HIDClient *client = new_hidclient();
|
||||
|
||||
@ -205,10 +222,35 @@ static void *wiiu_hid_init(void)
|
||||
// }
|
||||
|
||||
return NULL;
|
||||
=======
|
||||
HIDSetup();
|
||||
wiiu_hid_t *hid = new_hid();
|
||||
HIDClient *client = new_hidclient();
|
||||
if(!hid || !client) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
start_polling_thread(hid);
|
||||
if(!hid->polling_thread)
|
||||
goto error;
|
||||
|
||||
HIDAddClient(client, wiiu_attach_callback);
|
||||
hid->client = client;
|
||||
|
||||
return hid;
|
||||
|
||||
error:
|
||||
RARCH_LOG("[hid]: initialization failed. cleaning up.\n");
|
||||
stop_polling_thread(hid);
|
||||
delete_hid(hid);
|
||||
delete_hidclient(client);
|
||||
return NULL;
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
}
|
||||
|
||||
static void wiiu_hid_free(void *data)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
wiiu_hid_t *hid = (wiiu_hid_t*)data;
|
||||
|
||||
if (hid) {
|
||||
@ -243,24 +285,35 @@ static void free_pad_list(void) {
|
||||
/**
|
||||
* This is a no-op because polling is done with a worker thread.
|
||||
*/
|
||||
=======
|
||||
wiiu_hid_t *hid = (wiiu_hid_t*)data;
|
||||
|
||||
if (hid) {
|
||||
stop_polling_thread(hid);
|
||||
delete_hidclient(hid->client);
|
||||
delete_hid(hid);
|
||||
}
|
||||
HIDTeardown();
|
||||
}
|
||||
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
static void wiiu_hid_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation functions
|
||||
*/
|
||||
|
||||
static void start_polling_thread(wiiu_hid_t *hid) {
|
||||
RARCH_LOG("[hid]: starting polling thread.\n");
|
||||
OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2 |
|
||||
OS_THREAD_ATTRIB_STACK_USAGE;
|
||||
int32_t stack_size = 0x8000;
|
||||
// wild-ass guess. the patcher thread used 28 for the network threads (10 for BOTW).
|
||||
int32_t priority = 10;
|
||||
OSThread *thread = memalign(8, sizeof(OSThread));
|
||||
void *stack = memalign(32, stack_size);
|
||||
BOOL result;
|
||||
|
||||
int32_t stack_size = 0x8000;
|
||||
int32_t priority = 10;
|
||||
OSThread *thread = memalign(ALIGN_POINTER, sizeof(OSThread));
|
||||
void *stack = memalign(ALIGN_POINTER, stack_size);
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
@ -281,9 +334,19 @@ static void start_polling_thread(wiiu_hid_t *hid) {
|
||||
if(!thread || !stack)
|
||||
>>>>>>> Only call HIDSetup/HidTeardown once
|
||||
goto error;
|
||||
|
||||
if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes))
|
||||
=======
|
||||
if(!thread || !stack) {
|
||||
RARCH_LOG("[hid]: allocation failed, aborting thread start.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
RARCH_LOG("[hid]: thread = %x; stack = %x\n", thread, stack);
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
|
||||
if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) {
|
||||
RARCH_LOG("[hid]: OSCreateThread failed.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
hid->polling_thread = thread;
|
||||
hid->polling_thread_stack = stack;
|
||||
@ -292,6 +355,7 @@ static void start_polling_thread(wiiu_hid_t *hid) {
|
||||
error:
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
if(pad_list_mutex)
|
||||
delete_fastmutex(pad_list_mutex);
|
||||
@ -305,26 +369,32 @@ static void start_polling_thread(wiiu_hid_t *hid) {
|
||||
>>>>>>> Only call HIDSetup/HidTeardown once
|
||||
if(stack)
|
||||
free(stack);
|
||||
=======
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
if(thread)
|
||||
free(thread);
|
||||
if(stack)
|
||||
free(stack);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void stop_polling_thread(wiiu_hid_t *hid) {
|
||||
int thread_result = 0;
|
||||
RARCH_LOG("[hid]: stopping polling thread.\n");
|
||||
|
||||
if(hid == NULL || hid->polling_thread == NULL)
|
||||
if(!hid || !hid->polling_thread)
|
||||
return;
|
||||
|
||||
hid->polling_thread_quit = true;
|
||||
OSJoinThread(hid->polling_thread, &thread_result);
|
||||
|
||||
free(hid->polling_thread);
|
||||
free(hid->polling_thread_stack);
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> More progress on the HID driver
|
||||
|
||||
@ -339,17 +409,18 @@ static void stop_polling_thread(wiiu_hid_t *hid) {
|
||||
>>>>>>> More progress on the HID driver
|
||||
=======
|
||||
>>>>>>> Only call HIDSetup/HidTeardown once
|
||||
=======
|
||||
hid->polling_thread = NULL;
|
||||
hid->polling_thread_stack = NULL;
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
}
|
||||
|
||||
/**
|
||||
* Entrypoint for the polling thread.
|
||||
*/
|
||||
static int wiiu_hid_polling_thread(int argc, const char **argv) {
|
||||
wiiu_hid_t *hid = (wiiu_hid_t *)argv;
|
||||
while(!hid->polling_thread_quit) {
|
||||
wiiu_hid_do_poll(hid);
|
||||
void log_device(HIDDevice *device) {
|
||||
if(!device) {
|
||||
RARCH_LOG("NULL device.\n");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -402,14 +473,35 @@ int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t atta
|
||||
break;
|
||||
case HID_DEVICE_DETACH:
|
||||
RARCH_LOG("Device detached\n");
|
||||
=======
|
||||
RARCH_LOG(" handle: %d\n", device->handle);
|
||||
RARCH_LOG(" physical_device_inst: %d\n", device->physical_device_inst);
|
||||
RARCH_LOG(" vid: 0x%x\n", device->vid);
|
||||
RARCH_LOG(" pid: 0x%x\n", device->pid);
|
||||
RARCH_LOG(" interface_index: %d\n", device->interface_index);
|
||||
RARCH_LOG(" sub_class: %d\n", device->sub_class);
|
||||
RARCH_LOG(" protocol: %d\n", device->protocol);
|
||||
RARCH_LOG(" max_packet_size_rx: %d\n", device->max_packet_size_rx);
|
||||
RARCH_LOG(" max_packet_size_tx: %d\n", device->max_packet_size_tx);
|
||||
}
|
||||
|
||||
static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) {
|
||||
switch(attach) {
|
||||
case HID_DEVICE_ATTACH:
|
||||
RARCH_LOG("USB device attach event\n");
|
||||
break;
|
||||
case HID_DEVICE_DETACH:
|
||||
RARCH_LOG("USB device detach event\n");
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
break;
|
||||
default:
|
||||
// Undefined behavior, bail out
|
||||
break;
|
||||
}
|
||||
log_device(device);
|
||||
|
||||
return result;
|
||||
return DEVICE_UNUSED;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
*/
|
||||
/**
|
||||
* Allocation
|
||||
@ -421,16 +513,27 @@ wiiu_hid_t *new_hid(void) {
|
||||
memset(hid, 0, sizeof(wiiu_hid_t));
|
||||
|
||||
return hid;
|
||||
}
|
||||
=======
|
||||
|
||||
void delete_hid(wiiu_hid_t *hid) {
|
||||
if(hid) {
|
||||
if(hid->polling_thread_stack)
|
||||
free(hid->polling_thread_stack);
|
||||
|
||||
free(hid);
|
||||
static int wiiu_hid_polling_thread(int argc, const char **argv) {
|
||||
wiiu_hid_t *hid = (wiiu_hid_t *)argv;
|
||||
while(!hid->polling_thread_quit) {
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static wiiu_hid_t *new_hid(void) {
|
||||
return alloc_zeroed(2, sizeof(wiiu_hid_t));
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
}
|
||||
|
||||
static void delete_hid(wiiu_hid_t *hid) {
|
||||
if(hid)
|
||||
free(hid);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
/*
|
||||
HIDClient *new_hidclient(void) {
|
||||
HIDClient *client = memalign(32, sizeof(HIDClient));
|
||||
@ -445,6 +548,28 @@ void delete_hidclient(HIDClient *client) {
|
||||
free(client);
|
||||
}
|
||||
*/
|
||||
=======
|
||||
|
||||
static HIDClient *new_hidclient(void) {
|
||||
return alloc_zeroed(32, sizeof(HIDClient));
|
||||
}
|
||||
|
||||
static void delete_hidclient(HIDClient *client) {
|
||||
if(client)
|
||||
free(client);
|
||||
}
|
||||
|
||||
void *alloc_zeroed(size_t alignment, size_t size) {
|
||||
void *result = memalign(alignment, size);
|
||||
if(result) {
|
||||
memset(result, 0, size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
>>>>>>> Simplify, add logging, revert some of the changes
|
||||
hid_driver_t wiiu_hid = {
|
||||
wiiu_hid_init,
|
||||
wiiu_hid_joypad_query,
|
||||
|
@ -1,14 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -z $1 ] ; then
|
||||
echo
|
||||
echo "usage: $0 <WiiU-ip>"
|
||||
echo
|
||||
exit 0
|
||||
fi
|
||||
|
||||
interrupt_count=0
|
||||
|
||||
trap 'if [ $interrupt_count -eq 20 ]; then exit 0; else interrupt_count=$(($interrupt_count + 1)); fi' INT
|
||||
trap 'if [ $interrupt_count -eq 5 ]; then exit 0; else interrupt_count=$(($interrupt_count + 1)); fi' INT
|
||||
|
||||
while true; do echo; echo ========= `date` =========; echo; netcat -p 4405 -l $1; done
|
||||
echo ===== START: `date` =====
|
||||
while true; do
|
||||
netcat -p 4405 -l
|
||||
if [ $? -ne 0 ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo ===== END: `date` =====
|
||||
|
Loading…
Reference in New Issue
Block a user