How to Program N-key Rollover atmega32u4?

Currently I have a keyboard working perfectly, with my own pcb and a code that I made using the keyboard.h library. The keyboard has 6 max keys at the same time and I would like to change that to N-keyrollover.

The sure solution is to change the code but I can't find anything to do with it.

Here is my code. Here are also more resources like images and schematics.
Teclado-Teseracto/keyboard.ino at main · Electroner/Teclado-Teseracto (github.com)

Or

Currently I have a keyboard working perfectly, with my own pcb and a code that I made using the keyboard.h library. The keyboard has 6 max keys at the same time and I would like to change that to N-keyrollover.

The sure solution is to change the code but I can't find anything to do with it.

Here is my code. Here are also more resources like images and schematics.
Keyboard-Tesseract / keyboard.ino at main · Electroner / Keyboard-Tesseract (github.com)

you can use google translate, too.

a7

You probably have to change this 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;
1 Like

This doesn't seems to work. Even changing the rest of the code of .cpp to make it work.

What value did you use in place of 6?

Did you change both places in Keyboard.cpp?

	// 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);
}
1 Like

You may also have to change the HID report descriptor. The HID report descriptor tells the USB host PC what to expect from the USB keyboard.

The original descriptor specifies at most 6 keys down. Try changing this to 61 then change every other reference in the code from 6 keys to 61 keys. 61 key rollover makes the entire HID report 64 bytes which is a fundamental unit of transfer for USB full speed (12 Mbits/s max). I have never tried this so more changes may be needed.

typedef struct
{
  uint8_t modifiers;
  uint8_t reserved;
  uint8_t keys[61];
} KeyReport;

See the commented out line REPORT_COUNT below.

static const uint8_t _hidReportDescriptor[] PROGMEM = {

  //  Keyboard
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)  // 47
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x85, 0x02,                    //   REPORT_ID (2)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
   
  0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    
  0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    
//0x95, 0x06,                    //   REPORT_COUNT (6)
  0x95, 0x3D,                    //   REPORT_COUNT (61)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x73,                    //   LOGICAL_MAXIMUM (115)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    
  0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x73,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0,                          // END_COLLECTION
};
1 Like

It worked thx, also have to change some other parts from 6 to 61 and

// Add k to the key report only if it's not already present
	// and if there is an empty slot.
	bool pass = true;
	for(int i = 0;i<61 && pass;i++) {
		if(_keyReport.keys[i] == k) {
			pass = false;
		}
	}
	if (pass) {
           ...

And the Release ALL

void Keyboard_::releaseAll(void)
{
	for(int i=0; i<61; i++) {
		_keyReport.keys[i] = 0;
	}
...

The edited coded has been uploaded to my github project for anyone how wanted to change it.
Teclado-Teseracto/SourceCode/Keyboard Modified Libraries at main · Electroner/Teclado-Teseracto (github.com)

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