Adding NKRO support to stock arduino libary?

HI

I'm still quite the n00b with arduino but i made a simple keyboard encoder and unfortunately i need to press more than the standard six buttons for my desired outcome.

I tried two of the other nrko projects found on github but they don't seem to compile, even with their provided ino examples. I also tried a few of the things seen in some other threads where people claimed to modify both the keyboard.cpp and keyboard.h but each time change the max key values past 6, my code will compile but do nothing on a programmed arduino (leonardo).

Has anyone successfully modified the latest stock keyboard library to support n key rollover? Any help would be greatly appreciated.

Did you change all of the places where the report is limited to 6 entries?

In Keyboard.h:

// Low level key report: up to 6 keys and shift, ctrl etc at once
typedef struct
{
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
} KeyReport;

In Keyboard.cpp:

    0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
	// Add k to the key report only if it's not already present
	// and if there is an empty slot.
	if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
		_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
		_keyReport.keys[4] != k && _keyReport.keys[5] != k) {

		for (i=0; i<6; i++) {
			if (_keyReport.keys[i] == 0x00) {
				_keyReport.keys[i] = k;
				break;
			}
		}
		if (i == 6) {
			setWriteError();
			return 0;
		}
	}
	// Test the key report to see if k is present.  Clear it if it exists.
	// Check all positions in case the key is present more than once (which it shouldn't be)
	for (i=0; i<6; i++) {
		if (0 != k && _keyReport.keys[i] == k) {
			_keyReport.keys[i] = 0x00;
		}
	}
void Keyboard_::releaseAll(void)
{
	_keyReport.keys[0] = 0;
	_keyReport.keys[1] = 0;
	_keyReport.keys[2] = 0;
	_keyReport.keys[3] = 0;
	_keyReport.keys[4] = 0;
	_keyReport.keys[5] = 0;
	_keyReport.modifiers = 0;
	sendReport(&_keyReport);
}

Thanks for your response.

Yes. I tried changing those values. Anything above 6 will compile using the arduino ide but when its uploaded to my leonardo, nothing happends. The leonardo is indeed being detected as a keyboard in my device control panel.

Just a quick follow up. I modified the value to 5 just to test and it also does not work.

Did you also set REPORT_SIZE to 7?

John

I've tried everything from 5-9. So far, no luck.

Did you also set REPORT_SIZE to 7-11?

Yes

My original aim was to press 12 buttons at once. Then i lowered it to 9. Then 5. Nothing I've tried so far is working.

Does it work if you set it back to the original 6?

yes. If i revert back to 6 it will work.

"However, the USB standard also allows you to declare that a keyboard can operate in “boot” mode, which means that the supplied report descriptor is ignored, and a standard report descriptor is assumed instead."

That is the explanation for why only 6-key rollover works. I looked at the Keyboard and HID libraries and can't figure out how to make a non-boot keyboard that, in theory, would allow more simultaneous keys.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.