1 Rules for CMSIS API Function documentation
2 ===========================================
4 This document describes how to generate Doxygen-style documentation for middleware "Components".
5 It explains how the Doxygen documentation under "Reference" is provided in header (*.h),
6 text (*.txt), template (*.c), and config files.
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
15 Files: Middleware components have the following files that are used to generate the API documentation:
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.
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
24 - *.c templates: show the usage of some middleware functionality and may be included in the Doxygen documentation.
25 *.c templates with '%Instance%' are copied to .\MW\Doc\component and '%Instance%' is replaced with 'n', otherwise
26 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.
29 - *.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
31 needs therefore be part of the config files.
33 Source files (*.c and *.h) should NOT use <TAB> character. Instead of <TAB> <space> characters are used.
36 API Documentation in .\Include\*.h files
37 ----------------------------------------
41 The following snippet shows a sample documentation (correct). In general functions are grouped and
42 a short descriptive line is added before a group of functions. In case that functions are only
43 relevant for the documentation (i.e. available in multiple instances), they are included in
44 #ifdef __DOXYGEN__ / #endif sections.
47 /// \brief Called during \ref USBD_Initialize to initialize the USB Device class.
49 extern void USBD_HIDn_Initialize (void);
51 // ==== USB Host Human Interface Device Functions ====
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.
57 extern bool USBH_HID_GetStatus (uint8_t index);
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.
64 extern int USBH_HID_Read (uint8_t index, uint8_t *ptr_data);
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.
71 extern int USBH_HID_Write (uint8_t index, uint8_t *ptr_data, uint16_t data_len);
73 /// \brief Get last error that happened on the Human Interface Device.
74 /// \param[in] index instance index of HID.
75 /// \return error code.
76 extern uint32_t USBH_HID_GetLastError (uint8_t index);
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.
86 extern bool USBH_HID_GetMouseData (uint8_t index, uint8_t *button, int8_t *x, int8_t *y, int8_t *wheel);
88 // ==== USB Device Human Interface Device Functions ====
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.
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
106 int32_t USBD_HIDn_GetReport (uint8_t rtype, uint8_t rid, uint8_t *buf, uint8_t req);
110 This section contains things that should be NOT DONE:
112 /// \brief Prepares HID report data to be sent
113 *** NO '.' to terminate brief documentation.
116 /// \brief Prepares HID report data to be sent.
117 *** NO 's' after a verb in brief documentation.
120 /// \brief Retrieve a state change since last call of the HID Mouse.
121 *** NO 'a' or 'the' in brief text.
124 /// \return true when state change since last call, false otherwise.
125 *** Confusing return statement, separate into two lines (looks also better):
127 /// - true = when state change since last call
128 /// - false = otherwise.
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.
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.
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
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.
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.
165 extern bool USBH_HID_GetStatus (uint8_t index);
166 Wrong: \fn not needed
169 /* USB Host Speed constants */
171 USBH_LS = 0, /* Low speed */
172 USBH_FS, /* Full speed */
173 USBH_HS /* High speed */
175 Wrong, should be Doxygen style. Correct is:
176 /// USB Host Speed constants
178 USBH_LS = 0, ///< Low speed
179 USBH_FS, ///< Full speed
180 USBH_HS ///< High speed
184 typedef 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;
187 Wrong: '/// comment' before 'struct {'
188 Bad: repeat of Thread ID and URB does not add value; avoid abbreviations like 'Hw'
191 /// Hardware Endpoint Settings for communication functions
193 osThreadId thread_id; ///< thread using USB Request Block (urb)
194 USBH_URB urb; ///< USB Request Block for endpoint communication
198 API Documentation in *.txt files
199 --------------------------------
201 A *.txt file that relates to a *.h contains:
202 - Functional group assignments using \defgroup along with \brief description
203 - Under \details an overview description for each functional group (should contain a useful code example)
204 - For each function in the header file a detailed description
208 Text *.txt files that document the user API of a component are located in .\MW\Doc\component.
209 Only for *.h files that provide user API, there is exactly one text file with the same name.
210 Defines/Functions that are internally used by a Component have no *.txt file.
213 .\MW\component\Include\rl_usb.h => .\MW\Doc\component\rl_usb.txt
215 The file documents each function that is exposed in *.h header file (and only those functions).
216 In case that functions are described in other files (i.e. USB Class Templates) there is a reference.
218 Functional Group assignements uses this syntax:
219 ---------------------------
221 \defgroup a group definition
222 [\ingroup] optionally within a group
223 \brief brief description of the group
229 \addtogroup a group definition
233 Below \addtogroup the documentation for related functions is provided. This section
236 Function documentation uses this syntax:
239 \fn functionName( args )
246 See rl_usb.txt for examples
247 No ';' at the end of the function declaration. Otherwise function description gets ignored.
251 Comments in doxygen code blocks should be marked with // and not /* ... */, which leads to errors.
252 -------------------------------------------------------
255 void ftp_server_notify (uint8_t event) {
256 /* Notify the user application about events in FTP server.*/
263 void ftp_server_notify (uint8_t event) {
264 // Notify the user application about events in FTP server.