Overhaul USB HID for Leonardo and Micro

This pull request includes the features from pull request 1488 and pull request 1391. I've somewhat overhauled the code to better match the surrounding code and a few features.

I've also added code examples for the less discoverable features.

If this pull request isn't "right" yet, I'd love feedback so I can improve it.
Nice catch. I'd thought that there was code to move items to earlier slots. Did this actually cause an operational issue for you?

Jesse


On Thu, Oct 16, 2014 at 01:43:16PM -0700, João Lopes wrote:
> > + 	uint8_t index = 0;
> > + 	uint8_t done = 0;
> > + 	
> > + 	if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) {
> > + 		// it's a modifier key
> > + 		_keyReport.modifiers |= (0x01 << (k - HID_KEYBOARD_LEFT_CONTROL));
> > + 	} else {
> > + 		// it's some other key:
> > + 		// Add k to the key report only if it's not already present
> > + 		// and if there is an empty slot.
> > + 		for (index = 0; index < KEYREPORT_KEYCOUNT; index++) {
> > + 			if (_keyReport.keys[index] != k) { // is k already in list?
> > + 				if (0 == _keyReport.keys[index]) { // have we found an empty slot?
> > + 					_keyReport.keys[index] = k;
> > + 					done = 1;
> > + 					break;
> 
> This code will allow to insert the same key multiple time into the report in the case where a free slot is found before the slot where the key is already stored.
> 
> 
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/arduino/Arduino/pull/1803/files#r18985064

--