Skip to content

add callback for report_descriptor#302

Merged
lneto merged 3 commits into
luainkernel:hid-stagingfrom
qrsikno2:hid-staging
Aug 8, 2025
Merged

add callback for report_descriptor#302
lneto merged 3 commits into
luainkernel:hid-stagingfrom
qrsikno2:hid-staging

Conversation

@qrsikno2
Copy link
Copy Markdown
Contributor

This pull request introduces enhancements to the HID driver integration in the lib/luahid.c file, including the addition of support for report fixups, a new luadata_t structure, and improved Lua integration for HID device information. These changes aim to extend the functionality of the driver and improve its interaction with Lua scripts.

New functionality for report fixups:

  • Added the luahid_report_fixup function to handle report fixups for HID devices, with support for kernel versions 6.12.0 and above. This function integrates Lua-based processing of HID reports, allowing modifications to the report data.
  • Introduced the luahid_doreport_fixup helper function to manage the Lua interaction for report fixups, including creating and handling luadata_t objects for report data.

New data structure and Lua integration:

  • Defined a new luadata_t structure to encapsulate report data, including a pointer to the data, its size, and additional options.
  • Added the luahid_push_device_info function to populate a Lua table with detailed HID device information, such as vendor, product, and version.

Registration enhancements:

  • Updated the luahid_register function to initialize a _report_des table for storing report descriptors and to assign the new report_fixup callback to the HID driver.

These changes improve the modularity and extensibility of the HID driver, enabling advanced use cases through Lua scripting.

Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luadata.c Outdated
Comment thread lib/luadata.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
@qrsikno2 qrsikno2 marked this pull request as draft July 16, 2025 16:54
@qrsikno2 qrsikno2 force-pushed the hid-staging branch 4 times, most recently from c5ecc77 to 8e22abb Compare July 17, 2025 15:47
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
@qrsikno2 qrsikno2 force-pushed the hid-staging branch 2 times, most recently from a02caeb to 6ee9fad Compare August 5, 2025 16:47
@qrsikno2 qrsikno2 marked this pull request as draft August 5, 2025 16:56
Comment thread lib/luahid.c Outdated
@qrsikno2 qrsikno2 marked this pull request as ready for review August 6, 2025 12:29
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c Outdated
Comment thread lib/luahid.c
Comment thread lib/luahid.c
Comment thread lib/luahid.c
Comment on lines +106 to +124
#define luahid_pcall(L, func, arg) \
do { \
int n = lua_gettop(L); \
lua_pushcfunction(L, func); \
lua_pushlightuserdata(L, (void *)arg); \
if (lua_pcall(L, 1, LUA_MULTRET, 0) != LUA_OK) { \
pr_warn("%s: %s\n", #func, lua_tostring(L, -1)); \
lua_settop(L, n); \
} \
} while (0)

#define luahid_newtable(L, dev, extra) \
do { \
lua_newtable(L); \
luahid_setfield(L, -1, dev, bus); \
luahid_setfield(L, -1, dev, group); \
luahid_setfield(L, -1, dev, vendor); \
luahid_setfield(L, -1, dev, product); \
luahid_setfield(L, -1, dev, extra); \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, fix the tabs

Comment thread lib/luahid.c Outdated
{
if (luahid_checkdriver(L, hid, -1, "_info") || lua_getfield(L, -2, "report_fixup") != LUA_TFUNCTION) {
pr_warn("report_fixup: invaild driver\n");
return 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0;
goto out;

Comment thread lib/luahid.c Outdated
lunatik_object_t *data;
if ((data = luahid_getdescriptor(L, hid)) == NULL) {
pr_warn("report_fixup: descriptor not found\n");
return 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0;
goto out;

Comment thread lib/luahid.c Outdated
pr_warn("report_fixup: %s\n", lua_tostring(L, -1));

luadata_clear(data);
return 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0;
out:
return 0; /* unused */

@lneto lneto merged commit 0b47f07 into luainkernel:hid-staging Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants