device tree在触屏中的实际应用

来源:互联网 发布:小猪微信分销系统源码 编辑:程序博客网 时间:2024/06/05 12:03
/*首先是在dtsi中定义一些和设备(触屏)相关的重要变量。定义这些个变量的目的就是在不同项目中,去读取与该项目对应的dtsi文件,对于触屏,提高了代码的兼容性,使内核代码更清晰明了。*//*首先看一下dtsi文件里写了什么。*//* ty-focaltech-ft6206.dtsi */&soc {i2c@78b9000 { /* BLSP1 QUP5 */focaltech@38 {};};gen-vkeys {compatible = "qcom,gen-vkeys";label = "ft5x06_ts";qcom,disp-maxx = <480>;qcom,disp-maxy = <854>;qcom,panel-maxx = <480>;qcom,panel-maxy = <946>;qcom,key-codes = <158 172 139>;qcom,y-offset = <0>;qcom,key-menu-coords = <120 900 30 30>;qcom,key-home-coords = <240 900 30 30>;qcom,key-back-coords = <360 900 30 30>;qcom,key-search-coords = <0 0 0 0>;};};处于方便的目的吧,通过of_find_property()函数,获取dtsi文件中的内容。dtsi文件中,等号左边是为了便于搜索,右边是真正的数值。了解了框架,下面在具体看一下of_find_property()函数执行的过程。读取dtsi中数据前,我们先建立一个数组:struct vkeys_platform_data {const char *name;int disp_maxx;int disp_maxy;int panel_maxx;int panel_maxy;int *keycodes;int num_keys;int y_offset;int y_center;int *x_center;int v_width;int v_height;};1. 读取字符串例如:label = "ft5x06_ts";char *name;rc = of_property_read_string(np, "label", &pdata->name);if (rc) {dev_err(dev, "Failed to read label\n");return -EINVAL;}snprintf(name, MAX_BUF_SIZE,"virtualkeys.%s", pdata->name);name指针就指向virtualkeys.ft5x06_ts了!这里面主要利用of_property_read_string()这个API!2. 读取单个数值例如:qcom,y-offset = <0>;rc = of_property_read_u32(np, "qcom,y-offset", &val);if (!rc)pdata->y_offset = val;else if (rc != -EINVAL) {dev_err(dev, "Failed to read y position offset\n");return rc;}//这个也很简单3. 读取数组:prop = of_find_property(np, "qcom,key-codes", NULL);if (prop) {pdata->num_keys = prop->length / sizeof(u32);pdata->keycodes = devm_kzalloc(dev,sizeof(u32) * pdata->num_keys, GFP_KERNEL);if (!pdata->keycodes)return -ENOMEM;rc = of_property_read_u32_array(np, "qcom,key-codes",pdata->keycodes, pdata->num_keys);if (rc) {dev_err(dev, "Failed to read key codes\n");return -EINVAL;}}这一步主要集中在rc = of_property_read_u32_array(np, "qcom,key-codes",pdata->keycodes, pdata->num_keys);结束后,数据存储在指针pdata->keycodes中, pdata->num_keys为数组中数据个数!---------------------------------------------------------------------------OK!

0 0
原创粉丝点击