Rework USBD shell to take speed arguments into account and revise
command help text. Rename some of the commands to better reflect what
they actually do.
Since most of the init code changes, rewrite the command to initialize
the default configuration in the shell to register all available
classes, but not to enable USB device support in a single command.
This will allow earlier notification in the future, if supported by the
controller, before the USB device controller is enabled.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
For the last dozen commits, the role of usbd_class_node has actually
been taken over by usbd_class_iter. After cleaning up and merging
usbd_class_node and usbd_class_data, we can rename usbd_class_iter to
usbd_class_node to better reflect its role.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Since only usbd_class_node contains the class instance data, rename it
to usbd_class_data.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
With the latest change, there are two structures that actually contain
class instance related data. Merge them into usbd_class_dnode, because
there is already a handy macro that can be used in class instances.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Some places have been overlooked, finally get rid of it. Use helpers to
get instance priv and device context.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
USB High-Speed devices must be able to operate at both High-Speed and
Full-Speed. The USB specification allows the device to have different
configurations depending on connection speed. Modify the API to reflect
USB Specification requirements on what can (e.g. configurations) and
what cannot (e.g. VID, PID) be speed dependent.
While the class configurations for different speeds are completely
independent, the actual class instances are shared between operating
speeds (because only one speed can be active at a time). Classes are
free to provide different number of interfaces and/or endpoints for
different speeds. The endpoints are assigned for all operating speeds
during initialization.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Introduce usbd_class_iter for keeping endpoint assignment variables
and the single-linked list node. No functional changes right now, but
this paves the way for independent speed specific configurations.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
When device is not configured, any class or endpoint request must result
in request error. Do not try to find transfer owner because there cannot
be one.
Make sure that the actual handling code path does not depend on the
configured log level because it is absolutely not desired for log level
to affect actual handling.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Do not require nil descriptor at the end of descriptor set because it
serves no other purpose than a sentinel. Just end processing on first
NULL pointer within descriptor set.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add necessary macros and convert UAC2 descriptor test from descriptor
blob to descriptor set. Currently there is only Full-Speed descriptor
set.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
For specification-compliant high-speed support, we need to support
device quilifiers and other-speed-configuration descriptor requests. We
also need to store different configurations of the class/function
descriptors, which typically only affect the endpoint descriptors. With
this change, the stack expects class/function descriptors to be passed
as an array of struct usb_desc_header pointers to e.g. interface,
interface-specific, and endpoint descriptors, with the last element of
the array pointing to a nil descriptor. And also passed for a specific
speed, for now we support full and high speed configurations.
During instantiation, the class/function implementation must choose the
correct configuration in the full-speed and high-speed descriptor sets
for values such as maximum packet size and bInterval values of interrupt
and isochronous endpoints.
During initialization, the stack reads the highest speed supported by
the controller and uses it to get the appropriate descriptors set
from the instance. If the controller supports only full speed, the stack
configures the class/function descriptor for full speed only, if the
controller supports high speed, the stack configures the descriptors for
high speed only, and a class/function must update the full speed
descriptor during the init callback processing.
During device operation, the class/function implementation must check
the actual speed of the device and use the correct configuration, such
as the endpoint address or maximum packet size.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Save actual device speed in the device context and add helpers to get
highest supported and actual speed.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The class implementations should not access the members of the struct
usbd_class_node directly.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This implementation is WIP and has mostly been used to test interface
and endpoint configuration by the stack. For future changes, make the
interfaces more compliant with the USB specification.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Updates the linker script fragments under 'subsys' to use
Z_LINK_ITERABLE_SUBALIGN for the subalignment instead of
a hardcoded value of 4.
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Add message types for line coding and contol line state updates.
Add a publish message function that takes a pointer to a device
structure as payload, and use USB notification in the CDC ACM
implementation.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The implementation uses the system workqueue and a callback provided
and registered by the application. The application callback is called in
the context of the workqueue. Notification messages are stored in a
queue and delivered to the callback in sequence.
We cannot call application callback directly from the USB device stack
thread because the behavior of arbitrary code provided by the
application is unpredictable, and we do not want it to be executed in
the same context where all events from the device controller are
handled.
Nor can we use the ZBUS subsystem directly. ZBUS offloads responsibility
for defined behavior to the observers and application, and does not
provide any way for the publisher to enforce defined behavior and
execution context.
ZBUS listener would be called from the USB thread context and is not
acceptable. ZBUS subscriber does not provide delivery guarantee and
cached message can be overwritten. ZBUS message subscriber has
cumbersome global configuration and buffers that are too complicated to
handle from USB configuration, and even if we would use it, defined
behavior is not possible because of how listener and subscriber are
handled.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Multiple CDC ACM instances can block each other because there are only
buffers for a single instance. Fix this by configuring the number of
buffers in the pool based on the number of CDC ACM instances.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Introduce new USB Audio 2 implementation written from scratch. Main goal
behind new implementation was to perform entity configuration with
devicetree bindings, hiding the descriptor complexity from application.
Initial implementation is working at Full-Speed only. High-Speed support
will come later, but even at Full-Speed only this is viable replacement
for old stack USB Audio 1 class (USB Audio 1 is limited to Full-Speed by
specification, i.e. it is explicitly forbidden for USB Audio 1 device to
work at High-Speed).
Implemented is only absolute minimum set of features required for basic
implicit and explicit feedback samples. Only one sample frequency is
currently supported. Optional interrupt notifications are not supported.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Start of Frame is not relevant for most classes, but it is crucial for
isochronous operation. The most prominent example where SOF is necessary
is USB Audio class.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
usbh_req_desc() truncates the descriptor id. This problem is most
visible with string descriptor requests, as only then can wIndex be
greater than 0xFF. In particular, this affects commonly used language
IDs such as English (United States), which is 0x0409.
Signed-off-by: Alexander Kaiser <akaiser@urbansky.com>
It might happens that DT(_INST)_PROP_OR is used with boolean properties.
For instance:
.single_wire = DT_INST_PROP_OR(index, single_wire, false), \
.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false), \
This is not required as boolean properties are generated with false
value when not present, so the _OR macro extension is superflous
and the above code can be replaced by:
.single_wire = DT_INST_PROP(index, single_wire), \
.tx_rx_swap = DT_INST_PROP(index, tx_rx_swap), \
Signed-off-by: Roman Studenikin <srv@meta.com>
Fixes:
/__w/zephyr/zephyr/subsys/usb/usb_c/usbc_tc_src_states.c:260:21: error:
declaration of 'ret' shadows a previous local [-Werror=shadow]
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add calls to the PPC API that enables and disables the sink and source
paths in the appropriate USB-C stack states.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
audio_receive_cb is only used by headphones and headset, it is unused in
microphone-only configurations. Gate compilation based on the device
tree.
Signed-off-by: James Zipperer <jzipperer@fb.com>
Change function parameter name in function usbd_device_set_code_triple
from `class` to `base_class` as `class` is a keyword in C++.
Signed-off-by: Shane Snover <ssnover95@gmail.com>
Add macros to initialize full set of descriptors required for USB Audio
Class 2 instance. Descriptors start with Interface Association
Descriptor that binds together the AudioControl interface and all
AudioStreaming interfaces.
AudioStreaming interfaces have alternate setting 0 without any endpoints
and alternate setting 1 with isochronous endpoint with max packet size
calculated on maximum sample frequency, number of channels, subslot size
and clock synchronization (asynchronous endpoints require +1 sample).
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Initial set of macros to generate class specific descriptors based on
devicetree nodes. Descriptors are generated as uint8_t array initializer
list because there is variable number of entities in between standard
USB interface and endpoint descriptors. Because the descriptors are
automatically generated there is no real point in trying to generate
corresponding C structures (especially that some entity descriptors have
variably sized fields in the middle of descriptor, e.g. Clock Selector).
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Usually we want set all values of code triple Base Class, SubClass, and
Protocol at once. Merge existing functions to set code, subcode,
protocol into just one helper to set code triple.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add an interface to verify and enable a test mode. The test mode
selected in the SetFeature control request must be verified to be
supported by the controller and enabled after the status stage is
completed.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Not all device controllers expect the device address to be set after the
status stage. Add support to directly set a new device address without
waiting for the control request status stage.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.
The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.
This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Queue characters in TX ring buffer regardless of interface state. This
allows simple applications that print basic output to CDC ACM port to
not care about connection or DTR state. Note that depending on actual
application requirements it might be still wise to wait for DTR before
trying to send data.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Prevent ECHO on Linux by arming IN endpoint with ZLP when interface is
configured and making sure that actual payload is only sent after
initialization timeout. The ZLP is not visible to host side applications
because the applications are really accessing tty buffer and received
ZLP does not modify tty buffer in any way.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Rename local usbd copy from nrfx_usbd to nrf_usbd_common and use it in
both USB stacks. Renaming header to nrf_usbd_common.h allows breaking
changes in exposed interface. Mark all doxygen comments as internal
because local usbd copy should not be treated as public interface
because we are under refactoring process that aims to arrive at native
driver and therefore drop nrf_usbd_common in the future.
Use Zephyr constructs directly instead of nrfx glue macros.
No functional changes.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
ZLP packet has to be read and acknowledged by host just like any other
DATA packet. Do not end transfer until the host actually acknowledged
the trailing ZLP. This fixes the race condition between host and Zephyr
application where the next transfer could be lost if host did not issue
IN token (that would read read ZLP) before the application tried to
start new transfer.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
According to the UART API documentation, implementation must block when
the transceiver is full. For CDC ACM UART, TX ringbuffer can be
considered as transceiver buffer/FIFO. Blocking when the USB subsystem
is not ready is considered highly undesirable behavior. Blocking may
also be undesirable when CDC ACM UART is used as a logging backend.
Change the behavior of CDC ACM poll out to:
- Block if the TX ring buffer is full, hw_flow_control property is
enabled, and called from a non-ISR context.
- Do not block if the USB subsystem is not ready, poll out
implementation is called from an ISR context, or hw_flow_control
property is disabled.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
When a usb_transfer is cancelled, the callback is finally invoked.
Silly, there is no transfer status passed, and in the callback we can
only check the size and device status.
Reported-by: Alex Kaiser
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add sleep prevention in crucial USB-C stack functions to make
state transitions faster and to send responses faster.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
Add internal function that prevents one sleep of the USB-C stack.
It can allow to have longer sleep times to conserve more power, while
still having possibility to respond in the required time and
set specific registers.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit adds checks for results and in case of error, handles it.
The failed initialization of the TCPC can postpone initialization in
case the TCPC needs more time after powering up. Otherwise if other
error happened, the Type-C Layer will be disabled.
Errors in other places of the USB-C stack, like communication errors,
moves the state machine to the error recovery, restarting the
communication with parner.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
These two functions are used together so there is no need for
splitting them into two functions. This commit also makes this
function required to be implemented by the TCPC driver.
Signed-off-by: Michał Barnaś <mb@semihalf.com>