Skip to content

[GSoC 2025] Basic APIs for luahid #249

@qrsikno2

Description

@qrsikno2

For luahid, as i mentioned in my design, I list the following APIs for my "class":

  • name for driver's name
  • match_list for matching the fixed device in bus(es). it is a table and must cantains the vendor_id and product_id.
  • match: a function for dynamic matching devices, like
-- other codes
match = function(device)  
    return device.vendor == 0x0111
end
  • report_descriptor, a tables contains several byted number, like
report_descriptor = {
0x05, 0x01, 0x09, 0x01, 0xa1, 0x01,
0x05, 0x09, 0x19, 0x01, 0x29, 0x08,
-- ... etc
}` 
  • init(device): a function to initialize the driver.
  • on_event: a table to process diffierent types of event, like:
on_event = {
  key = {
    [hid.input.KEY.A] = function(value)
      print("unsupported A, filtered", value)
      return true
    end,
    [hid.input.KEY.B] = function(value)
      print("Key B occured:", value)
      return false
    end,
    default = function(key, value)
      print("unknown key, filtered", key.name, value)
      return true
    end
  },
-- there is no ABS.Z in the example,
-- so the default event handler of it will be used.
-- you can also redefine the default event handler.
  abs = {
    [hid.input.ABS.X] = function(value)
      print("position X:", value)
      return true
    end,
    [hid.input.ABS.Y] = function(value)
      print("position Y:", value)
      return true
    end
  },
  raw = function(data)
    if data[1] == 0x01 then
      print("find a special data:", data[2])
      return true
    end
    return false
  end
}

This is my inital design(given in examples) of on_event, but it is a little bit difficult to implement & process the hole on_event in C.
But names likeon_event_raw, on_event_key are lack of extensibility.

  • input_mapping: a function to process data "before" submit to Linux input subsys.
  • input_mapped: a function to process data "after" submit to Linux input subsys.
    the two above may use the submodule luahid.input, but it is optional to use or not.

and the class is loaded by an API register in luahid and the other API funcs send_report is used to operate the device if you want.

feel free to discuss, thanks. =)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions