You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/creating_apps/code_style.md
+26-26Lines changed: 26 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# Code contributions: GitHub pull requests and code style guide
1
+
##Code contributions: GitHub pull requests and code style guide
2
2
3
3
The mbed OS codebase is hosted on GitHub, and you can submit new features or bug fixes. Please follow the [guidelines for GitHub pull requests](#guidelines-for-github-pull-requests) and the [coding style guide](#coding-style) in your submissions.
4
4
5
5
<spanclass="tips">**Tip:** Please also read the section [Creating and publishing your own libraries and contributing to mbed OS](contributing.md) for a review of the process and legal requirements.</span>
6
6
7
-
## Guidelines for GitHub pull requests
7
+
###Guidelines for GitHub pull requests
8
8
9
9
Pull requests on GitHub have to meet the following requirements in order to keep the code and commit history clean:
10
10
@@ -22,17 +22,17 @@ Pull requests on GitHub have to meet the following requirements in order to keep
22
22
* Because we use GitHub and explicit CLAs, special commit tags that other projects may use, such as “Reviewed-by”, or “Signed-off-by”, are redundant and should be omitted. GitHub keeps track of who reviewed what and when, and our stack of signed CLAs shows us who has agreed to our development contribution agreement.
23
23
* Prefixing your commit message with a domain is acceptable and recommended where it makes sense to do so. However, prefixing one's domain with the name of the repo is not useful. For example, making a commit entitled "mbed-drivers: Fix doppelwidget frobulation" to the mbed-drivers repo would not be acceptable, as it is already understood that the commit applies to "mbed-drivers". Renaming the commit to "doppelwidget: Fix frobulation" would be better, if we presume that "doppelwidget" is a meaningful domain for changes, as it communicates that the change applies to the doppelwidget area of mbed-drivers.
24
24
25
-
## Code acceptance
25
+
###Code acceptance
26
26
27
27
[After the CLA](contributing.md) is in place and the code has gone through automated testing, developers will take a look and comment on the pull request. If all is well and acceptable, your code will be ready for merging into the central development branch.
28
28
29
-
## Coding style
29
+
###Coding style
30
30
31
-
Whether you're writing new code or fixing bugs in existing code, please follow the mbed OS coding style.
31
+
Whether you're writing new code or fixing bugs in existing code, please follow the mbed OS coding style.
32
32
33
33
mbed OS follows the [K&R style](https://en.wikipedia.org/wiki/Indent_style#K.26R_style), with at least two exceptions (which can be found in the list below the code sample).
while (!adc_hal_is_conversion_completed(instance, 0)) {
56
56
if (timeout == 0) {
57
57
break;
58
58
} else {
59
59
timeout--;
60
60
}
61
61
}
62
-
62
+
63
63
if (obj->adc == ADC_CHANNEL0) {
64
64
adc_measure_channel(instance);
65
65
adc_stop_channel(instance);
66
66
} else {
67
67
error("channel not available");
68
68
}
69
-
69
+
70
70
#if DEBUG
71
71
for (uint32_t i = 0; i < 10; i++) {
72
72
printf("Loop : %d", i);
73
73
}
74
74
#endif
75
75
return adc_hal_get_conversion_value(instance, 0);
76
-
}
76
+
}
77
77
```
78
-
### Rules
78
+
#### Rules
79
79
80
80
* Indentation - four spaces. Please do not use tabs.
81
81
82
82
* Braces - K&R style.
83
83
84
-
* One true brace style (1TBS) - use braces for statements of type `if`, `else`, `while` and `for` (exception [from K&R](http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS)).
84
+
* One true brace style (1TBS) - use braces for statements of type `if`, `else`, `while` and `for` (exception [from K&R](http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS)).
All C and C++ code submitted to mbed OS must compile with GCC ARM Embedded, ARM Compiler 5 and IAR EWARM. Code must compile with specific flags for each compiler. See the list of these flags below. The profiles used by the mbed OS tools are each subsets of these flags. Each profile has one optimization setting.
186
186
187
-
### GCC ARM Embedded
187
+
####GCC ARM Embedded
188
188
189
189
Code must be compatible with the `softfp` float ABI. mbed OS uses the following flags when compiling with GCC ARM Embedded.
190
190
@@ -198,10 +198,10 @@ flag | meaning
198
198
`-fno-rtti` | Disable runtime type information (C++ only)
199
199
`-Os` | Optimize for size
200
200
`-O0` | Do not optimize
201
-
`-std=gnu99` | C uses the GNU99 standard
201
+
`-std=gnu99` | C uses the GNU99 standard
202
202
`-std=gnu++98` | C++ uses the GNU++98 standard
203
203
204
-
### ARM Compiler 5
204
+
####ARM Compiler 5
205
205
206
206
mbed OS uses the following flags when compiling with ARM Compiler 5.
207
207
@@ -213,7 +213,7 @@ flag | meaning
213
213
`-O3` | Optimize for speed
214
214
`-c99` | C uses the C99 standard
215
215
216
-
### IAR EWARM
216
+
####IAR EWARM
217
217
218
218
mbed OS uses the following flags when compiling with IAR EWARM.
Copy file name to clipboardExpand all lines: docs/creating_apps/contributing.md
+23-23Lines changed: 23 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Creating and publishing your own libraries and contributing to mbed OS
1
+
##Creating and publishing your own libraries and contributing to mbed OS
2
2
3
3
This chapter covers the different aspects of developing your own libraries for use in mbed devices, as well as items to keep in mind during development, such as licensing. It covers:
4
4
@@ -8,17 +8,17 @@ This chapter covers the different aspects of developing your own libraries for u
8
8
9
9
### Licensing binaries and libraries
10
10
11
-
When you write original code, you own the copyright and can choose to make it available to others under a license of your choice. A license gives rights and puts limitations on the reuse of your code by others. Not having a license means others cannot use your code. We encourage you to choose a license that makes possible (and encourages!) reuse by others.
11
+
When you write original code, you own the copyright and can choose to make it available to others under a license of your choice. A license gives rights and puts limitations on the reuse of your code by others. Not having a license means others cannot use your code. We encourage you to choose a license that makes possible (and encourages!) reuse by others.
12
12
13
13
If you create new software, such as drivers, libraries and examples, you can apply whatever license you like as the author and copyright holder of that code. Having said that, we encourage you to use a well-known license such as one of the ones listed [on the SPDX License List](http://spdx.org/licenses/), preferably an [OSI-approved] (https://opensource.org/licenses/alphabetical), permissive open source software license. Specifically, we recommend the following:
14
14
15
15
* For original source code, use the Apache 2.0 license.
16
16
17
17
* For binary releases (for example, private source code you can’t or don’t want to release but want to share as a binary library and headers available for others to use), consider the [Permissive Binary License](https://www.mbed.com/licenses/PBL-1.0). This is designed to be compatible with Apache 2.0 and the mbed OS codebase.
18
18
19
-
* If your software incorporates or is derived from other third party open source code, please be sure to retain all notices and identify the license for the third party licensed code in the same manner as described below. Remember, you cannot change the license on someone else’s code, because you are not the copyright holder! Instead, choose a license that is compatible with the license used by the third party open source code, or use the same license as that code. For example, if your software is derived from GPL source code, GPL requires you to license the rest of your code in that software under the GPL too. Note that many commercial users won’t be able to use GPL source code in their products, so we don't recommend this license if you're not obligated to use it.
19
+
* If your software incorporates or is derived from other third party open source code, please be sure to retain all notices and identify the license for the third party licensed code in the same manner as described below. Remember, you cannot change the license on someone else’s code, because you are not the copyright holder! Instead, choose a license that is compatible with the license used by the third party open source code, or use the same license as that code. For example, if your software is derived from GPL source code, GPL requires you to license the rest of your code in that software under the GPL too. Note that many commercial users won’t be able to use GPL source code in their products, so we don't recommend this license if you're not obligated to use it.
20
20
21
-
You must either write all the code you provide yourself, or have the necessary rights to provide code written by someone else.
21
+
You must either write all the code you provide yourself, or have the necessary rights to provide code written by someone else.
22
22
23
23
In all cases, whatever license you use, please use an [SPDX license identifier](http://spdx.org/licenses/) in every source file following the recommendations [here](https://spdx.org/spdx-specification-21-web-version#h.twlc0ztnng3b) to make it easier for users to understand and review licenses.
24
24
@@ -34,7 +34,7 @@ In order to clearly reflect the Apache 2.0 license, please create two text files
34
34
35
35
* A *LICENSE* file with the following text:</br>
36
36
37
-
<pre>Unless specifically indicated otherwise in a file, files are licensed under the Apache 2.0 license,
37
+
<pre>Unless specifically indicated otherwise in a file, files are licensed under the Apache 2.0 license,
38
38
as can be found in: LICENSE-apache-2.0.txt</pre>
39
39
40
40
* The full original [Apache 2.0 license text](http://www.apache.org/licenses/LICENSE-2.0) in *LICENSE-apache-2.0.txt*
@@ -45,13 +45,13 @@ Each source header should *start with* your copyright line, the SPDX identifier
45
45
Copyright (c) [First year]-[Last year], **Your Name or Company Here**
46
46
SPDX-License-Identifier: Apache-2.0
47
47
48
-
Licensed under the Apache License, Version 2.0 (the "License");
48
+
Licensed under the Apache License, Version 2.0 (the "License");
49
49
you may not use this file except in compliance with the License.
50
50
51
51
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
52
52
53
-
Unless required by applicable law or agreed to in writing, software
54
-
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
53
+
Unless required by applicable law or agreed to in writing, software
54
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
55
55
either express or implied.
56
56
57
57
See the License for the specific language governing permissions and limitations under the License.
@@ -61,7 +61,7 @@ See the License for the specific language governing permissions and limitations
61
61
62
62
The Permissive Binary License (PBL) is a permissive license based on BSD-3-Clause and designed specifically for binary blobs. It's minimal but covers the basics, including an express patent grant.
63
63
64
-
It allows you to share a binary blob and the relevant headers, and allows others to use that binary blob as part of their product - as long as they provide it with all the relevant dependencies and don't modify it or reverse engineer it.
64
+
It allows you to share a binary blob and the relevant headers, and allows others to use that binary blob as part of their product - as long as they provide it with all the relevant dependencies and don't modify it or reverse engineer it.
65
65
66
66
The full text can be found on [mbed.com](https://www.mbed.com/licenses/PBL-1.0).
67
67
@@ -71,7 +71,7 @@ In order to clearly reflect the PBL license, please create three text files:
71
71
72
72
* A *LICENSE* file with:
73
73
74
-
<pre>Unless specifically indicated otherwise in a file, files are licensed under the Permissive Binary License,
74
+
<pre>Unless specifically indicated otherwise in a file, files are licensed under the Permissive Binary License,
75
75
as can be found in: LICENSE-permissive-binary-license-1.0.txt</pre>
76
76
77
77
* The full original [Permissive Binary License 1.0 text](https://www.mbed.com/licenses/PBL-1.0) in *LICENSE-permissive-binary-license-1.0.txt*.
@@ -104,56 +104,56 @@ If you decide to use a different license for your work, follow the same pattern:
104
104
105
105
* If more than one license applies to the source file, then use an SPDX license expression (see [SPDX Specification, Appendix IV](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60)), to reflect the presence of multiple licenses in your *LICENSE* file and in each source file.
106
106
107
-
## Contributing to the mbed OS codebase
107
+
###Contributing to the mbed OS codebase
108
108
109
-
### mbed OS principles
109
+
####mbed OS principles
110
110
111
111
mbed OS uses these same basic principles for its source code and library distributions. So source code we own is distributed under the Apache 2.0 license, and binary blobs are released under the Permissive Binary License. Software parts from third parties that were already licensed under a different license are available under that original license.
112
112
113
113
All the source code and binary blobs that end up in mbed OS are maintained in public GitHub repositories.
114
114
115
-
### Contributions
115
+
####Contributions
116
116
117
117
All code changes and additions to mbed OS are handled through GitHub. If you want to contribute, either by adding features or by fixing bugs, please follow the guidelines for [new features](#contributing-new-features-to-mbed-os) and [bugs](#reporting-and-fixing-bugs), and in both cases please follow the [code style guide and GitHub pull request guidelines](code_style.md).
118
118
119
-
### Inbound License for Contributions
119
+
####Inbound License for Contributions
120
120
121
-
If you want to contribute code to mbed OS, you must sign an mbed Contributor License Agreement (CLA). Please ask for a CLA before submitting any code (for example, while discussing the issue on GitHub), then wait for ARM to confirm acceptance of your CLA before making contributions.
121
+
If you want to contribute code to mbed OS, you must sign an mbed Contributor License Agreement (CLA). Please ask for a CLA before submitting any code (for example, while discussing the issue on GitHub), then wait for ARM to confirm acceptance of your CLA before making contributions.
122
122
123
123
<spanstyle="background-color:#E6E6E6;border:1pxsolid#000;display:block; height:100%; padding:10px">**Note:** If you publish a feature or a solution to a problem before signing the CLA, then find out that you are not able or allowed to sign the CLA, we will not be able to use your solution anymore. That may prevent us from solving the problem for you.</span>
124
124
125
-
When you ask for the CLA, we'll send you the agreement and ask you to sign it *before* we handle any pull request from you:
125
+
When you ask for the CLA, we'll send you the agreement and ask you to sign it *before* we handle any pull request from you:
126
126
127
127
* Individuals who want to contribute their own work must sign and return an Individual CLA.
128
128
129
129
* Companies that want employees to contribute on its behalf must sign and return a Corporate CLA.
130
130
131
131
The same agreement is then valid for all future pull requests from that GitHub username.
132
132
133
-
### Contributing new features to mbed OS
133
+
####Contributing new features to mbed OS
134
134
135
135
Before contributing an enhancement (new feature, new port and so on) please [discuss it on the forums](https://developer.mbed.org/forum/) to avoid duplication of work, as we or others might be working on a related feature.
136
136
137
137
Patch contributions can only be accepted through GitHub by creating a pull request from forked versions of our repositories. This allows us to review the contributions in a user friendly and reliable way, under public scrutiny.
138
138
139
139
Please create separate patches for each concern; each patch should have a clear unity of purpose. In particular, separate code formatting and style changes from functional changes. This makes each patch’s true contribution clearer and therefore quicker and easier to review.
140
140
141
-
### Reporting and fixing bugs
141
+
####Reporting and fixing bugs
142
142
143
143
Before submitting a bug report or a bug fix, please [discuss it on the forums](https://developer.mbed.org/forum/) to avoid duplication of work, as we or others might be working on it already.
144
144
145
-
#### Bug reports (issues) on GitHub
145
+
#####Bug reports (issues) on GitHub
146
146
147
147
All mbed OS is on GitHub; please use GitHub's [issues mechanism](https://guides.github.com/features/issues/) to open a bug report directly against the relevant GitHub repository.
148
148
149
-
#### Bug fixes
149
+
#####Bug fixes
150
150
151
-
Please refer to the [code contributions chapter](code_style.md).
151
+
Please refer to the [code contributions chapter](code_style.md).
152
152
153
-
Bug fixes must be verified by a member of the mbed team before they're pulled into the main branch. You must therefore use GitHub to fork the repo, then submit a pull request with your changes.
153
+
Bug fixes must be verified by a member of the mbed team before they're pulled into the main branch. You must therefore use GitHub to fork the repo, then submit a pull request with your changes.
154
154
155
155
The last line in your commit message description should say “Fixes #deadbeef”, where “deadbeef” is the issue number in GitHub. This allows GitHub to automatically close the issue when the commit is merged into the default branch.
156
156
157
-
## Further reading
157
+
###Further reading
158
158
159
159
Please see the [code contributions chapter](code_style.md) for the guidelines to GitHub pull requests and the coding style guide.
0 commit comments