|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | + * Copyright 2025 NXP |
| 4 | + * |
| 5 | + * SPDX-License-Identifier: Apache-2.0 |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef ZEPHYR_INCLUDE_USBD_CLASS_H |
| 9 | +#define ZEPHYR_INCLUDE_USBD_CLASS_H |
| 10 | + |
| 11 | +#include <zephyr/usb/usbh.h> |
| 12 | + |
| 13 | +/** |
| 14 | + * @brief Information about a device, which is relevant for matching a particular class. |
| 15 | + */ |
| 16 | +struct usbh_class_filter { |
| 17 | + /** Vendor ID */ |
| 18 | + uint16_t vid; |
| 19 | + /** Product ID */ |
| 20 | + uint16_t pid; |
| 21 | + /** Device Class Code */ |
| 22 | + uint8_t dclass; |
| 23 | + /** Class Subclass Code */ |
| 24 | + uint8_t sub; |
| 25 | + /** Class Protocol Code */ |
| 26 | + uint8_t proto; |
| 27 | + /** Flags that tell which field to match */ |
| 28 | + uint8_t flags; |
| 29 | +}; |
| 30 | + |
| 31 | +/** Match a device's vendor ID */ |
| 32 | +#define USBH_CLASS_MATCH_VID BIT(1) |
| 33 | + |
| 34 | +/** Match a device's product ID */ |
| 35 | +#define USBH_CLASS_MATCH_PID BIT(2) |
| 36 | + |
| 37 | +/** Match a class code */ |
| 38 | +#define USBH_CLASS_MATCH_DCLASS BIT(3) |
| 39 | + |
| 40 | +/** Match a subclass code */ |
| 41 | +#define USBH_CLASS_MATCH_SUB BIT(4) |
| 42 | + |
| 43 | +/** Match a protocol code */ |
| 44 | +#define USBH_CLASS_MATCH_PROTO BIT(5) |
| 45 | + |
| 46 | +/** Match a code triple */ |
| 47 | +#define USBH_CLASS_MATCH_CODE_TRIPLE \ |
| 48 | + (USBH_CLASS_MATCH_DCLASS | USBH_CLASS_MATCH_SUB | USBH_CLASS_MATCH_PROTO) |
| 49 | + |
| 50 | +/** |
| 51 | + * @brief Match an USB host class (a driver) against a device descriptor. |
| 52 | + * |
| 53 | + * @param[in] filters Array of filter rules to match |
| 54 | + * @param[in] n_filters Number of rules in the array. |
| 55 | + * @param[in] desc USB Device descriptor to match against each rule |
| 56 | + * @retval true if the USB Device descriptor matches at least one rule. |
| 57 | + */ |
| 58 | +bool usbh_class_is_matching(struct usbh_class_filter *const filters, size_t n_filters, |
| 59 | + struct usb_device_descriptor *const desc); |
| 60 | + |
| 61 | +#endif /* ZEPHYR_INCLUDE_USBD_CLASS_H */ |
0 commit comments