当前位置:网站首页>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 ;
边栏推荐
- Kuboard can't send email and nail alarm problem is solved
- Project practice five fitting straight lines to obtain the center line
- 按键精灵脚本学习-关于天猫抢红包
- vus. Precautions for SSR requesting data in asyndata function
- 【云原生】内存数据库如何发挥内存优势
- Detailed explanation of neo4j installation process
- My ideal software tester development status
- 按键精灵采集学习-矿药采集及跑图
- 1090: integer power (multi instance test)
- How do I get the last part of a string- How to get the last part of a string?
猜你喜欢
Example of Pushlet using handle of Pushlet
抽丝剥茧C语言(高阶)指针进阶练习
JSON introduction and JS parsing JSON
About binary cannot express decimals accurately
Mutual conversion between InputStream, int, shot, long and byte arrays
Outsourcing for three years, abandoned
Jenkins远程构建项目超时的问题
A concurrent rule verification implementation
ROS2规划系统plansys2简单的例子
Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.10 tabbar component (I) how to open and use the default tabbar comp
随机推荐
Stockage et pratique des données en langage C (haut niveau)
How can a 35 year old programmer build a technological moat?
[cloud native] how to give full play to memory advantage of memory database
BGP experiment (1)
English translation is too difficult? I wrote two translation scripts with crawler in a rage
Leetcode-543. Diameter of Binary Tree
Software acceptance test
Fullgc problem analysis and solution summary
按键精灵脚本学习-关于天猫抢红包
My ideal software tester development status
The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
vus.SSR在asynData函数中请求数据的注意事项
Mobx knowledge point collection case (quick start)
Procedure in PostgreSQL supports transaction syntax (instance & Analysis)
微信小程序中使用wx.showToast()进行界面交互
【云原生】内存数据库如何发挥内存优势
mips uclibc 交叉编译ffmpeg,支持 G711A 编解码
Blue Bridge Cup Netizen age (violence)
1090: integer power (multi instance test)
海思芯片(hi3516dv300)uboot镜像生成过程详解