|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Renesas Electronics Corporation, Embedd |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef ZEPHYR_INCLUDE_USB_CLASS_USBH_BILLBOARD_H_ |
| 8 | +#define ZEPHYR_INCLUDE_USB_CLASS_USBH_BILLBOARD_H_ |
| 9 | + |
| 10 | +#include <zephyr/device.h> |
| 11 | +#include <zephyr/syscall.h> |
| 12 | +#include <zephyr/usb/class/usb_billboard.h> |
| 13 | +#include <zephyr/usb/bos.h> |
| 14 | + |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" { |
| 17 | +#endif |
| 18 | + |
| 19 | +/** |
| 20 | + * @brief App callback to handle parsed capabilities descriptors |
| 21 | + * |
| 22 | + * @param cb_arg Pointer to callback specific context structure |
| 23 | + * @param cap_header Pointer to capability |
| 24 | + * |
| 25 | + */ |
| 26 | +typedef void (*usbh_billboard_cb_t)(void *cb_arg, struct usb_bos_capability_header *cap_header); |
| 27 | + |
| 28 | +/** |
| 29 | + * @brief Fetches BOS and parse billboard capabilities descriptors |
| 30 | + * |
| 31 | + * @param dev Pointer to the device |
| 32 | + * @param billboard_cb Application callback |
| 33 | + * @param cb_arg Pointer to callback specific context structure |
| 34 | + * |
| 35 | + * @return 0 on success, negative errno value on failure. |
| 36 | + */ |
| 37 | +typedef int (*usbh_billboard_fetch_and_parse_t)(struct device const *dev, |
| 38 | + usbh_billboard_cb_t billboard_cb, void *cb_arg); |
| 39 | + |
| 40 | +/** |
| 41 | + * @brief Fetches string descriptors |
| 42 | + * |
| 43 | + * @param dev Pointer to the device |
| 44 | + * @param str_idx String descriptor index |
| 45 | + * @param str_desc Output argument, double pointer to string descriptor |
| 46 | + * |
| 47 | + * @return 0 on success, negative errno value on failure. |
| 48 | + */ |
| 49 | +typedef int (*usbh_billboard_fetch_string_t)(struct device const *dev, uint8_t str_idx, |
| 50 | + struct usb_string_descriptor **str_desc); |
| 51 | + |
| 52 | +/** |
| 53 | + * @brief Fetches the supported languages from the device |
| 54 | + * |
| 55 | + * @param dev Pointer to the device |
| 56 | + * @param str_desc Output argument, double pointer to string descriptor |
| 57 | + * |
| 58 | + * @return 0 on success, negative errno value on failure. |
| 59 | + */ |
| 60 | +typedef int (*usbh_billboard_fetch_langs_t)(struct device const *dev, |
| 61 | + struct usb_string_descriptor **str_desc); |
| 62 | + |
| 63 | +/** |
| 64 | + * @brief Changes the language used for fetching string descriptors |
| 65 | + * |
| 66 | + * @param dev Pointer to the device |
| 67 | + * @param lang_code Language code |
| 68 | + * |
| 69 | + * @return 0 on success, negative errno value on failure. |
| 70 | + */ |
| 71 | +typedef int (*usbh_billboard_use_lang_t)(struct device const *dev, uint16_t lang_code); |
| 72 | + |
| 73 | +__subsystem struct usbh_billboard_driver_api { |
| 74 | + /** |
| 75 | + * @driver_ops_mandatory @copybrief usbh_billboard_fetch_and_parse |
| 76 | + */ |
| 77 | + usbh_billboard_fetch_and_parse_t fetch_and_parse; |
| 78 | + /** |
| 79 | + * @driver_ops_mandatory @copybrief usbh_billboard_fetch_string_desc |
| 80 | + */ |
| 81 | + usbh_billboard_fetch_string_t fetch_string; |
| 82 | + /** |
| 83 | + * @driver_ops_mandatory @copybrief usbh_billboard_fetch_langs_desc |
| 84 | + */ |
| 85 | + usbh_billboard_fetch_langs_t fetch_langs; |
| 86 | + /** |
| 87 | + * @driver_ops_mandatory @copybrief usbh_billboard_use_lang |
| 88 | + */ |
| 89 | + usbh_billboard_use_lang_t use_lang; |
| 90 | +}; |
| 91 | + |
| 92 | +/** |
| 93 | + * @brief Fetches BOS and parse billboard capabilities descriptors |
| 94 | + * |
| 95 | + * @param dev Pointer to the device |
| 96 | + * @param billboard_cb Application callback |
| 97 | + * @param cb_arg Pointer to callback specific context structure |
| 98 | + * |
| 99 | + * @return 0 on success, negative errno value on failure. |
| 100 | + */ |
| 101 | +__syscall int usbh_billboard_fetch_and_parse(struct device const *dev, |
| 102 | + usbh_billboard_cb_t billboard_cb, void *cb_arg); |
| 103 | + |
| 104 | +static inline int z_impl_usbh_billboard_fetch_and_parse(struct device const *dev, |
| 105 | + usbh_billboard_cb_t billboard_cb, |
| 106 | + void *cb_arg) |
| 107 | +{ |
| 108 | + struct usbh_billboard_driver_api const *api = DEVICE_API_GET(usbh_billboard, dev); |
| 109 | + |
| 110 | + if (api->fetch_and_parse == NULL) { |
| 111 | + return -ENOSYS; |
| 112 | + } |
| 113 | + return api->fetch_and_parse(dev, billboard_cb, cb_arg); |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * @brief Fetches string descriptors |
| 118 | + * |
| 119 | + * @param dev Pointer to the device |
| 120 | + * @param str_idx String descriptor index |
| 121 | + * @param str_desc Output argument, double pointer to string descriptor |
| 122 | + * |
| 123 | + * @return 0 on success, negative errno value on failure. |
| 124 | + */ |
| 125 | +__syscall int usbh_billboard_fetch_string_desc(struct device const *dev, uint8_t str_idx, |
| 126 | + struct usb_string_descriptor **str_desc); |
| 127 | + |
| 128 | +static inline int z_impl_usbh_billboard_fetch_string_desc(struct device const *dev, uint8_t str_idx, |
| 129 | + struct usb_string_descriptor **str_desc) |
| 130 | +{ |
| 131 | + struct usbh_billboard_driver_api const *api = DEVICE_API_GET(usbh_billboard, dev); |
| 132 | + |
| 133 | + if (api->fetch_string == NULL) { |
| 134 | + return -ENOSYS; |
| 135 | + } |
| 136 | + return api->fetch_string(dev, str_idx, str_desc); |
| 137 | +} |
| 138 | + |
| 139 | +/** |
| 140 | + * @brief Fetches the supported languages from the device |
| 141 | + * |
| 142 | + * @param dev Pointer to the device |
| 143 | + * @param str_desc Output argument, double pointer to string descriptor |
| 144 | + * |
| 145 | + * @return 0 on success, negative errno value on failure. |
| 146 | + */ |
| 147 | +__syscall int usbh_billboard_fetch_langs_desc(struct device const *dev, |
| 148 | + struct usb_string_descriptor **str_desc); |
| 149 | + |
| 150 | +static inline int z_impl_usbh_billboard_fetch_langs_desc(struct device const *dev, |
| 151 | + struct usb_string_descriptor **str_desc) |
| 152 | +{ |
| 153 | + struct usbh_billboard_driver_api const *api = DEVICE_API_GET(usbh_billboard, dev); |
| 154 | + |
| 155 | + if (api->fetch_langs == NULL) { |
| 156 | + return -ENOSYS; |
| 157 | + } |
| 158 | + return api->fetch_langs(dev, str_desc); |
| 159 | +} |
| 160 | + |
| 161 | +/** |
| 162 | + * @brief Changes the language used for fetching string descriptors |
| 163 | + * |
| 164 | + * @param dev Pointer to the device |
| 165 | + * @param lang_code Language code |
| 166 | + * |
| 167 | + * @return 0 on success, negative errno value on failure. |
| 168 | + */ |
| 169 | +__syscall int usbh_billboard_use_lang(struct device const *dev, uint16_t lang_code); |
| 170 | + |
| 171 | +static inline int z_impl_usbh_billboard_use_lang(struct device const *dev, uint16_t lang_code) |
| 172 | +{ |
| 173 | + struct usbh_billboard_driver_api const *api = DEVICE_API_GET(usbh_billboard, dev); |
| 174 | + |
| 175 | + if (api->use_lang == NULL) { |
| 176 | + return -ENOSYS; |
| 177 | + } |
| 178 | + return api->use_lang(dev, lang_code); |
| 179 | +} |
| 180 | + |
| 181 | +int usbh_billboard_find_dev(struct usb_device *udev, struct device **dev); |
| 182 | + |
| 183 | +#include <zephyr/syscalls/usbh_billboard.h> |
| 184 | + |
| 185 | +#ifdef __cplusplus |
| 186 | +} |
| 187 | +#endif |
| 188 | + |
| 189 | +#endif /* ZEPHYR_INCLUDE_USB_CLASS_USBH_BILLBOARD_H_ */ |
0 commit comments