Part 1
요약·해설
gpio-keys mapping, led0 요구 사항과 Linux input event 검증을 설명합니다.
Left · Right
X · Y axes
evtest
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
929CF6E585620C741CC125004D5F753DD75BF54237D596A9FEE6D0759C094313
.. zephyr:code-sample:: usb-hid-mouse
:name: USB HID mouse
:relevant-api: _usb_device_core_api usb_hid_device_api input_interface
Implement a basic HID mouse device.
Overview
********
This sample app demonstrates use of a USB Human Interface Device (HID) driver
by the Zephyr project. This very simple driver enumerates a board with a button
into a mouse that has a left mouse button and optionally (depending on
the number of buttons on the board) a right mouse button, X-axis movement,
and Y-axis movement.
If the USB peripheral driver supports remote wakeup feature, wakeup request
will be performed on every button click if the bus is in suspended state.
This sample can be found under :zephyr_file:`samples/subsys/usb/hid-mouse` in the
Zephyr project tree.
Requirements
************
This project requires an USB device driver and uses the :ref:`input` API.
There must be a :dtcompatible:`gpio-keys` group of buttons or keys defined at
the board level that can generate input events, otherwise the example will build
but not work as expected.
The key mapping in the sample is as follows:
- ``INPUT_KEY_0``: left button
- ``INPUT_KEY_1``: right button
- ``INPUT_KEY_2``: move the mouse along the x-axis
- ``INPUT_KEY_3``: move the mouse along the y-axis
An LED must also be configured via the ``led0`` devicetree alias. You may also
see this error if you try to build this sample for an unsupported board:
.. code-block:: none
Unsupported board: led0 devicetree alias is not defined
Building and Running
********************
This sample can be built for multiple boards, in this example we will build it
for the nucleo_f070rb board:
.. zephyr-app-commands::
:zephyr-app: samples/subsys/usb/hid-mouse
:board: nucleo_f070rb
: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 dmesg command:
.. code-block:: console
dmesg | tail -10
usb 2-2: new full-speed USB device number 2 using at91_ohci
usb 2-2: New USB device found, idVendor=2fe3, idProduct=0007, bcdDevice= 2.03
usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-2: Product: Zephyr HID mouse sample
usb 2-2: Manufacturer: ZEPHYR
usb 2-2: SerialNumber: 86FE679A598AC47A
input: ZEPHYR Zephyr HID mouse sample as /devices/soc0/ahb/600000.ohci/usb2/2-2/2-2:1.0/0003:2FE3:0100.0001/input/input0
hid-generic 0003:2FE3:0100.0001: input: USB HID v1.10 Mouse [ZEPHYR Zephyr HID mouse sample] on usb-at91-2/input0
You can also monitor mouse events by using the standard Linux ``evtest`` command
(see the `Ubuntu evtest man page`_ for more information about this tool):
.. _Ubuntu evtest man page:
http://manpages.ubuntu.com/manpages/trusty/man1/evtest.1.html
.. code-block:: console
sudo evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x2fe3 product 0x7 version 0x110
Input device name: "ZEPHYR Zephyr HID mouse sample"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 272 (BTN_LEFT)
Event code 273 (BTN_RIGHT)
Event code 274 (BTN_MIDDLE)
Event type 2 (EV_REL)
Event code 0 (REL_X)
Event code 1 (REL_Y)
Event code 8 (REL_WHEEL)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
When you press the button on your board, it will act as if the left
mouse button was pressed, and this information will be displayed
by ``evtest``:
.. code-block:: console
Event: time 1167609663.618515, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1167609663.618515, type 1 (EV_KEY), code 272 (BTN_LEFT), value 1
Event: time 1167609663.618515, -------------- SYN_REPORT ------------
Event: time 1167609663.730510, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1167609663.730510, type 1 (EV_KEY), code 272 (BTN_LEFT), value 0
Event: time 1167609663.730510, -------------- SYN_REPORT ------------
If your board has more than one button, they will act as right mouse button,
X-axis movement, and Y-axis movement.
Part 3
한국어 전문 번역
개요
Zephyr project의 USB Human Interface Device(HID) driver를 사용해 board button을 mouse input으로 노출하는 sample입니다.
Button이 있는 board는 기본적으로 left mouse button을 가진 mouse로 enumerate됩니다. Board의 button 수에 따라 right mouse button, X-axis movement, Y-axis movement 기능도 추가됩니다.
USB peripheral driver가 remote wakeup을 지원하고 bus가 suspended 상태라면 button을 누를 때마다 wakeup request를 보냅니다. Source는 samples/subsys/usb/hid-mouse에 있습니다.
요구 사항
USB device driver와 input API가 필요합니다. Board level Devicetree에 input event를 생성하는 gpio-keys compatible button 또는 key group이 없으면 build는 되지만 기대한 대로 동작하지 않습니다.
Sample의 key mapping은 다음과 같습니다.
INPUT_KEY_0: left buttonINPUT_KEY_1: right buttonINPUT_KEY_2: mouse X-axis 이동INPUT_KEY_3: mouse Y-axis 이동
led0 Devicetree alias로 LED도 구성해야 합니다. 지원하지 않는 board를 대상으로 하면 다음 error가 나타날 수 있습니다.
Unsupported board: led0 devicetree alias is not defined
빌드 및 실행
여러 board용으로 build할 수 있습니다. 다음 example은 nucleo_f070rb용 image를 build합니다.
west build -b nucleo_f070rb samples/subsys/usb/hid-mouse
Image를 build하고 board에 flash한 뒤 Linux PC 같은 host에 연결합니다. Linux dmesg에는 HID mouse와 input device가 다음과 같이 감지됩니다.
dmesg | tail -10
usb 2-2: new full-speed USB device number 2 using at91_ohci
usb 2-2: New USB device found, idVendor=2fe3, idProduct=0007, bcdDevice= 2.03
usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-2: Product: Zephyr HID mouse sample
usb 2-2: Manufacturer: ZEPHYR
usb 2-2: SerialNumber: 86FE679A598AC47A
input: ZEPHYR Zephyr HID mouse sample as /devices/soc0/ahb/600000.ohci/usb2/2-2/2-2:1.0/0003:2FE3:0100.0001/input/input0
hid-generic 0003:2FE3:0100.0001: input: USB HID v1.10 Mouse [ZEPHYR Zephyr HID mouse sample] on usb-at91-2/input0
표준 Linux evtest command로 mouse event를 감시할 수도 있습니다. 올바른 input event device를 지정하면 지원하는 EV_KEY·EV_REL·EV_MSC event 목록이 표시됩니다.
sudo evtest /dev/input/event0
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x2fe3 product 0x7 version 0x110
Input device name: "ZEPHYR Zephyr HID mouse sample"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 272 (BTN_LEFT)
Event code 273 (BTN_RIGHT)
Event code 274 (BTN_MIDDLE)
Event type 2 (EV_REL)
Event code 0 (REL_X)
Event code 1 (REL_Y)
Event code 8 (REL_WHEEL)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
Board button을 누르면 left mouse button을 누른 것처럼 동작하며 evtest에는 press value 1과 release value 0이 각각 SYN_REPORT와 함께 나타납니다.
Event: time 1167609663.618515, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1167609663.618515, type 1 (EV_KEY), code 272 (BTN_LEFT), value 1
Event: time 1167609663.618515, -------------- SYN_REPORT ------------
Event: time 1167609663.730510, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1167609663.730510, type 1 (EV_KEY), code 272 (BTN_LEFT), value 0
Event: time 1167609663.730510, -------------- SYN_REPORT ------------
Button이 둘 이상인 board에서는 나머지 button이 right mouse button과 X-axis·Y-axis movement로 동작합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.