icE1usb fw: Move handling of device-wide request in usb_dev.c
We have upcoming ones not related to the E1 interface, so really it make more sense to not have those in usb_e1.c Signed-off-by: Sylvain Munaut <tnt@246tNt.com> Change-Id: I686916bb2b2cb90e94ac9c595deab19f189fcd49
This commit is contained in:
parent
00b57625bc
commit
caf8cf94e1
|
@ -50,6 +50,7 @@ HEADERS_app=\
|
|||
ice1usb_proto.h \
|
||||
misc.h \
|
||||
usb_desc_ids.h \
|
||||
usb_dev.h \
|
||||
usb_e1.h \
|
||||
usb_str_app.gen.h \
|
||||
$(NULL)
|
||||
|
@ -59,6 +60,7 @@ SOURCES_app=\
|
|||
fw_app.c \
|
||||
misc.c \
|
||||
usb_desc_app.c \
|
||||
usb_dev.c \
|
||||
usb_e1.c \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "misc.h"
|
||||
#include "mini-printf.h"
|
||||
#include "spi.h"
|
||||
#include "usb_dev.h"
|
||||
#include "usb_e1.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -97,6 +98,7 @@ void main()
|
|||
|
||||
/* Enable USB directly */
|
||||
usb_init(&app_stack_desc);
|
||||
usb_dev_init();
|
||||
usb_dfu_rt_init();
|
||||
usb_e1_init();
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* usb_dev.c
|
||||
*
|
||||
* Copyright (C) 2019-2022 Sylvain Munaut <tnt@246tNt.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <no2usb/usb.h>
|
||||
#include <no2usb/usb_proto.h>
|
||||
|
||||
#include "console.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include "ice1usb_proto.h"
|
||||
|
||||
|
||||
static enum usb_fnd_resp
|
||||
_usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer)
|
||||
{
|
||||
/* Check it's a device-wide vendor request */
|
||||
if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV))
|
||||
return USB_FND_CONTINUE;
|
||||
|
||||
/* Dispatch / Handle */
|
||||
switch (req->bRequest) {
|
||||
case ICE1USB_DEV_GET_CAPABILITIES:
|
||||
xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO);
|
||||
xfer->len = 1;
|
||||
break;
|
||||
default:
|
||||
return USB_FND_ERROR;
|
||||
}
|
||||
|
||||
return USB_FND_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static struct usb_fn_drv _dev_drv = {
|
||||
.ctrl_req = _usb_dev_ctrl_req,
|
||||
};
|
||||
|
||||
void
|
||||
usb_dev_init(void)
|
||||
{
|
||||
usb_register_function_driver(&_dev_drv);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* usb_dev.h
|
||||
*
|
||||
* Copyright (C) 2019-2022 Sylvain Munaut <tnt@246tNt.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void usb_dev_init(void);
|
|
@ -371,13 +371,16 @@ _set_rx_mode_done(struct usb_xfer *xfer)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* per-interface requests */
|
||||
static enum usb_fnd_resp
|
||||
_e1_ctrl_req_intf(struct usb_ctrl_req *req, struct usb_xfer *xfer)
|
||||
_e1_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer)
|
||||
{
|
||||
struct usb_e1_state *usb_e1;
|
||||
int port;
|
||||
|
||||
/* Check it's for an E1 interface */
|
||||
if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_INTF))
|
||||
return USB_FND_CONTINUE;
|
||||
|
||||
/* Get matching port (if any) */
|
||||
port = _ifnum2port(req->wIndex);
|
||||
if (port < 0)
|
||||
|
@ -424,42 +427,6 @@ _e1_ctrl_req_intf(struct usb_ctrl_req *req, struct usb_xfer *xfer)
|
|||
return USB_FND_SUCCESS;
|
||||
}
|
||||
|
||||
/* device-global requests */
|
||||
static enum usb_fnd_resp
|
||||
_e1_ctrl_req_dev(struct usb_ctrl_req *req, struct usb_xfer *xfer)
|
||||
{
|
||||
switch (req->bRequest) {
|
||||
case ICE1USB_DEV_GET_CAPABILITIES:
|
||||
xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO);
|
||||
xfer->len = 1;
|
||||
break;
|
||||
default:
|
||||
return USB_FND_ERROR;
|
||||
}
|
||||
|
||||
return USB_FND_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/* USB host issues a control request to us */
|
||||
static enum usb_fnd_resp
|
||||
_e1_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer)
|
||||
{
|
||||
if (USB_REQ_TYPE(req) != USB_REQ_TYPE_VENDOR)
|
||||
return USB_FND_CONTINUE;
|
||||
|
||||
switch (USB_REQ_RCPT(req)) {
|
||||
case USB_REQ_RCPT_DEV:
|
||||
return _e1_ctrl_req_dev(req, xfer);
|
||||
case USB_REQ_RCPT_INTF:
|
||||
return _e1_ctrl_req_intf(req, xfer);
|
||||
case USB_REQ_RCPT_EP:
|
||||
case USB_REQ_RCPT_OTHER:
|
||||
default:
|
||||
return USB_FND_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct usb_fn_drv _e1_drv = {
|
||||
.set_conf = _e1_set_conf,
|
||||
|
|
Loading…
Reference in New Issue