Skip to content

Commit dfbf36a

Browse files
committed
[Docs] Added new sections to the docs and fixed issues
1 parent cb60a76 commit dfbf36a

File tree

3 files changed

+84
-37
lines changed

3 files changed

+84
-37
lines changed
File renamed without changes.
File renamed without changes.

docs/source/api/gpio.rst

Lines changed: 84 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,140 @@ GPIO
55
About
66
-----
77

8-
GPIO (General Purpouse Input Output) is peripheral responsible to controls reception and
9-
deliver digital signals by means of easy interface acess with world, physical pins.
8+
One of the most used and versatile peripheral in a microcontroller is the GPIO. The GPIO is commonly used to write and read the pin state.
109

11-
Fetures of this peripheral relates with largely quantity pins available on chip, also being
12-
this programmable and configurable. An example of interaction happen when turn on LED or pulse control a button.
10+
GPIO stands to General Purpose Input Output, and is responsible to control or read the state of a specific pin in the digital world. For example, this peripheral is widely used to create the LED blinking or to read a simple button.
1311

14-
.. note::
15-
There are some GPIOs with special functions and not all the is accessible in all development board. For more information strong suggest acess datasheet_.
12+
.. note:: There are some GPIOs with special restrictions, and not all GPIOs are accessible through the developemnt board. For more information about it, see the corresponding board pin layout information.
1613

17-
GPIOs Configuration
18-
*******************
14+
GPIOs Modes
15+
***********
1916

20-
The GPIOs used two different configuration :
17+
There are two different modes in the GPIO configuration:
2118

22-
- **Input**
19+
- **Input Mode**
2320

24-
- Receive external digital signals
25-
21+
In this mode, the GPIO will receive the digital state from a specific device. This device could be a button or a switch.
2622

27-
- **Output**
23+
- **Output Mode**
2824

29-
- Send internal digital signals
25+
For the output mode, the GPIO will change the GPIO digital state to a specific device. You can drive an LED for example.
3026

27+
GPIO API
28+
--------
3129

32-
Arduino - ESP32 API
33-
-------------------------
34-
Here are description of frequently used functions for GPIOs
30+
Here is the common functions used for the GPIO peripheral.
3531

3632
pinMode
37-
***********
38-
39-
Initial configuration for use pin with input or output.
33+
*******
4034

35+
The ``pinMode`` function is used to define the GPIO operation mode for a specific pin.
4136

4237
.. code-block:: arduino
4338
4439
void pinMode(uint8_t pin, uint8_t mode);
4540
46-
* ``pin`` select GPIO
47-
* ``mode`` sets mode operation (``INPUT``, ``OUTPUT`` or ``INPUT_PULLUP``, ).
41+
* ``pin`` defines the GPIO pin number.
42+
* ``mode`` sets operation mode.
43+
44+
The following modes are supported for the basic `input` and `output`:
45+
46+
* **INPUT** sets the GPIO as input without pullup or pulldown (high impedance).
47+
* **OUTPUT** sets the GPIO as output/read mode.
48+
* **INPUT_PULLDOWN** sets the GPIO as input with the internal pulldown.
49+
* **INPUT_PULLUP** sets the GPIO as input with the internal pullup.
50+
51+
Internal Pullup and Pulldown
52+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53+
54+
The ESP32 SoC families supports the internal pullup and pulldown throught a 45kR resistor, that can be enabled when configuring the GPIO mode as ``INPUT`` mode.
55+
If the pullup or pulldown mode is not defined, the pin will stay in the high impedance mode.
4856

4957
digitalWrite
5058
*************
5159

52-
Write digital signal on pin.
60+
The function ``digitalWrite`` sets the state of the selected GPIO to ``HIGH`` or ``LOW``. This function is only used if the ``pinMode`` was configured as ``OUTPUT``.
5361

5462
.. code-block:: arduino
5563
5664
void digitalWrite(uint8_t pin, uint8_t val);
5765
58-
* ``pin`` select a GPIO
59-
* ``val`` logic level write on pin (``HIGH`` or ``LOW``)
60-
61-
.. warning::
62-
If pin not set to ``OUTPUT`` on pinMode(), may not work correct.
66+
* ``pin`` defines the GPIO pin number.
67+
* ``val`` set the output digital state to ``HIGH`` or ``LOW``.
6368

6469
digitalRead
6570
***********
6671

67-
Read digital pin signal picked
72+
To read the state of a given pin configured as ``INPUT``, the function ``digitalRead`` is used.
6873

6974
.. code-block:: arduino
7075
7176
int digitalRead(uint8_t pin);
7277
7378
* ``pin`` select GPIO
7479

75-
This function will be return logical state ``HIGH`` or ``LOW``
80+
This function will return the logical state of the selecetd pin as ``HIGH`` or ``LOW``.
7681

77-
Simulation
82+
Interrupts
7883
----------
7984

80-
This application helps understand concepts using dynamic simulation provide by `Wokwi`_, test the gpio code and start.
85+
The GPIO peripheral on the ESP32 supports interruptions.
86+
87+
attachInterrupt
88+
***************
89+
90+
The function ``attachInterruptArg`` is used to attach the interrupt to the defined pin.
91+
92+
.. code-block:: arduino
93+
94+
attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode);
8195
82-
.. raw:: html
96+
* ``pin`` defines the GPIO pin number.
97+
* ``handler`` set the handler function.
98+
* ``mode`` set the interrupt mode.
8399

84-
<iframe src="https://wokwi.com/arduino/projects/314835473253007936" width="100%" height="400" border="0"></iframe>
100+
Here are the supported interrupt modes:
85101

102+
* **DISABLED**
103+
* **RISING**
104+
* **FALLING**
105+
* **CHANGE**
106+
* **ONLOW**
107+
* **ONHIGH**
108+
* **ONLOW_WE**
109+
* **ONHIGH_WE**
110+
111+
attachInterruptArg
112+
******************
113+
114+
The function ``attachInterruptArg`` is used to attach the interrupt to the defined pin using arguments.
115+
116+
.. code-block:: arduino
117+
118+
attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void * arg, int mode);
119+
120+
* ``pin`` defines the GPIO pin number.
121+
* ``handler`` set the handler function.
122+
* ``arg`` pointer to the interrupt arguments.
123+
* ``mode`` set the interrupt mode.
124+
125+
detachInterrupt
126+
***************
127+
128+
To detach the interruption from a specific pin, use the ``detachInterrupt`` function giving the GPIO to be detached.
129+
130+
.. code-block:: arduino
131+
132+
detachInterrupt(uint8_t pin);
133+
134+
* ``pin`` defines the GPIO pin number.
86135

87136
.. _gpio_example_code:
88137

89138
Example Code
90139
-------------
91140

92-
Here is full code for example application of GPIOs
141+
Here is the full code for the GPIO application example.
93142

94143
.. code-block::
95144
@@ -113,5 +162,3 @@ Here is full code for example application of GPIOs
113162
114163
.. _Wokwi: https://wokwi.com/
115164
.. _datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf
116-
117-

0 commit comments

Comments
 (0)