Skip to content

Commit 089482e

Browse files
jfischer-nocfriedt
authored andcommitted
samples: usb: make WebUSB next sample default
Move legacy WebUSB sample to legacy directory and make WebUSB next sample default. Signed-off-by: Johann Fischer <[email protected]>
1 parent a53b49f commit 089482e

File tree

25 files changed

+710
-707
lines changed

25 files changed

+710
-707
lines changed

doc/connectivity/usb/device/usb_device.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ The application should register descriptors such as Capability Descriptor
389389
using :c:func:`usb_bos_register_cap`. Registered descriptors are added to the root
390390
BOS descriptor and handled by the stack.
391391

392-
See :zephyr:code-sample:`webusb` sample for reference.
392+
See :zephyr:code-sample:`legacy-webusb` sample for reference.
393393

394394
Interface number and endpoint address assignment
395395
************************************************

doc/releases/release-notes-4.1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ New Samples
958958
* :zephyr:code-sample:`uart`
959959
* :zephyr:code-sample:`usb-midi2-device`
960960
* :zephyr:code-sample:`usbd-cdc-acm-console`
961-
* :zephyr:code-sample:`webusb-next`
961+
* :zephyr:code-sample:`webusb`
962962

963963
Other notable changes
964964
*********************

samples/subsys/usb/webusb-next/CMakeLists.txt renamed to samples/subsys/usb/legacy/webusb/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
55
project(webusb)
66

7-
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
7+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/usb)
8+
89
FILE(GLOB app_sources src/*.c)
910
target_sources(app PRIVATE ${app_sources})
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.. zephyr:code-sample:: legacy-webusb
2+
:name: Legacy WebUSB
3+
:relevant-api: _usb_device_core_api
4+
5+
Receive and echo data from a web page using WebUSB API.
6+
7+
For a deeper dive into the WebUSB, refer to
8+
https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web
9+
10+
WebUSB API Specification:
11+
https://wicg.github.io/webusb/
12+
13+
Overview
14+
********
15+
16+
This simple echo application demonstrates the WebUSB sample application.
17+
This application receives the data and echoes back to the WebUSB
18+
based web application (web page) running in the browser at host.
19+
This application is intended for testing purposes only. For running
20+
real usecase, implement applications based on the WebUSB API.
21+
This sample can be found under :zephyr_file:`samples/subsys/usb/legacy/webusb` in the
22+
Zephyr project tree.
23+
24+
.. note::
25+
This samples demonstrate deprecated :ref:`usb_device_stack`.
26+
27+
Requirements
28+
************
29+
30+
This project requires an USB device driver, which is available for multiple
31+
boards supported in Zephyr.
32+
33+
Building and Running
34+
********************
35+
36+
Build and flash webusb sample with:
37+
38+
.. zephyr-app-commands::
39+
:zephyr-app: samples/subsys/usb/legacy/webusb
40+
:board: <board to use>
41+
:goals: flash
42+
:compact:
43+
44+
Testing with the latest Google Chrome on host
45+
*********************************************
46+
47+
This sample application requires the latest Google Chrome, a web page
48+
based on WebUSB API to connect to the USB device and optionally
49+
http server running on localhost to serve the web page.
50+
51+
WebUSB is a powerful new feature added to the Web and it is available
52+
only to secure origins. This means the web page/site that is used to
53+
connect to the device must be served over a secure connection (HTTPS).
54+
55+
Follow these steps to run the demo on your host system:
56+
57+
#. Run the latest Google Chrome on host.
58+
59+
#. Implement a web app (web page) using WebUSB API and run
60+
it on localhost.
61+
62+
The sample can be found in the webusb sample directory:
63+
:zephyr_file:`samples/subsys/usb/legacy/webusb/index.html`.
64+
65+
This sample web page demonstrates how to create and use a WebUSB
66+
interface, as well as demonstrate the communication between browser
67+
and WebUSB enabled device.
68+
69+
There are two ways to access this sample page:
70+
71+
* Using Chrome browser go to :doc:`demo`
72+
73+
* Host the demo page locally: Start a web server
74+
in the webusb sample directory.
75+
76+
.. code-block:: console
77+
78+
$ python -m http.server
79+
80+
Using Chrome browser open url http://localhost:8001/
81+
82+
#. Connect the board to your host.
83+
84+
#. Once the device is booted, you should see a notification from
85+
Chrome: "Go to localhost to connect.". Click on the notification
86+
to open demo page.
87+
Note that at the moment WebUSB landing page notification is disabled
88+
in Chrome on Windows. See https://github.com/WICG/webusb#implementation-status
89+
90+
#. Click on the :guilabel:`Connect` button to connect to the device.
91+
92+
#. Send some text to the device by clicking on the :guilabel:`Send` button.
93+
The demo app will receive the same text from the device and display it in
94+
the text area.
File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_USB_DEVICE_STACK=y
3+
CONFIG_USB_DEVICE_BOS=y
4+
CONFIG_SERIAL=y
5+
CONFIG_USB_DEVICE_PRODUCT="Zephyr WebUSB sample"
6+
CONFIG_USB_DEVICE_PID=0x000A
7+
CONFIG_UART_INTERRUPT_DRIVEN=y
8+
CONFIG_UART_LINE_CTRL=y
9+
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
10+
11+
CONFIG_LOG=y
12+
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
13+
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sample:
2+
name: Web USB
3+
tests:
4+
sample.usb.legacy.webusb:
5+
depends_on: usb_device
6+
build_only: true
7+
tags: usb

0 commit comments

Comments
 (0)