blob: 8c5d1c46105628a0294b4c38356c869348247bd7 [file] [log] [blame]
Liviu Ionescu82b946d2016-03-02 12:43:48 +02001Rules for CMSIS API Function documentation
ReinhardKeilfc14d082016-02-18 15:36:24 +01002===========================================
3
Liviu Ionescu82b946d2016-03-02 12:43:48 +02004This document describes how to generate Doxygen-style documentation for middleware "Components".
ReinhardKeilfc14d082016-02-18 15:36:24 +01005It explains how the Doxygen documentation under "Reference" is provided in header (*.h),
6text (*.txt), template (*.c), and config files.
7
8Folder structure:
9 .\MW\component\Include *.h files
10 .\MW\component\Template *.c user code templates
11 .\MW\component\Config *.c or *.h config files
12 .\MW\Doc\component *.txt files
13 .\MW\Doc\component\images graphic files used by *.txt files
14
15Files: Middleware components have the following files that are used to generate the API documentation:
16
17 - *.h files: one or more header files which expose data types and functions (the API). Doxygen uses the *.h files
18 that are in .\MW\component\include folder.
19
20 - *.txt files: documentation files that group functions and explain overall the API. Each *.h file should have a *.txt
21 file with the same name, i.e. rl_usb.h => rl_usb.txt; a exception is permitted when a template is used to explain
Jonatan Antonie4a48772018-02-08 16:18:14 +010022 API functions.
ReinhardKeilfc14d082016-02-18 15:36:24 +010023
Liviu Ionescu82b946d2016-03-02 12:43:48 +020024 - *.c templates: show the usage of some middleware functionality and may be included in the Doxygen documentation.
ReinhardKeilfc14d082016-02-18 15:36:24 +010025 *.c templates with '%Instance%' are copied to .\MW\Doc\component and '%Instance%' is replaced with 'n', otherwise
Jonatan Antonie4a48772018-02-08 16:18:14 +010026 Doxygen uses the *.c templates in folder .\MW\component\Template. If a template is used in documentation
27 the related *.txt file has the same name as the template, i.e. USBD_User_HID.c => USBD_User_HID.txt.
28
ReinhardKeilfc14d082016-02-18 15:36:24 +010029 - *.c or *.h config files should be self-explaining using <i> tags. config files will not be replicated
30 in Doxygen *.txt files, but the high-level usage will be explained. The impact of parameters to middleware
Jonatan Antonie4a48772018-02-08 16:18:14 +010031 needs therefore be part of the config files.
ReinhardKeilfc14d082016-02-18 15:36:24 +010032
33Source files (*.c and *.h) should NOT use <TAB> character. Instead of <TAB> <space> characters are used.
34
35
36API Documentation in .\Include\*.h files
37----------------------------------------
38
39Example:
40
Liviu Ionescub6394cd2016-03-02 12:47:37 +020041The following snippet shows a sample documentation (correct). In general functions are grouped and
ReinhardKeilfc14d082016-02-18 15:36:24 +010042a short descriptive line is added before a group of functions. In case that functions are only
Liviu Ionescu82b946d2016-03-02 12:43:48 +020043relevant for the documentation (i.e. available in multiple instances), they are included in
ReinhardKeilfc14d082016-02-18 15:36:24 +010044#ifdef __DOXYGEN__ / #endif sections.
45
46{code}
Liviu Ionescu82b946d2016-03-02 12:43:48 +020047/// \brief Called during \ref USBD_Initialize to initialize the USB Device class.
ReinhardKeilfc14d082016-02-18 15:36:24 +010048/// \return none
49extern void USBD_HIDn_Initialize (void);
50
51// ==== USB Host Human Interface Device Functions ====
52
53/// \brief Get status of the Human Interface Device.
54/// \param[in] index instance index of HID.
55/// \return true device is configured and initialized.
56/// \return false device not ready.
57extern bool USBH_HID_GetStatus (uint8_t index);
58
59/// \brief Read data received from Human Interface Device.
60/// \param[in] index instance index of HID.
61/// \param[out] ptr_data data to be read.
62/// \return value >= 0 number of bytes read.
63/// \return value -1 communication error.
64extern int USBH_HID_Read (uint8_t index, uint8_t *ptr_data);
65
66/// \brief Write data to Human Interface Device.
67/// \param[in] index instance index of HID.
68/// \param[in] ptr_data data to be written.
69/// \param[in] data_len number of data bytes to be written.
70/// \return number of bytes written.
71extern int USBH_HID_Write (uint8_t index, uint8_t *ptr_data, uint16_t data_len);
72
73/// \brief Get last error that happened on the Human Interface Device.
74/// \param[in] index instance index of HID.
75/// \return error code.
76extern uint32_t USBH_HID_GetLastError (uint8_t index);
77
78/// \brief Retrieve state change since last call of HID Mouse.
79/// \param[in] index instance index of HID.
80/// \param[out] button pointer to variable that receives button state.
81/// \param[out] x pointer to variable that receives x position change.
82/// \param[out] y pointer to variable that receives y position change.
83/// \param[out] wheel pointer to variable that receives wheel change.
84/// \return true state change since last call.
85/// \return false no state change since last call.
86extern bool USBH_HID_GetMouseData (uint8_t index, uint8_t *button, int8_t *x, int8_t *y, int8_t *wheel);
87
88// ==== USB Device Human Interface Device Functions ====
89
90#ifdef __DOXYGEN__
91// following functions are available for each instance of a HID class.
92// generic prefix USBD_HIDn is USBD_HID0 for HID class instance 0.
93
94/// \brief Prepare HID report data to be sent.
95/// \param[in] rtype Report type
96/// - HID_REPORT_INPUT = Input report requested.
97/// - HID_REPORT_FEATURE = Feature report requested.
98/// \param[in] rid Report ID (0 if only one report exists)
99/// \param[out] buf Buffer for report data to be sent.
100/// \param[in] req Request type
101/// - USBD_HID_REQ_EP_CTRL = Control endpoint request.
102/// - USBD_HID_REQ_PERIOD_UPDATE = Idle period expiration request.
103/// - USBD_HID_REQ_EP_INT = Previously sent report on interrupt endpoint request.
104/// \return value >= 0 number of data bytes prepared
105/// \return value < 0 error code
106int32_t USBD_HIDn_GetReport (uint8_t rtype, uint8_t rid, uint8_t *buf, uint8_t req);
107
108{code}
109
110This section contains things that should be NOT DONE:
111
112/// \brief Prepares HID report data to be sent
113*** NO '.' to terminate brief documentation.
114
115
116/// \brief Prepares HID report data to be sent.
117*** NO 's' after a verb in brief documentation.
118
119
120/// \brief Retrieve a state change since last call of the HID Mouse.
121*** NO 'a' or 'the' in brief text.
122
123
124/// \return true when state change since last call, false otherwise.
125*** Confusing return statement, separate into two lines (looks also better):
126/// \return
127/// - true = when state change since last call
128/// - false = otherwise.
129
130
131/// \return 0 no communication error.
132/// \return - 1 communication error.
133*** Confusing, may generate a bullet point, use instead "value" in front of plain numbers, correct is:
134/// \return value 0 no communication error.
135/// \return value -1 communication error.
136
137
138/// \param[in] req Request type:
139/// USBD_HID_REQ_EP_CTRL = Control endpoint request.
140/// USBD_HID_REQ_PERIOD_UPDATE = Idle period expiration request.
141/// USBD_HID_REQ_EP_INT = Previously sent report on interrupt endpoint request.
142*** Missing '-' in front of parameter details => hard to read in documentation.
143
144
145/// \param[in] stat error status and line states
146/// - bit 6 - bOverRun
147/// - bit 5 - bParity
148*** Missing ':' after states and bit numbers, correct is:
149/// \param[in] stat error status and line states:
150/// - bit 6: bOverRun
151/// - bit 5: bParity
152
153
154/// \param[in] ptr_data pointer to data buffer where information is written.
155*** Wrong, should be param[out].
156*** Redundant: a data buffer is always a pointer, better is:
157/// \param[out] ptr_data data buffer that receives information.
158
159
160/// \fn bool USBH_HID_GetStatus (uint8_t index);
161/// \brief Get status of the Human Interface Device.
162/// \param[in] index instance index of HID.
163/// \return true device is configured and initialized.
164/// \return false device not ready.
165extern bool USBH_HID_GetStatus (uint8_t index);
166Wrong: \fn not needed
167
168
169/* USB Host Speed constants */
170enum {
171 USBH_LS = 0, /* Low speed */
172 USBH_FS, /* Full speed */
173 USBH_HS /* High speed */
174};
175Wrong, should be Doxygen style. Correct is:
176/// USB Host Speed constants
177enum {
178 USBH_LS = 0, ///< Low speed
179 USBH_FS, ///< Full speed
180 USBH_HS ///< High speed
181};
182
183
184typedef struct { ///< Hw Endpoint settings structure
185 osThreadId thread_id; ///< Thread ID of thread that uses URB
186 USBH_URB urb; ///< URB used for endpoint communication} USBH_EP;
187Wrong: '/// comment' before 'struct {'
188Bad: repeat of Thread ID and URB does not add value; avoid abbreviations like 'Hw'
189
190Better is:
191/// Hardware Endpoint Settings for communication functions
192typedef struct {
193 osThreadId thread_id; ///< thread using USB Request Block (urb)
194 USBH_URB urb; ///< USB Request Block for endpoint communication
195
196
197
198API Documentation in *.txt files
199--------------------------------
200
201A *.txt file that relates to a *.h contains:
202 - Functional group assignments using \defgroup along with \brief description
Liviu Ionescu82b946d2016-03-02 12:43:48 +0200203 - Under \details an overview description for each functional group (should contain a useful code example)
ReinhardKeilfc14d082016-02-18 15:36:24 +0100204 - For each function in the header file a detailed description
205
206
207IMPORTANT:
208Text *.txt files that document the user API of a component are located in .\MW\Doc\component.
Liviu Ionescub6394cd2016-03-02 12:47:37 +0200209Only for *.h files that provide user API, there is exactly one text file with the same name.
ReinhardKeilfc14d082016-02-18 15:36:24 +0100210Defines/Functions that are internally used by a Component have no *.txt file.
211
212Example:
213 .\MW\component\Include\rl_usb.h => .\MW\Doc\component\rl_usb.txt
214
215The file documents each function that is exposed in *.h header file (and only those functions).
216In case that functions are described in other files (i.e. USB Class Templates) there is a reference.
217
Jonatan Antonie4a48772018-02-08 16:18:14 +0100218Functional Group assignments uses this syntax:
ReinhardKeilfc14d082016-02-18 15:36:24 +0100219---------------------------
220/**
221\defgroup a group definition
222[\ingroup] optionally within a group
223\brief brief description of the group
224\details
225description
226*/
227
228/**
229\addtogroup a group definition
230@{
231*/
232
Liviu Ionescu82b946d2016-03-02 12:43:48 +0200233Below \addtogroup the documentation for related functions is provided. This section
ReinhardKeilfc14d082016-02-18 15:36:24 +0100234ends with @}
235
236Function documentation uses this syntax:
237--------
238/**
239\fn functionName( args )
240\details
241[\note]
242[<b>Code Example</b>
243\code | \snippet]
244*/
245
246See rl_usb.txt for examples
247No ';' at the end of the function declaration. Otherwise function description gets ignored.
248
249
250
251Comments in doxygen code blocks should be marked with // and not /* ... */, which leads to errors.
252-------------------------------------------------------
253Example: Wrong:
254\code
255void ftp_server_notify (uint8_t event) {
256 /* Notify the user application about events in FTP server.*/
257 ...
258}
259\endcode
260
261Example: correct:
262\code
263void ftp_server_notify (uint8_t event) {
264 // Notify the user application about events in FTP server.
265 ...
266}
267\endcode
268
269
Jonatan Antonie4a48772018-02-08 16:18:14 +0100270
271Cross references (between components)
272-------------------------------------
273
274Within a single component (same .dxy configuration) one can easily created cross references.
275Known symbol names are automatically assumed as a reference by Doxygen. Pages, sections and
276subsections can be referenced using "\ref" notation.
277
278Cross references do not work between different components, though. Doxygen offers the possibility
279to import so called tags (symbol and section names) from an another external documentation.
280Unfortunately this creates output that crashes the MDK DoxyIndex importer. Hence cross references
281needs to be placed manually using <a href="[url]">...</a> notation, for the time being.