documenting-code.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. Documenting Code
  2. ================
  3. :link_to_translation:`zh_CN:[中文]`
  4. The purpose of this description is to provide quick summary on documentation style used in `espressif/esp-idf`_ repository and how to add new documentation.
  5. Introduction
  6. ------------
  7. When documenting code for this repository, please follow `Doxygen style <http://doxygen.nl/manual/docblocks.html#specialblock>`_. You are doing it by inserting special commands, for instance ``@param``, into standard comments blocks, for example: ::
  8. /**
  9. * @param ratio this is oxygen to air ratio
  10. */
  11. Doxygen is phrasing the code, extracting the commands together with subsequent text, and building documentation out of it.
  12. Typical comment block, that contains documentation of a function, looks like below.
  13. .. image:: ../../_static/doc-code-documentation-inline.png
  14. :align: center
  15. :alt: Sample inline code documentation
  16. Doxygen supports couple of formatting styles. It also gives you great flexibility on level of details to include in documentation. To get familiar with available features, please check data rich and very well organized `Doxygen Manual <http://doxygen.nl/manual/index.html>`_.
  17. Why we need it?
  18. ---------------
  19. The ultimate goal is to ensure that all the code is consistently documented, so we can use tools like `Sphinx`_ and `Breathe`_ to aid preparation and automatic updates of API documentation when the code changes.
  20. With these tools the above piece of code renders like below:
  21. .. image:: ../../_static/doc-code-documentation-rendered.png
  22. :align: center
  23. :alt: Sample inline code after rendering
  24. Go for it!
  25. ----------
  26. When writing code for this repository, please follow guidelines below.
  27. 1. Document all building blocks of code: functions, structs, typedefs, enums, macros, etc. Provide enough information on purpose, functionality and limitations of documented items, as you would like to see them documented when reading the code by others.
  28. 2. Documentation of function should describe what this function does. If it accepts input parameters and returns some value, all of them should be explained.
  29. 3. Do not add a data type before parameter or any other characters besides spaces. All spaces and line breaks are compressed into a single space. If you like to break a line, then break it twice.
  30. .. image:: ../../_static/doc-code-function.png
  31. :align: center
  32. :alt: Sample function documented inline and after rendering
  33. 4. If function has void input or does not return any value, then skip ``@param`` or ``@return``
  34. .. image:: ../../_static/doc-code-void-function.png
  35. :align: center
  36. :alt: Sample void function documented inline and after rendering
  37. 5. When documenting a ``define`` as well as members of a ``struct`` or ``enum``, place specific comment like below after each member.
  38. .. image:: ../../_static/doc-code-member.png
  39. :align: center
  40. :alt: Sample of member documentation inline and after rendering
  41. 6. To provide well formatted lists, break the line after command (like ``@return`` in example below). ::
  42. *
  43. * @return
  44. * - ESP_OK if erase operation was successful
  45. * - ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
  46. * - ESP_ERR_NVS_READ_ONLY if handle was opened as read only
  47. * - ESP_ERR_NVS_NOT_FOUND if the requested key doesn't exist
  48. * - other error codes from the underlying storage driver
  49. *
  50. 7. Overview of functionality of documented header file, or group of files that make a library, should be placed in the same directory in a separate ``README.rst`` file. If directory contains header files for different APIs, then the file name should be ``apiname-readme.rst``.
  51. Go one extra mile
  52. -----------------
  53. There is couple of tips, how you can make your documentation even better and more useful to the reader.
  54. 1. Add code snippets to illustrate implementation. To do so, enclose snippet using ``@code{c}`` and ``@endcode`` commands. ::
  55. *
  56. * @code{c}
  57. * // Example of using nvs_get_i32:
  58. * int32_t max_buffer_size = 4096; // default value
  59. * esp_err_t err = nvs_get_i32(my_handle, "max_buffer_size", &max_buffer_size);
  60. * assert(err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND);
  61. * // if ESP_ERR_NVS_NOT_FOUND was returned, max_buffer_size will still
  62. * // have its default value.
  63. * @endcode
  64. *
  65. The code snippet should be enclosed in a comment block of the function that it illustrates.
  66. 2. To highlight some important information use command ``@attention`` or ``@note``. ::
  67. *
  68. * @attention
  69. * 1. This API only impact WIFI_MODE_STA or WIFI_MODE_APSTA mode
  70. * 2. If the ESP32 is connected to an AP, call esp_wifi_disconnect to disconnect.
  71. *
  72. Above example also shows how to use a numbered list.
  73. 3. To provide common description to a group of similar functions, enclose them using ``/**@{*/`` and ``/**@}*/`` markup commands::
  74. /**@{*/
  75. /**
  76. * @brief common description of similar functions
  77. *
  78. */
  79. void first_similar_function (void);
  80. void second_similar_function (void);
  81. /**@}*/
  82. For practical example see :component_file:`nvs_flash/include/nvs.h`.
  83. 4. You may want to go even further and skip some code like e.g. repetitive defines or enumerations. In such case enclose the code within ``/** @cond */`` and ``/** @endcond */`` commands. Example of such implementation is provided in :component_file:`driver/include/driver/gpio.h`.
  84. 5. Use markdown to make your documentation even more readable. You will add headers, links, tables and more. ::
  85. *
  86. * [{IDF_TARGET_NAME} Technical Reference Manual]({IDF_TARGET_TRM_EN_URL})
  87. *
  88. .. note::
  89. Code snippets, notes, links, etc. will not make it to the documentation, if not enclosed in a comment block associated with one of documented objects.
  90. 6. Prepare one or more complete code examples together with description. Place description in a separate file ``README.md`` in specific folder of :idf:`examples` directory.
  91. .. _link-custom-roles:
  92. Linking Examples
  93. ----------------
  94. When linking to examples on GitHub do not use absolute / hardcoded URLs. Instead, use docutils custom roles that will generate links for you. These auto-generated links point to the tree or blob for the git commit ID (or tag) of the repository. This is needed to ensure that links do not get broken when files in master branch are moved around or deleted. The roles will transparently handle files that are located in submodules and will link to the submodule's repository with the correct commit ID.
  95. The following roles are provided:
  96. - ``:idf:`path``` - points to directory inside ESP-IDF
  97. - ``:idf_file:`path``` - points to file inside ESP-IDF
  98. - ``:idf_raw:`path``` - points to raw view of the file inside ESP-IDF
  99. - ``:component:`path``` - points to directory inside ESP-IDF components dir
  100. - ``:component_file:`path``` - points to file inside ESP-IDF components dir
  101. - ``:component_raw:`path``` - points to raw view of the file inside ESP-IDF components dir
  102. - ``:example:`path``` - points to directory inside ESP-IDF examples dir
  103. - ``:example_file:`path``` - points to file inside ESP-IDF examples dir
  104. - ``:example_raw:`path``` - points to raw view of the file inside ESP-IDF examples dir
  105. Example implementation::
  106. * :example:`get-started/hello_world`
  107. * :example:`Hello World! <get-started/hello_world>`
  108. How it renders:
  109. * :example:`get-started/hello_world`
  110. * :example:`Hello World! <get-started/hello_world>`
  111. A check is added to the CI build script, which searches RST files for presence of hard-coded links (identified by tree/master, blob/master, or raw/master part of the URL). This check can be run manually: ``cd docs`` and then ``make gh-linkcheck``.
  112. .. _link-language-versions:
  113. Linking Language Versions
  114. -------------------------
  115. Switching between documentation in different languages may be done using ``:link_to_translation:`` custom role. The role placed on a page of documentation provides a link to the same page in a language specified as a parameter. Examples below show how to enter links to Chinese and English versions of documentation::
  116. :link_to_translation:`zh_CN:中文版`
  117. :link_to_translation:`en:English`
  118. The language is specified using standard abbreviations like ``en`` or ``zh_CN``. The text after last semicolon is not standardized and may be entered depending on the context where the link is placed, e.g.::
  119. :link_to_translation:`en:see description in English`
  120. .. _add-illustrations:
  121. Add Illustrations
  122. -----------------
  123. Consider adding diagrams and pictures to illustrate described concepts.
  124. Sometimes it is better to add an illustration than writing a lengthy paragraph to describe a complex idea, a data structure or an algorithm. This repository is using `blockdiag <http://blockdiag.com/en/index.html>`_ suite of tools to generate diagram images from simple text files.
  125. The following types of diagrams are supported:
  126. * `Block diagram <http://blockdiag.com/en/blockdiag/index.html>`_
  127. * `Sequence diagram <http://blockdiag.com/en/seqdiag/index.html>`_
  128. * `Activity diagram <http://blockdiag.com/en/actdiag/index.html>`_
  129. * `Logical network diagram <http://blockdiag.com/en/nwdiag/index.html>`_
  130. With this suite of tools it is possible to generate beautiful diagram images from simple text format (similar to graphviz’s DOT format). The diagram elements are laid out automatically. The diagram code is then converted into ".png" graphics and integrated "behind the scenes" into **Sphinx** documents.
  131. For the diagram preparation you can use an on-line `interactive shell`_ that instantly shows the rendered image.
  132. Below are couple of diagram examples:
  133. * Simple **block diagram** / ``blockdiag`` - `Wi-Fi Buffer Configuration <http://interactive.blockdiag.com/?compression=deflate&src=eJylUk1rwkAQvfsrBntpIUKiRQqSgK0VSj0EtCi0EjbJxCyuuyG7QW3pf-9m06hJeyg0t33zmHkfCZmItjElGwiLJME8IEwjRFHBA3WAj04H9HcFGyZCwoAoldOwUCgNzkWMwZ7GKgUXnKE9gjOcIt2kSuN39sigMiP8jDqX6GmF_Y3GmJCCqUCmJEM9yEXBY4xDcWjOE8GVpO9oztdaGQmRSRAJlMZysjOCKsVj358Fi_H8GV4Nze2Os4zRyvEbB0XktrseQWVktn_ym-wS-UFb0ilt0pa0N6Vn3i_KUEY5zcqrbXWTx_nDaZHjwYvEHGKiSNeC2q_r3FpQZekObAtMTi4XCi2IBBO5e0Rd5L7ppLG574GvO__PUuO7sXTgweTIyY5GcD1XOtToBhYruDf_VvuUad3tD-0_Xq1TLPPSI84xKvNrF9vzLnrTj1M7rYhrXv24cCPVkZUaOK47n1-lOvbk>`_
  134. * Slightly more complicated **block diagram** - `Wi-Fi programming model <http://interactive.blockdiag.com/?compression=deflate&src=eJyFk09P40AMxe98CqscIVILq72UIFX8kSoQWy0RHABFTuImFtOZaGYKuyC-O840bagaRI7Pfs7Pz0mmTP5cMJbwynNOa2tKi4sF6zJdmIIUvO_tgTz7UCqToQL03nK29OSCrqUpfeXCVxDD6Gg47tSKuKy8yL9b1dWov1E3E4atWtAcl8qnrsKapGDNUhdUZObfdr2UQp3mRhkrXdpoGq-BGwhQmJFaoSZns_Q2mZxdwUNQ44Eojxqcx_x5cAhzo73jN4pHv55WL7m4u0nSZHLbOeiFtBePR9dvmcxm19sWrGvFOXo2utd4CGH5eHQ8bGfcTy-n6fnfO9jMuOfoksV9bvmFbO-Lr27-JPAQ4oqbGJ62c8iN1pQ3EA4O-lOJTncXDvvupCGdu3vmqFQmSQqm3CIYBx0EWou6pADjQJbw3Bj-h3I4onxpsHrCQLnmoD0yVKgLJXuP1x3GsowPmUpfbay3yH5T7khPoi7NnpU-1nisPdkFyY_gV4x9XB3Y0pHdpfoJ60toURQOtqbYuvpJ1B6zDXYym0qmTVpNnh-fpWcbRA>`_
  135. * **Sequence diagram** / ``seqdiag`` - `Scan for a Specific AP in All Channels <http://interactive.blockdiag.com/seqdiag/?compression=deflate&src=eJyVkU1PwzAMhu_7FdburUgQXMomTaPcKIdOIIRQlDVuG1EloUknPsR_J2s2rRsT2nKJ9drvY8ex-C4kr8AWXLFSt8waLBg38D0Cf3jh5Io7qRVMQGmFSS-jqJA1qCpXe51cXwTZGg-pUVa1W8tXQRVY8q5xzNbcoNdb3SmBYqk_9vOlVs7Kr3UJoQmMwgDGMMftWwK4QuU28ZOM7uQm3q_zYTQd5OGl4UtsJmMSE5jCXKtSVl2LUPgpXPvpb4Hj1-RUCPWQ3O_K-wKpX84WMLAcB9B-igCouVLYADnDTA_N9GRzHMdnNMoOG2Vb8-4b4CY6Zr4MT3zOF-k9Sx_TbMHy-Sxjtw9Z-mfRHjEA7hD0X8TPLxU91AQ>`_
  136. * **Packet diagram** / ``packetdiag`` - `NVS Page Structure <http://interactive.blockdiag.com/packetdiag/?compression=deflate&src=eJxFkMFOwzAQRO_9ij2mh63idRKaSj1V_ACIE6DIxG4StTgh3oCg6r_j2JTs8c3szNqDqk-GdacasJ-uGlRjKsfjVPM0GriswE_dn786zS3sQRJAYLbXprpRkS-sNV3TcrAGqM1RTWeujr1l1_2Y2U6rIKUod_DIis2LTbJ1YBneeWY-Nj5ts-AtkudPdnJGQ0JppLRFKXZweDhIWrySsPDB95bHb3BzPLx1_K4GSCSt_-4vMizzmykNSuBlgWKuioJYBOHLROnbEBGe_ZfEh-7pNcolIdF_raA8rl5_AaqqWyE>`_
  137. Try them out by modifying the source code and see the diagram instantly rendering below.
  138. .. note::
  139. There may be slight differences in rendering of font used by the `interactive shell`_ compared to the font used in the esp-idf documentation.
  140. Add Notes
  141. ---------
  142. Working on a document, you might need to:
  143. - Place some suggestions on what should be added or modified in future.
  144. - Leave a reminder for yourself or somebody else to follow up.
  145. In this case, add a todo note to your reST file using the directive ``.. todo::``. For example:
  146. .. code-block:: none
  147. .. todo::
  148. Add a package diagram.
  149. If you add ``.. todolist::`` to a reST file, the directive will be replaced by a list of all todo notes from the whole documentation.
  150. By default, the directives ``.. todo::`` and ``.. todolist::`` are ignored by documentation builders. If you want the notes and the list of notes to be visible in your locally built documentation, do the following:
  151. 1. Open your local ``conf_common.py`` file.
  152. 2. Find the parameter ``todo_include_todos``.
  153. 3. Change its value from ``False`` to ``True``.
  154. Before pushing your changes to origin, please set the value of ``todo_include_todos`` back to ``False``.
  155. For more details about the extension, see `sphinx.ext.todo <https://www.sphinx-doc.org/en/master/usage/extensions/todo.html#directive-todolist>`_ documentation.
  156. Writing generic documentation for multiple chips
  157. ------------------------------------------------
  158. The documentation for all of Espressif's chips is built from the same files. To faciliate the writing of documents that can be re-used for multiple different chips (called below "targets"), we provide you with the following functionality:
  159. Exclusion of content based on chip-target
  160. """""""""""""""""""""""""""""""""""""""""
  161. Occasionally there will be content that is only relevant for one of targets. When this is the case, you can exclude that content by using the ''.. only:: TAG'' directive, where you replace 'TAG' with one of the following names:
  162. Chip name:
  163. * esp32
  164. * esp32s2
  165. Define identifiers from 'sdkconfig.h', generated by the default menuconfig settings for the target, e.g:
  166. * CONFIG_FREERTOS_UNICORE
  167. Define identifiers from the soc '\*_caps' headers, e.g:
  168. * SOC_BT_SUPPORTED
  169. * SOC_CAN_SUPPORTED
  170. Example:
  171. .. code-block:: none
  172. .. only:: esp32
  173. ESP32 specific content.
  174. This directive also supports the boolean operators 'and', 'or' and 'not'. Example:
  175. .. code-block:: none
  176. .. only:: SOC_BT_SUPPORTED and CONFIG_FREERTOS_UNICORE
  177. BT specific content only relevant for single-core targets.
  178. This functionality is provided by the `Sphinx selective exclude <https://github.com/pfalcon/sphinx_selective_exclude>`_ extension.
  179. A weakness in this extension is that it does not correctly handle the case were you exclude a section, and that is directly followed by a labeled new section. In these cases everything will render correctly, but the label will not correctly link to the section that follows. A temporary work-around for the cases were this can't be avoided is the following:
  180. .. code-block:: none
  181. .. only:: esp32
  182. .. _section_1_label:
  183. Section 1
  184. ^^^^^^^^^
  185. Section one content
  186. .. _section_2_label:
  187. .. only:: esp32s2
  188. _section_2_label:
  189. Section 2
  190. ^^^^^^^^^
  191. Section 2 content
  192. The :TAG: role is used for excluding content from a table of content tree. For example:
  193. .. code-block:: none
  194. .. toctree::
  195. :maxdepth: 1
  196. :esp32: configure-wrover
  197. configure-other-jtag
  198. When building the documents, Sphinx will use the above mentioned directive and role to include or exclude content based on the target tag it was called with.
  199. .. note::
  200. If excluding an entire document from the toctree based on targets, it's necessary to also update the ``exclude_patterns`` list in :idf_file:`docs/conf_common.py` to exclude the file for other targets, or a Sphinx warning "WARNING: document isn't included in any toctree" will be generated..
  201. The recommended way of doing it is adding the document to one of the list that gets included in ``conditional_include_dict`` in :idf_file:`docs/conf_common.py`, e.g. a document which should only be shown for BT capable targets should be added to ``BT_DOCS``. :idf_file:`docs/idf_extensions/exclude_docs.py` will then take care of adding it to ``exclude_patterns`` if the corresponding tag is not set.
  202. If you need to exclude content inside a list or bullet points then this should be done by using the '':TAG:'' role inside the ''.. list:: '' directive.
  203. .. code-block:: none
  204. .. list::
  205. :esp32: - ESP32 specific content
  206. :SOC_BT_SUPPORTED: - BT specific content
  207. - Common bullet point
  208. - Also common bullet point
  209. Substitution macros
  210. """""""""""""""""""
  211. When you need to refer to the chip's name, toolchain name, path or other common names that depend on the target type you can consider using the substitution macros supplied by :idf_file:`docs/idf_extensions/format_idf_target.py`.
  212. For example, the following reStructuredText content:
  213. This is a {\IDF_TARGET_NAME}, with /{\IDF_TARGET_PATH_NAME}/soc.c, compiled with `xtensa-{\IDF_TARGET_TOOLCHAIN_NAME}-elf-gcc` with `CONFIG_{\IDF_TARGET_CFG_PREFIX}_MULTI_DOC`
  214. Would render in the documentation as:
  215. This is a {IDF_TARGET_NAME}, with /{IDF_TARGET_PATH_NAME}/soc.c, compiled with `xtensa-{IDF_TARGET_TOOLCHAIN_NAME}-elf-gcc` with `CONFIG_{IDF_TARGET_CFG_PREFIX}_MULTI_DOC`.
  216. This extension also supports markup for defining local (within a single source file) substitutions. Place a definition like the following into a single line of the RST file::
  217. {\IDF_TARGET_SUFFIX:default="DEFAULT_VALUE", esp32="ESP32_VALUE", esp32s2="ESP32S2_VALUE"}
  218. This will define a target-dependent substitution of the tag {\IDF_TARGET_SUFFIX} in the current RST file. For example::
  219. {\IDF_TARGET_TX_PIN:default="IO3", esp32="IO4", esp32s2="IO5"}
  220. Will define a substitution for the tag {\IDF_TARGET_TX_PIN}, which would be replaced by the text IO5 if sphinx was called with the tag esp32s2.
  221. .. note::
  222. These single-file definitions can be placed anywhere in the .rst file (on their own line), but the name of the directive must start with ``IDF_TARGET_``.
  223. Put it all together
  224. -------------------
  225. Once documentation is ready, follow instruction in :doc:`../api-reference/template` and create a single file, that will merge all individual pieces of prepared documentation. Finally add a link to this file to respective ``.. toctree::`` in ``index.rst`` file located in ``/docs`` folder or subfolders.
  226. OK, but I am new to Sphinx!
  227. ---------------------------
  228. 1. No worries. All the software you need is well documented. It is also open source and free. Start by checking `Sphinx`_ documentation. If you are not clear how to write using rst markup language, see `reStructuredText Primer <https://www.sphinx-doc.org/en/stable/rest.html>`_. You can also use markdown (.md) files, and find out about more about the specific markdown syntax that we use on `Recommonmark parser's documentation page <https://recommonmark.readthedocs.io/en/latest/>`_.
  229. 2. Check the source files of this documentation to understand what is behind of what you see now on the screen. Sources are maintained on GitHub in `espressif/esp-idf`_ repository in :idf:`docs` folder. You can go directly to the source file of this page by scrolling up and clicking the link in the top right corner. When on GitHub, see what's really inside, open source files by clicking ``Raw`` button.
  230. 3. You will likely want to see how documentation builds and looks like before posting it on the GitHub. There are two options to do so:
  231. * Install `Sphinx`_, `Breathe`_, `Blockdiag <http://blockdiag.com/en/index.html>`_ and `Doxygen <http://doxygen.nl/>`_ to build it locally, see chapter below.
  232. * Set up an account on `Read the Docs <https://readthedocs.org/>`_ and build documentation in the cloud. Read the Docs provides document building and hosting for free and their service works really quick and great.
  233. 4. To preview documentation before building, use `Sublime Text <https://www.sublimetext.com/>`_ editor together with `OmniMarkupPreviewer <https://github.com/timonwong/OmniMarkupPreviewer>`_ plugin.
  234. .. _setup-for-building-documentation:
  235. Setup for building documentation locally
  236. ----------------------------------------
  237. Install Dependencies
  238. """"""""""""""""""""
  239. You can setup environment to build documentation locally on your PC by installing:
  240. 1. Doxygen - http://doxygen.nl/
  241. 2. Sphinx - https://github.com/sphinx-doc/sphinx/#readme-for-sphinx
  242. 3. Breathe - https://github.com/michaeljones/breathe#breathe
  243. 4. Document theme "sphinx_idf_theme" - https://github.com/espressif/sphinx_idf_theme
  244. 5. Custom 404 page "sphinx-notfound-page" - https://github.com/readthedocs/sphinx-notfound-page
  245. 6. Blockdiag - http://blockdiag.com/en/index.html
  246. 7. Recommonmark - https://github.com/rtfd/recommonmark
  247. The package "sphinx_idf_theme" is added to have the same "look and feel" of `ESP-IDF Programming Guide <https://docs.espressif.com/projects/esp-idf/en/latest/index.html>`_.
  248. Do not worry about being confronted with several packages to install. Besides Doxygen, all remaining packages are written in pure Python. Therefore installation of all of them is combined into one simple step.
  249. .. important:: Docs building now supports Python 3 only. Python 2 installations will not work.
  250. Doxygen
  251. @@@@@@@
  252. Installation of Doxygen is OS dependent:
  253. **Linux**
  254. ::
  255. sudo apt-get install doxygen
  256. **Windows** - install in MSYS2 console
  257. ::
  258. pacman -S doxygen
  259. **MacOS**
  260. ::
  261. brew install doxygen
  262. .. note::
  263. If you are installing on Windows MSYS2 system (Linux and MacOS users should skip this note, Windows users who don't use MSYS2 will need to find other alternatives), **before** going further, execute two extra steps below. These steps are required to install dependencies of "blockdiag" discussed under :ref:`add-illustrations`.
  264. 1. Update all the system packages:
  265. ::
  266. $ pacman -Syu
  267. This process will likely require restarting of the MSYS2 MINGW32 console and repeating above commands, until update is complete.
  268. 2. Install *pillow*, that is one of dependences of the *blockdiag*:
  269. ::
  270. $ pacman -S mingw32/mingw-w64-i686-python-pillow
  271. Check the log on the screen that ``mingw-w64-i686-python-pillow-4.3.0-1`` or newer is installed. Previous versions of *pillow* will not work.
  272. A downside of Windows installation is that fonts of the `blockdiag pictures <add-illustrations>` do not render correctly, you will see some random characters instead. Until this issue is fixed, you can use the `interactive shell`_ to see how the complete picture looks like.
  273. Remaining applications
  274. @@@@@@@@@@@@@@@@@@@@@@
  275. All remaining applications are `Python <https://www.python.org/>`_ packages and you can install them in one step as follows:
  276. ::
  277. cd ~/esp/esp-idf/docs
  278. pip install --user -r requirements.txt
  279. .. note::
  280. Installation steps assume that ESP-IDF is placed in ``~/esp/esp-idf`` directory, that is default location of ESP-IDF used in documentation.
  281. Building Documentation
  282. """"""""""""""""""""""
  283. ::
  284. cd ~/esp/esp-idf/docs
  285. Now you should be ready to build documentation by invoking::
  286. ./build_docs.py build
  287. This will build docs for all supported ESP-IDF languages & targets. This can take some time, although jobs will run in parallel up to the number of CPU cores you have (can modify this with the ``--sphinx-parallel-builds`` option, see ``./build_docs.py --help`` for details).
  288. To build for a single language and target combination only::
  289. ./build_docs.py -l en -t esp32 build
  290. Choices for language (``-l``) are ``en`` and ``zh_CN``. Choices for target (``-t``) are any supported ESP-IDF build system target (for example ``esp32`` and ``esp32s2``).
  291. Build documentation will be placed in ``_build/<language>/<target>/html`` folder. To see it, open the ``index.html`` inside this directory in a web browser.
  292. Building a subset of the documentation
  293. """"""""""""""""""""""""""""""""""""""
  294. Since building the full documentation can be quite slow, it might be useful to just build just the subset of the documentation you are interested in.
  295. This can be achieved by listing the document you want to build::
  296. ./build_docs.py -l en -t esp32 -i api-reference/peripherals/can.rst build
  297. Building multiple documents is also possible::
  298. ./build_docs.py -l en -t esp32 -i api-reference/peripherals/can.rst api-reference/peripherals/adc.rst build
  299. As well as wildcards::
  300. ./build_docs.py -l en -t esp32 -i api-reference/peripherals/* build
  301. Note that this is a feature intended to simply testing and debugging during writing of documentation. The HTML output won't be perfect, i.e. it will not build a proper index that lists all the documents, and any references to documents that are not built will result in warnings.
  302. Building PDF
  303. """"""""""""
  304. It is also possible to build latex files and a PDF of the documentation using ``build_docs.py``. To do this the following Latex packages are required to be installed:
  305. * latexmk
  306. * texlive-latex-recommended
  307. * texlive-fonts-recommended
  308. * texlive-xetex
  309. The following fonts are also required to be installed:
  310. * Freefont Serif, Sans and Mono OpenType fonts, available as the package ``fonts-freefont-otf`` on Ubuntu
  311. * Lmodern, available as the package ``fonts-lmodern`` on Ubuntu
  312. * Fandol, can be downloaded from `here <https://ctan.org/tex-archive/fonts/fandol>`_
  313. Now you can build the PDF for a target by invoking::
  314. ./build_docs.py -bs latex -l en -t esp32 build
  315. Or alternatively build both html and PDF::
  316. ./build_docs.py -bs html latex -l en -t esp32 build
  317. Latex files and the PDF will be placed in ``_build/<language>/<target>/latex`` folder.
  318. Wrap up
  319. -------
  320. We love good code that is doing cool things.
  321. We love it even better, if it is well documented, so we can quickly make it run and also do the cool things.
  322. Go ahead, contribute your code and documentation!
  323. Related Documents
  324. -----------------
  325. * :doc:`../api-reference/template`
  326. * :doc:`add-ons-reference`
  327. .. _espressif/esp-idf: https://github.com/espressif/esp-idf/
  328. .. _interactive shell: http://interactive.blockdiag.com/?compression=deflate&src=eJxlUMFOwzAMvecrrO3aITYQQirlAIIzEseJQ5q4TUSIq8TVGIh_J2m7jbKc7Ge_5_dSO1Lv2soWvoVYgieNoMh7VGzJR9FJtugZ7lYQ0UcKEbYNOY36rRQHZHUPT68vV5tceGLbWCUzPfeaFFMoBZzecVc56vWwJFnWMmJ59CCZg617xpOFbTSyw0pmvT_HJ7hxtFNGBr6wvuu5SCkchcrZ1vAeXZomznh5YgTqfcpR02cBO6vZVDeXBRjMjKEcFRbLh8f18-Z2UUBDnqP9wmp9ncRmSSfND2ldGo2h_zse407g0Mxc1q7HzJ3-4jzYYTJjtQH3iSV-fgFzx50J
  329. .. _Sphinx: https://www.sphinx-doc.org/
  330. .. _Breathe: https://breathe.readthedocs.io