-
Notifications
You must be signed in to change notification settings - Fork 40
Skel2hid #255
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
Draft
qrsikno2
wants to merge
7
commits into
luainkernel:master
Choose a base branch
from
qrsikno2:skel2hid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Skel2hid #255
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5e7b7f5
feat(draft): start up from a skel
qrsikno2 05c86ac
start from a skel
qrsikno2 21d65f2
inital version
qrsikno2 2e0840a
bug(hid): fix module problem
qrsikno2 d3f229f
refractor(headers): move lunatik_setstring from lib/luanetfilter.h to…
qrsikno2 a6c2fc0
bug(lunatik): add module name in lunatik script
qrsikno2 3a73034
style(luahid): fix C++ comment style
qrsikno2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: (c) 2025 Jieming Zhou <[email protected]> | ||
| * SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
| */ | ||
|
|
||
| #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| #include <linux/kernel.h> | ||
| #include <linux/module.h> | ||
| #include <linux/version.h> | ||
| #include <linux/slab.h> | ||
| #include <linux/limits.h> | ||
| #include <asm/byteorder.h> | ||
|
|
||
| #include <linux/hid.h> | ||
|
|
||
| #include <lua.h> | ||
| #include <lualib.h> | ||
| #include <lauxlib.h> | ||
|
|
||
| #include <lunatik.h> | ||
|
|
||
| typedef struct luahid_s { | ||
| lunatik_object_t *runtime; | ||
| struct hid_driver driver; | ||
| } luahid_t; | ||
|
|
||
| /* | ||
| * kernel codes copied from drivers/hid/hid-generic.c | ||
| * links: https://elixir.bootlin.com/linux/v6.13.7/source/drivers/hid/hid-generic.c | ||
| */ | ||
| static int hid_generic_probe(struct hid_device *hdev, | ||
| const struct hid_device_id *id) | ||
| { | ||
| int ret; | ||
|
|
||
| hdev->quirks |= HID_QUIRK_INPUT_PER_APP; | ||
|
|
||
| ret = hid_parse(hdev); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| return hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
| } | ||
| static const struct hid_device_id hid_table[] = { | ||
| { HID_USB_DEVICE(0x046D, 0xC542) }, | ||
| { } | ||
| }; | ||
| MODULE_DEVICE_TABLE(hid, hid_table); | ||
|
|
||
|
|
||
| static void luahid_release(void *private) | ||
| { | ||
| luahid_t *hid = (luahid_t *)private; | ||
| if (hid) { | ||
| hid_unregister_driver(&hid->driver); | ||
| lunatik_putobject(hid->runtime); | ||
| } | ||
| } | ||
|
|
||
| static int luahid_register(lua_State *L); | ||
|
|
||
| static const luaL_Reg luahid_lib[] = { | ||
| {"register", luahid_register}, | ||
| {NULL, NULL} | ||
| }; | ||
|
|
||
| static const luaL_Reg luahid_mt[] = { | ||
| {"__gc", lunatik_deleteobject}, | ||
| {NULL, NULL} | ||
| }; | ||
|
|
||
| static const lunatik_class_t luahid_class = { | ||
| .name = "hid", | ||
| .methods = luahid_mt, | ||
| .release = luahid_release, | ||
| .sleep = true, | ||
| }; | ||
|
|
||
| static int luahid_register(lua_State *L) | ||
| { | ||
| luaL_checktype(L, 1, LUA_TTABLE); /* assure that is a driver */ | ||
|
|
||
| lunatik_object_t *object = lunatik_newobject(L, &luahid_class, sizeof(luahid_t)); | ||
| luahid_t *hid = (luahid_t *)object->private; | ||
|
|
||
| /* | ||
| * configure the driver's properties & callbacks | ||
| */ | ||
| struct hid_driver *user_driver = &(hid->driver); | ||
| user_driver -> name = lunatik_checkalloc(L, NAME_MAX); | ||
| lunatik_setstring(L, 1, user_driver, name, NAME_MAX); | ||
| user_driver -> id_table = hid_table; | ||
| user_driver -> probe = hid_generic_probe; | ||
|
|
||
| lunatik_registerobject(L, 1, object); | ||
|
|
||
| int ret = __hid_register_driver(user_driver, THIS_MODULE, KBUILD_MODNAME); | ||
| if (ret) { | ||
| lunatik_unregisterobject(L, object); | ||
| luaL_error(L, "failed to register hid driver: %s", user_driver->name); | ||
| } | ||
| lunatik_setruntime(L, hid, hid); | ||
| lunatik_getobject(hid->runtime); | ||
| return 1; /* object */ | ||
| } | ||
|
|
||
| LUNATIK_NEWLIB(hid, luahid_lib, &luahid_class, NULL); | ||
|
|
||
| static int __init luahid_init(void) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static void __exit luahid_exit(void) | ||
| { | ||
| } | ||
|
|
||
| module_init(luahid_init); | ||
| module_exit(luahid_exit); | ||
| MODULE_LICENSE("Dual MIT/GPL"); | ||
| MODULE_AUTHOR("Jieming Zhou <[email protected]>"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mind our code style.. when in doubt, use Linux's code style.. no space around ->