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

Helpers for creating USB HID keyboards #28

Open
amclain opened this issue Jul 1, 2020 · 3 comments
Open

Helpers for creating USB HID keyboards #28

amclain opened this issue Jul 1, 2020 · 3 comments

Comments

@amclain
Copy link
Member

amclain commented Jul 1, 2020

Creating a USB gadget device that exposes a HID keyboard can involve some cryptic settings, especially for developers who just want to send keyboard events without diving into the USB spec. An example of this configuration can be found in Xebow's hid_gadget.ex file:

# 6-key-rollover descriptor:
# 05 01 09 06 A1 01 05 07 19 E0 29 E7 15 00 25 01
# 75 01 95 08 81 02 81 01 19 00 29 FF 15 00 25 FF
# 75 08 95 06 81 00 05 08 19 01 29 05 15 00 25 01
# 75 01 95 05 91 02 95 03 91 01 C0

# n-key-rollover descriptor:
# 05 01 09 06 A1 01 75 01 95 08 15 00 25 01 05 07
# 19 E0 29 E7 81 02 75 01 95 05 05 08 19 01 29 05
# 91 02 75 03 95 01 91 03 75 01 95 F8 15 00 25 01
# 05 07 19 00 29 F7 81 02 C0

hid_settings = %{
  "protocol" => "1",
  "report_length" => "8",
  "subclass" => "1",
  "report_desc" =>
    <<0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, 0x15, 0x00,
      0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x81, 0x01, 0x19, 0x00, 0x29, 0xFF,
      0x15, 0x00, 0x25, 0xFF, 0x75, 0x08, 0x95, 0x06, 0x81, 0x00, 0x05, 0x08, 0x19, 0x01,
      0x29, 0x05, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x05, 0x91, 0x02, 0x95, 0x03,
      0x91, 0x01, 0xC0>>
}

AFK could encapsulate USB configuration into one or more helpers, like:

hid_settings = AFK.USB.create_hid_settings(rollover_type: :six_key)
@amclain
Copy link
Member Author

amclain commented Jul 3, 2020

This may be helpful:
https://github.com/ConnorRigby/elixir-libusb

@doughsay
Copy link
Member

doughsay commented Jul 4, 2020

This may be helpful:
https://github.com/ConnorRigby/elixir-libusb

Correct me if I'm wrong but that library looks like it's meant to interact with USB devices from a host?

@amclain
Copy link
Member Author

amclain commented Jul 5, 2020

Sorry, I didn't mean to imply we should use the library as a dependency. I saw it spits out USB configuration and device data, so thought I'd reference it here in case it can help with figuring out things like n-key rollover.

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

2 participants