Skip to content

Commit 0b10c8b

Browse files
authored
[Docs] Added the guideline for documentation (espressif#6409)
* [Docs] Added the guideline for documentation * [Docs] Added more descriptions about the API documenting process * [Docs] PR review * [Docs] PR review and minor typos and grammar fixes
1 parent d977359 commit 0b10c8b

File tree

1 file changed

+334
-0
lines changed

1 file changed

+334
-0
lines changed

Diff for: docs/source/guides/docs_contributing.rst

+334
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
#####################################
2+
Documentation Contribution Guidelines
3+
#####################################
4+
5+
Introduction
6+
------------
7+
8+
This is a guideline for the Arduino ESP32 project documentation. The idea for this guideline is to show how to start collaborating on the project.
9+
10+
The guideline works to give you the directions and to keep the documentation more concise, helping users to better understand the structure.
11+
12+
About Documentation
13+
-------------------
14+
15+
We all know how important documentation is. This project is no different.
16+
17+
This documentation was created in a collaborative and open way, letting everyone contribute, from a small typo fix to a new chapter writing. We try to motivate our community by giving all the support needed through this guide.
18+
19+
The documentation is in **English only**. Future translations can be added when we finish the essential content in English first.
20+
21+
How to Collaborate
22+
------------------
23+
24+
Everyone with some knowledge to share is welcome to collaborate.
25+
26+
One thing you need to consider is the fact that your contribution must be concise and assertive since it will be used by people developing projects. The information is very important for everyone, be sure you are not making the developer's life harder!
27+
28+
Documentation Guide
29+
-------------------
30+
31+
This documentation is based on the `Sphinx`_ with `reStructuredText`_ and hosted by `ReadTheDocs`_.
32+
33+
If you want to get started with `Sphinx`_, see the official documentation:
34+
35+
* `Documentation Index <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
36+
* `Basics <https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html>`_
37+
* `Directives <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html>`_
38+
39+
First Steps
40+
***********
41+
42+
Before starting your collaboration, you need to get the documentation source code from the Arduino-ESP32 project.
43+
44+
* **Step 1** - Fork the `Arduino-ESP32`_ to your GitHub account.
45+
* **Step 2** - Check out the recently created fork.
46+
* **Step 3** - Create a new branch for the changes/addition to the docs.
47+
* **Step 4** - Write!
48+
49+
Requirements
50+
************
51+
52+
To properly work with the documentation, you need to install some packages in your system.
53+
54+
.. code-block::
55+
56+
pip install -U Sphinx
57+
pip install -r requirements.txt
58+
59+
The requirements file is under the ``docs`` folder.
60+
61+
Using Visual Studio Code
62+
************************
63+
64+
If you are using the Visual Studio Code, you can install some extensions to help you while writing documentation.
65+
66+
`reStructuredText Pack <https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext-pack>`_
67+
68+
We also recommend you install to grammar check extension to help you to review English grammar.
69+
70+
`Grammarly <https://marketplace.visualstudio.com/items?itemName=znck.grammarly>`_
71+
72+
Building
73+
********
74+
75+
To build the documentation and generate the HTLM files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the `build/html` folder.
76+
77+
.. code-block::
78+
79+
make html
80+
81+
This step is essential to ensure that there are no syntax errors and also to see the final result.
82+
83+
If everything is ok, you will see some output logs similar to this one:
84+
85+
.. code-block::
86+
87+
Running Sphinx v2.3.1
88+
loading pickled environment... done
89+
building [mo]: targets for 0 po files that are out of date
90+
building [html]: targets for 35 source files that are out of date
91+
updating environment: [extensions changed ('sphinx_tabs.tabs')] 41 added, 3 changed, 0 removed
92+
reading sources... [100%] tutorials/tutorials
93+
looking for now-outdated files... none found
94+
pickling environment... done
95+
checking consistency... done
96+
preparing documents... done
97+
writing output... [100%] tutorials/tutorials
98+
generating indices... genindexdone
99+
writing additional pages... searchdone
100+
copying images... [100%] tutorials/../_static/tutorials/peripherals/tutorial_peripheral_diagram.png
101+
copying static files... ... done
102+
copying extra files... done
103+
dumping search index in English (code: en)... done
104+
dumping object inventory... done
105+
build succeeded.
106+
107+
The HTML pages are in build/html.
108+
109+
Sections
110+
--------
111+
112+
The Arduino ESP32 is structured in some sections to make it easier to maintain. Here is a brief description of this structure.
113+
114+
API
115+
***
116+
117+
In this section, you will include all the documentation about drivers, libraries, and any other related to the core.
118+
119+
In this section, we do not add general information. For more general information, we have sections for other related parts, like the FAQ, library builder, troubleshooting, etc.
120+
121+
Boards
122+
******
123+
124+
Here is the place to add any special guide on the development boards, pin layout, schematics, and any other relevant content.
125+
126+
Common
127+
******
128+
129+
In this folder, you can add all common information used in several different places. This helps to make documentation easily maintainable.
130+
131+
132+
Guides
133+
******
134+
135+
This is the place to add the guides for common applications, IDEs configuration, and any other information that can be used as a guideline.
136+
137+
Tutorials
138+
*********
139+
140+
If you want to add a specific tutorial related to the Arduino core for ESP32, this is the place. The intention is not to create a blog or a demo area, but this can be used to add some complex description or to add some more information about APIs.
141+
142+
Images and Assets
143+
*****************
144+
145+
All the files used on the documentation must be stored in the ``_static`` folder. Be sure that the content used is not with any copyright restriction.
146+
147+
Documentation Rules
148+
-------------------
149+
150+
Here are some guidelines to help you. We also recommend copying a sample file from the same category you are creating.
151+
152+
This will help you to follow the structure as well as to get inspired.
153+
154+
Basic Structure
155+
***************
156+
157+
To help you create a new section from scratch, we recommend you include this structure in your content if it applies.
158+
159+
* **About** - Brief description of the document.
160+
* Description of the peripheral, driver, protocol, including all different modes and configurations.
161+
* **API** - Description of each public function, macros, and structs.
162+
* **Basic Usage**
163+
* **Example Application**
164+
165+
About Section
166+
^^^^^^^^^^^^^
167+
168+
In this section, you need to add a brief description of the API. If you are describing a peripheral API, you should explain a little bit about the peripheral and the working modes, if it's applicable.
169+
170+
API Functions
171+
^^^^^^^^^^^^^
172+
173+
To add a new function description, you must know that the users only have access to the public functions.
174+
175+
176+
Here is an example of how to add the function description from `I2C API <https://docs.espressif.com/projects/arduino-esp32/en/latest/api/i2c.html>`_:
177+
178+
.. code-block::
179+
180+
setPins
181+
^^^^^^^
182+
183+
This function is used to define the ``SDA`` and ``SCL`` pins.
184+
185+
.. note:: Call this function before ``begin`` to change the pins from the default ones.
186+
187+
.. code-block:: arduino
188+
189+
bool setPins(int sdaPin, int sclPin);
190+
191+
* ``sdaPin`` sets the GPIO to be used as the I2C peripheral data line.
192+
193+
* ``sclPin`` sets the GPIO to be used as the I2C peripheral clock line.
194+
195+
The default pins may vary from board to board. On the *Generic ESP32* the default I2C pins are:
196+
197+
* ``sdaPin`` **GPIO21**
198+
199+
* ``sclPin`` **GPIO22**
200+
201+
This function will return ``true`` if the peripheral was configured correctly.
202+
203+
Be sure to include a very comprehensive description, add all the parameters in and out, and describe the desired output.
204+
205+
If the function uses a specific structure, you can also describe the structure in the same function block or add a specific section if the structure is shared with other functions.
206+
207+
Basic Usage
208+
^^^^^^^^^^^
209+
210+
Some APIs are more complex to use or require more steps in order to configure or initialize. If the API is not straightforward in terms of usability, please consider adding a how-to-use section describing all the steps to get the API configured.
211+
212+
Here is an example:
213+
214+
.. code-block::
215+
216+
Basic Usage
217+
^^^^^^^^^^^
218+
219+
To start using I2C as slave mode on the Arduino, the first step is to include the ``Wire.h`` header to the sketch.
220+
221+
.. code-block:: arduino
222+
223+
#include "Wire.h"
224+
225+
Before calling ``begin``, you must create two callback functions to handle the communication with the master device.
226+
227+
.. code-block:: arduino
228+
229+
Wire.onReceive(onReceive);
230+
231+
and
232+
233+
.. code-block:: arduino
234+
235+
Wire.onRequest(onRequest);
236+
237+
The ``onReceive`` will handle the request from the ``master`` device upon a slave read request and the ``onRequest`` will handle the answer to the master.
238+
239+
Now, we can start the peripheral configuration by calling ``begin`` function with the device address.
240+
241+
.. code-block:: arduino
242+
243+
Wire.begin((uint8_t)I2C_DEV_ADDR);
244+
245+
By using ``begin`` without any arguments, all the settings will be done by using the default values. To set the values on your own, see the function description. This function is described here: `i2c begin`_
246+
247+
248+
249+
Example Application
250+
^^^^^^^^^^^^^^^^^^^
251+
It is very important to include at least one application example or a code snippet to help people using the API.
252+
253+
If the API does not have any application example, you can embed the code directly. However, if the example is available, you must include it as a literal block.
254+
255+
.. code-block::
256+
257+
.. literalinclude:: ../../../libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
258+
:language: arduino
259+
260+
261+
Sphinx Basics
262+
-------------
263+
264+
Heading Levels
265+
**************
266+
267+
The heading levels used on this documentation are:
268+
269+
* **H1**: - (Dash)
270+
* **H2**: * (Asterisk)
271+
* **H3**: ^ (Circumflex)
272+
* **H4**: # (Sharp)
273+
274+
Code Block
275+
**********
276+
277+
To add a code block, you can use the following structure:
278+
279+
.. code-block::
280+
281+
.. code-block:: arduino
282+
bool begin(); //Code example
283+
284+
Links
285+
*****
286+
287+
To include links to external content, you can use two ways.
288+
289+
* First option:
290+
291+
.. code-block::
292+
293+
`Arduino Wire Library`_
294+
295+
_Arduino Wire Library: https://www.arduino.cc/en/reference/wire
296+
297+
* Second option:
298+
299+
.. code-block::
300+
301+
`Arduino Wire Library <https://www.arduino.cc/en/reference/wire>`_
302+
303+
Images
304+
******
305+
306+
To include images in the docs, first, add all the files into the ``_static`` folder with a filename that makes sense for the topic.
307+
308+
After that, you can use the following structure to include the image in the docs.
309+
310+
.. code-block::
311+
312+
.. figure:: ../_static/arduino_i2c_master.png
313+
:align: center
314+
:width: 720
315+
:figclass: align-center
316+
317+
You can adjust the ``width`` according to the image size.
318+
319+
Be sure the file size does not exceed 600kB.
320+
321+
Support
322+
*******
323+
324+
If you need support on the documentation, you can ask a question in the discussion `here <https://github.com/espressif/arduino-esp32/discussions>`_.
325+
326+
Additional Guidelines
327+
---------------------
328+
329+
If you want to contribute with code on the Arduino ESP32 core, be sure to follow the `ESP-IDF Documenting Code <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/contribute/documenting-code.html>`_ as a reference.
330+
331+
.. _Arduino-ESP32: https://github.com/espressif/arduino-esp32
332+
.. _Sphinx: https://www.sphinx-doc.org/en/master/
333+
.. _ReadTheDocs: https://readthedocs.org/
334+
.. _reStructuredText: https://docutils.sourceforge.io/rst.html

0 commit comments

Comments
 (0)