差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
|
r36s0 [2023/02/20 22:51] wjj |
r36s0 [2023/02/22 19:07] (当前版本) wjj |
||
|---|---|---|---|
| 行 75: | 行 75: | ||
| 7、最后点击连接,串口进入后台 | 7、最后点击连接,串口进入后台 | ||
| - | {{: | + | {{: |
| === Android ADB === | === Android ADB === | ||
| 行 109: | 行 109: | ||
| {{page>: | {{page>: | ||
| == USB == | == USB == | ||
| - | {{page>:template:temp_android_usb}} | + | {{:arm:rk3399: |
| == SDCARD == | == SDCARD == | ||
| {{page>: | {{page>: | ||
| 行 134: | 行 134: | ||
| === 接口功能测试 === | === 接口功能测试 === | ||
| == GPIO == | == GPIO == | ||
| - | 1. IO 控制节点都在/ | + | 1. IO 控制节点都在/ |
| {{: | {{: | ||
| 行 173: | 行 173: | ||
| ^ 主板丝印 | ^ 主板丝印 | ||
| - | | | + | | |
| - | | | + | | |
| - | | | + | | |
| - | | | + | | |
| - | | RS485_A1\B1 | + | | RS485_A1\B1 |
| - | | RS485_A2\B2 | + | | RS485_A2\B2 |
| - | 3. CuTecom 测试串口,以UART_RX5\TX5_232回环测试为例 | + | 3. CuTecom 测试串口,以232_RX5\TX5回环测试为例 |
| - | * 参考步骤1~2短接UART_RX5\TX5_232的 TX & RX (2~3 pin); | + | * 参考步骤1~2短接232_RX5\TX5的 TX & RX (2~3 pin); |
| * 双击桌面CuteCom图标,打开APP,Device选择测试端口对应的设备节点(见步骤2); | * 双击桌面CuteCom图标,打开APP,Device选择测试端口对应的设备节点(见步骤2); | ||
| * 点击Settings,设置串口参数,如下图所示: | * 点击Settings,设置串口参数,如下图所示: | ||
| 行 211: | 行 211: | ||
| {{page>: | {{page>: | ||
| == GPIO/DIO == | == GPIO/DIO == | ||
| - | 1. IO 控制节点都在/ | + | 1. IO 控制节点都在/ |
| {{: | {{: | ||
| 行 268: | 行 268: | ||
| == EMMC == | == EMMC == | ||
| {{page>: | {{page>: | ||
| - | ==== Linux编程指南 ==== | ||
| - | {{page>: | ||
| + | |||
| + | |||
| + | ==== Linux 应用编程 ==== | ||
| + | === GPIO 应用编程 === | ||
| + | C参考代码如下: | ||
| + | <code C> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | static char gpio_path[100]; | ||
| + | static int gpio_config(const char *attr, const char *val) | ||
| + | { | ||
| + | char file_path[100]; | ||
| + | int len; | ||
| + | int fd; | ||
| + | sprintf(file_path, | ||
| + | if (0 > (fd = open(file_path, | ||
| + | perror(" | ||
| + | return fd; | ||
| + | } | ||
| + | len = strlen(val); | ||
| + | if (len != write(fd, val, len)) { | ||
| + | perror(" | ||
| + | close(fd); | ||
| + | return -1; | ||
| + | } | ||
| + | close(fd); // | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | int main(int argc, char *argv[]) | ||
| + | { | ||
| + | char file_path[100]; | ||
| + | char val; | ||
| + | int fd; | ||
| + | /* 校验传参 */ | ||
| + | if (2 != argc) { | ||
| + | fprintf(stderr, | ||
| + | exit(-1); | ||
| + | } | ||
| + | /* 判断指定编号的 GPIO 是否导出 */ | ||
| + | sprintf(gpio_path, | ||
| + | if (access(gpio_path, | ||
| + | int len; | ||
| + | if (0 > (fd = open("/ | ||
| + | perror(" | ||
| + | exit(-1); | ||
| + | } | ||
| + | len = strlen(argv[1]); | ||
| + | if (len != write(fd, argv[1], len)) {//导出 gpio | ||
| + | perror(" | ||
| + | close(fd); | ||
| + | exit(-1); | ||
| + | } | ||
| + | close(fd); // | ||
| + | } | ||
| + | |||
| + | /* 配置为输入模式 */ | ||
| + | if (gpio_config(" | ||
| + | exit(-1); | ||
| + | /* 极性设置 */ | ||
| + | if (gpio_config(" | ||
| + | exit(-1); | ||
| + | /* 配置为非中断方式 */ | ||
| + | if (gpio_config(" | ||
| + | exit(-1); | ||
| + | /* 读取 GPIO 电平状态 */ | ||
| + | sprintf(file_path, | ||
| + | if (0 > (fd = open(file_path, | ||
| + | perror(" | ||
| + | exit(-1); | ||
| + | } | ||
| + | |||
| + | if (0 > read(fd, &val, 1)) { | ||
| + | perror(" | ||
| + | close(fd); | ||
| + | exit(-1); | ||
| + | } | ||
| + | printf(" | ||
| + | /* 退出程序 */ | ||
| + | close(fd); | ||
| + | exit(0); | ||
| + | } | ||
| + | </ | ||
| + | 交叉编译源码: | ||
| + | |||
| + | aarch64-linux-gnu-gcc -o gpio gpio.c | ||
| + | |||
| + | 将编译好的gpio程序使用scp拷贝到 r36s0 主板上,执行测试: | ||
| + | |||
| + | 使用方法: | ||
| + | |||
| + | 0:./gpio 3 | ||
| + | |||
| + | 1:./gpio 1 | ||
| + | | ||
| + | {{: | ||
| + | |||
| + | |||
| + | === UART 应用编程 === | ||
| + | |||
| + | 系统下操作 UART 的测试串口,以 232_RX5\TX5 测试为例: | ||
| + | |||
| + | 232_RX5\TX5 设备节点为: | ||
| + | |||
| + | / | ||
| + | |||
| + | C参考UART高低电平输入代码如下: | ||
| + | |||
| + | <code C> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | int set_opt(int, | ||
| + | |||
| + | void main(){ | ||
| + | int fd,nByte; | ||
| + | char *uart3 = "/ | ||
| + | char bufferR[2]; | ||
| + | char bufferW[2]; | ||
| + | |||
| + | memset(bufferR, | ||
| + | memset(bufferW, | ||
| + | |||
| + | if((fd=open(uart3, | ||
| + | { | ||
| + | printf(" | ||
| + | } | ||
| + | else{ | ||
| + | printf(" | ||
| + | set_opt(fd, | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | while(1){ | ||
| + | |||
| + | nByte = 0; | ||
| + | |||
| + | memset(bufferR, | ||
| + | memset(bufferW, | ||
| + | |||
| + | // printf(" | ||
| + | if((nByte = read(fd, bufferR, 1)) == 1){ // | ||
| + | |||
| + | |||
| + | printf(" | ||
| + | |||
| + | bufferW[0] = ' | ||
| + | |||
| + | write(fd, | ||
| + | |||
| + | |||
| + | memset(bufferR, | ||
| + | memset(bufferW, | ||
| + | |||
| + | nByte = 0; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | close(fd); | ||
| + | |||
| + | } | ||
| + | |||
| + | // | ||
| + | int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop) | ||
| + | { | ||
| + | struct termios newtio, | ||
| + | // | ||
| + | if ( tcgetattr( fd,& | ||
| + | perror(" | ||
| + | return -1; | ||
| + | } | ||
| + | // | ||
| + | bzero( & | ||
| + | newtio.c_cflag | ||
| + | newtio.c_cflag &= ~CSIZE; | ||
| + | // | ||
| + | switch( nBits ) | ||
| + | { | ||
| + | case 7: | ||
| + | newtio.c_cflag |= CS7; | ||
| + | break; | ||
| + | case 8: | ||
| + | newtio.c_cflag |= CS8; | ||
| + | break; | ||
| + | } | ||
| + | // | ||
| + | switch( nEvent ) | ||
| + | { | ||
| + | // | ||
| + | case ' | ||
| + | newtio.c_cflag |= PARENB;// | ||
| + | newtio.c_cflag |= PARODD;// | ||
| + | newtio.c_iflag |= (INPCK | ISTRIP);// | ||
| + | break; | ||
| + | case ' | ||
| + | newtio.c_iflag |= (INPCK | ISTRIP); | ||
| + | newtio.c_cflag |= PARENB; | ||
| + | newtio.c_cflag &= ~PARODD;// | ||
| + | break; | ||
| + | case ' | ||
| + | newtio.c_cflag &= ~PARENB;// | ||
| + | break; | ||
| + | } | ||
| + | // | ||
| + | switch( nSpeed ) | ||
| + | { | ||
| + | case 2400: | ||
| + | cfsetispeed(& | ||
| + | cfsetospeed(& | ||
| + | break; | ||
| + | case 4800: | ||
| + | cfsetispeed(& | ||
| + | cfsetospeed(& | ||
| + | break; | ||
| + | case 9600: | ||
| + | cfsetispeed(& | ||
| + | cfsetospeed(& | ||
| + | break; | ||
| + | case 115200: | ||
| + | cfsetispeed(& | ||
| + | cfsetospeed(& | ||
| + | break; | ||
| + | case 460800: | ||
| + | cfsetispeed(& | ||
| + | cfsetospeed(& | ||
| + | break; | ||
| + | default: | ||
| + | cfsetispeed(& | ||
| + | cfsetospeed(& | ||
| + | break; | ||
| + | } | ||
| + | // | ||
| + | if( nStop == 1 ) | ||
| + | newtio.c_cflag & | ||
| + | else if ( nStop == 2 ) | ||
| + | newtio.c_cflag |= CSTOPB;// | ||
| + | |||
| + | newtio.c_cc[VTIME] | ||
| + | newtio.c_cc[VMIN] = 0;// | ||
| + | |||
| + | tcflush(fd, | ||
| + | |||
| + | // | ||
| + | if((tcsetattr(fd, | ||
| + | { | ||
| + | perror(" | ||
| + | return -1; | ||
| + | } | ||
| + | // | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | 交叉编译源码: | ||
| + | |||
| + | aarch64-linux-gnu-gcc -o uart uart.c | ||
| + | |||
| + | 将编译好的程序使用 scp 拷贝到 r36s0 主板上,执行测试: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | === KEY 应用编程 === | ||
| + | |||
| + | 参考系统下操作Key的方法,获取到key的设备节点为 | ||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | C参考代码如下: | ||
| + | |||
| + | <code C> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #define INPUT_DEVICE "/ | ||
| + | int main(int argc, char **argv){ | ||
| + | int fd; | ||
| + | struct input_event event; | ||
| + | ssize_t bytesRead; | ||
| + | int ret; | ||
| + | fd_set readfds; | ||
| + | if ( 0 > (fd = open(INPUT_DEVICE, | ||
| + | { | ||
| + | perror(" | ||
| + | return fd; | ||
| + | } | ||
| + | while(1){ | ||
| + | FD_ZERO(& | ||
| + | FD_SET(fd,& | ||
| + | ret = select(fd + 1, & | ||
| + | if (ret == -1){ | ||
| + | fprintf(stderr," | ||
| + | break; | ||
| + | } | ||
| + | if(FD_ISSET(fd,& | ||
| + | bytesRead = read(fd, & | ||
| + | if(bytesRead == -1 ) | ||
| + | fprintf(stderr," | ||
| + | } | ||
| + | if(event.type == EV_KEY && (event.value == 0 || event.value == 1)) | ||
| + | { | ||
| + | printf(" | ||
| + | } | ||
| + | } | ||
| + | close(fd); | ||
| + | return EXIT_SUCCESS; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | 交叉编译源码: | ||
| + | |||
| + | < | ||
| + | aarch64-linux-gnu-gcc -o key key.c | ||
| + | </ | ||
| + | 将编译好的程序使用 scp 拷贝到 r36e0 主板上,执行测试,按动 key 打印如下: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | *按下按键时显示:key pressed | ||
| + | *松开按键时显示:key released | ||
| ==== Linux 应用支持 ==== | ==== Linux 应用支持 ==== | ||