Skip to content

Commit 29003ff

Browse files
jfischer-nofabiobaltieri
authored andcommitted
usb: bos: cleanup Binary Device Object Store header
We could reuse the BOS header, but there are parts that are only needed in the legacy device support or used internally and the tests. Move this parts to the appropriate places. Signed-off-by: Johann Fischer <[email protected]>
1 parent 4f17bc6 commit 29003ff

File tree

6 files changed

+60
-48
lines changed

6 files changed

+60
-48
lines changed

include/zephyr/usb/bos.h

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* @{
1818
*/
1919

20-
/**
21-
* @brief Helper macro to place the BOS compatibility descriptor
22-
* in the right memory section.
23-
*/
24-
#define USB_DEVICE_BOS_DESC_DEFINE_CAP \
25-
static __in_section(usb, bos_desc_area, 1) __aligned(1) __used
20+
/** Root BOS Descriptor */
21+
struct usb_bos_descriptor {
22+
uint8_t bLength;
23+
uint8_t bDescriptorType;
24+
uint16_t wTotalLength;
25+
uint8_t bNumDeviceCaps;
26+
} __packed;
2627

2728
/** Device capability type codes */
2829
enum usb_bos_capability_types {
@@ -62,45 +63,6 @@ struct usb_bos_capability_msos {
6263
uint8_t bAltEnumCode;
6364
} __packed;
6465

65-
/**
66-
* @brief Register BOS capability descriptor
67-
*
68-
* This function should be used by the application to register BOS capability
69-
* descriptors before the USB device stack is enabled.
70-
*
71-
* @param[in] hdr Pointer to BOS capability descriptor
72-
*/
73-
void usb_bos_register_cap(struct usb_bos_platform_descriptor *hdr);
74-
75-
/**
76-
* @cond INTERNAL_HIDDEN
77-
* Internally used functions
78-
*/
79-
80-
/* BOS Descriptor (root descriptor) */
81-
struct usb_bos_descriptor {
82-
uint8_t bLength;
83-
uint8_t bDescriptorType;
84-
uint16_t wTotalLength;
85-
uint8_t bNumDeviceCaps;
86-
} __packed;
87-
88-
#define USB_DEVICE_BOS_DESC_DEFINE_HDR \
89-
static __in_section(usb, bos_desc_area, 0) __aligned(1) __used
90-
91-
size_t usb_bos_get_length(void);
92-
93-
void usb_bos_fix_total_length(void);
94-
95-
const void *usb_bos_get_header(void);
96-
97-
#if defined(CONFIG_USB_DEVICE_BOS)
98-
int usb_handle_bos(struct usb_setup_packet *setup, int32_t *len, uint8_t **data);
99-
#else
100-
#define usb_handle_bos(x, y, z) -ENOTSUP
101-
#endif
102-
/** @endcond */
103-
10466
/**
10567
* @}
10668
*/

include/zephyr/usb/usb_device.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,23 @@ int usb_wakeup_request(void);
446446
*/
447447
bool usb_get_remote_wakeup_status(void);
448448

449+
/**
450+
* @brief Helper macro to place the BOS compatibility descriptor
451+
* in the right memory section.
452+
*/
453+
#define USB_DEVICE_BOS_DESC_DEFINE_CAP \
454+
static __in_section(usb, bos_desc_area, 1) __aligned(1) __used
455+
456+
/**
457+
* @brief Register BOS capability descriptor
458+
*
459+
* This function should be used by the application to register BOS capability
460+
* descriptors before the USB device stack is enabled.
461+
*
462+
* @param[in] hdr Pointer to BOS capability descriptor
463+
*/
464+
void usb_bos_register_cap(void *hdr);
465+
449466
/**
450467
* @}
451468
*/

subsys/usb/device/bos.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
#include <zephyr/logging/log.h>
88
LOG_MODULE_REGISTER(usb_bos, CONFIG_USB_DEVICE_LOG_LEVEL);
99

10-
#include <zephyr/kernel.h>
10+
#include <bos_desc.h>
1111

12+
#include <zephyr/kernel.h>
1213
#include <zephyr/usb/usb_device.h>
13-
1414
#include <zephyr/usb/bos.h>
1515

1616
extern const uint8_t __usb_bos_desc_start[];
1717
extern const uint8_t __usb_bos_desc_end[];
1818

19+
#define USB_DEVICE_BOS_DESC_DEFINE_HDR \
20+
static __in_section(usb, bos_desc_area, 0) __aligned(1) __used
21+
1922
USB_DEVICE_BOS_DESC_DEFINE_HDR struct usb_bos_descriptor bos_hdr = {
2023
.bLength = sizeof(struct usb_bos_descriptor),
2124
.bDescriptorType = USB_DESC_BOS,
@@ -38,8 +41,10 @@ void usb_bos_fix_total_length(void)
3841
bos_hdr.wTotalLength = usb_bos_get_length();
3942
}
4043

41-
void usb_bos_register_cap(struct usb_bos_platform_descriptor *desc)
44+
void usb_bos_register_cap(void *desc)
4245
{
46+
ARG_UNUSED(desc);
47+
4348
/* Has effect only on first register */
4449
bos_hdr.wTotalLength = usb_bos_get_length();
4550

subsys/usb/device/bos_desc.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_USB_DEVICE_BOS_DESC_H_
8+
#define ZEPHYR_INCLUDE_USB_DEVICE_BOS_DESC_H_
9+
10+
#include <stdint.h>
11+
#include <zephyr/usb/usb_ch9.h>
12+
13+
size_t usb_bos_get_length(void);
14+
15+
void usb_bos_fix_total_length(void);
16+
17+
const void *usb_bos_get_header(void);
18+
19+
#if defined(CONFIG_USB_DEVICE_BOS)
20+
int usb_handle_bos(struct usb_setup_packet *setup, int32_t *len, uint8_t **data);
21+
#else
22+
#define usb_handle_bos(x, y, z) -ENOTSUP
23+
#endif
24+
25+
#endif /* ZEPHYR_INCLUDE_USB_DEVICE_BOS_DESC_H_ */

subsys/usb/device/usb_device.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
#include <errno.h>
6161
#include <stddef.h>
62+
#include <bos_desc.h>
6263
#include <zephyr/sys/util.h>
6364
#include <zephyr/sys/__assert.h>
6465
#include <zephyr/init.h>

tests/subsys/usb/bos/src/test_bos.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <bos_desc.h>
8+
79
#include <zephyr/ztest.h>
810
#include <zephyr/tc_util.h>
911

0 commit comments

Comments
 (0)