Fundamental question about HID

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folks

 

Hopefully a basic question but one I've struggled to get a conclusive answer to.

 

I want to design a XMega based HID solution that notifies a PC (Windows) if a switch has been pressed and/or pass on some data that's been recieved over the UART from another source.

 

The question is, is HID exclusively a polled solution (that's how I've been doing it so far) or does the specification allow for the HID device to raise an event along the lines of 'I've some data ready for you, please collect'?

 

Not looking specific code on how to do it, just if it's possible and general pointers to where I should be looking. I haven't looked at the ASF examples yet but other examples I've checked seem to be polled.

 

thanks

Last Edited: Tue. Oct 3, 2017 - 01:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you need to understand how USB works. USB devices can't just send whenever they like, they have to wait for a packet from the host that polls them for data. The host will send these packets regularly, say every 10ms for HID, and at that time the device can send new data if it has any.

 

My advice would be to send the status of the switch with an HID report. The host software can poll that, and when it sees that the switch is closed it can send a request for UART data on the control endpoint. Alternatively you could just send the UART data with the HID report as well, it really depends on the nature of the data and how your software wants to handle it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks

 

That was my understanding of how USB works as well and the 10ms polling is exactly what I currently do.

 

The spanner in the works was that the HID library I use on the PC side (https://github.com/mikeobrien/Hi...) has an OnReport event which seems to be designed to fire when the device sends a report.

 

Admittedly I've never been able to get it to work and others have reported similar problems but it did leave me wondering if I was missing something.

 

thanks again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When the host polls you don't have to send a new HID report. If you don't the host will just assume that the state didn't change, i.e. if the button was pressed it is still pressed.

 

The ASF code, as well as most other frameworks, have a function that sends an HID report. What it actually does is prepare that data for sending, and then an interrupt is triggered by the USB IN packet (which is the host polling) to actually send it. If there is no new data to send then the device can send a NACK packet instead, which is handled by the ASF code. The NACK is important because the way that the host knows that the device is still connected it that it consistently gets a response to polling.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@GilchristT

 

I have different experience. I have several commercial designs out in the wild that emulate a HID keyboard and "type" data depending upon the external stimulus applied to the atmel chips (I have used Mega8, Tiny2313 and Mega88). Admittedly at the receiving end my customer has written his own software to handle the incoming messages, but his end does not need to do anything magical.

 

This youtube and linked website demonstrates the approach very well  I think. Hopefully it might give you some ideas.

 

https://www.youtube.com/watch?v=...

 

Cheers,

 

Ross

 

ps... I should say that the youtube demo is of a serial comms approach... not the keyboard one, but you should get the idea.

 

Ross McKenzie ValuSoft Melbourne Australia

Last Edited: Mon. Oct 2, 2017 - 08:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's a good idea. I made a little project with a keyboard that sent macros, i.e. one button actually send ctrl-alt-windows-F12, and then just assigned those hotkeys to stuff in Windows. You could do something similar and simply look for a keypress, as valusoft suggests.

 

There are actually some special keys supported by HID keyboards that real keyboards never have, like F13-F24, which are ideal for this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely, the whole point of USB is that the way HID works is independent of the specific hardware - so this has nothing specifically to do with XMEGA ?