1 /* 2 * Copyright (c) 2022 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_USBD_DEVICE_H 8 #define ZEPHYR_INCLUDE_USBD_DEVICE_H 9 10 #include <zephyr/usb/usbd.h> 11 12 /** 13 * @brief Get device descriptor bNumConfigurations value 14 * 15 * @param[in] uds_ctx Pointer to a device context 16 * 17 * @return bNumConfigurations value 18 */ usbd_get_num_configs(const struct usbd_contex * const uds_ctx)19static inline uint8_t usbd_get_num_configs(const struct usbd_contex *const uds_ctx) 20 { 21 struct usb_device_descriptor *desc = uds_ctx->desc; 22 23 return desc->bNumConfigurations; 24 } 25 26 27 /** 28 * @brief Set device descriptor bNumConfigurations value 29 * 30 * @param[in] uds_ctx Pointer to a device context 31 * @param[in] value new bNumConfigurations value 32 */ usbd_set_num_configs(struct usbd_contex * const uds_ctx,const uint8_t value)33static inline void usbd_set_num_configs(struct usbd_contex *const uds_ctx, 34 const uint8_t value) 35 { 36 struct usb_device_descriptor *desc = uds_ctx->desc; 37 38 desc->bNumConfigurations = value; 39 } 40 41 /** 42 * @brief Check whether USB device is enabled 43 * 44 * @param[in] node Pointer to a device context 45 * 46 * @return true if USB device is in enabled, false otherwise 47 */ usbd_is_enabled(const struct usbd_contex * const uds_ctx)48static inline bool usbd_is_enabled(const struct usbd_contex *const uds_ctx) 49 { 50 return uds_ctx->status.enabled; 51 } 52 53 /** 54 * @brief Check whether USB device is enabled 55 * 56 * @param[in] node Pointer to a device context 57 * 58 * @return true if USB device is in enabled, false otherwise 59 */ usbd_is_initialized(const struct usbd_contex * const uds_ctx)60static inline bool usbd_is_initialized(const struct usbd_contex *const uds_ctx) 61 { 62 return uds_ctx->status.initialized; 63 } 64 65 /** 66 * @brief Set device suspended status 67 * 68 * @param[in] uds_ctx Pointer to a device context 69 * @param[in] value new suspended value 70 */ usbd_status_suspended(struct usbd_contex * const uds_ctx,const bool value)71static inline void usbd_status_suspended(struct usbd_contex *const uds_ctx, 72 const bool value) 73 { 74 uds_ctx->status.suspended = value; 75 } 76 77 /** 78 * @brief Lock USB device stack context 79 * 80 * @param[in] node Pointer to a device context 81 */ usbd_device_lock(struct usbd_contex * const uds_ctx)82static inline void usbd_device_lock(struct usbd_contex *const uds_ctx) 83 { 84 k_mutex_lock(&uds_ctx->mutex, K_FOREVER); 85 } 86 87 /** 88 * @brief Lock USB device stack context 89 * 90 * @param[in] node Pointer to a device context 91 */ usbd_device_unlock(struct usbd_contex * const uds_ctx)92static inline void usbd_device_unlock(struct usbd_contex *const uds_ctx) 93 { 94 k_mutex_unlock(&uds_ctx->mutex); 95 } 96 97 /** 98 * @brief Init USB device stack core 99 * 100 * @param[in] uds_ctx Pointer to a device context 101 * 102 * @return 0 on success, other values on fail. 103 */ 104 int usbd_device_init_core(struct usbd_contex *uds_ctx); 105 106 /** 107 * @brief Shutdown USB device stack core 108 * 109 * @param[in] uds_ctx Pointer to a device context 110 * 111 * @return 0 on success, other values on fail. 112 */ 113 int usbd_device_shutdown_core(struct usbd_contex *const uds_ctx); 114 115 #endif /* ZEPHYR_INCLUDE_USBD_DEVICE_H */ 116