1.. _doc_guidelines:
2
3Documentation Guidelines
4########################
5
6.. highlight:: rst
7
8.. note::
9
10   For instructions on building the documentation, see :ref:`zephyr_doc`.
11
12Zephyr Project content is written using the `reStructuredText`_ markup
13language (.rst file extension) with Sphinx extensions, and processed
14using Sphinx to create a formatted standalone website.  Developers can
15view this content either in its raw form as .rst markup files, or (with
16Sphinx installed) they can :ref:`build the documentation <zephyr_doc>` locally
17to generate the documentation in HTML or PDF format. The HTML content can
18then be viewed using a web browser. This same .rst content is served by the
19`Zephyr documentation`_ website.
20
21You can read details about `reStructuredText`_
22and about `Sphinx extensions`_ from their respective websites.
23
24.. _Sphinx extensions: http://www.sphinx-doc.org/en/stable/contents.html
25.. _reStructuredText: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
26.. _Sphinx Inline Markup:  http://sphinx-doc.org/markup/inline.html#inline-markup
27.. _Zephyr documentation:  https://docs.zephyrproject.org
28
29This document provides a quick reference for commonly used reST and
30Sphinx-defined directives and roles used to create the documentation
31you're reading.
32
33Content Structure
34*****************
35
36Tabs, spaces, and indenting
37===========================
38
39Indenting is significant in reST file content, and using spaces is
40preferred.  Extra indenting can (unintentionally) change the way content
41is rendered too.  For lists and directives, indent the content text to
42the first non-white space in the preceding line.  For example::
43
44   * List item that spans multiple lines of text
45     showing where to indent the continuation line.
46
47   1. And for numbered list items, the continuation
48      line should align with the text of the line above.
49
50   .. code-block::
51
52      The text within a directive block should align with the
53      first character of the directive name.
54
55Refer to the Zephyr :ref:`coding_style` for additional requirements.
56
57Headings
58========
59
60While reST allows use of both an overline and matching underline to
61indicate a heading, we only use an underline indicator for headings.
62
63* Document title (h1) use ``#`` for the underline character
64* First section heading level (h2) use ``*``
65* Second section heading level (h3) use ``=``
66* Third section heading level (h4) use ``-``
67
68The heading underline must be the same length as the heading text.
69
70For example::
71
72   This is a title heading
73   #######################
74
75   some content goes here
76
77   First section heading
78   *********************
79
80
81Lists
82=====
83
84For bullet lists, place an asterisk (``*``) or hyphen (``-``) at
85the start of a paragraph and indent continuation lines with two
86spaces.
87
88The first item in a list (or sublist) must have a blank line before it
89and should be indented at the same level as the preceding paragraph
90(and not indented itself).
91
92For numbered lists
93start with a 1. or a. for example, and continue with autonumbering by
94using a ``#`` sign.  Indent continuation lines with three spaces::
95
96   * This is a bulleted list.
97   * It has two items, the second
98     item and has more than one line of reST text.  Additional lines
99     are indented to the first character of the
100     text of the bullet list.
101
102   1. This is a new numbered list. If the wasn't a blank line before it,
103      it would be a continuation of the previous list (or paragraph).
104   #. It has two items too.
105
106   a. This is a numbered list using alphabetic list headings
107   #. It has three items (and uses autonumbering for the rest of the list)
108   #. Here's the third item
109
110   #. This is an autonumbered list (default is to use numbers starting
111      with 1).
112
113      #. This is a second-level list under the first item (also
114         autonumbered).  Notice the indenting.
115      #. And a second item in the nested list.
116   #. And a second item back in the containing list.  No blank line
117      needed, but it wouldn't hurt for readability.
118
119Definition lists (with a term and its definition) are a convenient way
120to document a word or phrase with an explanation.  For example this reST
121content::
122
123   The Makefile has targets that include:
124
125   html
126      Build the HTML output for the project
127
128   clean
129      Remove all generated output, restoring the folders to a
130      clean state.
131
132Would be rendered as:
133
134   The Makefile has targets that include:
135
136   html
137      Build the HTML output for the project
138
139   clean
140      Remove all generated output, restoring the folders to a
141      clean state.
142
143Multi-column lists
144==================
145
146If you have a long bullet list of items, where each item is short, you
147can indicate the list items should be rendered in multiple columns with
148a special ``.. rst-class:: rst-columns`` directive.  The directive will
149apply to the next non-comment element (e.g., paragraph), or to content
150indented under the directive. For example, this unordered list::
151
152   .. rst-class:: rst-columns
153
154   * A list of
155   * short items
156   * that should be
157   * displayed
158   * horizontally
159   * so it doesn't
160   * use up so much
161   * space on
162   * the page
163
164would be rendered as:
165
166.. rst-class:: rst-columns
167
168   * A list of
169   * short items
170   * that should be
171   * displayed
172   * horizontally
173   * so it doesn't
174   * use up so much
175   * space on
176   * the page
177
178A maximum of three columns will be displayed, and change based on the
179available width of the display window, reducing to one column on narrow
180(phone) screens if necessary.  We've deprecated use of the ``hlist``
181directive because it misbehaves on smaller screens.
182
183Tables
184======
185
186There are a few ways to create tables, each with their limitations or
187quirks.  `Grid tables
188<http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#grid-tables>`_
189offer the most capability for defining merged rows and columns, but are
190hard to maintain::
191
192   +------------------------+------------+----------+----------+
193   | Header row, column 1   | Header 2   | Header 3 | Header 4 |
194   | (header rows optional) |            |          |          |
195   +========================+============+==========+==========+
196   | body row 1, column 1   | column 2   | column 3 | column 4 |
197   +------------------------+------------+----------+----------+
198   | body row 2             | ...        | ...      | you can  |
199   +------------------------+------------+----------+ easily   +
200   | body row 3 with a two column span   | ...      | span     |
201   +------------------------+------------+----------+ rows     +
202   | body row 4             | ...        | ...      | too      |
203   +------------------------+------------+----------+----------+
204
205This example would render as:
206
207+------------------------+------------+----------+----------+
208| Header row, column 1   | Header 2   | Header 3 | Header 4 |
209| (header rows optional) |            |          |          |
210+========================+============+==========+==========+
211| body row 1, column 1   | column 2   | column 3 | column 4 |
212+------------------------+------------+----------+----------+
213| body row 2             | ...        | ...      | you can  |
214+------------------------+------------+----------+ easily   +
215| body row 3 with a two column span   | ...      | span     |
216+------------------------+------------+----------+ rows     +
217| body row 4             | ...        | ...      | too      |
218+------------------------+------------+----------+----------+
219
220`List tables
221<http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table>`_
222are much easier to maintain, but don't support row or column spans::
223
224   .. list-table:: Table title
225      :widths: 15 20 40
226      :header-rows: 1
227
228      * - Heading 1
229        - Heading 2
230        - Heading 3
231      * - body row 1, column 1
232        - body row 1, column 2
233        - body row 1, column 3
234      * - body row 2, column 1
235        - body row 2, column 2
236        - body row 2, column 3
237
238This example would render as:
239
240.. list-table:: Table title
241   :widths: 15 20 40
242   :header-rows: 1
243
244   * - Heading 1
245     - Heading 2
246     - Heading 3
247   * - body row 1, column 1
248     - body row 1, column 2
249     - body row 1, column 3
250   * - body row 2, column 1
251     - body row 2, column 2
252     - body row 2, column 3
253
254The ``:widths:`` parameter lets you define relative column widths.  The
255default is equal column widths. If you have a three-column table and you
256want the first column to be half as wide as the other two equal-width
257columns, you can specify ``:widths: 1 2 2``.  If you'd like the browser
258to set the column widths automatically based on the column contents, you
259can use ``:widths: auto``.
260
261Tabbed Content
262==============
263
264As introduced in the :ref:`getting_started`, you can provide alternative
265content to the reader via a tabbed interface. When the reader clicks on
266a tab, the content for that tab is displayed, for example::
267
268   .. tabs::
269
270      .. tab:: Apples
271
272         Apples are green, or sometimes red.
273
274      .. tab:: Pears
275
276         Pears are green.
277
278      .. tab:: Oranges
279
280         Oranges are orange.
281
282will display as:
283
284.. tabs::
285
286   .. tab:: Apples
287
288      Apples are green, or sometimes red.
289
290   .. tab:: Pears
291
292      Pears are green.
293
294   .. tab:: Oranges
295
296      Oranges are orange.
297
298Tabs can also be grouped, so that changing the current tab in one area
299changes all tabs with the same name throughout the page.  For example:
300
301.. tabs::
302
303   .. group-tab:: Linux
304
305      Linux Line 1
306
307   .. group-tab:: macOS
308
309      macOS Line 1
310
311   .. group-tab:: Windows
312
313      Windows Line 1
314
315.. tabs::
316
317   .. group-tab:: Linux
318
319      Linux Line 2
320
321   .. group-tab:: macOS
322
323      macOS Line 2
324
325   .. group-tab:: Windows
326
327      Windows Line 2
328
329In this latter case, we're using ``.. group-tab::`` instead of simply
330``.. tab::``.  Under the hood, we're using the `sphinx-tabs
331<https://github.com/executablebooks/sphinx-tabs>`_ extension that's included
332in the Zephyr setup.  Within a tab, you can have most any content *other
333than a heading* (code-blocks, ordered and unordered lists, pictures,
334paragraphs, and such).  You can read more about sphinx-tabs from the
335link above.
336
337
338Text Formatting
339***************
340
341ReSTructuredText supports a variety of text formatting options. This section provides a quick
342reference for some of the most commonly used text formatting options in Zephyr documentation. For an
343exhaustive list, refer to the `reStructuredText Quick Reference`_,
344`reStructuredText Interpreted Text Roles`_ as well as the `additional roles provided by Sphinx`_.
345
346.. _reStructuredText Quick Reference: http://docutils.sourceforge.io/docs/user/rst/quickref.html
347.. _reStructuredText Interpreted Text Roles: https://docutils.sourceforge.io/docs/ref/rst/roles.html
348.. _additional roles provided by Sphinx: https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html
349
350Content Highlighting
351====================
352
353Some common reST inline markup samples:
354
355* one asterisk: ``*text*`` for emphasis (*italics*),
356* two asterisks: ``**text**`` for strong emphasis (**boldface**), and
357* two backquotes: ````text```` for ``inline code`` samples.
358
359If asterisks or backquotes appear in running text and could be confused with
360inline markup delimiters, you can eliminate the confusion by adding a
361backslash (``\``) before it.
362
363File Names and Commands
364=======================
365
366Sphinx extends reST by supporting additional inline markup elements (called
367"roles") used to tag text with special
368meanings and allow style output formatting. (You can refer to the `Sphinx Inline Markup`_
369documentation for the full list).
370
371While double quotes can be used for rendering text as "code", you are encouraged to use the
372following roles for marking up file names, command names, and other "special" text.
373
374* :rst:role:`file` for file names, e.g., ``:file:`CMakeLists.txt``` will render as
375  :file:`CMakeLists.txt`
376
377  .. note::
378
379     In case you want to indicate a "variable" file path, you may use curly braces to enclose the
380     variable part of the path, e.g., ``:file:`{boardname}_defconfig``` will render as
381     :file:`{boardname}_defconfig`.
382
383* :rst:role:`command` for command names, e.g., ``:command:`make``` will render as :command:`make`
384
385* :rst:role:`envvar` for environment variables, e.g., ``:envvar:`ZEPHYR_BASE``` will render as
386  :envvar:`ZEPHYR_BASE`
387
388For creating references to files that are hosted in the Zephyr organization on GitHub, refer to
389:ref:`linking_to_zephyr_files` section below.
390
391User Interaction
392================
393
394When documenting user interactions, such as key combinations or GUI interactions, use the following
395roles to highlight the commands in a meaningful way:
396
397* :rst:role:`kbd` for keyboard input, e.g., ``:kbd:`Ctrl-C``` will render as :kbd:`Ctrl-C`
398
399* :rst:role:`menuselection` for menu selections, e.g., ``:menuselection:`File --> Open``` will render
400  as :menuselection:`File --> Open`
401
402* :rst:role:`guilabel` for GUI labels, e.g., ``:guilabel:`Cancel``` will render as :guilabel:`Cancel`
403
404Mathematical Formulas
405=====================
406
407You can include mathematical formulas using either the :rst:role:`math` role or :rst:dir:`math`
408directive. The directive provides more flexibility in case you have a more complex formula.
409
410The input language for mathematics is LaTeX markup. Example::
411
412   The answer to life, the universe, and everything is :math:`30 + 2^2 + \sqrt{64} = 42`.
413
414This would render as:
415
416   The answer to life, the universe, and everything is :math:`30 + 2^2 + \sqrt{64} = 42`.
417
418Non-ASCII Characters
419====================
420
421You can insert non-ASCII characters such as a Trademark symbol (|trade|),
422by using the notation ``|trade|``.
423Available replacement names are defined in an include file used during the Sphinx processing
424of the reST files.  The names of these replacement characters are the same as used in HTML
425entities used to insert characters in HTML, e.g., ``\&trade;`` and are defined in the
426file :zephyr_file:`doc/substitutions.txt` as listed below:
427
428.. literalinclude:: ../../substitutions.txt
429   :language: rst
430
431We've kept the substitutions list small but others can be added as
432needed by submitting a change to the :zephyr_file:`doc/substitutions.txt` file.
433
434Code Blocks and Command Examples
435================================
436
437Use the reST :rst:dir:`code-block` directive to create a highlighted block of
438fixed-width text, typically used for showing formatted code or console
439commands and output.  Smart syntax highlighting is also supported (using the
440Pygments package). You can also directly specify the highlighting language.
441For example::
442
443   .. code-block:: c
444
445      struct k_object {
446         char *name;
447         uint8_t perms[CONFIG_MAX_THREAD_BYTES];
448         uint8_t type;
449         uint8_t flags;
450         uint32_t data;
451      } __packed;
452
453Note the blank line between the :rst:dir:`code-block` directive and the first
454line of the code-block body, and the body content is indented three
455spaces (to the first non-white space of the directive name).
456
457This would be rendered as:
458
459   .. code-block:: c
460
461      struct k_object {
462         char *name;
463         uint8_t perms[CONFIG_MAX_THREAD_BYTES];
464         uint8_t type;
465         uint8_t flags;
466         uint32_t data;
467      } __packed;
468
469
470Other languages are of course supported (see `languages supported by Pygments`_), and in particular,
471you are encouraged to make use of the following when appropriate:
472
473.. _`languages supported by Pygments`: http://pygments.org/languages/
474
475* ``c`` for C code
476* ``cpp`` for C++ code
477* ``python`` for Python code
478* ``console`` for console output, i.e. interactive shell sessions where commands are prefixed by a
479  prompt (ex. ``$`` for Linux, or ``uart:~$`` for Zephyr's shell), and where the output is also
480  shown. The commands will be highlighted, and the output will not. What's more, copying code block
481  using the "copy" button will automatically copy just the commands, excluding the prompt and the
482  outputs of the commands.
483* ``shell`` or ``bash`` for shell commands. Both languages get highlighted the same but you may use
484  ``bash`` for conveying that the commands are bash-specific, and ``shell`` for generic shell
485  commands.
486
487  .. note::
488
489     Do not use ``bash`` or ``shell`` if your code block includes a prompt, use ``console`` instead.
490
491     Reciprocally, do not use ``console`` if your code block does not include a prompt and is not
492     showcasing an interactive session with command(s) and their output.
493
494     .. list-table:: When to use ``bash``/``shell`` vs. ``console``
495        :class: wrap-normal
496        :header-rows: 1
497        :widths: 20,40,40
498
499        * - Use case
500          - ``code-block`` snippet
501          - Expected output
502
503        * - One or several commands, no output
504
505          - .. code-block:: rst
506
507               .. code-block:: shell
508
509                  echo "Hello World!"
510
511          - .. code-block:: shell
512
513               echo "Hello World!"
514
515        * - An interactive shell session with command(s) and their output
516
517          - .. code-block:: rst
518
519               .. code-block:: console
520
521                  $ echo "Hello World!"
522                  Hello World!
523
524          - .. code-block:: console
525
526               $ echo "Hello World!"
527               Hello World!
528
529        * - An interactive Zephyr shell session, with commands and their outputs
530
531          - .. code-block:: rst
532
533               .. code-block:: console
534
535                  uart:~$ version
536                  Zephyr version 3.5.99
537                  uart:~$ kernel uptime
538                  Uptime: 20970 ms
539
540          - .. code-block:: console
541
542               uart:~$ version
543               Zephyr version 3.5.99
544               uart:~$ kernel uptime
545               Uptime: 20970 ms
546
547* ``bat`` for Windows batch files
548* ``cfg`` for config files with "KEY=value" entries (ex. Kconfig ``.conf`` files)
549* ``cmake`` for CMake
550* ``devicetree`` for Devicetree
551* ``kconfig`` for Kconfig
552* ``yaml`` for YAML
553* ``rst`` for reStructuredText
554
555When no language is specified, the language is set to ``none`` and the code block is not
556highlighted. You may also use ``none`` explicitly to achieve the same result; for example::
557
558   .. code-block:: none
559
560      This would be a block of text styled with a background
561      and box, but with no syntax highlighting.
562
563Would display as:
564
565   .. code-block:: none
566
567      This would be a block of text styled with a background
568      and box, but with no syntax highlighting.
569
570There's a shorthand for writing code blocks too: end the introductory paragraph with a double colon
571(``::``) and indent the code block content that follows it by three spaces.  On output, only one
572colon will be shown.  The code block will have no highlighting (i.e. ``none``). You may however use
573the :rst:dir:`highlight` directive to customize the default language used in your document (see for
574example how this is done at the beginning of this very document).
575
576
577Links and Cross-References
578**************************
579
580.. _internal-linking:
581
582Cross-referencing internal content
583==================================
584
585Traditional ReST links are only supported within the current file using the
586notation::
587
588   Refer to the `internal-linking`_ page
589
590which renders as,
591
592   Refer to the `internal-linking`_ page
593
594Note the use of a trailing
595underscore to indicate an outbound link. In this example, the label was
596added immediately before a heading, so the text that's displayed is the
597heading text itself. You can change the text that's displayed as the
598link writing this as::
599
600   Refer to the `show this text instead <internal-linking_>`_ page
601
602which renders as,
603
604   Refer to the `show this text instead <internal-linking_>`_ page
605
606
607Cross-referencing external content
608==================================
609
610With Sphinx's help, we can create
611link-references to any tagged text within the Zephyr Project documentation.
612
613Target locations in a document are defined with a label directive::
614
615      .. _my label name:
616
617      Heading
618      =======
619
620Note the leading underscore indicating an inbound link.
621The content immediately following
622this label must be a heading, and is the target for a ``:ref:`my label name```
623reference from anywhere within the Zephyr documentation.
624The heading text is shown when referencing this label.
625You can also change the text that's displayed for this link, such as::
626
627   :ref:`some other text <my label name>`
628
629
630To enable easy cross-page linking within the site, each file should have
631a reference label before its title so it can
632be referenced from another file. These reference labels must be unique
633across the whole site, so generic names such as "samples" should be
634avoided.  For example the top of this document's .rst file is::
635
636   .. _doc_guidelines:
637
638   Documentation Guidelines for the Zephyr Project
639   ###############################################
640
641
642Other .rst documents can link to this document using the ``:ref:`doc_guidelines``` tag and
643it will show up as :ref:`doc_guidelines`.  This type of internal cross reference works across
644multiple files, and the link text is obtained from the document source so if the title changes,
645the link text will update as well.
646
647You can also define links to any URL and then reference it in your document.
648For example, with this label definition in the document::
649
650   .. _Zephyr Wikipedia Page:
651      https://en.wikipedia.org/wiki/Zephyr_(operating_system)
652
653you can reference it with::
654
655   Read the `Zephyr Wikipedia Page`_ for more information about the
656   project.
657
658.. tip::
659
660   When a document contains many external links, it can be useful to list them in a single
661   "References" section at the end of the document. This can be done using the
662   :rst:dir:`target-notes` directive. Example::
663
664      References
665      ==========
666
667      .. target-notes::
668
669      .. _external_link1: https://example.com
670      .. _external_link2: https://example.org
671
672Cross-referencing C documentation
673=================================
674
675.. rst:role:: c:member
676              c:data
677              c:var
678              c:func
679              c:macro
680              c:struct
681              c:union
682              c:enum
683              c:enumerator
684              c:type
685
686   You may use these roles to cross-reference the Doxygen documentation of C functions, macros,
687   types, etc.
688
689   They are rendered in the HTML output as links to the corresponding Doxygen documentation for the
690   item. For example::
691
692      Check out :c:function:`gpio_pin_configure` for more information.
693
694   Will render as:
695
696      Check out :c:func:`gpio_pin_configure` for more information.
697
698   You may provide a custom link text, similar to the built-in :rst:role:`ref` role.
699
700Visual Elements
701***************
702
703.. _doc_images:
704
705Images
706======
707
708Images are included in the documentation by using an :rst:dir:`image` directive::
709
710   .. image:: ../../images/doc-gen-flow.png
711      :align: center
712      :alt: alt text for the image
713
714or if you'd like to add an image caption, use::
715
716    .. figure:: ../../images/doc-gen-flow.png
717       :alt: image description
718
719       Caption for the figure
720
721The file name specified is relative to the document source file,
722and we recommend putting images into an ``images`` folder where the document
723source is found.
724
725The usual image formats handled by a web browser are supported: WebP, PNG, GIF,
726JPEG, and SVG.
727
728Keep the image size only as large as needed, generally at least 500 px wide but
729no more than 1000 px, and no more than 100 KB unless a particularly large image
730is needed for clarity.
731
732Recommended image formats based on content
733------------------------------------------
734
735* **Screenshots**: WebP or PNG.
736* **Diagrams**: Consider using Graphviz for simple diagrams (see
737  `dedicated section <graphviz_diagrams>`_ below. If using an external tool, SVG is preferred.
738* **Photos** (ex. boards): WebP. Use transparency if possible/available.
739
740
741.. _graphviz_diagrams:
742
743Graphviz
744========
745
746`Graphviz`_ is a tool for creating diagrams specified in a simple text language. As it's important
747to allow for diagrams used in the documentation to be easily maintained, we encourage the use of
748Graphviz for creating diagrams. Graphviz is particularly well suited for creating state diagrams, flow
749charts, and other types of diagrams that can be expressed as a graph.
750
751To include a Graphviz diagram in a document, use the :rst:dir:`graphviz` directive. For example::
752
753   .. graphviz::
754
755      digraph G {
756         rankdir=LR;
757         A -> B;
758         B -> C;
759         C -> D;
760      }
761
762Would render as:
763
764   .. graphviz::
765
766      digraph G {
767         rankdir=LR;
768         A -> B;
769         B -> C;
770         C -> D;
771      }
772
773Please refer to the `Graphviz documentation`_ for more information on how to create diagrams using
774Graphviz's DOT language.
775
776.. _Graphviz: https://graphviz.org
777.. _Graphviz documentation: https://graphviz.org/documentation
778
779
780Custom Sphinx Roles and Directives
781**********************************
782
783The Zephyr documentation uses custom Sphinx roles and directives to provide additional functionality
784and to make it easier to write and maintain consistent documentation.
785
786Application build commands
787==========================
788
789.. rst:directive:: .. zephyr-app-commands::
790
791   Generate consistent documentation of the shell commands needed to manage (build, flash, etc.) an
792   application
793
794   For example, to generate commands to build ``samples/hello_world`` for ``qemu_x86`` use::
795
796      .. zephyr-app-commands::
797         :zephyr-app: samples/hello_world
798         :board: qemu_x86
799         :goals: build
800
801   This will render as:
802
803      .. zephyr-app-commands::
804         :zephyr-app: samples/hello_world
805         :board: qemu_x86
806         :goals: build
807
808   .. rubric::  Options
809
810   .. rst:directive:option:: tool
811      :type: string
812
813      Which tool to use. Valid options are currently ``cmake``, ``west`` and ``all``.
814      The default is ``west``.
815
816   .. rst:directive:option:: app
817      :type: string
818
819      Path to the application to build.
820
821   .. rst:directive:option:: zephyr-app
822      :type: string
823
824      Path to the application to build, this is an app present in the upstream zephyr repository.
825      Mutually exclusive with ``:app:``.
826
827   .. rst:directive:option:: cd-into
828      :type: no value
829
830      If set, build instructions are given from within the ``:app:`` folder, instead of outside of
831      it.
832
833   .. rst:directive:option:: generator
834      :type: string
835
836      Which build system to generate.
837
838      Valid options are currently ``ninja`` and ``make``. The default is ``ninja``. This option is
839      not case sensitive.
840
841   .. rst:directive:option:: host-os
842
843      Which host OS the instructions are for.
844
845      Valid options are ``unix``, ``win`` and ``all``. The default is ``all``.
846
847   .. rst:directive:option:: board
848      :type: string
849
850      If set, build commands will target the given board.
851
852   .. rst:directive:option:: shield
853      :type: string
854
855      If set, build commands will target the given shield.
856
857      Multiple shields can be provided in a comma separated list.
858
859   .. rst:directive:option:: conf
860
861      If set, build commands will use the given configuration file(s).
862
863      If multiple configuration files are provided, enclose the space-separated list of files with
864      double quotes, e.g., `"a.conf b.conf"`.
865
866   .. rst:directive:option:: gen-args
867      :type: string
868
869      If set, indicates additional arguments to the CMake invocation.
870
871   .. rst:directive:option:: build-args
872      :type: string
873
874      If set, indicates additional arguments to the build invocation.
875
876   .. rst:directive:option:: west-args
877      :type: string
878
879      If set, additional arguments to the west invocation (ignored for ``:tool: cmake``).
880
881   .. rst:directive:option:: flash-args
882      :type: string
883
884      If set, additional arguments to the flash invocation.
885
886   .. rst:directive:option:: snippets
887      :type: string
888
889      If set, indicates the application should be compiled with the listed snippets.
890
891      Multiple snippets can be provided in a comma separated list.
892
893   .. rst:directive:option:: build-dir
894      :type: string
895
896      If set, the application build directory will *APPEND* this relative, Unix-separated, path to
897      the standard build directory. This is mostly useful for distinguishing builds for one
898      application within a single page.
899
900   .. rst:directive:option:: build-dir-fmt
901      :type: string
902
903      If set, assume that `west config build.dir-fmt`` has been set to this path.
904
905      Exclusive with ``:build-dir:`` and depends on ``:tool: west``.
906
907   .. rst:directive:option:: goals
908      :type: string
909
910      A whitespace-separated list of what to do with the app (any of ``build``, ``flash``,
911      ``debug``, ``debugserver``, ``run``).
912
913      Commands to accomplish these tasks will be generated in the right order.
914
915   .. rst:directive:option:: maybe-skip-config
916      :type: no value
917
918      If set, this indicates the reader may have already created a build directory and changed
919      there, and will tweak the text to note that doing so again is not necessary.
920
921   .. rst:directive:option:: compact
922      :type: no value
923
924      If set, the generated output is a single code block with no additional comment lines.
925
926
927.. _linking_to_zephyr_files:
928
929Cross-referencing files in the Zephyr tree
930==========================================
931
932Special roles are available to reference files in the Zephyr tree. For example, referencing this
933very file can be done using the :rst:role:`zephyr_file` role.
934
935.. rst:role:: zephyr_file
936
937   This role is used to reference a file in the Zephyr tree. For example::
938
939      Check out :zephyr_file:`doc/contribute/documentation/guidelines.rst` for more information.
940
941   Will render as:
942
943      Check out :zephyr_file:`doc/contribute/documentation/guidelines.rst` for more information.
944
945   You can reference specific lines or line ranges in a file by appending :samp:`#L{line_number}` or
946   :samp:`#L{start_line}-L{end_line}` to the file path::
947
948      See :zephyr_file:`doc/contribute/documentation/guidelines.rst#L3` for the main heading of
949      this document.
950
951   Will render as:
952
953      See :zephyr_file:`doc/contribute/documentation/guidelines.rst#L3` for the main heading of
954      this document.
955
956   The role automatically verifies that the referenced file exists in the Zephyr tree and will
957   generate a warning during documentation build if the file is not found.
958
959   .. note::
960
961      Use the line references sparingly as keeping them accurate over time can be challenging as the
962      content of the linked file is subject to change.
963
964   You may use the :rst:role:`zephyr_raw` role instead if you want to reference the "raw" content.
965
966.. rst:role:: zephyr_raw
967
968   This role is used to reference the raw content of a file in the Zephyr tree. For example::
969
970      Check out :zephyr_raw:`doc/contribute/documentation/guidelines.rst` for more information.
971
972   Will render as:
973
974      Check out :zephyr_raw:`doc/contribute/documentation/guidelines.rst` for more information.
975
976.. rst:role:: module_file
977
978   This role is used to reference a module in the Zephyr tree. For example::
979
980         Check out :module_file:`hal_stm32:CMakeLists.txt` for more information.
981
982   Will render as:
983
984         Check out :module_file:`hal_stm32:CMakeLists.txt` for more information.
985
986   Similar to :rst:role:`zephyr_file`, you can reference specific lines or line ranges in a file.
987
988Cross-referencing GitHub issues and pull requests
989=================================================
990
991.. rst:role:: github
992
993   This role is used to reference a GitHub issue or pull request.
994
995   For example, to reference issue #1234::
996
997      Check out :github:`1234` for more background about this known issue.
998
999   This will render as:
1000
1001      Check out :github:`1234` for more background about this known issue.
1002
1003Doxygen API documentation
1004=========================
1005
1006.. app.add_directive("doxygengroup", DoxygenGroupDirective)
1007.. app.add_role_to_domain("c", "group", CXRefRole())
1008
1009.. rst:directive:: .. doxygengroup:: name
1010
1011   This directive is used to output a short description of a Doxygen group and a link to the
1012   corresponding Doxygen-generated documentation.
1013
1014   All the code samples (declared using the :rst:dir:`zephyr:code-sample` directive) indicating the
1015   group as relevant will automatically be list and referenced in the rendered output.
1016
1017   For example::
1018
1019      .. doxygengroup:: can_interface
1020
1021   Will render as:
1022
1023      .. doxygengroup:: can_interface
1024
1025
1026   .. rubric:: Options
1027
1028   .. rst:directive:option:: project
1029      :type: project name (optional)
1030
1031      Associated Doxygen project. This can be useful when multiple Doxygen
1032      projects are configured.
1033
1034.. rst:role:: c:group
1035
1036   This role is used to reference a Doxygen group in the Zephyr tree. In the HTML documentation,
1037   they are rendered as links to the corresponding Doxygen-generated documentation for the group.
1038   For example::
1039
1040      Check out :c:group:`gpio_interface` for more information.
1041
1042   Will render as:
1043
1044      Check out :c:group:`gpio_interface` for more information.
1045
1046   You may provide a custom link text, similar to the built-in :rst:role:`ref` role.
1047
1048
1049Kconfig options
1050===============
1051
1052If you want to reference a Kconfig option from a document, you can use the
1053:rst:role:`kconfig:option` role and provide the name of the option you want to reference. The role
1054will automatically generate a link to the documentation of the Kconfig option when building HTML
1055output.
1056
1057Make sure to use the full name of the Kconfig option, including the ``CONFIG_`` prefix.
1058
1059.. rst:role:: kconfig:option
1060
1061   This role is used to reference a Kconfig option in the Zephyr tree. For example::
1062
1063      Check out :kconfig:option:`CONFIG_GPIO` for more information.
1064
1065   Will render as:
1066
1067      Check out :kconfig:option:`CONFIG_GPIO` for more information.
1068
1069Devicetree bindings
1070===================
1071
1072If you want to reference a Devicetree binding from a document, you can use the
1073:rst:role:`dtcompatible` role and provide the compatible string of the binding you want to
1074reference. The role will automatically generate a link to the documentation of the binding when
1075building HTML output.
1076
1077.. rst:role:: dtcompatible
1078
1079   This role can be used inline to make a reference to the generated documentation for the
1080   Devicetree compatible given as argument.
1081
1082   There may be more than one page for a single compatible. For example, that happens if a binding
1083   behaves differently depending on the bus the node is on. If that occurs, the reference points at
1084   a "disambiguation" page which links out to all the possibilities, similarly to how Wikipedia
1085   disambiguation pages work. Example::
1086
1087      Check out :dtcompatible:`zephyr,input-longpress` for more information.
1088
1089   Will render as:
1090
1091      Check out :dtcompatible:`zephyr,input-longpress` for more information.
1092
1093Code samples
1094============
1095
1096.. rst:directive:: .. zephyr:code-sample:: id
1097
1098   This directive is used to describe a code sample, including which noteworthy APIs it may be
1099   exercising.
1100
1101   For example::
1102
1103      .. zephyr:code-sample:: blinky
1104         :name: Blinky
1105         :relevant-api: gpio_interface
1106
1107         Blink an LED forever using the GPIO API.
1108
1109   The content of the directive is used as the description of the code sample.
1110
1111   .. rubric:: Options
1112
1113   .. rst:directive:option:: name
1114      :type: text
1115
1116      Indicates the human-readable short name of the sample.
1117
1118   .. rst:directive:option:: relevant-api
1119      :type: text
1120
1121      Optional space-separated list of Doxygen group names that correspond to the APIs exercised
1122      by the code sample.
1123
1124.. rst:role:: zephyr:code-sample
1125
1126   This role is used to reference a code sample described using :rst:dir:`zephyr:code-sample`.
1127
1128   For example::
1129
1130      Check out :zephyr:code-sample:`blinky` for more information.
1131
1132   Will render as:
1133
1134      Check out :zephyr:code-sample:`blinky` for more information.
1135
1136   This can be used exactly like the built-in :rst:role:`ref` role, i.e. you may provide a custom
1137   link text. For example::
1138
1139      Check out :zephyr:code-sample:`blinky code sample <blinky>` for more information.
1140
1141   Will render as:
1142
1143      Check out :zephyr:code-sample:`blinky code sample <blinky>` for more information.
1144
1145.. rst:directive:: .. zephyr:code-sample-category:: id
1146
1147   This directive is used to define a category for grouping code samples.
1148
1149   For example::
1150
1151      .. zephyr:code-sample-category:: gpio
1152         :name: GPIO
1153         :show-listing:
1154
1155         Samples related to the GPIO subsystem.
1156
1157   The contents of the directive is used as the description of the category. It can contain any
1158   valid reStructuredText content.
1159
1160   .. rubric:: Options
1161
1162   .. rst:directive:option:: name
1163      :type: text
1164
1165      Indicates the human-readable name of the category.
1166
1167   .. rst:directive:option:: show-listing
1168      :type: flag
1169
1170      If set, a listing of code samples in the category will be shown. The listing is automatically
1171      generated based on all code samples found in the subdirectories of the current document.
1172
1173   .. rst:directive:option:: glob
1174      :type: text
1175
1176      A glob pattern to match the files to include in the listing. The default is `*/*` but it can
1177      be overridden e.g. when samples may be found in directories not sitting directly under the
1178      category directory.
1179
1180.. rst:role:: zephyr:code-sample-category
1181
1182   This role is used to reference a code sample category described using
1183   :rst:dir:`zephyr:code-sample-category`.
1184
1185   For example::
1186
1187      Check out :zephyr:code-sample-category:`cloud` samples for more information.
1188
1189   Will render as:
1190
1191      Check out :zephyr:code-sample-category:`cloud` samples for more information.
1192
1193.. rst:directive:: .. zephyr:code-sample-listing::
1194
1195   This directive is used to show a listing of all code samples found in one or more categories.
1196
1197   For example::
1198
1199      .. zephyr:code-sample-listing::
1200         :categories: cloud
1201
1202   Will render as:
1203
1204      .. zephyr:code-sample-listing::
1205         :categories: cloud
1206
1207   .. rubric:: Options
1208
1209   .. rst:directive:option:: categories
1210      :type: text
1211
1212      A space-separated list of category IDs for which to show the listing.
1213
1214   .. rst:directive:option:: live-search
1215      :type: flag
1216
1217      A flag to include a search box right above the listing. The search box allows users to filter
1218      the listing by code sample name/description, which can be useful for categories with a large
1219      number of samples. This option is only available in the HTML builder.
1220
1221Boards
1222======
1223
1224.. rst:directive:: .. zephyr:board:: name
1225
1226   This directive is used at the beginning of a document to indicate it is the main documentation
1227   page for a board whose name is given as the directive argument.
1228
1229   For example::
1230
1231      .. zephyr:board:: wio_terminal
1232
1233   The metadata for the board is read from various config files and used to automatically populate
1234   some sections of the board documentation. A board documentation page that uses this directive
1235   can be linked to using the :rst:role:`zephyr:board` role.
1236
1237.. rst:role:: zephyr:board
1238
1239   This role is used to reference a board documented using :rst:dir:`zephyr:board`.
1240
1241   For example::
1242
1243      Check out :zephyr:board:`wio_terminal` for more information.
1244
1245   Will render as:
1246
1247      Check out :zephyr:board:`wio_terminal` for more information.
1248
1249.. rst:directive:: .. zephyr:board-catalog::
1250
1251   This directive is used to generate a catalog of Zephyr-supported boards that can be used to
1252   quickly browse the list of all supported boards and filter them according to various criteria.
1253
1254.. rst:directive:: .. zephyr:board-supported-hw::
1255
1256   This directive is used to show supported hardware features for all the targets of the board
1257   documented in the current page. The tables are automatically generated based on the board's
1258   Devicetree.
1259
1260   The directive must be used in a document that also contains a :rst:dir:`zephyr:board` directive,
1261   as it relies on the board information to generate the table.
1262
1263   .. note::
1264
1265      This directive requires that the documentation is built with hardware features generation enabled
1266      (``zephyr_generate_hw_features`` config option set to ``True``). If disabled, a warning message
1267      will be shown instead of the hardware features tables.
1268
1269References
1270**********
1271
1272.. target-notes::
1273