Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解

马肤
摘要:,,本文介绍了Android和Linux系统中GPIO(General Purpose Input/Output)的控制方法。文章首先概述了GPIO的基本概念及其在操作系统中的作用,然后详细描述了如何在Android和Linux平台上进行GPIO的配置和控制,包括相关命令、编程接口以及操作步骤。文章旨在帮助开发者理解并实现在这些系统中对GPIO的有效控制,以促进硬件交互和系统集成。

目录

1 GPIO整体架构

2 user space 层 gpio使用方法

2.1 sysfs控制方法

2.1.1 kernel版本区别

 2.1.2 /sys/class/gpio

 2.1.3 /sys/bug/gpio/devices

2.2 chardev控制方法 

2.2.1 chardev 示例代码

2.2.2 示例代码主要步骤描述

2.2.3 include/linux/gpio.h 全部代码

2.3 gpiolib_tools

2.3.1 gpiodetect

2.3.2 gpioinfo

2.3.3  gpio-event-mon 

2.4 gpiolib-debugfs

2.4.1 /sys/kernel/debug/gpio

2.4.2/sys/kernel/debug/gpio/pinctrl

 3 kernel空间使用gpio

3.1 pinctrl子系统概念 

3.1.1 pinctrl 子系统 DTS设定

3.1.2 pinctrl 子系统 driver设定

3.2 gpio子系统

3.2.1 gpio子系统 DTS设定

3.2.2  gpio子系统 driver设定

4 gpio IRQ相关简述

4.1 linux中断描述及常用API

4.2 GPIO中断API 

4.3 GPIO中断使用代码示例:

4.4 gpio中断效果确认


1 GPIO整体架构

从Linux kernel 2.6.24开始,GPIO控制核心就通过gpiolib来进行实现了。

   gpiolib初始提交信息:

gpiolib: add gpio provider infrastructure - kernel/git/torvalds/linux.git - Linux kernel source tree

   gpiolib初始提交代码:

   gpiolib.c « gpio « drivers - kernel/git/torvalds/linux.git - Linux kernel source tree

关于gpio的使用block图如下:

Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第1张

对于hardware层:

  • GPIO controller是硬件物理结构

    对于kernel space层:

    • 芯片厂商的bsp工程师负责gpio chip driver
    • 开源社区(linux kernel)的大佬负责gpiolib的核心功能实现
    • BSP开发担当负责编写gpio consumer driver,可以从kernel driver中控制gpio

      对于user space层:

      • APP开发担当可以从user space 使用sysfs和chardev的形式控制gpio

        因此正常情况下,BSP及APP开发不需要深入GPIO chip driver和gpiolib,仅了解其使用方式即可

        2 user space 层 gpio使用方法

        2.1 sysfs控制方法

                查看kernel版本中关于gpiofs的官方描述,可以通过kernel官网

                网址:kernel.org/doc/Documentation/gpio/sysfs.txt

        2.1.1 kernel版本区别

                上述网站中最新的描述中可以看到gpio sysfs已经弃用了

         

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第2张

        查看相关资料时发现,这个改动是从2015年逐渐从linux kernel4.6开始引入的,至到4.8版本(2020年)正式废弃。这部分的提交代码如下:

        网址:gpio: add a userspace chardev ABI for GPIOs - kernel/git/torvalds/linux.git - Linux kernel source tree

        所以在kernel4.8以前可以直接使用gpio sysfs的方法来控制gpio。

        如果在4.8以后,想要再使用这个接口,可以通过改变menuconfig的方式打开CONFIG_GPIO_SYSFS,然后就可以继续使用gpio sysfs来控制gpio了。

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第3张

         2.1.2 /sys/class/gpio

                该目录下的gpio可以直接通过命令进行操作

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第4张

                该目录下有个export文件,向export文件写入要操作的GPIO号,使得该GPIO的操作接口从内核空间暴露到用户空间,GPIO的操作接口包括direction和value等,direction控制GPIO输入或者输出模式,而value可控制GPIO的状态或者读取状态。

                /sys/class/gpio/目录下各个文件说明:

                 /sys/class/gpio/export文件用于通知系统需要导出控制的GPIO引脚编号;

                /sys/class/gpio/unexport 用于通知系统取消导出;

                /sys/class/gpio/gpioX/direction文件,可以通过echo写入in(设置输入方向)或out(设置输出方向);通过cat读出输入方向

                /sys/class/gpio/gpioX/value文件是可以读写GPIO状态;echo 写入,cat读出

                /sys/class/gpio/gpiochipX目录保存系统中GPIO寄存器的信息,包括每个寄存器控制引脚的起始编号,寄存器名称,引脚总数;其中X表示具体的引脚编号。

                对于组别和编号的判断,在此目录下使用命令:  for file in ./gpiochip*/label;do echo -n "$file ------->";cat "$file";done; 可以确认端子组别信息

                效果如下:

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第5张

                上述内容gpc对应的gpio起始编号为61,如果此时想要操作gpc_0,则对应编号则为61+0=61

                使用echo 61 > export则可以导出gpc_0的端子文件目录

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第6张

                 进入gpio61 目录后可以通过 cat 获取当前gpio的电平状态和输入输出状态,也可以通过echo命令 改变gpio输出的电平状态

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第7张

                通过echo和cat命令 确认gpio输入输出模式 

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第8张

        上述的控制台命令在app的代码上可以使用system函数取代例如: 

        void GPIO_LOW_SET(void)
        {
            system("echo 247 > /sys/class/gpio/export");
            system("echo out > /sys/class/gpio/gpio247/direction");
            system("echo 0 > /sys/class/gpio/gpio247/value");
            system("echo 248 > /sys/class/gpio/export");
            system("echo out > /sys/class/gpio/gpio248/direction");
            system("echo 0 > /sys/class/gpio/gpio248/value");   
            
            system("echo 249 > /sys/class/gpio/export");
            system("echo out > /sys/class/gpio/gpio249/direction");
            system("echo 0 > /sys/class/gpio/gpio249/value");   
            
        }

         2.1.3 /sys/bug/gpio/devices

                确认gpio组别不仅可以通过上述  /gpio/class/gpio/gpiochip*/label  取得。

            还可以通过  /sys/bus/gpio/devices/gpiochip* /of_node/name 取得

            在/sys/bus/gpio/devices目录下使用命令:  

        for file in ./gpiochip* ;do echo -n "$file ------->";cat "$file/of_node/name";echo ;done;

        结果效果:

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第9张

        其实/sys/bus/gpio/devices和/sys/class/gpio的区别到底在哪呢?在此不详细说明,通过下面的内容也许能为你提供一些灵感。(下图可能也表明了/sys/bus和/sys/class的一些奥妙!)

            /sys/bus/gpio/devices

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第10张

                /sys/class/gpio 

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第11张

        2.2 chardev控制方法 

        通过【1gpio整体架构】的block图可以看到主要使用的节点是/dev/gpiochip*,这是一个设备节点。对于app的开发,应当使用open,ioctl,write,read等文件接口对它进行操作。

        可操作的设备 在/dev下都命名为gpiochip*  如下图:

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第12张

        相关libgpiod网页:libgpiod/libgpiod.git - C library and tools for interacting with the linux GPIO character device (kernel.org) 

        2.2.1 chardev 示例代码

        下面是一段用于拉高gpiochip4_4的示例代码

        #include 
        #define HIGH                        (1)
        #define LOW                         (0)
        #define RES_NG                      (1)
        #define RES_OK                      (0)
        #define INIT_STATUS_LINES 4
        #define  INIT_STATUS_GPIOCHIPS "/dev/gpiochip4"
        /********************************************************************************/
        /* Function Name        : nswWrite_PowerGPIO_Value                              */
        /* Date                 : 2024/01/11                                            */
        /* Author               : HeartJoKer                                            */
        /* Description          : Set Power Gpio:INIT_STATE Value                       */
        /* Argument Code        : none   */
        /* Return Code          : Type_sWord    aswRet 0 is OK,1 is NG                  */
        /* Tips                 : GPIO 相关宏及结构体定义参考/include/linux/gpio.h       */
        /*------------------------------------------------------------------------------*/
        /* Revision History              */
        /* No.        Date                  Revised by          Function Name           */
        /* 0001    2024/01/11               HeartJoKer            New                   */
        /********************************************************************************/
        Type_sWord nswWrite_PowerGPIO_Value()
        {
            Type_sWord aswRet = RES_NG;
            Type_sWord aswLineFd = 0;
            Type_sWord aswChipFd = 0;
            struct gpiohandle_data astData;
            struct gpiohandle_request astreq;
            memset(&astData,0,sizeof(astData));
            memset(&astreq,0,sizeof(astreq));
            ALOGI("Start to Set GPIO:INIT_STATUS Vaule");
            aswChipFd = open(INIT_STATUS_GPIOCHIPS, 0);
            if(aswChipFd  
        

        2.2.2 示例代码主要步骤描述

        其中有四步关键内容

        ①open(INIT_STATUS_GPIOCHIPS, 0);

        ②ioctl(aswChipFd, GPIO_GET_LINEHANDLE_IOCTL, &astreq)

        ③ioctl(astreq.fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &astData)

        ④ close(aswChipFd)

        再提及这四个具体步骤之前,要明确两个概念

        概念一:gpiochip_group:参照上文提到的gpiochip,对应不同gpio组,例如:

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第13张

        概念二:gpiochip_group_line:对应每一个gpiochip_group每一组下的每一个gpio 

        Android&Linux GPIO控制方法,Android与Linux的GPIO控制方法详解 第14张

               结合上述两个概念,gpioe-4,即/dev/gpiochip4--->line4

              明确上述概念后,上述代码的四步逻辑就能比较清晰的理解

                ①选择gpiochip,通过open函数获取对应dev的Fd句柄

                ②通过ioctl获取对应Line句柄

                ③通过ioctl上述选择的Line进行操作

                ④关闭dev设备

        对于②③可用的ioctrl宏参照如下:(include/linux/gpio.h)

        /*
         * v1 and v2 ioctl()s
         */
        #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info)
        #define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0C, __u32)
        /*
         * v2 ioctl()s
         */
        #define GPIO_V2_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x05, struct gpio_v2_line_info)
        #define GPIO_V2_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x06, struct gpio_v2_line_info)
        #define GPIO_V2_GET_LINE_IOCTL _IOWR(0xB4, 0x07, struct gpio_v2_line_request)
        #define GPIO_V2_LINE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0D, struct gpio_v2_line_config)
        #define GPIO_V2_LINE_GET_VALUES_IOCTL _IOWR(0xB4, 0x0E, struct gpio_v2_line_values)
        #define GPIO_V2_LINE_SET_VALUES_IOCTL _IOWR(0xB4, 0x0F, struct gpio_v2_line_values)
        /*
         * v1 ioctl()s
         *
         * These ioctl()s are deprecated.  Use the v2 equivalent instead.
         */
        #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info)
        #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request)
        #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request)
        #define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data)
        #define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data)
        #define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0A, struct gpiohandle_config)
        #define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0B, struct gpioline_info)

        使用这些宏时需要关注其相关结构体,例如上文中使用

        ②GPIO_GET_LINEHANDLE_IOCTL----> gpiohandle_request

        对应结构体

        /**
         * struct gpiohandle_request - Information about a GPIO handle request
         * @lineoffsets: an array of desired lines, specified by offset index for the
         * associated GPIO device
         * @flags: desired flags for the desired GPIO lines, such as
         * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added
         * together. Note that even if multiple lines are requested, the same flags
         * must be applicable to all of them, if you want lines with individual
         * flags set, request them one by one. It is possible to select
         * a batch of input or output lines, but they must all have the same
         * characteristics, i.e. all inputs or all outputs, all active low etc
         * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set for a requested
         * line, this specifies the default output value, should be 0 (low) or
         * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)
         * @consumer_label: a desired consumer label for the selected GPIO line(s)
         * such as "my-bitbanged-relay"
         * @lines: number of lines requested in this request, i.e. the number of
         * valid fields in the above arrays, set to 1 to request a single line
         * @fd: if successful this field will contain a valid anonymous file handle
         * after a %GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value
         * means error
         *
         * Note: This struct is part of ABI v1 and is deprecated.
         * Use &struct gpio_v2_line_request instead.
         */
        struct gpiohandle_request {
        	__u32 lineoffsets[GPIOHANDLES_MAX];
        	__u32 flags;
        	__u8 default_values[GPIOHANDLES_MAX];
        	char consumer_label[GPIO_MAX_NAME_SIZE];
        	__u32 lines;
        	int fd;
        };

        ③GPIOHANDLE_SET_LINE_VALUES_IOCTL -> gpiohandle_data

            对应结构体描述

        /**
         * struct gpiohandle_data - Information of values on a GPIO handle
         * @values: when getting the state of lines this contains the current
         * state of a line, when setting the state of lines these should contain
         * the desired target state
         *
         * Note: This struct is part of ABI v1 and is deprecated.
         * Use &struct gpio_v2_line_values instead.
         */
        struct gpiohandle_data {
        	__u8 values[GPIOHANDLES_MAX];
        };

        2.2.3 include/linux/gpio.h 全部代码

        gpio.h整体内容如下 ,可以详细了解:

        /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
        /*
         *  - userspace ABI for the GPIO character devices
         *
         * Copyright (C) 2016 Linus Walleij
         *
         * This program is free software; you can redistribute it and/or modify it
         * under the terms of the GNU General Public License version 2 as published by
         * the Free Software Foundation.
         */
        #ifndef _UAPI_GPIO_H_
        #define _UAPI_GPIO_H_
        #include 
        #include 
        #include 
        /*
         * The maximum size of name and label arrays.
         *
         * Must be a multiple of 8 to ensure 32/64-bit alignment of structs.
         */
        #define GPIO_MAX_NAME_SIZE 32
        /**
         * struct gpiochip_info - Information about a certain GPIO chip
         * @name: the Linux kernel name of this GPIO chip
         * @label: a functional name for this GPIO chip, such as a product
         * number, may be empty (i.e. label[0] == '')
         * @lines: number of GPIO lines on this chip
         */
        struct gpiochip_info {
        	char name[GPIO_MAX_NAME_SIZE];
        	char label[GPIO_MAX_NAME_SIZE];
        	__u32 lines;
        };
        /*
         * Maximum number of requested lines.
         *
         * Must be no greater than 64, as bitmaps are restricted here to 64-bits
         * for simplicity, and a multiple of 2 to ensure 32/64-bit alignment of
         * structs.
         */
        #define GPIO_V2_LINES_MAX 64
        /*
         * The maximum number of configuration attributes associated with a line
         * request.
         */
        #define GPIO_V2_LINE_NUM_ATTRS_MAX 10
        /**
         * enum gpio_v2_line_flag - &struct gpio_v2_line_attribute.flags values
         * @GPIO_V2_LINE_FLAG_USED: line is not available for request
         * @GPIO_V2_LINE_FLAG_ACTIVE_LOW: line active state is physical low
         * @GPIO_V2_LINE_FLAG_INPUT: line is an input
         * @GPIO_V2_LINE_FLAG_OUTPUT: line is an output
         * @GPIO_V2_LINE_FLAG_EDGE_RISING: line detects rising (inactive to active)
         * edges
         * @GPIO_V2_LINE_FLAG_EDGE_FALLING: line detects falling (active to
         * inactive) edges
         * @GPIO_V2_LINE_FLAG_OPEN_DRAIN: line is an open drain output
         * @GPIO_V2_LINE_FLAG_OPEN_SOURCE: line is an open source output
         * @GPIO_V2_LINE_FLAG_BIAS_PULL_UP: line has pull-up bias enabled
         * @GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN: line has pull-down bias enabled
         * @GPIO_V2_LINE_FLAG_BIAS_DISABLED: line has bias disabled
         * @GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME: line events contain REALTIME timestamps
         */
        enum gpio_v2_line_flag {
        	GPIO_V2_LINE_FLAG_USED			= _BITULL(0),
        	GPIO_V2_LINE_FLAG_ACTIVE_LOW		= _BITULL(1),
        	GPIO_V2_LINE_FLAG_INPUT			= _BITULL(2),
        	GPIO_V2_LINE_FLAG_OUTPUT		= _BITULL(3),
        	GPIO_V2_LINE_FLAG_EDGE_RISING		= _BITULL(4),
        	GPIO_V2_LINE_FLAG_EDGE_FALLING		= _BITULL(5),
        	GPIO_V2_LINE_FLAG_OPEN_DRAIN		= _BITULL(6),
        	GPIO_V2_LINE_FLAG_OPEN_SOURCE		= _BITULL(7),
        	GPIO_V2_LINE_FLAG_BIAS_PULL_UP		= _BITULL(8),
        	GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN	= _BITULL(9),
        	GPIO_V2_LINE_FLAG_BIAS_DISABLED		= _BITULL(10),
        	GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME	= _BITULL(11),
        };
        /**
         * struct gpio_v2_line_values - Values of GPIO lines
         * @bits: a bitmap containing the value of the lines, set to 1 for active
         * and 0 for inactive.
         * @mask: a bitmap identifying the lines to get or set, with each bit
         * number corresponding to the index into &struct
         * gpio_v2_line_request.offsets.
         */
        struct gpio_v2_line_values {
        	__aligned_u64 bits;
        	__aligned_u64 mask;
        };
        /**
         * enum gpio_v2_line_attr_id - &struct gpio_v2_line_attribute.id values
         * identifying which field of the attribute union is in use.
         * @GPIO_V2_LINE_ATTR_ID_FLAGS: flags field is in use
         * @GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES: values field is in use
         * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us field is in use
         */
        enum gpio_v2_line_attr_id {
        	GPIO_V2_LINE_ATTR_ID_FLAGS		= 1,
        	GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES	= 2,
        	GPIO_V2_LINE_ATTR_ID_DEBOUNCE		= 3,
        };
        /**
         * struct gpio_v2_line_attribute - a configurable attribute of a line
         * @id: attribute identifier with value from &enum gpio_v2_line_attr_id
         * @padding: reserved for future use and must be zero filled
         * @flags: if id is %GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO
         * line, with values from &enum gpio_v2_line_flag, such as
         * %GPIO_V2_LINE_FLAG_ACTIVE_LOW, %GPIO_V2_LINE_FLAG_OUTPUT etc, added
         * together.  This overrides the default flags contained in the &struct
         * gpio_v2_line_config for the associated line.
         * @values: if id is %GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap
         * containing the values to which the lines will be set, with each bit
         * number corresponding to the index into &struct
         * gpio_v2_line_request.offsets.
         * @debounce_period_us: if id is %GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the
         * desired debounce period, in microseconds
         */
        struct gpio_v2_line_attribute {
        	__u32 id;
        	__u32 padding;
        	union {
        		__aligned_u64 flags;
        		__aligned_u64 values;
        		__u32 debounce_period_us;
        	};
        };
        /**
         * struct gpio_v2_line_config_attribute - a configuration attribute
         * associated with one or more of the requested lines.
         * @attr: the configurable attribute
         * @mask: a bitmap identifying the lines to which the attribute applies,
         * with each bit number corresponding to the index into &struct
         * gpio_v2_line_request.offsets.
         */
        struct gpio_v2_line_config_attribute {
        	struct gpio_v2_line_attribute attr;
        	__aligned_u64 mask;
        };
        /**
         * struct gpio_v2_line_config - Configuration for GPIO lines
         * @flags: flags for the GPIO lines, with values from &enum
         * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
         * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together.  This is the default for
         * all requested lines but may be overridden for particular lines using
         * @attrs.
         * @num_attrs: the number of attributes in @attrs
         * @padding: reserved for future use and must be zero filled
         * @attrs: the configuration attributes associated with the requested
         * lines.  Any attribute should only be associated with a particular line
         * once.  If an attribute is associated with a line multiple times then the
         * first occurrence (i.e. lowest index) has precedence.
         */
        struct gpio_v2_line_config {
        	__aligned_u64 flags;
        	__u32 num_attrs;
        	/* Pad to fill implicit padding and reserve space for future use. */
        	__u32 padding[5];
        	struct gpio_v2_line_config_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX];
        };
        /**
         * struct gpio_v2_line_request - Information about a request for GPIO lines
         * @offsets: an array of desired lines, specified by offset index for the
         * associated GPIO chip
         * @consumer: a desired consumer label for the selected GPIO lines such as
         * "my-bitbanged-relay"
         * @config: requested configuration for the lines.
         * @num_lines: number of lines requested in this request, i.e. the number
         * of valid fields in the %GPIO_V2_LINES_MAX sized arrays, set to 1 to
         * request a single line
         * @event_buffer_size: a suggested minimum number of line events that the
         * kernel should buffer.  This is only relevant if edge detection is
         * enabled in the configuration. Note that this is only a suggested value
         * and the kernel may allocate a larger buffer or cap the size of the
         * buffer. If this field is zero then the buffer size defaults to a minimum
         * of @num_lines * 16.
         * @padding: reserved for future use and must be zero filled
         * @fd: if successful this field will contain a valid anonymous file handle
         * after a %GPIO_GET_LINE_IOCTL operation, zero or negative value means
         * error
         */
        struct gpio_v2_line_request {
        	__u32 offsets[GPIO_V2_LINES_MAX];
        	char consumer[GPIO_MAX_NAME_SIZE];
        	struct gpio_v2_line_config config;
        	__u32 num_lines;
        	__u32 event_buffer_size;
        	/* Pad to fill implicit padding and reserve space for future use. */
        	__u32 padding[5];
        	__s32 fd;
        };
        /**
         * struct gpio_v2_line_info - Information about a certain GPIO line
         * @name: the name of this GPIO line, such as the output pin of the line on
         * the chip, a rail or a pin header name on a board, as specified by the
         * GPIO chip, may be empty (i.e. name[0] == '')
         * @consumer: a functional name for the consumer of this GPIO line as set
         * by whatever is using it, will be empty if there is no current user but
         * may also be empty if the consumer doesn't set this up
         * @offset: the local offset on this GPIO chip, fill this in when
         * requesting the line information from the kernel
         * @num_attrs: the number of attributes in @attrs
         * @flags: flags for this GPIO line, with values from &enum
         * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
         * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together.
         * @attrs: the configuration attributes associated with the line
         * @padding: reserved for future use
         */
        struct gpio_v2_line_info {
        	char name[GPIO_MAX_NAME_SIZE];
        	char consumer[GPIO_MAX_NAME_SIZE];
        	__u32 offset;
        	__u32 num_attrs;
        	__aligned_u64 flags;
        	struct gpio_v2_line_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX];
        	/* Space reserved for future use. */
        	__u32 padding[4];
        };
        /**
         * enum gpio_v2_line_changed_type - &struct gpio_v2_line_changed.event_type
         * values
         * @GPIO_V2_LINE_CHANGED_REQUESTED: line has been requested
         * @GPIO_V2_LINE_CHANGED_RELEASED: line has been released
         * @GPIO_V2_LINE_CHANGED_CONFIG: line has been reconfigured
         */
        enum gpio_v2_line_changed_type {
        	GPIO_V2_LINE_CHANGED_REQUESTED	= 1,
        	GPIO_V2_LINE_CHANGED_RELEASED	= 2,
        	GPIO_V2_LINE_CHANGED_CONFIG	= 3,
        };
        /**
         * struct gpio_v2_line_info_changed - Information about a change in status
         * of a GPIO line
         * @info: updated line information
         * @timestamp_ns: estimate of time of status change occurrence, in nanoseconds
         * @event_type: the type of change with a value from &enum
         * gpio_v2_line_changed_type
         * @padding: reserved for future use
         */
        struct gpio_v2_line_info_changed {
        	struct gpio_v2_line_info info;
        	__aligned_u64 timestamp_ns;
        	__u32 event_type;
        	/* Pad struct to 64-bit boundary and reserve space for future use. */
        	__u32 padding[5];
        };
        /**
         * enum gpio_v2_line_event_id - &struct gpio_v2_line_event.id values
         * @GPIO_V2_LINE_EVENT_RISING_EDGE: event triggered by a rising edge
         * @GPIO_V2_LINE_EVENT_FALLING_EDGE: event triggered by a falling edge
         */
        enum gpio_v2_line_event_id {
        	GPIO_V2_LINE_EVENT_RISING_EDGE	= 1,
        	GPIO_V2_LINE_EVENT_FALLING_EDGE	= 2,
        };
        /**
         * struct gpio_v2_line_event - The actual event being pushed to userspace
         * @timestamp_ns: best estimate of time of event occurrence, in nanoseconds.
         * @id: event identifier with value from &enum gpio_v2_line_event_id
         * @offset: the offset of the line that triggered the event
         * @seqno: the sequence number for this event in the sequence of events for
         * all the lines in this line request
         * @line_seqno: the sequence number for this event in the sequence of
         * events on this particular line
         * @padding: reserved for future use
         *
         * By default the @timestamp_ns is read from %CLOCK_MONOTONIC and is
         * intended to allow the accurate measurement of the time between events.
         * It does not provide the wall-clock time.
         *
         * If the %GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME flag is set then the
         * @timestamp_ns is read from %CLOCK_REALTIME.
         */
        struct gpio_v2_line_event {
        	__aligned_u64 timestamp_ns;
        	__u32 id;
        	__u32 offset;
        	__u32 seqno;
        	__u32 line_seqno;
        	/* Space reserved for future use. */
        	__u32 padding[6];
        };
        /*
         * ABI v1
         *
         * This version of the ABI is deprecated.
         * Use the latest version of the ABI, defined above, instead.
         */
        /* Informational flags */
        #define GPIOLINE_FLAG_KERNEL		(1UL 

0
收藏0
文章版权声明:除非注明,否则均为VPS857原创文章,转载或复制请以超链接形式并注明出处。

相关阅读

  • 【研发日记】Matlab/Simulink自动生成代码(二)——五种选择结构实现方法,Matlab/Simulink自动生成代码的五种选择结构实现方法(二),Matlab/Simulink自动生成代码的五种选择结构实现方法详解(二)
  • 超级好用的C++实用库之跨平台实用方法,跨平台实用方法的C++实用库超好用指南,C++跨平台实用库使用指南,超好用实用方法集合,C++跨平台实用库超好用指南,方法与技巧集合
  • 【动态规划】斐波那契数列模型(C++),斐波那契数列模型(C++实现与动态规划解析),斐波那契数列模型解析与C++实现(动态规划)
  • 【C++】,string类底层的模拟实现,C++中string类的模拟底层实现探究
  • uniapp 小程序实现微信授权登录(前端和后端),Uniapp小程序实现微信授权登录全流程(前端后端全攻略),Uniapp小程序微信授权登录全流程攻略,前端后端全指南
  • Vue脚手架的安装(保姆级教程),Vue脚手架保姆级安装教程,Vue脚手架保姆级安装指南,Vue脚手架保姆级安装指南,从零开始教你如何安装Vue脚手架
  • 如何在树莓派 Raspberry Pi中本地部署一个web站点并实现无公网IP远程访问,树莓派上本地部署Web站点及无公网IP远程访问指南,树莓派部署Web站点及无公网IP远程访问指南,本地部署与远程访问实践,树莓派部署Web站点及无公网IP远程访问实践指南,树莓派部署Web站点及无公网IP远程访问实践指南,本地部署与远程访问详解,树莓派部署Web站点及无公网IP远程访问实践详解,本地部署与远程访问指南,树莓派部署Web站点及无公网IP远程访问实践详解,本地部署与远程访问指南。
  • vue2技术栈实现AI问答机器人功能(流式与非流式两种接口方法),Vue2技术栈实现AI问答机器人功能,流式与非流式接口方法探究,Vue2技术栈实现AI问答机器人功能,流式与非流式接口方法详解
  • 发表评论

    快捷回复:表情:
    评论列表 (暂无评论,0人围观)

    还没有评论,来说两句吧...

    目录[+]

    取消
    微信二维码
    微信二维码
    支付宝二维码