一个tp小程序

#include <linux/delay.h>

#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/semaphore.h>
#include <linux/mutex.h>
#include <linux/syscalls.h>
#include <asm/unistd.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
#include <linux/i2c.h>
#include <linux/input.h>


struct input_dev *input_dev;


static ssize_t X_store(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
char * nouse;
if(input_dev){
input_report_abs(input_dev, ABS_MT_POSITION_X, simple_strtoul(buf,&nouse,0));
printk(KERN_ERR "song_touch: ok\n");
}
return count;
}
static DEVICE_ATTR(X, S_IRUGO|S_IWUSR, NULL, X_store);


static ssize_t Y_store(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
char * nouse;
if(input_dev) {
input_report_abs(input_dev, ABS_MT_POSITION_Y, simple_strtoul(buf,&nouse,0));
printk(KERN_ERR "song_touch: ok\n");
}
return count;
}
static DEVICE_ATTR(Y, S_IRUGO|S_IWUSR, NULL, Y_store);


static ssize_t O_store(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
char * nouse;
if(input_dev) {
input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, simple_strtoul(buf,&nouse,0));
input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 1);
input_report_abs(input_dev, ABS_MT_PRESSURE, simple_strtoul(buf,&nouse,0));
printk(KERN_ERR "song_touch: ok\n");
}
return count;
}
static DEVICE_ATTR(O, S_IRUGO|S_IWUSR, NULL, O_store);


static ssize_t ID_store(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
char * nouse;
if(input_dev) {
input_report_abs(input_dev, ABS_MT_TRACKING_ID, simple_strtoul(buf,&nouse,0));
printk(KERN_ERR "song_touch: ok\n");
}
return count;
}
static DEVICE_ATTR(ID, S_IRUGO|S_IWUSR, NULL, ID_store);


static ssize_t SYNC_store(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
if(input_dev) {
input_sync(input_dev);
// printk(KERN_ERR "song_touch: ok\n");
}
return count;
}
static DEVICE_ATTR(SYNC, S_IRUGO|S_IWUSR, NULL, SYNC_store);


static ssize_t MT_store(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
if(input_dev) {
input_mt_sync(input_dev);
// printk(KERN_ERR "song_touch: ok\n");
}
return count;
}
static DEVICE_ATTR(MT, S_IRUGO|S_IWUSR, NULL, MT_store);


static ssize_t key_press2(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
char * nouse;
if(input_dev) {
input_report_key(input_dev,simple_strtoul(buf,&nouse,0),1);
printk(KERN_ERR "song_touch: ok:%d\n",(int) simple_strtoul(buf,&nouse,0));
}
return count;
}
static DEVICE_ATTR(PRESS, S_IRUGO|S_IWUSR, NULL, key_press2);


static ssize_t key_release2(struct device *dev,
struct device_attribute *attr,
        const char *buf, size_t count)
{
char * nouse;
if(input_dev) {
input_report_key(input_dev,simple_strtoul(buf,&nouse,0),0);
printk(KERN_ERR "song_touch: ok:%d\n", (int) simple_strtoul(buf,&nouse,0));
}
return count;
}
static DEVICE_ATTR(RELEASE, S_IRUGO|S_IWUSR, NULL, key_release2);


static const struct attribute *song_touch_attr[] = {
        &dev_attr_X.attr,
        &dev_attr_Y.attr,
        &dev_attr_O.attr,
        &dev_attr_ID.attr,
        &dev_attr_SYNC.attr,
        &dev_attr_MT.attr,
        &dev_attr_PRESS.attr,
        &dev_attr_RELEASE.attr,
        NULL,
};


static const struct attribute_group song_touch_attr_group = {
        .attrs = (struct attribute **) song_touch_attr,
};


static struct class song_touchscreen_class = {
        .name =         "song_touch",
        .owner =        THIS_MODULE,
};


static int __init song_touch_init(void)
{
int ret = 0;
struct device *dev = NULL;
ret = class_register(&song_touchscreen_class);
if (ret < 0) {
printk(KERN_ERR "song_touch: class_register fail\n");
return ret;
}


dev = device_create(&song_touchscreen_class, NULL, MKDEV(0, 0), NULL, "song_touch");
if (dev) {
ret = sysfs_create_group(&dev->kobj, &song_touch_attr_group);
if(ret < 0) {
printk(KERN_ERR "song_touch:sysfs_create_group fail\r\n");
return ret;
}
} else {
printk(KERN_ERR "song_touch:device_create fail\r\n");
ret = -1;
return ret;
}


input_dev = input_allocate_device();
if (!input_dev) {
printk(KERN_ERR "song_touch:input_allocate_device fail\r\n");
ret = -1;
return ret;
}


input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, 720, 0, 0);
input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 1280, 0, 0);
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 5, 0, 0);
input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
set_bit(EV_ABS, input_dev->evbit);
set_bit(EV_SYN, input_dev->evbit);
set_bit(INPUT_PROP_DIRECT, input_dev->propbit);


set_bit(EV_KEY, input_dev->evbit);
input_set_capability(input_dev, EV_KEY, 158); //back
input_set_capability(input_dev, EV_KEY, 102); //home
input_set_capability(input_dev, EV_KEY, 0x244); //menu


input_dev->name = "song_touch";
ret = input_register_device(input_dev);
if (ret < 0) {
printk(KERN_ERR "song_touch: input_register_device fail\n");
return ret;
}


return 0;
}
module_init(song_touch_init);
MODULE_AUTHOR("<wmzjzwlzs@163.com>");
MODULE_DESCRIPTION("song self TouchScreen driver");
MODULE_LICENSE("GPL");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值