Skip to content

Commit f2f4647

Browse files
committed
[Docs] Added more descriptions about the API documenting process
1 parent 5e09c5c commit f2f4647

File tree

1 file changed

+109
-6
lines changed

1 file changed

+109
-6
lines changed

docs/source/guides/docs_contributing.rst

+109-6
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,110 @@ Basic Structure
154154

155155
To help you create a new section from scratch, we recommend you include this structure in your content if it applies.
156156

157-
* Brief description of the document.
158-
* Description of the peripheral, driver, protocol, including all different modes and configurations.
159-
* Description of each public function, macros, and structs.
160-
* If it's relevant for the user or if it's used in the example must be included in the description.
161-
* How to use.
162-
* Example code from the examples folder or code snippet.
157+
* **About** - Brief description of the document.
158+
* Description of the peripheral, driver, protocol, including all different modes and configurations.
159+
* **API** - Description of each public function, macros, and structs.
160+
* **Basic Usage**
161+
* **Example Application**
162+
163+
About Section
164+
^^^^^^^^^^^^^
165+
166+
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.
167+
168+
API Functions
169+
^^^^^^^^^^^^^
170+
171+
To add a new function description, you must have in mind that the users only have access to the public functions.
172+
173+
174+
Here is an example on how to add the function description from `I2C API <https://docs.espressif.com/projects/arduino-esp32/en/latest/api/i2c.html>`_:
175+
176+
.. code-block::
177+
178+
setPins
179+
^^^^^^^
180+
181+
This function is used to define the ``SDA`` and ``SCL`` pins.
182+
183+
.. note:: Call this function before ``begin`` to change the pins from the default ones.
184+
185+
.. code-block:: arduino
186+
187+
bool setPins(int sdaPin, int sclPin);
188+
189+
* ``sdaPin`` sets the GPIO to be used as the I2C peripheral data line.
190+
191+
* ``sclPin`` sets the GPIO to be used as the I2C peripheral clock line.
192+
193+
The default pins may vary from board to board. On the *Generic ESP32* the default I2C pins are:
194+
195+
* ``sdaPin`` **GPIO21**
196+
197+
* ``sclPin`` **GPIO22**
198+
199+
This function will return ``true`` if the peripheral was configured correctly.
200+
201+
Be sure to include a very comprehensive description, add all the parameters in and out, and describe the desired output.
202+
203+
If the function use a spacific 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.
204+
205+
Basic Usage
206+
^^^^^^^^^^^
207+
208+
Some APIs are more complex to use or require more steps in order to configure or initialize. If the API is not straight forward in terms of usalibilty, plese consider adding a how to use section, describing all the steps to get the API configured.
209+
210+
Here is an example:
211+
212+
.. code-block::
213+
214+
Basic Usage
215+
^^^^^^^^^^^
216+
217+
To start using I2C as slave mode on the Arduino, the first step is to include the ``Wire.h`` header to the scketch.
218+
219+
.. code-block:: arduino
220+
221+
#include "Wire.h"
222+
223+
Before calling ``begin`` we must create two callback functions to handle the communication with the master device.
224+
225+
.. code-block:: arduino
226+
227+
Wire.onReceive(onReceive);
228+
229+
and
230+
231+
.. code-block:: arduino
232+
233+
Wire.onRequest(onRequest);
234+
235+
The ``onReceive`` will handle the request from the master device uppon a slave read request and the ``onRequest`` will handle the answer to the master.
236+
237+
Now, we can start the peripheral configuration by calling ``begin`` function with the device address.
238+
239+
.. code-block:: arduino
240+
241+
Wire.begin((uint8_t)I2C_DEV_ADDR);
242+
243+
By using ``begin`` without any arguments, all the settings will be done by using the default values. To set the values by your own, see the function description. This function is described here: `i2c begin`_
244+
245+
246+
247+
Example Application
248+
^^^^^^^^^^^^^^^^^^^
249+
It is very important to include at least one application example or a code snippet to help people using the API.
250+
251+
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.
252+
253+
.. code-block::
254+
255+
.. literalinclude:: ../../../libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
256+
:language: arduino
257+
258+
259+
Sphinx Basics
260+
-------------
163261

164262
Heading Levels
165263
**************
@@ -221,6 +319,11 @@ Support
221319

222320
If you need support on the documentation, you can ask a question as a discussion `here <https://github.com/espressif/arduino-esp32/discussions>`_.
223321

322+
Additional Guidelines
323+
---------------------
324+
325+
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.
326+
224327
.. _Arduino-ESP32: https://github.com/espressif/arduino-esp32
225328
.. _Sphinx: https://www.sphinx-doc.org/en/master/
226329
.. _ReadTheDocs: https://readthedocs.org/

0 commit comments

Comments
 (0)