Skip to content

Commit 4202f6e

Browse files
author
Josuah Demangeon
committed
usb: host: add host status to the host context
Add a "struct usbh_status" that contains a bitmask of flags to keep track of the global state of the host context, like done for the device_next implementation. Add helpers to check the status. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 1bad1d0 commit 4202f6e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

include/zephyr/usb/usbh.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ extern "C" {
3333
* @{
3434
*/
3535

36+
/**
37+
* USB host support status
38+
*/
39+
struct usbh_status {
40+
/** USB host support is initialized */
41+
unsigned int initialized : 1;
42+
/** USB host support is enabled */
43+
unsigned int enabled : 1;
44+
};
45+
3646
/**
3747
* USB host support runtime context
3848
*/
@@ -43,6 +53,8 @@ struct usbh_context {
4353
struct k_mutex mutex;
4454
/** Pointer to UHC device struct */
4555
const struct device *dev;
56+
/** Status of the USB host support */
57+
struct usbh_status status;
4658
/** USB device list */
4759
sys_dlist_t udevs;
4860
/** USB root device */

subsys/usb/host/usbh_host.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_USBH_HOST_H
8+
#define ZEPHYR_INCLUDE_USBH_HOST_H
9+
10+
#include <stdbool.h>
11+
#include <zephyr/usb/usbh.h>
12+
13+
/**
14+
* @brief Check whether USB host is enabled
15+
*
16+
* @param[in] uhs_ctx Pointer to a host context
17+
*
18+
* @return true if USB host is in enabled, false otherwise
19+
*/
20+
static inline bool usbd_is_enabled(const struct usbh_context *const uhs_ctx)
21+
{
22+
return uhs_ctx->status.enabled;
23+
}
24+
25+
/**
26+
* @brief Check whether USB host is enabled
27+
*
28+
* @param[in] uhs_ctx Pointer to a host context
29+
*
30+
* @return true if USB host is in enabled, false otherwise
31+
*/
32+
static inline bool usbd_is_initialized(const struct usbh_context *const uhs_ctx)
33+
{
34+
return uhs_ctx->status.initialized;
35+
}
36+
37+
#endif /* ZEPHYR_INCLUDE_USBH_HOST_H */

0 commit comments

Comments
 (0)