【问题标题】:Generic keyboard emulation using Arduino Leonardo使用 Arduino Leonardo 的通用键盘仿真
【发布时间】:2012-10-01 23:16:32
【问题描述】:

我正在尝试使用Arduino Leonardo 进行键盘模拟,因为这是它宣传的功能之一。我一直在玩 Leonardo,并根据 Blink 示例写了一个非常简单的草图。

// Pin 13 has an LED connected on most Arduino boards.
int led = 13;

// The setup routine runs once when you press reset:
void setup()
{
    // Initialize the digital pin as an output.
    pinMode(led, OUTPUT);
}

// The loop routine runs over and over again forever:
void loop()
{
    delay(5000);              // Wait for five seconds
    digitalWrite(led, HIGH);  // Turn the LED on (HIGH is the voltage level)
    delay(100);               // Wait for a secondA
    digitalWrite(led, LOW);   // Turn the LED off by making the voltage LOW
    Keyboard.write('A');      // Write an A using keyboard emulator
}

现在这个例子在我的 Windows XP 机器上运行良好。它被识别为通用HID 键盘,每五秒输入一个“A”。

目标环境正在运行 DOS,因此据我所知,我需要让这台机器上的 BIOS 识别出 Arduino Leonardo,但事实并非如此,并且它不会在 DOS 中键入“A”。

我一直在修改 Leonardo 的 USB 设备描述符,试图让它尽可能匹配戴尔 L100。我所做的修改没有帮助,我怀疑这是因为 Leonardo 是一个复合设备,它在同一个 USB 端口上公开了串行通信、键盘仿真和鼠标仿真。 USB 描述符/配置的源代码可供编辑,位于:

  • Arduino_Installation\hardware\arduino\cores\arduino\HID.cpp
  • Arduino_Installation\hardware\arduino\cores\arduino\USBDesc.h
  • Arduino_Installation\hardware\arduino\cores\arduino\USBCore.h
  • Arduino_Installation\hardware\arduino\cores\arduino\USBCore.cpp

以下是 Leonardo 的 USB 设备查看器的转储:

[Port3]  :  USB Composite Device

          ---===>Device Information<===---
English product name: "Arduino Leonardo"

ConnectionStatus:
Current Config Value:              0x01  -> Device Bus Speed: Full
Device Address:                    0x03
Open Pipes:                           4

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x81  -> Direction: IN - EndpointID: 1
bmAttributes:                      0x03  -> Interrupt Transfer Type
wMaxPacketSize:                  0x0010 = 0x10 bytes
bInterval:                         0x40

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x02  -> Direction: OUT - EndpointID: 2
bmAttributes:                      0x02  -> Bulk Transfer Type
wMaxPacketSize:                  0x0040 = 0x40 bytes
bInterval:                         0x00

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x83  -> Direction: IN - EndpointID: 3
bmAttributes:                      0x02  -> Bulk Transfer Type
wMaxPacketSize:                  0x0040 = 0x40 bytes
bInterval:                         0x00

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x84  -> Direction: IN - EndpointID: 4
bmAttributes:                      0x03  -> Interrupt Transfer Type
wMaxPacketSize:                  0x0040 = 0x40 bytes
bInterval:                         0x01

          ===>Device Descriptor<===
bLength:                           0x12
bDescriptorType:                   0x01
bcdUSB:                          0x0110
bDeviceClass:                      0x00
*!*ERROR: device class should be Multi-interface Function 0xEF
          When IAD descriptor is used
bDeviceSubClass:                   0x00
*!*ERROR: device SubClass should be USB Common Sub Class 2
          When IAD descriptor is used
bDeviceProtocol:                   0x00
*!*ERROR: device Protocol should be USB IAD Protocol 1
          When IAD descriptor is used
bMaxPacketSize0:                   0x40 = (64) Bytes
idVendor:                        0x2341 = Vendor ID not listed with USB.org as of 03-19-2008
idProduct:                       0x8036
bcdDevice:                       0x0100
iManufacturer:                     0x01
     English (United States)  "Arduino LLC"
iProduct:                          0x02
     English (United States)  "Arduino Leonardo"
iSerialNumber:                     0x00
bNumConfigurations:                0x01

          ===>Configuration Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x02
wTotalLength:                    0x0064  -> Validated
bNumInterfaces:                    0x03
bConfigurationValue:               0x01
iConfiguration:                    0x00
bmAttributes:                      0x80  -> Bus Powered
MaxPower:                          0xFA = 500 mA

          ===>IAD Descriptor<===
bLength:                           0x08
bDescriptorType:                   0x0B
bFirstInterface:                   0x00
bInterfaceCount:                   0x02
bFunctionClass:                    0x02  -> This is Communications (CDC Control) USB Device Interface Class
bFunctionSubClass:                 0x01
bFunctionProtocol:                 0x01
iFunction:                         0x00

          ===>Interface Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x04
bInterfaceNumber:                  0x00
bAlternateSetting:                 0x00
bNumEndpoints:                     0x01
bInterfaceClass:                   0x02  -> This is Communications (CDC Control) USB Device Interface Class
bInterfaceSubClass:                0x01
bInterfaceProtocol:                0x00
CAUTION:  This may be an invalid bInterfaceProtocol
iInterface:                        0x00
  -> This is a Communications (CDC Control) USB Device Interface Class

          ===>Descriptor Hex Dump<===
bLength:                           0x05
bDescriptorType:                   0x24
05 24 00 10 01
  -> This is a Communications (CDC Control) USB Device Interface Class

          ===>Descriptor Hex Dump<===
bLength:                           0x05
bDescriptorType:                   0x24
05 24 01 01 01
  -> This is a Communications (CDC Control) USB Device Interface Class

          ===>Descriptor Hex Dump<===
bLength:                           0x04
bDescriptorType:                   0x24
04 24 02 06
  -> This is a Communications (CDC Control) USB Device Interface Class

          ===>Descriptor Hex Dump<===
bLength:                           0x05
bDescriptorType:                   0x24
05 24 06 00 01

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x81  -> Direction: IN - EndpointID: 1
bmAttributes:                      0x03  -> Interrupt Transfer Type
wMaxPacketSize:                  0x0010 = 0x10 bytes
bInterval:                         0x40

          ===>Interface Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x04
bInterfaceNumber:                  0x01
bAlternateSetting:                 0x00
bNumEndpoints:                     0x02
bInterfaceClass:                   0x0A  -> This is a CDC Data USB Device Interface Class
bInterfaceSubClass:                0x01
bInterfaceProtocol:                0x00
CAUTION:  This may be an invalid bInterfaceProtocol
iInterface:                        0x00

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x02  -> Direction: OUT - EndpointID: 2
bmAttributes:                      0x02  -> Bulk Transfer Type
wMaxPacketSize:                  0x0040 = 0x40 bytes
bInterval:                         0x00

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x83  -> Direction: IN - EndpointID: 3
bmAttributes:                      0x02  -> Bulk Transfer Type
wMaxPacketSize:                  0x0040 = 0x40 bytes
bInterval:                         0x00

          ===>Interface Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x04
bInterfaceNumber:                  0x02
bAlternateSetting:                 0x00
bNumEndpoints:                     0x01
bInterfaceClass:                   0x03  -> HID Interface Class
bInterfaceSubClass:                0x01
bInterfaceProtocol:                0x00
CAUTION:  This may be an invalid bInterfaceProtocol
iInterface:                        0x00

          ===>HID Descriptor<===
bLength:                           0x09
bDescriptorType:                   0x21
bcdHID:                          0x0101
bCountryCode:                      0x00
bNumDescriptors:                   0x01
bDescriptorType:                   0x22
wDescriptorLength:               0x0065

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x84  -> Direction: IN - EndpointID: 4
bmAttributes:                      0x03  -> Interrupt Transfer Type
wMaxPacketSize:                  0x0040 = 0x40 bytes
bInterval:                         0x01

我怎样才能让 BIOS 将这个 Leonardo 识别为通用键盘?

【问题讨论】:

  • 您有解决方案吗?我也有同样的问题。
  • 我没有。我确实尝试了 darBis 提供的解决方案,但它也没有设法让 PC 识别它。
  • 您可以将问题报告给您的 BIOS 供应商并推动他们支持它。

标签: arduino hid emulation


【解决方案1】:

Arduino 不支持启动协议。我已经开始使用Teensy(兼容Arduino),效果很好。

【讨论】:

  • 查看启动协议后,我也相信这是问题所在。我在这里找到了文档USB.ORG,解释了它是如何实现的。
  • @wirecat:您是否能够修改 HID 源代码以使其工作?
  • @Force 我不是。从那以后我使用了不同的解决方案,并且没有时间回到这个问题。
【解决方案2】:

我可能弄错了,但是如果您希望您的设备在启动过程中被识别,bInterfaceSubClass 应该是 0x01(启动设备子类)。 在您指出的源文件中,到处都有子类设置为 0x00。

您可以尝试在 D_INTERFACE 宏的所有用法中将子类从 USBCore.h 设置为 0x01。

我不是 Arduino 用户,我只在 AVR 上使用 V-USB 玩过 HID 键盘仿真。您可以尝试在文档中的USB.org 找到有关 USB 描述符的详细信息。但要读的书页实在是太多了。

这是我键盘的部分 od HID 描述符转储,请注意接口描述符中的值:

Bus 005 Device 002: ID 046d:c30e Logitech, Inc. UltraX Keyboard (Y-BL49)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x046d Logitech, Inc.
  idProduct          0xc30e UltraX Keyboard (Y-BL49)
  bcdDevice            1.80
  iManufacturer           1 Logitech
  iProduct                2 HID compliant keyboard
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           59
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      1 Keyboard
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      62

在 linux 下使用“lsusb -v”作为 root 进行转储。

【讨论】:

  • 我尝试了您推荐的解决方案,但不幸的是,BIOS 仍然无法识别 Leonardo。我将在我的问题中添加来自 USB 设备查看器的转储,显示 Leonardo 的当前描述符。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-05
  • 2021-08-17
  • 2011-08-02
  • 2013-03-19
  • 2021-05-11
  • 1970-01-01
相关资源
最近更新 更多