Cosmetic changes from review of last PR

This commit is contained in:
Gregory Nutt 2017-03-18 06:47:34 -06:00
parent 148e74fd10
commit 175f8960cf

View File

@ -2,7 +2,8 @@
* drivers/usbhost/usbhost_xboxcontroller.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Authors: Gregory Nutt <gnutt@nuttx.org>
* Brian Webb <webbbn@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -143,7 +144,8 @@
#define XBOX_BUTTON_STICK_LEFT_Y 6
#define XBOX_BUTTON_STICK_RIGHT_X 7
#define XBOX_BUTTON_STICK_RIGHT_Y 8
#define XBOX_BUTTON_SET(buffer, index, mask) ((((buffer)[(index)] & (mask)) != 0) ? true : false);
#define XBOX_BUTTON_SET(buffer, index, mask) \
((((buffer)[(index)] & (mask)) != 0) ? true : false);
/****************************************************************************
* Private Types
@ -342,7 +344,7 @@ static void usbhost_takesem(sem_t *sem)
* awakened by a signal.
*/
ASSERT(errno == EINTR);
DEBUGASSERT(errno == EINTR);
}
}
@ -558,7 +560,7 @@ static void usbhost_notify(FAR struct usbhost_state_s *priv)
#ifndef CONFIG_DISABLE_POLL
for (i = 0; i < CONFIG_XBOXCONTROLLER_NPOLLWAITERS; i++)
{
struct pollfd *fds = priv->fds[i];
FAR struct pollfd *fds = priv->fds[i];
if (fds)
{
fds->revents |= POLLIN;
@ -640,7 +642,6 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
if (nbytes != -EAGAIN)
{
uerr("ERROR: DRVR_TRANSFER returned: %d/%u\n",
(int)nbytes, nerrors);
@ -657,23 +658,21 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
else
{
/* Success, reset the error counter */
nerrors = 0;
/* The type of message is in the first byte */
switch (priv->tbuffer[0])
{
case USBHOST_WAITING_CONNECTION:
/* Send the initialization message when we received the
* the first waiting connection message.
*/
if (!priv->initialized) {
if (!priv->initialized)
{
/* Get exclusive access to the controller state data */
usbhost_takesem(&priv->exclsem);
@ -695,7 +694,6 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
break;
case USBHOST_GUIDE_BUTTON_STATUS:
/* Get exclusive access to the controller state data */
usbhost_takesem(&priv->exclsem);
@ -703,15 +701,16 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
/* Read the data out of the controller report. */
priv->rpt.guide = (priv->tbuffer[XBOX_BUTTON_GUIDE_INDEX] != 0) ? true : false;
priv->valid = true;
/* The One X controller requires an ACK of the guide button status message. */
/* The One X controller requires an ACK of the guide button status
* message.
*/
if (priv->tbuffer[1] == 0x30)
{
static const uint8_t guide_button_report_ack[] = {
static const uint8_t guide_button_report_ack[] =
{
0x01, 0x20, 0x00, 0x09, 0x00, 0x07, 0x20, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00
};
@ -722,7 +721,8 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
/* Copy the ACK packet into the transfer buffer. */
memcpy(priv->tbuffer, guide_button_report_ack, sizeof(guide_button_report_ack));
memcpy(priv->tbuffer, guide_button_report_ack,
sizeof(guide_button_report_ack));
/* Ensure the sequence number is the same as the input packet. */
@ -730,8 +730,8 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
/* Perform the transfer. */
nbytes = DRVR_TRANSFER(hport->drvr, priv->epout,
priv->tbuffer, sizeof(guide_button_report_ack));
nbytes = DRVR_TRANSFER(hport->drvr, priv->epout, priv->tbuffer,
sizeof(guide_button_report_ack));
}
/* Notify any waiters that new controller data is available */
@ -745,7 +745,6 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
break;
case USBHOST_BUTTON_DATA:
/* Ignore the controller data if no task has opened the driver. */
if (priv->open)
@ -756,27 +755,62 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
/* Read the data out of the controller report. */
priv->rpt.sync = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_SYNC_INDEX, XBOX_BUTTON_SYNC_MASK);
priv->rpt.start = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_START_INDEX, XBOX_BUTTON_START_MASK);
priv->rpt.back = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_BACK_INDEX, XBOX_BUTTON_BACK_MASK);
priv->rpt.a = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_A_INDEX, XBOX_BUTTON_A_MASK);
priv->rpt.b = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_B_INDEX, XBOX_BUTTON_B_MASK);
priv->rpt.x = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_X_INDEX, XBOX_BUTTON_X_MASK);
priv->rpt.y = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_Y_INDEX, XBOX_BUTTON_Y_MASK);
priv->rpt.dpad_up = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_UP_INDEX, XBOX_BUTTON_DPAD_UP_MASK);
priv->rpt.dpad_down = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_DOWN_INDEX, XBOX_BUTTON_DPAD_DOWN_MASK);
priv->rpt.dpad_left = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_LEFT_INDEX, XBOX_BUTTON_DPAD_LEFT_MASK);
priv->rpt.dpad_right = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_RIGHT_INDEX, XBOX_BUTTON_DPAD_RIGHT_MASK);
priv->rpt.bumper_left = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_BUMPER_LEFT_INDEX, XBOX_BUTTON_BUMPER_LEFT_MASK);
priv->rpt.bumper_right = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_BUMPER_RIGHT_INDEX, XBOX_BUTTON_BUMPER_RIGHT_MASK);
priv->rpt.stick_click_left = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_STICK_LEFT_INDEX, XBOX_BUTTON_STICK_LEFT_MASK);
priv->rpt.stick_click_right = XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_STICK_RIGHT_INDEX, XBOX_BUTTON_STICK_RIGHT_MASK);
priv->rpt.trigger_left = ((int16_t*)(priv->tbuffer))[XBOX_BUTTON_TRIGGER_LEFT];
priv->rpt.trigger_right = ((int16_t*)(priv->tbuffer))[XBOX_BUTTON_TRIGGER_RIGHT];
priv->rpt.stick_left_x = ((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_LEFT_X];
priv->rpt.stick_left_y = ((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_LEFT_Y];
priv->rpt.stick_right_x = ((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_RIGHT_X];
priv->rpt.stick_right_y = ((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_RIGHT_Y];
priv->rpt.sync =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_SYNC_INDEX,
XBOX_BUTTON_SYNC_MASK);
priv->rpt.start =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_START_INDEX,
XBOX_BUTTON_START_MASK);
priv->rpt.back =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_BACK_INDEX,
XBOX_BUTTON_BACK_MASK);
priv->rpt.a =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_A_INDEX,
XBOX_BUTTON_A_MASK);
priv->rpt.b =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_B_INDEX,
XBOX_BUTTON_B_MASK);
priv->rpt.x =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_X_INDEX,
XBOX_BUTTON_X_MASK);
priv->rpt.y =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_Y_INDEX,
XBOX_BUTTON_Y_MASK);
priv->rpt.dpad_up =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_UP_INDEX,
XBOX_BUTTON_DPAD_UP_MASK);
priv->rpt.dpad_down =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_DOWN_INDEX,
XBOX_BUTTON_DPAD_DOWN_MASK);
priv->rpt.dpad_left =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_LEFT_INDEX,
XBOX_BUTTON_DPAD_LEFT_MASK);
priv->rpt.dpad_right =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_DPAD_RIGHT_INDEX,
XBOX_BUTTON_DPAD_RIGHT_MASK);
priv->rpt.bumper_left =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_BUMPER_LEFT_INDEX,
XBOX_BUTTON_BUMPER_LEFT_MASK);
priv->rpt.bumper_right =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_BUMPER_RIGHT_INDEX, XBOX_BUTTON_BUMPER_RIGHT_MASK);
priv->rpt.stick_click_left =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_STICK_LEFT_INDEX,
XBOX_BUTTON_STICK_LEFT_MASK);
priv->rpt.stick_click_right =
XBOX_BUTTON_SET(priv->tbuffer, XBOX_BUTTON_STICK_RIGHT_INDEX,
XBOX_BUTTON_STICK_RIGHT_MASK);
priv->rpt.trigger_left =
((int16_t*)(priv->tbuffer))[XBOX_BUTTON_TRIGGER_LEFT];
priv->rpt.trigger_right =
((int16_t*)(priv->tbuffer))[XBOX_BUTTON_TRIGGER_RIGHT];
priv->rpt.stick_left_x =
((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_LEFT_X];
priv->rpt.stick_left_y =
((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_LEFT_Y];
priv->rpt.stick_right_x =
((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_RIGHT_X];
priv->rpt.stick_right_y =
((int16_t*)(priv->tbuffer))[XBOX_BUTTON_STICK_RIGHT_Y];
priv->valid = true;
@ -792,11 +826,8 @@ static int usbhost_xboxcontroller_poll(int argc, char *argv[])
break;
default:
uinfo("Received messge type: %x\n", priv->tbuffer[0]);
}
}
/* If USB debug is on, then provide some periodic indication that
@ -1142,6 +1173,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
return -EINVAL;
}
found |= USBHOST_EPOUTFOUND;
/* Save the bulk OUT endpoint information */
@ -1199,7 +1231,7 @@ static inline int usbhost_cfgdesc(FAR struct usbhost_state_s *priv,
if (found == USBHOST_ALLFOUND)
{
done=true;
done = true;
}
/* Increment the address of the next descriptor */
@ -1563,6 +1595,7 @@ static FAR struct usbhost_class_s *usbhost_create(FAR struct usbhost_hubport_s *
{
usbhost_freeclass(priv);
}
return NULL;
}
@ -1785,7 +1818,6 @@ static int usbhost_open(FAR struct file *filep)
}
leave_critical_section(flags);
usbhost_givesem(&priv->exclsem);
return ret;
}
@ -1973,7 +2005,6 @@ errout:
static ssize_t usbhost_write(FAR struct file *filep, FAR const char *buffer,
size_t len)
{
/* Not implemented. */
return -ENOSYS;
@ -1994,7 +2025,8 @@ static int usbhost_ioctl(FAR struct file* filep, int cmd, unsigned long arg)
int ret = 0;
int nbytes;
FAR struct usbhost_hubport_s *hport;
static uint8_t rumble_cmd[] = {
static uint8_t rumble_cmd[] =
{
0x09, 0x00, 0x00, 0x09, 0x00, 0x0f, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0xff
};
@ -2021,6 +2053,7 @@ static int usbhost_ioctl(FAR struct file* filep, int cmd, unsigned long arg)
}
/* Determine which IOCTL command to execute. */
switch (cmd)
{