Kuroneko.Gadget.HID (kuroneko_gadget v0.5.0)

Copy Markdown View Source

The kernel's HID function: a keyboard, a mouse, a game controller, any device a HID report descriptor describes. A program writes its reports to the instance's device file.

pad = %{report_desc: File.read!("pad.bin"), report_length: 4}
Kuroneko.Gadget.configure([{Kuroneko.Gadget.HID, name: "pad", descriptor: pad}])
{:ok, path} = Kuroneko.Gadget.HID.device(name: "pad")

The :keyboard, :mouse and :relative_mouse of Kuroneko.Gadget are instances with the descriptors of descriptor/1, which Kuroneko.Gadget.Input drives.

Options

  • :descriptor - a map with the :report_desc, the :report_length of the longest input report, and the boot :protocol and :subclass: 1 and 1 for a keyboard, 2 and 1 for a mouse, 0 and 0 by default. Or a descriptor of descriptor/1, by its name.

Summary

Types

The built-in descriptors: a boot keyboard, the absolute pointer as a mouse, a pen (for Android and iPadOS) or a touch screen, and a relative boot mouse.

Functions

The name of a built-in descriptor, nil for another one.

A built-in descriptor.

The device file of an instance, such as "/dev/hidg0": the one :name names, "hid" by default. Takes the :gadget option.

Types

builtin()

@type builtin() :: :keyboard | :mouse | :stylus | :touch | :relative_mouse

The built-in descriptors: a boot keyboard, the absolute pointer as a mouse, a pen (for Android and iPadOS) or a touch screen, and a relative boot mouse.

descriptor()

@type descriptor() :: %{
  report_desc: binary(),
  report_length: pos_integer(),
  protocol: 0..2,
  subclass: 0..1
}

Functions

builtin(descriptor)

@spec builtin(descriptor()) :: builtin() | nil

The name of a built-in descriptor, nil for another one.

descriptor(name)

@spec descriptor(builtin()) :: descriptor()

A built-in descriptor.

device(opts \\ [])

@spec device(keyword()) ::
  {:ok, Path.t()} | {:error, Kuroneko.Gadget.configfs_error()}

The device file of an instance, such as "/dev/hidg0": the one :name names, "hid" by default. Takes the :gadget option.