This commit adds a device-tree prop for the audio streaming
terminals to specify the bInterval values for the Isochronous
endpoints.
Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
Introduce a new USB Video Class (UVC) implementation from scratch.
It exposes a native Zephyr Video driver interface, allowing to call the
video_enqueue()/video_dequeue() interface. It will query the attached
video device to learn about the video capabilities, and use this to
configure the USB descriptors. At runtime, this UVC implementation will
send this device all the control requests, which it will send to the
attached video device. The application can poll the format currently
selected by the host, but will not be alerted when the host configures
a new format, as there is no video.h API for it yet.
Signed-off-by: Josuah Demangeon <me@josuah.net>
UDC drivers use udc_buf_get_all() when dequeueing endpoint. On drivers
that require double buffering for isochronous IN endpoint, the dequeue
on interface disable will result in class request API called on net_buf
with frags set. Call release callback on the buffer pointed in frags
because it was passed in using usbd_uac2_send().
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Allow optimization if high speed is not supported. Unify strings for
error logging. Allow the application to enable/disable the USB device.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
In both implementation, when comparing received data length take into
account that the buffer obtained from bt_buf_get_tx() stores the type at
the top. The buffer types are H:4 and in the TX path we need to check for
BT_HCI_H4_* types not BT_BUF_*.
In the legacy implementation, the hci_acl_pkt_len() function obtains the
length from the USB transaction buffer, which does not contain a buffer
type at the top.
In the new implementation, partially revert the changes and restore
hci_pkt_get_len(), this will be required for any further changes anyway.
Fixes commit f85d63a6cc ("Bluetooth: Remove USB H4 mode support").
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add Kconfig option to limit the length requested from HWINFO to a
meaningful number of digits. Also, check the length returned by the
HWINFO driver and rename the variables to a more suitable name.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
See Discussion https://github.com/zephyrproject-rtos/zephyr/discussions/83659
for information about the purpose of this change.
Modifies run actions of hierarchical state machines
to return a value indicating if the event was handled
by the run action or should be propagated up to the
parent run action. Flat state machines are not affected,
and their run action returns void.
smf_set_handled() has been removed and replaced by
this return value. smf_set_state() will not propagate
events regardless of the return value as the transition
is considered to have occurred.
Documentation, tests, samples, has been updated.
USB-C and hawkBit use SMF and have been updated to use
the new return codes.
Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Apply clang-format to USB-C in preparation for code changes
No code is changed, only formatting.
Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
With the commit fe3c001eeb ("usb: device_next: disable high-speed USB
device descriptor if not used") there is no high-speed device descriptor
by default.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The intention was to use the "interface-name" string property in the
interface string descriptor, but using the label property is acceptable
again. Therefore, allow the use of the DT label property string in the
interface string descriptor.
Follow exactly the same approach as in the CDC ACM implementation
introduced in the commit b0791400f6
("usb: device_next: cdc_acm: allow setting the interface description").
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The usbd_class_remove_all removes all registered classes from a
configuration. However, it previously left the uds_ctx back-pointer to the
usdb_context set, meaning that if the class is re-registered with the
usbd_register_class function, this fails with the error message "Class
registered to other context at different speed" due to uds_ctx being set to
another context.
This patch corrects the issue by clearing udc_ctx after usbd_class_shutdown
has been called.
Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
Disable the high-speed USB device descriptor if it is not in use.
Add checks to the code where the high-speed descriptor may be used.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The required buffer is 128 bytes per instance on a full-speed device.
Use common (UDC) buffer, as this results in a smaller footprint.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Disable high-speed descriptors when they are not in use saves 64 bytes
in flash/RAM. It is unlikely that it will scale well enough to be used
in all class implementations or to support a different speed.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add Kconfig option to use dedicated workqueue in CDC ACM but use the
system work queue in CDC ACM by default.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allowing message callback execution from the USBD thread saves about 800
bytes. For small devices, the option can be useful to reduce flash/RAM
usage, those with enough resources should not bother about it.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This non-standard feature never had any proper host side implementation
(e.g. it was never upstreamed to BlueZ), and since it comes with notable
maintenance overhead it's fair to just remove it.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
This function is used for testing purposes only, there is no real use
for it in a user application. Remove in favor of implementation in new
device stack.
Also remove the part of the documentation that depends on loopback.
Documentation on how to implement your own USB device function using the
new USB device support will follow during the documentation rework.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
In my opinion, the user is supposed to configure the speed of the stack
and drivers ough to honor that choice. However current Zephyr USB
maintainer imposes that the dependency is the other way round, i.e.
that user first needs to disable High-Speed chirp at driver level and
only then can select Full-Speed only operation. Adhere to the
arbitrarily set up rule to allow this really necessary functionality to
enter Zephyr.
I consider this change to be harmful because it opens up a Kconfig trap
that allows configuring High-Speed capable stack with a device driver
limited to Full-Speed only operation.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Allow compiler optimizations to remove High-Speed handling code. Knowing
that maximum operating speed is Full-Speed allows to reduce bulk buffers
from 512 to 64 bytes. More RAM optimizations are possible but this
commit only gets the low hanging fruits.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Two main ideas behind setting maximum speed are:
* Allow code and RAM optimizations at compile time
* Allow High-Speed capable drivers to limit operating speed to user
choice.
This commit only introduces the necessary Kconfig options but does not
implement any code or RAM optimizations and does not modify any driver.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
The interface descriptor and its associated string descriptor are shared
between different speed configurations. Do not try to add a string
descriptor if it has already been added and the index is not zero.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
For many devices iSerialNumber is not required. The only device class
currently supported in Zephyr that requires iSerialNumber is MSC. If the
serial number is not available then iSerialNumber must be 0. Failure to
read the string descriptor for non-zero iSerialNumber fails USB Command
Verifier Chapter 9 tests.
When USBD_DESC_SERIAL_NUMBER_DEFINE() was used without CONFIG_HWINFO
then it did lead to runtime failure when requesting the string (thus
failing certification).
Fail USBD_DESC_SERIAL_NUMBER_DEFINE() at build-time if CONFIG_HWINFO is
not set to prevent the surprise at runtime. Only define serial number
descriptors if CONFIG_HWINFO is enabled.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Disable/enable endpoints even if the new alternate is the same as the
current one, forcing the endpoint to reset to defaults.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Do not report canceled transfers as an error and continue the transfers
regardless of the previous transfer status.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Implement Set/Clear Feature endpoint halt request and
fix the corresponding commands in the shell.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The device command is broken due to the overhaul of how USB devices are
handled in the host stack. Add a device address argument to all device
commands and obtain a pointer to the USB device during command
execution.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
We need to track the self-powered status of the device independently of
the D6 bit in the bmAttributes value of the configuration descriptor
because the Get Status request about the self-powered status is valid in
address state and we support multiple configurations.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Reset semaphore if USB transfer failed or was canceled and prevent
cdc_acm_send_notification() from blocking forever.
Signed-off-by: Martin Gysel <me@bearsh.org>
There are some boards and samples in the tree that use the CDC ACM UART
as the default serial backend, just like a real UART controller would.
The new device stack requires more detailed configuration than the old
one. In order to use the CDC ACM UART as the serial backend with the new
device stack in the same way as with the legacy stack, we need to
provide a solution to initialise and enable the CDC ACM UART at boot
time. We cannot use snippets as they do not support Kconfig files or
source code. Shields would be an option, but they cannot be used for
virtual devices such as the CDC ACM UART. The remaining solution is to
put the code and Kconfig file for it in the subsys directory.
Allow CDC ACM UART instance and USB device stack to be initialized and
enabled at boot time and to use it as serial backend for logging or
shell.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Fix "warning: 'cdc_acm_send_notification' defined but not used"
when Kconfig option UART_USE_RUNTIME_CONFIGURE is not used and
properly handle enqueue error.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The server uses host support to export a USB device to a remote
USBIP client. It supports control and bulk transfers, interrupt
transfers may also work, but this depends on the host controller used.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allow dynamic allocation of USB devices on connected event.
Add very basic USB device validation and configuration.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Handle them in separate contexts so that the request completion callback
cannot be blocked, such as when a device connection is detected and
requires configuration.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The transfers require enpoint MPS for proper transaction handling,
assign it in the common place during transfer allsocation so that it can
be reused.
Some users, such as USBIP, may need to keep a reference to private data,
add a parameter for completion callback data.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add an opaque pointer to store upper layer private data and initialize
it with the USB host context during controller initialization. Use the
pointer in event processing to get the correct context.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Address parameter/argument is no longer needed because we have a pointer
to the USB device. The Attrib parameter has never been used and will be
replaced by the interval and start-frame parameters in the future.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>