Cubieboard official gpio driver usage Summary

Source: Internet
Author: User

I recently referred to the gpio operation tutorial of tll and finally completed the gpio control operation of CB.
The operating system used by the Board is the linaro official IMG of the official standard System Version 1.1, which already contains the gpio driver file.
1. Official driver for gpio-sunxi.ko, located in/lib/modules/3.0.62/kernel/Drivers/gpio/gpio-sunxi.ko.
2. Because the driver module is not loaded after the system is started, you need to insert it yourself and use the insmod command. Then lsmod can see gpio-sunxi.
Of course you can also edit/etc/modules and add a gpio-sunxi.ko to it. After the restart, lsmod checks whether it has been loaded.
3. After the driver is loaded, you can operate the gpio port.
The operation on the gpio port requires the following three steps:
1). Specify the port number to be operated.
Echo 4>/sys/class/gpio/Export
Ls/sys/class/gpio
The port folder gpio4-pe4 we need appears,
If Echo 1>/sys/class/gpio/export appears gpio1-pe1.
2) Open the gpio4-pe4, or ls gpio4-pe4, you can see the files in the gpio4-pe4, there are 2 files related to our operation:
They are ction and value. We can see that they represent the direction of the port and the value of the port respectively.
For direction, you can write echo out>/sys/class/gpio/gpio4-pe4/direction to set this port to the output end. If this parameter is not set, no response is returned when data is written.
3) set or clear the port.
Set or clear the port by writing 1 or 0 to the value file.
Echo 1>/sys/class/gpio/gpio4-pe4/value; Set 1.
The above three steps can be used to select, set, and use the gpio port.
However, problems found and solutions are as follows:
1 gpio-sunxi.ko driver will not be automatically loaded by the system, each time you need to load your own, more trouble.
Solution: edit/etc/modules to add the gpio driver module. After each restart, the system automatically loads the gpio module.
2. After each system restart, you must reset the gpio port and configure the port direction.
Solution: edit/etc/rc. Local and add
Echo 1>/sys/class/gpio/Export
Echo out>/sys/class/gpio/gpio4-pe4/Direction
Select the gpip port and set the port.
3. the CHMOD permission is required for/sys operations. Chmod-r 777/sys.
This also requires editing/etc/rc. Local.

In addition, this time I used CB to implement a function similar to TTL smart door lock. I used a mobile phone to control the lighting.
The basic architecture is also the use of lnmp as the server, the use of PHP language/sys/class/gpio/gpio4-pe4/value read and write operations to complete.
Note the website directory settings of the nginx server. The previous settings in/etc/nginx/www/cannot complete the operations on/sys.
Later, I modified the website directory and directly set it to/to complete the operations on the/sys file.

After studying gpio over the past few days, I feel that Linux users are very powerful. Haha !!!!


Flyword
Http://forum.cubietech.com/forum.php? MoD = viewthread & tid = 725 & Highlight = gpio

Cubieboard official gpio driver usage Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.