简体   繁体   中英

How to control/check gpio states with shell commands (at91sam9260 board)

I need to write a script that controls and checks the gpio states.

I have been trying for a while to find a way to do it, but I didn't succeed.

Here is for the details : I use an at91sam9260 board with a Linux kernel 2.6.27 embedded in it.

I see the /dev/gpio device I tried some commands like cat /dev/gpio OR echo 1> /dev/gpio but it did not give me any result ( except an error message for the first command)

I also tried to create /dev/gpio0 .. to /dev/gpio31 (with the makedev command before recompiling the CRAMFS filesystem, but I did not get more results.

Does someone know how to check these gpio states and set/clear some of them ?

More generally, Is there an easy way to find out the proper shell commands for a particular device just by looking at the driver source files ?

If your kernel has sysfs support you can access and control the gpio pins through the interface in /sys/class/gpio . See the sysfs section of the kernel document in Documentation/gpio.txt .

I have used at91sam9260. You can set/unset the gpio pins using sysfs interface. for ex. go to: cd /sys/class/gpio and then "echo 2 > export" and then set the directions of gpio pins to input(in)/output(out) by "echo in > direction" and then you can read the value from "value" file by "cat value"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM