Skip to content

Commit 187703c

Browse files
jfischer-nofabiobaltieri
authored andcommitted
usb: device_next: allow vendor request support to be disabled
Disabling it if not needed can save about 100 bytes of flash memory. Signed-off-by: Johann Fischer <[email protected]>
1 parent ed4c27b commit 187703c

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

include/zephyr/usb/usbd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,16 @@ static inline void *usbd_class_get_private(const struct usbd_class_data *const c
688688
/**
689689
* @brief Define a vendor request with recipient device
690690
*
691+
* @note It requires Kconfig options USBD_VREQ_SUPPORT to be enabled.
692+
*
691693
* @param name Vendor request identifier
692694
* @param vcode Vendor request code
693695
* @param vto_host Vendor callback for to-host direction request
694696
* @param vto_dev Vendor callback for to-device direction request
695697
*/
696698
#define USBD_VREQUEST_DEFINE(name, vcode, vto_host, vto_dev) \
699+
BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_VREQ_SUPPORT), \
700+
"USB device vendor request support is disabled"); \
697701
static struct usbd_vreq_node name = { \
698702
.code = vcode, \
699703
.to_host = vto_host, \
@@ -709,6 +713,9 @@ static inline void *usbd_class_get_private(const struct usbd_class_data *const c
709713
* USBD_DESC_BOS_VREQ_DEFINE(bos_vreq_webusb, sizeof(bos_cap_webusb), &bos_cap_webusb,
710714
* SAMPLE_WEBUSB_VENDOR_CODE, webusb_to_host_cb, NULL);
711715
*
716+
* @note It requires Kconfig options USBD_VREQ_SUPPORT and USBD_BOS_SUPPORT to
717+
* be enabled.
718+
*
712719
* @param name Descriptor node identifier
713720
* @param len Device Capability descriptor length
714721
* @param subset Pointer to a Device Capability descriptor

subsys/usb/device_next/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ config USBD_BOS_SUPPORT
4343
BOS support can be disabled if the application does not use a BOS
4444
descriptor.
4545

46+
config USBD_VREQ_SUPPORT
47+
bool "USB device vendor request support"
48+
default y
49+
help
50+
Allow the application to register a handler for the vendor request
51+
with the recipient device.
52+
4653
config USBD_SHELL
4754
bool "USB device shell"
4855
depends on SHELL

subsys/usb/device_next/usbd_ch9.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,11 @@ static int vendor_device_request(struct usbd_context *const uds_ctx,
940940
struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx);
941941
struct usbd_vreq_node *vreq_nd;
942942

943+
if (!IS_ENABLED(CONFIG_USBD_VREQ_SUPPORT)) {
944+
errno = -ENOTSUP;
945+
return 0;
946+
}
947+
943948
vreq_nd = usbd_device_get_vreq(uds_ctx, setup->bRequest);
944949
if (vreq_nd == NULL) {
945950
errno = -ENOTSUP;

subsys/usb/device_next/usbd_desc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ int usbd_add_descriptor(struct usbd_context *const uds_ctx,
145145

146146
if (IS_ENABLED(CONFIG_USBD_BOS_SUPPORT) &&
147147
desc_nd->bDescriptorType == USB_DESC_BOS) {
148-
if (desc_nd->bos.utype == USBD_DUT_BOS_VREQ) {
148+
if (IS_ENABLED(CONFIG_USBD_VREQ_SUPPORT) &&
149+
desc_nd->bos.utype == USBD_DUT_BOS_VREQ) {
149150
ret = usbd_device_register_vreq(uds_ctx, desc_nd->bos.vreq_nd);
150151
if (ret) {
151152
goto add_descriptor_error;

subsys/usb/device_next/usbd_device.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ int usbd_device_register_vreq(struct usbd_context *const uds_ctx,
364364
{
365365
int ret = 0;
366366

367+
if (!IS_ENABLED(CONFIG_USBD_VREQ_SUPPORT)) {
368+
return -ENOTSUP;
369+
}
370+
367371
usbd_device_lock(uds_ctx);
368372

369373
if (usbd_is_initialized(uds_ctx)) {

0 commit comments

Comments
 (0)