zephyr/samples/subsys/usb/hid-cdc
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
..
src usb: api: Add user device status callback 2019-12-19 13:08:55 +01:00
CMakeLists.txt license: cleanup: add SPDX Apache-2.0 license identifier 2019-04-07 08:45:22 -04:00
Kconfig kconfig: Clean up header comments and make them consistent 2019-11-04 17:31:27 -05:00
prj.conf samples: hid-cdc: Update USB device names and project conf 2019-04-28 12:22:23 -04:00
README.rst global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
sample.yaml samples: fix identifiers for samples 2019-04-01 12:23:09 -04:00

.. _usb_hid-cdc:

USB HID CDC ACM Application
################################

Overview
********

This sample app demonstrates use of multiple USB classes with multiple
instances. It combines two HID instances and two CDC ACM instances.
This sample can be found under :zephyr_file:`samples/subsys/usb/hid-cdc` in the
Zephyr project tree.

Requirements
************

This project requires an USB device driver and multiple endpoints.

Building and Running
********************

This sample can be built for multiple boards, in this example we will build it
for the nrf52840_pca10056 board:

.. zephyr-app-commands::
	:zephyr-app: samples/subsys/usb/hid-cdc
	:board: nrf52840_pca10056
	: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.
Two CDC ACM interfaces (for example /dev/ttyACM1 and /dev/ttyACM2)
and two HID devices will be detected:

.. code-block:: console

	usb 2-2: new full-speed USB device number 3 using ohci-pci
	usb 2-2: New USB device found, idVendor=2fe3, idProduct=0100
	usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
	usb 2-2: Product: Zephyr HID and CDC ACM sample
	usb 2-2: Manufacturer: ZEPHYR
	usb 2-2: SerialNumber: 0.01
	cdc_acm 2-2:1.0: ttyACM1: USB ACM device
	input: ZEPHYR Zephyr HID and CDC ACM sample as /devices/pci0000:00/0000:00:06.0/usb2/2-2/2-2:1.2/0003:2FE3:0100.0002/input/input8
	hid-generic 0003:2FE3:0100.0002: input,hidraw1: USB HID v1.10 Mouse [ZEPHYR Zephyr HID and CDC ACM sample] on usb-0000:00:06.0-2/input2
	cdc_acm 2-2:1.3: ttyACM2: USB ACM device
	input: ZEPHYR Zephyr HID and CDC ACM sample as /devices/pci0000:00/0000:00:06.0/usb2/2-2/2-2:1.5/0003:2FE3:0100.0003/input/input9
	hid-generic 0003:2FE3:0100.0003: input,hidraw2: USB HID v1.10 Keyboard [ZEPHYR Zephyr HID and CDC ACM sample] on usb-0000:00:06.0-2/input5

You can now connect to both CDC ACM ports:

.. code-block:: console

	minicom -D /dev/ttyACM1 -b 115200

.. code-block:: console

	minicom -D /dev/ttyACM2 -b 115200

After both ports have been connected to, messages explaining usage of each port will be displayed:

.. code-block:: console

	Welcome to CDC ACM 0!
	Supported commands:
	up    - moves the mouse up
	down  - moves the mouse down
	right - moves the mouse to right
	left  - moves the mouse to left

.. code-block:: console

	Welcome to CDC ACM 1!
	Enter a string and terminate it with ENTER.
	It will be sent via HID when BUTTON 2 is pressed.
	You can modify it by sending a new one here.

CDC ACM 0 may be used to control the mouse by typing a command and pressing :kbd:`ENTER`.

CDC ACM 1 is used to control the keyboard - any string typed into it and finished with :kbd:`ENTER` will be saved
on the device and typed back to the host when BUTTON 2 is pressed.

Buttons have following functions:

- Button 0 moves HID mouse in random direction
- Button 1 is a left HID mouse button
- Button 2 types the string sent with CDC ACM 1 using HID keyboard
- Button 3 is a CAPS LOCK on HID keyboard