Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions include/zephyr/usb/usbh.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
/**
* USB host support runtime context
*/
struct usbh_contex {
struct usbh_context {
/** Name of the USB device */
const char *name;
/** Access mutex */
Expand All @@ -53,7 +53,7 @@ struct usbh_contex {

#define USBH_CONTROLLER_DEFINE(device_name, uhc_dev) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider adding doxygen docs at some point in the future :) thanks!

SYS_BITARRAY_DEFINE_STATIC(ba_##device_name, 128); \
static STRUCT_SECTION_ITERABLE(usbh_contex, device_name) = { \
static STRUCT_SECTION_ITERABLE(usbh_context, device_name) = { \
.name = STRINGIFY(device_name), \
.mutex = Z_MUTEX_INITIALIZER(device_name.mutex), \
.dev = uhc_dev, \
Expand All @@ -80,20 +80,20 @@ struct usbh_class_data {
struct usbh_code_triple code;

/** Initialization of the class implementation */
/* int (*init)(struct usbh_contex *const uhs_ctx); */
/* int (*init)(struct usbh_context *const uhs_ctx); */
/** Request completion event handler */
int (*request)(struct usbh_contex *const uhs_ctx,
int (*request)(struct usbh_context *const uhs_ctx,
struct uhc_transfer *const xfer, int err);
/** Device connected handler */
int (*connected)(struct usbh_contex *const uhs_ctx);
int (*connected)(struct usbh_context *const uhs_ctx);
/** Device removed handler */
int (*removed)(struct usbh_contex *const uhs_ctx);
int (*removed)(struct usbh_context *const uhs_ctx);
/** Bus remote wakeup handler */
int (*rwup)(struct usbh_contex *const uhs_ctx);
int (*rwup)(struct usbh_context *const uhs_ctx);
/** Bus suspended handler */
int (*suspended)(struct usbh_contex *const uhs_ctx);
int (*suspended)(struct usbh_context *const uhs_ctx);
/** Bus resumed handler */
int (*resumed)(struct usbh_contex *const uhs_ctx);
int (*resumed)(struct usbh_context *const uhs_ctx);
};

/**
Expand All @@ -109,7 +109,7 @@ struct usbh_class_data {
*
* @return 0 on success, other values on fail.
*/
int usbh_init(struct usbh_contex *uhs_ctx);
int usbh_init(struct usbh_context *uhs_ctx);

/**
* @brief Enable the USB host support and class instances
Expand All @@ -120,7 +120,7 @@ int usbh_init(struct usbh_contex *uhs_ctx);
*
* @return 0 on success, other values on fail.
*/
int usbh_enable(struct usbh_contex *uhs_ctx);
int usbh_enable(struct usbh_context *uhs_ctx);

/**
* @brief Disable the USB host support
Expand All @@ -131,7 +131,7 @@ int usbh_enable(struct usbh_contex *uhs_ctx);
*
* @return 0 on success, other values on fail.
*/
int usbh_disable(struct usbh_contex *uhs_ctx);
int usbh_disable(struct usbh_context *uhs_ctx);

/**
* @brief Shutdown the USB host support
Expand All @@ -142,7 +142,7 @@ int usbh_disable(struct usbh_contex *uhs_ctx);
*
* @return 0 on success, other values on fail.
*/
int usbh_shutdown(struct usbh_contex *const uhs_ctx);
int usbh_shutdown(struct usbh_context *const uhs_ctx);

/**
* @}
Expand Down
50 changes: 25 additions & 25 deletions samples/subsys/usb/shell/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,37 @@ Sample shell interaction

.. code-block:: console

uart:~$ usbd defaults
dev: USB descriptors initialized
uart:~$ usbd config add 1
uart:~$ usbd class add foobaz 1
dev: added USB class foobaz to configuration 1
uart:~$ usbd init
*** Booting Zephyr OS build v4.2.0-1588-g83f1bd7341de ***
uart:~$ usbd defcfg
dev: added default string descriptors
dev: register FS loopback_0
dev: register HS loopback_0
dev: USB initialized
uart:~$ usbh init
host: USB host initialized
uart:~$ usbh enable
host: USB host enabled
[611:00:28.620,000] <wrn> usbd_core: VBUS detected event
uart:~$ usbh bus resume
host: USB bus resumed
uart:~$ usbd enable
host: USB device connected
dev: USB enabled
uart:~$ usbh device descriptor device 0
host: transfer finished 0x20006250, err 0
00000000: 80 06 00 01 00 00 12 00 |........ |
bLength 18
bDescriptorType 1
bcdUSB 200
bDeviceClass 239
bDeviceSubClass 2
bDeviceProtocol 1
bMaxPacketSize0 64
idVendor 2fe3
idProduct ffff
bcdDevice 301
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
[160:04:13.870,000] <inf> usb_loopback: Enable loopback_0
uart:~$ usbh device list
1
uart:~$ usbh device descriptor device 1
host: USB device with address 1
bLength 18
bDescriptorType 1
bcdUSB 200
bDeviceClass 239
bDeviceSubClass 2
bDeviceProtocol 1
bMaxPacketSize0 64
idVendor 2fe3
idProduct ffff
bcdDevice 402
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
uart:~$
25 changes: 13 additions & 12 deletions subsys/usb/host/usbh_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

#include <errno.h>
#include <zephyr/sys/util.h>
#include "usbh_host.h"
#include "usbh_internal.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(uhs_api, CONFIG_USBH_LOG_LEVEL);

int usbh_init(struct usbh_contex *uhs_ctx)
int usbh_init(struct usbh_context *uhs_ctx)
{
int ret;

k_mutex_lock(&uhs_ctx->mutex, K_FOREVER);
usbh_host_lock(uhs_ctx);

if (!device_is_ready(uhs_ctx->dev)) {
LOG_ERR("USB host controller is not ready");
Expand All @@ -32,15 +33,15 @@ int usbh_init(struct usbh_contex *uhs_ctx)
ret = usbh_init_device_intl(uhs_ctx);

init_exit:
k_mutex_unlock(&uhs_ctx->mutex);
usbh_host_unlock(uhs_ctx);
return ret;
}

int usbh_enable(struct usbh_contex *uhs_ctx)
int usbh_enable(struct usbh_context *uhs_ctx)
{
int ret;

k_mutex_lock(&uhs_ctx->mutex, K_FOREVER);
usbh_host_lock(uhs_ctx);

if (!uhc_is_initialized(uhs_ctx->dev)) {
LOG_WRN("USB host controller is not initialized");
Expand All @@ -61,11 +62,11 @@ int usbh_enable(struct usbh_contex *uhs_ctx)
}

enable_exit:
k_mutex_unlock(&uhs_ctx->mutex);
usbh_host_unlock(uhs_ctx);
return ret;
}

int usbh_disable(struct usbh_contex *uhs_ctx)
int usbh_disable(struct usbh_context *uhs_ctx)
{
int ret;

Expand All @@ -74,30 +75,30 @@ int usbh_disable(struct usbh_contex *uhs_ctx)
return 0;
}

k_mutex_lock(&uhs_ctx->mutex, K_FOREVER);
usbh_host_lock(uhs_ctx);

ret = uhc_disable(uhs_ctx->dev);
if (ret) {
LOG_ERR("Failed to disable USB controller");
}

k_mutex_unlock(&uhs_ctx->mutex);
usbh_host_unlock(uhs_ctx);

return 0;
}

int usbh_shutdown(struct usbh_contex *const uhs_ctx)
int usbh_shutdown(struct usbh_context *const uhs_ctx)
{
int ret;

k_mutex_lock(&uhs_ctx->mutex, K_FOREVER);
usbh_host_lock(uhs_ctx);

ret = uhc_shutdown(uhs_ctx->dev);
if (ret) {
LOG_ERR("Failed to shutdown USB device");
}

k_mutex_unlock(&uhs_ctx->mutex);
usbh_host_unlock(uhs_ctx);

return ret;
}
14 changes: 7 additions & 7 deletions subsys/usb/host/usbh_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int usbh_event_carrier(const struct device *dev,
return err;
}

static void dev_connected_handler(struct usbh_contex *const ctx,
static void dev_connected_handler(struct usbh_context *const ctx,
const struct uhc_event *const event)
{

Expand Down Expand Up @@ -73,7 +73,7 @@ static void dev_connected_handler(struct usbh_contex *const ctx,
}
}

static void dev_removed_handler(struct usbh_contex *const ctx)
static void dev_removed_handler(struct usbh_context *const ctx)
{
if (ctx->root != NULL) {
usbh_device_free(ctx->root);
Expand All @@ -84,7 +84,7 @@ static void dev_removed_handler(struct usbh_contex *const ctx)
}
}

static int discard_ep_request(struct usbh_contex *const ctx,
static int discard_ep_request(struct usbh_context *const ctx,
struct uhc_transfer *const xfer)
{
const struct device *dev = ctx->dev;
Expand All @@ -97,7 +97,7 @@ static int discard_ep_request(struct usbh_contex *const ctx,
return uhc_xfer_free(dev, xfer);
}

static ALWAYS_INLINE int usbh_event_handler(struct usbh_contex *const ctx,
static ALWAYS_INLINE int usbh_event_handler(struct usbh_context *const ctx,
struct uhc_event *const event)
{
int ret = 0;
Expand Down Expand Up @@ -141,7 +141,7 @@ static void usbh_bus_thread(void *p1, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);

struct usbh_contex *uhs_ctx;
struct usbh_context *uhs_ctx;
struct uhc_event event;

while (true) {
Expand All @@ -158,7 +158,7 @@ static void usbh_thread(void *p1, void *p2, void *p3)
ARG_UNUSED(p2);
ARG_UNUSED(p3);

struct usbh_contex *uhs_ctx;
struct usbh_context *uhs_ctx;
struct uhc_event event;
usbh_udev_cb_t cb;
int ret;
Expand All @@ -182,7 +182,7 @@ static void usbh_thread(void *p1, void *p2, void *p3)
}
}

int usbh_init_device_intl(struct usbh_contex *const uhs_ctx)
int usbh_init_device_intl(struct usbh_context *const uhs_ctx)
{
int ret;

Expand Down
2 changes: 1 addition & 1 deletion subsys/usb/host/usbh_data.ld
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <zephyr/linker/iterable_sections.h>

ITERABLE_SECTION_RAM(usbh_contex, Z_LINK_ITERABLE_SUBALIGN)
ITERABLE_SECTION_RAM(usbh_context, Z_LINK_ITERABLE_SUBALIGN)
ITERABLE_SECTION_RAM(usbh_class_data, Z_LINK_ITERABLE_SUBALIGN)
14 changes: 7 additions & 7 deletions subsys/usb/host/usbh_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ K_MEM_SLAB_DEFINE_STATIC(usb_device_slab, sizeof(struct usb_device),

K_HEAP_DEFINE(usb_device_heap, CONFIG_USBH_USB_DEVICE_HEAP);

struct usb_device *usbh_device_alloc(struct usbh_contex *const uhs_ctx)
struct usb_device *usbh_device_alloc(struct usbh_context *const uhs_ctx)
{
struct usb_device *udev;

Expand All @@ -37,7 +37,7 @@ struct usb_device *usbh_device_alloc(struct usbh_contex *const uhs_ctx)

void usbh_device_free(struct usb_device *const udev)
{
struct usbh_contex *const uhs_ctx = udev->ctx;
struct usbh_context *const uhs_ctx = udev->ctx;

sys_bitarray_clear_bit(uhs_ctx->addr_ba, udev->addr);
sys_dlist_remove(&udev->node);
Expand All @@ -48,7 +48,7 @@ void usbh_device_free(struct usb_device *const udev)
k_mem_slab_free(&usb_device_slab, (void *)udev);
}

struct usb_device *usbh_device_get_any(struct usbh_contex *const uhs_ctx)
struct usb_device *usbh_device_get_any(struct usbh_context *const uhs_ctx)
{
sys_dnode_t *const node = sys_dlist_peek_head(&uhs_ctx->udevs);
struct usb_device *udev;
Expand All @@ -58,7 +58,7 @@ struct usb_device *usbh_device_get_any(struct usbh_contex *const uhs_ctx)
return udev;
}

struct usb_device *usbh_device_get(struct usbh_contex *const uhs_ctx, const uint8_t addr)
struct usb_device *usbh_device_get(struct usbh_context *const uhs_ctx, const uint8_t addr)
{
struct usb_device *udev;

Expand Down Expand Up @@ -99,7 +99,7 @@ static int validate_device_mps0(const struct usb_device *const udev)

static int alloc_device_address(struct usb_device *const udev, uint8_t *const addr)
{
struct usbh_contex *const uhs_ctx = udev->ctx;
struct usbh_context *const uhs_ctx = udev->ctx;
int val;
int err;

Expand Down Expand Up @@ -285,7 +285,7 @@ static int parse_configuration_descriptor(struct usb_device *const udev)
dhp = (void *)((uint8_t *)udev->cfg_desc + cfg_desc->bLength);
desc_end = (void *)((uint8_t *)udev->cfg_desc + cfg_desc->wTotalLength);

while ((dhp->bDescriptorType != 0 || dhp->bLength != 0) && (void *)dhp < desc_end) {
while ((void *)dhp < desc_end && (dhp->bDescriptorType != 0 || dhp->bLength != 0)) {
if (dhp->bDescriptorType == USB_DESC_INTERFACE_ASSOC) {
iad = (struct usb_association_descriptor *)dhp;
LOG_DBG("bFirstInterface %u", iad->bFirstInterface);
Expand Down Expand Up @@ -449,7 +449,7 @@ int usbh_device_set_configuration(struct usb_device *const udev, const uint8_t n

int usbh_device_init(struct usb_device *const udev)
{
struct usbh_contex *const uhs_ctx = udev->ctx;
struct usbh_context *const uhs_ctx = udev->ctx;
uint8_t new_addr;
int err;

Expand Down
Loading