Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
translations translations
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Thank You for your continued support and contributions!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  [Solved] USB HID: Holding down a key
« previous next »
  • Print
Pages: [1]

Author Topic: [Solved] USB HID: Holding down a key  (Read 2033 times)

Offline __builtin

  • Developer
  • Member
  • *
  • Posts: 409
  • iPod 6G, c200v1 (RIP), e200v1 (RIP)
    • FWEI.TK
[Solved] USB HID: Holding down a key
« on: September 27, 2015, 02:26:52 PM »
Recently I've been trying to figure out how to simulate a key being held down via Rockbox's USB HID feature.

In firmware/usbstack/usb_hid.c where the function usb_hid_send() is defined, there's this piece of code:
Code: [Select]
    logf("Sending cmd 0x%x", id);
    length = report->buf_set(&buf[1], id) + 1;
    logf("length %u", length);

    if (!length)
        return;

    /* Key pressed */
    buf_dump(buf, length, "key press");
    usb_hid_queue(buf, length);

    if (report->is_key_released)
    {
        /* Key released */
        memset(&buf[1], 0, length-1);

        buf_dump(buf, length, "key release");
        usb_hid_queue(buf, length);
    }

Looking at that, it seems that the last if block is what sends the 'key up' event to the host.
My reasoning was that by removing this, you could simulate a key being held down.

Building on this, idea, I wrote a function identical to usb_hid_send(), but with that if statement removed:

Code: [Select]
void usb_hid_send_keydown(usage_page_t usage_page, int id)
{
    uint8_t length;
    static unsigned char buf[HID_BUF_SIZE_CMD] USB_DEVBSS_ATTR
        __attribute__((aligned(32)));
    usb_hid_report_t *report = NULL;

    for (uint8_t report_id = 1; report_id < REPORT_ID_COUNT; report_id++)
        if (usb_hid_reports[report_id].usage_page == usage_page)
        {
            report = &usb_hid_reports[report_id];
            buf[0] = report_id;
            break;
        }

    if (!report)
    {
        logf("Unsupported usage_page");
        return;
    }

    logf("Sending cmd 0x%x", id);
    length = report->buf_set(&buf[1], id) + 1;
    logf("length %u", length);

    if (!length)
        return;

    usb_hid_try_send_drv();
}

However, it doesn't work.

My question is this: what should I do to simulate a key being held down?

EDIT:As it turns, out, I was Doing It Wrong (TM). The HID driver's keyboard component can take up to 4 key codes at once, packed into a 4-byte int.
« Last Edit: September 27, 2015, 03:16:12 PM by theunamedguy »
Logged
No support questions by PM, please.

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  [Solved] USB HID: Holding down a key
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.047 seconds with 17 queries.