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
5859static 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)
8184ESP_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
8588esp_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}
9396esp_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)
102106static bool tinyusb_device_mounted = false ;
103107static 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
170175ESPUSB::~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
203208ESPUSB::operator bool () const { return _started && tinyusb_device_mounted; }
204209
210+ // NOLINTBEGIN(readability-convert-member-functions-to-static,readability-make-member-function-const)
205211bool 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
220226bool 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
228234bool 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
236242bool 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
244250bool 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
252258bool 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
260266bool 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
268274bool 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
276282bool 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
284290bool 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
295301bool 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
303309bool 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
311317bool 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
319325bool 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)
327336ESPUSB USB;
328337
329338#endif /* CONFIG_TINYUSB_ENABLED */
0 commit comments