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>
This commit adds check in cc_open entry state and logs if setting
either of the values were unsuccessful.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
When the get_cc function returns error, the CC lines should be
considered as open. It may happen either due to some chip malfunction
or chip going into sleep mode and needing time to reinitialize.
TCPC should only go to sleep if there is no partner attaches, so
in case of this error, the lines should be considered as disconnected.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
If TCPC supports checking for pending messages, it should be done
instead of forcefully trying to read the message and getting no-data
result. This helps with powereficiency for chips that go to sleep
when there is no message pending. Trying to read the message can
wake up the chip providing higher power usage.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
The TCPC driver initialization can be unsuccessful and it should be
checked and logged if that's the case.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
TCPC API functions should be able to inform the caller if the function
is supported and successfully executed. Bool values doesn't allow this
so it is needed to change the type to int.
For is_rx_pending_msg function the return code should conform to
existing error codes, so in case of function being not supported,
the -ENOSYS should be returned. In case of successful execution,
if there is no pending message, the -ENODATA should be returned and
in case of message pending, the value of 0.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
Do not explicitly check buf parameter in usbh_req_setup()
but add ASSERT to check unresolved data stage conditions.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add command to get the current device configuration.
Revise the shell part to have a set|get configuration
subcommands.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
With the latest change, there is no need for this structure
to be used as a completion handler.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use the USB device structure and wrappers introduced earlier.
With this patch, users of ch9 requests do not need to work
directly with the UHC API. The requests are now blocked until
there is a response from the UHC. Callers finally have access
to the data buffer and request status.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add a structure to represent a USB device and wrappers to avoid
glue UHC calls when operating on devices. Although there is a long
road to device configuration and management, we can start with
the tools that can also be used for USB device support testing.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Remove ugly hack to call class driver ops.
This is preparation for later changes where we will change
parts to work on structure that represents USB device and
not on glue UHC functions.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The current approach is a bit impractical in the upper layer.
This patch removes the two fifos that hold the transfer buffers
and replaces them with a byte array for the setup packet and
a pointer to a data buffer. The data buffer is mandatory for
all types of transfers except control without a data stage.
The waste of eight unused bytes for non-control transfers should
be insignificant, since an additional pointer would be at least
half of it, and then there would be the overhead of handling it.
This patch also clean up the transfer flags, rename owner to callback
as it reflects the upper layer use case, and add an additional member
to hold the pointer to the USB device (peripheral on the bus).
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
There was a new Kconfig for USB-C init priority that is conflicting
with currently used Kconfig for init of VBUS and TCPC.
This commit changes the names to more specific related to the subsystem
they belong to.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
Usage of application level for device drivers needs to be avoided. Also
introduced a new init level, with default to 90 as other dependencies of
USB-C run at priority 80.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Fix few instances of delayable work handlers using the k_work pointer
directly in a CONTAINER_OF pointing to a k_work_delayable.
This is harmless since the k_work is the first element in
k_work_delayable, but using k_work_delayable_from_work is the right way
of handling it.
Change a couple of explicit CONTAINER_OF doing the same work as the
macro in the process.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
CONFIG_COVERAGE has been incorrectly used to
change other kconfig options (stack sizes, etc)
code defaults, as well as some samples behaviour,
which should not have dependend on it.
Instead those should have depended on COVERAGE_GCOV,
which, being the one which adds special code and
temporary RAM storage for embedded targets,
require changes to many features.
When building for the native targets, all this was
unnecessary.
=> Fix the dependency.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
With gcc from the zephyr sdk and -Wold-style-declaration is giving this
output:
zephyr/arch/arm/core/aarch32/cortex_a_r/fault.c:101:1: warning:
'inline' is not at beginning of declaration [-Wold-style-declaration]
101 | static void ALWAYS_INLINE
z_arm_fpu_caller_save(struct __fpu_sf *fpu)
| ^~~~~~
I searched to all of the source code to find these further occurances
where inline is not at the beginning of a function declaration.
Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>