当前位置:网站首页>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 ;
边栏推荐
- 抽絲剝繭C語言(高階)數據的儲存+練習
- How do I get the last part of a string- How to get the last part of a string?
- 面试结束后,被面试官在朋友圈吐槽了......
- 計算機服務中缺失MySQL服務
- My ideal software tester development status
- Blue Bridge Cup Birthday candles (violence)
- 按键精灵采集学习-矿药采集及跑图
- 二、并发、测试笔记 青训营笔记
- 抽丝剥茧C语言(高阶)指针进阶练习
- Leetcode-226. Invert Binary Tree
猜你喜欢
English translation is too difficult? I wrote two translation scripts with crawler in a rage
"Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr
About binary cannot express decimals accurately
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Sqlmap tutorial (IV) practical skills three: bypass the firewall
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
URP - shaders and materials - simple lit
2022-07-06:以下go语言代码是否会panic?A:会;B:不会。 package main import “C“ func main() { var ch chan struct
[2022 CISCN]初赛 web题目复现
今日现货白银操作建议
随机推荐
Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.9 introduction to network interface (IX) extending the request3 met
Le Service MySQL manque dans le service informatique
测试周期被压缩?教你9个方法去应对
抽丝剥茧C语言(高阶)数据的储存+练习
Example of Pushlet using handle of Pushlet
按键精灵采集学习-矿药采集及跑图
My ideal software tester development status
Determining the full type of a variable
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
gslx680触摸屏驱动源码码分析(gslX680.c)
MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding
Leetcode-206. Reverse Linked List
Robot technology innovation and practice old version outline
IO流 file
Several important steps to light up the display
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
1141_ SiCp learning notes_ Functions abstracted as black boxes
外包干了四年,废了...
vus.SSR在asynData函数中请求数据的注意事项
【leetcode】1020. Number of enclaves