当前位置:网站首页>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 ;
边栏推荐
- Tianqing sends instructions to bypass the secondary verification
- Outlier detection technology of time series data
- Bi she - college student part-time platform system based on SSM
- 海思芯片(hi3516dv300)uboot镜像生成过程详解
- 面试结束后,被面试官在朋友圈吐槽了......
- MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding
- 1、 Go knowledge check and remedy + practical course notes youth training camp notes
- [ANSYS] learning experience of APDL finite element analysis
- idea添加类注释模板和方法模板
- 在线直播系统源码,使用ValueAnimator实现view放大缩小动画效果
猜你喜欢

Mutual conversion between InputStream, int, shot, long and byte arrays

C language (high-level) data storage + Practice

At the age of 20, I got the ByteDance offer on four sides, and I still can't believe it

L'étape avancée du pointeur de langage C (haut de gamme) pour l'enroulement des cocons

ROS2规划系统plansys2简单的例子

UWB learning 1

IO流 file

After 95, Alibaba P7 published the payroll: it's really fragrant to make up this

毕设-基于SSM大学生兼职平台系统

抽丝剥茧C语言(高阶)指针的进阶
随机推荐
外包干了三年,废了...
Example of Pushlet using handle of Pushlet
The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
为什么要了解现货黄金走势?
1、 Go knowledge check and remedy + practical course notes youth training camp notes
JS get all date or time stamps between two time stamps
Jenkins远程构建项目超时的问题
Make a bat file for cleaning system garbage
Interviewer: what development models do you know?
MySQL service is missing from computer service
JS small exercise ---- time sharing reminder and greeting, form password display hidden effect, text box focus event, closing advertisement
Invalid table alias or column reference`xxx`
1142_ SiCp learning notes_ Functions and processes created by functions_ Linear recursion and iteration
微信小程序中使用wx.showToast()进行界面交互
How do I get the last part of a string- How to get the last part of a string?
Calculus key and difficult points record part integral + trigonometric function integral
"Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr
微信小程序中的路由跳转
Lm11 reconstruction of K-line and construction of timing trading strategy
解决:Could NOT find KF5 (missing: CoreAddons DBusAddons DocTools XmlGui)