Standardized function parameter with xxx_class
This commit is contained in:
@@ -35,7 +35,7 @@ static uint32_t g_devinuse = 0;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *priv)
|
||||
static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
size_t flags;
|
||||
int devno;
|
||||
@@ -45,7 +45,7 @@ static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *priv)
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
priv->minor = devno;
|
||||
cdc_acm_class->minor = devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -63,9 +63,9 @@ static int usbh_cdc_acm_devno_alloc(struct usbh_cdc_acm *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *priv)
|
||||
static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *cdc_acm_class)
|
||||
{
|
||||
int devno = priv->minor;
|
||||
int devno = cdc_acm_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
size_t flags = usb_osal_enter_critical_section();
|
||||
@@ -74,25 +74,18 @@ static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *priv)
|
||||
}
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_set_line_coding(struct usbh_hubport *hport, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
struct usb_setup_packet *setup = cdc_acm_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (cdc_acm_class->ctrl_intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = CDC_REQUEST_SET_LINE_CODING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = cdc_acm_class->ctrl_intf;
|
||||
setup->wLength = 7;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)line_coding);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport->ep0, setup, (uint8_t *)line_coding);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -100,25 +93,18 @@ int usbh_cdc_acm_set_line_coding(struct usbh_hubport *hport, uint8_t intf, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_hubport *hport, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
struct usb_setup_packet *setup = cdc_acm_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (cdc_acm_class->ctrl_intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = CDC_REQUEST_GET_LINE_CODING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = cdc_acm_class->ctrl_intf;
|
||||
setup->wLength = 7;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, (uint8_t *)line_coding);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport->ep0, setup, (uint8_t *)line_coding);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -126,25 +112,18 @@ int usbh_cdc_acm_get_line_coding(struct usbh_hubport *hport, uint8_t intf, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_set_line_state(struct usbh_hubport *hport, uint8_t intf, bool dtr, bool rts)
|
||||
int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts)
|
||||
{
|
||||
struct usb_setup_packet *setup = cdc_acm_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (cdc_acm_class->ctrl_intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE;
|
||||
setup->wValue = (dtr << 0) | (rts << 1);
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = cdc_acm_class->ctrl_intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, NULL);
|
||||
ret = usbh_control_transfer(cdc_acm_class->hport->ep0, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -155,7 +134,7 @@ int usbh_cdc_acm_set_line_state(struct usbh_hubport *hport, uint8_t intf, bool d
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
@@ -169,6 +148,8 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
memset(cdc_acm_class, 0, sizeof(struct usbh_cdc_acm));
|
||||
cdc_acm_class->hport = hport;
|
||||
cdc_acm_class->ctrl_intf = intf;
|
||||
cdc_acm_class->data_intf = intf + 1;
|
||||
|
||||
usbh_cdc_acm_devno_alloc(cdc_acm_class);
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, cdc_acm_class->minor);
|
||||
@@ -181,19 +162,17 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
USB_LOG_ERR("Fail to alloc linecoding\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
cdc_acm_class->ctrl_intf = intf;
|
||||
cdc_acm_class->data_intf = intf + 1;
|
||||
|
||||
cdc_acm_class->linecoding->dwDTERate = 115200;
|
||||
cdc_acm_class->linecoding->bDataBits = 8;
|
||||
cdc_acm_class->linecoding->bParityType = 0;
|
||||
cdc_acm_class->linecoding->bCharFormat = 0;
|
||||
ret = usbh_cdc_acm_set_line_coding(hport, intf, cdc_acm_class->linecoding);
|
||||
ret = usbh_cdc_acm_set_line_coding(cdc_acm_class, cdc_acm_class->linecoding);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbh_cdc_acm_set_line_state(hport, intf, true, true);
|
||||
ret = usbh_cdc_acm_set_line_state(cdc_acm_class, true, true);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -230,7 +209,7 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ struct usbh_cdc_acm {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
|
||||
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
|
||||
int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -31,11 +31,11 @@ static uint32_t g_devinuse = 0;
|
||||
* Name: usbh_hid_devno_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate a unique /dev/hid[n] minor number in the range 0-31.
|
||||
* Allocate a unique /dev/input[n] minor number in the range 0-31.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_hid_devno_alloc(struct usbh_hid *priv)
|
||||
static int usbh_hid_devno_alloc(struct usbh_hid *hid_class)
|
||||
{
|
||||
size_t flags;
|
||||
int devno;
|
||||
@@ -45,7 +45,7 @@ static int usbh_hid_devno_alloc(struct usbh_hid *priv)
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
priv->minor = devno;
|
||||
hid_class->minor = devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -59,13 +59,13 @@ static int usbh_hid_devno_alloc(struct usbh_hid *priv)
|
||||
* Name: usbh_hid_devno_free
|
||||
*
|
||||
* Description:
|
||||
* Free a /dev/hid[n] minor number so that it can be used.
|
||||
* Free a /dev/input[n] minor number so that it can be used.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_hid_devno_free(struct usbh_hid *priv)
|
||||
static void usbh_hid_devno_free(struct usbh_hid *hid_class)
|
||||
{
|
||||
int devno = priv->minor;
|
||||
int devno = hid_class->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
size_t flags = usb_osal_enter_critical_section();
|
||||
@@ -74,45 +74,32 @@ static void usbh_hid_devno_free(struct usbh_hid *priv)
|
||||
}
|
||||
}
|
||||
|
||||
int usbh_hid_get_report_descriptor(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
struct usb_setup_packet *setup = hid_class->hport->setup;
|
||||
int ret;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
setup->wValue = HID_DESCRIPTOR_TYPE_HID_REPORT << 8;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = hid_class->intf;
|
||||
setup->wLength = 128;
|
||||
|
||||
return usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
return usbh_control_transfer(hid_class->hport->ep0, setup, buffer);
|
||||
}
|
||||
|
||||
int usbh_hid_set_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration)
|
||||
{
|
||||
struct usb_setup_packet *setup = hid_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_SET_IDLE;
|
||||
setup->wValue = report_id;
|
||||
setup->wIndex = (duration << 8) | intf;
|
||||
setup->wIndex = (duration << 8) | hid_class->intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, NULL);
|
||||
ret = usbh_control_transfer(hid_class->hport->ep0, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -120,25 +107,18 @@ int usbh_hid_set_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t report_i
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hid_get_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup = hid_class->hport->setup;
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_GET_IDLE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = hid_class->intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
ret = usbh_control_transfer(hid_class->hport->ep0, setup, buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -160,20 +140,20 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
memset(hid_class, 0, sizeof(struct usbh_hid));
|
||||
hid_class->hport = hport;
|
||||
|
||||
hid_class->intf = intf;
|
||||
|
||||
usbh_hid_devno_alloc(hid_class);
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, hid_class->minor);
|
||||
|
||||
hport->config.intf[intf].priv = hid_class;
|
||||
hid_class->intf = intf;
|
||||
|
||||
ret = usbh_hid_set_idle(hport, intf, 0, 0);
|
||||
ret = usbh_hid_set_idle(hid_class, 0, 0);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t *report_buffer = usb_iomalloc(128);
|
||||
ret = usbh_hid_get_report_descriptor(hport, intf, report_buffer);
|
||||
ret = usbh_hid_get_report_descriptor(hid_class, report_buffer);
|
||||
if (ret < 0) {
|
||||
usb_iofree(report_buffer);
|
||||
return ret;
|
||||
|
||||
@@ -38,6 +38,9 @@ struct usbh_hid {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration);
|
||||
int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -37,14 +37,14 @@ extern void usbh_hport_deactivate(struct usbh_hubport *hport);
|
||||
|
||||
static void usbh_external_hub_callback(void *arg, int nbytes);
|
||||
|
||||
static inline void usbh_hub_register(struct usbh_hub *hub)
|
||||
static inline void usbh_hub_register(struct usbh_hub *hub_class)
|
||||
{
|
||||
usb_slist_add_tail(&hub_class_head, &hub->list);
|
||||
usb_slist_add_tail(&hub_class_head, &hub_class->list);
|
||||
}
|
||||
|
||||
static inline void usbh_hub_unregister(struct usbh_hub *hub)
|
||||
static inline void usbh_hub_unregister(struct usbh_hub *hub_class)
|
||||
{
|
||||
usb_slist_remove(&hub_class_head, &hub->list);
|
||||
usb_slist_remove(&hub_class_head, &hub_class->list);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -55,7 +55,7 @@ static inline void usbh_hub_unregister(struct usbh_hub *hub)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_hub_devno_alloc(struct usbh_hub *hub)
|
||||
static int usbh_hub_devno_alloc(struct usbh_hub *hub_class)
|
||||
{
|
||||
size_t flags;
|
||||
int devno;
|
||||
@@ -65,7 +65,7 @@ static int usbh_hub_devno_alloc(struct usbh_hub *hub)
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
hub->index = devno;
|
||||
hub_class->index = devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -83,9 +83,9 @@ static int usbh_hub_devno_alloc(struct usbh_hub *hub)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_hub_devno_free(struct usbh_hub *hub)
|
||||
static void usbh_hub_devno_free(struct usbh_hub *hub_class)
|
||||
{
|
||||
int devno = hub->index;
|
||||
int devno = hub_class->index;
|
||||
|
||||
if (devno >= 2 && devno < 32) {
|
||||
size_t flags = usb_osal_enter_critical_section();
|
||||
@@ -94,11 +94,11 @@ static void usbh_hub_devno_free(struct usbh_hub *hub)
|
||||
}
|
||||
}
|
||||
|
||||
int usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
||||
static int usbh_hub_get_hub_descriptor(struct usbh_hub *hub_class, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
|
||||
setup = hub->parent->setup;
|
||||
setup = hub_class->parent->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
@@ -106,14 +106,14 @@ int usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = USB_SIZEOF_HUB_DESC;
|
||||
|
||||
return usbh_control_transfer(hub->parent->ep0, setup, buffer);
|
||||
return usbh_control_transfer(hub_class->parent->ep0, setup, buffer);
|
||||
}
|
||||
|
||||
int usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
|
||||
static int usbh_hub_get_status(struct usbh_hub *hub_class, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
|
||||
setup = hub->parent->setup;
|
||||
setup = hub_class->parent->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = HUB_REQUEST_GET_STATUS;
|
||||
@@ -121,14 +121,14 @@ int usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 2;
|
||||
|
||||
return usbh_control_transfer(hub->parent->ep0, setup, buffer);
|
||||
return usbh_control_transfer(hub_class->parent->ep0, setup, buffer);
|
||||
}
|
||||
|
||||
int usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_status *port_status)
|
||||
static int usbh_hub_get_portstatus(struct usbh_hub *hub_class, uint8_t port, struct hub_port_status *port_status)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
|
||||
setup = hub->parent->setup;
|
||||
setup = hub_class->parent->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
||||
setup->bRequest = HUB_REQUEST_GET_STATUS;
|
||||
@@ -136,14 +136,14 @@ int usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_
|
||||
setup->wIndex = port;
|
||||
setup->wLength = 4;
|
||||
|
||||
return usbh_control_transfer(hub->parent->ep0, setup, (uint8_t *)port_status);
|
||||
return usbh_control_transfer(hub_class->parent->ep0, setup, (uint8_t *)port_status);
|
||||
}
|
||||
|
||||
int usbh_hub_set_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
||||
static int usbh_hub_set_feature(struct usbh_hub *hub_class, uint8_t port, uint8_t feature)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
|
||||
setup = hub->parent->setup;
|
||||
setup = hub_class->parent->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
||||
setup->bRequest = HUB_REQUEST_SET_FEATURE;
|
||||
@@ -151,14 +151,14 @@ int usbh_hub_set_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
||||
setup->wIndex = port;
|
||||
setup->wLength = 0;
|
||||
|
||||
return usbh_control_transfer(hub->parent->ep0, setup, NULL);
|
||||
return usbh_control_transfer(hub_class->parent->ep0, setup, NULL);
|
||||
}
|
||||
|
||||
int usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
||||
static int usbh_hub_clear_feature(struct usbh_hub *hub_class, uint8_t port, uint8_t feature)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
|
||||
setup = hub->parent->setup;
|
||||
setup = hub_class->parent->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
||||
setup->bRequest = HUB_REQUEST_CLEAR_FEATURE;
|
||||
@@ -166,7 +166,7 @@ int usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
||||
setup->wIndex = port;
|
||||
setup->wLength = 0;
|
||||
|
||||
return usbh_control_transfer(hub->parent->ep0, setup, NULL);
|
||||
return usbh_control_transfer(hub_class->parent->ep0, setup, NULL);
|
||||
}
|
||||
|
||||
static int parse_hub_descriptor(struct usb_hub_descriptor *desc, uint16_t length)
|
||||
@@ -191,7 +191,7 @@ static int parse_hub_descriptor(struct usb_hub_descriptor *desc, uint16_t length
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
@@ -204,6 +204,8 @@ int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
memset(hub_class, 0, sizeof(struct usbh_hub));
|
||||
hub_class->dev_addr = hport->dev_addr;
|
||||
hub_class->parent = hport;
|
||||
|
||||
hub_class->port_status = usb_iomalloc(sizeof(struct hub_port_status));
|
||||
if (hub_class->port_status == NULL) {
|
||||
@@ -215,8 +217,6 @@ int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, hub_class->index);
|
||||
|
||||
hport->config.intf[intf].priv = hub_class;
|
||||
hub_class->dev_addr = hport->dev_addr;
|
||||
hub_class->parent = hport;
|
||||
|
||||
uint8_t *hub_desc_buffer = usb_iomalloc(32);
|
||||
|
||||
@@ -273,7 +273,7 @@ int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_hubport *child;
|
||||
int ret = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ static uint32_t g_devinuse = 0;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_msc_devno_alloc(struct usbh_msc *priv)
|
||||
static int usbh_msc_devno_alloc(struct usbh_msc *msc_class)
|
||||
{
|
||||
size_t flags;
|
||||
int devno;
|
||||
@@ -46,7 +46,7 @@ static int usbh_msc_devno_alloc(struct usbh_msc *priv)
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
priv->sdchar = 'a' + devno;
|
||||
msc_class->sdchar = 'a' + devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -64,9 +64,9 @@ static int usbh_msc_devno_alloc(struct usbh_msc *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_msc_devno_free(struct usbh_msc *priv)
|
||||
static void usbh_msc_devno_free(struct usbh_msc *msc_class)
|
||||
{
|
||||
int devno = priv->sdchar - 'a';
|
||||
int devno = msc_class->sdchar - 'a';
|
||||
|
||||
if (devno >= 0 && devno < 26) {
|
||||
size_t flags = usb_osal_enter_critical_section();
|
||||
@@ -75,24 +75,18 @@ static void usbh_msc_devno_free(struct usbh_msc *priv)
|
||||
}
|
||||
}
|
||||
|
||||
static int usbh_msc_get_maxlun(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
static int usbh_msc_get_maxlun(struct usbh_msc *msc_class, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_msc *msc_class = (struct usbh_msc *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (msc_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
struct usb_setup_packet *setup = msc_class->hport->setup;
|
||||
int ret;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = MSC_REQUEST_GET_MAX_LUN;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wIndex = msc_class->intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
return usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
return usbh_control_transfer(msc_class->hport->ep0, setup, buffer);
|
||||
}
|
||||
|
||||
static void usbh_msc_cbw_dump(struct CBW *cbw)
|
||||
@@ -325,7 +319,7 @@ int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, cons
|
||||
return nbytes < 0 ? (int)nbytes : 0;
|
||||
}
|
||||
|
||||
int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
@@ -339,7 +333,8 @@ int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
memset(msc_class, 0, sizeof(struct usbh_msc));
|
||||
msc_class->hport = hport;
|
||||
|
||||
msc_class->intf = intf;
|
||||
|
||||
usbh_msc_devno_alloc(msc_class);
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, msc_class->sdchar);
|
||||
|
||||
@@ -351,7 +346,7 @@ int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = usbh_msc_get_maxlun(hport, intf, msc_class->tx_buffer);
|
||||
ret = usbh_msc_get_maxlun(msc_class, msc_class->tx_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -387,7 +382,7 @@ int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user