Parcourir la source

Clean up comments, USB flash, NULLs

Scott Lahteine il y a 3 ans
Parent
révision
ec23e37a4a
45 fichiers modifiés avec 231 ajouts et 238 suppressions
  1. 2
    2
      Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp
  2. 2
    2
      Marlin/src/HAL/ESP32/i2s.cpp
  3. 2
    2
      Marlin/src/HAL/LINUX/eeprom.cpp
  4. 6
    6
      Marlin/src/HAL/LINUX/hardware/Gpio.h
  5. 2
    2
      Marlin/src/HAL/SAMD51/HAL.cpp
  6. 2
    2
      Marlin/src/HAL/SAMD51/QSPIFlash.cpp
  7. 1
    1
      Marlin/src/HAL/STM32/tft/xpt2046.cpp
  8. 1
    1
      Marlin/src/HAL/STM32/timers.cpp
  9. 1
    1
      Marlin/src/HAL/STM32F1/HAL.h
  10. 1
    1
      Marlin/src/HAL/STM32F1/SPI.cpp
  11. 1
    1
      Marlin/src/HAL/STM32F1/fastio.h
  12. 1
    1
      Marlin/src/gcode/parser.h
  13. 2
    2
      Marlin/src/gcode/queue.cpp
  14. 1
    1
      Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
  15. 1
    1
      Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
  16. 1
    1
      Marlin/src/lcd/dogm/marlinui_DOGM.cpp
  17. 1
    1
      Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
  18. 1
    1
      Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp
  19. 6
    7
      Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp
  20. 3
    3
      Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp
  21. 6
    6
      Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp
  22. 1
    1
      Marlin/src/lcd/menu/menu.cpp
  23. 1
    1
      Marlin/src/lcd/tft/canvas.cpp
  24. 1
    1
      Marlin/src/lcd/tft/tft_image.cpp
  25. 10
    10
      Marlin/src/lcd/tft/tft_queue.cpp
  26. 1
    1
      Marlin/src/lcd/tft/tft_string.cpp
  27. 4
    5
      Marlin/src/lcd/tft/touch.cpp
  28. 1
    1
      Marlin/src/lcd/tft/ui_320x240.cpp
  29. 2
    2
      Marlin/src/lcd/tft/ui_480x320.cpp
  30. 4
    4
      Marlin/src/libs/heatshrink/heatshrink_decoder.cpp
  31. 1
    1
      Marlin/src/libs/vector_3.cpp
  32. 1
    1
      Marlin/src/pins/mega/pins_CNCONTROLS_11.h
  33. 1
    1
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h
  34. 2
    2
      Marlin/src/sd/SdBaseFile.cpp
  35. 2
    5
      Marlin/src/sd/SdBaseFile.h
  36. 2
    1
      Marlin/src/sd/SdFatConfig.h
  37. 2
    5
      Marlin/src/sd/SdFatStructs.h
  38. 2
    0
      Marlin/src/sd/SdFatUtil.cpp
  39. 2
    0
      Marlin/src/sd/SdFatUtil.h
  40. 2
    0
      Marlin/src/sd/SdFile.cpp
  41. 3
    6
      Marlin/src/sd/SdFile.h
  42. 2
    0
      Marlin/src/sd/SdVolume.cpp
  43. 2
    5
      Marlin/src/sd/SdVolume.h
  44. 2
    2
      Marlin/src/sd/cardreader.cpp
  45. 136
    138
      Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp

+ 2
- 2
Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp Voir le fichier

@@ -84,7 +84,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
84 84
     card.getSd2Card().readData(sector_buf);
85 85
 
86 86
     // RAM -> USB
87
-    if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) {
87
+    if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
88 88
       card.getSd2Card().readStop();
89 89
       return CTRL_FAIL;
90 90
     }
@@ -120,7 +120,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
120 120
   while (nb_sector--) {
121 121
 
122 122
     // USB -> RAM
123
-    if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) {
123
+    if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
124 124
       card.getSd2Card().writeStop();
125 125
       return CTRL_FAIL;
126 126
     }

+ 2
- 2
Marlin/src/HAL/ESP32/i2s.cpp Voir le fichier

@@ -184,7 +184,7 @@ int i2s_init() {
184 184
 
185 185
   // Allocate the array of pointers to the buffers
186 186
   dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT);
187
-  if (dma.buffers == nullptr) return -1;
187
+  if (!dma.buffers) return -1;
188 188
 
189 189
   // Allocate each buffer that can be used by the DMA controller
190 190
   for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
@@ -194,7 +194,7 @@ int i2s_init() {
194 194
 
195 195
   // Allocate the array of DMA descriptors
196 196
   dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT);
197
-  if (dma.desc == nullptr) return -1;
197
+  if (!dma.desc) return -1;
198 198
 
199 199
   // Allocate each DMA descriptor that will be used by the DMA controller
200 200
   for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {

+ 2
- 2
Marlin/src/HAL/LINUX/eeprom.cpp Voir le fichier

@@ -40,7 +40,7 @@ size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
40 40
 bool PersistentStore::access_start() {
41 41
   const char eeprom_erase_value = 0xFF;
42 42
   FILE * eeprom_file = fopen(filename, "rb");
43
-  if (eeprom_file == nullptr) return false;
43
+  if (!eeprom_file) return false;
44 44
 
45 45
   fseek(eeprom_file, 0L, SEEK_END);
46 46
   std::size_t file_size = ftell(eeprom_file);
@@ -59,7 +59,7 @@ bool PersistentStore::access_start() {
59 59
 
60 60
 bool PersistentStore::access_finish() {
61 61
   FILE * eeprom_file = fopen(filename, "wb");
62
-  if (eeprom_file == nullptr) return false;
62
+  if (!eeprom_file) return false;
63 63
   fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file);
64 64
   fclose(eeprom_file);
65 65
   return true;

+ 6
- 6
Marlin/src/HAL/LINUX/hardware/Gpio.h Voir le fichier

@@ -86,10 +86,10 @@ public:
86 86
     GpioEvent::Type evt_type = value > 1 ? GpioEvent::SET_VALUE : value > pin_map[pin].value ? GpioEvent::RISE : value < pin_map[pin].value ? GpioEvent::FALL : GpioEvent::NOP;
87 87
     pin_map[pin].value = value;
88 88
     GpioEvent evt(Clock::nanos(), pin, evt_type);
89
-    if (pin_map[pin].cb != nullptr) {
89
+    if (pin_map[pin].cb) {
90 90
       pin_map[pin].cb->interrupt(evt);
91 91
     }
92
-    if (Gpio::logger != nullptr) Gpio::logger->log(evt);
92
+    if (Gpio::logger) Gpio::logger->log(evt);
93 93
   }
94 94
 
95 95
   static uint16_t get(pin_type pin) {
@@ -105,8 +105,8 @@ public:
105 105
     if (!valid_pin(pin)) return;
106 106
     pin_map[pin].mode = value;
107 107
     GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM);
108
-    if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt);
109
-    if (Gpio::logger != nullptr) Gpio::logger->log(evt);
108
+    if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt);
109
+    if (Gpio::logger) Gpio::logger->log(evt);
110 110
   }
111 111
 
112 112
   static uint8_t getMode(pin_type pin) {
@@ -118,8 +118,8 @@ public:
118 118
     if (!valid_pin(pin)) return;
119 119
     pin_map[pin].dir = value;
120 120
     GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD);
121
-    if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt);
122
-    if (Gpio::logger != nullptr) Gpio::logger->log(evt);
121
+    if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt);
122
+    if (Gpio::logger) Gpio::logger->log(evt);
123 123
   }
124 124
 
125 125
   static uint8_t getDir(pin_type pin) {

+ 2
- 2
Marlin/src/HAL/SAMD51/HAL.cpp Voir le fichier

@@ -300,7 +300,7 @@ uint16_t HAL_adc_result;
300 300
           DMA_ADDRESS_INCREMENT_STEP_SIZE_1,  // STEPSIZE
301 301
           DMA_STEPSEL_SRC                     // STEPSEL
302 302
         );
303
-        if (descriptor != nullptr)
303
+        if (descriptor)
304 304
           descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
305 305
         adc0DMAProgram.startJob();
306 306
       }
@@ -337,7 +337,7 @@ uint16_t HAL_adc_result;
337 337
           DMA_ADDRESS_INCREMENT_STEP_SIZE_1,  // STEPSIZE
338 338
           DMA_STEPSEL_SRC                     // STEPSEL
339 339
         );
340
-        if (descriptor != nullptr)
340
+        if (descriptor)
341 341
           descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
342 342
         adc1DMAProgram.startJob();
343 343
       }

+ 2
- 2
Marlin/src/HAL/SAMD51/QSPIFlash.cpp Voir le fichier

@@ -35,10 +35,10 @@ uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE];
35 35
 uint32_t QSPIFlash::_addr = INVALID_ADDR;
36 36
 
37 37
 void QSPIFlash::begin() {
38
-  if (_flashBase != nullptr) return;
38
+  if (_flashBase) return;
39 39
 
40 40
   _flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI());
41
-  _flashBase->begin(NULL);
41
+  _flashBase->begin(nullptr);
42 42
 }
43 43
 
44 44
 size_t QSPIFlash::size() {

+ 1
- 1
Marlin/src/HAL/STM32/tft/xpt2046.cpp Voir le fichier

@@ -99,7 +99,7 @@ void XPT2046::Init() {
99 99
     #endif
100 100
   }
101 101
   else {
102
-    SPIx.Instance = NULL;
102
+    SPIx.Instance = nullptr;
103 103
     SET_INPUT(TOUCH_MISO_PIN);
104 104
     SET_OUTPUT(TOUCH_MOSI_PIN);
105 105
     SET_OUTPUT(TOUCH_SCK_PIN);

+ 1
- 1
Marlin/src/HAL/STM32/timers.cpp Voir le fichier

@@ -109,7 +109,7 @@
109 109
 // Private Variables
110 110
 // ------------------------
111 111
 
112
-HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL };
112
+HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { nullptr };
113 113
 
114 114
 // ------------------------
115 115
 // Public functions

+ 1
- 1
Marlin/src/HAL/STM32F1/HAL.h Voir le fichier

@@ -124,7 +124,7 @@ void HAL_idletask();
124 124
 #endif
125 125
 
126 126
 #ifndef digitalPinHasPWM
127
-  #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
127
+  #define digitalPinHasPWM(P) !!PIN_MAP[P].timer_device
128 128
   #define NO_COMPILE_TIME_PWM
129 129
 #endif
130 130
 

+ 1
- 1
Marlin/src/HAL/STM32F1/SPI.cpp Voir le fichier

@@ -656,7 +656,7 @@ static const spi_pins* dev_to_spi_pins(spi_dev *dev) {
656 656
     #if BOARD_NR_SPI >= 3
657 657
       case RCC_SPI3: return board_spi_pins + 2;
658 658
     #endif
659
-    default: return NULL;
659
+    default: return nullptr;
660 660
   }
661 661
 }
662 662
 

+ 1
- 1
Marlin/src/HAL/STM32F1/fastio.h Voir le fichier

@@ -51,7 +51,7 @@
51 51
 #define IS_INPUT(IO)            (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
52 52
 #define IS_OUTPUT(IO)           (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)
53 53
 
54
-#define PWM_PIN(IO)             (PIN_MAP[IO].timer_device != nullptr)
54
+#define PWM_PIN(IO)             !!PIN_MAP[IO].timer_device
55 55
 
56 56
 // digitalRead/Write wrappers
57 57
 #define extDigitalRead(IO)      digitalRead(IO)

+ 1
- 1
Marlin/src/gcode/parser.h Voir le fichier

@@ -245,7 +245,7 @@ public:
245 245
   #endif
246 246
 
247 247
   // The code value pointer was set
248
-  FORCE_INLINE static bool has_value() { return value_ptr != nullptr; }
248
+  FORCE_INLINE static bool has_value() { return !!value_ptr; }
249 249
 
250 250
   // Seen a parameter with a value
251 251
   static inline bool seenval(const char c) { return seen(c) && has_value(); }

+ 2
- 2
Marlin/src/gcode/queue.cpp Voir le fichier

@@ -180,7 +180,7 @@ bool GCodeQueue::enqueue_one(const char* cmd) {
180 180
  * Return 'true' if any commands were processed.
181 181
  */
182 182
 bool GCodeQueue::process_injected_command_P() {
183
-  if (injected_commands_P == nullptr) return false;
183
+  if (!injected_commands_P) return false;
184 184
 
185 185
   char c;
186 186
   size_t i = 0;
@@ -480,7 +480,7 @@ void GCodeQueue::get_serial_commands() {
480 480
 
481 481
         if (npos) {
482 482
 
483
-          bool M110 = strstr_P(command, PSTR("M110")) != nullptr;
483
+          const bool M110 = !!strstr_P(command, PSTR("M110"));
484 484
 
485 485
           if (M110) {
486 486
             char* n2pos = strchr(command + 4, 'N');

+ 1
- 1
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp Voir le fichier

@@ -1036,7 +1036,7 @@ void MarlinUI::draw_status_screen() {
1036 1036
   void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
1037 1037
     ui.encoder_direction_normal();
1038 1038
     uint8_t n = lcd_put_u8str_ind_P(0, 1, pstr, itemIndex, itemString, LCD_WIDTH - 1);
1039
-    if (value != nullptr) {
1039
+    if (value) {
1040 1040
       lcd_put_wchar(':'); n--;
1041 1041
       const uint8_t len = utf8_strlen(value) + 1;   // Plus one for a leading space
1042 1042
       const lcd_uint_t valrow = n < len ? 2 : 1;    // Value on the next row if it won't fit

+ 1
- 1
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp Voir le fichier

@@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() {
863 863
     lcd.setCursor(0, MIDDLE_Y);
864 864
     lcd.write(COLOR_EDIT);
865 865
     lcd_put_u8str_P(pstr);
866
-    if (value != nullptr) {
866
+    if (value) {
867 867
       lcd.write(':');
868 868
       lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y);  // Right-justified, padded by spaces
869 869
       lcd.write(' ');     // Overwrite char if value gets shorter

+ 1
- 1
Marlin/src/lcd/dogm/marlinui_DOGM.cpp Voir le fichier

@@ -423,7 +423,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
423 423
     if (onpage) lcd_put_u8str_ind_P(0, baseline, pstr, itemIndex, itemString);
424 424
 
425 425
     // If a value is included, print a colon, then print the value right-justified
426
-    if (value != nullptr) {
426
+    if (value) {
427 427
       lcd_put_wchar(':');
428 428
       if (extra_row) {
429 429
         // Assume that value is numeric (with no descender)

+ 1
- 1
Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp Voir le fichier

@@ -346,7 +346,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
346 346
 
347 347
   switch (msg) {
348 348
     case U8G_DEV_MSG_INIT:
349
-      dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL);
349
+      dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr);
350 350
       tftio.Init();
351 351
       tftio.InitTFT();
352 352
 

+ 1
- 1
Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp Voir le fichier

@@ -294,7 +294,7 @@ namespace Anycubic {
294 294
   }
295 295
 
296 296
   void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) {
297
-    if (str != nullptr) {
297
+    if (str) {
298 298
       #if ACDEBUG(AC_SOME)
299 299
         SERIAL_ECHOPGM("> ");
300 300
       #endif

+ 6
- 7
Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp Voir le fichier

@@ -218,12 +218,12 @@ void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) {
218 218
 }
219 219
 
220 220
 float AnycubicTFTClass::CodeValue() {
221
-  return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], NULL));
221
+  return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], nullptr));
222 222
 }
223 223
 
224 224
 bool AnycubicTFTClass::CodeSeen(char code) {
225 225
   TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code);
226
-  return (TFTstrchr_pointer != NULL); // Return True if a character was found
226
+  return !!TFTstrchr_pointer; // Return True if a character was found
227 227
 }
228 228
 
229 229
 bool AnycubicTFTClass::IsNozzleHomed() {
@@ -536,7 +536,7 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
536 536
 }
537 537
 
538 538
 void AnycubicTFTClass::GetCommandFromTFT() {
539
-  char *starpos = NULL;
539
+  char *starpos = nullptr;
540 540
   while (LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
541 541
     serial3_char = LCD_SERIAL.read();
542 542
     if (serial3_char == '\n' ||
@@ -549,10 +549,10 @@ void AnycubicTFTClass::GetCommandFromTFT() {
549 549
 
550 550
       TFTcmdbuffer[TFTbufindw][serial3_count] = 0; // terminate string
551 551
 
552
-      if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) {
552
+      if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != nullptr)) {
553 553
         int16_t a_command;
554 554
         TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A');
555
-        a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL))));
555
+        a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], nullptr))));
556 556
 
557 557
         #if ENABLED(ANYCUBIC_LCD_DEBUG)
558 558
           if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please!
@@ -682,8 +682,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
682 682
                 else {
683 683
                   SelectedDirectory[0] = 0;
684 684
 
685
-                  if (starpos != NULL)
686
-                    *(starpos - 1) = '\0';
685
+                  if (starpos) *(starpos - 1) = '\0';
687 686
 
688 687
                   strcpy(SelectedFile, TFTstrchr_pointer + 4);
689 688
                   SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected

+ 3
- 3
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp Voir le fichier

@@ -146,9 +146,9 @@
146 146
   uint16_t FTDI::get_utf8_char_width(utf8_char_t c, font_size_t fs) {
147 147
     int x = 0, y = 0;
148 148
     #ifdef TOUCH_UI_UTF8_WESTERN_CHARSET
149
-      WesternCharSet::render_glyph(NULL, x, y, fs, c) ||
149
+      WesternCharSet::render_glyph(nullptr, x, y, fs, c) ||
150 150
     #endif
151
-      StandardCharSet::render_glyph(NULL, x, y, fs, c);
151
+      StandardCharSet::render_glyph(nullptr, x, y, fs, c);
152 152
     return x;
153 153
   }
154 154
 
@@ -165,7 +165,7 @@
165 165
     */
166 166
 
167 167
   uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs) {
168
-    return render_utf8_text(NULL, 0, 0, str, fs);
168
+    return render_utf8_text(nullptr, 0, 0, str, fs);
169 169
   }
170 170
 
171 171
   uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) {

+ 6
- 6
Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp Voir le fichier

@@ -110,7 +110,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
110 110
       draw_return_ui();
111 111
     }
112 112
     else {
113
-      lv_kb_set_ta(kb, nullptr); /*De-assign the text area  to hide it cursor if needed*/
113
+      lv_kb_set_ta(kb, nullptr); // De-assign the text area  to hide it cursor if needed
114 114
       lv_obj_del(kb);
115 115
       return;
116 116
     }
@@ -174,7 +174,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
174 174
   return;
175 175
   }
176 176
 
177
-  /*Add the characters to the text area if set*/
177
+  // Add the characters to the text area if set
178 178
   if (!ext->ta) return;
179 179
 
180 180
   if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0)
@@ -214,7 +214,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
214 214
 void lv_draw_keyboard() {
215 215
   scr = lv_screen_create(KEY_BOARD_UI, "");
216 216
 
217
-  /*Create styles for the keyboard*/
217
+  // Create styles for the keyboard
218 218
   static lv_style_t rel_style, pr_style;
219 219
 
220 220
   lv_style_copy(&rel_style, &lv_style_btn_rel);
@@ -229,7 +229,7 @@ void lv_draw_keyboard() {
229 229
   pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15);
230 230
   pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C);
231 231
 
232
-  /*Create a keyboard and apply the styles*/
232
+  // Create a keyboard and apply the styles
233 233
   lv_obj_t *kb = lv_kb_create(scr, nullptr);
234 234
   lv_obj_set_event_cb(kb, lv_kb_event_cb);
235 235
   lv_kb_set_cursor_manage(kb, true);
@@ -243,7 +243,7 @@ void lv_draw_keyboard() {
243 243
     }
244 244
   #endif
245 245
 
246
-  /*Create a text area. The keyboard will write here*/
246
+  // Create a text area. The keyboard will write here
247 247
   lv_obj_t *ta = lv_ta_create(scr, nullptr);
248 248
   lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10);
249 249
   if (keyboard_value == gcodeCommand) {
@@ -255,7 +255,7 @@ void lv_draw_keyboard() {
255 255
     lv_ta_set_text(ta, "");
256 256
   }
257 257
 
258
-  /*Assign the text area to the keyboard*/
258
+  // Assign the text area to the keyboard
259 259
   lv_kb_set_ta(kb, ta);
260 260
 }
261 261
 

+ 1
- 1
Marlin/src/lcd/menu/menu.cpp Voir le fichier

@@ -129,7 +129,7 @@ void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) {
129 129
   if (ui.should_draw())
130 130
     draw_edit_screen(strfunc(ui.encoderPosition + minEditValue));
131 131
   if (ui.lcd_clicked || (liveEdit && ui.should_draw())) {
132
-    if (editValue != nullptr) loadfunc(editValue, ui.encoderPosition + minEditValue);
132
+    if (editValue) loadfunc(editValue, ui.encoderPosition + minEditValue);
133 133
     if (callbackFunc && (liveEdit || ui.lcd_clicked)) (*callbackFunc)();
134 134
     if (ui.use_click()) ui.goto_previous_screen();
135 135
   }

+ 1
- 1
Marlin/src/lcd/tft/canvas.cpp Voir le fichier

@@ -79,7 +79,7 @@ void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, ui
79 79
 
80 80
 void CANVAS::AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors) {
81 81
   uint16_t *data = (uint16_t *)Images[image].data;
82
-  if (data == NULL) return;
82
+  if (!data) return;
83 83
 
84 84
   uint16_t image_width = Images[image].width,
85 85
            image_height = Images[image].height;

+ 1
- 1
Marlin/src/lcd/tft/tft_image.cpp Voir le fichier

@@ -23,7 +23,7 @@
23 23
 #include "tft_image.h"
24 24
 #include <stddef.h>
25 25
 
26
-const tImage NoLogo                 = { (void *)NULL, 0, 0, NOCOLORS };
26
+const tImage NoLogo                 = { nullptr, 0, 0, NOCOLORS };
27 27
 
28 28
 const tImage MarlinLogo112x38x1     = { (void *)marlin_logo_112x38x1, 112, 38, GREYSCALE1 };
29 29
 const tImage MarlinLogo228x255x2    = { (void *)marlin_logo_228x255x2, 228, 255, GREYSCALE2 };

+ 10
- 10
Marlin/src/lcd/tft/tft_queue.cpp Voir le fichier

@@ -30,19 +30,19 @@
30 30
 
31 31
 uint8_t TFT_Queue::queue[];
32 32
 uint8_t *TFT_Queue::end_of_queue = queue;
33
-uint8_t *TFT_Queue::current_task = NULL;
34
-uint8_t *TFT_Queue::last_task = NULL;
33
+uint8_t *TFT_Queue::current_task = nullptr;
34
+uint8_t *TFT_Queue::last_task = nullptr;
35 35
 
36 36
 void TFT_Queue::reset() {
37 37
   tft.abort();
38 38
 
39 39
   end_of_queue = queue;
40
-  current_task = NULL;
41
-  last_task = NULL;
40
+  current_task = nullptr;
41
+  last_task = nullptr;
42 42
 }
43 43
 
44 44
 void TFT_Queue::async() {
45
-  if (current_task == NULL) return;
45
+  if (!current_task) return;
46 46
   queueTask_t *task = (queueTask_t *)current_task;
47 47
 
48 48
   // Check IO busy status
@@ -63,7 +63,7 @@ void TFT_Queue::async() {
63 63
 }
64 64
 
65 65
 void TFT_Queue::finish_sketch() {
66
-  if (last_task == NULL) return;
66
+  if (!last_task) return;
67 67
   queueTask_t *task = (queueTask_t *)last_task;
68 68
 
69 69
   if (task->state == TASK_STATE_SKETCH) {
@@ -71,7 +71,7 @@ void TFT_Queue::finish_sketch() {
71 71
     task->nextTask = end_of_queue;
72 72
     task->state = TASK_STATE_READY;
73 73
 
74
-    if (current_task == NULL) current_task = (uint8_t *)task;
74
+    if (!current_task) current_task = (uint8_t *)task;
75 75
   }
76 76
 }
77 77
 
@@ -184,7 +184,7 @@ void TFT_Queue::fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui
184 184
   task->state = TASK_STATE_READY;
185 185
   task->type = TASK_FILL;
186 186
 
187
-  if (current_task == NULL) current_task = (uint8_t *)task;
187
+  if (!current_task) current_task = (uint8_t *)task;
188 188
 }
189 189
 
190 190
 void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
@@ -195,7 +195,7 @@ void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
195 195
 
196 196
   task->state = TASK_STATE_SKETCH;
197 197
   task->type = TASK_CANVAS;
198
-  task->nextTask = NULL;
198
+  task->nextTask = nullptr;
199 199
 
200 200
   end_of_queue += sizeof(queueTask_t);
201 201
   parametersCanvas_t *task_parameters = (parametersCanvas_t *)end_of_queue;
@@ -207,7 +207,7 @@ void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
207 207
   task_parameters->height = height;
208 208
   task_parameters->count = 0;
209 209
 
210
-  if (current_task == NULL) current_task = (uint8_t *)task;
210
+  if (!current_task) current_task = (uint8_t *)task;
211 211
 }
212 212
 
213 213
 void TFT_Queue::set_background(uint16_t color) {

+ 1
- 1
Marlin/src/lcd/tft/tft_string.cpp Voir le fichier

@@ -42,7 +42,7 @@ void TFT_String::set_font(const uint8_t *font) {
42 42
   font_header = (font_t *)font;
43 43
   uint32_t glyph;
44 44
 
45
-  for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = NULL;
45
+  for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = nullptr;
46 46
 
47 47
   DEBUG_ECHOLNPAIR("Format: ", font_header->Format);
48 48
   DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth);

+ 4
- 5
Marlin/src/lcd/tft/touch.cpp Voir le fichier

@@ -119,9 +119,8 @@ void Touch::idle() {
119 119
           NOMORE(y, current_control->y + current_control->height);
120 120
           touch(current_control);
121 121
         }
122
-        else {
123
-          current_control = NULL;
124
-        }
122
+        else
123
+          current_control = nullptr;
125 124
       }
126 125
       else {
127 126
         for (i = 0; i < controls_count; i++) {
@@ -133,7 +132,7 @@ void Touch::idle() {
133 132
         }
134 133
       }
135 134
 
136
-      if (current_control == NULL)
135
+      if (!current_control)
137 136
         touch_time = last_touch_ms;
138 137
     }
139 138
     x = _x;
@@ -141,7 +140,7 @@ void Touch::idle() {
141 140
   }
142 141
   else {
143 142
     x = y = 0;
144
-    current_control = NULL;
143
+    current_control = nullptr;
145 144
     touch_time = 0;
146 145
     touch_control_type = NONE;
147 146
     time_to_hold = 0;

+ 1
- 1
Marlin/src/lcd/tft/ui_320x240.cpp Voir le fichier

@@ -452,7 +452,7 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu
452 452
 void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
453 453
   uint16_t line = 1;
454 454
 
455
-  if (string == NULL) line++;
455
+  if (!string) line++;
456 456
 
457 457
   menu_line(line++);
458 458
   tft_string.set(pref);

+ 2
- 2
Marlin/src/lcd/tft/ui_480x320.cpp Voir le fichier

@@ -457,7 +457,7 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu
457 457
 void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
458 458
   uint16_t line = 1;
459 459
 
460
-  if (string == NULL) line++;
460
+  if (!string) line++;
461 461
 
462 462
   menu_line(line++);
463 463
   tft_string.set(pref);
@@ -945,7 +945,7 @@ static void drawBtn(int x, int y, const char* label, int32_t data, MarlinImage i
945 945
   tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
946 946
 
947 947
   // TODO: Make an add_text() taking a font arg
948
-  if (label != NULL) {
948
+  if (label) {
949 949
     tft_string.set(label);
950 950
     tft_string.trim();
951 951
     tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string);

+ 4
- 4
Marlin/src/libs/heatshrink/heatshrink_decoder.cpp Voir le fichier

@@ -89,7 +89,7 @@ heatshrink_decoder *heatshrink_decoder_alloc(uint16_t input_buffer_size, uint8_t
89 89
   size_t buffers_sz = (1 << window_sz2) + input_buffer_size;
90 90
   size_t sz = sizeof(heatshrink_decoder) + buffers_sz;
91 91
   heatshrink_decoder *hsd = HEATSHRINK_MALLOC(sz);
92
-  if (hsd == nullptr) return nullptr;
92
+  if (!hsd) return nullptr;
93 93
   hsd->input_buffer_size = input_buffer_size;
94 94
   hsd->window_sz2 = window_sz2;
95 95
   hsd->lookahead_sz2 = lookahead_sz2;
@@ -124,7 +124,7 @@ void heatshrink_decoder_reset(heatshrink_decoder *hsd) {
124 124
 /* Copy SIZE bytes into the decoder's input buffer, if it will fit. */
125 125
 HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd,
126 126
   uint8_t *in_buf, size_t size, size_t *input_size) {
127
-  if (hsd == nullptr || in_buf == nullptr || input_size == nullptr)
127
+  if (!hsd || !in_buf || !input_size)
128 128
     return HSDR_SINK_ERROR_NULL;
129 129
 
130 130
   size_t rem = HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(hsd) - hsd->input_size;
@@ -160,7 +160,7 @@ static HSD_state st_backref_count_lsb(heatshrink_decoder *hsd);
160 160
 static HSD_state st_yield_backref(heatshrink_decoder *hsd, output_info *oi);
161 161
 
162 162
 HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size) {
163
-  if (hsd == nullptr || out_buf == nullptr || output_size == nullptr)
163
+  if (!hsd || !out_buf || !output_size)
164 164
     return HSDR_POLL_ERROR_NULL;
165 165
 
166 166
   *output_size = 0;
@@ -351,7 +351,7 @@ static uint16_t get_bits(heatshrink_decoder *hsd, uint8_t count) {
351 351
 }
352 352
 
353 353
 HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd) {
354
-  if (hsd == nullptr) { return HSDR_FINISH_ERROR_NULL; }
354
+  if (!hsd) return HSDR_FINISH_ERROR_NULL;
355 355
   switch (hsd->state) {
356 356
     case HSDS_TAG_BIT:
357 357
       return hsd->input_size == 0 ? HSDR_FINISH_DONE : HSDR_FINISH_MORE;

+ 1
- 1
Marlin/src/libs/vector_3.cpp Voir le fichier

@@ -141,7 +141,7 @@ matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) {
141 141
 }
142 142
 
143 143
 void matrix_3x3::debug(PGM_P const title) {
144
-  if (title != nullptr) {
144
+  if (title) {
145 145
     serialprintPGM(title);
146 146
     SERIAL_EOL();
147 147
   }

+ 1
- 1
Marlin/src/pins/mega/pins_CNCONTROLS_11.h Voir le fichier

@@ -141,7 +141,7 @@
141 141
 // Pins for DOGM SPI LCD Support
142 142
 #define DOGLCD_A0                             26
143 143
 #define DOGLCD_CS                             24
144
-#define DOGLCD_MOSI                           -1
144
+#define DOGLCD_MOSI                           -1  // Prevent auto-define by Conditionals_post.h
145 145
 #define DOGLCD_SCK                            -1
146 146
 
147 147
 #define BTN_EN1                               23

+ 1
- 1
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h Voir le fichier

@@ -171,7 +171,7 @@
171 171
 
172 172
 // Shared FSMC Configs
173 173
 #if HAS_FSMC_TFT
174
-  #define DOGLCD_MOSI                       -1    // prevent redefine Conditionals_post.h
174
+  #define DOGLCD_MOSI                       -1    // Prevent auto-define by Conditionals_post.h
175 175
   #define DOGLCD_SCK                        -1
176 176
 
177 177
   #define FSMC_CS_PIN                       PD7   // NE4

+ 2
- 2
Marlin/src/sd/SdBaseFile.cpp Voir le fichier

@@ -21,12 +21,12 @@
21 21
  */
22 22
 
23 23
 #if __GNUC__ > 8
24
-  // The NXP platform updated GCC from 7.2.1 to 9.2.1
25
-  // and this new warning apparently can be ignored.
26 24
   #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
27 25
 #endif
28 26
 
29 27
 /**
28
+ * sd/SdBaseFile.cpp
29
+ *
30 30
  * Arduino SdFat Library
31 31
  * Copyright (c) 2009 by William Greiman
32 32
  *

+ 2
- 5
Marlin/src/sd/SdBaseFile.h Voir le fichier

@@ -22,11 +22,8 @@
22 22
 #pragma once
23 23
 
24 24
 /**
25
- * \file
26
- * \brief SdBaseFile class
27
- */
28
-
29
-/**
25
+ * sd/SdBaseFile.h
26
+ *
30 27
  * Arduino SdFat Library
31 28
  * Copyright (c) 2009 by William Greiman
32 29
  *

+ 2
- 1
Marlin/src/sd/SdFatConfig.h Voir le fichier

@@ -22,7 +22,8 @@
22 22
 #pragma once
23 23
 
24 24
 /**
25
- * SdFatConfig.h
25
+ * sd/SdFatConfig.h
26
+ *
26 27
  * Arduino SdFat Library
27 28
  * Copyright (c) 2009 by William Greiman
28 29
  *

+ 2
- 5
Marlin/src/sd/SdFatStructs.h Voir le fichier

@@ -22,11 +22,8 @@
22 22
 #pragma once
23 23
 
24 24
 /**
25
- * \file
26
- * \brief FAT file structures
27
- */
28
-
29
-/**
25
+ * sd/SdFatStructs.h
26
+ *
30 27
  * Arduino SdFat Library
31 28
  * Copyright (c) 2009 by William Greiman
32 29
  *

+ 2
- 0
Marlin/src/sd/SdFatUtil.cpp Voir le fichier

@@ -21,6 +21,8 @@
21 21
  */
22 22
 
23 23
 /**
24
+ * sd/SdFatUtil.cpp
25
+ *
24 26
  * Arduino SdFat Library
25 27
  * Copyright (c) 2008 by William Greiman
26 28
  *

+ 2
- 0
Marlin/src/sd/SdFatUtil.h Voir le fichier

@@ -22,6 +22,8 @@
22 22
 #pragma once
23 23
 
24 24
 /**
25
+ * sd/SdFatUtil.h
26
+ *
25 27
  * Arduino SdFat Library
26 28
  * Copyright (c) 2008 by William Greiman
27 29
  *

+ 2
- 0
Marlin/src/sd/SdFile.cpp Voir le fichier

@@ -21,6 +21,8 @@
21 21
  */
22 22
 
23 23
 /**
24
+ * sd/SdFile.cpp
25
+ *
24 26
  * Arduino SdFat Library
25 27
  * Copyright (c) 2009 by William Greiman
26 28
  *

+ 3
- 6
Marlin/src/sd/SdFile.h Voir le fichier

@@ -22,11 +22,8 @@
22 22
 #pragma once
23 23
 
24 24
 /**
25
- * \file
26
- * \brief SdFile class
27
- */
28
-
29
-/**
25
+ * sd/SdFile.h
26
+ *
30 27
  * Arduino SdFat Library
31 28
  * Copyright (c) 2009 by William Greiman
32 29
  *
@@ -42,7 +39,7 @@
42 39
  * \class SdFile
43 40
  * \brief SdBaseFile with Print.
44 41
  */
45
-class SdFile : public SdBaseFile/*, public Print*/ {
42
+class SdFile : public SdBaseFile {
46 43
  public:
47 44
   SdFile() {}
48 45
   SdFile(const char* name, uint8_t oflag);

+ 2
- 0
Marlin/src/sd/SdVolume.cpp Voir le fichier

@@ -21,6 +21,8 @@
21 21
  */
22 22
 
23 23
 /**
24
+ * sd/SdVolume.cpp
25
+ *
24 26
  * Arduino SdFat Library
25 27
  * Copyright (c) 2009 by William Greiman
26 28
  *

+ 2
- 5
Marlin/src/sd/SdVolume.h Voir le fichier

@@ -22,11 +22,8 @@
22 22
 #pragma once
23 23
 
24 24
 /**
25
- * \file
26
- * \brief SdVolume class
27
- */
28
-
29
-/**
25
+ * sd/SdVolume.h
26
+ *
30 27
  * Arduino SdFat Library
31 28
  * Copyright (c) 2009 by William Greiman
32 29
  *

+ 2
- 2
Marlin/src/sd/cardreader.cpp Voir le fichier

@@ -639,7 +639,7 @@ bool CardReader::fileExists(const char * const path) {
639 639
     selectByName(*diveDir, fname);
640 640
     diveDir->close();
641 641
   }
642
-  return fname != nullptr;
642
+  return !!fname;
643 643
 }
644 644
 
645 645
 //
@@ -684,7 +684,7 @@ void CardReader::write_command(char * const buf) {
684 684
   char* end = buf + strlen(buf) - 1;
685 685
 
686 686
   file.writeError = false;
687
-  if ((npos = strchr(buf, 'N')) != nullptr) {
687
+  if ((npos = strchr(buf, 'N'))) {
688 688
     begin = strchr(npos, ' ') + 1;
689 689
     end = strchr(npos, '*') - 1;
690 690
   }

+ 136
- 138
Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp Voir le fichier

@@ -22,7 +22,10 @@
22 22
  * Web      :  https://www.circuitsathome.com
23 23
  * e-mail   :  support@circuitsathome.com
24 24
  */
25
-/* USB functions */
25
+
26
+//
27
+// USB functions supporting Flash Drive
28
+//
26 29
 
27 30
 #include "../../../inc/MarlinConfigPre.h"
28 31
 
@@ -35,7 +38,7 @@ static uint8_t usb_task_state;
35 38
 
36 39
 /* constructor */
37 40
 USB::USB() : bmHubPre(0) {
38
-  usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; //set up state machine
41
+  usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; // Set up state machine
39 42
   init();
40 43
 }
41 44
 
@@ -45,13 +48,8 @@ void USB::init() {
45 48
   bmHubPre = 0;
46 49
 }
47 50
 
48
-uint8_t USB::getUsbTaskState() {
49
-  return usb_task_state;
50
-}
51
-
52
-void USB::setUsbTaskState(uint8_t state) {
53
-  usb_task_state = state;
54
-}
51
+uint8_t USB::getUsbTaskState() { return usb_task_state; }
52
+void USB::setUsbTaskState(uint8_t state) { usb_task_state = state; }
55 53
 
56 54
 EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) {
57 55
   UsbDevice *p = addrPool.GetUsbDevicePtr(addr);
@@ -70,9 +68,11 @@ EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) {
70 68
   return nullptr;
71 69
 }
72 70
 
73
-/* set device table entry */
74
-
75
-/* each device is different and has different number of endpoints. This function plugs endpoint record structure, defined in application, to devtable */
71
+/**
72
+ * Set device table entry
73
+ * Each device is different and has different number of endpoints.
74
+ * This function plugs endpoint record structure, defined in application, to devtable
75
+ */
76 76
 uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr) {
77 77
   if (!eprecord_ptr)
78 78
     return USB_ERROR_INVALID_ARGUMENT;
@@ -112,7 +112,7 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l
112 112
     USBTRACE2(" NAK Limit: ", nak_limit);
113 113
     USBTRACE("\r\n");
114 114
    */
115
-  regWr(rPERADDR, addr); //set peripheral address
115
+  regWr(rPERADDR, addr); // Set peripheral address
116 116
 
117 117
   uint8_t mode = regRd(rMODE);
118 118
 
@@ -121,8 +121,6 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l
121 121
   //Serial.print("\r\nLS: ");
122 122
   //Serial.println(p->lowspeed, HEX);
123 123
 
124
-
125
-
126 124
   // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise
127 125
   regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED));
128 126
 
@@ -133,11 +131,10 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l
133 131
 /* depending on request. Actual requests are defined as inlines                                                                                      */
134 132
 /* return codes:                */
135 133
 /* 00       =   success         */
136
-
137 134
 /* 01-0f    =   non-zero HRSLT  */
138 135
 uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
139 136
   uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p) {
140
-  bool direction = false; //request direction, IN or OUT
137
+  bool direction = false; // Request direction, IN or OUT
141 138
   uint8_t rcode;
142 139
   SETUP_PKT setup_pkt;
143 140
 
@@ -157,15 +154,15 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque
157 154
   setup_pkt.wIndex = wInd;
158 155
   setup_pkt.wLength = total;
159 156
 
160
-  bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); //transfer to setup packet FIFO
157
+  bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); // Transfer to setup packet FIFO
161 158
 
162
-  rcode = dispatchPkt(tokSETUP, ep, nak_limit); //dispatch packet
159
+  rcode = dispatchPkt(tokSETUP, ep, nak_limit); // Dispatch packet
163 160
   if (rcode) return rcode; // Return HRSLT if not zero
164 161
 
165
-  if (dataptr != nullptr) { //data stage, if present
166
-    if (direction) { //IN transfer
162
+  if (dataptr) { // Data stage, if present
163
+    if (direction) { // IN transfer
167 164
       uint16_t left = total;
168
-      pep->bmRcvToggle = 1; //bmRCVTOG1;
165
+      pep->bmRcvToggle = 1; // BmRCVTOG1;
169 166
 
170 167
       while (left) {
171 168
         // Bytes read into buffer
@@ -174,7 +171,7 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque
174 171
 
175 172
         rcode = InTransfer(pep, nak_limit, &read, dataptr);
176 173
         if (rcode == hrTOGERR) {
177
-          // yes, we flip it wrong here so that next time it is actually correct!
174
+          // Yes, we flip it wrong here so that next time it is actually correct!
178 175
           pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
179 176
           continue;
180 177
         }
@@ -189,21 +186,21 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque
189 186
         if (read < nbytes) break;
190 187
       }
191 188
     }
192
-    else { //OUT transfer
193
-      pep->bmSndToggle = 1; //bmSNDTOG1;
189
+    else { // OUT transfer
190
+      pep->bmSndToggle = 1; // BmSNDTOG1;
194 191
       rcode = OutTransfer(pep, nak_limit, nbytes, dataptr);
195 192
     }
196
-    if (rcode) return rcode; // return error
193
+    if (rcode) return rcode; // Return error
197 194
   }
198 195
   // Status stage
199
-  return dispatchPkt((direction) ? tokOUTHS : tokINHS, ep, nak_limit); //GET if direction
196
+  return dispatchPkt((direction) ? tokOUTHS : tokINHS, ep, nak_limit); // GET if direction
200 197
 }
201 198
 
202
-/* IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */
203
-/* Keep sending INs and writes data to memory area pointed by 'data'                                                           */
204
-
205
-/* rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error,
206
-      fe USB xfer timeout */
199
+/**
200
+ * IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes.
201
+ * Keep sending INs and writes data to memory area pointed by 'data'
202
+ * rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, fe = USB xfer timeout
203
+ */
207 204
 uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) {
208 205
   EpInfo *pep = nullptr;
209 206
   uint16_t nak_limit = 0;
@@ -227,29 +224,29 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
227 224
   uint8_t maxpktsize = pep->maxPktSize;
228 225
 
229 226
   *nbytesptr = 0;
230
-  regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value
227
+  regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); // Set toggle value
231 228
 
232
-  // use a 'break' to exit this loop
229
+  // Use a 'break' to exit this loop
233 230
   for (;;) {
234
-    rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS.
231
+    rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); // IN packet to EP-'endpoint'. Function takes care of NAKS.
235 232
     if (rcode == hrTOGERR) {
236
-      // yes, we flip it wrong here so that next time it is actually correct!
233
+      // Yes, we flip it wrong here so that next time it is actually correct!
237 234
       pep->bmRcvToggle = (regRd(rHRSL) & bmRCVTOGRD) ? 0 : 1;
238
-      regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value
235
+      regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); // Set toggle value
239 236
       continue;
240 237
     }
241 238
     if (rcode) {
242 239
       //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode);
243
-      break; //should be 0, indicating ACK. Else return error code.
240
+      break; // Should be 0, indicating ACK. Else return error code.
244 241
     }
245 242
     /* check for RCVDAVIRQ and generate error if not present */
246 243
     /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */
247 244
     if ((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
248 245
       //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
249
-      rcode = 0xF0; //receive error
246
+      rcode = 0xF0; // Receive error
250 247
       break;
251 248
     }
252
-    pktsize = regRd(rRCVBC); //number of received bytes
249
+    pktsize = regRd(rRCVBC); // Number of received bytes
253 250
     //printf("Got %i bytes \r\n", pktsize);
254 251
     // This would be OK, but...
255 252
     //assert(pktsize <= nbytes);
@@ -266,7 +263,7 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
266 263
     data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data);
267 264
 
268 265
     regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer
269
-    *nbytesptr += pktsize; // add this packet's byte count to total transfer length
266
+    *nbytesptr += pktsize; // Add this packet's byte count to total transfer length
270 267
 
271 268
     /* The transfer is complete under two conditions:           */
272 269
     /* 1. The device sent a short packet (L.T. maxPacketSize)   */
@@ -284,10 +281,11 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
284 281
   return rcode;
285 282
 }
286 283
 
287
-/* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */
288
-/* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer   */
289
-
290
-/* rcode 0 if no errors. rcode 01-0f is relayed from HRSL                       */
284
+/**
285
+ * OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes.
286
+ * Handles NAK bug per Maxim Application Note 4000 for single buffer transfer
287
+ * rcode 0 if no errors. rcode 01-0f is relayed from HRSL
288
+ */
291 289
 uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
292 290
   EpInfo *pep = nullptr;
293 291
   uint16_t nak_limit = 0;
@@ -300,7 +298,7 @@ uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dat
300 298
 
301 299
 uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) {
302 300
   uint8_t rcode = hrSUCCESS, retry_count;
303
-  uint8_t *data_p = data; //local copy of the data pointer
301
+  uint8_t *data_p = data; // Local copy of the data pointer
304 302
   uint16_t bytes_tosend, nak_count;
305 303
   uint16_t bytes_left = nbytes;
306 304
 
@@ -311,17 +309,17 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
311 309
 
312 310
   uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT;
313 311
 
314
-  regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
312
+  regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); // Set toggle value
315 313
 
316 314
   while (bytes_left) {
317 315
     retry_count = 0;
318 316
     nak_count = 0;
319 317
     bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
320
-    bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO
321
-    regWr(rSNDBC, bytes_tosend); //set number of bytes
322
-    regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
323
-    while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
324
-    regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
318
+    bytesWr(rSNDFIFO, bytes_tosend, data_p); // Filling output FIFO
319
+    regWr(rSNDBC, bytes_tosend); // Set number of bytes
320
+    regWr(rHXFR, (tokOUT | pep->epAddr)); // Dispatch packet
321
+    while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); // Wait for the completion IRQ
322
+    regWr(rHIRQ, bmHXFRDNIRQ); // Clear IRQ
325 323
     rcode = (regRd(rHRSL) & 0x0F);
326 324
 
327 325
     while (rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) {
@@ -330,18 +328,18 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
330 328
           nak_count++;
331 329
           if (nak_limit && (nak_count == nak_limit))
332 330
             goto breakout;
333
-          //return ( rcode);
331
+          //return rcode;
334 332
           break;
335 333
         case hrTIMEOUT:
336 334
           retry_count++;
337 335
           if (retry_count == USB_RETRY_LIMIT)
338 336
             goto breakout;
339
-          //return ( rcode);
337
+          //return rcode;
340 338
           break;
341 339
         case hrTOGERR:
342
-          // yes, we flip it wrong here so that next time it is actually correct!
340
+          // Yes, we flip it wrong here so that next time it is actually correct!
343 341
           pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
344
-          regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
342
+          regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); // Set toggle value
345 343
           break;
346 344
         default:
347 345
           goto breakout;
@@ -351,26 +349,27 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
351 349
       regWr(rSNDBC, 0);
352 350
       regWr(rSNDFIFO, *data_p);
353 351
       regWr(rSNDBC, bytes_tosend);
354
-      regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
355
-      while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
356
-      regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
352
+      regWr(rHXFR, (tokOUT | pep->epAddr)); // Dispatch packet
353
+      while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); // Wait for the completion IRQ
354
+      regWr(rHIRQ, bmHXFRDNIRQ); // Clear IRQ
357 355
       rcode = (regRd(rHRSL) & 0x0F);
358
-    } // while rcode && ....
356
+    } // While rcode && ....
359 357
     bytes_left -= bytes_tosend;
360 358
     data_p += bytes_tosend;
361
-  } // while bytes_left...
359
+  } // While bytes_left...
362 360
 breakout:
363 361
 
364
-  pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; //bmSNDTOG1 : bmSNDTOG0;  //update toggle
365
-  return ( rcode); //should be 0 in all cases
362
+  pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; // BmSNDTOG1 : bmSNDTOG0;  // Update toggle
363
+  return ( rcode); // Should be 0 in all cases
366 364
 }
367 365
 
368
-/* dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty       */
369
-/* If NAK, tries to re-send up to nak_limit times                                                   */
370
-/* If nak_limit == 0, do not count NAKs, exit after timeout                                         */
371
-/* If bus timeout, re-sends up to USB_RETRY_LIMIT times                                             */
372
-
373
-/* return codes 0x00-0x0F are HRSLT( 0x00 being success ), 0xFF means timeout                       */
366
+/**
367
+ * Dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty
368
+ * If NAK, tries to re-send up to nak_limit times
369
+ * If nak_limit == 0, do not count NAKs, exit after timeout
370
+ * If bus timeout, re-sends up to USB_RETRY_LIMIT times
371
+ * return codes 0x00-0x0F are HRSLT( 0x00 being success ), 0xFF means timeout
372
+ */
374 373
 uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
375 374
   uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT;
376 375
   uint8_t tmpdata;
@@ -380,29 +379,28 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
380 379
 
381 380
   while ((int32_t)((uint32_t)millis() - timeout) < 0L) {
382 381
     #if defined(ESP8266) || defined(ESP32)
383
-      yield(); // needed in order to reset the watchdog timer on the ESP8266
382
+      yield(); // Needed in order to reset the watchdog timer on the ESP8266
384 383
     #endif
385
-    regWr(rHXFR, (token | ep)); //launch the transfer
384
+    regWr(rHXFR, (token | ep)); // Launch the transfer
386 385
     rcode = USB_ERROR_TRANSFER_TIMEOUT;
387 386
 
388
-    while ((int32_t)((uint32_t)millis() - timeout) < 0L) { //wait for transfer completion
387
+    while ((int32_t)((uint32_t)millis() - timeout) < 0L) { // Wait for transfer completion
389 388
       #if defined(ESP8266) || defined(ESP32)
390
-        yield(); // needed to reset the watchdog timer on the ESP8266
389
+        yield(); // Needed to reset the watchdog timer on the ESP8266
391 390
       #endif
392 391
       tmpdata = regRd(rHIRQ);
393 392
 
394 393
       if (tmpdata & bmHXFRDNIRQ) {
395
-        regWr(rHIRQ, bmHXFRDNIRQ); //clear the interrupt
394
+        regWr(rHIRQ, bmHXFRDNIRQ); // Clear the interrupt
396 395
         rcode = 0x00;
397 396
         break;
398 397
       }
399 398
 
400
-    } // while millis() < timeout
399
+    } // While millis() < timeout
401 400
 
402
-    //if (rcode != 0x00) //exit if timeout
403
-    //        return ( rcode);
401
+    //if (rcode != 0x00) return rcode; // Exit if timeout
404 402
 
405
-    rcode = (regRd(rHRSL) & 0x0F); //analyze transfer result
403
+    rcode = (regRd(rHRSL) & 0x0F); // Analyze transfer result
406 404
 
407 405
     switch (rcode) {
408 406
       case hrNAK:
@@ -419,12 +417,12 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
419 417
         return (rcode);
420 418
     }
421 419
 
422
-  } // while timeout > millis()
420
+  } // While timeout > millis()
423 421
   return rcode;
424 422
 }
425 423
 
426
-/* USB main task. Performs enumeration/cleanup */
427
-void USB::Task() { //USB state machine
424
+// USB main task. Performs enumeration/cleanup
425
+void USB::Task() { // USB state machine
428 426
   uint8_t rcode;
429 427
   uint8_t tmpdata;
430 428
   static uint32_t delay = 0;
@@ -437,19 +435,19 @@ void USB::Task() { //USB state machine
437 435
 
438 436
   /* modify USB task state if Vbus changed */
439 437
   switch (tmpdata) {
440
-    case SE1: //illegal state
438
+    case SE1: // Illegal state
441 439
       usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL;
442 440
       lowspeed = false;
443 441
       break;
444
-    case SE0: //disconnected
442
+    case SE0: // Disconnected
445 443
       if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED)
446 444
         usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE;
447 445
       lowspeed = false;
448 446
       break;
449 447
     case LSHOST:
450 448
       lowspeed = true;
451
-      //intentional fallthrough
452
-    case FSHOST: //attached
449
+      // Intentional fallthrough
450
+    case FSHOST: // Attached
453 451
       if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
454 452
         delay = (uint32_t)millis() + USB_SETTLE_DELAY;
455 453
         usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE;
@@ -470,31 +468,31 @@ void USB::Task() { //USB state machine
470 468
 
471 469
       usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE;
472 470
       break;
473
-    case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: //just sit here
471
+    case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: // Just sit here
474 472
       break;
475
-    case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
473
+    case USB_DETACHED_SUBSTATE_ILLEGAL: // Just sit here
476 474
       break;
477
-    case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device
475
+    case USB_ATTACHED_SUBSTATE_SETTLE: // Settle time for just attached device
478 476
       if ((int32_t)((uint32_t)millis() - delay) >= 0L)
479 477
         usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
480
-      else break; // don't fall through
478
+      else break; // Don't fall through
481 479
     case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
482
-      regWr(rHCTL, bmBUSRST); //issue bus reset
480
+      regWr(rHCTL, bmBUSRST); // Issue bus reset
483 481
       usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE;
484 482
       break;
485 483
     case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE:
486 484
       if ((regRd(rHCTL) & bmBUSRST) == 0) {
487
-        tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation
485
+        tmpdata = regRd(rMODE) | bmSOFKAENAB; // Start SOF generation
488 486
         regWr(rMODE, tmpdata);
489 487
         usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF;
490
-        //delay = (uint32_t)millis() + 20; //20ms wait after reset per USB spec
488
+        //delay = (uint32_t)millis() + 20; // 20ms wait after reset per USB spec
491 489
       }
492 490
       break;
493
-    case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order
491
+    case USB_ATTACHED_SUBSTATE_WAIT_SOF: // Todo: change check order
494 492
       if (regRd(rHIRQ) & bmFRAMEIRQ) {
495
-        //when first SOF received _and_ 20ms has passed we can continue
493
+        // When first SOF received _and_ 20ms has passed we can continue
496 494
         /*
497
-          if (delay < (uint32_t)millis()) //20ms passed
495
+          if (delay < (uint32_t)millis()) // 20ms passed
498 496
             usb_task_state = USB_STATE_CONFIGURING;
499 497
         */
500 498
         usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
@@ -503,7 +501,7 @@ void USB::Task() { //USB state machine
503 501
       break;
504 502
     case USB_ATTACHED_SUBSTATE_WAIT_RESET:
505 503
       if ((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING;
506
-      else break; // don't fall through
504
+      else break; // Don't fall through
507 505
     case USB_STATE_CONFIGURING:
508 506
 
509 507
       //Serial.print("\r\nConf.LS: ");
@@ -565,11 +563,11 @@ again:
565 563
   if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) {
566 564
     if (parent == 0) {
567 565
       // Send a bus reset on the root interface.
568
-      regWr(rHCTL, bmBUSRST); //issue bus reset
569
-      delay(102); // delay 102ms, compensate for clock inaccuracy.
566
+      regWr(rHCTL, bmBUSRST); // Issue bus reset
567
+      delay(102); // Delay 102ms, compensate for clock inaccuracy.
570 568
     }
571 569
     else {
572
-      // reset parent port
570
+      // Reset parent port
573 571
       devConfig[parent]->ResetHubPort(port);
574 572
     }
575 573
   }
@@ -592,11 +590,11 @@ again:
592 590
     // Issue a bus reset, because the device may be in a limbo state
593 591
     if (parent == 0) {
594 592
       // Send a bus reset on the root interface.
595
-      regWr(rHCTL, bmBUSRST); //issue bus reset
596
-      delay(102); // delay 102ms, compensate for clock inaccuracy.
593
+      regWr(rHCTL, bmBUSRST); // Issue bus reset
594
+      delay(102); // Delay 102ms, compensate for clock inaccuracy.
597 595
     }
598 596
     else {
599
-      // reset parent port
597
+      // Reset parent port
600 598
       devConfig[parent]->ResetHubPort(port);
601 599
     }
602 600
   }
@@ -623,19 +621,19 @@ again:
623 621
  * 4: set address
624 622
  * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail
625 623
  * 6: while (configurations) {
626
- *              for (each configuration) {
627
- *                      for (each driver) {
628
- *                              6a: Ask device if it likes configuration. Returns 0 on OK.
629
- *                                      If successful, the driver configured device.
630
- *                                      The driver now owns the endpoints, and takes over managing them.
631
- *                                      The following will need codes:
632
- *                                          Everything went well, instance consumed, exit with success.
633
- *                                          Instance already in use, ignore it, try next driver.
634
- *                                          Not a supported device, ignore it, try next driver.
635
- *                                          Not a supported configuration for this device, ignore it, try next driver.
636
- *                                          Could not configure device, fatal, exit with fail.
637
- *                      }
638
- *              }
624
+ *      for (each configuration) {
625
+ *        for (each driver) {
626
+ *           6a: Ask device if it likes configuration. Returns 0 on OK.
627
+ *             If successful, the driver configured device.
628
+ *             The driver now owns the endpoints, and takes over managing them.
629
+ *             The following will need codes:
630
+ *                 Everything went well, instance consumed, exit with success.
631
+ *                 Instance already in use, ignore it, try next driver.
632
+ *                 Not a supported device, ignore it, try next driver.
633
+ *                 Not a supported configuration for this device, ignore it, try next driver.
634
+ *                 Could not configure device, fatal, exit with fail.
635
+ *        }
636
+ *      }
639 637
  *    }
640 638
  * 7: for (each driver) {
641 639
  *      7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID
@@ -671,7 +669,7 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
671 669
   oldep_ptr = p->epinfo;
672 670
 
673 671
   // Temporary assign new pointer to epInfo to p->epinfo in order to
674
-  // avoid toggle inconsistence
672
+  // Avoid toggle inconsistence
675 673
 
676 674
   p->epinfo = &epInfo;
677 675
 
@@ -687,7 +685,7 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
687 685
     return rcode;
688 686
   }
689 687
 
690
-  // to-do?
688
+  // To-do?
691 689
   // Allocate new address according to device class
692 690
   //bAddress = addrPool.AllocAddress(parent, false, port);
693 691
 
@@ -698,11 +696,11 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
698 696
   // Qualify with subclass too.
699 697
   //
700 698
   // VID/PID & class tests default to false for drivers not yet ported
701
-  // subclass defaults to true, so you don't have to define it if you don't have to.
699
+  // Subclass defaults to true, so you don't have to define it if you don't have to.
702 700
   //
703 701
   for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
704
-    if (!devConfig[devConfigIndex]) continue; // no driver
705
-    if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed
702
+    if (!devConfig[devConfigIndex]) continue; // No driver
703
+    if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed
706 704
     if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) {
707 705
       rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
708 706
       if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED)
@@ -712,20 +710,20 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
712 710
 
713 711
   if (devConfigIndex < USB_NUMDEVICES) return rcode;
714 712
 
715
-  // blindly attempt to configure
713
+  // Blindly attempt to configure
716 714
   for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
717 715
     if (!devConfig[devConfigIndex]) continue;
718
-    if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed
716
+    if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed
719 717
     if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) continue; // If this is true it means it must have returned USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED above
720 718
     rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
721 719
 
722 720
     //printf("ERROR ENUMERATING %2.2x\r\n", rcode);
723 721
     if (!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) {
724
-      // in case of an error dev_index should be reset to 0
725
-      //                in order to start from the very beginning the
726
-      //                next time the program gets here
722
+      // In case of an error dev_index should be reset to 0
723
+      // in order to start from the very beginning the
724
+      // next time the program gets here
727 725
       //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE)
728
-      //        devConfigIndex = 0;
726
+      //devConfigIndex = 0;
729 727
       return rcode;
730 728
     }
731 729
   }
@@ -744,20 +742,22 @@ uint8_t USB::ReleaseDevice(uint8_t addr) {
744 742
   return 0;
745 743
 }
746 744
 
747
-#if 1 //!defined(USB_METHODS_INLINE)
748
-//get device descriptor
749
-
745
+// Get device descriptor
750 746
 uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
751 747
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, nullptr);
752 748
 }
753
-//get configuration descriptor
754 749
 
750
+// Get configuration descriptor
755 751
 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
756 752
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, nullptr);
757 753
 }
758 754
 
759
-/* Requests Configuration Descriptor. Sends two Get Conf Descr requests. The first one gets the total length of all descriptors, then the second one requests this
760
- total length. The length of the first request can be shorter ( 4 bytes ), however, there are devices which won't work unless this length is set to 9 */
755
+/**
756
+ * Requests Configuration Descriptor. Sends two Get Conf Descr requests.
757
+ * The first one gets the total length of all descriptors, then the second one requests this
758
+ * total length. The length of the first request can be shorter (4 bytes), however, there are
759
+ * devices which won't work unless this length is set to 9.
760
+ */
761 761
 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) {
762 762
   const uint8_t bufSize = 64;
763 763
   uint8_t buf[bufSize];
@@ -773,25 +773,23 @@ uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser
773 773
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p);
774 774
 }
775 775
 
776
-//get string descriptor
777
-
776
+// Get string descriptor
778 777
 uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) {
779 778
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, ns, ns, dataptr, nullptr);
780 779
 }
781
-//set address
782 780
 
781
+// Set address
783 782
 uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
784 783
   uint8_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr);
785
-  //delay(2); //per USB 2.0 sect.9.2.6.3
784
+  //delay(2); // Per USB 2.0 sect.9.2.6.3
786 785
   delay(300); // Older spec says you should wait at least 200ms
787 786
   return rcode;
788 787
   //return ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr);
789 788
 }
790
-//set configuration
791 789
 
790
+// Set configuration
792 791
 uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
793 792
   return ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr);
794 793
 }
795 794
 
796
-#endif // defined(USB_METHODS_INLINE)
797 795
 #endif // USB_FLASH_DRIVE_SUPPORT

Chargement…
Annuler
Enregistrer