差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
r39s2 [2023/02/07 00:44] hc |
r39s2 [2023/02/21 18:46] (当前版本) wjj |
||
---|---|---|---|
行 81: | 行 81: | ||
{{page>: | {{page>: | ||
== GPIO/DIO == | == GPIO/DIO == | ||
+ | 1. IO 控制节点都在/ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | 2. IO 对应表如下: | ||
+ | ^ 功能 | ||
+ | ^ 输入 | ||
+ | | ::: | IO2 | gpio_ip1 | ||
+ | | ::: | IO3 | gpio_ip2 | ||
+ | | ::: | IO4 | gpio_ip3 | ||
+ | ^ 输出 | ||
+ | | ::: | IO6 | gpio_op1 | ||
+ | | ::: | IO7 | gpio_op2 | ||
+ | | ::: | IO8 | gpio_op3 | ||
+ | |||
+ | |||
+ | 3. IO控制方法: | ||
+ | |||
+ | *输出低电平: | ||
+ | |||
+ | echo 0 >/ | ||
+ | | ||
+ | | ||
+ | *输出高电平: | ||
+ | |||
+ | | ||
+ | echo 1 >/ | ||
+ | | ||
+ | | ||
+ | *查看输入电平: | ||
+ | |||
+ | | ||
+ | cat / | ||
{{page>: | {{page>: | ||
== Audio == | == Audio == | ||
行 108: | 行 141: | ||
== EMMC == | == EMMC == | ||
{{page>: | {{page>: | ||
- | ==== Linux编程指南 ==== | + | ==== Linux 编程指南 ==== |
- | {{page>:template:temp_Linux_sw}} | + | |
+ | === 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拷贝到 r39s2 主板上,执行测试: | ||
+ | |||
+ | 使用方法: | ||
+ | |||
+ | 0:./gpio 3 | ||
+ | |||
+ | 1:./gpio 1 | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | === UART 应用编程 === | ||
+ | |||
+ | 系统下操作 UART 的测试串口,以 J_RS232 TX3\RX3 测试为例: | ||
+ | |||
+ | J_RS232 TX3\RX3 设备节点为: | ||
+ | |||
+ | / | ||
+ | |||
+ | 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 拷贝到 3399 主板上,执行测试: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | === 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 拷贝到 r39s2 主板上,执行测试,按动 key 打印如下: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | *按下按键时显示:key pressed | ||
+ | *松开按键时显示:key released | ||
行 133: | 行 504: | ||
终端输入 ota 进行固件在线升级 | 终端输入 ota 进行固件在线升级 | ||
- | {{: | + | {{: |