查看: 248|回复: 5

[hi3559/hi3559a] 应用层操作GPIO口

[复制链接]
发表于 2019-9-11 16:45:21 | 显示全部楼层 |阅读模式
最近开始调3559CV100,在应用层操作GPIO口,以前在3521A上直接有接口(HI_MPI_SYS_SetReg), 现在没有这个接口了,于是在外围驱动操作指南中按照export操作。但是IO口没有反应,各个调用也没有报错,求问各位大神是怎么操作IO口的
 楼主| 发表于 2019-9-12 15:28:05 | 显示全部楼层
原来调用之前需要配置复用,否则,export无效
发表于 2019-9-18 11:31:22 | 显示全部楼层
现在海思支持Linux标准GPIO了,可以用标准GPIO来做驱动
发表于 2019-9-20 15:24:34 | 显示全部楼层
测试gpio24:
echo 24 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio24/direction
echo 1 > /sys/class/gpio/gpio24/value
echo 0 > /sys/class/gpio/gpio24/value

测试gpio25:
echo 25 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio25/direction
echo 1 > /sys/class/gpio/gpio25/value
echo 0 > /sys/class/gpio/gpio25/value

测试gpio26:
echo 26 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio26/direction
echo 1 > /sys/class/gpio/gpio26/value
echo 0 > /sys/class/gpio/gpio26/value

测试gpio27:
echo 27 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio27/direction
echo 1 > /sys/class/gpio/gpio27/value
echo 0 > /sys/class/gpio/gpio27/value
发表于 2019-9-20 15:29:13 | 显示全部楼层
//测试 GPIO14_0@Hi3559AV100
//编译 aarch64-himix100-linux-gcc -o gpio_mmap gpio_mmap.c
//如果没有/dev/mem,则执行 mknod /dev/mem c 1 1
//
//等效于
//echo 112 > /sys/class/gpio/export
//echo out > /sys/class/gpio/gpio112/direction
//echo 1 > /sys/class/gpio/gpio112/value
//#echo 0 > /sys/class/gpio/gpio112/value
//等效于
//devmem 0x1f000124 w 0x00001600
//devmem 0x1214E400 w 0x00000001
//devmem 0x1214E004 w 0x00000001
//#devmem 0x1214E004 w 0x00000000

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/mman.h>


#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE - 1)

#define GPIO_CFG_BASE 0x1f000124
#define GPIO_CTL_BASE 0x1214e000
#define rGPBCON 0x400
#define rGPBDAT 0x0

unsigned int *GPBCON,*GPBDAT,*GPBUP;

void Led_Display(int data)
{
        *(volatile unsigned int *)GPBDAT= (~data & 0x1) << 0;//因为是第0位,且只有1位,故 左移0
}

int main(int argc, char** argv)
{
        int gpio_fd, ip=0, i=0;
        void *gpio_map;
        void *gpio_cfg;
         
         
        gpio_map = NULL;
        GPBCON = NULL;
        GPBDAT = NULL;
        GPBUP = NULL;
         
        gpio_fd =open("/dev/mem",O_RDWR);
        if (gpio_fd == -1)
        {
                printf("can't open /dev/mem.\n");
                return 1;
        }
         
        //gpio_cfg = (unsigned char *)mmap(0, 0x4, PROT_READ | PROT_WRITE, MAP_SHARED, gpio_fd, GPIO_CFG_BASE);
        //gpio_map = (unsigned char *)mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, gpio_fd, GPIO_CTL_BASE);
       
        gpio_cfg = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, gpio_fd, GPIO_CFG_BASE & ~MAP_MASK);
        gpio_cfg = gpio_cfg + (GPIO_CFG_BASE & MAP_MASK);  // virtual address
        gpio_map = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, gpio_fd, GPIO_CTL_BASE & ~MAP_MASK) + (GPIO_CTL_BASE & MAP_MASK);
        GPBCON = (volatile unsigned int *) (gpio_map+rGPBCON);
        GPBDAT = (volatile unsigned int *) (gpio_map+rGPBDAT+(0x1<<2)); // bit0 mask 0x01

        //初始化io
        *(volatile unsigned int *)gpio_cfg = 0x00001600;
        *(volatile unsigned int *)GPBCON = 0x00000001;

        for(i=0;i<30;i++)
        {
                Led_Display(i);
                sleep(1);
        }

        munmap(0, 0xbc);
        if (gpio_fd != 0x0)
        {
                close(gpio_fd);
        }

        printf("GPIO Control Test end\n");

}
发表于 2019-11-4 15:35:53 | 显示全部楼层
怎么操作的,请教
您需要登录后才可以回帖 登录 | 注册

本版积分规则

© 2008-2017 当前位置 易百纳技术社区论坛 返回 易百纳技术社区 ( 苏ICP备14036084 )   Powered by Discuz! X3.1
快速回复 返回顶部 返回列表