Is it possible to do extra comm with usb-hid keyboard?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
fish47
Posts: 4
Joined: Tue Dec 11, 2012 6:24 am

Is it possible to do extra comm with usb-hid keyboard?

Post by fish47 » Tue Dec 11, 2012 6:45 am

Hello everyone, rencently I got a interesting idea --- making a customizable keyboard, but I came accross some problems I can't figure out. I hope you can help me. Thanks a lot.
As the similar projects which have been done, making a usb-hid keyboard is not a difficult task.
I want to customize the keycodes of the buttons via PC. Using IR or UART is ok, but they aren't so convenient as the previous solution.
Since libusb can do direct communication with usb device, even the device isn't driven. But is it poosible to do so while the device has been recognized as usb-hid keyboard ?

xiangrui
Rank 1
Rank 1
Posts: 30
Joined: Sun Jan 01, 2012 5:19 am

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by xiangrui » Wed Dec 12, 2012 6:07 pm

For Windows, it is unlikely. The system will claim full control of the USB HID keyboard. For Linux, I am not sure, but probably you can do it.

-Xiangrui

fish47
Posts: 4
Joined: Tue Dec 11, 2012 6:24 am

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by fish47 » Thu Dec 13, 2012 9:51 am

xiangrui wrote:For Windows, it is unlikely. The system will claim full control of the USB HID keyboard. For Linux, I am not sure, but probably you can do it.

-Xiangrui


Thanks for your tips.

Bob
Posts: 17
Joined: Sun Jun 10, 2007 7:10 pm
Location: Melbourne

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by Bob » Sun Dec 16, 2012 2:07 pm

In Windows, it's possible to send and receive data to a keyboard or mouse using feature reports.
The trick is to open the device as ACCESS_TYPE_NONE otherwise it will fail as it's locked and owned by windows.

handle = CreateFile(deviceDetails->DevicePath, ACCESS_TYPE_NONE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL);

fish47
Posts: 4
Joined: Tue Dec 11, 2012 6:24 am

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by fish47 » Wed Mar 13, 2013 2:59 am

I have found a better solution. In short, the way to achieve my goal is to decalre two devices in hid descriptor: one for keyboard/mouse, one for a hid-data device. LibUsb can claim the device(s) even so. It works fine under Linux or Windows platform. If you want more detail, the website below is worth reading.
http://www.frank-zhao.com/cache/hid_tutorial_1.php

Bob
Posts: 17
Joined: Sun Jun 10, 2007 7:10 pm
Location: Melbourne

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by Bob » Thu Mar 14, 2013 5:31 pm

That means you must install libusb drivers on the target.
If you're going to do that, there is no need for a composite device descriptor, libusb can access mice and keyboards without any tricks.
The method I described doesn't require any drivers or libusb to be installed.
However, using libusb means it will pretty much work on any platform which is always a good thing :)

fish47
Posts: 4
Joined: Tue Dec 11, 2012 6:24 am

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by fish47 » Sun Mar 17, 2013 8:26 am

Bob wrote:That means you must install libusb drivers on the target.
If you're going to do that, there is no need for a composite device descriptor, libusb can access mice and keyboards without any tricks.
The method I described doesn't require any drivers or libusb to be installed.
However, using libusb means it will pretty much work on any platform which is always a good thing :)

You can use the public pid/vid that v-usb provides. It can be driven on win7 and ubuntu12.04. According to *libusbx* wiki, keyboard and mouse is not accessible.
https://github.com/libusbx/libusbx/wiki ... kend#about
BTW, using *libusbx* is very convenient, because it provide win32 static/dynamic library dist. You can also compile it on Linux too.

Bob
Posts: 17
Joined: Sun Jun 10, 2007 7:10 pm
Location: Melbourne

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by Bob » Thu Mar 21, 2013 5:50 pm

I haven't tried libusbx but can assure you that the older libusb works fine with keyboards and mice when doing control transfers.

xiangrui
Rank 1
Rank 1
Posts: 30
Joined: Sun Jan 01, 2012 5:19 am

Re: Is it possible to do extra comm with usb-hid keyboard?

Post by xiangrui » Sun Mar 24, 2013 9:29 pm

fish47 wrote:I have found a better solution. In short, the way to achieve my goal is to decalre two devices in hid descriptor: one for keyboard/mouse, one for a hid-data device. LibUsb can claim the device(s) even so. It works fine under Linux or Windows platform. If you want more detail, the website below is worth reading.
http://www.frank-zhao.com/cache/hid_tutorial_1.php


I just tried a keyboard and another generic hid device, and it works fine! I had to use reportID for both devices. Thanks for the information.

I wonder whether there is a way to use different VID/PID and device name for the two device, which are all defined in usbconfig.h. According to V-USB, they should have different PID, since they use different drivers.

-Xiangrui

Post Reply