summaryrefslogtreecommitdiffstats
path: root/tools/usb_gadget
diff options
context:
space:
mode:
authorreillyg@chromium.org <reillyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-04 18:08:13 +0000
committerreillyg@chromium.org <reillyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-04 18:08:13 +0000
commitac0b5b8ae61e90fc6758cfd4a6f2c5e6f95d0068 (patch)
tree3a0480ee7d68b40363e87083bdb18d3743bf9ccc /tools/usb_gadget
parentee5460655f5445a1e5e98221d7c4557a609b7130 (diff)
downloadchromium_src-ac0b5b8ae61e90fc6758cfd4a6f2c5e6f95d0068.zip
chromium_src-ac0b5b8ae61e90fc6758cfd4a6f2c5e6f95d0068.tar.gz
chromium_src-ac0b5b8ae61e90fc6758cfd4a6f2c5e6f95d0068.tar.bz2
[usb_gadget p13] Replace LUFA with UsbTestGadget in HidConnection tests.
The culmination of all this USB gadget nonsense... the HidConnection tests can now use the USB gadget framework I have built to validate device I/O works. This replaces the code based on a specially programmed Arduino running the LUFA library. BUG=396682 Review URL: https://codereview.chromium.org/423473008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287364 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/usb_gadget')
-rw-r--r--tools/usb_gadget/__main__.py2
-rw-r--r--tools/usb_gadget/hid_echo_gadget.py105
-rw-r--r--tools/usb_gadget/usb_constants.py1
3 files changed, 108 insertions, 0 deletions
diff --git a/tools/usb_gadget/__main__.py b/tools/usb_gadget/__main__.py
index f45a51b..e82dd6d 100644
--- a/tools/usb_gadget/__main__.py
+++ b/tools/usb_gadget/__main__.py
@@ -9,6 +9,7 @@ import argparse
import netifaces
from tornado import ioloop
+import hid_echo_gadget
import keyboard_gadget
import linux_gadgetfs
import mouse_gadget
@@ -48,6 +49,7 @@ def main():
server.chip = linux_gadgetfs.LinuxGadgetfs(server.hardware)
server.SwitchGadget(server.default)
+ hid_echo_gadget.RegisterHandlers()
keyboard_gadget.RegisterHandlers()
mouse_gadget.RegisterHandlers()
diff --git a/tools/usb_gadget/hid_echo_gadget.py b/tools/usb_gadget/hid_echo_gadget.py
new file mode 100644
index 0000000..ac677bb
--- /dev/null
+++ b/tools/usb_gadget/hid_echo_gadget.py
@@ -0,0 +1,105 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""A HID-class echo device.
+
+This module provides a HID feature and HID device that can be used as an
+echo test for HID drivers. The device exposes vendor-specific input, output
+and feature usages that transmit 8 bytes of data. Data written sent as an
+output report is echoed as an input report. The value of the feature report
+can be written and read with control transfers.
+"""
+
+import struct
+
+import hid_constants
+import hid_descriptors
+import hid_gadget
+import usb_constants
+
+
+class EchoFeature(hid_gadget.HidFeature):
+
+ REPORT_DESC = hid_descriptors.ReportDescriptor(
+ hid_descriptors.UsagePage(0xFF00), # Vendor Defined
+ hid_descriptors.Usage(0),
+ hid_descriptors.Collection(
+ hid_constants.CollectionType.APPLICATION,
+ hid_descriptors.LogicalMinimum(0, force_length=1),
+ hid_descriptors.LogicalMaximum(255, force_length=2),
+ hid_descriptors.ReportSize(8),
+ hid_descriptors.ReportCount(8),
+ hid_descriptors.Usage(0),
+ hid_descriptors.Input(hid_descriptors.Data,
+ hid_descriptors.Variable,
+ hid_descriptors.Absolute),
+ hid_descriptors.Usage(0),
+ hid_descriptors.Output(hid_descriptors.Data,
+ hid_descriptors.Variable,
+ hid_descriptors.Absolute),
+ hid_descriptors.Usage(0),
+ hid_descriptors.Feature(hid_descriptors.Data,
+ hid_descriptors.Variable,
+ hid_descriptors.Absolute)
+ )
+ )
+
+ def __init__(self):
+ super(EchoFeature, self).__init__()
+ self._input_output_report = 0
+ self._feature_report = 0
+
+ def SetInputReport(self, data):
+ self._input_output_report, = struct.unpack('<Q', data)
+ self.SendReport(struct.pack('<Q', self._input_output_report))
+ return True
+
+ def SetOutputReport(self, data):
+ self._input_output_report, = struct.unpack('<Q', data)
+ self.SendReport(struct.pack('<Q', self._input_output_report))
+ return True
+
+ def SetFeatureReport(self, data):
+ self._feature_report, = struct.unpack('<Q', data)
+ return True
+
+ def GetInputReport(self):
+ return struct.pack('<Q', self._input_output_report)
+
+ def GetOutputReport(self):
+ return struct.pack('<Q', self._input_output_report)
+
+ def GetFeatureReport(self):
+ return struct.pack('<Q', self._feature_report)
+
+
+class EchoGadget(hid_gadget.HidGadget):
+
+ def __init__(self):
+ self._feature = EchoFeature()
+ super(EchoGadget, self).__init__(
+ report_desc=EchoFeature.REPORT_DESC,
+ features={0: self._feature},
+ packet_size=8,
+ interval_ms=1,
+ out_endpoint=True,
+ vendor_id=usb_constants.VendorID.GOOGLE,
+ product_id=usb_constants.ProductID.GOOGLE_HID_ECHO_GADGET,
+ device_version=0x0100)
+ self.AddStringDescriptor(1, 'Google Inc.')
+ self.AddStringDescriptor(2, 'HID Echo Gadget')
+
+
+def RegisterHandlers():
+ from tornado import web
+
+ class WebConfigureHandler(web.RequestHandler):
+
+ def post(self):
+ server.SwitchGadget(EchoGadget())
+
+ import server
+ server.app.add_handlers('.*$', [
+ (r'/hid_echo/configure', WebConfigureHandler),
+ ])
diff --git a/tools/usb_gadget/usb_constants.py b/tools/usb_gadget/usb_constants.py
index b0d1e38..333f03a 100644
--- a/tools/usb_gadget/usb_constants.py
+++ b/tools/usb_gadget/usb_constants.py
@@ -166,3 +166,4 @@ class ProductID(object):
GOOGLE_TEST_GADGET = 0x2000
GOOGLE_KEYBOARD_GADGET = 0x2001
GOOGLE_MOUSE_GADGET = 0x2002
+ GOOGLE_HID_ECHO_GADGET = 0x2003