2012-10-01 70 views
6

Tôi đang cố gắng sử dụng một mô phỏng Arduino Leonardo cho bàn phím vì đó là một trong những tính năng được quảng cáo của nó. Tôi đã chơi với Leonardo và đã viết một bản phác thảo rất đơn giản dựa trên ví dụ Blink.Giả lập bàn phím chung sử dụng Arduino Leonardo

// 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 
} 

Ví dụ này hoạt động tốt trên máy tính Windows XP của tôi. Nó được công nhận là bàn phím chung HID và sẽ nhập 'A' cứ sau năm giây.

Môi trường được nhắm mục tiêu đang chạy DOS để kiến ​​thức của tôi, tôi cần phải nhận được Arduino Leonardo được BIOS công nhận trên máy này, không phải là nó và không gõ 'A' trong DOS.

Tôi đã thực hiện sửa đổi đối với bộ mô tả thiết bị USB của Leonardo, cố gắng làm cho nó phù hợp với Dell L100 càng nhiều càng tốt. Những sửa đổi tôi đã thực hiện đã không giúp đỡ, và tôi nghi ngờ đó là bởi vì Leonardo là một thiết bị tổng hợp cho thấy giao tiếp nối tiếp, mô phỏng bàn phím và mô phỏng chuột trên cùng một cổng USB. Các mã nguồn cho các mô tả USB/cấu hình có sẵn để được chỉnh sửa và tọa lạc tại địa chỉ:

  • Arduino_Installation \ phần cứng \ Arduino \ lõi \ Arduino \ HID.cpp
  • Arduino_Installation \ phần cứng \ Arduino \ lõi \ Arduino \ USBDesc.h
  • Arduino_Installation \ phần cứng \ Arduino \ lõi \ Arduino \ USBCore.h
  • Arduino_Installation \ phần cứng \ Arduino \ lõi \ Arduino \ USBCore.cpp

sau đây là một bãi chứa từ thiết bị USB Người xem cho Leonardo:

[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 

Làm thế nào tôi có thể nhận được Leonardo này được BIOS công nhận là bàn phím chung?

+0

Bạn có sử dụng giải pháp không ?. Tôi có cùng một vấn đề. – Delta

+0

Tôi thì không. Tôi đã thử giải pháp được cung cấp bởi darBis, nhưng nó cũng không quản lý để PC nhận ra nó. –

Trả lời

2

Arduino không hỗ trợ giao thức khởi động. Tôi đã bắt đầu sử dụng Teensy (đó là Arduino tương thích), và nó hoạt động khá tốt.

+1

Sau khi nhìn vào giao thức khởi động, tôi cũng tin rằng đây là vấn đề. Tôi tìm thấy tài liệu ở đây [USB.ORG] (http://www.usb.org/developers/devclass_docs/HID1_11.pdf) giải thích cách nó có thể được triển khai. –

+0

@wirecat: Bạn có thể sửa đổi mã nguồn HID để làm cho nó hoạt động không? – Force

+0

@Force tôi thì không. Từ đó tôi đã sử dụng một giải pháp khác và không có thời gian để quay lại điều này. –

1

Tôi có thể bị nhầm lẫn, nhưng nếu bạn muốn bạn được công nhận trong khi khởi động, thì bInterfaceSubClass phải là 0x01 (Phân lớp thiết bị khởi động). Trong các tệp nguồn bạn đã chỉ ra, có mọi lớp phụ được đặt là 0x00.

Bạn có thể thử đặt phân lớp trong tất cả các tập quán của macro D_INTERFACE từ USBCore.h thành 0x01.

Tôi không phải là người dùng Arduino, tôi chỉ chơi một lần với mô phỏng bàn phím HID trên AVR sử dụng V-USB. Bạn có thể thử tìm thông tin chi tiết về mô tả usb tại USB.org trong tài liệu. Nhưng có khá nhiều trang để đọc.

Dưới đây là phần mô tả od HID bãi chứa của bàn phím của tôi, giá trị thông báo trong giao diện Descriptor:

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 

Dump được đưa ra sử dụng "lsusb -v" như rễ dưới Linux.

+1

Tôi đã thử giải pháp được khuyên dùng của bạn nhưng tiếc là Leonardo vẫn chưa được BIOS công nhận.Tôi sẽ thêm một kết xuất từ ​​Trình xem thiết bị USB trong câu hỏi của tôi hiển thị các bộ mô tả hiện tại cho Leonardo. –

Các vấn đề liên quan