Commit graph

68 commits

Author SHA1 Message Date
Alberto Escolar Piedras af047e1891 samples/subsys: Use hwmv2 native targets identifiers
For the 64 bit targets, change identifiers to the new hwmv2 ones.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-03-15 16:13:12 +01:00
Alberto Escolar Piedras 063ce9caf5 samples/subsys/usb/hid: Enable for native_sim
Allow this sample in native_sim, and set it as default
integration platform instead of native_posix.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-16 09:37:59 +01:00
Benjamin Cabé 4f1cd0e428 doc: Migrate subsys/ code samples to new Sphinx extension
This migrates the subsys code samples to the new Sphinx code-sample
extension, making it easier to find relevant samples when browsing
API reference.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2023-09-21 09:28:31 +02:00
Johann Fischer ee43610b96 samples: usb: hid: remove SYS_INIT
There is no need to use SYS_INIT as the HID specific initialisation
can be done in the main before the usb_enable() call.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-08-04 10:41:38 +02:00
Johann Fischer 430818ecaa sample/tests: remove CONFIG_USB_COMPOSITE_DEVICE usage
This is no longer necessary, as this option is selected as a dependency
for class implementations where it is required.
Also remove redundant test cases.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-07-26 14:37:15 +02:00
Gerard Marull-Paretas 93b63df762 samples, tests: convert string-based twister lists to YAML lists
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-10 09:52:37 +02:00
Alberto Escolar Piedras 01c9b1483f samples/usb: Fix filtering for POSIX arch
Some of these samples were filtering all POSIX arch
boards out by explictly listing them by name
(and for the nrf52_bsim by lack of usb_device).

Instead filter by the architecture.

There is no functional difference in tree with this change.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-05-04 16:48:01 -04:00
Keith Packard 0b90fd5adf samples, tests, boards: Switch main return type from void to int
As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-14 07:49:41 +09:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Jamie McCrae 11c7371f99 samples: Explicitly disable boot USB device support init at boot
Disables having USB enabled for boards that configure USB CDC for
console, shell or logging at bootup in applications that enable USB
to prevent a conflict arising whereby USB is registered from
multiple points and later calls fail.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-10 12:21:10 +01:00
Anas Nashif ba7d730e9b tests/samples: use integration_plaforms in more tests/samples
integration_platforms help us control what get built/executed in CI and
for each PR submitted. They do not filter out platforms, instead they
just minimize the amount of builds/testing for a particular
tests/sample.
Tests still run on all supported platforms when not in integration mode.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-29 16:03:23 +01:00
Johann Fischer 1c4011ff6e usb: remove usb_pid.Kconfig file
Remove Kconfig file samples/subsys/usb/usb_pid.Kconfig added in
the commit e5cbe6a9e7 ("usb: cdc: Add unique PIDs for each sample")
with the motivation to have a separate ID for each sample supposedly
to be recognizable by the host.

The new USB support does not use the options, VID/PID is set
directly in the application. As a note, it is not necessary to have
unique PID for each sample, especially for the well known USB classes.

Replace the individual Kconfig options in the documentation
by a table with the references to the samples and PIDs.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-11-22 11:09:21 +01:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Gerard Marull-Paretas c7b5b3c419 samples: migrate includes to contain <zephyr/...> prefix
In order to bring consistency in-tree, migrate all samples to the use
the new prefix <zephyr/...>. Note that the conversion has been scripted:

```python
from pathlib import Path
import re

EXTENSIONS = ("c", "h", "cpp", "rst")

for p in Path(".").glob("samples/**/*"):
    if not p.is_file() or p.suffix and p.suffix[1:] not in EXTENSIONS:
        continue

    content = ""
    with open(p) as f:
        for line in f:
            m = re.match(r"^(.*)#include <(.*)>(.*)$", line)
            if (m and
                not m.group(2).startswith("zephyr/") and
                (Path(".") / "include" / "zephyr" / m.group(2)).exists()):
                content += (
                    m.group(1) +
                    "#include <zephyr/" + m.group(2) +">" +
                    m.group(3) + "\n"
                )
            else:
                content += line

    with open(p, "w") as f:
        f.write(content)
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 11:29:59 +02:00
Torsten Rasmussen 1cccc8a8fe cmake: increase minimal required version to 3.20.0
Move to CMake 3.20.0.

At the Toolchain WG it was decided to move to CMake 3.20.0.

The main reason for increasing CMake version is better toolchain
support.

Better toolchain support is added in the following CMake versions:
- armclang, CMake 3.15
- Intel oneAPI, CMake 3.20
- IAR, CMake 3.15 and 3.20

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-08-20 09:47:34 +02:00
Johann Fischer 946964e374 samples: remove USB configuration option
Remove USB configuration option, replace it where necessary
with USB_DEVICE_STACK.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:00:12 -04:00
Johann Fischer 90d7322d8c sample: hid: fixup harness config regex
Fixup outdated harness config regex.

Fixes: #33542

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-22 10:40:25 -04:00
Johann Fischer 5ebb4214c9 samples: hid: set boot interface Protocol Code
Update sampele to show how to set boot interface Protocol Code.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-19 09:51:21 -04:00
Johann Fischer 6a2a26024a samples: hid: filter subsequent USB_DC_CONFIGURED events
Filter subsequent USB_DC_CONFIGURED events.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-17 11:34:42 +01:00
Johann Fischer 352f63d98b samples: hid: adjust LOG level
Adjust LOG level to hide repeating debugging outputs.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-17 11:34:42 +01:00
Johann Fischer 84e55414ad samples: hid: rework USB HID sample report descriptor
HID report descriptor in the sample has unnecessarily output report
which is not used anywhere. This patch removes unnecessary report.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-17 11:34:42 +01:00
Johann Fischer 0bf67d2c6e samples: hid: rework USB HID sample report and on_idle callback
HID sample has on_idle callback implementation present in the code,
but has not turned on USB_DEVICE_SOF and so does not have
corresponding code in sample self and class/hid/core.c covered.
Also on_idle implementation in HID sample has not taken into
account send_report() which also calls hid_int_ep_write().
This patch enables USB_DEVICE_SOF and revises both on_idle and
the regular report function.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-17 11:34:42 +01:00
Johann Fischer 65678bb1d4 samples: hid: convert to use new common HID macros
Convert to use new common HID macros.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-02-28 16:50:24 -05:00
Johann Fischer 5b8d79fe9a sample: usb: exlude native_posix platform
Exlude native_posix platform from USB samples but
add build-only test case.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-02-03 08:37:38 -05:00
Emil Obalski 0d8bd579a5 usb: hid: All hid_ops callbacks get device pointer.
This commit extends USB hid API callbacks by adding
'const struct device *dev' parameter. If the application
configured more than one HID device then it must specify
separate hid_ops for each device as its unable to determine
for which device the callback was called.

This patch makes it possible to have only one hid_ops within
the application and the application is aware for which device
the callback was called because of explicit device pointer.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-09-04 12:27:44 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Marc Herbert 2cd51a33ce samples: make find_package(Zephyr...) REQUIRED
This provides a better error message when building with CMake and
forgetting ZEPHYR_BASE or not registering Zephyr in the CMake package
registry. See parent commit for more details (split from parent for
better readability).

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-05-29 10:47:25 +02:00
Johann Fischer 8f4df1784a samples: usb: update PID in the samples documentation
Update PID and SerialNumber in the samples documentation.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-05-27 14:15:52 +02:00
Torsten Rasmussen 407b49b35c cmake: use find_package to locate Zephyr
Using find_package to locate Zephyr.

Old behavior was to use $ENV{ZEPHYR_BASE} for inclusion of boiler plate
code.

Whenever an automatic run of CMake happend by the build system / IDE
then it was required that ZEPHYR_BASE was defined.
Using ZEPHYR_BASE only to locate the Zephyr package allows CMake to
cache the base variable and thus allowing subsequent invocation even
if ZEPHYR_BASE is not set in the environment.

It also removes the risk of strange build results if a user switchs
between different Zephyr based project folders and forgetting to reset
ZEPHYR_BASE before running ninja / make.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Emil Obalski 2128750138 usb: api: Add user device status callback
By this commit user gets possibility to register USB
device satutus callback. This callback represents device state
and is added so user could know what happend to USB device.

Callback is registered by providing it to usb_enable()
USB api is extended by this callback handler.

Samples using using USB are by default provide no callback
and the usb_enable() is called with NULL parameter.

Status callback registered by hid class is deleted as now
USB device has global callback for all classes within device.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-19 13:08:55 +01:00
Emil Obalski d65027d8c0 usb: samples: Application calling usb_enable by itself
User app is reponsible for issuing usb_enable and
making USB hardware operative.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-19 13:08:55 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Anas Nashif 578ae40761 boards: remove quarl_se_c1000
This board and SoC was discontinued some time ago and is currently not
maintained in the zephyr tree.
Remove all associated configurations and variants from the tree.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-29 21:30:25 -07:00
Andrei Emeltchenko 3f13079a7c samples: usb: hid: Fix harness configuration
Fix configuration indicating changes in USB device.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Andrei Emeltchenko 3880a42375 usb: Align legacy and composite interface
Remove duplicated execution path for composite configuration, USB
device stack initialization is done inside stack for both cases.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Marcin Szymczyk e5cbe6a9e7 usb: cdc: Add unique PIDs for each sample
Unique PID is required for each sample in order
to be recognized by host.

When creating a new sample:
- Add USB_PID_<SAMPLE_NAME>_SAMPLE
  in samples/subsys/usb/usb_pid.Kconfig
- Create Kconfig file in your sample's subdirectory, containing:
  config USB_DEVICE_PID
	default USB_PID_<SAMPLE_NAME>_SAMPLE

  source "Kconfig.zephyr"

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-05-09 08:20:34 -04:00
Andrei Emeltchenko 1b3227fd99 samples: usb: Correct USB HID device name
Use "HID_0" as a device name since we have only device count now.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrei Emeltchenko 35a81562e8 samples: usb: hid: Enable harness for the sample
Enable harness so we can execute smoke tests on the hardware with
command line:
sanitycheck --device-testing --device-serial /dev/ttyACM0 -p <BOARD>
  -T samples/subsys/usb/hid

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Anas Nashif da5f185e06 samples: add test identifier
Add unique identifier instead of just 'test' for samples.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-29 17:44:11 -04:00
David B. Kinder 505cc2bb0e doc: use :zephyr_file: where appropriate
A new role :zephyr_file: is available that renders to a link to the file
or folder in GitHub.  Find appropriate references using :file: and
convert to :zephyr_file: to take advantage of its linking capability.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-03-09 09:50:27 -05:00
Andrei Emeltchenko 6cf619f549 samples: hid: Use HID Device interface for samples
Use new HID Device interface for HID sample

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-08 11:23:04 -05:00
Anas Nashif 5060ca6a30 cmake: increase minimal required version to 3.13.1
Move to latest cmake version with many bug fixes and enhancements.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-01-03 11:51:29 -05:00
Marcin Szymczyk 801b54edb9 usb: hid: boot protocol
Set_Protocol and Get_Protocol requests are handled now.
Tested with USB3CV.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-19 07:36:18 -06:00
Marcin Szymczyk d5b79ff42c usb: hid: implement idle rate
Idle rate functionality has been implemented for HID USB class.
Bassed on Device Class Definition for Human Interface Devices 1.11.
Tested with USB3CV and host with idle rate.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-04 15:58:19 -05:00
Marcin Szymczyk 6a4ddffaf9 usb: hid: default request handlers
HID class now defaults to universal request callbacks in case they
are not provided by the application. This applies to following,
class-specific requests: Get_Report, Set_Report, Get_Idle, Set_Idle,
Get_Protocol and Set_Protocol.
Tested with USB3CV.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-04 15:58:19 -05:00
Marcin Szymczyk e4c447aac3 usb: add SoF event
Start of Frame events can now be accessed from USB classes.
This will be useful when implementing idle rate functionality.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-11-23 09:18:41 -05:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Andrei Emeltchenko 92c7ab74c0 usb: logs: Rename USB_DBG to LOG_DBG
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00