mirror of
https://github.com/libretro/RetroArch
synced 2025-02-22 12:40:09 +00:00
(connect_wii.c) Cleanups
This commit is contained in:
parent
f1a246c95e
commit
e0a5a77034
@ -162,7 +162,11 @@ typedef struct wiimote_t
|
|||||||
#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
|
#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
|
||||||
#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
|
#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
|
||||||
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
||||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
|
||||||
|
static bool wiimote_is_connected(struct wiimote_t *wm)
|
||||||
|
{
|
||||||
|
return WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send a packet to the wiimote.
|
* Send a packet to the wiimote.
|
||||||
@ -172,19 +176,17 @@ typedef struct wiimote_t
|
|||||||
static int wiimote_send(struct wiimote_t* wm,
|
static int wiimote_send(struct wiimote_t* wm,
|
||||||
uint8_t report_type, uint8_t* msg, int len)
|
uint8_t report_type, uint8_t* msg, int len)
|
||||||
{
|
{
|
||||||
int x = 2;
|
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
|
|
||||||
(void)x;
|
|
||||||
|
|
||||||
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
||||||
buf[1] = report_type;
|
buf[1] = report_type;
|
||||||
|
|
||||||
memcpy(buf+2, msg, len);
|
memcpy(buf+2, msg, len);
|
||||||
|
|
||||||
#ifdef WIIMOTE_DBG
|
#ifdef WIIMOTE_DBG
|
||||||
|
int x;
|
||||||
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
|
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
|
||||||
for (; x < len+2; ++x)
|
for (x = 2; x < len+2; ++x)
|
||||||
printf("%.2x ", buf[x]);
|
printf("%.2x ", buf[x]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
@ -202,7 +204,7 @@ static void wiimote_status(struct wiimote_t* wm)
|
|||||||
{
|
{
|
||||||
uint8_t buf = 0;
|
uint8_t buf = 0;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !wiimote_is_connected(wm))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef WIIMOTE_DBG
|
#ifdef WIIMOTE_DBG
|
||||||
@ -216,7 +218,7 @@ static void wiimote_data_report(struct wiimote_t* wm, uint8_t type)
|
|||||||
{
|
{
|
||||||
uint8_t buf[2] = {0x0,0x0};
|
uint8_t buf[2] = {0x0,0x0};
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !wiimote_is_connected(wm))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buf[1] = type;
|
buf[1] = type;
|
||||||
@ -239,27 +241,23 @@ static void wiimote_set_leds(struct wiimote_t* wm, int leds)
|
|||||||
{
|
{
|
||||||
uint8_t buf;
|
uint8_t buf;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !wiimote_is_connected(wm))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Remove the lower 4 bits because they control rumble. */
|
/* Remove the lower 4 bits because they control rumble. */
|
||||||
wm->leds = (leds & 0xF0);
|
wm->leds = (leds & 0xF0);
|
||||||
|
|
||||||
buf = wm->leds;
|
buf = wm->leds;
|
||||||
|
|
||||||
wiimote_send(wm, WM_CMD_LED, &buf, 1);
|
wiimote_send(wm, WM_CMD_LED, &buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Find what buttons are pressed. */
|
||||||
* Find what buttons are pressed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void wiimote_pressed_buttons(struct wiimote_t* wm, uint8_t* msg)
|
static void wiimote_pressed_buttons(struct wiimote_t* wm, uint8_t* msg)
|
||||||
{
|
{
|
||||||
/* Convert to big endian. */
|
/* Convert to big endian. */
|
||||||
int16_t now = swap_if_little16(*(int16_t*)msg) & WIIMOTE_BUTTON_ALL;
|
int16_t *val = (int16_t*)msg;
|
||||||
|
int16_t now = swap_if_little16(*val) & WIIMOTE_BUTTON_ALL;
|
||||||
|
|
||||||
/* buttons pressed now. */
|
|
||||||
wm->btns = now;
|
wm->btns = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +304,11 @@ static void process_axis(struct axis_t* axis, uint8_t raw)
|
|||||||
|
|
||||||
static void classic_ctrl_event(struct classic_ctrl_t* cc, uint8_t* msg)
|
static void classic_ctrl_event(struct classic_ctrl_t* cc, uint8_t* msg)
|
||||||
{
|
{
|
||||||
|
if (!cc)
|
||||||
|
return;
|
||||||
|
|
||||||
cc->btns = ~swap_if_little16(*(int16_t*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL;
|
cc->btns = ~swap_if_little16(*(int16_t*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL;
|
||||||
|
|
||||||
process_axis(&cc->ljs.x, (msg[0] & 0x3F));
|
process_axis(&cc->ljs.x, (msg[0] & 0x3F));
|
||||||
process_axis(&cc->ljs.y, (msg[1] & 0x3F));
|
process_axis(&cc->ljs.y, (msg[1] & 0x3F));
|
||||||
process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) |
|
process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) |
|
||||||
@ -335,17 +337,16 @@ static void wiimote_handle_expansion(struct wiimote_t* wm, uint8_t* msg)
|
|||||||
static int wiimote_write_data(struct wiimote_t* wm,
|
static int wiimote_write_data(struct wiimote_t* wm,
|
||||||
uint32_t addr, uint8_t* data, uint8_t len)
|
uint32_t addr, uint8_t* data, uint8_t len)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
uint8_t buf[21] = {0}; /* the payload is always 23 */
|
uint8_t buf[21] = {0}; /* the payload is always 23 */
|
||||||
|
int32_t *buf32 = (int32_t*)buf;
|
||||||
|
|
||||||
(void)i;
|
if (!wm || !wiimote_is_connected(wm))
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
|
||||||
return 0;
|
return 0;
|
||||||
if (!data || !len)
|
if (!data || !len)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef WIIMOTE_DBG
|
#ifdef WIIMOTE_DBG
|
||||||
|
int i = 0;
|
||||||
printf("Writing %i bytes to memory location 0x%x...\n", len, addr);
|
printf("Writing %i bytes to memory location 0x%x...\n", len, addr);
|
||||||
printf("Write data is: ");
|
printf("Write data is: ");
|
||||||
for (; i < len; ++i)
|
for (; i < len; ++i)
|
||||||
@ -354,7 +355,7 @@ static int wiimote_write_data(struct wiimote_t* wm,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* the offset is in big endian */
|
/* the offset is in big endian */
|
||||||
*(int*)(buf) = swap_if_little32(addr);
|
*buf32 = swap_if_little32(addr);
|
||||||
|
|
||||||
/* length */
|
/* length */
|
||||||
*(uint8_t*)(buf + 4) = len;
|
*(uint8_t*)(buf + 4) = len;
|
||||||
@ -381,16 +382,17 @@ static int wiimote_read_data(struct wiimote_t* wm, uint32_t addr,
|
|||||||
uint16_t len)
|
uint16_t len)
|
||||||
{
|
{
|
||||||
uint8_t buf[6];
|
uint8_t buf[6];
|
||||||
|
int32_t *buf32 = (int32_t*)buf;
|
||||||
|
int16_t *buf16 = (int16_t*)(buf + 4);
|
||||||
|
|
||||||
/* No puden ser mas de 16 lo leido o vendra en trozos! */
|
/* No puden ser mas de 16 lo leido o vendra en trozos! */
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !len)
|
if (!wm || !wiimote_is_connected(wm) || !len)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* the offset is in big endian */
|
/* the offsets are in big endian */
|
||||||
*(int*)(buf) = swap_if_little32(addr);
|
*buf32 = swap_if_little32(addr);
|
||||||
/* the length is in big endian */
|
*buf16 = swap_if_little16(len);
|
||||||
*(int16_t*)(buf + 4) = swap_if_little16(len);
|
|
||||||
|
|
||||||
#ifdef WIIMOTE_DBG
|
#ifdef WIIMOTE_DBG
|
||||||
printf("Request read at address: 0x%x length: %i", addr, len);
|
printf("Request read at address: 0x%x length: %i", addr, len);
|
||||||
@ -455,6 +457,8 @@ static int wiimote_handshake(struct wiimote_t* wm,
|
|||||||
|
|
||||||
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||||
{
|
{
|
||||||
|
uint8_t buf;
|
||||||
|
|
||||||
/* Expansion port */
|
/* Expansion port */
|
||||||
|
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||||
@ -471,8 +475,6 @@ static int wiimote_handshake(struct wiimote_t* wm,
|
|||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t buf;
|
|
||||||
|
|
||||||
/*Old way. initialize the extension was by writing the
|
/*Old way. initialize the extension was by writing the
|
||||||
* single encryption byte 0x00 to 0x(4)A40040. */
|
* single encryption byte 0x00 to 0x(4)A40040. */
|
||||||
#if 0
|
#if 0
|
||||||
@ -484,12 +486,12 @@ static int wiimote_handshake(struct wiimote_t* wm,
|
|||||||
* 0x00 to 0x(4)A400FB. (support clones) */
|
* 0x00 to 0x(4)A400FB. (support clones) */
|
||||||
buf = 0x55;
|
buf = 0x55;
|
||||||
wiimote_write_data(wm, 0x04A400F0, &buf, 1);
|
wiimote_write_data(wm, 0x04A400F0, &buf, 1);
|
||||||
usleep(100000);
|
rarch_sleep(100);
|
||||||
buf = 0x00;
|
buf = 0x00;
|
||||||
wiimote_write_data(wm, 0x04A400FB, &buf, 1);
|
wiimote_write_data(wm, 0x04A400FB, &buf, 1);
|
||||||
|
|
||||||
/* check extension type! */
|
/* check extension type! */
|
||||||
usleep(100000);
|
rarch_sleep(100);
|
||||||
wiimote_read_data(wm, WM_EXP_MEM_CALIBR + 220, 4);
|
wiimote_read_data(wm, WM_EXP_MEM_CALIBR + 220, 4);
|
||||||
#if 0
|
#if 0
|
||||||
wiimote_read_data(wm, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
wiimote_read_data(wm, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||||
@ -543,10 +545,12 @@ static int wiimote_handshake(struct wiimote_t* wm,
|
|||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
int32_t *ptr = (int32_t*)data;
|
||||||
|
|
||||||
if (event != WM_RPT_READ)
|
if (event != WM_RPT_READ)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
id = swap_if_little32(*(int*)(data));
|
id = swap_if_little32(*data);
|
||||||
|
|
||||||
#ifdef WIIMOTE_DBG
|
#ifdef WIIMOTE_DBG
|
||||||
printf("Expansion id=0x%04x\n",id);
|
printf("Expansion id=0x%04x\n",id);
|
||||||
@ -563,7 +567,7 @@ static int wiimote_handshake(struct wiimote_t* wm,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
usleep(100000);
|
rarch_sleep(100);
|
||||||
/* pedimos datos de calibracion del JOY! */
|
/* pedimos datos de calibracion del JOY! */
|
||||||
wiimote_read_data(wm, WM_EXP_MEM_CALIBR, 16);
|
wiimote_read_data(wm, WM_EXP_MEM_CALIBR, 16);
|
||||||
wm->handshake_state = 5;
|
wm->handshake_state = 5;
|
||||||
@ -581,14 +585,22 @@ static int wiimote_handshake(struct wiimote_t* wm,
|
|||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
||||||
wm->handshake_state = 1;
|
wm->handshake_state = 1;
|
||||||
if(wm->unid==0)
|
|
||||||
|
switch (wm->unid)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
wiimote_set_leds(wm, WIIMOTE_LED_1);
|
wiimote_set_leds(wm, WIIMOTE_LED_1);
|
||||||
else if(wm->unid==1)
|
break;
|
||||||
|
case 1:
|
||||||
wiimote_set_leds(wm, WIIMOTE_LED_2);
|
wiimote_set_leds(wm, WIIMOTE_LED_2);
|
||||||
else if(wm->unid==2)
|
break;
|
||||||
|
case 2:
|
||||||
wiimote_set_leds(wm, WIIMOTE_LED_3);
|
wiimote_set_leds(wm, WIIMOTE_LED_3);
|
||||||
else if(wm->unid==3)
|
break;
|
||||||
|
case 3:
|
||||||
wiimote_set_leds(wm, WIIMOTE_LED_4);
|
wiimote_set_leds(wm, WIIMOTE_LED_4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user