1 /* 2 * Copyright (c) 2022 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_USBD_CONFIG_H 8 #define ZEPHYR_INCLUDE_USBD_CONFIG_H 9 10 #include <zephyr/usb/usbd.h> 11 12 /** 13 * @brief Get configuration descriptor bConfigurationValue value 14 * 15 * @param[in] cfg_nd Pointer to a configuration node structure 16 * 17 * @return bConfigurationValue value 18 */ usbd_config_get_value(const struct usbd_config_node * const cfg_nd)19static inline uint8_t usbd_config_get_value(const struct usbd_config_node *const cfg_nd) 20 { 21 struct usb_cfg_descriptor *cfg_desc = cfg_nd->desc; 22 23 return cfg_desc->bConfigurationValue; 24 } 25 26 /** 27 * @brief Set configuration descriptor bConfigurationValue value 28 * 29 * @param[in] cfg_nd Pointer to a configuration node structure 30 */ usbd_config_set_value(const struct usbd_config_node * const cfg_nd,const uint8_t value)31static inline void usbd_config_set_value(const struct usbd_config_node *const cfg_nd, 32 const uint8_t value) 33 { 34 struct usb_cfg_descriptor *cfg_desc = cfg_nd->desc; 35 36 cfg_desc->bConfigurationValue = value; 37 } 38 39 /** 40 * @brief Get configuration node 41 * 42 * Get configuration node with desired configuration number. 43 * 44 * @param[in] ctx Pointer to USB device support context 45 * @param[in] speed Speed the configuration number applies to 46 * @param[in] cfg Configuration number (bConfigurationValue) 47 * 48 * @return pointer to configuration node or NULL if does not exist 49 */ 50 struct usbd_config_node *usbd_config_get(struct usbd_context *uds_ctx, 51 const enum usbd_speed speed, 52 uint8_t cfg); 53 54 /** 55 * @brief Get selected configuration node 56 * 57 * Get configuration node based on configuration selected by the host. 58 * 59 * @param[in] ctx Pointer to USB device support context 60 * 61 * @return pointer to configuration node or NULL if does not exist 62 */ 63 struct usbd_config_node *usbd_config_get_current(struct usbd_context *uds_ctx); 64 65 /** 66 * @brief Check whether a configuration exist 67 * 68 * @param[in] ctx Pointer to USB device support context 69 * @param[in] speed Speed at which the configuration should be checked 70 * @param[in] cfg Configuration number (bConfigurationValue) 71 * 72 * @return True if a configuration exist. 73 */ 74 bool usbd_config_exist(struct usbd_context *const uds_ctx, 75 const enum usbd_speed speed, 76 const uint8_t cfg); 77 78 /** 79 * @brief Setup new USB device configuration 80 * 81 * This function disables all active endpoints of current configuration 82 * and enables all interface alternate 0 endpoints of a new configuration. 83 * Determined to be called Set Configuration request. 84 * 85 * @param[in] ctx Pointer to USB device support context 86 * @param[in] new_cfg New configuration number (bConfigurationValue) 87 * 88 * @return 0 on success, other values on fail. 89 */ 90 int usbd_config_set(struct usbd_context *uds_ctx, uint8_t new_cfg); 91 92 #endif /* ZEPHYR_INCLUDE_USBD_CONFIG_H */ 93