samples: usb: remove hid sample
Clean up before deprecating legacy device support. This sample does not contain anything special that is not present in the hid-mouse or hid-keyboard samples. It also makes no sense to port it to a new stack. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
cd9dff7d8c
commit
4dd1681fab
6 changed files with 2 additions and 278 deletions
|
@ -311,7 +311,7 @@ The disadvantage of this is that Kconfig options such as
|
|||
:kconfig:option:`CONFIG_HID_INTERRUPT_EP_MPS` apply to all instances. This design
|
||||
issue will be fixed in the HID class implementation for the new USB support.
|
||||
|
||||
See :zephyr:code-sample:`usb-hid` or :zephyr:code-sample:`usb-hid-mouse` sample for reference.
|
||||
See :zephyr:code-sample:`usb-hid-mouse` sample for reference.
|
||||
|
||||
Mass Storage Class
|
||||
==================
|
||||
|
@ -585,7 +585,7 @@ The following Product IDs are currently used:
|
|||
+----------------------------------------------------+--------+
|
||||
| :zephyr:code-sample:`usb-dfu` (Run-Time) | 0x0005 |
|
||||
+----------------------------------------------------+--------+
|
||||
| :zephyr:code-sample:`usb-hid` | 0x0006 |
|
||||
| Reserved (previously: usb-hid) | 0x0006 |
|
||||
+----------------------------------------------------+--------+
|
||||
| :zephyr:code-sample:`usb-hid-mouse` | 0x0007 |
|
||||
+----------------------------------------------------+--------+
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(hid)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -1,56 +0,0 @@
|
|||
.. zephyr:code-sample:: usb-hid
|
||||
:name: USB HID (Human Interface Device)
|
||||
:relevant-api: _usb_device_core_api usb_hid_device_api
|
||||
|
||||
Use USB HID driver to enumerate as a raw HID device.
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
This sample app demonstrates use of a USB Human Interface Device (HID) driver
|
||||
by the Zephyr project. This very simple driver is enumerated as a raw HID
|
||||
device. This sample can be found under :zephyr_file:`samples/subsys/usb/hid` in the
|
||||
Zephyr project tree.
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
This project requires a USB device driver.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample can be built for multiple boards, in this example we will build it
|
||||
for the reel_board board:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/subsys/usb/hid
|
||||
:board: reel_board
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
After you have built and flashed the sample app image to your board, plug the
|
||||
board into a host device, for example, a PC running Linux.
|
||||
The board will be detected as shown by the Linux journalctl command:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ journalctl -k -n 10
|
||||
usb 7-1: New USB device found, idVendor=2fe3, idProduct=0006, bcdDevice= 2.03
|
||||
usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
|
||||
usb 7-1: Product: Zephyr HID sample
|
||||
usb 7-1: Manufacturer: ZEPHYR
|
||||
usb 7-1: SerialNumber: 86FE679A598AC47A
|
||||
input: ZEPHYR Zephyr HID sample as /devices/platform/vhci_hcd.0/usb7/7-1/7-1:1.0/0003:2FE3:0100.0046/input/input81
|
||||
hid-generic 0003:2FE3:0100.0046: input,hidraw0: USB HID v1.10 Device [ZEPHYR Zephyr HID sample] on usb-vhci_hcd.0-1/input0
|
||||
|
||||
You can monitor report sending using standard Linux ``usbhid-dump`` command.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ sudo usbhid-dump -d 2fe3:0006 -es
|
||||
Starting dumping interrupt transfer stream
|
||||
with 1 minute timeout.
|
||||
|
||||
007:012:000:STREAM 1537362690.341208
|
||||
01 02
|
|
@ -1,13 +0,0 @@
|
|||
CONFIG_USB_DEVICE_STACK=y
|
||||
CONFIG_USB_DEVICE_HID=y
|
||||
CONFIG_USB_DEVICE_PRODUCT="Zephyr HID sample"
|
||||
CONFIG_USB_DEVICE_PID=0x0006
|
||||
CONFIG_USB_HID_BOOT_PROTOCOL=y
|
||||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
|
||||
|
||||
CONFIG_LOG=y
|
||||
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
|
||||
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
|
||||
|
||||
CONFIG_USB_DEVICE_SOF=y
|
||||
CONFIG_USB_HID_REPORTS=1
|
|
@ -1,24 +0,0 @@
|
|||
sample:
|
||||
name: USB HID sample
|
||||
tests:
|
||||
sample.usb.hid:
|
||||
depends_on: usb_device
|
||||
tags: usb
|
||||
arch_exclude: posix
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "main: HID Device: dev"
|
||||
- "main: Starting application"
|
||||
sample.usb.hid.buildonly:
|
||||
depends_on: usb_device
|
||||
tags: usb
|
||||
platform_allow:
|
||||
- native_posix
|
||||
- native_posix/native/64
|
||||
- native_sim
|
||||
- native_sim/native/64
|
||||
build_only: true
|
||||
integration_platforms:
|
||||
- native_sim
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016-2018 Intel Corporation.
|
||||
* Copyright (c) 2018-2021 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/init.h>
|
||||
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
#include <zephyr/usb/class/usb_hid.h>
|
||||
|
||||
#define LOG_LEVEL LOG_LEVEL_INF
|
||||
LOG_MODULE_REGISTER(main);
|
||||
|
||||
static bool configured;
|
||||
static const struct device *hdev;
|
||||
static struct k_work report_send;
|
||||
static ATOMIC_DEFINE(hid_ep_in_busy, 1);
|
||||
|
||||
#define HID_EP_BUSY_FLAG 0
|
||||
#define REPORT_ID_1 0x01
|
||||
#define REPORT_PERIOD K_SECONDS(2)
|
||||
|
||||
static struct report {
|
||||
uint8_t id;
|
||||
uint8_t value;
|
||||
} __packed report_1 = {
|
||||
.id = REPORT_ID_1,
|
||||
.value = 0,
|
||||
};
|
||||
|
||||
static void report_event_handler(struct k_timer *dummy);
|
||||
static K_TIMER_DEFINE(event_timer, report_event_handler, NULL);
|
||||
|
||||
/*
|
||||
* Simple HID Report Descriptor
|
||||
* Report ID is present for completeness, although it can be omitted.
|
||||
* Output of "usbhid-dump -d 2fe3:0006 -e descriptor":
|
||||
* 05 01 09 00 A1 01 15 00 26 FF 00 85 01 75 08 95
|
||||
* 01 09 00 81 02 C0
|
||||
*/
|
||||
static const uint8_t hid_report_desc[] = {
|
||||
HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP),
|
||||
HID_USAGE(HID_USAGE_GEN_DESKTOP_UNDEFINED),
|
||||
HID_COLLECTION(HID_COLLECTION_APPLICATION),
|
||||
HID_LOGICAL_MIN8(0x00),
|
||||
HID_LOGICAL_MAX16(0xFF, 0x00),
|
||||
HID_REPORT_ID(REPORT_ID_1),
|
||||
HID_REPORT_SIZE(8),
|
||||
HID_REPORT_COUNT(1),
|
||||
HID_USAGE(HID_USAGE_GEN_DESKTOP_UNDEFINED),
|
||||
HID_INPUT(0x02),
|
||||
HID_END_COLLECTION,
|
||||
};
|
||||
|
||||
static void send_report(struct k_work *work)
|
||||
{
|
||||
int ret, wrote;
|
||||
|
||||
if (!atomic_test_and_set_bit(hid_ep_in_busy, HID_EP_BUSY_FLAG)) {
|
||||
ret = hid_int_ep_write(hdev, (uint8_t *)&report_1,
|
||||
sizeof(report_1), &wrote);
|
||||
if (ret != 0) {
|
||||
/*
|
||||
* Do nothing and wait until host has reset the device
|
||||
* and hid_ep_in_busy is cleared.
|
||||
*/
|
||||
LOG_ERR("Failed to submit report");
|
||||
} else {
|
||||
LOG_DBG("Report submitted");
|
||||
}
|
||||
} else {
|
||||
LOG_DBG("HID IN endpoint busy");
|
||||
}
|
||||
}
|
||||
|
||||
static void int_in_ready_cb(const struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
if (!atomic_test_and_clear_bit(hid_ep_in_busy, HID_EP_BUSY_FLAG)) {
|
||||
LOG_WRN("IN endpoint callback without preceding buffer write");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* On Idle callback is available here as an example even if actual use is
|
||||
* very limited. In contrast to report_event_handler(),
|
||||
* report value is not incremented here.
|
||||
*/
|
||||
static void on_idle_cb(const struct device *dev, uint16_t report_id)
|
||||
{
|
||||
LOG_DBG("On idle callback");
|
||||
k_work_submit(&report_send);
|
||||
}
|
||||
|
||||
static void report_event_handler(struct k_timer *dummy)
|
||||
{
|
||||
/* Increment reported data */
|
||||
report_1.value++;
|
||||
k_work_submit(&report_send);
|
||||
}
|
||||
|
||||
static void protocol_cb(const struct device *dev, uint8_t protocol)
|
||||
{
|
||||
LOG_INF("New protocol: %s", protocol == HID_PROTOCOL_BOOT ?
|
||||
"boot" : "report");
|
||||
}
|
||||
|
||||
static const struct hid_ops ops = {
|
||||
.int_in_ready = int_in_ready_cb,
|
||||
.on_idle = on_idle_cb,
|
||||
.protocol_change = protocol_cb,
|
||||
};
|
||||
|
||||
static void status_cb(enum usb_dc_status_code status, const uint8_t *param)
|
||||
{
|
||||
switch (status) {
|
||||
case USB_DC_RESET:
|
||||
configured = false;
|
||||
break;
|
||||
case USB_DC_CONFIGURED:
|
||||
if (!configured) {
|
||||
int_in_ready_cb(hdev);
|
||||
configured = true;
|
||||
}
|
||||
break;
|
||||
case USB_DC_SOF:
|
||||
break;
|
||||
default:
|
||||
LOG_DBG("status %u unhandled", status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
hdev = device_get_binding("HID_0");
|
||||
if (hdev == NULL) {
|
||||
LOG_ERR("Cannot get USB HID Device");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
LOG_INF("HID Device: dev %p", hdev);
|
||||
|
||||
usb_hid_register_device(hdev, hid_report_desc, sizeof(hid_report_desc),
|
||||
&ops);
|
||||
|
||||
atomic_set_bit(hid_ep_in_busy, HID_EP_BUSY_FLAG);
|
||||
k_timer_start(&event_timer, REPORT_PERIOD, REPORT_PERIOD);
|
||||
|
||||
if (usb_hid_set_proto_code(hdev, HID_BOOT_IFACE_CODE_NONE)) {
|
||||
LOG_WRN("Failed to set Protocol Code");
|
||||
}
|
||||
|
||||
ret = usb_hid_init(hdev);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOG_INF("Starting application");
|
||||
|
||||
ret = usb_enable(status_cb);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to enable USB");
|
||||
return ret;
|
||||
}
|
||||
|
||||
k_work_init(&report_send, send_report);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue