当前位置:网站首页>Gslx680 touch screen driver source code analysis (gslx680. C)
Gslx680 touch screen driver source code analysis (gslx680. C)
2022-07-07 07:39:00 【Snail taking off】
1、 Overall analysis of touch screen code
(1)gslx680 The touch screen is I2C Interface device , So the driver code uses I2C Interface provided by subsystem , use I2C Provided by the core layer I2C The driver registration interface will be built I2C Drive the structure to I2C Subsystem registration ;】
(2) Registered touch screen I2C The driver will be in I2C On the bus and corresponding I2C Device matching , To call I2C Driven probe Method ;
(3)I2C The subsystem is in the whole touch screen driver code , Just responsible for I2C Equipment and master control Soc Communication for , The whole touch screen code also involves input The subsystem is used to report the touch time to the upper application , The interrupt subsystem is used to process the interrupt of the touch screen ;
2、 Touch screen driver registration function
static struct i2c_driver gsl_ts_driver = {
.driver = {
.name = GSLX680_I2C_NAME,
.owner = THIS_MODULE,
},
#ifndef CONFIG_HAS_EARLYSUSPEND
.suspend = gsl_ts_suspend,
.resume = gsl_ts_resume,
#endif
.probe = gsl_ts_probe,
.remove = __devexit_p(gsl_ts_remove),
.id_table = gsl_ts_id,
};
static int __init gsl_ts_init(void)
{
int ret;
print_info("==gsl_ts_init==\n");
ret = i2c_add_driver(&gsl_ts_driver);
print_info("ret=%d\n",ret);
return ret;
}
The function of the registration function is to I2C The subsystem is registered with the name gsl_ts_driver Of I2C drive ;
3、 Touch screen driven probe function
// stay gslx680 Touch screen driver is used to describe I2C Driven structure
struct gsl_ts {
struct i2c_client *client;
struct input_dev *input;
struct work_struct work;
struct workqueue_struct *wq;
struct gsl_ts_data *dd;
u8 *touch_data;
u8 device_id;
int irq;
#if defined(CONFIG_HAS_EARLYSUSPEND)
struct early_suspend early_suspend;
#endif
};
static int __devinit gsl_ts_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct gsl_ts *ts;
int rc;
······
// Check whether the adapter supports the standard I2C Communication protocol
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev, "I2C functionality not supported\n");
return -ENODEV;
}
ts = kzalloc(sizeof(*ts), GFP_KERNEL);
if (!ts)
return -ENOMEM;
print_info("==kzalloc success=\n");
// take client Save to ts In the structure
ts->client = client;
// hold ts Save to client->dev Private data for
i2c_set_clientdata(client, ts);
ts->device_id = id->driver_data;
// register input Subsystem , Initialize work queue , Bind the lower half of the touch screen interrupt
rc = gslX680_ts_init(client, ts);
if (rc < 0) {
dev_err(&client->dev, "GSLX680 init failed\n");
goto error_mutex_destroy;
}
gsl_client = client;
// Set touch screen related GPIO Pin
gslX680_init();
// Initialize by reading and writing the registers related to the touch screen chip
init_chip(ts->client);
check_mem_data(ts->client);
// Apply for interrupt number and bind interrupt handler
rc= request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING, client->name, ts);
if (rc < 0) {
print_info( "gsl_probe: request irq failed\n");
goto error_req_irq_fail;
}
······
}
(1) towards I2C Core layer registered I2C The touch screen driver will eventually be I2C Match on the bus I2C equipment , That is to say struct i2c_client Structure ;
(2)I2C The bus will call I2C Driven probe Method , Match it struct i2c_client The structure is passed in ;
(3)probe Function will complete the initialization , These include input Subsystem registration , Interrupt the registration of the program ;
4、 Interrupt handling function
static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
{
struct gsl_ts *ts = dev_id;
print_info("========gslX680 Interrupt=========\n");
// No interruptions
disable_irq_nosync(ts->irq);
// Detect whether the work queue to which the lower half of the interrupt belongs is suspended , If suspended, add the lower half of the interrupt to the queue for scheduling
// Call the lower half of the interrupt function , That is to say gslX680_ts_worker()
if (!work_pending(&ts->work))
{
queue_work(ts->wq, &ts->work);
}
return IRQ_HANDLED;
}
(1)gsl_ts_irq() Function is only the upper half of the interrupt handler , The actual function is to prohibit interruption , Then call the lower half of the interrupt ;
(2)gslX680_ts_worker() Is the bottom half of the interruption , stay gslX680_ts_init() Function ;
Add : Reference blog :《 The top half and bottom half of the interrupt are introduced and the implementation method (tasklet and Work queue )》;
5、 The logic of the whole touch screen driver code
gsl_ts_irq() // Break the top half
gslX680_ts_worker() // Break the bottom half
gsl_ts_write() // Touch screen driven write data
i2c_master_send() // The actual call I2C The data interface of the core layer
gsl_ts_read() // Touch screen driven data reading
i2c_master_recv() // The actual call I2C Data receiving interface of core layer
report_data() // Report data
input_report_abs() // The actual call input Reporting interface of subsystem
(1) When a touch event occurs on the touch screen , The interrupt handler that triggers the binding gsl_ts_irq();
(2)gsl_ts_irq() Is to interrupt the upper half , Disable the interrupt and then call the lower half of the interrupt gslX680_ts_worker();
(3)gslX680_ts_worker() The function passes through I2C The subsystem provides I2C Bus transceiver data interface function , Read and write the relevant registers of the touch screen chip ;
(4)gslX680_ts_worker() The function calculates and converts the data read from the touch screen chip , Then fill in the input event structure , According to the previously registered input Subsystem , Press input The input events of the subsystem are reported to the application layer ;
边栏推荐
- Model application of time series analysis - stock price prediction
- Music | cat and mouse -- classic not only plot
- 我理想的软件测试人员发展状态
- 二、并发、测试笔记 青训营笔记
- vus.SSR在asynData函数中请求数据的注意事项
- Outsourcing for three years, abandoned
- C language (high-level) data storage + Practice
- What is the difference between TCP and UDP?
- English translation is too difficult? I wrote two translation scripts with crawler in a rage
- leetcode:105. 从前序与中序遍历序列构造二叉树
猜你喜欢
Fast quantitative, abbkine protein quantitative kit BCA method is coming!
【leetcode】1020. Number of enclaves
English translation is too difficult? I wrote two translation scripts with crawler in a rage
二、并发、测试笔记 青训营笔记
leetcode:105. 从前序与中序遍历序列构造二叉树
MySQL service is missing from computer service
L'externalisation a duré trois ans.
idea添加类注释模板和方法模板
[Linux] process control and parent-child processes
测试周期被压缩?教你9个方法去应对
随机推荐
Initial experience of teambiion network disk (Alibaba cloud network disk)
毕设-基于SSM大学生兼职平台系统
I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over
gslx680触摸屏驱动源码码分析(gslX680.c)
Bindingexception exception (error reporting) processing
idea添加类注释模板和方法模板
JS decorator @decorator learning notes
JSON introduction and JS parsing JSON
外包干了四年,废了...
深度学习花书+机器学习西瓜书电子版我找到了
外包幹了三年,廢了...
Tumor immunotherapy research prosci Lag3 antibody solution
A concurrent rule verification implementation
Fast quantitative, abbkine protein quantitative kit BCA method is coming!
Sqlmap tutorial (IV) practical skills three: bypass the firewall
测试周期被压缩?教你9个方法去应对
【性能压测】如何做好性能压测?
[Linux] process control and parent-child processes
@component(““)
Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs