How to output data to e.g. HID device

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
tommyjunge

How to output data to e.g. HID device

Post by tommyjunge » Thu Jan 07, 2010 9:19 am

Hi,

I would like to create a V-USB application, that allows to send a few bytes from the host to the AVR and back.
I would like to use drivers already available in Windows, e.g. HID. (Are there other Windows interfaces that are better suited for this purpose?)

To my understanding HID is for INput devices. Can it still be used to OUTput data from the PC to the AVR? Can anybody recommend a V-USB example project where I can study how this is done?

Thanks, Tom

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to output data to e.g. HID device

Post by christian » Thu Jan 07, 2010 12:35 pm

You can use HID for bidirectional data transfer. However, since you must use feature reports (set and get), you are limited to fixed size data blocks. See the hid-data example, it uses HID feature reports to send and receive data.

tommyjunge

Re: How to output data to e.g. HID device

Post by tommyjunge » Thu Jan 07, 2010 2:29 pm

Thank you for the hint!

I am afraid I couldn't find the hid-data example. Can you please give me a link?

Thanks, Tom

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to output data to e.g. HID device

Post by christian » Thu Jan 07, 2010 2:56 pm

It's in the "examples" directory of the current driver package found at http://www.obdev.at/products/vusb/download.html

tommyjunge

Re: How to output data to e.g. HID device

Post by tommyjunge » Fri Jan 08, 2010 10:15 pm

Thanks, I have found HID_DATA and the AVR side is working nicely.

Now I need to learn how to deal with the host side.

I have no experience with HID. Where can I read how to handle the HID-DATA device on the host side, e.g. what kinds of transfers are being used and what are the APIs to be used?

I need to do this in Pascal/Delphi. Does anybody have experience how to use the Jedi JvHIDDevieController for this purpose?

iphi
Rank 2
Rank 2
Posts: 68
Joined: Mon Jun 25, 2007 11:37 am

Re: How to output data to e.g. HID device

Post by iphi » Sat Jan 09, 2010 10:37 pm

Ok, I finally figured it out to feed HID_DATA from Delphi.
The JvHidController component works great.
If anybody would like the Pascal code, contact me.

Tom

uchar
Posts: 15
Joined: Wed Oct 28, 2009 12:05 pm

Re: How to output data to e.g. HID device

Post by uchar » Tue Jan 19, 2010 5:49 pm

christian wrote:You can use HID for bidirectional data transfer. However, since you must use feature reports (set and get), you are limited to fixed size data blocks. See the hid-data example, it uses HID feature reports to send and receive data.


Respected Christian!
You have written about limitation by the fixed block size of the data. What size for the block - 8 byte?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to output data to e.g. HID device

Post by christian » Tue Jan 19, 2010 5:53 pm

It depends on your report descriptors. You can choose any block size you like (as long as you don't exceed the limits of V-USB or the host side drivers), provided that you describe the block in the report descriptor.

uchar
Posts: 15
Joined: Wed Oct 28, 2009 12:05 pm

Re: How to output data to e.g. HID device

Post by uchar » Tue Jan 19, 2010 6:09 pm

Thanks.

I use an example hid-data. I wish to write and read 512 byte in EEPROM.
But for me it is impossible to transfer more than 254 byte. In what there can be a problem?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to output data to e.g. HID device

Post by christian » Tue Jan 19, 2010 6:56 pm

254 bytes is the size limit of V-USB in the default configuration. If you need bigger descriptors, define USB_CFG_LONG_TRANSFERS in usbconfig.h.

uchar
Posts: 15
Joined: Wed Oct 28, 2009 12:05 pm

Re: How to output data to e.g. HID device

Post by uchar » Wed Jan 20, 2010 6:13 pm

Yes, I saw this define and have installed it, but it has not helped :(

Also I have changed a report-descriptor :

Code: Select all

PROGMEM char usbHidReportDescriptor[23] = {    /* USB report descriptor */
    0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    // USAGE (Vendor Usage 1)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0xff,              //   LOGICAL_MAXIMUM (512) 
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x96, 0xff, 0xff,                //   REPORT_COUNT (512) 
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)
    0xc0                           // END_COLLECTION
};



Please, tell in what my error.

uchar
Posts: 15
Joined: Wed Oct 28, 2009 12:05 pm

Re: How to output data to e.g. HID device

Post by uchar » Wed Jan 20, 2010 6:38 pm

Excuse, I have understood :)

Has downloaded HID Descriptor Tool and has checked up parametre Report Count - for 512 byte it should be such: 0x96, 0x00, 0x02.

Now all works :)

uchar
Posts: 15
Joined: Wed Oct 28, 2009 12:05 pm

Re: How to output data to e.g. HID device

Post by uchar » Thu Jan 21, 2010 3:03 pm

Christian, is again necessary to me your help :)

In an example hid-data the exchange goes through default control endpoint. Where it is described descriptor by this endpoint? (In a file usbdrv.c described two endpoint, with numbers 1 and 3)

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to output data to e.g. HID device

Post by christian » Fri Jan 22, 2010 11:36 am

Endpoint 0 is described in the USB spec. Since it MUST be a control endpoint, there is no need to add a separate descriptor for it.

pcs
Posts: 1
Joined: Wed Feb 10, 2010 11:12 pm

Re: How to output data to e.g. HID device

Post by pcs » Wed Feb 10, 2010 11:15 pm

hi,

i would be interested how to get the HID smaple to work with the Delphi HIDcontroller.
Tom can you please give me some advce?

kind regards
pcs

Post Reply