• tslib_交叉编译_程序编写


    tslib的交叉编译配置

    在学习linux应用开发的过程中,我对于交叉编译的指令不理解,今天就好好来解释一下每一条指令对应的意义。
    IMX6ULL板子上配置

    在unbuntu上的操作

    1.export ARCH=arm
    ARCH环境变量设置为arm,这个命令的目的是为了在编译和构建ARM架构的软件时告诉系统使用ARM架构的工具链和设置。

    2.export CROSS_COMPILE=arm-linux-gnueabihf-
    设置交叉编译环境变量,指定在构建软件时使用的交叉编译工具链CROSS_COMPILE 环境变量表示,构建过程中使用的编译器和工具前缀。在这种情况下,arm-linux-gnueabihf- 是一个针对 ARM 架构的交叉编译工具链的前缀。

    3.export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin将指定的路径添加到PATH环境变量中。PATH环境变量包含了一系列目录路径,用于查找可执行文件(shell查询可执行文件的路径)。当在命令行中输入一个命令时,系统会在PATH环境变量中指定的路径中搜索这个命令的可执行文件。

    4.tar xvf tslib-1.21.tar.xz 解压压缩包

    5.进入解压出来的文件,然后查看文件是否有configure脚本,有的话,就使用
    **./configure --host=arm-linux-gnueabihf --prefix=/**命令
    –host=arm-linux-gnueabihf 这个参数告诉configure脚本使用特定的编译器和工具链来生成针对ARM架构的可执行文件。
    –prefix=/:指定软件的安装路径。这个参数告诉configure`脚本在构建和安装软件时,将安装的文件放置在根目录下。

    1. echo ‘main(){}’| arm-linux-gnueabihf-gcc -E -v -` 是用于对指定的 C 代码进行预处理,并显示详细的编译器输出信息,以便开发者更好地了解预处理过程和编译器的工作方式。我们用这个命令来看头文件和动态库的检索路径,因为使用#include是这条预处理指令,会从特定路径去寻找头文件,动态库是在执行的时候链接的,也是从特定路径去寻找,我们找到这些路径。

    7.cp include/ /home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/…/arm-linugnueabihf/libc/usr/include*
    这条指令就是把编译时需要用到的头文件放到处理#include寻找的路径(及从这条路径里寻找头文件)。

    cp -d lib/so /home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/…/arm-linux-gnueabihf/libc/usr/lib/
    这条指令就是把执行程序时需要链接的动态库放到链接动态库寻找的路径(及从这条路径里寻找动态库)

    在板子上的操作

    1.cp /mnt/tslib-1.21/tmp/etc/ts.conf -d /etc将文件复制到该目录下可以确保系统在启动和运行时能够访问并正确读取配置文件的内容。

    2.cp /mnt/tslib-1.21/tmp/lib/so -d /lib将文件复制到该目录下可以确保程序在执行的时候能链接到动态库

    3.cp /mnt/tslib-1.21/tmp/bin/ /bin*
    这个命令的目的是将 /mnt/tslib-1.21/tmp/bin/ 目录下的所有可执行文件复制到 /bin 目录下,使得这些可执行文件能够在系统的标准可执行文件目录中被查找和执行。

    mv /etc/init.d/S07hmi /root.
    reboot
    对于 IMX6ULL,首先需要关闭默认的 qt gui 程序,才可以执行 ts_test_mt测试命令

    ts_test_mt 测试程序

    编写测试程序

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #include 
    
    #include 
    
    #include 
    
    int distance(struct ts_sample_mt *point1, struct ts_sample_mt *point2)
    {
    	int x = point1->x - point2->x;
    	int y = point1->y - point2->y;
    
    	return x*x + y*y;
    }
    
    int main(int argc, char **argv)
    {
    	struct tsdev *ts;
    	int i;
    	int ret;
    	struct ts_sample_mt **samp_mt;
    	struct ts_sample_mt **pre_samp_mt;	
    	int max_slots;
    	int point_pressed[20];
    	struct input_absinfo slot;
    	int touch_cnt = 0;
    
    	ts = ts_setup(NULL, 0);
    	if (!ts)
    	{
    		printf("ts_setup err\n");
    		return -1;
    	}
    
    	if (ioctl(ts_fd(ts), EVIOCGABS(ABS_MT_SLOT), &slot) < 0) {
    		perror("ioctl EVIOGABS");
    		ts_close(ts);
    		return errno;
    	}
    
    	max_slots = slot.maximum + 1 - slot.minimum;//计算出能测量的触摸点个数
    
    	samp_mt = malloc(sizeof(struct ts_sample_mt *));
    	if (!samp_mt) {
    		ts_close(ts);
    		return -ENOMEM;
    	}
    	samp_mt[0] = calloc(max_slots, sizeof(struct ts_sample_mt));
    	if (!samp_mt[0]) {
    		free(samp_mt);
    		ts_close(ts);
    		return -ENOMEM;
    	}
    
    	pre_samp_mt = malloc(sizeof(struct ts_sample_mt *));
    	if (!pre_samp_mt) {
    		ts_close(ts);
    		return -ENOMEM;
    	}
    	pre_samp_mt[0] = calloc(max_slots, sizeof(struct ts_sample_mt));
    	if (!pre_samp_mt[0]) {
    		free(pre_samp_mt);
    		ts_close(ts);
    		return -ENOMEM;
    	}
    
    
    	for ( i = 0; i < max_slots; i++)
    		pre_samp_mt[0][i].valid = 0;
    
    	while (1)
    	{
    		ret = ts_read_mt(ts, samp_mt, max_slots, 1);
    
    		if (ret < 0) {
    			printf("ts_read_mt err\n");
    			ts_close(ts);
    			return -1;
    		}
    
    		for (i = 0; i < max_slots; i++)
    		{
    			if (samp_mt[0][i].valid)//判断是否是新数据
    			{
    				memcpy(&pre_samp_mt[0][i], &samp_mt[0][i], sizeof(struct ts_sample_mt));
    			}
    		}
    
    		touch_cnt = 0;
    		for (i = 0; i < max_slots; i++)
    		{
    			if (pre_samp_mt[0][i].valid && pre_samp_mt[0][i].tracking_id != -1)//判断是否有新数据且数据不被释放
    				point_pressed[touch_cnt++] = i;//存储触摸点位置
    		}
    
    		if (touch_cnt == 2)//如果只有两个触摸点
    		{
    			printf("distance: %08d\n", distance(&pre_samp_mt[0][point_pressed[0]], &pre_samp_mt[0][point_pressed[1]]));
    		}
    	}
    	
    	return 0;
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116

    在unbuntu:上编译:arm-buildroot-linux-gnueabihf-gcc mt_cal_distance.c -o mt_cal_distance -lts,生成板子可使用的可执行文件mt_cal_distance

    然后板子上执行mt_cal_distance就行

  • 相关阅读:
    Kafka事务「原理剖析」
    Github自动构建及推送DockerHub
    自媒体人必看的9个网站,每一个都很实用,值得收藏
    微服务和 C++ 如何有效结合?
    jmeter 线程组
    理解现货白银走势的关键
    Elasticsearch简介及SpringBoot整合ES实例
    R语言data.table导入数据实战:data.table数据列索引
    雅思核心词拾遗02----Family+ Law
    阿里 P8 爆出的这份大厂面试指南,看完工资暴涨 30k!
  • 原文地址:https://blog.csdn.net/m0_57678852/article/details/133816795