Add usi-test tool

Add usi-test tool to inspect Universal Stylus Intiative (USI) device
communication via HID reports.

The tool currently supports:
* printing the report descriptor in human-readable formant
* printing incoming events in human-readable format
* setting and getting parameters for a paired stylus, and
* sending diagnostic commands a paired stylus.

BUG=b:165820387
TEST=build image including the tool, and test all commands

Change-Id: I7a92fd29cd677a5bed0bff51831a67f4f975df33
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/usi-test/+/2405391
Commit-Queue: Sean O'Brien <seobrien@chromium.org>
Tested-by: Sean O'Brien <seobrien@chromium.org>
Reviewed-by: Harry Cutts <hcutts@chromium.org>
4 files changed
tree: fe1c473b2a9fa0ac5caaee9ab1d472686620b7bc
  1. OWNERS
  2. README.md
  3. setup.py
  4. usi_test.py
README.md

USI Test Tool

Introduction

This repository contains a tool for testing a Universal Stylus Initiative (USI) digitizer and stylus at the HID protocol level.

Setting up

Make sure that your device has a dev or test image. You can use cros flash to flash a test image. Then you will need to enter the command prompt. Finally, you can run the tool with the usi-test command.

Commands

usi-test has five subcommands: descriptor, data, get, set, and diagnostic.

For any of these commands, you can set the path to the device with the -p or --path option. The default device path is /dev/hidraw0.

descriptor

This command simply prints out the report descriptor in human-readable format.

example:

$ usi-test --path /dev/hidraw0 descriptor

data

This command prints incoming events from the device in human-readable format. You can quit with Ctl-C.

example:

$ usi-test -p /dev/hidraw0 data

get

This command sends a HID feature request to the device and prints the response. All of these commands query a stylus paired with the device, which can be specified with the -i or --index option. This is the temporary index assigned to the stylus by the digitizer when it pairs. The default index is 1.

This command will wait for the specified stylus to pair with the digitizer, so you can send the command without having the stylus pressed to the digitizer.

The values you can query are:

  • color: The current color of the stylus stroke
  • width: The current width of the stylus stroke
  • style: The current style of the stylus stroke (ink, pencil, etc.)
  • buttons: The mapping from physical stylus buttons to the button types they are set to be emulating.
  • firmware: The vendor ID, product ID, and firmware version of the stylus.
  • usi_version: The USI protocol version this pen is using.

examples:

$ usi-test -p /dev/hidraw0 get color
$ usi-test get width --index 1
$ usi-test get buttons -i 2

set

This command sets the specified values for the stylus using a HID feature report. The stylus index is specified the same as with the get command.

This command will wait for the specified stylus to pair with the digitizer, so you can send the command without having the stylus pressed to the digitizer.

The values you can set are:

  • --color, -c: Values between 0 and 255. See the USI spec for color mapping.
  • --width, -w: Values between 0 and 255, in 0.1 mm increments. For example, A value of 25 gives a stroke width of 2.5 mm.
  • --style, -s: Choose from ink, pencil, highlighter, marker, brush, and none
  • --button, -b: This option requires two arguments. It will set the first button argument to emulate the second button argument. The first (physical) button may be (barrel, secondary, eraser), and the second (emulated) button may be (barrel, secondary, eraser, disabled)

You may set one or all of the values in the same command. The button option can be set once for each physical button.

examples:

$ usi-test set --color 50
$ usi-test set -c 50
$ usi-test set --style pencil --index 2
$ usi-test set -c 50 -w 20 -s pencil
  # set the barrel button to act as the secondary button:
$ usi-test set --button barrel secondary
$ usi-test set --button barrel secondary --button secondary eraser

diagnostic

This command sends a diagnostic command to the stylus and reads the response. If you want you can set the preamble and cyclic redundancy check (CRC) manually, but by default this tool will calculate and send the preamble and CRC defined by the USI spec. The stylus index can be set the same as with the get command.

This command expects the command ID as the first argument, and the data as the second argument.

It will print the full reponse from the stylus, and break the response into the error bit, error code, and command response.

examples:

  # send the echo command, with value 8
$ usi-test diagnostic 52 8
full response: 0x0000000000000008
error information available? 0
error code: 0x00
command response: 0x0008
$ usi-test diagnostic 52 7 --preamble 2 --crc 3