2018-05-31 15:26:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/logging/log.h>
|
2022-12-08 16:42:37 +01:00
|
|
|
LOG_MODULE_REGISTER(usb_bos, CONFIG_USB_DEVICE_LOG_LEVEL);
|
2018-05-31 15:26:58 +02:00
|
|
|
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2018-05-31 15:26:58 +02:00
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/usb/usb_device.h>
|
2018-05-31 15:26:58 +02:00
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/usb/bos.h>
|
2018-05-31 15:26:58 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
extern const uint8_t __usb_bos_desc_start[];
|
|
|
|
extern const uint8_t __usb_bos_desc_end[];
|
2018-05-31 15:26:58 +02:00
|
|
|
|
2021-02-01 14:37:30 +01:00
|
|
|
USB_DEVICE_BOS_DESC_DEFINE_HDR struct usb_bos_descriptor bos_hdr = {
|
2018-05-31 15:26:58 +02:00
|
|
|
.bLength = sizeof(struct usb_bos_descriptor),
|
2021-05-12 11:12:29 +02:00
|
|
|
.bDescriptorType = USB_DESC_BOS,
|
2018-05-31 15:26:58 +02:00
|
|
|
.wTotalLength = 0, /* should be corrected with register */
|
|
|
|
.bNumDeviceCaps = 0, /* should be set with register */
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t usb_bos_get_length(void)
|
|
|
|
{
|
|
|
|
return __usb_bos_desc_end - __usb_bos_desc_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *usb_bos_get_header(void)
|
|
|
|
{
|
|
|
|
return __usb_bos_desc_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_bos_fix_total_length(void)
|
|
|
|
{
|
2021-02-01 14:37:30 +01:00
|
|
|
bos_hdr.wTotalLength = usb_bos_get_length();
|
2018-05-31 15:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_bos_register_cap(struct usb_bos_platform_descriptor *desc)
|
|
|
|
{
|
|
|
|
/* Has effect only on first register */
|
2021-02-01 14:37:30 +01:00
|
|
|
bos_hdr.wTotalLength = usb_bos_get_length();
|
2018-05-31 15:26:58 +02:00
|
|
|
|
2021-02-01 14:37:30 +01:00
|
|
|
bos_hdr.bNumDeviceCaps += 1U;
|
2018-05-31 15:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int usb_handle_bos(struct usb_setup_packet *setup,
|
2020-05-27 18:26:57 +02:00
|
|
|
int32_t *len, uint8_t **data)
|
2018-05-31 15:26:58 +02:00
|
|
|
{
|
2021-05-12 11:12:29 +02:00
|
|
|
if (USB_GET_DESCRIPTOR_TYPE(setup->wValue) == USB_DESC_BOS) {
|
2019-10-01 10:29:02 +02:00
|
|
|
LOG_DBG("Read BOS descriptor");
|
2020-05-27 18:26:57 +02:00
|
|
|
*data = (uint8_t *)usb_bos_get_header();
|
2018-05-31 15:26:58 +02:00
|
|
|
*len = usb_bos_get_length();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|