使用Arduino Leonardo的通用键盘仿真

使用Arduino Leonardo的通用键盘仿真,arduino,hid,emulation,Arduino,Hid,Emulation,我正在尝试使用一个用于键盘模拟的,因为这是它的广告特性之一。我一直在玩莱昂纳多,并根据眨眼的例子写了一个非常简单的草图 //针脚13在大多数Arduino板上都连接了一个LED。 int led=13; //按“重置”时,设置例程运行一次: 无效设置() { //将数字管脚初始化为输出。 引脚模式(led,输出); } //循环例程会一直反复运行: void循环() { 延迟(5000);//等待五秒钟 数码写入(led,高);//打开led(高是电压电平) 延迟(100);//等待一秒钟 di

我正在尝试使用一个用于键盘模拟的,因为这是它的广告特性之一。我一直在玩莱昂纳多,并根据眨眼的例子写了一个非常简单的草图

//针脚13在大多数Arduino板上都连接了一个LED。
int led=13;
//按“重置”时,设置例程运行一次:
无效设置()
{
//将数字管脚初始化为输出。
引脚模式(led,输出);
}
//循环例程会一直反复运行:
void循环()
{
延迟(5000);//等待五秒钟
数码写入(led,高);//打开led(高是电压电平)
延迟(100);//等待一秒钟
digitalWrite(led,低);//通过降低电压关闭led
Keyboard.write('A');//使用键盘仿真器编写A
}
现在,这个例子在我的Windows XP机器上非常有效。它被认为是一个通用键盘,每五秒钟会键入一个“a”

目标环境正在运行DOS,因此据我所知,我需要让这台机器上的BIOS识别Arduino Leonardo,它不是,也不会在DOS中键入“A”

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

  • Arduino\u安装\hardware\Arduino\cores\Arduino\HID.cpp
  • Arduino\u安装\hardware\Arduino\cores\Arduino\USBDesc.h
  • Arduino\u安装\hardware\Arduino\cores\Arduino\USBCore.h
  • Arduino\u安装\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
[Port3]:USB复合设备
---==>设备信息设备总线速度:满
设备地址:0x03
明管:4
=>端点描述符方向:IN-EndpointID:1
bmAttributes:0x03->中断传输类型
wMaxPacketSize:0x0010=0x10字节
bInterval:0x40
=>端点描述符方向:OUT-端点ID:2
bmAttributes:0x02->批量传输类型
wMaxPacketSize:0x0040=0x40字节
b间期:0x00
=>端点描述符方向:IN-EndpointID:3
bmAttributes:0x02->批量传输类型
wMaxPacketSize:0x0040=0x40字节
b间期:0x00
=>端点描述符方向:IN-EndpointID:4
bmAttributes:0x03->中断传输类型
wMaxPacketSize:0x0040=0x40字节
bInterval:0x01
=>设备描述符配置描述符已验证
bNumberFaces:0x03
B配置值:0x01
i配置:0x00
bmAttributes:0x80->总线供电
最大功率:0xFA=500 mA
==>IAD描述符这是通信(CDC控制)USB设备接口类
bFunctionSubClass:0x01
bFunctionProtocol:0x01
iFunction:0x00
=>接口描述符这是通信(CDC控制)USB设备接口类
Binterface子类:0x01
bInterfaceProtocol:0x00
警告:这可能是无效的bInterfaceProtocol
界面:0x00
->这是一个通信(CDC控制)USB设备接口类
==>描述符十六进制转储这是一个通信(CDC控制)USB设备接口类
==>描述符十六进制转储这是一个通信(CDC控制)USB设备接口类
==>描述符十六进制转储这是一个通信(CDC控制)USB设备接口类
==>描述符十六进制转储端点描述符方向:IN-EndpointID:1
bmAttributes:0x03->中断传输类型
wMaxPacketSize:0x0010=0x10字节
bInterval:0x40
==>接口描述符这是一个CDC数据USB设备接口类
Binterface子类:0x01
bInterfaceProtocol:0x00
警告:这可能是无效的bInterfaceProtocol
界面:0x00
=>端点描述符方向:OUT-端点ID:2
bmAttributes:0x02->批量传输类型
wMaxPacketSize:0x0040=0x40字节
b间期:0x00
=>端点描述符方向:IN-EndpointID:3
bmAttributes:0x02->批量传输类型
wMaxPacketSize:0x0040=0x40字节
b间期:0x00
==>接口描述符HID接口类
Binterface子类:0x01
bInterfaceProtocol:0x00
警告:这可能是无效的bInterfaceProtocol
界面:0x00
=>HID描述符rendpoint描述符方向:IN-EndpointID:4
bmAttributes:0x03->中断传输类型
wMaxPacketSize:0x0040=0x40字节
bInterval:0x01

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

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

你可以试着设置一个
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