|
| 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 | +/** |
| 62 | + * @brief Initialize every class instantiated on the system |
| 63 | + * |
| 64 | + * @param[in] uhs_ctx USB Host context to pass to the class. |
| 65 | + * @retval 0 on success or negative error code on failure |
| 66 | + */ |
| 67 | +int usbh_class_init_all(struct usbh_context *const uhs_ctx); |
| 68 | + |
| 69 | +/** |
| 70 | + * @brief Probe all classes to against a newly connected USB device. |
| 71 | + * |
| 72 | + * @param[in] udev USB device to probe. |
| 73 | + * @retval 0 on success or negative error code on failure |
| 74 | + */ |
| 75 | +int usbh_class_probe_all(struct usb_device *const udev); |
| 76 | + |
| 77 | +/** |
| 78 | + * @brief Call the device removal handler for every class configured with it |
| 79 | + * |
| 80 | + * @param[in] udev USB device that got removed. |
| 81 | + * @retval 0 on success or negative error code on failure |
| 82 | + */ |
| 83 | +int usbh_class_remove_all(const struct usb_device *const udev); |
| 84 | + |
| 85 | +#endif /* ZEPHYR_INCLUDE_USBD_CLASS_H */ |
0 commit comments