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., ``\™`` 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 703Images 704====== 705 706Images are included in the documentation by using an :rst:dir:`image` directive:: 707 708 .. image:: ../../images/doc-gen-flow.png 709 :align: center 710 :alt: alt text for the image 711 712or if you'd like to add an image caption, use:: 713 714 .. figure:: ../../images/doc-gen-flow.png 715 :alt: image description 716 717 Caption for the figure 718 719The file name specified is relative to the document source file, 720and we recommend putting images into an ``images`` folder where the document 721source is found. 722 723The usual image formats handled by a web browser are supported: WebP, PNG, GIF, 724JPEG, and SVG. 725 726Keep the image size only as large as needed, generally at least 500 px wide but 727no more than 1000 px, and no more than 100 KB unless a particularly large image 728is needed for clarity. 729 730Recommended image formats based on content 731------------------------------------------ 732 733* **Screenshots**: WebP or PNG. 734* **Diagrams**: Consider using Graphviz for simple diagrams (see 735 `dedicated section <graphviz_diagrams>`_ below. If using an external tool, SVG is preferred. 736* **Photos** (ex. boards): WebP. Use transparency if possible/available. 737 738 739.. _graphviz_diagrams: 740 741Graphviz 742======== 743 744`Graphviz`_ is a tool for creating diagrams specified in a simple text language. As it's important 745to allow for diagrams used in the documentation to be easily maintained, we encourage the use of 746Graphviz for creating diagrams. Graphviz is particularly well suited for creating state diagrams, flow 747charts, and other types of diagrams that can be expressed as a graph. 748 749To include a Graphviz diagram in a document, use the :rst:dir:`graphviz` directive. For example:: 750 751 .. graphviz:: 752 753 digraph G { 754 rankdir=LR; 755 A -> B; 756 B -> C; 757 C -> D; 758 } 759 760Would render as: 761 762 .. graphviz:: 763 764 digraph G { 765 rankdir=LR; 766 A -> B; 767 B -> C; 768 C -> D; 769 } 770 771Please refer to the `Graphviz documentation`_ for more information on how to create diagrams using 772Graphviz's DOT language. 773 774.. _Graphviz: https://graphviz.org 775.. _Graphviz documentation: https://graphviz.org/documentation 776 777 778Custom Sphinx Roles and Directives 779********************************** 780 781The Zephyr documentation uses custom Sphinx roles and directives to provide additional functionality 782and to make it easier to write and maintain consistent documentation. 783 784Application build commands 785========================== 786 787.. rst:directive:: .. zephyr-app-commands:: 788 789 Generate consistent documentation of the shell commands needed to manage (build, flash, etc.) an 790 application 791 792 For example, to generate commands to build ``samples/hello_world`` for ``qemu_x86`` use:: 793 794 .. zephyr-app-commands:: 795 :zephyr-app: samples/hello_world 796 :board: qemu_x86 797 :goals: build 798 799 This will render as: 800 801 .. zephyr-app-commands:: 802 :zephyr-app: samples/hello_world 803 :board: qemu_x86 804 :goals: build 805 806 .. rubric:: Options 807 808 .. rst:directive:option:: tool 809 :type: string 810 811 Which tool to use. Valid options are currently ``cmake``, ``west`` and ``all``. 812 The default is ``west``. 813 814 .. rst:directive:option:: app 815 :type: string 816 817 Path to the application to build. 818 819 .. rst:directive:option:: zephyr-app 820 :type: string 821 822 Path to the application to build, this is an app present in the upstream zephyr repository. 823 Mutually exclusive with ``:app:``. 824 825 .. rst:directive:option:: cd-into 826 :type: no value 827 828 If set, build instructions are given from within the ``:app:`` folder, instead of outside of 829 it. 830 831 .. rst:directive:option:: generator 832 :type: string 833 834 Which build system to generate. 835 836 Valid options are currently ``ninja`` and ``make``. The default is ``ninja``. This option is 837 not case sensitive. 838 839 .. rst:directive:option:: host-os 840 841 Which host OS the instructions are for. 842 843 Valid options are ``unix``, ``win`` and ``all``. The default is ``all``. 844 845 .. rst:directive:option:: board 846 :type: string 847 848 If set, build commands will target the given board. 849 850 .. rst:directive:option:: shield 851 :type: string 852 853 If set, build commands will target the given shield. 854 855 Multiple shields can be provided in a comma separated list. 856 857 .. rst:directive:option:: conf 858 859 If set, build commands will use the given configuration file(s). 860 861 If multiple configuration files are provided, enclose the space-separated list of files with 862 double quotes, e.g., `"a.conf b.conf"`. 863 864 .. rst:directive:option:: gen-args 865 :type: string 866 867 If set, indicates additional arguments to the CMake invocation. 868 869 .. rst:directive:option:: build-args 870 :type: string 871 872 If set, indicates additional arguments to the build invocation. 873 874 .. rst:directive:option:: west-args 875 :type: string 876 877 If set, additional arguments to the west invocation (ignored for ``:tool: cmake``). 878 879 .. rst:directive:option:: flash-args 880 :type: string 881 882 If set, additional arguments to the flash invocation. 883 884 .. rst:directive:option:: snippets 885 :type: string 886 887 If set, indicates the application should be compiled with the listed snippets. 888 889 Multiple snippets can be provided in a comma separated list. 890 891 .. rst:directive:option:: build-dir 892 :type: string 893 894 If set, the application build directory will *APPEND* this relative, Unix-separated, path to 895 the standard build directory. This is mostly useful for distinguishing builds for one 896 application within a single page. 897 898 .. rst:directive:option:: build-dir-fmt 899 :type: string 900 901 If set, assume that `west config build.dir-fmt`` has been set to this path. 902 903 Exclusive with ``:build-dir:`` and depends on ``:tool: west``. 904 905 .. rst:directive:option:: goals 906 :type: string 907 908 A whitespace-separated list of what to do with the app (any of ``build``, ``flash``, 909 ``debug``, ``debugserver``, ``run``). 910 911 Commands to accomplish these tasks will be generated in the right order. 912 913 .. rst:directive:option:: maybe-skip-config 914 :type: no value 915 916 If set, this indicates the reader may have already created a build directory and changed 917 there, and will tweak the text to note that doing so again is not necessary. 918 919 .. rst:directive:option:: compact 920 :type: no value 921 922 If set, the generated output is a single code block with no additional comment lines. 923 924 925.. _linking_to_zephyr_files: 926 927Cross-referencing files in the Zephyr tree 928========================================== 929 930Special roles are available to reference files in the Zephyr tree. For example, referencing this 931very file can be done using the :rst:role:`zephyr_file` role, like this:: 932 933 Check out :zephyr_file:`doc/contribute/documentation/guidelines.rst` for more information. 934 935This would render as: 936 937 Check out :zephyr_file:`doc/contribute/documentation/guidelines.rst` for more information. 938 939You may use the :rst:role:`zephyr_raw` role instead if you want to reference the "raw" content. 940 941.. rst:role:: zephyr_file 942 943 This role is used to reference a file in the Zephyr tree. For example:: 944 945 Check out :zephyr_file:`doc/contribute/documentation/guidelines.rst` for more information. 946 947 Will render as: 948 949 Check out :zephyr_file:`doc/contribute/documentation/guidelines.rst` for more information. 950 951.. rst:role:: zephyr_raw 952 953 This role is used to reference the raw content of a file in the Zephyr tree. For example:: 954 955 Check out :zephyr_raw:`doc/contribute/documentation/guidelines.rst` for more information. 956 957 Will render as: 958 959 Check out :zephyr_raw:`doc/contribute/documentation/guidelines.rst` for more information. 960 961.. rst:role:: module_file 962 963 This role is used to reference a module in the Zephyr tree. For example:: 964 965 Check out :module_file:`hal_stm32:CMakeLists.txt` for more information. 966 967 Will render as: 968 969 Check out :module_file:`hal_stm32:CMakeLists.txt` for more information. 970 971 972Cross-referencing GitHub issues and pull requests 973================================================= 974 975.. rst:role:: github 976 977 This role is used to reference a GitHub issue or pull request. 978 979 For example, to reference issue #1234:: 980 981 Check out :github:`1234` for more background about this known issue. 982 983 This will render as: 984 985 Check out :github:`1234` for more background about this known issue. 986 987Doxygen API documentation 988========================= 989 990.. app.add_directive("doxygengroup", DoxygenGroupDirective) 991.. app.add_role_to_domain("c", "group", CXRefRole()) 992 993.. rst:directive:: .. doxygengroup:: name 994 995 This directive is used to output a short description of a Doxygen group and a link to the 996 corresponding Doxygen-generated documentation. 997 998 All the code samples (declared using the :rst:dir:`zephyr:code-sample` directive) indicating the 999 group as relevant will automatically be list and referenced in the rendered output. 1000 1001 For example:: 1002 1003 .. doxygengroup:: can_interface 1004 1005 Will render as: 1006 1007 .. doxygengroup:: can_interface 1008 1009.. rst:role:: c:group 1010 1011 This role is used to reference a Doxygen group in the Zephyr tree. In the HTML documentation, 1012 they are rendered as links to the corresponding Doxygen-generated documentation for the group. 1013 For example:: 1014 1015 Check out :c:group:`gpio_interface` for more information. 1016 1017 Will render as: 1018 1019 Check out :c:group:`gpio_interface` for more information. 1020 1021 You may provide a custom link text, similar to the built-in :rst:role:`ref` role. 1022 1023 1024Kconfig options 1025=============== 1026 1027If you want to reference a Kconfig option from a document, you can use the 1028:rst:role:`kconfig:option` role and provide the name of the option you want to reference. The role 1029will automatically generate a link to the documentation of the Kconfig option when building HTML 1030output. 1031 1032Make sure to use the full name of the Kconfig option, including the ``CONFIG_`` prefix. 1033 1034.. rst:role:: kconfig:option 1035 1036 This role is used to reference a Kconfig option in the Zephyr tree. For example:: 1037 1038 Check out :kconfig:option:`CONFIG_GPIO` for more information. 1039 1040 Will render as: 1041 1042 Check out :kconfig:option:`CONFIG_GPIO` for more information. 1043 1044Devicetree bindings 1045=================== 1046 1047If you want to reference a Devicetree binding from a document, you can use the 1048:rst:role:`dtcompatible` role and provide the compatible string of the binding you want to 1049reference. The role will automatically generate a link to the documentation of the binding when 1050building HTML output. 1051 1052.. rst:role:: dtcompatible 1053 1054 This role can be used inline to make a reference to the generated documentation for the 1055 Devicetree compatible given as argument. 1056 1057 There may be more than one page for a single compatible. For example, that happens if a binding 1058 behaves differently depending on the bus the node is on. If that occurs, the reference points at 1059 a "disambiguation" page which links out to all the possibilities, similarly to how Wikipedia 1060 disambiguation pages work. Example:: 1061 1062 Check out :dtcompatible:`zephyr,input-longpress` for more information. 1063 1064 Will render as: 1065 1066 Check out :dtcompatible:`zephyr,input-longpress` for more information. 1067 1068Code samples 1069============ 1070 1071.. rst:directive:: .. zephyr:code-sample:: id 1072 1073 This directive is used to describe a code sample, including which noteworthy APIs it may be 1074 exercising. 1075 1076 For example:: 1077 1078 .. zephyr:code-sample:: blinky 1079 :name: Blinky 1080 :relevant-api: gpio_interface 1081 1082 Blink an LED forever using the GPIO API. 1083 1084 The content of the directive is used as the description of the code sample. 1085 1086 .. rubric:: Options 1087 1088 .. rst:directive:option:: name 1089 :type: text 1090 1091 Indicates the human-readable short name of the sample. 1092 1093 .. rst:directive:option:: relevant-api 1094 :type: text 1095 1096 Optional space-separated list of Doxygen group names that correspond to the APIs exercised 1097 by the code sample. 1098 1099.. rst:role:: zephyr:code-sample 1100 1101 This role is used to reference a code sample described using :rst:dir:`zephyr:code-sample`. 1102 1103 For example:: 1104 1105 Check out :zephyr:code-sample:`blinky` for more information. 1106 1107 Will render as: 1108 1109 Check out :zephyr:code-sample:`blinky` for more information. 1110 1111 This can be used exactly like the built-in :rst:role:`ref` role, i.e. you may provide a custom 1112 link text. For example:: 1113 1114 Check out :zephyr:code-sample:`blinky code sample <blinky>` for more information. 1115 1116 Will render as: 1117 1118 Check out :zephyr:code-sample:`blinky code sample <blinky>` for more information. 1119 1120.. rst:directive:: .. zephyr:code-sample-category:: id 1121 1122 This directive is used to define a category for grouping code samples. 1123 1124 For example:: 1125 1126 .. zephyr:code-sample-category:: gpio 1127 :name: GPIO 1128 :show-listing: 1129 1130 Samples related to the GPIO subsystem. 1131 1132 The contents of the directive is used as the description of the category. It can contain any 1133 valid reStructuredText content. 1134 1135 .. rubric:: Options 1136 1137 .. rst:directive:option:: name 1138 :type: text 1139 1140 Indicates the human-readable name of the category. 1141 1142 .. rst:directive:option:: show-listing 1143 :type: flag 1144 1145 If set, a listing of code samples in the category will be shown. The listing is automatically 1146 generated based on all code samples found in the subdirectories of the current document. 1147 1148 .. rst:directive:option:: glob 1149 :type: text 1150 1151 A glob pattern to match the files to include in the listing. The default is `*/*` but it can 1152 be overridden e.g. when samples may be found in directories not sitting directly under the 1153 category directory. 1154 1155.. rst:role:: zephyr:code-sample-category 1156 1157 This role is used to reference a code sample category described using 1158 :rst:dir:`zephyr:code-sample-category`. 1159 1160 For example:: 1161 1162 Check out :zephyr:code-sample-category:`cloud` samples for more information. 1163 1164 Will render as: 1165 1166 Check out :zephyr:code-sample-category:`cloud` samples for more information. 1167 1168.. rst:directive:: .. zephyr:code-sample-listing:: 1169 1170 This directive is used to show a listing of all code samples found in one or more categories. 1171 1172 For example:: 1173 1174 .. zephyr:code-sample-listing:: 1175 :categories: cloud 1176 1177 Will render as: 1178 1179 .. zephyr:code-sample-listing:: 1180 :categories: cloud 1181 1182 .. rubric:: Options 1183 1184 .. rst:directive:option:: categories 1185 :type: text 1186 1187 A space-separated list of category IDs for which to show the listing. 1188 1189 .. rst:directive:option:: live-search 1190 :type: flag 1191 1192 A flag to include a search box right above the listing. The search box allows users to filter 1193 the listing by code sample name/description, which can be useful for categories with a large 1194 number of samples. This option is only available in the HTML builder. 1195 1196Boards 1197====== 1198 1199.. rst:directive:: .. zephyr:board:: name 1200 1201 This directive is used at the beginning of a document to indicate it is the main documentation 1202 page for a board whose name is given as the directive argument. 1203 1204 For example:: 1205 1206 .. zephyr:board:: wio_terminal 1207 1208 The metadata for the board is read from various config files and used to automatically populate 1209 some sections of the board documentation. A board documentation page that uses this directive 1210 can be linked to using the :rst:role:`zephyr:board` role. 1211 1212.. rst:role:: zephyr:board 1213 1214 This role is used to reference a board documented using :rst:dir:`zephyr:board`. 1215 1216 For example:: 1217 1218 Check out :zephyr:board:`wio_terminal` for more information. 1219 1220 Will render as: 1221 1222 Check out :zephyr:board:`wio_terminal` for more information. 1223 1224.. rst:directive:: .. zephyr:board-catalog:: 1225 1226 This directive is used to generate a catalog of Zephyr-supported boards that can be used to 1227 quickly browse the list of all supported boards and filter them according to various criteria. 1228 1229 1230References 1231********** 1232 1233.. target-notes:: 1234