From 5defad990dfd08ece013b677e8fc68e9144ddfc1 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Wed, 16 Dec 2020 16:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20mouse=20=E5=92=8C=20touch?= =?UTF-8?q?=20b=20=E7=A4=BA=E4=BE=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- Linux/KernelDriver/4.14/SPI/demo_spi.c | 4 +- Linux/KernelDriver/4.19/Input/demo_mouse.c | 39 +++++++++++++ Linux/KernelDriver/4.19/Input/demo_touch_a.c | 2 +- Linux/KernelDriver/4.19/Input/demo_touch_b.c | 60 ++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 Linux/KernelDriver/4.19/Input/demo_mouse.c create mode 100644 Linux/KernelDriver/4.19/Input/demo_touch_b.c diff --git a/Linux/KernelDriver/4.14/SPI/demo_spi.c b/Linux/KernelDriver/4.14/SPI/demo_spi.c index ce744a8..b907dbf 100644 --- a/Linux/KernelDriver/4.14/SPI/demo_spi.c +++ b/Linux/KernelDriver/4.14/SPI/demo_spi.c @@ -50,10 +50,10 @@ static const struct spi_device_id demo_id_table[] = { }; MODULE_DEVICE_TABLE(spi, demo_id_table); -static struct spi_driver demo_spi_driver = { +static const struct spi_driver demo_spi_driver = { .driver = { .name = "demo_spi", - .of_match_table = demo_of_match, + .of_match_table = of_match_ptr(demo_of_match), }, .id_table = demo_id_table, .probe = demo_spi_probe, diff --git a/Linux/KernelDriver/4.19/Input/demo_mouse.c b/Linux/KernelDriver/4.19/Input/demo_mouse.c new file mode 100644 index 0000000..89a6194 --- /dev/null +++ b/Linux/KernelDriver/4.19/Input/demo_mouse.c @@ -0,0 +1,39 @@ +#include +#include +#include + +struct input_dev *demo_mouse; + +static int __init demo_mouse_init(void) +{ + int ret; + demo_mouse = input_allocate_device(); + + demo_mouse->name = "Demo Mouse"; + demo_mouse->id.bustype = BUS_RS232; + + demo_mouse->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); + demo_mouse->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | + BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE); + demo_mouse->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); + demo_mouse->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) | + BIT_MASK(BTN_EXTRA); + demo_mouse->relbit[0] |= BIT_MASK(REL_WHEEL); + + ret = input_register_device(demo_mouse); + return ret; +} + +static void __exit demo_mouse_exit(void) +{ + input_unregister_device(demo_mouse); +} + +module_init(demo_mouse_init); +module_exit(demo_mouse_exit); + +MODULE_AUTHOR("Rick Chan "); +MODULE_DESCRIPTION("Mouse driver demo"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("1.0.0"); + diff --git a/Linux/KernelDriver/4.19/Input/demo_touch_a.c b/Linux/KernelDriver/4.19/Input/demo_touch_a.c index 9fbf81c..917c2da 100644 --- a/Linux/KernelDriver/4.19/Input/demo_touch_a.c +++ b/Linux/KernelDriver/4.19/Input/demo_touch_a.c @@ -33,7 +33,7 @@ module_init(demo_touch_a_init); module_exit(demo_touch_a_exit); MODULE_AUTHOR("Rick Chan "); -MODULE_DESCRIPTION("Touch driver demo"); +MODULE_DESCRIPTION("Touch A driver demo"); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0.0"); diff --git a/Linux/KernelDriver/4.19/Input/demo_touch_b.c b/Linux/KernelDriver/4.19/Input/demo_touch_b.c new file mode 100644 index 0000000..8d728e4 --- /dev/null +++ b/Linux/KernelDriver/4.19/Input/demo_touch_b.c @@ -0,0 +1,60 @@ +#include +#include +#include + +struct input_dev *demo_touch_b; + +void demo_touch_b_report_press(int id, int x, int y) +{ + input_mt_slot(demo_touch_b, id); + + input_mt_report_slot_state(demo_touch_b, MT_TOOL_FINGER, 1); + input_report_abs(demo_touch_b, ABS_MT_POSITION_X, x); + input_report_abs(demo_touch_b, ABS_MT_POSITION_Y, y); + input_report_key(demo_touch_b, BTN_TOUCH, 1); +} + +void demo_touch_b_report_release(int id) +{ + input_mt_slot(demo_touch_b, id); + input_report_key(demo_touch_b, BTN_TOUCH, 0); + input_mt_report_slot_state(demo_touch_b, MT_TOOL_FINGER, 0); +} + +void demo_touch_b_sync(void) +{ + input_mt_sync_frame(demo_touch_b); + input_sync(demo_touch_b); +} + +static int __init demo_touch_b_init(void) +{ + int ret; + demo_touch_b = input_allocate_device(); + + demo_touch_b->name = "Demo Touch B"; + demo_touch_b->id.bustype = BUS_USB; + + input_set_capability(demo_touch_b, EV_KEY, BTN_TOUCH); + input_set_abs_params(demo_touch_b, ABS_MT_POSITION_X, 0, 0xfff, 0, 0); + input_set_abs_params(demo_touch_b, ABS_MT_POSITION_Y, 0, 0xfff, 0, 0); + input_set_abs_params(demo_touch_b, ABS_MT_TRACKING_ID, 0, 255, 0, 0); + input_mt_init_slots(demo_touch_b, 5, INPUT_MT_DIRECT|INPUT_MT_DROP_UNUSED); + + ret = input_register_device(demo_touch_b); + return ret; +} + +static void __exit demo_touch_b_exit(void) +{ + input_unregister_device(demo_touch_b); +} + +module_init(demo_touch_b_init); +module_exit(demo_touch_b_exit); + +MODULE_AUTHOR("Rick Chan "); +MODULE_DESCRIPTION("Touch B driver demo"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("1.0.0"); +