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 |
Previous article:s3c2440 ontxt novel reader
Next article:S3C2440 FCLK, HCLK, PCLK configuration
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Let me ask, what are the most cutting-edge energy storage technologies currently?
- Review summary: Free review: The cheapest Hongmeng development board Neptune is here
- Has anyone used the software every circuit?
- Excuse me, is there any tutorial for assembling MCS-51 microcontroller?
- [Hardcore Science] What is a bipolar four-quadrant power supply? Is the power amplifier also a bipolar four-quadrant power supply?
- Nonvolatile MRAM and its cell structure
- FPGA controls DSP power-on reset procedure
- Ask for help, recommendation, keywords
- It's holiday time, but we're still working overtime every day
- Why use WDM-PON in 5G fronthaul