Skip to content

Commit 93a7ca0

Browse files
committed
added .clang-format
fix more alerts
1 parent 8979af3 commit 93a7ca0

File tree

29 files changed

+438
-402
lines changed

29 files changed

+438
-402
lines changed

.PVS-Studio/.pvsconfig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
//-V::2506
2-
//-V::2514
3-
//-V::2614
1+
//V_EXCLUDE_PATH */iar/cxarm*
2+
3+
//-V::2506 MISRA. A function should have a single point of exit at the end.
4+
//-V::2514 MISRA. Unions should not be used.
5+
//+V2614 DISABLE_LENGHT_LIMIT_CHECK:YES

.clang-format

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,88 @@
1-
# Generated from CLion C/C++ Code Style settings
1+
---
2+
Language: Cpp
23
BasedOnStyle: LLVM
3-
AccessModifierOffset: -2
4-
AlignAfterOpenBracket: Align
5-
AlignConsecutiveAssignments: None
6-
AlignOperands: Align
4+
AlignAfterOpenBracket: AlwaysBreak
5+
AlignConsecutiveAssignments:
6+
Enabled: true
7+
AcrossEmptyLines: false
8+
AcrossComments: false
9+
AlignConsecutiveBitFields:
10+
Enabled: true
11+
AcrossEmptyLines: false
12+
AcrossComments: false
13+
AlignConsecutiveDeclarations:
14+
Enabled: true
15+
AcrossEmptyLines: false
16+
AcrossComments: false
17+
AlignConsecutiveMacros:
18+
Enabled: true
19+
AcrossEmptyLines: true
20+
AcrossComments: false
21+
AlignConsecutiveShortCaseStatements:
22+
Enabled: true
23+
AcrossEmptyLines: true
24+
AcrossComments: true
25+
AlignCaseColons: false
26+
AlignEscapedNewlines: LeftWithLastLine
27+
AlignOperands: true
28+
AlignTrailingComments:
29+
Kind: Always
30+
OverEmptyLines: 2
731
AllowAllArgumentsOnNextLine: false
832
AllowAllConstructorInitializersOnNextLine: false
933
AllowAllParametersOfDeclarationOnNextLine: false
10-
AllowShortBlocksOnASingleLine: Always
11-
AllowShortCaseLabelsOnASingleLine: false
12-
AllowShortFunctionsOnASingleLine: All
13-
AllowShortIfStatementsOnASingleLine: Always
14-
AllowShortLambdasOnASingleLine: All
15-
AllowShortLoopsOnASingleLine: true
16-
AlwaysBreakAfterReturnType: None
34+
AllowShortBlocksOnASingleLine: Empty
35+
AllowShortCaseExpressionOnASingleLine: true
36+
AllowShortCaseLabelsOnASingleLine: true
37+
AllowShortFunctionsOnASingleLine: None
38+
AllowShortIfStatementsOnASingleLine: Never
1739
AlwaysBreakTemplateDeclarations: Yes
1840
BreakBeforeBraces: Custom
1941
BraceWrapping:
2042
AfterCaseLabel: false
2143
AfterClass: false
22-
AfterControlStatement: Never
44+
AfterControlStatement: false
2345
AfterEnum: false
2446
AfterFunction: false
2547
AfterNamespace: false
48+
AfterStruct: false
2649
AfterUnion: false
27-
BeforeCatch: false
50+
AfterExternBlock: false
51+
BeforeCatch: true
2852
BeforeElse: false
29-
IndentBraces: false
30-
SplitEmptyFunction: false
53+
BeforeLambdaBody: false
54+
BeforeWhile: false
55+
SplitEmptyFunction: true
3156
SplitEmptyRecord: true
32-
BreakBeforeBinaryOperators: None
33-
BreakBeforeTernaryOperators: true
34-
BreakConstructorInitializers: BeforeColon
35-
BreakInheritanceList: BeforeColon
36-
ColumnLimit: 0
37-
CompactNamespaces: false
38-
ContinuationIndentWidth: 4
57+
SplitEmptyNamespace: true
58+
BracedInitializerIndentWidth: 2
59+
BreakConstructorInitializers: AfterColon
60+
BreakConstructorInitializersBeforeComma: false
61+
ColumnLimit: 120
62+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
63+
Cpp11BracedListStyle: true
64+
IncludeCategories:
65+
- Regex: '^<.*'
66+
Priority: 1
67+
- Regex: '^".*'
68+
Priority: 2
69+
- Regex: '.*'
70+
Priority: 3
71+
IncludeIsMainRegex: '([-_](test|unittest))?$'
72+
InsertBraces: true
3973
IndentCaseLabels: true
40-
IndentPPDirectives: BeforeHash
41-
IndentWidth: 2
42-
KeepEmptyLinesAtTheStartOfBlocks: true
74+
InsertNewlineAtEOF: true
75+
MacroBlockBegin: ''
76+
MacroBlockEnd: ''
4377
MaxEmptyLinesToKeep: 2
4478
NamespaceIndentation: All
45-
ObjCSpaceAfterProperty: false
46-
ObjCSpaceBeforeProtocolList: true
47-
PointerAlignment: Right
4879
ReflowComments: false
49-
SpaceAfterCStyleCast: true
50-
SpaceAfterLogicalNot: false
5180
SpaceAfterTemplateKeyword: false
52-
SpaceBeforeAssignmentOperators: true
53-
SpaceBeforeCpp11BracedList: false
54-
SpaceBeforeCtorInitializerColon: true
55-
SpaceBeforeInheritanceColon: true
56-
SpaceBeforeParens: ControlStatements
5781
SpaceBeforeRangeBasedForLoopColon: false
5882
SpaceInEmptyParentheses: false
59-
SpacesBeforeTrailingComments: 0
6083
SpacesInAngles: false
84+
SpacesInConditionalStatement: false
6185
SpacesInCStyleCastParentheses: false
62-
SpacesInContainerLiterals: true
6386
SpacesInParentheses: false
64-
SpacesInSquareBrackets: false
6587
TabWidth: 2
66-
UseTab: Never
88+
...

examples/device/audio_4_channel_mic/src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ void tud_resume_cb(void) {
156156
void audio_task(void) {
157157
static uint32_t start_ms = 0;
158158
uint32_t curr_ms = board_millis();
159-
if (start_ms == curr_ms) return;// not enough time
159+
if (start_ms == curr_ms) {
160+
return; // not enough time
161+
}
160162
start_ms = curr_ms;
161163
tud_audio_write(i2s_dummy_buffer, AUDIO_SAMPLE_RATE / 1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX);
162164
}
@@ -406,7 +408,9 @@ void led_blinking_task(void) {
406408
static bool led_state = false;
407409

408410
// Blink every interval ms
409-
if (board_millis() - start_ms < blink_interval_ms) return;// not enough time
411+
if (board_millis() - start_ms < blink_interval_ms) {
412+
return; // not enough time
413+
}
410414
start_ms += blink_interval_ms;
411415

412416
board_led_write(led_state);

examples/device/audio_4_channel_mic_freertos/src/usb_descriptors.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
156156
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
157157
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
158158

159-
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
159+
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
160+
return NULL;
161+
}
160162

161163
const char *str = string_desc_arr[index];
162164

163165
// Cap at max char
164166
chr_count = strlen(str);
165167
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
166-
if ( chr_count > max_count ) chr_count = max_count;
168+
if ( chr_count > max_count ) {
169+
chr_count = max_count;
170+
}
167171

168172
// Convert ASCII string into UTF-16
169173
for ( size_t i = 0; i < chr_count; i++ ) {

examples/device/audio_test/src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ void tud_resume_cb(void) {
139139
void audio_task(void) {
140140
static uint32_t start_ms = 0;
141141
uint32_t curr_ms = board_millis();
142-
if (start_ms == curr_ms) return;// not enough time
142+
if (start_ms == curr_ms) {
143+
return; // not enough time
144+
}
143145
start_ms = curr_ms;
144146
for (size_t cnt = 0; cnt < sizeof(test_buffer_audio) / 2; cnt++) {
145147
test_buffer_audio[cnt] = startVal++;
@@ -400,7 +402,9 @@ void led_blinking_task(void) {
400402
static bool led_state = false;
401403

402404
// Blink every interval ms
403-
if (board_millis() - start_ms < blink_interval_ms) return;// not enough time
405+
if (board_millis() - start_ms < blink_interval_ms) {
406+
return; // not enough time
407+
}
404408
start_ms += blink_interval_ms;
405409

406410
board_led_write(led_state);

examples/device/audio_test/src/usb_descriptors.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
158158
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
159159
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
160160

161-
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
161+
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
162+
return NULL;
163+
}
162164

163165
const char *str = string_desc_arr[index];
164166

165167
// Cap at max char
166168
chr_count = strlen(str);
167169
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
168-
if ( chr_count > max_count ) chr_count = max_count;
170+
if (chr_count > max_count) {
171+
chr_count = max_count;
172+
}
169173

170174
// Convert ASCII string into UTF-16
171175
for ( size_t i = 0; i < chr_count; i++ ) {

examples/device/audio_test_freertos/src/usb_descriptors.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
158158
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
159159
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
160160

161-
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
161+
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
162+
return NULL;
163+
}
162164

163165
const char *str = string_desc_arr[index];
164166

165167
// Cap at max char
166168
chr_count = strlen(str);
167169
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
168-
if ( chr_count > max_count ) chr_count = max_count;
170+
if (chr_count > max_count) {
171+
chr_count = max_count;
172+
}
169173

170174
// Convert ASCII string into UTF-16
171175
for ( size_t i = 0; i < chr_count; i++ ) {

examples/device/audio_test_multi_rate/src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ void tud_resume_cb(void) {
147147
void audio_task(void) {
148148
static uint32_t start_ms = 0;
149149
uint32_t curr_ms = board_millis();
150-
if (start_ms == curr_ms) return;// not enough time
150+
if (start_ms == curr_ms) {
151+
return; // not enough time
152+
}
151153
start_ms = curr_ms;
152154
// 16bit
153155
if (bytesPerSample == 2) {
@@ -612,7 +614,9 @@ void led_blinking_task(void) {
612614
static bool led_state = false;
613615

614616
// Blink every interval ms
615-
if (board_millis() - start_ms < blink_interval_ms) return;// not enough time
617+
if (board_millis() - start_ms < blink_interval_ms) {
618+
return; // not enough time
619+
}
616620
start_ms += blink_interval_ms;
617621

618622
board_led_write(led_state);

examples/device/audio_test_multi_rate/src/usb_descriptors.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
213213
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
214214
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
215215

216-
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
216+
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
217+
return NULL;
218+
}
217219

218220
const char *str = string_desc_arr[index];
219221

220222
// Cap at max char
221223
chr_count = strlen(str);
222224
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
223-
if ( chr_count > max_count ) chr_count = max_count;
225+
if (chr_count > max_count) {
226+
chr_count = max_count;
227+
}
224228

225229
// Convert ASCII string into UTF-16
226230
for ( size_t i = 0; i < chr_count; i++ ) {

examples/device/cdc_dual_ports/src/main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count) {
7575
for (uint32_t i = 0; i < count; i++) {
7676
if (itf == 0) {
7777
// echo back 1st port as lower case
78-
if (isupper(buf[i])) buf[i] += case_diff;
78+
if (isupper(buf[i])) {
79+
buf[i] += case_diff;
80+
}
7981
} else {
8082
// echo back 2nd port as upper case
81-
if (islower(buf[i])) buf[i] -= case_diff;
83+
if (islower(buf[i])) {
84+
buf[i] -= case_diff;
85+
}
8286
}
8387

8488
tud_cdc_n_write_char(itf, buf[i]);
@@ -153,7 +157,9 @@ void led_blinking_task(void) {
153157
static bool led_state = false;
154158

155159
// Blink every interval ms
156-
if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
160+
if (board_millis() - start_ms < blink_interval_ms) {
161+
return; // not enough time
162+
}
157163
start_ms += blink_interval_ms;
158164

159165
board_led_write(led_state);

0 commit comments

Comments
 (0)