Commit graph

1,054 commits

Author SHA1 Message Date
Roman Leonov
a0dee7ddad usb: host: shell: add usbh device list_dd command
Added:
- usbh shell command to dump descriptors

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-04-17 10:34:50 +02:00
Johann Fischer
8d2cc34ecf usb: device_next: allow cdc_acm_poll_in() to receive
Allow cdc_acm_poll_in() to receive when CDC ACM function gets enabled,
but only when the IRQ API is not already used.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-04-14 22:08:22 -04:00
Nicholas Cadieux
4e5cb31d32 usb_c: pe: fix PE state on DRS sender response timeout
When the SenderResponseTimer expires in PE_DRS_SEND_SWAP, PE was
unconditionally transitioning to PE_SNK_READY. This is incorrect when
the port is operating as a Source, as it should return to PE_SRC_READY.

Replace pe_set_state(dev, PE_SNK_READY) with pe_set_ready_state(dev),
which selects the correct ready state based on the current power role.

Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
2026-03-31 18:24:46 -05:00
Alexander Wachter
a03080b002 usb: usb_c: fix level of vbus check in Attached.SNK
The transition from Attached.SNK to Unattached.SNK is currently
triggered if vbus is < vSafe5V.
USB-Type C Spec R2.4 Table 4-3 defines vSinkDisconnect as
the voltage to be used for the transition from
Attached.SNK to Unattached.SNK
This commit changes the check to use the correct voltage level.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2026-03-31 18:22:17 -05:00
Nicholas Cadieux
2665774487 usb: usb_c: pe: fix DPM notifications on PD attach and detach
On PD capable SRC detach, DPM was not being notified of
POWER_CHANGE_0A0 or NOT_PD_CONNECTED. Fix by notifying
POWER_CHANGE_0A0 in tc_attached_snk_exit() and NOT_PD_CONNECTED in
pe_suspend_entry().

On PD capable SNK or SRC detach, pe_suspend_entry() did not clear
the explicit contract flag. Fix by clearing PE_FLAGS_EXPLICIT_CONTRACT
in pe_suspend_entry().

On PD capable SNK attach, DPM was not being notified of PD_CONNECTED
at the correct time. Fix by notifying PD_CONNECTED when PS_RDY is
successfully transmitted (source) or received (sink), using
atomic_test_and_set_bit() to prevent duplicate notifications during
renegotiations.

Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
2026-03-30 10:02:58 -05:00
Fabio Baltieri
4d8eeff467 usb: device_next: cdc_acm: fix an llvm warning
Fixes an unused function warning when compiling with llvm, looks like
that does not fire with gcc for inline functions but it does for llvm,
tested with:

west build -p -b nrf52840dk/nrf52840 samples/subsys/usb/cdc_acm --
-DTOOLCHAIN_VARIANT_COMPILER=llvm -DCONFIG_UART_LINE_CTRL=n

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-03-27 12:35:07 -04:00
Fabio Baltieri
f08d56de23 usb: device_next: hid: fix some llvm warnings
Fixes:

zephyrproject/zephyr/subsys/usb/device_next/class/usbd_hid.c:635:19:
warning: unused function 'hid_dev_set_out_polling' [-Wunused-function]
zephyrproject/zephyr/subsys/usb/device_next/class/usbd_hid.c:665:19:
warning: unused function 'hid_dev_set_in_polling' [-Wunused-function]

When compiling with LLVM:

west build -p -b nrf52840dk/nrf52840 samples/subsys/usb/hid-keyboard --
-DTOOLCHAIN_VARIANT_COMPILER=llvm

Functions are only used when CONFIG_USBD_HID_SET_POLLING_PERIOD is
enabled, set as __maybe_unused instaed of inline.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-03-27 12:35:07 -04:00
Josuah Demangeon
7f1bf6028c usb: uvc: fix incorrect frame interval decoding
UVC counts frame intervals as 100ns units, so to get a number in
nanosecond, the value from USB needs to be divided by either
(USEC_PER_SEC * 10) or (NSEC_PER_SEC / 100). A mix of the two
was used.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2026-03-26 10:47:08 -04:00
Johann Fischer
04c150e3df usb: uvc: assign the actual streaming interface number
When UVC is part of a multi-function device, baInterfaceNr(0) may point
to an incorrect interface number. Assign the actual streaming interface
number after the configuration descriptor is initialized.

This is follow-up on commit 8d7bb597fc
("usb: uvc: use uvc_device_ in API and add _enable()/_shutdown()").

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-03-26 10:45:17 -04:00
Josuah Demangeon
8d7bb597fc usb: uvc: use uvc_device_ in API and add _enable()/_shutdown()
Use a different API call to complete the function rather than
relying on USB .init() to terminate the configuration.
This allows to set the endpoint descriptors before usbd_init()
is called.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-03-23 12:31:57 -05:00
Nicholas Cadieux
cf8197b7d1 usbc: tcpc: fix memory corruption in vconn_en and vconn_discharge callbacks
The vconn_en and vconn_discharge callbacks were invoked with the TCPC
device as the first argument. Application callbacks then called
usbc_get_dpm_data(dev) with the TCPC device, causing dev->data (which
is struct tcpc_data *) to be misinterpreted as struct usbc_port_data *.
This resulted in dpm_data->vconn_pol being written to an incorrect
memory offset, silently corrupting TCPC driver state.

Fix by adding a const struct device *usbc_dev parameter to
tcpc_vconn_control_cb_t and tcpc_vconn_discharge_cb_t, and propagating
it through set_vconn_cb and set_vconn_discharge_cb in the driver API.

Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
2026-03-21 00:48:09 +00:00
Nicholas Cadieux
d920c1689f usb: usb_c: tc: fix usbc_tc init race condition
Introduces a new TC_STARTUP_STATE to handle the initialization phase of
the Type-C state machine.

Previously, the state machine was initialized to TC_DISABLED_STATE during
POST_KERNEL initialization. This state inherits from
TC_CC_OPEN_SUPER_STATE, which executes tcpc_set_vconn(false). Since
VCONN callbacks are typically registered in main() (which runs after
POST_KERNEL), this resulted in an error log and the statemachine
unexpectedly transitioning to TC_ERROR_RECOVERY_STATE.

The new TC_STARTUP_STATE has no parent state and performs no hardware
operations. The state machine now transitions:
1. Boot (POST_KERNEL): Initialize to TC_STARTUP_STATE.
2. Start (MAIN): When usbc_start() runs the thread, tc_init() transitions
   to TC_DISABLED_STATE (ensuring VCONN/VBUS off with valid callbacks).
3. Run: Immediately transitions to TC_ERROR_RECOVERY_STATE to begin
   protocol operation.

Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
2026-03-21 00:48:09 +00:00
Nicholas Cadieux
9990ffa1d6 usb: usb_c: add Dual Role Power (DRP) support
Introduces DRP support to the USB-C subsystem, enabling dynamic
support for both Source and Sink power roles. Unattached devices
toggle between Source (Rp) and Sink (Rd) CC advertisements based
on the configured DRP period (tDRP) and duty cycle (dcSRC.DRP).
Once an attach is detected, the device enters the appropriate
Attached.SRC or Attached.SNK usbc_tc state and starts the
corresponding usbc_pe state machine to negotiate a power contract.

Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
2026-03-21 00:48:09 +00:00
Tomasz Moń
1525950cd6 usb: device_next: remove udc_buf_get_all()
Function udc_buf_get_all() was intended to be a helper to remove all
requests from endpoint FIFO. While for just freeing all queue the
it may be argued that there may be some doubtful simplicity argument,
merging multiple submitted transfers into one is just enforcing
unnecessary complexity on class implementations.

At general level, every submitted (enqueued) request should get
corresponding completion (request callback) call. UDC drivers were
violating this sensible behavior when dequeuing (cancelling) requests by
merging all submitted requests into one.

Remove udc_buf_get_all() and replace all uses with simple loops. For
most classes (that submit just one request for an endpoint at a time)
this has no functional difference. For classes that implement double
buffering this simplifies completion handling.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-03-21 00:47:16 +00:00
Aiden Hu
d820b0bd6a usb: host: uvc: implement USB host UVC class with video API
Add a USB Video Class (UVC) host class implementation that enables
Zephyr-based systems to act as USB hosts for standard UVC cameras.
This allows applications to capture video streams from USB cameras
using the standard Zephyr video API.

The implementation follows the UVC specification for device enumeration,
format negotiation, and stream control. It handles the complexity of UVC
descriptor parsing, bandwidth management, and isochronous transfer
scheduling, presenting a clean video device interface to applications.

Support for common camera controls such as brightness, contrast,
exposure, focus, and zoom allows applications to adjust camera settings
at runtime. Dynamic format and frame rate changes are also supported,
making it suitable for various use cases from simple video capture to
more advanced computer vision applications.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-03-21 00:46:16 +00:00
Aiden Hu
ee9c2221ee usb: uvc: add UVC_MAX_CTRL_SIZE macro
This macro is used for the data size of uvc control.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-03-21 00:46:16 +00:00
Tomasz Moń
188118f562 usb: device_next: Preallocate SETUP buffer
Preallocate and keep reusing the same buffer for SETUP data. This
ensures that USB stack will always be able to handle SETUP stage
regardless of UDC memory pool usage.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-03-19 16:58:56 +01:00
Tomasz Moń
244b015e99 usb: device_next: Allocate control buffers in stack
Allocating buffer in response to control transfer is part of processing
and therefore should not be done in UDC driver but rather in the stack.

Simplify UDC driver design by moving all control transfer buffer
allocations and processing to USB stack.

New control transfer handling flow is as follows:
  1. USB stack allocates and queues buffer for Setup stage. This informs
     UDC driver that USB stack is ready to process new transfer.
  2. UDC driver completes enqueued Setup buffer. SETUP data may have
     been received by device before Setup buffer was enqueued.
     If multiple SETUP data was received, UDC driver must complete
     request using last received SETUP data.
  3. USB stack processes request. USB stack is responsible for:
       * Stalling control endpoint when request cannot be processed
       * Allocating and enqueueing Data stage buffer if necessary
           - Depending on enqueued endpoint (IN/OUT), UDC driver is
	     expected to complete the transfer. If host sends new SETUP
             data for any reason (e.g. timeout), then Data stage buffer
             must be completed with -ECONNRESET code.
           - UDC driver may postpone processing Data IN until USB stack
	     enqueues new Setup stage buffer.
       * Handling status stage if applicable
           - If Data IN was enqueued, stack immediately allocates and
	     enqueues Status OUT stage buffer.
           - If Data OUT was enqueued, stack waits for Data OUT buffer
	     completion before doing any further processing.
           - If control transfer handling fails, stack is expected to
             STALL control endpoint.
       * Allocating and enqueuing Setup buffer.
           - This informs UDC driver that stack has finished processing
	     control transfer. UDC driver may choose to start processing
             Data IN and/or Status OUT only after new Setup buffer is
             enqueued.
  4. UDC driver must fail (complete with -ECONNRESET) any enqueued and
     not completed Data and Status buffers if host sends new SETUP data.
     UDC driver must be able to buffer last received SETUP data until
     USB stack is ready (enqueues Setup buffer).
  5. UDC driver must complete all Data and Status buffers before it
     completes Setup buffer.
  6. UDC driver may keep ownership of Setup, Data and/or Status buffers
     across USB bus resets. USB stack does not attempt to dequeue any
     control transfer buffer it enqueued.

This approach implicitly synchronizes UDC driver against USB stack,
which ensures that only one set of Setup/Data/Status buffers is
allocated at a time.

Another advantage of the rework is drawing a clear line on buffer
ownership. The buffer responsibilities are as follows:
  * USB stack is the only entity that both allocates and frees the
    buffers. Only USB stack is allowed to set "setup", "data" and
    "status" fields in struct udc_buf_info.
  * UDC takes ownership of buffers handed to it in udc_ep_enqueue().
  * UDC releases buffer ownership by calling udc_submit_ep_event().

Because there is just a single place where the buffer ownership changes,
and all buffers must go USB stack (alloc) -> UDC (perform requests on
the bus) -> USB stack (free) route it would be possible in the future to
implement a "tap" similar to Linux usbmon that would ease debugging.

This commit significantly changes how USB stack communicates with UDC
drivers. It was decided that supporting both the old and new model
simultaneously would require way too much effort. Therefore all UDC
drivers were reworked. Following people worked on driver rework:
  * Tomasz Moń - ambiq, dwc2, kinetis, mcux ip3511, nrf, numaker,
                 renesas ra, rpi pico, smartbond, virtual
  * Mathieu Choplain - stm32
  * Mark Wang - mcux ehci
  * Johann Fischer - sam0, stm32
  * Ren Chen - it82xx2
  * Brandon Hurst - max32
  * Gerson Fernando Budke - sam udp, sam usbc, sam usbhs

Co-authored-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Co-authored-by: Mark Wang <yichang.wang@nxp.com>
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
Co-authored-by: Ren Chen <Ren.Chen@ite.com.tw>
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
Co-authored-by: Brandon Hurst <brandon.hurst@analog.com>
Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
Co-authored-by: Gerson Fernando Budke <nandojve@gmail.com>
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-03-19 16:58:56 +01:00
Jamie McCrae
f22592cbc5 tree: Replace FIXED_PARTITION_* macro usage with PARTITION_*
Replaces usage of these deprecated macros with ones that support
fixed and mapped partition compatibles. Also includes an update to
hal_espressif which also (rightly or wrongly) has zephyr specific
code in it

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-03-17 18:24:52 -04:00
Roman Leonov
638731f438 drivers: usb: host: Fixed small typo in description
Fixed small typo in doxygen description interace -> interface.

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
2026-03-17 18:18:49 -04:00
Aiden Hu
fb3ae541cf usb: host: refine connect/disconnect handling
The attach and detach flow was previously scattered across bus event
handlers and class code, causing duplicated enumeration and class
probe/remove logic. Root-device state was also manipulated directly in
the host context, which made lifecycle handling implicit and limited
the ability to support devices behind a hub.

This update introduces common helpers for device attach and detach and
replaces direct root access with simple accessor functions. By unifying
enumeration and teardown into a single path, the control flow becomes
clearer and more consistent, and the host stack is no longer tied to a
single-root assumption. These changes form the basis for supporting
multiple devices attached through a hub in future updates.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-03-17 10:25:34 +00:00
Josuah Demangeon
8d669364e6 usb: device_next: uvc: fix ordering of frame interval
Fix the qsort comparison function that was hitting an integer underflow.
Some video sources such as video-sw-generator have UINT32_MAX for maximum
frame interval (arbitrarily slow), which made the comparison underflow,
which in turn lead to frame interval being listed in the wrong order,
breaking Windows support.

Fixes #101259.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-03-11 23:18:21 -04:00
Henrik Brix Andersen
0f8e72a7c2 usb: device_next: reduce log level to debug for internal status logs
Reduce the log level to debug for a number of internal status logs within
the USB device_next stack.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2026-03-11 20:55:57 -04:00
James Bennion-Pedley
d0057bd2cc usb: uac2: kconfig override for feedback endpoint size
Adds compile-time option for overriding UAC2 Feedback endpoint to allow
usage with non-class-compliant Windows UAC2 driver.

Signed-off-by: James Bennion-Pedley <James.Bennion-Pedley@thinksmartbox.com>
2026-03-06 15:12:15 +01:00
Tomasz Moń
cbe1958809 usb: device_next: dfu: actually fail requests
Control read handlers handle_get_status(), handle_get_state() and
handle_upload() return value is used to set errno. Setting errno inside
the functions and then returning 0 therefore does not fail the request
as intended.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-02-20 14:58:46 +01:00
Josuah Demangeon
6c1d24cde1 usb: device_next: uvc: fix frame/formats descriptors
The standard format "frame-based payload" was abused as a way to get
generic descriptors that match all other format and frame types.
This is not accurate as some fields do not match, causing misalignment
of some struct fields in some case.

Correct the misuse by introducing new valid structs and refactoring the
descriptor parsing to use them instead.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2026-02-18 10:30:44 +00:00
Josuah Demangeon
4360894965 usb: host: class: support multiple controllers
Only bind to a controller after probing. Wait that a class is matching and
assigned to a device to assign a host controller to a class. This allows
a class to be used by any of the controller in place.
Remove the `c_data->uhs_ctx` field, not used anywhere, in favor of using
`c_data->udev->ctx`.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2026-02-18 10:29:27 +00:00
Muhammad Waleed Badar
4490c05eef usb: device_next: shell: adopt SHELL_HELP macro
Convert USB device shell command help strings to use the
SHELL_HELP() macro instead of inline help text.

This aligns the USB device shell with the updated shell help
formatting used across the tree and ensures consistent
presentation of command descriptions and argument usage.

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
2026-02-13 13:56:04 +01:00
Johann Fischer
eee1fa2d2c usb: usbip: use recently introduce zsock_send_all()
zsock_send() does not necessarily have to send the entire data. Use the
recently introduced function zsock_send_all().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-13 10:05:52 +01:00
Johann Fischer
6f602ded27 usb: usbip: retry if the UHC transfer allocation fails
Depending on the server, functions, and client application, we may
get out of transfers very quickly. To throttle here may allow
submitted transfers to be finished.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-13 10:05:52 +01:00
Johann Fischer
665ab07831 usb: usbip: use variable buffer pool for URB data
UHC transfer handling and assignment of completed transfers to URB
sequences relies on the buf->size. For that, we can just use variable
net_buf pools instead of fixed. Perhaps it gives us also better
utilization of the buffer.

Add Kconfig optons to configure pool size and number of buffers
and use large default pool size for native_sim platform.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-13 10:05:52 +01:00
Johann Fischer
c9e105873a usb: usbip: improve completion handling when client disconnects
Make request completion handling a bit more robust when, for whatever
reason, the connection has been closed. Do not implicitly clear the USB
device pointer on client disconnect, to allow the completion callback to
clean up. Before handling USBIP_RET_SUBMIT, check whether the device is
still exported, and if not, just drop completed transfer.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-13 10:05:52 +01:00
Johann Fischer
0c31b37525 usb: move instances Kconfig template to common directory
Move the Kconfig template to configure the number of instances in, for
example, functions or class drivers, to a common directory.
This makes it less confusing when used in host support.

Template was not used in CDC ECM function and can be removed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-12 14:28:18 +00:00
Aiden Hu
0b6930e66d usb: host: fix usbh_bus_thread name setting
Use correct thread data pointer when setting bus thread name.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-02-11 07:59:17 +01:00
Josuah Demangeon
5c88168758 usb: host: shell: call usbh_device_set_address()
Instead of calling the low-level function from usbh_ch9.c, call the
higher level function from usbh_device.c to update the address,
making sure that the udev->address and udev->state are updated
appropriately.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-10 13:02:10 +01:00
Josuah Demangeon
abdc1ff11d usb: host: add a usbh_device_set_address() function
To complement usbh_req_set_address(), add a matching function
usbh_device_set_address() that also takes care of updating the data
structures.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-10 13:02:10 +01:00
Jay Beavers
03a86f89a1 usb: device_next: fix bInterfaceSubClass for CDC ECM data interface
According to the USB CDC 1.2 specification, section 4.6, the value of
bInterfaceSubClass for the data interface should be 0.

Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
2026-02-10 08:23:40 +01:00
Fabio Baltieri
89e778d5b2 usb: device_next: usbd_cdc_{ecm,ncm}: support promisc mode
Flag the ECM and NCM interfaces as supporting promisc mode. There's no
filtering really so enabling promisc is a noop but pretending to have
support is needed to allow these to be added to a bridge.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-02-10 08:22:46 +01:00
Aiden Hu
376d2c3139 usb: uvc: update header for UVC 1.5 compliance
Add input terminal descriptor and CS descriptor header and
extend frame descriptor fields (buffer size, default interval)

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
Co-authored-by: Aiden Hu <weiwei.hu@nxp.com>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-09 16:12:00 -06:00
Josuah Demangeon
9fd1afc6f9 usb: uvc: use max host/device for MAX_FRMIVAL
Compute the maximum of the CONFIG_USBD_VIDEO_MAX_FRMIVAL and
CONFIG_USBH_VIDEO_MAX_FRMIVAL for struct definition, so that
the same struct can be relevant for both host and device
implementation.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
Co-authored-by: Aiden Hu <weiwei.hu@nxp.com>
2026-02-09 16:12:00 -06:00
Josuah Demangeon
69d9f133c4 usb: host: uvc: placeholder implementation
Loop through each of the VideoStreaming and VideoControl descriptor
to parse them. This is meant as a stub for the purpose of testing the
class API.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-09 16:12:00 -06:00
Josuah Demangeon
5412bf3265 usb: uvc: move helpers functinos to common/
Move UVC helper functions to a file shared between UVC host and device.
The arrays are not visible anymore from either USB host or device, but
instead accessed through a front-end funciton.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-06 11:18:45 +01:00
Johann Fischer
5163ea64fe usb: device_next: hid: do not use false and true in COND_CODE_1
With the C23 standard, false and true are keywords and constants of type
bool with a value of 0 and 1. Though there does not seem to be issues
with GCC version 14, there is a note in the specification that the
spelling of false and true inside expressions that are subject to the #
and ## preprocessing operators is unspecified.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-05 16:54:58 +01:00
Alberto Escolar Piedras
45fae3de24 usb: host: Correct function prototype
Correct function prototype which causes a compiler warning
and builds to fail due to it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-05 16:51:26 +01:00
Josuah Demangeon
a8007b2209 usb: host: add debug logs for the configuration descriptor
The USB host will have to select the appropriate size for the configurtion
descriptor, and the defaults will not be enough for some classes that
encode a lot of information in the configuration descriptor.
Add logging to debug this.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
cdd8bdf239 tests: usb: host: test API using initialization code from USB samples
Add tests making sure the USB Host class APIs introduced build
and run as expected. Use USB device samples common code for
initialization.

Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
32c25aa978 usb: host: add a nil entry at the end of configuration descriptor
Allocate a larger size to keep room for a nil descriptor at the end of
the configuration descriptor. This is used to walk through the list of
descriptors until this empty descriptor happens.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
7e455ae0fe usb: host: improve safety of configuration descriptor parsing
Make sure that there is at least enough room for the header before
dereferencing the fields such as bLength.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
29504e2d86 usb: uvc: move the header definition to include/
Move the UVC header with all the definitions from the UVC standard to
share it between USB host and device class implementation.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
92c4d2744e usb: host: introduce usbh_class with init/remove functions
Add functions to probe/remove all classes as part of a new usbh_class.c
and a matching usbh_class.h. These functions are called from the function
usbh_init_device_intl() in usbh_core.c to initialize every class upon
connection of a device. Every class driver provide filters to match the
interfaces of the device.

Co-authored-by: Aiden Hu <weiwei.hu@nxp.com>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00