Skip to content

Commit c5dc1a1

Browse files
committed
add zephyr twister test for USB device level testing
Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
1 parent f7e0834 commit c5dc1a1

25 files changed

Lines changed: 542 additions & 27 deletions

.github/workflows/zephyr.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ jobs:
3838
with:
3939
manifest: west4nrfsdk.yml
4040

41+
- name: Run USB virtual-device tests
42+
working-directory: zephyr/tests
43+
shell: bash
44+
run: |
45+
west twister \
46+
-T usb/device_virtual \
47+
-p native_sim/native/64 \
48+
--inline-logs \
49+
-v
50+
4151
- name: Build ble-keyboard firmware
4252
working-directory: zephyr/examples/ble-keyboard
4353
shell: bash

c2usb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ CPMAddPackage("gh:Neargye/magic_enum@0.9.3")
3838
include(../cmake/get_cpm.cmake)
3939
if(ZEPHYR_HID_RP_MODULE_DIR OR MCUX_HID_RP_MODULE_DIR)
4040
else()
41-
CPMAddPackage("gh:IntergatedCircuits/hid-rp#1cf78a8905c13e3670fe4999523cb04ad01f18ee")
41+
CPMAddPackage("gh:IntergatedCircuits/hid-rp#770f31f71bf602f6d0a9c387dccd4b54dbe6d7c8")
4242
endif()
4343

4444
if(ZEPHYR_ETL_MODULE_DIR OR MCUX_ETL_MODULE_DIR)

c2usb/port/zephyr/Kconfig.shell

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
menuconfig SHELL_BACKEND_C2USB
33
bool "c2usb shell backend"
4+
depends on SHELL
45
help
56
Build c2usb shell backend.
67

c2usb/port/zephyr/udc_mac.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ namespace usb::zephyr
2626
class udc_mac : public df::mac
2727
{
2828
public:
29+
static constexpr usb::speeds supported_speeds()
30+
{
31+
#if !defined(CONFIG_UDC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED) || \
32+
!defined(CONFIG_UDC_DRIVER_HAS_HIGH_SPEED_SUPPORT)
33+
return usb::speeds(usb::speed::FULL);
34+
#else
35+
return usb::speeds(usb::speed::FULL, usb::speed::HIGH);
36+
#endif
37+
}
38+
2939
udc_mac(const ::device* dev, size_t ctrl_ep_buf_size);
3040
udc_mac(const ::device* dev, size_t ctrl_ep_buf_size, usb::power::state power_state);
3141
~udc_mac() override;

c2usb/port/zephyr/usb_shell.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include "port/zephyr/usb_shell.hpp"
1+
// SPDX-License-Identifier: MPL-2.0
2+
#include "usb_shell.hpp"
23
#include <cassert>
34

45
extern "C" const struct shell* c2usb_shell_handle();

c2usb/port/zephyr/usb_shell.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#ifndef __USB_SHELL_HPP
2-
#define __USB_SHELL_HPP
3-
1+
// SPDX-License-Identifier: MPL-2.0
2+
#pragma once
43
#include <atomic>
54
#include <optional>
65
#include <zephyr/shell/shell.h>
@@ -119,5 +118,3 @@ class usb_shell : public usb::df::cdc::acm::function
119118
};
120119

121120
} // namespace usb::zephyr
122-
123-
#endif // __USB_SHELL_HPP

c2usb/usb/base.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ struct descriptor : public descriptor_header
5858
constexpr descriptor(uint8_t length)
5959
: descriptor_header(length, type())
6060
{}
61+
62+
[[nodiscard]] constexpr bool type_valid() const { return (bDescriptorType == type()); }
6163
};
6264

6365
// TODO: https://github.com/mariusbancila/stduuid

c2usb/usb/control.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ struct request : public request_id
8686

8787
template <typename T>
8888
constexpr request(usb::direction dir, request_base::type t, request_base::recipient rec, T code,
89-
uint16_t value, uint16_t len = 0, uint16_t index = 0)
89+
uint16_t value, uint16_t index = 0, uint16_t len = 0)
9090
: request_id(dir, t, rec, code), wValue(value), wIndex(index), wLength(len)
9191
{}
9292

93+
constexpr request(request_id id, uint16_t value, uint16_t index = 0, uint16_t len = 0)
94+
: request_id(id), wValue(value), wIndex(index), wLength(len)
95+
{}
96+
9397
struct splittable_uint16_t : public le_uint16_t
9498
{
9599
[[nodiscard]] constexpr uint8_t high_byte() const { return this->storage[1]; }

c2usb/usb/df/class/cdc_acm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void function::control_setup_request(message& msg, const config::interface& ifac
4949
{
5050
if (!iface.primary())
5151
{
52-
msg.reject();
52+
return msg.reject();
5353
}
5454

5555
using namespace usb::cdc::control;

c2usb/usb/df/ep_flags.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
/// @file
2-
///
3-
/// @author Benedek Kupper
4-
/// @date 2023
5-
///
6-
/// @copyright
7-
/// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
8-
/// If a copy of the MPL was not distributed with this file, You can obtain one at
9-
/// https://mozilla.org/MPL/2.0/.
10-
///
11-
#ifndef __USB_DF_EP_FLAGS_HPP_
12-
#define __USB_DF_EP_FLAGS_HPP_
13-
1+
// SPDX-License-Identifier: MPL-2.0
2+
#pragma once
143
#include <array>
154
#include <atomic>
165

@@ -54,5 +43,3 @@ class ep_flags
5443
};
5544

5645
} // namespace usb::df
57-
58-
#endif // __USB_DF_EP_FLAGS_HPP_

0 commit comments

Comments
 (0)