Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support N-key rollover #36

Open
TheButlah opened this issue Dec 20, 2021 · 3 comments
Open

Support N-key rollover #36

TheButlah opened this issue Dec 20, 2021 · 3 comments

Comments

@TheButlah
Copy link

Hi, currently the KeyboardReport only supports reporting up to 6 key presses, not including modifier keys. I'd like to request that it be updated to support an arbitrary number of keypresses.

More can be read here: https://www.devever.net/~hl/usbnkro

@TheButlah
Copy link
Author

I am happy to contribute if you can point me in the right direction!

@haata
Copy link
Collaborator

haata commented Dec 20, 2021

I have this working here: https://github.com/kiibohd/kiibohd-core/tree/main/kiibohd-usb/src

I'm traveling right now but I can provide some guidance in a couple days.

@mdevlamynck
Copy link

The scheme described at the end of the article that support both boot and nkro would be defined as:

#[gen_hid_descriptor(
    (collection = APPLICATION, usage_page = GENERIC_DESKTOP, usage = KEYBOARD) = {
        (usage_page = KEYBOARD, usage_min = 0xE0, usage_max = 0xE7) = {
            #[packed_bits 8]
            #[item_settings data,variable,absolute]
            modifier=input;
        };
        (usage_min = 0x00, usage_max = 0xFF) = {
            #[item_settings constant,variable,absolute]
            reserved=input;
        };
        (usage_page = LEDS, usage_min = 0x01, usage_max = 0x05) = {
            #[packed_bits 5]
            #[item_settings data,variable,absolute]
            leds=output;
        };
        (usage_min = 0x00, usage_max = 0xFF) = {
            #[item_settings constant,variable,absolute]
            keycodes=input;
        };
        (usage_page = KEYBOARD, usage_min = 0x00, usage_max = 0x65) = {
            #[packed_bits 101]
            #[item_settings data,variable,absolute]
            nkro_keycodes=input;
        };
    }
)]
pub struct KeyboardReport {
    pub modifier:     u8,
    pub reserved:     u8,
    pub leds:         u8,
    pub keycodes:     [u8; 6],
    pub nkro_keycodes: [u8; 13],
}

You might want more than [u8; 13] though to support the full range of values defined in the HID spec:

#[gen_hid_descriptor(
    (collection = APPLICATION, usage_page = GENERIC_DESKTOP, usage = KEYBOARD) = {
        (usage_min = 0xE0, usage_max = 0xE7) = {
            #[packed_bits 8]
            #[item_settings constant,variable,absolute]
            modifier=input;
        };
        (usage_min = 0x00, usage_max = 0xFF) = {
            #[item_settings constant,variable,absolute]
            reserved=input;
        };
        (usage_page = LEDS, usage_min = 0x01, usage_max = 0x05) = {
            #[packed_bits 5]
            #[item_settings data,variable,absolute]
            leds=output;
        };
        (usage_min = 0x00, usage_max = 0xFF) = {
            #[item_settings constant,variable,absolute]
            keycodes=input;
        };
        (usage_page = KEYBOARD, usage_min = 0x00, usage_max = 0xE7) = {
            #[packed_bits 232]
            #[item_settings data,variable,absolute]
            all_keycodes=input;
        };
    }
)]
pub struct KeyboardReport {
    pub modifier:     u8,
    pub reserved:     u8,
    pub leds:         u8,
    pub keycodes:     [u8; 6],
    pub all_keycodes: [u8; 29],
}

Here the modifiers are included in the all_keycodes field and modifier is configured as a constant to be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants