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] cfg Configuration number (bConfigurationValue) 46 * 47 * @return pointer to configuration node or NULL if does not exist 48 */ 49 struct usbd_config_node *usbd_config_get(struct usbd_contex *uds_ctx, 50 uint8_t cfg); 51 52 /** 53 * @brief Get selected configuration node 54 * 55 * Get configuration node based on configuration selected by the host. 56 * 57 * @param[in] ctx Pointer to USB device support context 58 * 59 * @return pointer to configuration node or NULL if does not exist 60 */ 61 struct usbd_config_node *usbd_config_get_current(struct usbd_contex *uds_ctx); 62 63 /** 64 * @brief Check whether a configuration exist 65 * 66 * @param[in] ctx Pointer to USB device support context 67 * @param[in] cfg Configuration number (bConfigurationValue) 68 * 69 * @return True if a configuration exist. 70 */ 71 bool usbd_config_exist(struct usbd_contex *const uds_ctx, 72 const uint8_t cfg); 73 74 /** 75 * @brief Setup new USB device configuration 76 * 77 * This function disables all active endpoints of current configuration 78 * and enables all interface alternate 0 endpoints of a new configuration. 79 * Determined to be called Set Configuration request. 80 * 81 * @param[in] ctx Pointer to USB device support context 82 * @param[in] new_cfg New configuration number (bConfigurationValue) 83 * 84 * @return 0 on success, other values on fail. 85 */ 86 int usbd_config_set(struct usbd_contex *uds_ctx, uint8_t new_cfg); 87 88 #endif /* ZEPHYR_INCLUDE_USBD_CONFIG_H */ 89