/sys/class/gpio file interface operation IO port (s3c2440)

Publisher:心灵舞动Latest update time:2024-07-26 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The operation of GPIO is the most basic operation in embedded devices. The general approach is to write a separate driver, which is the case in most examples on the Internet. In fact, there is a universal GPIO operation interface under Linux, which is the "/sys/class/gpio" method I will introduce.

First, check if there is a folder called "/sys/class/gpio" in the system. If not, add it to Device Drivers —> GPIO Support —> /sys/class/gpio/… (sysfs interface) when compiling the kernel.

Instructions for using /sys/class/gpio:

01 gpio_operation operates the IO port GPIO to the file system mapping through the /sys/ file interface

class/gpio

The class/gpio/export file is used to inform the system of the GPIO pin number that needs to be exported for control

class/gpio/unexport is used to notify the system to cancel the export

The class/gpio/gpiochipX directory stores the information of the GPIO registers in the system, including the starting number base, register name, and total number of pins controlled by each register. The steps to export a pin

07 * To the /sys/class/gpio/gpio12 directory, if no corresponding directory appears, it means that this pin cannot be exported:

class/gpio/export

10 echo out > direction
12 * The value file is the numerical value of the port, which is 1 or 0.

class/gpio

for i in gpiochip* ;

2 GPIOE: 128
4 GPIOG: 192
6 GPIOB: 32
8 GPIOD: 96

2. Calculate GPIO number

We use GPE11 to control LED.

The header of GPE0 is 128, and that of GPE11 is 128+11 = 139.

1 $ echo 139 > /sys/

class

/gpio/gpio139/direction

Then you can configure the output settings.

1 $ echo 1 > /sys/

class

/gpio/gpio139/value


Reference address:/sys/class/gpio file interface operation IO port (s3c2440)

Previous article:s3c2440 ontxt novel reader
Next article:S3C2440 FCLK, HCLK, PCLK configuration

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号