zoukankan      html  css  js  c++  java
  • am335x -- kio 控制接口

    //example
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))

    int main(int argc, char * argv)
    {
            int i, n, fd;
            char num,val;
            int ret;
            fd = open("/dev/kio", O_RDWR);                //打开设备
            if (fd < 0)
            {
                printf("can't open /dev/kio! ");
                exit(1);
            }
            sleep(1);
            ioctl(fd, 1, GPIO_TO_PIN(1,22));                //设置gpio1-22为输出(user:led3)
            ioctl(fd, 0, GPIO_TO_PIN(2, 1));                //设置gpio2-1 为输入(p8-18)
            while (1)
            {
                    num = 1;
                    ret = write(fd,"1",GPIO_TO_PIN(1,22)); //置高
                    if(ret < 0)
                    {
                            perror("write");
                            return -1;
                    }
                    sleep(1);
                    ret = write(fd,"0",GPIO_TO_PIN(1,22));//置低
                    if(ret < 0)
                    {
                        perror("write");
                        return -1;
         }

          ret = read(fd, &val, GPIO_TO_PIN(2,1)); //读取电平

                 if(ret == 1) //高电平

                     printf("val==1 ");

                 if(ret == 0) // 低电平

                     printf("val == 0 ");

      }

    }

  • 相关阅读:
    pycharm右键无file Encoding问题解决
    IDEA build 时报无效的源发行版: 9 和 无效的目标发行版: 9
    LNMP与LAMP框架的简介及原理
    Dynamics CRM实体系列之键
    Dynamics CRM实体系列之图表
    Dynamics CRM实体系列之视图
    Dynamics CRM实体系列之窗体
    Dynamics CRM实体系列之字段
    Dynamics CRM实体系列之实体讲解
    Dynamics CRM字段安全配置文件
  • 原文地址:https://www.cnblogs.com/zym0805/p/4276205.html
Copyright © 2011-2022 走看看