Skip to content

Commit

Permalink
usbd_next: switch from usbd_register_all_classes() to usbd_register_c…
Browse files Browse the repository at this point in the history
…lass()

Switch from usbd_register_all_classes() to usbd_register_class() as the
former is mostly meant as a utility function for use in in-tree Zephyr
samples/tests.

Using usbd_register_class() furthermore improves error handling as it will
fail if the expected class instance is not available.

Signed-off-by: Henrik Brix Andersen <[email protected]>
  • Loading branch information
henrikbrixandersen committed Jan 29, 2025
1 parent 80ea0c5 commit 87f6ec0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions app/src/usb.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Henrik Brix Andersen <[email protected]>
* Copyright (c) 2024-2025 Henrik Brix Andersen <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -23,6 +23,8 @@

LOG_MODULE_REGISTER(usb, CONFIG_CANNECTIVITY_LOG_LEVEL);

#define GS_USB_CLASS_INSTANCE_NAME "gs_usb_0"

#define CANNECTIVITY_USB_BCD_DRN \
(USB_DEC_TO_BCD(APP_VERSION_MAJOR) << 8 | USB_DEC_TO_BCD(APP_VERSION_MINOR))

Expand Down Expand Up @@ -188,9 +190,9 @@ static int cannectivity_usb_init_usbd(void)
return err;
}

err = usbd_register_all_classes(&usbd, USBD_SPEED_HS, 1);
err = usbd_register_class(&usbd, GS_USB_CLASS_INSTANCE_NAME, USBD_SPEED_HS, 1);
if (err != 0) {
LOG_ERR("failed to register high-speed classes (err %d)", err);
LOG_ERR("failed to register high-speed class instance (err %d)", err);
return err;
}

Expand All @@ -213,9 +215,9 @@ static int cannectivity_usb_init_usbd(void)
return err;
}

err = usbd_register_all_classes(&usbd, USBD_SPEED_FS, 1);
err = usbd_register_class(&usbd, GS_USB_CLASS_INSTANCE_NAME, USBD_SPEED_FS, 1);
if (err != 0) {
LOG_ERR("failed to register full-speed classes (err %d)", err);
LOG_ERR("failed to register full-speed class instance (err %d)", err);
return err;
}

Expand Down
12 changes: 7 additions & 5 deletions tests/subsys/usb/gs_usb/host/src/usb.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Henrik Brix Andersen <[email protected]>
* Copyright (c) 2024-2025 Henrik Brix Andersen <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,6 +18,8 @@

LOG_MODULE_REGISTER(usb, LOG_LEVEL_DBG);

#define GS_USB_CLASS_INSTANCE_NAME "gs_usb_0"

#ifdef CONFIG_USB_DEVICE_STACK_NEXT
#define TEST_BOS_DESC_DEFINE_CAP static
#else /* CONFIG_USB_DEVICE_STACK_NEXT */
Expand Down Expand Up @@ -83,9 +85,9 @@ static int test_usb_init_usbd(void)
return err;
}

err = usbd_register_all_classes(&usbd, USBD_SPEED_HS, 1);
err = usbd_register_class(&usbd, GS_USB_CLASS_INSTANCE_NAME, USBD_SPEED_HS, 1);
if (err != 0) {
LOG_ERR("failed to register high-speed classes (err %d)", err);
LOG_ERR("failed to register high-speed class instance (err %d)", err);
return err;
}

Expand All @@ -108,9 +110,9 @@ static int test_usb_init_usbd(void)
return err;
}

err = usbd_register_all_classes(&usbd, USBD_SPEED_FS, 1);
err = usbd_register_class(&usbd, GS_USB_CLASS_INSTANCE_NAME, USBD_SPEED_FS, 1);
if (err != 0) {
LOG_ERR("failed to register full-speed classes (err %d)", err);
LOG_ERR("failed to register full-speed class instance (err %d)", err);
return err;
}

Expand Down

0 comments on commit 87f6ec0

Please sign in to comment.