Skip to content

Commit 8a8a2a8

Browse files
greg-ferRuth Fuchss
authored andcommitted
doc: finalize documentation style guide
Removed TBS and PH elements. Added new examples and sections. Signed-off-by: Grzegorz Ferenc <[email protected]>
1 parent 0529658 commit 8a8a2a8

File tree

2 files changed

+148
-66
lines changed

2 files changed

+148
-66
lines changed

doc/nrf/doc_styleguide.rst

Lines changed: 145 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,28 @@
33
Documentation style guide
44
#########################
55

6-
.. note::
7-
8-
These style guides are not finalized. Details may change.
9-
106
NCS documentation is written in two formats:
117

12-
* Doxygen for API documentation
8+
* doxygen for API documentation
139
* RST for conceptual documentation
1410

1511

1612
RST style guide
1713
***************
1814

19-
See :ref:`zephyr:doc_guidelines` for a short introduction to RST and, most importantly, to the conventions used in Zephyr.
15+
See Zephyr's :ref:`zephyr:doc_guidelines` for a short introduction to RST and, most importantly, to the conventions used in Zephyr.
2016
More information about RST is available in the `reStructuredText Primer`_.
2117

2218
The |NCS| documentation follows the Zephyr style guide, and adds a few more restrictive rules:
2319

2420
* Headings use sentence case, which means that the first word is capitalized, and the following words use normal capitalization.
2521
* Do not use consecutive headings without intervening text.
26-
* For readability reasons, start every sentence on a new line in the source files.
22+
* For readability reasons, start every sentence on a new line in the source files and do not add line breaks within the sentence.
2723
In the output, consecutive lines without blank lines in between are combined into one paragraph.
2824

25+
.. note:: For the conceptual documentation written in RST, you can have more than 80 characters per line.
26+
The requirement for 80 characters per line applies only to the code documentation written in doxygen.
27+
2928
Hyperlinks
3029
==========
3130

@@ -44,6 +43,39 @@ It is also possible to define more than one default link text for a link, which
4443
.. _`Link text one`:
4544
.. _`Link text two`: http://..
4645

46+
Diagrams
47+
========
48+
49+
You can include Message Sequence Chart (MSC) diagrams in RST by using the ``.. msc::`` directive and including the MSC content, for example:
50+
51+
.. code-block:: python
52+
53+
.. msc::
54+
hscale = "1.3";
55+
Module,Application;
56+
Module<<Application [label="nrf_cloud_connect() returns successfully"];
57+
Module>>Application [label="NRF_CLOUD_EVT_TRANSPORT_CONNECTED"];
58+
Module>>Application [label="NRF_CLOUD_EVT_USER_ASSOCIATION_REQUEST"];
59+
Module<<Application [label="nrf_cloud_user_associate()"];
60+
Module>>Application [label="NRF_CLOUD_EVT_USER_ASSOCIATED"];
61+
Module>>Application [label="NRF_CLOUD_EVT_READY"];
62+
Module>>Application [label="NRF_CLOUD_EVT_TRANSPORT_DISCONNECTED"];
63+
64+
65+
This will generate the following output:
66+
67+
.. msc::
68+
hscale = "1.3";
69+
Module,Application;
70+
Module<<Application [label="nrf_cloud_connect() returns successfully"];
71+
Module>>Application [label="NRF_CLOUD_EVT_TRANSPORT_CONNECTED"];
72+
Module>>Application [label="NRF_CLOUD_EVT_USER_ASSOCIATION_REQUEST"];
73+
Module<<Application [label="nrf_cloud_user_associate()"];
74+
Module>>Application [label="NRF_CLOUD_EVT_USER_ASSOCIATED"];
75+
Module>>Application [label="NRF_CLOUD_EVT_READY"];
76+
Module>>Application [label="NRF_CLOUD_EVT_TRANSPORT_DISCONNECTED"];
77+
78+
4779
Kconfig
4880
=======
4981

@@ -54,23 +86,26 @@ Kconfig options can be linked to from RST by using the ``:option:`` domain::
5486
Breathe
5587
=======
5688

57-
The Breathe Sphinx plugin provides a bridge between RST and Doxygen.
89+
The Breathe Sphinx plugin provides a bridge between RST and doxygen.
5890

59-
The Doxygen documentation is not automatically included in RST.
91+
The doxygen documentation is not automatically included in RST.
6092
Therefore, every group must be explicitly added to an RST file.
6193

62-
See the following example for including a doxygen group:
63-
6494
.. code-block:: python
95+
:caption: Example of how to include a doxygen group
6596
6697
.. doxygengroup:: bluetooth_gatt_throughput
6798
:project: nrf
6899
:members:
69100
101+
102+
.. note::
103+
Including a group on a page does not include all its subgroups automatically.
104+
To include subgroups, list them on the page of the group they belong to.
105+
70106
The `Breathe documentation`_ contains information about what you can link to.
71107

72-
To link directly to a Doxygen reference from RST, use the following breathe
73-
domains:
108+
To link directly to a doxygen reference from RST, use the following Breathe domains:
74109

75110
* Function: ``:cpp:func:``
76111
* Structure: ``:c:type:``
@@ -80,31 +115,31 @@ domains:
80115
* Structure member: ``:cpp:member:``
81116

82117
.. note::
83-
The ``:cpp:enum:`` and ``:cpp:enumerator:`` domains do not generate a link
84-
due to `breathe issue #437`_. As a workaround, use the following command::
118+
The ``:cpp:enum:`` and ``:cpp:enumerator:`` domains do not generate a link due to `Breathe issue #437`_.
119+
As a workaround, use the following command::
85120

86-
:cpp:enumerator:`ENUM_VALUE <DOXYGEN_GROUP>::ENUM_VALUE`
121+
:cpp:enumerator:`ENUM_VALUE <DOXYGEN_GROUP::ENUM_VALUE>`
87122

88123
Doxygen style guide
89124
*******************
90125

91-
This style guide covers guidelines for the Doxygen-based API documentation.
126+
This style guide covers guidelines for the doxygen-based API documentation.
92127

93128
General documentation guidelines
94129
================================
95130

96131
#. Always use full sentences, except for descriptions for variables, structs, and enums, where sentence fragments with no verb are accepted, and always end everything with period.
97132
#. Everything that is documented must belong to a group (see below).
98-
#. Use capitalization sparingly; when in doubt, use lowercase. *We'll create a list of terms that should be capitalized.*
99-
#. Line breaks: In Doxygen, break after 80 characters (following the dev guidelines). In RST, break after each sentence.
133+
#. Use capitalization sparingly. When in doubt, use lowercase.
134+
#. Line breaks: In doxygen, break after 80 characters (following the dev guidelines). In RST, break after each sentence.
100135
#. **@note** and **@warning** should only be used in the details section, and only when really needed for emphasis.
101136
Use notes for emphasis and warnings if things will really really go wrong if you ignore the warning.
102137

103138
File headers and groups
104139
=======================
105140

106141
#. **@file** element is always required at the start of a file.
107-
#. **There is no need to use @brief** for **@file**. *Coding Style page on Vestavind needs to be updated.*
142+
#. There is no need to use **@brief** for **@file**.
108143
#. **@defgroup** or **@addgroup** usually follows **@file**.
109144
You can divide a file into several groups as well.
110145
#. **@{** must open the group, **@}** must close it.
@@ -165,51 +200,87 @@ File headers and groups
165200
Functions
166201
=========
167202

168-
#. **Do not use @fn**. Instead, document each function where it is defined.
203+
#. Do not use **@fn**. Instead, document each function where it is defined.
169204
#. **@brief** is mandatory.
170205

171-
* Start the brief with the "do sth" form (for example, "Initialize the module", "Send Boot Keyboard Input Report").
206+
* Start the brief with the "do sth" form.
207+
208+
.. code-block:: none
209+
:caption: Brief documentation examples
210+
211+
/** @brief Request a read operation to be executed from Secure Firmware.
212+
213+
/** @brief Send Boot Keyboard Input Report.
172214
173215
#. **@details** is optional.
174216
It can be introduced either by using **@details** or by leaving a blank line after **@brief**.
175217
#. **@param** should be used for every parameter.
176218

177219
* Always add parameter description.
178220
Use a sentence fragment (no verb) with period at the end.
179-
* Specify for all parameters whether they are ``[in]``, ``[out]``, or ``[in,out]``. *- TBD*
221+
* Make sure the parameter documentation within the function is consistently using the parameter type: ``[in]``, ``[out]``, or ``[in,out]``.
222+
223+
.. code-block:: none
224+
:caption: Parameter documentation example
225+
226+
* @param[out] destination Pointer to destination array where the content is
227+
* to be copied.
228+
* @param[in] addr Address to be copied from.
229+
* @param[in] len Number of bytes to copy.
180230
181231
#. If you include more than one **@sa** ("see also", optional), add them this way::
182232

183233
@sa first_function
184234
@sa second_function
185235

186-
#. **@return** should be used to describe a return value (for example, "@return The length of ...", "@return The handle").
236+
#. **@return** should be used to describe a generic return value without a specific value (for example, "@return The length of ...", "@return The handle").
187237
There is usually only one return value.
238+
239+
.. code-block:: none
240+
:caption: Return documentation example
241+
242+
* @return Initializer that sets up the pipe, length, and byte array for
243+
* content of the TX data.
244+
188245
#. **@retval** should be used for specific return values (for example, "@retval true", "@retval CONN_ERROR").
189246
Describe the condition for each of the return values (for example, "If the function completes successfully", "If the connection cannot be established").
190-
If there is only one retval, add what happens otherwise. Example: "Otherwise, an error code is returned".
191-
#. **Do not use @returns**.
247+
248+
.. code-block:: none
249+
:caption: Retval documentation example
250+
251+
* @retval 0 If the operation was successful.
252+
* Otherwise, a (negative) error code is returned.
253+
* @retval (-ENOTSUP) Special error code used when the UUID
254+
* of the service does not match the expected UUID.
255+
256+
#. Do not use **@returns**.
192257
Use **@return** instead.
193258

194259
.. code-block:: c
195-
:caption: Function documentation example
196-
197-
/** @brief Send Boot Keyboard Input Report.
198-
*
199-
* @param hids_obj HIDS instance.
200-
* @param rep Pointer to the report data.
201-
* @param len Length of report data.
202-
*
203-
* @retval 0 If the operation was successful.
204-
* Otherwise, a (negative) error code is returned.
205-
*/
206-
int hids_boot_kb_inp_rep_send(struct hids *hids_obj, u8_t const *rep,
207-
u16_t len);
260+
:caption: Complete function documentation example
261+
262+
/** @brief Request a random number from the Secure Firmware.
263+
*
264+
* This function provides a True Random Number from the on-board random number generator.
265+
*
266+
* @note Currently, the RNG hardware is run each time this function is called. This
267+
* consumes significant time and power.
268+
*
269+
* @param[out] output The random number. Must be at least @p len long.
270+
* @param[in] len The length of the output array. Currently, @p len must be
271+
* 144.
272+
* @param[out] olen The length of the random number provided.
273+
*
274+
* @retval 0 If the operation was successful.
275+
* @retval -EINVAL If @p len is invalid. Currently, @p len must be 144.
276+
*/
277+
int spm_request_random_number(u8_t *output, size_t len, size_t *olen);
208278
209279
Enums
210280
=====
211281

212282
The documentation block should precede the documented element.
283+
This is in accordance with the `Zephyr coding style`_.
213284

214285

215286
.. code-block:: c
@@ -229,6 +300,7 @@ Structs
229300
=======
230301

231302
The documentation block should precede the documented element.
303+
This is in accordance with the `Zephyr coding style`_.
232304
Make sure to add ``:members:`` when you include the API documentation in RST; otherwise, the member documentation will not show up.
233305

234306
.. code-block:: c
@@ -248,43 +320,52 @@ Make sure to add ``:members:`` when you include the API documentation in RST; ot
248320
const struct event_type *type_id;
249321
};
250322
323+
324+
.. note::
325+
Always add a name for the struct.
326+
Avoid using unnamed structs due to `Sphinx parser issue`_.
327+
328+
251329
References
252330
==========
253331

254-
To link to functions, enums, or structs from within Doxygen itself, use the
332+
To link to functions, enums, or structs from within doxygen itself, use the
255333
``@ref`` keyword.
256334

257-
.. code-block:: c
335+
.. code-block:: none
258336
:caption: Reference documentation example
259337
260-
/** @brief Event header structure.
261-
* Use this structure with the function @ref function_name and
262-
* this structure is related to another structure, @ref structure_name.
263-
*/
338+
/** @brief Event header structure.
339+
* Use this structure with the function @ref function_name and
340+
* this structure is related to another structure, @ref structure_name.
341+
*/
264342
265343
.. note::
266-
Linking to functions does not currently work due to `breathe issue #438`_.
344+
Linking to functions does not currently work due to `Breathe issue #438`_.
267345

268346

269-
Typedefs - WIP
270-
==============
347+
Typedefs
348+
========
271349

272-
#. The documentation block should follow, not precede, the documented element.
273-
#. The C99-style single line comment, ``//``, is not allowed, as per `Zephyr coding style`_.
350+
The documentation block should precede the documented element.
351+
This is in accordance with the `Zephyr coding style`_.
274352

275353
.. code-block:: c
276-
:caption: Typedef documentation example -- PH
277-
278-
TBD
279-
280-
TBD
281-
==============
282-
283-
@def, @fn should not be used for defines or functions; Zephyr seems to require this but we should be ok without this.
284-
Just use a @brief and let doxygen figure out what exactly you are documenting.
285-
286-
For parameters, it is recommended to specify whether they are [in], [out], or [in,out].
287-
If you specify this for one parameter in a function, all others must have it as well, for consistency. *To be discussed if this should be a requirement.*
354+
:caption: Typedef documentation example
355+
356+
/**
357+
* @brief Download client asynchronous event handler.
358+
*
359+
* Through this callback, the application receives events, such as
360+
* download of a fragment, download completion, or errors.
361+
*
362+
* If the callback returns a non-zero value, the download stops.
363+
* To resume the download, use @ref download_client_start().
364+
*
365+
* @param[in] event The event.
366+
*
367+
* @retval 0 The download continues.
368+
* @retval non-zero The download stops.
369+
*/
370+
typedef int (*download_client_callback_t)(const struct download_client_evt *event);
288371
289-
What about @warning, @pre, and other rare doxygen tags?
290-
Should we have a rule for these?

doc/nrf/links.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@
132132

133133
.. _`SMP over Bluetooth`: https://github.com/apache/mynewt-mcumgr/blob/master/transport/smp-bluetooth.md
134134

135-
.. _`breathe issue #437`: https://github.com/michaeljones/breathe/issues/437
136-
.. _`breathe issue #438`: https://github.com/michaeljones/breathe/issues/438
135+
.. _`Breathe issue #437`: https://github.com/michaeljones/breathe/issues/437
136+
.. _`Breathe issue #438`: https://github.com/michaeljones/breathe/issues/438
137+
.. _`Sphinx parser issue`: https://github.com/sphinx-doc/sphinx/issues/2683
137138

138139
.. _`HIDAPI library`: https://github.com/libusb/hidapi
139140
.. _`HIDAPI releases`: https://github.com/libusb/hidapi/releases

0 commit comments

Comments
 (0)