Author Topic: Replicating a USB HID  (Read 12023 times)

usbcom

  • Member
  • ***
  • Posts: 1
Replicating a USB HID
« on: June 25, 2010, 01:08:41 pm »
Hi,

Hope someone can help, and sorry for the long post. I have reasonable experience of electronics hardware, but much less programming experience.

The task I've set myself as a learning exercise/project is to attempt to emulate a data logger device that represents itself as a USB HID. I've used USB monitoring software to gain an understanding of the messages the logger is sending. Apart from the enumeration phase when the device is first plugged in, it does not interact with the host thereafter, and just constantly transmits data to the host. It transmits 8 byte message blocks every 8ms. The blocks consist of parts of a message containing two A/D readings made every 32ms. The message when reconstructed is always in the format:

Code: [Select]
<<<<<jjkk llmm>>>>>>

then terminated with 0x0A and 0x0D. jjkk and llmm are the two A/D readings seperated by a space.

Each 8 byte data block consists of a first byte that indicates how many of the subsequent bytes are valid, followed by ASCII representation of the data. An example of actual transmitted data is:

Code: [Select]
05 3C 3C 3C 3C 3C 3E 0A = first 0x05 bytes only = <<<<< in ASCII
07 31 32 35 32 20 30 38 = 1252 08 (Note space, 0x20, between 1st and 2nd data pairs)
03 34 31 3E 32 20 30 38 = 41>
07 3E 3E 3E 3E 3E 0A 0D = >>>>> then 0x0A 0x0D

So the message reads:

Code: [Select]
<<<<<1252 0841>>>>>> terminated by 0x0A 0x0D.

The A/D measurements need to be fixed in time relative to the previous measurements (every 32ms) in order that varying input signals can be accurately reconstructed, so I'm assuming they are interrupt driven. Each 8 byte message block happens every 8ms, so I'm assuming they are interrupt driven. I'd be grateful if someone can explain to me (in general terms) how the I should go about emulating this message structure. Does the form of the messages indicate some standard technique?

I plan to develop this using C on an Atmel chip.

Thanks,

Mike

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Replicating a USB HID
« Reply #1 on: June 25, 2010, 11:08:29 pm »
For guaranteed bandwidth and error detecting, the device should use interrupt transfers. If the device is full or high speed, the descriptor for the interrupt IN endpoint can request a maximum latency of 8 ms (or less, down to 1 ms). With 8 ms max latency, the host will send an IN token packet to request data at least every 8 ms, with the option to request data more often. If it's low speed, the most the endpoint can request is a transaction attempt every 10 ms, though in reality (but no guarantee), if the endpoint requests 10 ms, most hosts will attempt a transaction every 8 ms.

To send the data, the device firmware must "arm" the endpoint, typically by placing data to send in a buffer and setting the endpoint to return data on the next IN token packet.

A Windows host application can use ReadFile to read the data and can decode the data as needed.

If the messages are 32 bytes and the device is full or high speed, you can set the endpoint size to 32 bytes and send the whole message in one transaction.

My HID page has example device firmware and host software for basic HID transfers:

http://www.lvr.com/hidpage.htm

Jan