samples: bluetooth: hci_usb: Use common USB sample initialization

Convert hci_usb sample to use common USB sample initialization code.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
Tomasz Moń 2024-02-29 10:49:27 +01:00 committed by Carles Cufí
commit d05d51d869
4 changed files with 18 additions and 53 deletions

View file

@ -4,4 +4,5 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hci_usb) project(hci_usb)
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,9 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# Source common USB sample options used to initialize new experimental USB
# device stack. The scope of these options is limited to USB samples in project
# tree, you cannot use them in your own application.
source "samples/subsys/usb/common/Kconfig.sample_usbd"
source "Kconfig.zephyr"

View file

@ -10,65 +10,18 @@
#include <zephyr/usb/usbd.h> #include <zephyr/usb/usbd.h>
#if defined(CONFIG_USB_DEVICE_STACK_NEXT) #if defined(CONFIG_USB_DEVICE_STACK_NEXT)
USBD_CONFIGURATION_DEFINE(config_1, #include <sample_usbd.h>
USB_SCD_SELF_POWERED,
200);
USBD_DESC_LANG_DEFINE(sample_lang);
USBD_DESC_MANUFACTURER_DEFINE(sample_mfr, "ZEPHYR");
USBD_DESC_PRODUCT_DEFINE(sample_product, "Zephyr USBD BT HCI");
USBD_DESC_SERIAL_NUMBER_DEFINE(sample_sn, "0123456789ABCDEF");
USBD_DEVICE_DEFINE(sample_usbd,
DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)),
0x2fe3, 0x000b);
static int enable_usb_device_next(void) static int enable_usb_device_next(void)
{ {
int err; struct usbd_contex *sample_usbd = sample_usbd_init_device();
err = usbd_add_descriptor(&sample_usbd, &sample_lang); if (sample_usbd == NULL) {
if (err) { printk("Failed to initialize USB device");
return err; return -ENODEV;
} }
err = usbd_add_descriptor(&sample_usbd, &sample_mfr); return usbd_enable(sample_usbd);
if (err) {
return err;
}
err = usbd_add_descriptor(&sample_usbd, &sample_product);
if (err) {
return err;
}
err = usbd_add_descriptor(&sample_usbd, &sample_sn);
if (err) {
return err;
}
err = usbd_add_configuration(&sample_usbd, &config_1);
if (err) {
return err;
}
err = usbd_register_class(&sample_usbd, "bt_hci_0", 1);
if (err) {
return err;
}
err = usbd_init(&sample_usbd);
if (err) {
return err;
}
err = usbd_enable(&sample_usbd);
if (err) {
return err;
}
return 0;
} }
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */ #endif /* CONFIG_USB_DEVICE_STACK_NEXT */

View file

@ -8,6 +8,8 @@ CONFIG_BT=y
CONFIG_BT_HCI_RAW=y CONFIG_BT_HCI_RAW=y
CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_SAMPLE_USBD_PID=0x000b
CONFIG_SAMPLE_USBD_PRODUCT="Zephyr USBD BT HCI"
CONFIG_USBD_BT_HCI=y CONFIG_USBD_BT_HCI=y
CONFIG_LOG=y CONFIG_LOG=y