/*
*
*
*文件名称 : my_i2c_dri.c
*
*功能 : i2c 驱动端
*
*时间 : 2017年1月3日16:27:07
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <mach/gpio.h>
#include <plat/gpio-cfg.h>
#include <plat/ctouch.h>
#include <plat/ft5x0x_touch.h>
#include <linux/timer.h>
typedef struct touchScreens {
u32 points;
u32 x;
u32 y;
u8 pressure;
}T_touchScreens,*PT_touchScreens;
T_touchScreens touchData;
//static struct timer_list timerlist;
static struct i2c_client *clt = NULL;
static struct input_dev *xyd_idev = NULL;
static struct work_struct xyd_work;
static DEFINE_SEMAPHORE(sem);
static void test_to_user(struct i2c_client *client){
s32 ret;
ret = i2c_smbus_read_byte_data(client, 0xa6);
printk("<0>Firmware ID = %d",ret);
ret = i2c_smbus_read_byte_data(client, 0xa8);
printk("<0>CTPM Vendor ID = %d",ret);
i2c_smbus_write_byte_data(client,0xa5,0);
ret = i2c_smbus_read_byte_data(client, 0xa5);
printk("<0>Power Consume Mode = %d",ret);
/*int set = 0xa6;
i2c_master_send(client, (char *)&set, 1);
i2c_master_recv(client, (char *)&set, 1);
printk("<0>ID = %d ",set);
*/
}
static void work_hendler(struct work_struct *arg){
s32 ret;
u8 buf[1024]= {0};
down_interruptible(&sem);
ret = i2c_smbus_read_i2c_block_data(clt,0x00,7,buf);
if(ret == 0){
printk("<0>read is failed \r\n");
}
if((buf[2]&0x0f) == 0){
// printk("-----------------\n");
input_report_abs(xyd_idev, ABS_PRESSURE, 0);
input_report_key(xyd_idev, BTN_TOUCH, 0);
input_sync(xyd_idev);
}
if((buf[2]&0x0f) == 1){
u16 x = (u16)(((buf[3]&0x0f) << 8) | buf[4]);
u16 y = (u16)(((buf[5]&0x0f) << 8) | buf[6]);
touchData.x = x;
touchData.y = y;
touchData.pressure = 1;
input_report_abs(xyd_idev, ABS_X, touchData.x);
input_report_abs(xyd_idev, ABS_Y, touchData.y);
input_report_abs(xyd_idev, ABS_PRESSURE, touchData.pressure);
input_report_key(xyd_idev, BTN_TOUCH, 1);
input_sync(xyd_idev);
}
up(&sem);
}
//static void timer_handler(unsigned long data){
// schedule_work(&xyd_work);
//}
static irqreturn_t xyd_irq_handler(int argc, void *argv){
// mod_timer(&timerlist,jiffies + msecs_to_jiffies(5));
schedule_work(&xyd_work);
return IRQ_HANDLED;
}
static int xyd_probe(struct i2c_client *xyd_client, const struct i2c_device_id *id){
clt = xyd_client;
xyd_idev = input_allocate_device();
__set_bit(EV_ABS, xyd_idev->evbit);
__set_bit(ABS_X, xyd_idev->absbit);
__set_bit(ABS_Y, xyd_idev->absbit);
__set_bit(ABS_PRESSURE, xyd_idev->absbit);
__set_bit(EV_SYN, xyd_idev->evbit);
__set_bit(EV_KEY, xyd_idev->evbit);
__set_bit(BTN_TOUCH, xyd_idev->keybit);
input_set_abs_params(xyd_idev, ABS_X, 0, 799, 0, 0);
input_set_abs_params(xyd_idev, ABS_Y, 0, 479, 0, 0);
input_set_abs_params(xyd_idev, ABS_PRESSURE, 0, 1 ,0, 0);
input_register_device(xyd_idev);
test_to_user(clt);
INIT_WORK(&xyd_work,work_hendler);
request_irq(IRQ_EINT(14),xyd_irq_handler,IRQF_TRIGGER_FALLING,"xyd_i2c",&touchData);
//init_timer(&timerlist);
//setup_timer(&timerlist,&timer_handler,(unsigned long)0);
return 0;
}
static int xyd_remove(struct i2c_client *xyd_client){
printk("<0>xyd_remove !!!!!!\r\n");
free_irq(IRQ_EINT(14),&touchData);
input_unregister_device(xyd_idev);
return 0;
}
static const struct i2c_device_id xyd_id[] = {
{ "xydI2c", 0 },
};
static struct i2c_driver xyd_driver = {
.driver = {
.name = "xydI2c",
},
.probe = xyd_probe,
.remove =xyd_remove,
.id_table = xyd_id,
};
static int __init xyd_i2c_driInit(void){
i2c_add_driver(&xyd_driver);
return 0;
}
static void __exit xyd_i2c_driExit(void){
i2c_del_driver(&xyd_driver);
}
module_init(xyd_i2c_driInit);
module_exit(xyd_i2c_driExit);
MODULE_LICENSE("GPL");
linux-i2c.zip_LINUX iic 驱动_TINY4412_i2c子系统_linux3.5的IIC子系统模型_tin
版权申诉
197 浏览量
2022-09-14
23:43:58
上传
评论
收藏 2KB ZIP 举报
weixin_42651887
- 粉丝: 75
- 资源: 1万+
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0