usbdev: move usbdev_req function to common code

Move usbdev_req function to common code, Reduce duplicated code.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
This commit is contained in:
zhangyuan21
2023-07-06 13:57:42 +08:00
committed by Xiang Xiao
parent d8ca744052
commit 602d5974c8
12 changed files with 174 additions and 510 deletions
+2 -56
View File
@@ -74,10 +74,6 @@ static int composite_classsetup(FAR struct composite_dev_s *priv,
FAR struct usbdev_s *dev,
FAR const struct usb_ctrlreq_s *ctrl, FAR uint8_t *dataout,
size_t outlen);
static struct usbdev_req_s *composite_allocreq(FAR struct usbdev_ep_s *ep,
uint16_t len);
static void composite_freereq(FAR struct usbdev_ep_s *ep,
FAR struct usbdev_req_s *req);
/* USB class device *********************************************************/
@@ -281,56 +277,6 @@ static int composite_msftdescriptor(FAR struct composite_dev_s *priv,
}
#endif
/****************************************************************************
* Name: composite_allocreq
*
* Description:
* Allocate a request instance along with its buffer
*
****************************************************************************/
static struct usbdev_req_s *composite_allocreq(FAR struct usbdev_ep_s *ep,
uint16_t len)
{
FAR struct usbdev_req_s *req;
req = EP_ALLOCREQ(ep);
if (req != NULL)
{
req->len = len;
req->buf = EP_ALLOCBUFFER(ep, len);
if (!req->buf)
{
EP_FREEREQ(ep, req);
req = NULL;
}
}
return req;
}
/****************************************************************************
* Name: composite_freereq
*
* Description:
* Free a request instance along with its buffer
*
****************************************************************************/
static void composite_freereq(FAR struct usbdev_ep_s *ep,
FAR struct usbdev_req_s *req)
{
if (ep != NULL && req != NULL)
{
if (req->buf != NULL)
{
EP_FREEBUFFER(ep, req->buf);
}
EP_FREEREQ(ep, req);
}
}
/****************************************************************************
* USB Class Driver Methods
****************************************************************************/
@@ -366,7 +312,7 @@ static int composite_bind(FAR struct usbdevclass_driver_s *driver,
/* Preallocate one control request */
priv->ctrlreq = composite_allocreq(dev->ep0, priv->cfgdescsize);
priv->ctrlreq = usbdev_allocreq(dev->ep0, priv->cfgdescsize);
if (priv->ctrlreq == NULL)
{
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_ALLOCCTRLREQ), 0);
@@ -460,7 +406,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver,
priv->config = COMPOSITE_CONFIGIDNONE;
if (priv->ctrlreq != NULL)
{
composite_freereq(dev->ep0, priv->ctrlreq);
usbdev_freereq(dev->ep0, priv->ctrlreq);
priv->ctrlreq = NULL;
}