嵌入式开发者社区
标题:
【试用报告】创龙科技 TL335x-EVM-S评估板应用开发之USER按键
[打印本页]
作者:
别打牛牛
时间:
2022-1-17 16:25
标题:
【试用报告】创龙科技 TL335x-EVM-S评估板应用开发之USER按键
本次试用的依旧是创龙科技的
TL335x-EVM-S评估板,测试下USER按键是否可以正常使用。
1、尝试一下应用发方式使用USER按键
2、监听用户按键USER设备节点状态,检测按键事件
在虚拟机的Ubuntut系统里,先建一个文件夹src,下面两个文件makefile和tl_key_test.c
tl_key_test.c脚本
/* Copyright 2018 Tronlong Elec. Tech. Co. Ltd. All Rights Reserved. */
#include <stdio.h>
#include <stdbool.h>
#include <libgen.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <
getopt
.h>
#include <sys/select.h>
#include <linux/input.h>
#define INADEQUATE_CONDI
ti
ONS 3
typedef enum { KEY_CODE_NONE = 0, KEY_CODE_USER0, KEY_CODE_USER1 } KeyCode;
/* Exit flag */
volatile bool g_quit = false;
/* Short option names */
static const char g_shortopts [] = ":d:vh";
/* Option names */
static const struct option g_longopts [] = {
{ "device", required_argument, NULL, 'd' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
static void usage(FILE *fp, int argc, char **argv) {
f
printf
(fp,
"Usage: %s [options]\n\n"
"Options:\n"
" -d | --device Device \n"
" -v | --version
display
version information\n"
" -h | --help Show help content\n\n"
"", basename(argv[0]));
}
static void opt_parsing_err_handle(int argc, char **argv, int flag) {
/* Exit
IF
no input parameters are entered */
int state = 0;
if (argc < 2) {
printf("No input parameters are entered, please check the input.\n");
state = -1;
} else {
/* Feedback Error parameter information then exit */
if (optind < argc || flag) {
printf("Error: Parameter parsing fai
LED
\n");
if (flag)
printf("\tunrecognized option '%s'\n", argv[optind-1]);
while (optind < argc) {
printf("\tunrecognized option '%s'\n", argv[optind++]);
}
state = -1;
}
}
if (state == -1) {
printf("Tips: '-h' or '--help' to get help\n\n");
exit(2);
}
}
void sig_handle(int arg) {
g_quit = true;
}
static int check_button_pressed(int fd) {
assert(fd >= 0);
/* wait button being pressed or released. */
fd_set input;
FD_ZERO(&input);
FD_SET(fd, &input);
int ret = select(fd + 1, &input, NULL, NULL, NULL);
if (ret < 0) {
printf("%s", strerror(errno));
return -1;
}
/* read event */
struct input_event buf;
if (read(fd, &buf, sizeof(struct input_event)) < 0) {
printf("%s", strerror(errno));
return -1;
}
/* Check the input_event value */
switch (buf.code) {
case KEY_PROG1:
/* 1: pressed; 0: released */
if (buf.value == 1)
return KEY_CODE_USER0;
break;
case KEY_PROG2:
if (buf.value == 1)
return KEY_CODE_USER1;
break;
default:
return KEY_CODE_NONE;
break;
}
return KEY_CODE_NONE;
}
int main(int argc, char **argv) {
int c = 0;
int flag = 0;
char *dev;
/* Parsing input parameters */
while ((c = getopt_long(argc, argv, g_shortopts, g_longopts, NULL)) != -1) {
switch (c) {
case 'd':
dev = optarg;
break;
case 'v':
/* Display the version */
printf("version : 1.0\n");
exit(0);
case 'h':
usage(stdout, argc, argv);
exit(0);
default :
flag = 1;
break;
}
}
opt_parsing_err_handle(argc, argv, flag);
/* Ctrl+c handler */
signal(SIGINT, sig_handle);
int fd = open(dev, O_RDONLY);
if (fd < 0) {
printf("Error: Failed to open device\n");
return INADEQUATE_CONDITIONS;
}
printf("Please press the key to test.\n");
while (!g_quit) {
int key_code = check_button_pressed(fd);
if (key_code < 0)
continue;
switch (key_code) {
case KEY_CODE_USER0:
printf("Key user0 pressed!\n");
break;
case KEY_CODE_USER1:
printf("Key user1 pressed!\n");
break;
default:
break;
}
}
close(fd);
return 0;
}
[color=rgb(51, 102, 153) !important]复制代码
makefile脚本
tl_key_test:tl_key_test.c
$(CC) -Wall [ DISCUZ_CODE_513 ]lt; -o $@
clean:
rm -f tl_key_test *.o *~
install:
cp tl_key_test $(PREFIX)
[color=rgb(51, 102, 153) !important]复制代码
3、生成执行文件tl_key_test
source /home/tronlong/ti-processor-sdk-linux-rt-am335x-evm-04.03.00.05/linux-devkit/environment-setup
make
[color=rgb(51, 102, 153) !important]复制代码
4、
开发板
eth0接好
网线
,获得的IP是 192.168.31.40 通过OpenSSH进行文件
传输
命令
行命令
scp tl_key_test
root@192.168.31.40
:/
[color=rgb(51, 102, 153) !important]复制代码
5、通过开发板串口进入开发板的命行,可以看见传递过来的文件,并能执行
USER按键信息已完美监听到了。
转自——电子发烧友
欢迎光临 嵌入式开发者社区 (https://51dsp.net/)
Powered by Discuz! X3.4