Skip to content

Commit afea7ca

Browse files
authored
Update clang-tidy configuration and fix some warnings (#1474)
Don't enable coding conventions from unrelated projects. Only enable generic checks.
1 parent bfedf47 commit afea7ca

24 files changed

+152
-150
lines changed

.clang-tidy

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
Checks: '*,
2-
-altera-unroll-loops,
3-
-llvmlibc-callee-namespace,
4-
-llvmlibc-implementation-in-namespace,
5-
-llvmlibc-restrict-system-libc-headers,
6-
-llvm-header-guard,
7-
-llvm-namespace-comment,
8-
-google-build-using-namespace,
9-
-google-runtime-int,
10-
-google-readability-namespace-comments,
11-
-fuchsia-statically-constructed-objects,
1+
Checks: 'bugprone-*,
2+
cert-*,
3+
cppcoreguidelines-*,
4+
hicpp-*,
5+
misc-*,
6+
modernize-*,
7+
performance-*,
8+
portability-*,
9+
readability-*,
10+
fuchsia-trailing-return,
11+
-cert-err58-cpp,
12+
-cert-err60-cpp,
1213
-cppcoreguidelines-prefer-member-initializer,
1314
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
1415
-cppcoreguidelines-pro-bounds-constant-array-index,
@@ -20,19 +21,17 @@ Checks: '*,
2021
-cppcoreguidelines-avoid-non-const-global-variables,
2122
-cppcoreguidelines-avoid-c-arrays,
2223
-cppcoreguidelines-special-member-functions,
23-
-readability-magic-numbers,
24-
-readability-uppercase-literal-suffix,
25-
-modernize-use-trailing-return-type,
26-
-modernize-avoid-c-arrays,
2724
-hicpp-avoid-c-arrays,
2825
-hicpp-uppercase-literal-suffix,
2926
-hicpp-vararg,
3027
-hicpp-no-assembler,
3128
-hicpp-no-array-decay,
3229
-hicpp-signed-bitwise,
3330
-hicpp-special-member-functions,
34-
-cert-err58-cpp,
35-
-cert-err60-cpp'
31+
-modernize-use-trailing-return-type,
32+
-modernize-avoid-c-arrays,
33+
-readability-magic-numbers,
34+
-readability-uppercase-literal-suffix'
3635
CheckOptions:
3736
- key: readability-function-cognitive-complexity.Threshold
3837
value: 100

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ link_directories(
778778
)
779779

780780

781-
set(COMMON_FLAGS -MP -MD -mthumb -mabi=aapcs -Wall -Wextra -Warray-bounds=2 -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-nonliteral -ftree-vrp -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-expansion-to-defined -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wreturn-type -Werror=return-type -fstack-usage -fno-exceptions -fno-non-call-exceptions)
781+
set(COMMON_FLAGS -MP -MD -mthumb -mabi=aapcs -Wall -Wextra -Warray-bounds=2 -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-nonliteral -ftree-vrp -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-expansion-to-defined -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin -fshort-enums -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wreturn-type -Werror=return-type -fstack-usage -fno-exceptions -fno-non-call-exceptions)
782782
add_definitions(-DCONFIG_GPIO_AS_PINRESET)
783783
add_definitions(-DNIMBLE_CFG_CONTROLLER)
784784
add_definitions(-DOS_CPUTIME_FREQ)

src/components/alarm/AlarmController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : da
2828

2929
namespace {
3030
void SetOffAlarm(TimerHandle_t xTimer) {
31-
auto controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer));
31+
auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer));
3232
controller->SetOffAlarmNow();
3333
}
3434
}

src/components/battery/BatteryController.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Battery::Battery() {
1616
}
1717

1818
void Battery::ReadPowerState() {
19-
isCharging = !nrf_gpio_pin_read(PinMap::Charging);
20-
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
19+
isCharging = (nrf_gpio_pin_read(PinMap::Charging) == 0);
20+
isPowerPresent = (nrf_gpio_pin_read(PinMap::PowerPresent) == 0);
2121

2222
if (isPowerPresent && !isCharging) {
2323
isFull = true;
@@ -81,10 +81,8 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
8181
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
8282
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
8383

84-
uint8_t newPercent;
85-
if (isFull) {
86-
newPercent = 100;
87-
} else {
84+
uint8_t newPercent = 100;
85+
if (!isFull) {
8886
newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
8987
}
9088

src/components/ble/NavigationService.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace {
4040
constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)};
4141

4242
int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
43-
auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
43+
auto* navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
4444
return navService->OnCommand(conn_handle, attr_handle, ctxt);
4545
}
4646
} // namespace

src/components/heartrate/Ppg.cpp

+23-15
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ namespace {
2929
auto z1 = CompareShift(d, mn - 1, size);
3030
for (int i = mn; i < mx + 1; i++) {
3131
auto z = CompareShift(d, i, size);
32-
if (z2 > z1 && z1 < z)
32+
if (z2 > z1 && z1 < z) {
3333
return i;
34+
}
3435
z2 = z1;
3536
z1 = z;
3637
}
@@ -52,41 +53,48 @@ int8_t Ppg::Preprocess(float spl) {
5253

5354
auto spl_int = static_cast<int8_t>(spl);
5455

55-
if (dataIndex < 200)
56+
if (dataIndex < 200) {
5657
data[dataIndex++] = spl_int;
58+
}
5759
return spl_int;
5860
}
5961

60-
float Ppg::HeartRate() {
61-
if (dataIndex < 200)
62+
int Ppg::HeartRate() {
63+
if (dataIndex < 200) {
6264
return 0;
65+
}
6366

6467
NRF_LOG_INFO("PREPROCESS, offset = %d", offset);
6568
auto hr = ProcessHeartRate();
6669
dataIndex = 0;
6770
return hr;
6871
}
69-
float Ppg::ProcessHeartRate() {
70-
auto t0 = Trough(data.data(), dataIndex, 7, 48);
71-
if (t0 < 0)
72+
73+
int Ppg::ProcessHeartRate() {
74+
int t0 = Trough(data.data(), dataIndex, 7, 48);
75+
if (t0 < 0) {
7276
return 0;
77+
}
7378

74-
float t1 = t0 * 2;
79+
int t1 = t0 * 2;
7580
t1 = Trough(data.data(), dataIndex, t1 - 5, t1 + 5);
76-
if (t1 < 0)
81+
if (t1 < 0) {
7782
return 0;
83+
}
7884

79-
float t2 = static_cast<int>(t1 * 3) / 2;
85+
int t2 = (t1 * 3) / 2;
8086
t2 = Trough(data.data(), dataIndex, t2 - 5, t2 + 5);
81-
if (t2 < 0)
87+
if (t2 < 0) {
8288
return 0;
89+
}
8390

84-
float t3 = static_cast<int>(t2 * 4) / 3;
91+
int t3 = (t2 * 4) / 3;
8592
t3 = Trough(data.data(), dataIndex, t3 - 4, t3 + 4);
86-
if (t3 < 0)
87-
return static_cast<int>(60 * 24 * 3) / static_cast<int>(t2);
93+
if (t3 < 0) {
94+
return (60 * 24 * 3) / t2;
95+
}
8896

89-
return static_cast<int>(60 * 24 * 4) / static_cast<int>(t3);
97+
return (60 * 24 * 4) / t3;
9098
}
9199

92100
void Ppg::SetOffset(uint16_t offset) {

src/components/heartrate/Ppg.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Pinetime {
1212
public:
1313
Ppg();
1414
int8_t Preprocess(float spl);
15-
float HeartRate();
15+
int HeartRate();
1616

17-
void SetOffset(uint16_t i);
17+
void SetOffset(uint16_t offset);
1818
void Reset();
1919

2020
private:
@@ -25,7 +25,7 @@ namespace Pinetime {
2525
Ptagc agc;
2626
Biquad lpf;
2727

28-
float ProcessHeartRate();
28+
int ProcessHeartRate();
2929
};
3030
}
3131
}

src/components/heartrate/Ptagc.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ Ptagc::Ptagc(float start, float decay, float threshold) : peak {start}, decay {d
1414
}
1515

1616
float Ptagc::Step(float spl) {
17-
if (std::abs(spl) > peak)
17+
if (std::abs(spl) > peak) {
1818
peak *= boost;
19-
else
19+
} else {
2020
peak *= decay;
21+
}
2122

22-
if ((spl > (peak * threshold)) || (spl < (peak * -threshold)))
23+
if ((spl > (peak * threshold)) || (spl < (peak * -threshold))) {
2324
return 0.0f;
25+
}
2426

2527
spl = 100.0f * spl / (2.0f * peak);
2628
return spl;

src/components/motion/MotionController.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ bool MotionController::Should_RaiseWake(bool isSleeping) {
2626
if (not isSleeping) {
2727
if (y <= 0) {
2828
return false;
29-
} else {
30-
lastYForWakeUp = 0;
31-
return false;
3229
}
30+
lastYForWakeUp = 0;
31+
return false;
3332
}
3433

3534
if (y >= 0) {

src/displayapp/DisplayApp.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void DisplayApp::Refresh() {
152152
}
153153

154154
Messages msg;
155-
if (xQueueReceive(msgQueue, &msg, queueTimeout)) {
155+
if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) {
156156
switch (msg) {
157157
case Messages::DimScreen:
158158
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
@@ -485,10 +485,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
485485

486486
void DisplayApp::PushMessage(Messages msg) {
487487
if (in_isr()) {
488-
BaseType_t xHigherPriorityTaskWoken;
489-
xHigherPriorityTaskWoken = pdFALSE;
488+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
490489
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
491-
if (xHigherPriorityTaskWoken) {
490+
if (xHigherPriorityTaskWoken == pdTRUE) {
492491
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
493492
}
494493
} else {
@@ -532,8 +531,7 @@ void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
532531
}
533532
void DisplayApp::ApplyBrightness() {
534533
auto brightness = settingsController.GetBrightness();
535-
if(brightness != Controllers::BrightnessController::Levels::Low &&
536-
brightness != Controllers::BrightnessController::Levels::Medium &&
534+
if (brightness != Controllers::BrightnessController::Levels::Low && brightness != Controllers::BrightnessController::Levels::Medium &&
537535
brightness != Controllers::BrightnessController::Levels::High) {
538536
brightness = Controllers::BrightnessController::Levels::High;
539537
}

src/displayapp/screens/FirmwareValidation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app,
3232
lv_label_set_long_mode(labelIsValidated, LV_LABEL_LONG_BREAK);
3333
lv_obj_set_width(labelIsValidated, 240);
3434

35-
if (validator.IsValidated())
35+
if (validator.IsValidated()) {
3636
lv_label_set_text_static(labelIsValidated, "You have already\n#00ff00 validated# this firmware#");
37-
else {
37+
} else {
3838
lv_label_set_text_static(labelIsValidated,
3939
"Please #00ff00 Validate# this version or\n#ff0000 Reset# to rollback to the previous version.");
4040

4141
buttonValidate = lv_btn_create(lv_scr_act(), nullptr);
4242
buttonValidate->user_data = this;
4343
lv_obj_set_size(buttonValidate, 115, 50);
44-
lv_obj_align(buttonValidate, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
44+
lv_obj_align(buttonValidate, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
4545
lv_obj_set_event_cb(buttonValidate, ButtonEventHandler);
4646
lv_obj_set_style_local_bg_color(buttonValidate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight);
4747

src/displayapp/screens/HeartRate.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ HeartRate::HeartRate(Pinetime::Applications::DisplayApp* app,
6464

6565
label_startStop = lv_label_create(btn_startStop, nullptr);
6666
UpdateStartStopButton(isHrRunning);
67-
if (isHrRunning)
67+
if (isHrRunning) {
6868
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
69+
}
6970

7071
taskRefresh = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
7172
}
@@ -110,8 +111,9 @@ void HeartRate::OnStartStopEvent(lv_event_t event) {
110111
}
111112

112113
void HeartRate::UpdateStartStopButton(bool isRunning) {
113-
if (isRunning)
114+
if (isRunning) {
114115
lv_label_set_text_static(label_startStop, "Stop");
115-
else
116+
} else {
116117
lv_label_set_text_static(label_startStop, "Start");
118+
}
117119
}

src/displayapp/screens/Motion.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ using namespace Pinetime::Applications::Screens;
77

88
Motion::Motion(Pinetime::Applications::DisplayApp* app, Controllers::MotionController& motionController)
99
: Screen(app), motionController {motionController} {
10-
chart = lv_chart_create(lv_scr_act(), NULL);
10+
chart = lv_chart_create(lv_scr_act(), nullptr);
1111
lv_obj_set_size(chart, 240, 240);
12-
lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
12+
lv_obj_align(chart, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0);
1313
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
1414
// lv_chart_set_series_opa(chart, LV_OPA_70); /*Opacity of the data series*/
1515
// lv_chart_set_series_width(chart, 4); /*Line width and point radious*/
@@ -28,13 +28,13 @@ Motion::Motion(Pinetime::Applications::DisplayApp* app, Controllers::MotionContr
2828
lv_chart_init_points(chart, ser3, 0);
2929
lv_chart_refresh(chart); /*Required after direct set*/
3030

31-
label = lv_label_create(lv_scr_act(), NULL);
31+
label = lv_label_create(lv_scr_act(), nullptr);
3232
lv_label_set_text_fmt(label, "X #FF0000 %d# Y #00B000 %d# Z #FFFF00 %d#", 0, 0, 0);
3333
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
34-
lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
34+
lv_obj_align(label, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10);
3535
lv_label_set_recolor(label, true);
3636

37-
labelStep = lv_label_create(lv_scr_act(), NULL);
37+
labelStep = lv_label_create(lv_scr_act(), nullptr);
3838
lv_obj_align(labelStep, chart, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
3939
lv_label_set_text_static(labelStep, "Steps ---");
4040

@@ -58,5 +58,5 @@ void Motion::Refresh() {
5858
motionController.X() / 0x10,
5959
motionController.Y() / 0x10,
6060
motionController.Z() / 0x10);
61-
lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
61+
lv_obj_align(label, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10);
6262
}

0 commit comments

Comments
 (0)