增加 mouse 和 touch b 示例.

Signed-off-by: rick.chan <chenyang@autoai.com>
This commit is contained in:
rick.chan 2020-12-16 16:09:04 +08:00
parent a96875806b
commit 5defad990d
4 changed files with 102 additions and 3 deletions

View File

@ -50,10 +50,10 @@ static const struct spi_device_id demo_id_table[] = {
}; };
MODULE_DEVICE_TABLE(spi, 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 = { .driver = {
.name = "demo_spi", .name = "demo_spi",
.of_match_table = demo_of_match, .of_match_table = of_match_ptr(demo_of_match),
}, },
.id_table = demo_id_table, .id_table = demo_id_table,
.probe = demo_spi_probe, .probe = demo_spi_probe,

View File

@ -0,0 +1,39 @@
#include <linux/input.h>
#include <linux/module.h>
#include <linux/init.h>
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 <cy187lion@sina.com>");
MODULE_DESCRIPTION("Mouse driver demo");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0");

View File

@ -33,7 +33,7 @@ module_init(demo_touch_a_init);
module_exit(demo_touch_a_exit); module_exit(demo_touch_a_exit);
MODULE_AUTHOR("Rick Chan <cy187lion@sina.com>"); MODULE_AUTHOR("Rick Chan <cy187lion@sina.com>");
MODULE_DESCRIPTION("Touch driver demo"); MODULE_DESCRIPTION("Touch A driver demo");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0"); MODULE_VERSION("1.0.0");

View File

@ -0,0 +1,60 @@
#include <linux/input.h>
#include <linux/module.h>
#include <linux/init.h>
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 <cy187lion@sina.com>");
MODULE_DESCRIPTION("Touch B driver demo");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0");