|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file |
| 9 | + * @brief USB host stack class instances API |
| 10 | + * |
| 11 | + * This file contains the USB host stack class instances API. |
| 12 | + */ |
| 13 | + |
| 14 | +#ifndef ZEPHYR_INCLUDE_USBH_CLASS_API_H |
| 15 | +#define ZEPHYR_INCLUDE_USBH_CLASS_API_H |
| 16 | + |
| 17 | +#include <zephyr/usb/usbh.h> |
| 18 | + |
| 19 | +/** |
| 20 | + * @brief Initialization of the class implementation |
| 21 | + * |
| 22 | + * This is called for each instance during the initialization phase, |
| 23 | + * for every registered class. |
| 24 | + * It can be used to initialize underlying systems. |
| 25 | + * |
| 26 | + * @param[in] c_data Pointer to USB host class data |
| 27 | + * |
| 28 | + * @return 0 on success, negative error code on failure. |
| 29 | + */ |
| 30 | +static inline int usbh_class_init(struct usbh_class_data *const c_data) |
| 31 | +{ |
| 32 | + const struct usbh_class_api *api = c_data->api; |
| 33 | + |
| 34 | + if (api->init != NULL) { |
| 35 | + return api->init(c_data); |
| 36 | + } |
| 37 | + |
| 38 | + return -ENOTSUP; |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * @brief Request completion event handler |
| 43 | + * |
| 44 | + * Called upon completion of a request made by the host to this class. |
| 45 | + * |
| 46 | + * @param[in] c_data Pointer to USB host class data |
| 47 | + * @param[in] xfer Completed transfer |
| 48 | + * @param[in] err Result of the transfer. 0 if the transfer was successful. |
| 49 | + * |
| 50 | + * @return 0 on success, negative error code on failure. |
| 51 | + */ |
| 52 | +static inline int usbh_class_request(struct usbh_class_data *const c_data, |
| 53 | + struct uhc_transfer *const xfer, int err) |
| 54 | +{ |
| 55 | + const struct usbh_class_api *api = c_data->api; |
| 56 | + |
| 57 | + if (api->request != NULL) { |
| 58 | + return api->request(c_data, xfer, err); |
| 59 | + } |
| 60 | + |
| 61 | + return -ENOTSUP; |
| 62 | +} |
| 63 | + |
| 64 | +/** |
| 65 | + * @brief Device connected handler |
| 66 | + * |
| 67 | + * Called when a device is connected to the bus |
| 68 | + * and it matches the class filters of this instance. |
| 69 | + * |
| 70 | + * @param[in] c_data Pointer to USB host class data |
| 71 | + * @param[in] desc_start_addr Pointer to the start of the descriptor |
| 72 | + * @param[in] desc_end_addr Pointer after the end of the USB descriptor |
| 73 | + * |
| 74 | + * @return 0 on success, negative error code on failure. |
| 75 | + */ |
| 76 | +static inline int usbh_class_connected(struct usbh_class_data *const c_data, |
| 77 | + void *const desc_start_addr, |
| 78 | + void *const desc_end_addr) |
| 79 | +{ |
| 80 | + const struct usbh_class_api *api = c_data->api; |
| 81 | + |
| 82 | + if (api->connected != NULL) { |
| 83 | + return api->connected(c_data, desc_start_addr, desc_end_addr); |
| 84 | + } |
| 85 | + |
| 86 | + return -ENOTSUP; |
| 87 | +} |
| 88 | + |
| 89 | +/** |
| 90 | + * @brief Device removed handler |
| 91 | + * |
| 92 | + * Called when the device is removed from the bus |
| 93 | + * and it matches the class filters of this instance. |
| 94 | + * |
| 95 | + * @param[in] c_data Pointer to USB host class data |
| 96 | + * |
| 97 | + * @return 0 on success, negative error code on failure. |
| 98 | + */ |
| 99 | +static inline int usbh_class_removed(struct usbh_class_data *const c_data) |
| 100 | +{ |
| 101 | + const struct usbh_class_api *api = c_data->api; |
| 102 | + |
| 103 | + if (api->removed != NULL) { |
| 104 | + return api->removed(c_data); |
| 105 | + } |
| 106 | + |
| 107 | + return -ENOTSUP; |
| 108 | +} |
| 109 | + |
| 110 | +/** |
| 111 | + * @brief Bus remote wakeup handler |
| 112 | + * |
| 113 | + * Called when the device trigger a remote wakeup to the host. |
| 114 | + * and it matches the class filters. |
| 115 | + * |
| 116 | + * @param[in] c_data Pointer to USB host class data |
| 117 | + * |
| 118 | + * @return 0 on success, negative error code on failure. |
| 119 | + */ |
| 120 | +static inline int usbh_class_rwup(struct usbh_class_data *const c_data) |
| 121 | +{ |
| 122 | + const struct usbh_class_api *api = c_data->api; |
| 123 | + |
| 124 | + if (api->rwup != NULL) { |
| 125 | + return api->rwup(c_data); |
| 126 | + } |
| 127 | + |
| 128 | + return -ENOTSUP; |
| 129 | +} |
| 130 | + |
| 131 | +/** |
| 132 | + * @brief Bus suspended handler |
| 133 | + * |
| 134 | + * Called when the host has suspending the bus. |
| 135 | + * It can be used to suspend underlying systems. |
| 136 | + * |
| 137 | + * @param[in] c_data Pointer to USB host class data |
| 138 | + * |
| 139 | + * @return 0 on success, negative error code on failure. |
| 140 | + */ |
| 141 | +static inline int usbh_class_suspended(struct usbh_class_data *const c_data) |
| 142 | +{ |
| 143 | + const struct usbh_class_api *api = c_data->api; |
| 144 | + |
| 145 | + if (api->suspended != NULL) { |
| 146 | + return api->suspended(c_data); |
| 147 | + } |
| 148 | + |
| 149 | + return -ENOTSUP; |
| 150 | +} |
| 151 | + |
| 152 | +/** |
| 153 | + * @brief Bus resumed handler |
| 154 | + * |
| 155 | + * Called when the host resumes the activity on a bus. |
| 156 | + * It can be used to wake-up underlying systems. |
| 157 | + * |
| 158 | + * @param[in] c_data Pointer to USB host class data |
| 159 | + * |
| 160 | + * @return 0 on success, negative error code on failure. |
| 161 | + */ |
| 162 | +static inline int usbh_class_resumed(struct usbh_class_data *const c_data) |
| 163 | +{ |
| 164 | + const struct usbh_class_api *api = c_data->api; |
| 165 | + |
| 166 | + if (api->resumed != NULL) { |
| 167 | + return api->resumed(c_data); |
| 168 | + } |
| 169 | + |
| 170 | + return -ENOTSUP; |
| 171 | +} |
| 172 | + |
| 173 | +#endif /* ZEPHYR_INCLUDE_USBD_CLASS_API_H */ |
0 commit comments