全志A20 GPIO 总结文档

本文档详述了全志A20芯片的GPIO工作原理,包括配置、操作和调试方法。通过实例解析,读者将了解如何在Android系统下进行GPIO驱动开发及问题排查,深入理解Linux内核中的GPIO接口和调试技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
 * author:          chwenj@gmail.com.
 * Agreement:       GPL.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define GPIO_SET      0xAC  
#define GPIO_GET      0xAB

#define DEVICE_FILE "/dev/gpio_cdev"

typedef struct {
    unsigned char count;  //GPIO序列
    unsigned char data;   //GPIO电平状态
} gpio_userspace_t;

/*main*/
int main(/* int argc, char **argv */)
{
    /*open*/
    int gpio_fd, ret;

    gpio_fd = open(DEVICE_FILE, O_RDWR);    //读写权限打开文件
    if (gpio_fd < 0) {
        printf("gpio device fail to open.\n");
        return -1;
    }
    printf("%s opend.\n", DEVICE_FILE);

#if 1
    /*write*/
    gpio_userspace_t write_gpio;
    write_gpio.count = 5;   //GPIO序列号
    write_gpio.data = 1;    //GPIO电平值

    printf("write: count = %d , data = %d.\n", write_gpio.count, write_gpio.data);

    ret = write(gpio_fd, &write_gpio, sizeof(gpio_userspace_t));
    if (ret < 0) {
        printf("%s fail to write.\n", DEVICE_FILE);
        return -1;
    }
#endif

    /*ioctl*/
    gpio_userspace_t ioctl_gpio;
    ioctl_gpio.data = 0xff;     //level:0xff
    ioctl_gpio.count = 5;       //pin:4

    ret = ioctl(gpio_fd, GPIO_SET, &ioctl_gpio);
    if (ret < 0) {
        printf("ioctl: ioctl fail.\n");
        return -1;
    }

    /*read*/
    gpio_userspace_t read_gpio;

    ret = read(gpio_fd, &read_gpio, sizeof(gpio_userspace_t));
    if (ret < 0) {
        printf("read: fail to read.\n");
        return -1;
    }
    printf("read: count = %d, data = %d.\n", read_gpio.count, read_gpio.data);

    /*close*/
    close(gpio_fd);
    printf("%s close.\n", DEVICE_FILE);

    return 0;
}



#include <linux/fs.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/platform_device.h>
#include <linux/utsname.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <mach/sys_config.h>
#include <mach/includes.h>
#include <linux/gpio.h>
#include <linux/delay.h>


/**********
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值