First coarse run to fix coding style in locm3.

Added --terse and --mailback options to the make stylecheck target. It
also does continue even if it enounters a possible error.

We decided on two exceptions from the linux kernel coding standard:
- Empty wait while loops may end with ; on the same line.
- All blocks after while, if, for have to be in brackets even if they
  only contain one statement. Otherwise it is easy to introduce an
  error.

Checkpatch needs to be adapted to reflect those changes.
This commit is contained in:
Piotr Esden-Tempski
2013-06-12 17:44:07 -07:00
parent 48e0f3326b
commit 7df63fcae0
147 changed files with 3323 additions and 2565 deletions

View File

@@ -6,7 +6,8 @@
@version 1.0.0
@author @htmlonly &copy; @endhtmlonly 2010 Gareth McMullin <gareth@blacksphere.co.nz>
@author @htmlonly &copy; @endhtmlonly 2010
Gareth McMullin <gareth@blacksphere.co.nz>
@date 10 March 2013
@@ -61,8 +62,8 @@ LGPL License Terms @ref lgpl_license
* @return Zero on success (currently cannot fail).
*/
usbd_device *usbd_init(const usbd_driver *driver,
const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf,
const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf,
const char **strings, int num_strings,
u8 *control_buffer, u16 control_buffer_size)
{
@@ -117,8 +118,9 @@ void _usbd_reset(usbd_device *usbd_dev)
usbd_ep_setup(usbd_dev, 0, USB_ENDPOINT_ATTR_CONTROL, 64, NULL);
usbd_dev->driver->set_address(usbd_dev, 0);
if (usbd_dev->user_callback_reset)
if (usbd_dev->user_callback_reset) {
usbd_dev->user_callback_reset();
}
}
/* Functions to wrap the low-level driver */
@@ -130,8 +132,9 @@ void usbd_poll(usbd_device *usbd_dev)
void usbd_disconnect(usbd_device *usbd_dev, bool disconnected)
{
/* not all drivers support disconnection */
if (usbd_dev->driver->disconnect)
if (usbd_dev->driver->disconnect) {
usbd_dev->driver->disconnect(usbd_dev, disconnected);
}
}
void usbd_ep_setup(usbd_device *usbd_dev, u8 addr, u8 type, u16 max_size,

View File

@@ -6,7 +6,8 @@
@version 1.0.0
@author @htmlonly &copy; @endhtmlonly 2010 Gareth McMullin <gareth@blacksphere.co.nz>
@author @htmlonly &copy; @endhtmlonly 2010
Gareth McMullin <gareth@blacksphere.co.nz>
@date 10 March 2013
@@ -45,8 +46,9 @@ int usbd_register_control_callback(usbd_device *usbd_dev, u8 type, u8 type_mask,
int i;
for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++) {
if (usbd_dev->user_control_callback[i].cb)
if (usbd_dev->user_control_callback[i].cb) {
continue;
}
usbd_dev->user_control_callback[i].type = type;
usbd_dev->user_control_callback[i].type_mask = type_mask;
@@ -59,7 +61,8 @@ int usbd_register_control_callback(usbd_device *usbd_dev, u8 type, u8 type_mask,
static void usb_control_send_chunk(usbd_device *usbd_dev)
{
if (usbd_dev->desc->bMaxPacketSize0 < usbd_dev->control_state.ctrl_len) {
if (usbd_dev->desc->bMaxPacketSize0 <
usbd_dev->control_state.ctrl_len) {
/* Data stage, normal transmission */
usbd_ep_write_packet(usbd_dev, 0,
usbd_dev->control_state.ctrl_buf,
@@ -108,8 +111,9 @@ static int usb_control_request_dispatch(usbd_device *usbd_dev,
/* Call user command hook function. */
for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++) {
if (cb[i].cb == NULL)
if (cb[i].cb == NULL) {
break;
}
if ((req->bmRequestType & cb[i].type_mask) == cb[i].type) {
result = cb[i].cb(usbd_dev, req,
@@ -117,11 +121,12 @@ static int usb_control_request_dispatch(usbd_device *usbd_dev,
&(usbd_dev->control_state.ctrl_len),
&(usbd_dev->control_state.complete));
if (result == USBD_REQ_HANDLED ||
result == USBD_REQ_NOTSUPP)
result == USBD_REQ_NOTSUPP) {
return result;
}
}
}
/* Try standard request if not already handled. */
return _usbd_standard_request(usbd_dev, req,
&(usbd_dev->control_state.ctrl_buf),
@@ -162,10 +167,11 @@ static void usb_control_setup_write(usbd_device *usbd_dev,
usbd_dev->control_state.ctrl_buf = usbd_dev->ctrl_buf;
usbd_dev->control_state.ctrl_len = 0;
/* Wait for DATA OUT stage. */
if (req->wLength > usbd_dev->desc->bMaxPacketSize0)
if (req->wLength > usbd_dev->desc->bMaxPacketSize0) {
usbd_dev->control_state.state = DATA_OUT;
else
} else {
usbd_dev->control_state.state = LAST_DATA_OUT;
}
}
/* Do not appear to belong to the API, so are omitted from docs */
@@ -198,16 +204,19 @@ void _usbd_control_out(usbd_device *usbd_dev, u8 ea)
switch (usbd_dev->control_state.state) {
case DATA_OUT:
if (usb_control_recv_chunk(usbd_dev) < 0)
if (usb_control_recv_chunk(usbd_dev) < 0) {
break;
}
if ((usbd_dev->control_state.req.wLength -
usbd_dev->control_state.ctrl_len) <=
usbd_dev->desc->bMaxPacketSize0)
usbd_dev->desc->bMaxPacketSize0) {
usbd_dev->control_state.state = LAST_DATA_OUT;
}
break;
case LAST_DATA_OUT:
if (usb_control_recv_chunk(usbd_dev) < 0)
if (usb_control_recv_chunk(usbd_dev) < 0) {
break;
}
/*
* We have now received the full data payload.
* Invoke callback to process.
@@ -224,9 +233,10 @@ void _usbd_control_out(usbd_device *usbd_dev, u8 ea)
case STATUS_OUT:
usbd_ep_read_packet(usbd_dev, 0, NULL, 0);
usbd_dev->control_state.state = IDLE;
if (usbd_dev->control_state.complete)
if (usbd_dev->control_state.complete) {
usbd_dev->control_state.complete(usbd_dev,
&(usbd_dev->control_state.req));
}
usbd_dev->control_state.complete = NULL;
break;
default:
@@ -247,14 +257,16 @@ void _usbd_control_in(usbd_device *usbd_dev, u8 ea)
usbd_dev->control_state.state = STATUS_OUT;
break;
case STATUS_IN:
if (usbd_dev->control_state.complete)
if (usbd_dev->control_state.complete) {
usbd_dev->control_state.complete(usbd_dev,
&(usbd_dev->control_state.req));
}
/* Exception: Handle SET ADDRESS function here... */
if ((req->bmRequestType == 0) &&
(req->bRequest == USB_REQ_SET_ADDRESS))
(req->bRequest == USB_REQ_SET_ADDRESS)) {
usbd_dev->driver->set_address(usbd_dev, req->wValue);
}
usbd_dev->control_state.state = IDLE;
break;
default:

View File

@@ -86,12 +86,14 @@ static void usb_set_ep_rx_bufsize(usbd_device *dev, u8 ep, u32 size)
{
(void)dev;
if (size > 62) {
if (size & 0x1f)
if (size & 0x1f) {
size -= 32;
}
USB_SET_EP_RX_COUNT(ep, (size << 5) | 0x8000);
} else {
if (size & 1)
if (size & 1) {
size++;
}
USB_SET_EP_RX_COUNT(ep, size << 10);
}
}
@@ -153,9 +155,10 @@ static void stm32f103_endpoints_reset(usbd_device *dev)
static void stm32f103_ep_stall_set(usbd_device *dev, u8 addr, u8 stall)
{
(void)dev;
if (addr == 0)
if (addr == 0) {
USB_SET_EP_TX_STAT(addr, stall ? USB_EP_TX_STAT_STALL :
USB_EP_TX_STAT_NAK);
}
if (addr & 0x80) {
addr &= 0x7F;
@@ -164,12 +167,14 @@ static void stm32f103_ep_stall_set(usbd_device *dev, u8 addr, u8 stall)
USB_EP_TX_STAT_NAK);
/* Reset to DATA0 if clearing stall condition. */
if (!stall)
if (!stall) {
USB_CLR_EP_TX_DTOG(addr);
}
} else {
/* Reset to DATA0 if clearing stall condition. */
if (!stall)
if (!stall) {
USB_CLR_EP_RX_DTOG(addr);
}
USB_SET_EP_RX_STAT(addr, stall ? USB_EP_RX_STAT_STALL :
USB_EP_RX_STAT_VALID);
@@ -195,13 +200,15 @@ static void stm32f103_ep_nak_set(usbd_device *dev, u8 addr, u8 nak)
{
(void)dev;
/* It does not make sence to force NAK on IN endpoints. */
if (addr & 0x80)
if (addr & 0x80) {
return;
}
force_nak[addr] = nak;
if (nak)
if (nak) {
USB_SET_EP_RX_STAT(addr, USB_EP_RX_STAT_NAK);
}
else
USB_SET_EP_RX_STAT(addr, USB_EP_RX_STAT_VALID);
}
@@ -218,8 +225,9 @@ static void usb_copy_to_pm(volatile void *vPM, const void *buf, u16 len)
const u16 *lbuf = buf;
volatile u16 *PM = vPM;
for (len = (len + 1) >> 1; len; PM += 2, lbuf++, len--)
for (len = (len + 1) >> 1; len; PM += 2, lbuf++, len--) {
*PM = *lbuf;
}
}
static u16 stm32f103_ep_write_packet(usbd_device *dev, u8 addr,
@@ -228,8 +236,9 @@ static u16 stm32f103_ep_write_packet(usbd_device *dev, u8 addr,
(void)dev;
addr &= 0x7F;
if ((*USB_EP_REG(addr) & USB_EP_TX_STAT) == USB_EP_TX_STAT_VALID)
if ((*USB_EP_REG(addr) & USB_EP_TX_STAT) == USB_EP_TX_STAT_VALID) {
return 0;
}
usb_copy_to_pm(USB_GET_EP_TX_BUFF(addr), buf, len);
USB_SET_EP_TX_COUNT(addr, len);
@@ -251,26 +260,30 @@ static void usb_copy_from_pm(void *buf, const volatile void *vPM, u16 len)
const volatile u16 *PM = vPM;
u8 odd = len & 1;
for (len >>= 1; len; PM += 2, lbuf++, len--)
for (len >>= 1; len; PM += 2, lbuf++, len--) {
*lbuf = *PM;
}
if (odd)
if (odd) {
*(u8 *) lbuf = *(u8 *) PM;
}
}
static u16 stm32f103_ep_read_packet(usbd_device *dev, u8 addr, void *buf,
u16 len)
{
(void)dev;
if ((*USB_EP_REG(addr) & USB_EP_RX_STAT) == USB_EP_RX_STAT_VALID)
if ((*USB_EP_REG(addr) & USB_EP_RX_STAT) == USB_EP_RX_STAT_VALID) {
return 0;
}
len = MIN(USB_GET_EP_RX_COUNT(addr) & 0x3ff, len);
usb_copy_from_pm(buf, USB_GET_EP_RX_BUFF(addr), len);
USB_CLR_EP_RX_CTR(addr);
if (!force_nak[addr])
if (!force_nak[addr]) {
USB_SET_EP_RX_STAT(addr, USB_EP_RX_STAT_VALID);
}
return len;
}
@@ -295,27 +308,31 @@ static void stm32f103_poll(usbd_device *dev)
else /* IN transaction */
USB_CLR_EP_TX_CTR(ep);
if (dev->user_callback_ctr[ep][type])
if (dev->user_callback_ctr[ep][type]) {
dev->user_callback_ctr[ep][type] (dev, ep);
else
} else {
USB_CLR_EP_RX_CTR(ep);
}
}
if (istr & USB_ISTR_SUSP) {
USB_CLR_ISTR_SUSP();
if (dev->user_callback_suspend)
if (dev->user_callback_suspend) {
dev->user_callback_suspend();
}
}
if (istr & USB_ISTR_WKUP) {
USB_CLR_ISTR_WKUP();
if (dev->user_callback_resume)
if (dev->user_callback_resume) {
dev->user_callback_resume();
}
}
if (istr & USB_ISTR_SOF) {
if (dev->user_callback_sof)
if (dev->user_callback_sof) {
dev->user_callback_sof();
}
USB_CLR_ISTR_SOF();
}
}

View File

@@ -59,10 +59,10 @@ static usbd_device *stm32f107_usbd_init(void)
OTG_FS_GCCFG |= OTG_FS_GCCFG_VBUSBSEN | OTG_FS_GCCFG_PWRDWN;
/* Wait for AHB idle. */
while (!(OTG_FS_GRSTCTL & OTG_FS_GRSTCTL_AHBIDL)) ;
while (!(OTG_FS_GRSTCTL & OTG_FS_GRSTCTL_AHBIDL));
/* Do core soft reset. */
OTG_FS_GRSTCTL |= OTG_FS_GRSTCTL_CSRST;
while (OTG_FS_GRSTCTL & OTG_FS_GRSTCTL_CSRST) ;
while (OTG_FS_GRSTCTL & OTG_FS_GRSTCTL_CSRST);
/* Force peripheral only mode. */
OTG_FS_GUSBCFG |= OTG_FS_GUSBCFG_FDMOD | OTG_FS_GUSBCFG_TRDT_MASK;

View File

@@ -59,10 +59,10 @@ static usbd_device *stm32f207_usbd_init(void)
OTG_HS_GCCFG |= OTG_HS_GCCFG_VBUSBSEN | OTG_HS_GCCFG_PWRDWN;
/* Wait for AHB idle. */
while (!(OTG_HS_GRSTCTL & OTG_HS_GRSTCTL_AHBIDL)) ;
while (!(OTG_HS_GRSTCTL & OTG_HS_GRSTCTL_AHBIDL));
/* Do core soft reset. */
OTG_HS_GRSTCTL |= OTG_HS_GRSTCTL_CSRST;
while (OTG_HS_GRSTCTL & OTG_HS_GRSTCTL_CSRST) ;
while (OTG_HS_GRSTCTL & OTG_HS_GRSTCTL_CSRST);
/* Force peripheral only mode. */
OTG_HS_GUSBCFG |= OTG_HS_GUSBCFG_FDMOD | OTG_HS_GUSBCFG_TRDT_MASK;

View File

@@ -29,9 +29,9 @@
/* The FS core and the HS core have the same register layout.
* As the code can be used on both cores, the registers offset is modified
* according to the selected cores base address. */
#define dev_base_address (usbd_dev->driver->base_address)
#define REBASE(x) MMIO32((x)+(dev_base_address))
#define REBASE_FIFO(x) ((volatile u32*)((dev_base_address) + (OTG_FIFO(x))))
#define dev_base_address (usbd_dev->driver->base_address)
#define REBASE(x) MMIO32((x)+(dev_base_address))
#define REBASE_FIFO(x) ((volatile u32*)((dev_base_address) + (OTG_FIFO(x))))
void stm32fx07_set_address(usbd_device *usbd_dev, u8 addr)
{
@@ -59,6 +59,7 @@ void stm32fx07_ep_setup(usbd_device *usbd_dev, u8 addr, u8 type, u16 max_size,
} else {
REBASE(OTG_DIEPCTL0) = OTG_FS_DIEPCTL0_MPSIZ_8;
}
REBASE(OTG_DIEPTSIZ0) =
(max_size & OTG_FS_DIEPSIZ0_XFRSIZ_MASK);
REBASE(OTG_DIEPCTL0) |=
@@ -122,10 +123,11 @@ void stm32fx07_endpoints_reset(usbd_device *usbd_dev)
void stm32fx07_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall)
{
if (addr == 0) {
if (stall)
if (stall) {
REBASE(OTG_DIEPCTL(addr)) |= OTG_FS_DIEPCTL0_STALL;
else
} else {
REBASE(OTG_DIEPCTL(addr)) &= ~OTG_FS_DIEPCTL0_STALL;
}
}
if (addr & 0x80) {
@@ -150,26 +152,29 @@ void stm32fx07_ep_stall_set(usbd_device *usbd_dev, u8 addr, u8 stall)
u8 stm32fx07_ep_stall_get(usbd_device *usbd_dev, u8 addr)
{
/* Return non-zero if STALL set. */
if (addr & 0x80)
if (addr & 0x80) {
return (REBASE(OTG_DIEPCTL(addr & 0x7f)) &
OTG_FS_DIEPCTL0_STALL) ? 1 : 0;
else
} else {
return (REBASE(OTG_DOEPCTL(addr)) &
OTG_FS_DOEPCTL0_STALL) ? 1 : 0;
}
}
void stm32fx07_ep_nak_set(usbd_device *usbd_dev, u8 addr, u8 nak)
{
/* It does not make sence to force NAK on IN endpoints. */
if (addr & 0x80)
if (addr & 0x80) {
return;
}
usbd_dev->force_nak[addr] = nak;
if (nak)
if (nak) {
REBASE(OTG_DOEPCTL(addr)) |= OTG_FS_DOEPCTL0_SNAK;
else
} else {
REBASE(OTG_DOEPCTL(addr)) |= OTG_FS_DOEPCTL0_CNAK;
}
}
u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr,
@@ -181,8 +186,9 @@ u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr,
addr &= 0x7F;
/* Return if endpoint is already enabled. */
if (REBASE(OTG_DIEPTSIZ(addr)) & OTG_FS_DIEPSIZ0_PKTCNT)
if (REBASE(OTG_DIEPTSIZ(addr)) & OTG_FS_DIEPSIZ0_PKTCNT) {
return 0;
}
/* Enable endpoint for transmission. */
REBASE(OTG_DIEPTSIZ(addr)) = OTG_FS_DIEPSIZ0_PKTCNT | len;
@@ -191,8 +197,9 @@ u16 stm32fx07_ep_write_packet(usbd_device *usbd_dev, u8 addr,
volatile u32 *fifo = REBASE_FIFO(addr);
/* Copy buffer to endpoint FIFO, note - memcpy does not work */
for (i = len; i > 0; i -= 4)
for (i = len; i > 0; i -= 4) {
*fifo++ = *buf32++;
}
return len;
}
@@ -207,8 +214,9 @@ u16 stm32fx07_ep_read_packet(usbd_device *usbd_dev, u8 addr, void *buf, u16 len)
usbd_dev->rxbcnt -= len;
volatile u32 *fifo = REBASE_FIFO(addr);
for (i = len; i >= 4; i -= 4)
for (i = len; i >= 4; i -= 4) {
*buf32++ = *fifo++;
}
if (i) {
extra = *fifo++;
@@ -243,15 +251,17 @@ void stm32fx07_poll(usbd_device *usbd_dev)
u32 rxstsp = REBASE(OTG_GRXSTSP);
u32 pktsts = rxstsp & OTG_FS_GRXSTSP_PKTSTS_MASK;
if ((pktsts != OTG_FS_GRXSTSP_PKTSTS_OUT) &&
(pktsts != OTG_FS_GRXSTSP_PKTSTS_SETUP))
(pktsts != OTG_FS_GRXSTSP_PKTSTS_SETUP)) {
return;
}
u8 ep = rxstsp & OTG_FS_GRXSTSP_EPNUM_MASK;
u8 type;
if (pktsts == OTG_FS_GRXSTSP_PKTSTS_SETUP)
if (pktsts == OTG_FS_GRXSTSP_PKTSTS_SETUP) {
type = USB_TRANSACTION_SETUP;
else
} else {
type = USB_TRANSACTION_OUT;
}
/* Save packet size for stm32f107_ep_read_packet(). */
usbd_dev->rxbcnt = (rxstsp & OTG_FS_GRXSTSP_BCNT_MASK) >> 4;
@@ -261,15 +271,18 @@ void stm32fx07_poll(usbd_device *usbd_dev)
* This appears to fix a problem where the first 4 bytes
* of the DATA OUT stage of a control transaction are lost.
*/
for (i = 0; i < 1000; i++)
for (i = 0; i < 1000; i++) {
__asm__("nop");
}
if (usbd_dev->user_callback_ctr[ep][type])
if (usbd_dev->user_callback_ctr[ep][type]) {
usbd_dev->user_callback_ctr[ep][type] (usbd_dev, ep);
}
/* Discard unread packet data. */
for (i = 0; i < usbd_dev->rxbcnt; i += 4)
for (i = 0; i < usbd_dev->rxbcnt; i += 4) {
(void)*REBASE_FIFO(ep);
}
usbd_dev->rxbcnt = 0;
}
@@ -281,29 +294,33 @@ void stm32fx07_poll(usbd_device *usbd_dev)
for (i = 0; i < 4; i++) { /* Iterate over endpoints. */
if (REBASE(OTG_DIEPINT(i)) & OTG_FS_DIEPINTX_XFRC) {
/* Transfer complete. */
if (usbd_dev->user_callback_ctr[i][USB_TRANSACTION_IN])
if (usbd_dev->user_callback_ctr[i][USB_TRANSACTION_IN]) {
usbd_dev->user_callback_ctr[i]
[USB_TRANSACTION_IN](usbd_dev, i);
}
REBASE(OTG_DIEPINT(i)) = OTG_FS_DIEPINTX_XFRC;
}
}
if (intsts & OTG_FS_GINTSTS_USBSUSP) {
if (usbd_dev->user_callback_suspend)
if (usbd_dev->user_callback_suspend) {
usbd_dev->user_callback_suspend();
}
REBASE(OTG_GINTSTS) = OTG_FS_GINTSTS_USBSUSP;
}
if (intsts & OTG_FS_GINTSTS_WKUPINT) {
if (usbd_dev->user_callback_resume)
if (usbd_dev->user_callback_resume) {
usbd_dev->user_callback_resume();
}
REBASE(OTG_GINTSTS) = OTG_FS_GINTSTS_WKUPINT;
}
if (intsts & OTG_FS_GINTSTS_SOF) {
if (usbd_dev->user_callback_sof)
if (usbd_dev->user_callback_sof) {
usbd_dev->user_callback_sof();
}
REBASE(OTG_GINTSTS) = OTG_FS_GINTSTS_SOF;
}
}

View File

@@ -39,7 +39,7 @@ LGPL License Terms @ref lgpl_license
#define MAX_USER_CONTROL_CALLBACK 4
#define MIN(a, b) ((a)<(b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/** Internal collection of device information. */
struct _usbd_device {
@@ -68,7 +68,7 @@ struct _usbd_device {
DATA_IN, LAST_DATA_IN, STATUS_IN,
DATA_OUT, LAST_DATA_OUT, STATUS_OUT,
} state;
struct usb_setup_data req __attribute__((aligned(4)));
struct usb_setup_data req __aligned(4);
u8 *ctrl_buf;
u16 ctrl_len;
void (*complete)(usbd_device *usbd_dev,
@@ -92,18 +92,18 @@ struct _usbd_device {
uint16_t fifo_mem_top;
uint16_t fifo_mem_top_ep0;
u8 force_nak[4];
/*
* We keep a backup copy of the out endpoint size registers to restore them
* after a transaction.
*/
u32 doeptsiz[4];
/*
* Received packet size for each endpoint. This is assigned in
* stm32f107_poll() which reads the packet status push register GRXSTSP
* for use in stm32f107_ep_read_packet().
*/
uint16_t rxbcnt;
u8 force_nak[4];
/*
* We keep a backup copy of the out endpoint size registers to restore
* them after a transaction.
*/
u32 doeptsiz[4];
/*
* Received packet size for each endpoint. This is assigned in
* stm32f107_poll() which reads the packet status push register GRXSTSP
* for use in stm32f107_ep_read_packet().
*/
uint16_t rxbcnt;
};
enum _usbd_transaction {

View File

@@ -6,7 +6,8 @@
@version 1.0.0
@author @htmlonly &copy; @endhtmlonly 2010 Gareth McMullin <gareth@blacksphere.co.nz>
@author @htmlonly &copy; @endhtmlonly 2010
Gareth McMullin <gareth@blacksphere.co.nz>
@date 10 March 2013
@@ -40,7 +41,7 @@ LGPL License Terms @ref lgpl_license
void usbd_register_set_config_callback(usbd_device *usbd_dev,
void (*callback)(usbd_device *usbd_dev,
u16 wValue))
u16 wValue))
{
usbd_dev->user_callback_set_config = callback;
}
@@ -141,33 +142,43 @@ static int usb_standard_get_descriptor(usbd_device *usbd_dev,
if (descr_idx == 0) {
/* Send sane Language ID descriptor... */
sd->wData[0] = USB_LANGID_ENGLISH_US;
sd->bLength = sizeof(sd->bLength) + sizeof(sd->bDescriptorType)
+ sizeof(sd->wData[0]);
sd->bLength = sizeof(sd->bLength) +
sizeof(sd->bDescriptorType) +
sizeof(sd->wData[0]);
*len = MIN(*len, sd->bLength);
} else {
array_idx = descr_idx - 1;
if (!usbd_dev->strings)
return USBD_REQ_NOTSUPP; /* Device doesn't support strings. */
/* Check that string index is in range. */
if (array_idx >= usbd_dev->num_strings)
if (!usbd_dev->strings) {
/* Device doesn't support strings. */
return USBD_REQ_NOTSUPP;
}
/* Check that string index is in range. */
if (array_idx >= usbd_dev->num_strings) {
return USBD_REQ_NOTSUPP;
}
/* Strings with Language ID differnet from
* USB_LANGID_ENGLISH_US are not supported */
if (req->wIndex != USB_LANGID_ENGLISH_US)
if (req->wIndex != USB_LANGID_ENGLISH_US) {
return USBD_REQ_NOTSUPP;
}
/* Ths string is returned as UTF16, hence the multiplication */
/* Ths string is returned as UTF16, hence the
* multiplication
*/
sd->bLength = strlen(usbd_dev->strings[array_idx]) * 2 +
sizeof(sd->bLength) + sizeof(sd->bDescriptorType);
sizeof(sd->bLength) +
sizeof(sd->bDescriptorType);
*len = MIN(*len, sd->bLength);
for (i = 0; i < (*len / 2) - 1; i++)
for (i = 0; i < (*len / 2) - 1; i++) {
sd->wData[i] =
usbd_dev->strings[array_idx][i];
}
}
sd->bDescriptorType = USB_DT_STRING;
@@ -187,8 +198,9 @@ static int usb_standard_set_address(usbd_device *usbd_dev,
(void)len;
/* The actual address is only latched at the STATUS IN stage. */
if ((req->bmRequestType != 0) || (req->wValue >= 128))
if ((req->bmRequestType != 0) || (req->wValue >= 128)) {
return 0;
}
usbd_dev->current_address = req->wValue;
@@ -196,8 +208,9 @@ static int usb_standard_set_address(usbd_device *usbd_dev,
* Special workaround for STM32F10[57] that require the address
* to be set here. This is undocumented!
*/
if ( usbd_dev->driver->set_address_before_status)
if (usbd_dev->driver->set_address_before_status) {
usbd_dev->driver->set_address(usbd_dev, req->wValue);
}
return 1;
}
@@ -213,8 +226,9 @@ static int usb_standard_set_configuration(usbd_device *usbd_dev,
(void)len;
/* Is this correct, or should we reset alternate settings. */
if (req->wValue == usbd_dev->current_config)
if (req->wValue == usbd_dev->current_config) {
return 1;
}
usbd_dev->current_config = req->wValue;
@@ -226,8 +240,9 @@ static int usb_standard_set_configuration(usbd_device *usbd_dev,
* Flush control callbacks. These will be reregistered
* by the user handler.
*/
for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++)
for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++) {
usbd_dev->user_control_callback[i].cb = NULL;
}
usbd_dev->user_callback_set_config(usbd_dev, req->wValue);
}
@@ -241,8 +256,9 @@ static int usb_standard_get_configuration(usbd_device *usbd_dev,
{
(void)req;
if (*len > 1)
if (*len > 1) {
*len = 1;
}
(*buf)[0] = usbd_dev->current_config;
return 1;
@@ -257,8 +273,9 @@ static int usb_standard_set_interface(usbd_device *usbd_dev,
(void)buf;
/* FIXME: Adapt if we have more than one interface. */
if (req->wValue != 0)
if (req->wValue != 0) {
return 0;
}
*len = 0;
return 1;
@@ -288,8 +305,9 @@ static int usb_standard_device_get_status(usbd_device *usbd_dev,
/* bit 0: self powered */
/* bit 1: remote wakeup */
if (*len > 2)
if (*len > 2) {
*len = 2;
}
(*buf)[0] = 0;
(*buf)[1] = 0;
@@ -304,8 +322,9 @@ static int usb_standard_interface_get_status(usbd_device *usbd_dev,
(void)req;
/* not defined */
if (*len > 2)
if (*len > 2) {
*len = 2;
}
(*buf)[0] = 0;
(*buf)[1] = 0;
@@ -318,8 +337,9 @@ static int usb_standard_endpoint_get_status(usbd_device *usbd_dev,
{
(void)req;
if (*len > 2)
if (*len > 2) {
*len = 2;
}
(*buf)[0] = usbd_ep_stall_get(usbd_dev, req->wIndex) ? 1 : 0;
(*buf)[1] = 0;
@@ -366,9 +386,11 @@ int _usbd_standard_request_device(usbd_device *usbd_dev,
if (req->wValue == USB_FEAT_DEVICE_REMOTE_WAKEUP) {
/* Device wakeup code goes here. */
}
if (req->wValue == USB_FEAT_TEST_MODE) {
/* Test mode code goes here. */
}
break;
case USB_REQ_SET_ADDRESS:
/*
@@ -398,8 +420,9 @@ int _usbd_standard_request_device(usbd_device *usbd_dev,
break;
}
if (!command)
if (!command) {
return 0;
}
return command(usbd_dev, req, buf, len);
}
@@ -427,8 +450,9 @@ int _usbd_standard_request_interface(usbd_device *usbd_dev,
break;
}
if (!command)
if (!command) {
return 0;
}
return command(usbd_dev, req, buf, len);
}
@@ -442,12 +466,14 @@ int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
if (req->wValue == USB_FEAT_ENDPOINT_HALT)
if (req->wValue == USB_FEAT_ENDPOINT_HALT) {
command = usb_standard_endpoint_unstall;
}
break;
case USB_REQ_SET_FEATURE:
if (req->wValue == USB_FEAT_ENDPOINT_HALT)
if (req->wValue == USB_FEAT_ENDPOINT_HALT) {
command = usb_standard_endpoint_stall;
}
break;
case USB_REQ_GET_STATUS:
command = usb_standard_endpoint_get_status;
@@ -461,8 +487,9 @@ int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
break;
}
if (!command)
if (!command) {
return 0;
}
return command(usbd_dev, req, buf, len);
}
@@ -471,8 +498,9 @@ int _usbd_standard_request(usbd_device *usbd_dev,
struct usb_setup_data *req, u8 **buf, u16 *len)
{
/* FIXME: Have class/vendor requests as well. */
if ((req->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD)
if ((req->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD) {
return 0;
}
switch (req->bmRequestType & USB_REQ_TYPE_RECIPIENT) {
case USB_REQ_TYPE_DEVICE: