]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/docs/COMMITTERS.md
remove experimental return, cleanup slash_question key
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / docs / COMMITTERS.md
1 # Committing changes to mbedmicro/mbed
2 * Our current branching model is very simple. We are using ```master``` branch to merge all pull requests.
3 * Based on stable ```SHA``` version of ```master``` branch we decide to release and att he same time ```tag``` our build release.
4 * Our current release versioning follows simple integer version: ```94```, ```95```, ```96``` etc.
5
6 # Committer Guide
7
8 ## How to decide what release(s) should be patched
9 This section provides a guide to help a committer decide the specific base branch that a change set should be merged into.
10
11 Currently our default branch is ```master``` branch. All pull requests should be created against ```master``` branch.
12 mbed SDK is released currently on master branch under certain tag name (see [Git tagging basics]( http://git-scm.com/book/en/v2/Git-Basics-Tagging)). You can see mbed SDK tags and switch between them to for example go back to previous mbed SDK release.
13 ```
14 $ git tag
15 ```
16
17 Please note: mebd SDK ```master``` branch's ```HEAD``` is our latest code and may not be as stable as you expect. We are putting our best effort to run regression testing (in-house) against pull requests and latest code.
18 Each commit to ```master``` will trigger [GitHub's Travis Continuous Integration](https://travis-ci.org/mbedmicro/mbed/builds).
19
20 ### Pull request
21 Please send pull requests with changes which are:
22 * Complete (your code will compile and perform as expected).
23 * Tested on hardware.
24 * You can use included mbed SDK test suite to perform testing. See TESTING.md.
25 * If your change, feature do not have a test case included please add one (or more) to cover new functionality.
26 * If you can't test your functionality describe why.
27 * Documented source code:
28 * New, modified functions have descriptive comments.
29 * You follow coding rules and styles provided by mbed SDK project.
30 * Documented pull request description:
31 * Description of changes is added - explain your change / enhancement.
32 * References to existing issues, other pull requests or forum discussions are included.
33 * Test results are added.
34
35 After you send us your pull request our Gate Keeper will change the state of pull request to:
36 \95 ``` enhancement``` or ```bug``` when pull request creates new improvement or fixed issue.
37 Than we will set for you labels:
38 \95 ```review``` to let you know your pull request is under review and you can expect review related comments from us.
39 \95 ```in progress``` when you pull request requires some additional change which will for now block this pull request from merging.
40 At the end we will remove ```review``` label and merge your change if everything goes well.
41
42 ## C++ coding rules & coding guidelines
43 ### Rules
44 * The mbed SDK code follows K&R style (Reference: [K&R style](http://en.wikipedia.org/wiki/Indent_style#K.26R_style)) with at least 2 exceptions which can be found in the list below the code snippet:
45
46 ```c++
47 static const PinMap PinMap_ADC[] = {
48 {PTC2, ADC0_SE4b, 0},
49 {NC , NC , 0}
50 };
51
52 uint32_t adc_function(analogin_t *obj, uint32_t options)
53 {
54 uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT;
55 switch (options) {
56 case 1:
57 timeout = 6;
58 break;
59 default:
60 timeout = 10;
61 break;
62 }
63
64 while (!adc_hal_is_conversion_completed(instance, 0)) {
65 if (timeout == 0) {
66 break;
67 } else {
68 timeout--;
69 }
70 }
71
72 if (obj->adc == ADC_CHANNEL0) {
73 adc_measure_channel(instance);
74 adc_stop_channel(instance);
75 } else {
76 error("channel not available");
77 }
78
79 #if DEBUG
80 for (uint32_t i = 0; i < 10; i++) {
81 printf("Loop : %d", i);
82 }
83 #endif
84 return adc_hal_get_conversion_value(instance, 0);
85 }
86 ```
87 * Indentation - 4 spaces. Please do not use tabs!
88 * Braces - K&R, except for functions where the opening brace is on the new line.
89 * 1 TBS - use braces for statements ```if```, ```else```, ```while```, ```for``` (exception from K&R) Reference: [1TBS](http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS)).
90 * One line per statement.
91 * Preprocessor macro starts at the beginning of a new line, the code inside is indented accordingly the code above it.
92 * Cases within switch are indented (exception from K&R).
93 * Space after statements if, while, for, switch, same applies to binary and ternary operators.
94 * Each line has preferably at most 120 characters.
95 * For pointers, ```*``` is adjacent to a name (analogin_t *obj).
96 * Don't leave trailing spaces at the end of lines.
97 * Empty lines should have no trailing spaces.
98 * Unix line endings are default option for files.
99 * Use capital letters for macros.
100 * A file should have an empty line at the end.
101 and:
102 * We are not using C++11 yet so do not write code compliant to this standard.
103 * We are not using libraries like ```BOOST``` so please so not include any ```BOOST``` headers to your code.
104 * C++ & templates: please take under consideration templates are not fully supported by cross-compilers. You may have difficulties compiling template code few cross-compilers so make sure your template code compilers for more than one compiler.
105
106 ### Naming conventions
107 Classes:
108 * Begins with a capital letter, and each word in it begins also with a capital letter (```AnalogIn```, ```BusInOut```).
109 * Methods contain small letters, distinct words separated by underscore.
110 * Private members starts with an underscore.
111
112 User defined types (typedef):
113 * Structures - suffix ```_t``` - to denote it is user defined type
114 * Enumeration - the type name and values name - same naming convention as classes (e.g ```MyNewEnum```)
115
116 Functions:
117 * Contain lower case letters (as methods within classes)
118 * Distinct words separated by underscore (```wait_ms```, ```read_u16```)
119 * Please make sure that in your module all functions have unique prefix so when your module is compiled with other modules function names (and e.g. extern global variable names) are not in naming conflict.
120
121 Example code look&feel:
122 ```c++
123 #define ADC_INSTANCE_SHIFT 8
124
125 class AnalogIn {
126 public:
127 /** Create an AnalogIn, connected to the specified pin
128 *
129 * @param pin AnalogIn pin to connect to
130 * @param name (optional) A string to identify the object
131 */
132 AnalogIn(PinName pin) {
133 analogin_init(&_adc, pin);
134 }
135
136 /** Read the input voltage, represented as a float in the range [0.0, 1.0]
137 *
138 * @returns
139 * A floating-point value representing the current input voltage, measured as a percentage
140 */
141 uint32_t read() {
142 return analogin_read(&_adc, operation);
143 }
144
145 protected:
146 analogin_t _adc;
147 };
148
149 typedef enum {
150 ADC0_SE0 = (0 << ADC_INSTANCE_SHIFT) | 0,
151 } ADCName;
152
153 struct analogin_s {
154 ADCName adc;
155 };
156
157 typedef struct analogin_s analogin_t;
158 ```
159 ### Doxygen documentation
160 All functions / methods should contain a documentation using doxygen javadoc in a header file. More information regarding writing API Documentation, follow [this](https://mbed.org/handbook/API-Documentation) link.
161
162 Example of well documentet code:
163 ```c++
164 #ifndef ADC_H
165 #define ADC_H
166
167 #ifdef __cplusplus
168 extern "C" {
169 #endif
170
171 /** ADC Measurement method
172 *
173 * @param obj Pointer to the analogin object.
174 * @param options Options to be enabled by ADC peripheral.
175 *
176 * @returns
177 * Measurement value on defined ADC channel.
178 */
179 uint32_t adc_function(analogin_t *obj, uint32_t options)
180
181 #ifdef __cplusplus
182 }
183 #endif
184
185 #endif
186 ```
187 ### C/C++ Source code indenter
188 In Mbed project you can use AStyle (Reference: [Artistic Style](http://astyle.sourceforge.net/)) source code indenter to help you auto format your source code. It will for sure not correct all your coding styles but for sure will eliminate most of them. You can download AStyle from this location.
189
190 Official Mbed SDK styles include below AStyle styles (defined by command line switched):
191 ```
192 --style=kr --indent=spaces=4 --indent-switches
193 ```
194 To format your file you can execute below command. Just replace ```$(FULL_CURRENT_PATH)``` with path to your source file.
195 ```
196 $ astyle.exe --style=kr --indent=spaces=4 --indent-switches $(FULL_CURRENT_PATH)
197 ```
198
199 ## Python coding rules & coding guidelines
200 Some of our tools in workspace_tools are written in ```Python 2.7```. In case of developing tools for python we prefer to keep similar code styles across all Python source code. Please note that not all rules must be enforced. For example we do not limit you to 80 characters per line, just be sure your code can fit to widescreen display.
201
202 Please stay compatible with ```Python 2.7``` but nothing stops you to write your code so in the future it will by Python 3 friendly.
203
204 Please check our Python source code (especially ```test_api.py``` and ```singletest.py```) to get notion of how your new code should look like). We know our code is not perfect but please try to fit the same coding style to existing code so source looks consistent and is not series of different flavors.
205
206 Some general guidelines:
207 * Use Python idioms, please refer to one of many on-line guidelines how to write Pythonic code: [Code Like a Pythonista: Idiomatic Python](http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html).
208 * Please do not use TABs. Please use 4 spaces instead for indentations.
209 * Please put space character between operators, after comma etc.
210 * Please document your code, write comments and ```doc``` sections for each function or class you implement.
211
212 ### Static Code Analizers for Python
213 If you are old-school developer for sure you remember tools like lint. "lint was the name originally given to a particular program that flagged some suspicious and non-portable constructs (likely to be bugs) in C language source code." Now lint-like programs are used to check similar code issues for multiple languages, also for Python. Please do use them if you want to commit new code to workspace_tools and other mbed SDK Python tooling.
214
215 Below is the list Python lint tools you may want to use:
216
217 * [pyflakes](https://pypi.python.org/pypi/pyflakes) - Please scan your code with pyflakes and remove all issues reported by it. If you are unsure if something should be modified or not you can skip lint report related fix and report this issue as possible additional commit in your pull request description.
218
219 * [pylint](http://www.pylint.org/) - Please scan your code with pylint and check if there are any issues which can be resolved and are obvious "to fix" bugs. For example you may forgot to add 'self' as first parameter in class method parameter list or you are calling unknown functions / functions from not imported modules.
220
221 * [pychecker](http://pychecker.sourceforge.net/) - optional, but more the merrier ;)
222
223 Example Python look&feel:
224 ```python
225 class HostRegistry:
226 """ Class stores registry with host tests and objects representing them
227 """
228 HOST_TESTS = {} # host_test_name -> host_test_ojbect
229
230 def register_host_test(self, ht_name, ht_object):
231 """ Registers (removes) host test by name from HOST_TESTS registry
232 if host test is not already registered (check by name).
233 """
234 if ht_name not in self.HOST_TESTS:
235 self.HOST_TESTS[ht_name] = ht_object
236
237 def unregister_host_test(self):
238 """ Unregisters (removes) host test by name from HOST_TESTS registry.
239 """
240 if ht_name in HOST_TESTS:
241 self.HOST_TESTS[ht_name] = None
242
243 def get_host_test(self, ht_name):
244 """ Returns HOST_TEST if host name is valid.
245 In case no host test is available return None
246 """
247 return self.HOST_TESTS[ht_name] if ht_name in self.HOST_TESTS else None
248
249 def is_host_test(self, ht_name):
250 """ Function returns True if host name is valid (is in HOST_TESTS)
251 """
252 return ht_name in self.HOST_TESTS
253 ```
254
255 ## Testing
256 Please refer to TESTING.md document for detais regarding mbed SDK test suite and build scripts included in ```mbed/workspace_tools/```.
257
258 ## Before pull request checklist
259 * Your pull request description section contains:
260 * Rationale \96 tell us why you submitted this pull request. This is your change to write us summary of your change.
261 * Description \96 describe changes you\92ve made and tell us which new features / functionalities were implemented.
262 * Manual / Cookbook / Handbook \96 you can put here manual, cookbook or handbook related to your change / enhancement. Your documentation can stay with pull request.
263 * Test results (if applicable).
264 * Make sure you followed project's coding rules and styles.
265 * No dependencies are created to external C/C++ libraries which are not included already in our repository.
266 * Please make sure that in your module all functions have unique prefix (no name space collisions).
267 * You reused existing functionality, please do not add or rewrite existing code. E.g. use mbed\92s ```FunctionPointer``` if possible to store your function pointers. Do not write another wrapper for it. We already got one. If some functionality is missing, just add it! Extend our APIs wisely!
268 * Were you consistent? Please continue using style / code formatting, variables naming etc. in file they are modifying.
269 * Your code compiles and links. Also doesn\92t generate additional compilation warnings.
Imprint / Impressum