Skip to content

Commit 04c18c6

Browse files
committed
[GS] Fix clang-tidy issues
1 parent 63f4cc7 commit 04c18c6

34 files changed

+859
-726
lines changed

.github/workflows/merge-criteria.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
name: Build + Lint
7474
# We are running this on windows because the users get binaries compiled on windows.
7575
# The code should also be tested in a linux build.
76-
runs-on: windows-latest
76+
runs-on: ubuntu-latest
7777
timeout-minutes: 60
7878
strategy:
7979
fail-fast: false

ground_station/platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ debug_load_mode = always
109109

110110
extra_scripts =
111111
pre:pre_config.py
112+
post:post_config.py
112113
upload_script.py
113114

114115
upload_protocol = custom
@@ -129,4 +130,4 @@ check_src_filters =
129130
+<src/>
130131
# TODO: check_skip_packages should be removed once the clang-tidy command length is reduced.
131132
# Because of this flag clang-tidy complains it can't find library files such as "Arduino.h"
132-
check_skip_packages = yes
133+
; check_skip_packages = yes

ground_station/post_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Import("projenv")
2+
3+
include_flags = []
4+
for path in projenv["CPPPATH"]:
5+
if path != projenv["PROJECT_INCLUDE_DIR"]:
6+
include_flags.append(["-isystem", path])
7+
8+
projenv.Append(
9+
CXXFLAGS = include_flags
10+
)

ground_station/pre_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def src_file_config(env, node):
6262
"-Wformat-truncation=2",
6363
"-Wformat-overflow",
6464
"-Wformat-signedness",
65+
"-Wattributes",
66+
"-Wextra",
6567

6668
"-Werror",
6769
]

ground_station/src/USB.cpp

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,67 +51,72 @@
5151
#define USB_WEBUSB_ENABLED false
5252
#endif
5353
#ifndef USB_WEBUSB_URL
54+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
5455
#define USB_WEBUSB_URL "https://espressif.github.io/arduino-esp32/webusb.html"
5556
#endif
5657

5758
#if CFG_TUD_DFU_RUNTIME
5859
static uint16_t load_dfu_descriptor(uint8_t *dst, uint8_t *itf) {
5960
#define DFU_ATTRS (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_CAN_UPLOAD | DFU_ATTR_MANIFESTATION_TOLERANT)
6061

61-
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT");
62+
const uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT");
6263
uint8_t descriptor[TUD_DFU_RT_DESC_LEN] = {
6364
// Interface number, string index, attributes, detach timeout, transfer size */
64-
TUD_DFU_RT_DESCRIPTOR(*itf, str_index, DFU_ATTRS, 700, 64)};
65+
// NOLINTNEXTLINE(hicpp-signed-bitwise)
66+
TUD_DFU_RT_DESCRIPTOR(*itf, str_index, DFU_ATTRS, 700U, 64U)};
6567
*itf += 1;
6668
memcpy(dst, descriptor, TUD_DFU_RT_DESC_LEN);
6769
return TUD_DFU_RT_DESC_LEN;
6870
}
6971
// Invoked on DFU_DETACH request to reboot to the bootloader
70-
void tud_dfu_runtime_reboot_to_dfu_cb(void) {
72+
void tud_dfu_runtime_reboot_to_dfu_cb() {
7173
// MODIFICATION: If DFU Detach request gets received, UF2-Bootloader instead of ROM-Bootloader gets launched!
7274

7375
// usb_persist_restart(RESTART_BOOTLOADER_DFU);
7476
const uint16_t APP_REQUEST_UF2_RESET_HINT = 0x11F2;
7577
esp_reset_reason();
76-
esp_reset_reason_set_hint((esp_reset_reason_t)APP_REQUEST_UF2_RESET_HINT);
78+
esp_reset_reason_set_hint(static_cast<esp_reset_reason_t>(APP_REQUEST_UF2_RESET_HINT));
7779
esp_restart();
7880
}
7981
#endif /* CFG_TUD_DFU_RUNTIME */
8082

83+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
8184
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_EVENTS);
82-
83-
static esp_event_loop_handle_t arduino_usb_event_loop_handle = NULL;
85+
static esp_event_loop_handle_t arduino_usb_event_loop_handle = nullptr;
86+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
8487

8588
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data,
8689
size_t event_data_size, TickType_t ticks_to_wait) {
87-
if (arduino_usb_event_loop_handle == NULL) {
90+
if (arduino_usb_event_loop_handle == nullptr) {
8891
return ESP_FAIL;
8992
}
9093
return esp_event_post_to(arduino_usb_event_loop_handle, event_base, event_id, event_data, event_data_size,
9194
ticks_to_wait);
9295
}
9396
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id,
9497
esp_event_handler_t event_handler, void *event_handler_arg) {
95-
if (arduino_usb_event_loop_handle == NULL) {
98+
if (arduino_usb_event_loop_handle == nullptr) {
9699
return ESP_FAIL;
97100
}
98101
return esp_event_handler_register_with(arduino_usb_event_loop_handle, event_base, event_id, event_handler,
99102
event_handler_arg);
100103
}
101104

105+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
102106
static bool tinyusb_device_mounted = false;
103107
static bool tinyusb_device_suspended = false;
108+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
104109

105110
// Invoked when device is mounted (configured)
106-
void tud_mount_cb(void) {
111+
void tud_mount_cb() {
107112
tinyusb_device_mounted = true;
108113
arduino_usb_event_data_t p;
109114
arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STARTED_EVENT, &p, sizeof(arduino_usb_event_data_t),
110115
portMAX_DELAY);
111116
}
112117

113118
// Invoked when device is unmounted
114-
void tud_umount_cb(void) {
119+
void tud_umount_cb() {
115120
tinyusb_device_mounted = false;
116121
arduino_usb_event_data_t p;
117122
arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, &p, sizeof(arduino_usb_event_data_t),
@@ -129,7 +134,7 @@ void tud_suspend_cb(bool remote_wakeup_en) {
129134
}
130135

131136
// Invoked when usb bus is resumed
132-
void tud_resume_cb(void) {
137+
void tud_resume_cb() {
133138
tinyusb_device_suspended = false;
134139
arduino_usb_event_data_t p;
135140
arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_RESUME_EVENT, &p, sizeof(arduino_usb_event_data_t),
@@ -155,22 +160,22 @@ ESPUSB::ESPUSB(size_t task_stack_size, uint8_t event_task_priority)
155160
_started(false),
156161
_task_stack_size(task_stack_size),
157162
_event_task_priority(event_task_priority) {
158-
if (!arduino_usb_event_loop_handle) {
159-
esp_event_loop_args_t event_task_args = {.queue_size = 5,
160-
.task_name = "arduino_usb_events",
161-
.task_priority = _event_task_priority,
162-
.task_stack_size = _task_stack_size,
163-
.task_core_id = tskNO_AFFINITY};
163+
if (arduino_usb_event_loop_handle == nullptr) {
164+
const esp_event_loop_args_t event_task_args = {.queue_size = 5,
165+
.task_name = "arduino_usb_events",
166+
.task_priority = _event_task_priority,
167+
.task_stack_size = _task_stack_size,
168+
.task_core_id = tskNO_AFFINITY};
164169
if (esp_event_loop_create(&event_task_args, &arduino_usb_event_loop_handle) != ESP_OK) {
165170
log_e("esp_event_loop_create failed");
166171
}
167172
}
168173
}
169174

170175
ESPUSB::~ESPUSB() {
171-
if (arduino_usb_event_loop_handle) {
176+
if (arduino_usb_event_loop_handle != nullptr) {
172177
esp_event_loop_delete(arduino_usb_event_loop_handle);
173-
arduino_usb_event_loop_handle = NULL;
178+
arduino_usb_event_loop_handle = nullptr;
174179
}
175180
}
176181

@@ -202,6 +207,7 @@ void ESPUSB::onEvent(arduino_usb_event_t event, esp_event_handler_t callback) {
202207

203208
ESPUSB::operator bool() const { return _started && tinyusb_device_mounted; }
204209

210+
// NOLINTBEGIN(readability-convert-member-functions-to-static,readability-make-member-function-const)
205211
bool ESPUSB::enableDFU() {
206212
#if CFG_TUD_DFU_RUNTIME
207213
return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_RT_DESC_LEN, load_dfu_descriptor) == ESP_OK;
@@ -215,71 +221,71 @@ bool ESPUSB::VID(uint16_t v) {
215221
}
216222
return !_started;
217223
}
218-
uint16_t ESPUSB::VID(void) { return vid; }
224+
uint16_t ESPUSB::VID() { return vid; }
219225

220226
bool ESPUSB::PID(uint16_t p) {
221227
if (!_started) {
222228
pid = p;
223229
}
224230
return !_started;
225231
}
226-
uint16_t ESPUSB::PID(void) { return pid; }
232+
uint16_t ESPUSB::PID() { return pid; }
227233

228234
bool ESPUSB::firmwareVersion(uint16_t version) {
229235
if (!_started) {
230236
fw_version = version;
231237
}
232238
return !_started;
233239
}
234-
uint16_t ESPUSB::firmwareVersion(void) { return fw_version; }
240+
uint16_t ESPUSB::firmwareVersion() { return fw_version; }
235241

236242
bool ESPUSB::usbVersion(uint16_t version) {
237243
if (!_started) {
238244
usb_version = version;
239245
}
240246
return !_started;
241247
}
242-
uint16_t ESPUSB::usbVersion(void) { return usb_version; }
248+
uint16_t ESPUSB::usbVersion() { return usb_version; }
243249

244250
bool ESPUSB::usbPower(uint16_t mA) {
245251
if (!_started) {
246252
usb_power_ma = mA;
247253
}
248254
return !_started;
249255
}
250-
uint16_t ESPUSB::usbPower(void) { return usb_power_ma; }
256+
uint16_t ESPUSB::usbPower() { return usb_power_ma; }
251257

252258
bool ESPUSB::usbClass(uint8_t _class) {
253259
if (!_started) {
254260
usb_class = _class;
255261
}
256262
return !_started;
257263
}
258-
uint8_t ESPUSB::usbClass(void) { return usb_class; }
264+
uint8_t ESPUSB::usbClass() { return usb_class; }
259265

260266
bool ESPUSB::usbSubClass(uint8_t subClass) {
261267
if (!_started) {
262268
usb_subclass = subClass;
263269
}
264270
return !_started;
265271
}
266-
uint8_t ESPUSB::usbSubClass(void) { return usb_subclass; }
272+
uint8_t ESPUSB::usbSubClass() { return usb_subclass; }
267273

268274
bool ESPUSB::usbProtocol(uint8_t protocol) {
269275
if (!_started) {
270276
usb_protocol = protocol;
271277
}
272278
return !_started;
273279
}
274-
uint8_t ESPUSB::usbProtocol(void) { return usb_protocol; }
280+
uint8_t ESPUSB::usbProtocol() { return usb_protocol; }
275281

276282
bool ESPUSB::usbAttributes(uint8_t attr) {
277283
if (!_started) {
278284
usb_attributes = attr;
279285
}
280286
return !_started;
281287
}
282-
uint8_t ESPUSB::usbAttributes(void) { return usb_attributes; }
288+
uint8_t ESPUSB::usbAttributes() { return usb_attributes; }
283289

284290
bool ESPUSB::webUSB(bool enabled) {
285291
if (!_started) {
@@ -290,40 +296,43 @@ bool ESPUSB::webUSB(bool enabled) {
290296
}
291297
return !_started;
292298
}
293-
bool ESPUSB::webUSB(void) { return webusb_enabled; }
299+
bool ESPUSB::webUSB() { return webusb_enabled; }
294300

295301
bool ESPUSB::productName(const char *name) {
296302
if (!_started) {
297303
product_name = name;
298304
}
299305
return !_started;
300306
}
301-
const char *ESPUSB::productName(void) { return product_name.c_str(); }
307+
const char *ESPUSB::productName() { return product_name.c_str(); }
302308

303309
bool ESPUSB::manufacturerName(const char *name) {
304310
if (!_started) {
305311
manufacturer_name = name;
306312
}
307313
return !_started;
308314
}
309-
const char *ESPUSB::manufacturerName(void) { return manufacturer_name.c_str(); }
315+
const char *ESPUSB::manufacturerName() { return manufacturer_name.c_str(); }
310316

311317
bool ESPUSB::serialNumber(const char *name) {
312318
if (!_started) {
313319
serial_number = name;
314320
}
315321
return !_started;
316322
}
317-
const char *ESPUSB::serialNumber(void) { return serial_number.c_str(); }
323+
const char *ESPUSB::serialNumber() { return serial_number.c_str(); }
318324

319325
bool ESPUSB::webUSBURL(const char *name) {
320326
if (!_started) {
321327
webusb_url = name;
322328
}
323329
return !_started;
324330
}
325-
const char *ESPUSB::webUSBURL(void) { return webusb_url.c_str(); }
331+
const char *ESPUSB::webUSBURL() { return webusb_url.c_str(); }
332+
333+
// NOLINTEND(readability-convert-member-functions-to-static,readability-make-member-function-const)
326334

335+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
327336
ESPUSB USB;
328337

329338
#endif /* CONFIG_TINYUSB_ENABLED */

0 commit comments

Comments
 (0)