forked from CANnectivity/cannectivity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
usbd_next: switch from usbd_register_all_classes() to usbd_register_c…
…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
1 parent
80ea0c5
commit 87f6ec0
Showing
2 changed files
with
14 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
@@ -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)) | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
@@ -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 */ | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|