12 063
правки
(не показано 17 промежуточных версий этого же участника) | |||
Строка 10: | Строка 10: | ||
On some | On some GPIOs (particularly at the 3 GPIOs, launched into terminals in Wiren Board rev. 2.8) can be programmatically set to lift 47K + 3.3V. See. [[Special:MyLanguage/Pin_pull-up|Pin_pull-up]]. | ||
=== sysfs interface | === sysfs interface in Linux === | ||
GPIOs in Linux are supported through sysfs-interface. | |||
To work | To work via sysfs a certain GPIO must be exported: | ||
Here and further N | Here and further N is a number of gpio | ||
<pre> | <pre> | ||
Строка 38: | Строка 38: | ||
</pre> | </pre> | ||
The | The folder <b>/sys/class/gpioN</b> now contains files to work with GPIO (where N is a GPIO number): | ||
<pre> | <pre> | ||
Строка 55: | Строка 55: | ||
<pre> | <pre> | ||
echo in > /sys/class/gpio/gpioN/direction #set the GPIO to input | echo in > /sys/class/gpio/gpioN/direction #set the GPIO N to input | ||
echo out > /sys/class/gpio/gpioN/direction # set the GPIO to output | echo out > /sys/class/gpio/gpioN/direction # set the GPIO N to output | ||
</pre> | </pre> | ||
Reading and | Reading and setting the GPIO is made using the file <b>value</b>. | ||
Reading: | Reading: | ||
Строка 107: | Строка 107: | ||
Interrupts can be caught from userspace using the system call | Interrupts can be caught from userspace using the system call epoll () and select () on file value. | ||
See example here [https://github.com/contactless/wiegand-linux-sysfs] | |||
see also [http://elinux.org/GPIO elinux.org] | see also [http://elinux.org/GPIO elinux.org] | ||
Строка 115: | Строка 115: | ||
===Direct access by processor memory=== | ===Direct access by processor memory=== | ||
<b>This method is strongly | <b>This method is NOT strongly recommended for use without sufficient reason. To work in C / C ++ is to use the files to work through sysfs, as described in the previous section</b>. | ||
You can manage GPIO using the direct access to the processor registers, bypassing the Linux interface/dev/mem. At the same time, compared to the work via sysfs, this case minimizes costs. This method can be used, | |||
if you need a very fast access to GPIO, such bitbang protocols or PWM. It should be borne in mind that the process scheduler can still contribute to the work program of significant delays. | if you need a very fast access to GPIO, such bitbang protocols or PWM. It should be borne in mind that the process scheduler can still contribute to the work program of significant delays. | ||
It is recommended to make time-critical tasks in the kernel. | It is recommended to make time-critical tasks in the kernel. | ||
Строка 126: | Строка 126: | ||
===GPIO and Device Tree=== | ===GPIO and Device Tree=== | ||
It's necessary to place the GPIO in Device Tree to configure the GPIO to work in a mode of software SPI, I2C, for GPIO to be used as the source of the interrupt, etc. | |||
For example on a pin 10 @ UEXT1 (CS) and pins 5 @ UEXT2 (SCL), 6 @ UEXT2 (SDA), 10 @ UEXT2 (CS) | For example on a pin 10 @ UEXT1 (CS) and pins 5 @ UEXT2 (SCL), 6 @ UEXT2 (SDA), 10 @ UEXT2 (CS) GPIO processor lines are derived. They can be configured to use such as a chip-select for SPI or as I2C. | ||
The processor's and peripherals' GPIOs are divided into banks (gpio chip).Processor's GPIO are split into 3 banks for 32 GPIO: gpio0, gpio1, gpio2. Addressing GPIO in Device Tree comes to the number of the bank and the number of GPIO * in * the bank. | |||
====Example 1==== | ====Example 1==== | ||
We define signal 6 @ UEXT2 (SDA) as the source of the interrupt driver mrf24j40. According to the table [[Special: MyLanguage / | We define signal 6 @ UEXT2 (SDA) as the source of the interrupt driver mrf24j40. According to the table [[Special:MyLanguage/Список_GPIO/en|List of GPIOs]], signal corresponds to 53 GPIO of processor. 53 belongs to the second bank gpio (32 to 63). GPIO number inside the bank 53-32 = 21: | ||
<pre> | <pre> |
правки