Browse Source

Clean up comments, USB flash, NULLs

Scott Lahteine 4 years ago
parent
commit
ec23e37a4a
45 changed files with 231 additions and 238 deletions
  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 View File

84
     card.getSd2Card().readData(sector_buf);
84
     card.getSd2Card().readData(sector_buf);
85
 
85
 
86
     // RAM -> USB
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
       card.getSd2Card().readStop();
88
       card.getSd2Card().readStop();
89
       return CTRL_FAIL;
89
       return CTRL_FAIL;
90
     }
90
     }
120
   while (nb_sector--) {
120
   while (nb_sector--) {
121
 
121
 
122
     // USB -> RAM
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
       card.getSd2Card().writeStop();
124
       card.getSd2Card().writeStop();
125
       return CTRL_FAIL;
125
       return CTRL_FAIL;
126
     }
126
     }

+ 2
- 2
Marlin/src/HAL/ESP32/i2s.cpp View File

184
 
184
 
185
   // Allocate the array of pointers to the buffers
185
   // Allocate the array of pointers to the buffers
186
   dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT);
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
   // Allocate each buffer that can be used by the DMA controller
189
   // Allocate each buffer that can be used by the DMA controller
190
   for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
190
   for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
194
 
194
 
195
   // Allocate the array of DMA descriptors
195
   // Allocate the array of DMA descriptors
196
   dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT);
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
   // Allocate each DMA descriptor that will be used by the DMA controller
199
   // Allocate each DMA descriptor that will be used by the DMA controller
200
   for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
200
   for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {

+ 2
- 2
Marlin/src/HAL/LINUX/eeprom.cpp View File

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

+ 6
- 6
Marlin/src/HAL/LINUX/hardware/Gpio.h View File

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;
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
     pin_map[pin].value = value;
87
     pin_map[pin].value = value;
88
     GpioEvent evt(Clock::nanos(), pin, evt_type);
88
     GpioEvent evt(Clock::nanos(), pin, evt_type);
89
-    if (pin_map[pin].cb != nullptr) {
89
+    if (pin_map[pin].cb) {
90
       pin_map[pin].cb->interrupt(evt);
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
   static uint16_t get(pin_type pin) {
95
   static uint16_t get(pin_type pin) {
105
     if (!valid_pin(pin)) return;
105
     if (!valid_pin(pin)) return;
106
     pin_map[pin].mode = value;
106
     pin_map[pin].mode = value;
107
     GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM);
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
   static uint8_t getMode(pin_type pin) {
112
   static uint8_t getMode(pin_type pin) {
118
     if (!valid_pin(pin)) return;
118
     if (!valid_pin(pin)) return;
119
     pin_map[pin].dir = value;
119
     pin_map[pin].dir = value;
120
     GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD);
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
   static uint8_t getDir(pin_type pin) {
125
   static uint8_t getDir(pin_type pin) {

+ 2
- 2
Marlin/src/HAL/SAMD51/HAL.cpp View File

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

+ 2
- 2
Marlin/src/HAL/SAMD51/QSPIFlash.cpp View File

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

+ 1
- 1
Marlin/src/HAL/STM32/tft/xpt2046.cpp View File

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

+ 1
- 1
Marlin/src/HAL/STM32/timers.cpp View File

109
 // Private Variables
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
 // Public functions
115
 // Public functions

+ 1
- 1
Marlin/src/HAL/STM32F1/HAL.h View File

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

+ 1
- 1
Marlin/src/HAL/STM32F1/SPI.cpp View File

656
     #if BOARD_NR_SPI >= 3
656
     #if BOARD_NR_SPI >= 3
657
       case RCC_SPI3: return board_spi_pins + 2;
657
       case RCC_SPI3: return board_spi_pins + 2;
658
     #endif
658
     #endif
659
-    default: return NULL;
659
+    default: return nullptr;
660
   }
660
   }
661
 }
661
 }
662
 
662
 

+ 1
- 1
Marlin/src/HAL/STM32F1/fastio.h View File

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)
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
 #define IS_OUTPUT(IO)           (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)
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
 // digitalRead/Write wrappers
56
 // digitalRead/Write wrappers
57
 #define extDigitalRead(IO)      digitalRead(IO)
57
 #define extDigitalRead(IO)      digitalRead(IO)

+ 1
- 1
Marlin/src/gcode/parser.h View File

245
   #endif
245
   #endif
246
 
246
 
247
   // The code value pointer was set
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
   // Seen a parameter with a value
250
   // Seen a parameter with a value
251
   static inline bool seenval(const char c) { return seen(c) && has_value(); }
251
   static inline bool seenval(const char c) { return seen(c) && has_value(); }

+ 2
- 2
Marlin/src/gcode/queue.cpp View File

180
  * Return 'true' if any commands were processed.
180
  * Return 'true' if any commands were processed.
181
  */
181
  */
182
 bool GCodeQueue::process_injected_command_P() {
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
   char c;
185
   char c;
186
   size_t i = 0;
186
   size_t i = 0;
480
 
480
 
481
         if (npos) {
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
           if (M110) {
485
           if (M110) {
486
             char* n2pos = strchr(command + 4, 'N');
486
             char* n2pos = strchr(command + 4, 'N');

+ 1
- 1
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp View File

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

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

+ 1
- 1
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

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

+ 1
- 1
Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp View File

346
 
346
 
347
   switch (msg) {
347
   switch (msg) {
348
     case U8G_DEV_MSG_INIT:
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
       tftio.Init();
350
       tftio.Init();
351
       tftio.InitTFT();
351
       tftio.InitTFT();
352
 
352
 

+ 1
- 1
Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp View File

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

+ 6
- 7
Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp View File

218
 }
218
 }
219
 
219
 
220
 float AnycubicTFTClass::CodeValue() {
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
 bool AnycubicTFTClass::CodeSeen(char code) {
224
 bool AnycubicTFTClass::CodeSeen(char code) {
225
   TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code);
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
 bool AnycubicTFTClass::IsNozzleHomed() {
229
 bool AnycubicTFTClass::IsNozzleHomed() {
536
 }
536
 }
537
 
537
 
538
 void AnycubicTFTClass::GetCommandFromTFT() {
538
 void AnycubicTFTClass::GetCommandFromTFT() {
539
-  char *starpos = NULL;
539
+  char *starpos = nullptr;
540
   while (LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
540
   while (LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
541
     serial3_char = LCD_SERIAL.read();
541
     serial3_char = LCD_SERIAL.read();
542
     if (serial3_char == '\n' ||
542
     if (serial3_char == '\n' ||
549
 
549
 
550
       TFTcmdbuffer[TFTbufindw][serial3_count] = 0; // terminate string
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
         int16_t a_command;
553
         int16_t a_command;
554
         TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A');
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
         #if ENABLED(ANYCUBIC_LCD_DEBUG)
557
         #if ENABLED(ANYCUBIC_LCD_DEBUG)
558
           if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please!
558
           if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please!
682
                 else {
682
                 else {
683
                   SelectedDirectory[0] = 0;
683
                   SelectedDirectory[0] = 0;
684
 
684
 
685
-                  if (starpos != NULL)
686
-                    *(starpos - 1) = '\0';
685
+                  if (starpos) *(starpos - 1) = '\0';
687
 
686
 
688
                   strcpy(SelectedFile, TFTstrchr_pointer + 4);
687
                   strcpy(SelectedFile, TFTstrchr_pointer + 4);
689
                   SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected
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 View File

146
   uint16_t FTDI::get_utf8_char_width(utf8_char_t c, font_size_t fs) {
146
   uint16_t FTDI::get_utf8_char_width(utf8_char_t c, font_size_t fs) {
147
     int x = 0, y = 0;
147
     int x = 0, y = 0;
148
     #ifdef TOUCH_UI_UTF8_WESTERN_CHARSET
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
     #endif
150
     #endif
151
-      StandardCharSet::render_glyph(NULL, x, y, fs, c);
151
+      StandardCharSet::render_glyph(nullptr, x, y, fs, c);
152
     return x;
152
     return x;
153
   }
153
   }
154
 
154
 
165
     */
165
     */
166
 
166
 
167
   uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs) {
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
   uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) {
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 View File

110
       draw_return_ui();
110
       draw_return_ui();
111
     }
111
     }
112
     else {
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
       lv_obj_del(kb);
114
       lv_obj_del(kb);
115
       return;
115
       return;
116
     }
116
     }
174
   return;
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
   if (!ext->ta) return;
178
   if (!ext->ta) return;
179
 
179
 
180
   if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0)
180
   if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0)
214
 void lv_draw_keyboard() {
214
 void lv_draw_keyboard() {
215
   scr = lv_screen_create(KEY_BOARD_UI, "");
215
   scr = lv_screen_create(KEY_BOARD_UI, "");
216
 
216
 
217
-  /*Create styles for the keyboard*/
217
+  // Create styles for the keyboard
218
   static lv_style_t rel_style, pr_style;
218
   static lv_style_t rel_style, pr_style;
219
 
219
 
220
   lv_style_copy(&rel_style, &lv_style_btn_rel);
220
   lv_style_copy(&rel_style, &lv_style_btn_rel);
229
   pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15);
229
   pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15);
230
   pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C);
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
   lv_obj_t *kb = lv_kb_create(scr, nullptr);
233
   lv_obj_t *kb = lv_kb_create(scr, nullptr);
234
   lv_obj_set_event_cb(kb, lv_kb_event_cb);
234
   lv_obj_set_event_cb(kb, lv_kb_event_cb);
235
   lv_kb_set_cursor_manage(kb, true);
235
   lv_kb_set_cursor_manage(kb, true);
243
     }
243
     }
244
   #endif
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
   lv_obj_t *ta = lv_ta_create(scr, nullptr);
247
   lv_obj_t *ta = lv_ta_create(scr, nullptr);
248
   lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10);
248
   lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10);
249
   if (keyboard_value == gcodeCommand) {
249
   if (keyboard_value == gcodeCommand) {
255
     lv_ta_set_text(ta, "");
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
   lv_kb_set_ta(kb, ta);
259
   lv_kb_set_ta(kb, ta);
260
 }
260
 }
261
 
261
 

+ 1
- 1
Marlin/src/lcd/menu/menu.cpp View File

129
   if (ui.should_draw())
129
   if (ui.should_draw())
130
     draw_edit_screen(strfunc(ui.encoderPosition + minEditValue));
130
     draw_edit_screen(strfunc(ui.encoderPosition + minEditValue));
131
   if (ui.lcd_clicked || (liveEdit && ui.should_draw())) {
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
     if (callbackFunc && (liveEdit || ui.lcd_clicked)) (*callbackFunc)();
133
     if (callbackFunc && (liveEdit || ui.lcd_clicked)) (*callbackFunc)();
134
     if (ui.use_click()) ui.goto_previous_screen();
134
     if (ui.use_click()) ui.goto_previous_screen();
135
   }
135
   }

+ 1
- 1
Marlin/src/lcd/tft/canvas.cpp View File

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

+ 1
- 1
Marlin/src/lcd/tft/tft_image.cpp View File

23
 #include "tft_image.h"
23
 #include "tft_image.h"
24
 #include <stddef.h>
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
 const tImage MarlinLogo112x38x1     = { (void *)marlin_logo_112x38x1, 112, 38, GREYSCALE1 };
28
 const tImage MarlinLogo112x38x1     = { (void *)marlin_logo_112x38x1, 112, 38, GREYSCALE1 };
29
 const tImage MarlinLogo228x255x2    = { (void *)marlin_logo_228x255x2, 228, 255, GREYSCALE2 };
29
 const tImage MarlinLogo228x255x2    = { (void *)marlin_logo_228x255x2, 228, 255, GREYSCALE2 };

+ 10
- 10
Marlin/src/lcd/tft/tft_queue.cpp View File

30
 
30
 
31
 uint8_t TFT_Queue::queue[];
31
 uint8_t TFT_Queue::queue[];
32
 uint8_t *TFT_Queue::end_of_queue = queue;
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
 void TFT_Queue::reset() {
36
 void TFT_Queue::reset() {
37
   tft.abort();
37
   tft.abort();
38
 
38
 
39
   end_of_queue = queue;
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
 void TFT_Queue::async() {
44
 void TFT_Queue::async() {
45
-  if (current_task == NULL) return;
45
+  if (!current_task) return;
46
   queueTask_t *task = (queueTask_t *)current_task;
46
   queueTask_t *task = (queueTask_t *)current_task;
47
 
47
 
48
   // Check IO busy status
48
   // Check IO busy status
63
 }
63
 }
64
 
64
 
65
 void TFT_Queue::finish_sketch() {
65
 void TFT_Queue::finish_sketch() {
66
-  if (last_task == NULL) return;
66
+  if (!last_task) return;
67
   queueTask_t *task = (queueTask_t *)last_task;
67
   queueTask_t *task = (queueTask_t *)last_task;
68
 
68
 
69
   if (task->state == TASK_STATE_SKETCH) {
69
   if (task->state == TASK_STATE_SKETCH) {
71
     task->nextTask = end_of_queue;
71
     task->nextTask = end_of_queue;
72
     task->state = TASK_STATE_READY;
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
   task->state = TASK_STATE_READY;
184
   task->state = TASK_STATE_READY;
185
   task->type = TASK_FILL;
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
 void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
190
 void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
195
 
195
 
196
   task->state = TASK_STATE_SKETCH;
196
   task->state = TASK_STATE_SKETCH;
197
   task->type = TASK_CANVAS;
197
   task->type = TASK_CANVAS;
198
-  task->nextTask = NULL;
198
+  task->nextTask = nullptr;
199
 
199
 
200
   end_of_queue += sizeof(queueTask_t);
200
   end_of_queue += sizeof(queueTask_t);
201
   parametersCanvas_t *task_parameters = (parametersCanvas_t *)end_of_queue;
201
   parametersCanvas_t *task_parameters = (parametersCanvas_t *)end_of_queue;
207
   task_parameters->height = height;
207
   task_parameters->height = height;
208
   task_parameters->count = 0;
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
 void TFT_Queue::set_background(uint16_t color) {
213
 void TFT_Queue::set_background(uint16_t color) {

+ 1
- 1
Marlin/src/lcd/tft/tft_string.cpp View File

42
   font_header = (font_t *)font;
42
   font_header = (font_t *)font;
43
   uint32_t glyph;
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
   DEBUG_ECHOLNPAIR("Format: ", font_header->Format);
47
   DEBUG_ECHOLNPAIR("Format: ", font_header->Format);
48
   DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth);
48
   DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth);

+ 4
- 5
Marlin/src/lcd/tft/touch.cpp View File

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

+ 1
- 1
Marlin/src/lcd/tft/ui_320x240.cpp View File

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*/) {
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
   uint16_t line = 1;
453
   uint16_t line = 1;
454
 
454
 
455
-  if (string == NULL) line++;
455
+  if (!string) line++;
456
 
456
 
457
   menu_line(line++);
457
   menu_line(line++);
458
   tft_string.set(pref);
458
   tft_string.set(pref);

+ 2
- 2
Marlin/src/lcd/tft/ui_480x320.cpp View File

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*/) {
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
   uint16_t line = 1;
458
   uint16_t line = 1;
459
 
459
 
460
-  if (string == NULL) line++;
460
+  if (!string) line++;
461
 
461
 
462
   menu_line(line++);
462
   menu_line(line++);
463
   tft_string.set(pref);
463
   tft_string.set(pref);
945
   tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
945
   tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
946
 
946
 
947
   // TODO: Make an add_text() taking a font arg
947
   // TODO: Make an add_text() taking a font arg
948
-  if (label != NULL) {
948
+  if (label) {
949
     tft_string.set(label);
949
     tft_string.set(label);
950
     tft_string.trim();
950
     tft_string.trim();
951
     tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string);
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 View File

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

+ 1
- 1
Marlin/src/libs/vector_3.cpp View File

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

+ 1
- 1
Marlin/src/pins/mega/pins_CNCONTROLS_11.h View File

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

+ 1
- 1
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h View File

171
 
171
 
172
 // Shared FSMC Configs
172
 // Shared FSMC Configs
173
 #if HAS_FSMC_TFT
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
   #define DOGLCD_SCK                        -1
175
   #define DOGLCD_SCK                        -1
176
 
176
 
177
   #define FSMC_CS_PIN                       PD7   // NE4
177
   #define FSMC_CS_PIN                       PD7   // NE4

+ 2
- 2
Marlin/src/sd/SdBaseFile.cpp View File

21
  */
21
  */
22
 
22
 
23
 #if __GNUC__ > 8
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
   #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
24
   #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
27
 #endif
25
 #endif
28
 
26
 
29
 /**
27
 /**
28
+ * sd/SdBaseFile.cpp
29
+ *
30
  * Arduino SdFat Library
30
  * Arduino SdFat Library
31
  * Copyright (c) 2009 by William Greiman
31
  * Copyright (c) 2009 by William Greiman
32
  *
32
  *

+ 2
- 5
Marlin/src/sd/SdBaseFile.h View File

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

+ 2
- 1
Marlin/src/sd/SdFatConfig.h View File

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

+ 2
- 5
Marlin/src/sd/SdFatStructs.h View File

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

+ 2
- 0
Marlin/src/sd/SdFatUtil.cpp View File

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

+ 2
- 0
Marlin/src/sd/SdFatUtil.h View File

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

+ 2
- 0
Marlin/src/sd/SdFile.cpp View File

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

+ 3
- 6
Marlin/src/sd/SdFile.h View File

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

+ 2
- 0
Marlin/src/sd/SdVolume.cpp View File

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

+ 2
- 5
Marlin/src/sd/SdVolume.h View File

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

+ 2
- 2
Marlin/src/sd/cardreader.cpp View File

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

+ 136
- 138
Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp View File

22
  * Web      :  https://www.circuitsathome.com
22
  * Web      :  https://www.circuitsathome.com
23
  * e-mail   :  support@circuitsathome.com
23
  * e-mail   :  support@circuitsathome.com
24
  */
24
  */
25
-/* USB functions */
25
+
26
+//
27
+// USB functions supporting Flash Drive
28
+//
26
 
29
 
27
 #include "../../../inc/MarlinConfigPre.h"
30
 #include "../../../inc/MarlinConfigPre.h"
28
 
31
 
35
 
38
 
36
 /* constructor */
39
 /* constructor */
37
 USB::USB() : bmHubPre(0) {
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
   init();
42
   init();
40
 }
43
 }
41
 
44
 
45
   bmHubPre = 0;
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
 EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) {
54
 EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) {
57
   UsbDevice *p = addrPool.GetUsbDevicePtr(addr);
55
   UsbDevice *p = addrPool.GetUsbDevicePtr(addr);
70
   return nullptr;
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
 uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr) {
76
 uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr) {
77
   if (!eprecord_ptr)
77
   if (!eprecord_ptr)
78
     return USB_ERROR_INVALID_ARGUMENT;
78
     return USB_ERROR_INVALID_ARGUMENT;
112
     USBTRACE2(" NAK Limit: ", nak_limit);
112
     USBTRACE2(" NAK Limit: ", nak_limit);
113
     USBTRACE("\r\n");
113
     USBTRACE("\r\n");
114
    */
114
    */
115
-  regWr(rPERADDR, addr); //set peripheral address
115
+  regWr(rPERADDR, addr); // Set peripheral address
116
 
116
 
117
   uint8_t mode = regRd(rMODE);
117
   uint8_t mode = regRd(rMODE);
118
 
118
 
121
   //Serial.print("\r\nLS: ");
121
   //Serial.print("\r\nLS: ");
122
   //Serial.println(p->lowspeed, HEX);
122
   //Serial.println(p->lowspeed, HEX);
123
 
123
 
124
-
125
-
126
   // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise
124
   // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise
127
   regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED));
125
   regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED));
128
 
126
 
133
 /* depending on request. Actual requests are defined as inlines                                                                                      */
131
 /* depending on request. Actual requests are defined as inlines                                                                                      */
134
 /* return codes:                */
132
 /* return codes:                */
135
 /* 00       =   success         */
133
 /* 00       =   success         */
136
-
137
 /* 01-0f    =   non-zero HRSLT  */
134
 /* 01-0f    =   non-zero HRSLT  */
138
 uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
135
 uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
139
   uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p) {
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
   uint8_t rcode;
138
   uint8_t rcode;
142
   SETUP_PKT setup_pkt;
139
   SETUP_PKT setup_pkt;
143
 
140
 
157
   setup_pkt.wIndex = wInd;
154
   setup_pkt.wIndex = wInd;
158
   setup_pkt.wLength = total;
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
   if (rcode) return rcode; // Return HRSLT if not zero
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
       uint16_t left = total;
164
       uint16_t left = total;
168
-      pep->bmRcvToggle = 1; //bmRCVTOG1;
165
+      pep->bmRcvToggle = 1; // BmRCVTOG1;
169
 
166
 
170
       while (left) {
167
       while (left) {
171
         // Bytes read into buffer
168
         // Bytes read into buffer
174
 
171
 
175
         rcode = InTransfer(pep, nak_limit, &read, dataptr);
172
         rcode = InTransfer(pep, nak_limit, &read, dataptr);
176
         if (rcode == hrTOGERR) {
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
           pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
175
           pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
179
           continue;
176
           continue;
180
         }
177
         }
189
         if (read < nbytes) break;
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
       rcode = OutTransfer(pep, nak_limit, nbytes, dataptr);
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
   // Status stage
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
 uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) {
204
 uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) {
208
   EpInfo *pep = nullptr;
205
   EpInfo *pep = nullptr;
209
   uint16_t nak_limit = 0;
206
   uint16_t nak_limit = 0;
227
   uint8_t maxpktsize = pep->maxPktSize;
224
   uint8_t maxpktsize = pep->maxPktSize;
228
 
225
 
229
   *nbytesptr = 0;
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
   for (;;) {
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
     if (rcode == hrTOGERR) {
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
       pep->bmRcvToggle = (regRd(rHRSL) & bmRCVTOGRD) ? 0 : 1;
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
       continue;
236
       continue;
240
     }
237
     }
241
     if (rcode) {
238
     if (rcode) {
242
       //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode);
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
     /* check for RCVDAVIRQ and generate error if not present */
242
     /* check for RCVDAVIRQ and generate error if not present */
246
     /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */
243
     /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */
247
     if ((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
244
     if ((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
248
       //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
245
       //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
249
-      rcode = 0xF0; //receive error
246
+      rcode = 0xF0; // Receive error
250
       break;
247
       break;
251
     }
248
     }
252
-    pktsize = regRd(rRCVBC); //number of received bytes
249
+    pktsize = regRd(rRCVBC); // Number of received bytes
253
     //printf("Got %i bytes \r\n", pktsize);
250
     //printf("Got %i bytes \r\n", pktsize);
254
     // This would be OK, but...
251
     // This would be OK, but...
255
     //assert(pktsize <= nbytes);
252
     //assert(pktsize <= nbytes);
266
     data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data);
263
     data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data);
267
 
264
 
268
     regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer
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
     /* The transfer is complete under two conditions:           */
268
     /* The transfer is complete under two conditions:           */
272
     /* 1. The device sent a short packet (L.T. maxPacketSize)   */
269
     /* 1. The device sent a short packet (L.T. maxPacketSize)   */
284
   return rcode;
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
 uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
289
 uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
292
   EpInfo *pep = nullptr;
290
   EpInfo *pep = nullptr;
293
   uint16_t nak_limit = 0;
291
   uint16_t nak_limit = 0;
300
 
298
 
301
 uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) {
299
 uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) {
302
   uint8_t rcode = hrSUCCESS, retry_count;
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
   uint16_t bytes_tosend, nak_count;
302
   uint16_t bytes_tosend, nak_count;
305
   uint16_t bytes_left = nbytes;
303
   uint16_t bytes_left = nbytes;
306
 
304
 
311
 
309
 
312
   uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT;
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
   while (bytes_left) {
314
   while (bytes_left) {
317
     retry_count = 0;
315
     retry_count = 0;
318
     nak_count = 0;
316
     nak_count = 0;
319
     bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
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
     rcode = (regRd(rHRSL) & 0x0F);
323
     rcode = (regRd(rHRSL) & 0x0F);
326
 
324
 
327
     while (rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) {
325
     while (rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) {
330
           nak_count++;
328
           nak_count++;
331
           if (nak_limit && (nak_count == nak_limit))
329
           if (nak_limit && (nak_count == nak_limit))
332
             goto breakout;
330
             goto breakout;
333
-          //return ( rcode);
331
+          //return rcode;
334
           break;
332
           break;
335
         case hrTIMEOUT:
333
         case hrTIMEOUT:
336
           retry_count++;
334
           retry_count++;
337
           if (retry_count == USB_RETRY_LIMIT)
335
           if (retry_count == USB_RETRY_LIMIT)
338
             goto breakout;
336
             goto breakout;
339
-          //return ( rcode);
337
+          //return rcode;
340
           break;
338
           break;
341
         case hrTOGERR:
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
           pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
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
           break;
343
           break;
346
         default:
344
         default:
347
           goto breakout;
345
           goto breakout;
351
       regWr(rSNDBC, 0);
349
       regWr(rSNDBC, 0);
352
       regWr(rSNDFIFO, *data_p);
350
       regWr(rSNDFIFO, *data_p);
353
       regWr(rSNDBC, bytes_tosend);
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
       rcode = (regRd(rHRSL) & 0x0F);
355
       rcode = (regRd(rHRSL) & 0x0F);
358
-    } // while rcode && ....
356
+    } // While rcode && ....
359
     bytes_left -= bytes_tosend;
357
     bytes_left -= bytes_tosend;
360
     data_p += bytes_tosend;
358
     data_p += bytes_tosend;
361
-  } // while bytes_left...
359
+  } // While bytes_left...
362
 breakout:
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
 uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
373
 uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
375
   uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT;
374
   uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT;
376
   uint8_t tmpdata;
375
   uint8_t tmpdata;
380
 
379
 
381
   while ((int32_t)((uint32_t)millis() - timeout) < 0L) {
380
   while ((int32_t)((uint32_t)millis() - timeout) < 0L) {
382
     #if defined(ESP8266) || defined(ESP32)
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
     #endif
383
     #endif
385
-    regWr(rHXFR, (token | ep)); //launch the transfer
384
+    regWr(rHXFR, (token | ep)); // Launch the transfer
386
     rcode = USB_ERROR_TRANSFER_TIMEOUT;
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
       #if defined(ESP8266) || defined(ESP32)
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
       #endif
390
       #endif
392
       tmpdata = regRd(rHIRQ);
391
       tmpdata = regRd(rHIRQ);
393
 
392
 
394
       if (tmpdata & bmHXFRDNIRQ) {
393
       if (tmpdata & bmHXFRDNIRQ) {
395
-        regWr(rHIRQ, bmHXFRDNIRQ); //clear the interrupt
394
+        regWr(rHIRQ, bmHXFRDNIRQ); // Clear the interrupt
396
         rcode = 0x00;
395
         rcode = 0x00;
397
         break;
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
     switch (rcode) {
405
     switch (rcode) {
408
       case hrNAK:
406
       case hrNAK:
419
         return (rcode);
417
         return (rcode);
420
     }
418
     }
421
 
419
 
422
-  } // while timeout > millis()
420
+  } // While timeout > millis()
423
   return rcode;
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
   uint8_t rcode;
426
   uint8_t rcode;
429
   uint8_t tmpdata;
427
   uint8_t tmpdata;
430
   static uint32_t delay = 0;
428
   static uint32_t delay = 0;
437
 
435
 
438
   /* modify USB task state if Vbus changed */
436
   /* modify USB task state if Vbus changed */
439
   switch (tmpdata) {
437
   switch (tmpdata) {
440
-    case SE1: //illegal state
438
+    case SE1: // Illegal state
441
       usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL;
439
       usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL;
442
       lowspeed = false;
440
       lowspeed = false;
443
       break;
441
       break;
444
-    case SE0: //disconnected
442
+    case SE0: // Disconnected
445
       if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED)
443
       if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED)
446
         usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE;
444
         usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE;
447
       lowspeed = false;
445
       lowspeed = false;
448
       break;
446
       break;
449
     case LSHOST:
447
     case LSHOST:
450
       lowspeed = true;
448
       lowspeed = true;
451
-      //intentional fallthrough
452
-    case FSHOST: //attached
449
+      // Intentional fallthrough
450
+    case FSHOST: // Attached
453
       if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
451
       if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
454
         delay = (uint32_t)millis() + USB_SETTLE_DELAY;
452
         delay = (uint32_t)millis() + USB_SETTLE_DELAY;
455
         usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE;
453
         usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE;
470
 
468
 
471
       usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE;
469
       usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE;
472
       break;
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
       break;
472
       break;
475
-    case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
473
+    case USB_DETACHED_SUBSTATE_ILLEGAL: // Just sit here
476
       break;
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
       if ((int32_t)((uint32_t)millis() - delay) >= 0L)
476
       if ((int32_t)((uint32_t)millis() - delay) >= 0L)
479
         usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
477
         usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
480
-      else break; // don't fall through
478
+      else break; // Don't fall through
481
     case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
479
     case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
482
-      regWr(rHCTL, bmBUSRST); //issue bus reset
480
+      regWr(rHCTL, bmBUSRST); // Issue bus reset
483
       usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE;
481
       usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE;
484
       break;
482
       break;
485
     case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE:
483
     case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE:
486
       if ((regRd(rHCTL) & bmBUSRST) == 0) {
484
       if ((regRd(rHCTL) & bmBUSRST) == 0) {
487
-        tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation
485
+        tmpdata = regRd(rMODE) | bmSOFKAENAB; // Start SOF generation
488
         regWr(rMODE, tmpdata);
486
         regWr(rMODE, tmpdata);
489
         usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF;
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
       break;
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
       if (regRd(rHIRQ) & bmFRAMEIRQ) {
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
             usb_task_state = USB_STATE_CONFIGURING;
496
             usb_task_state = USB_STATE_CONFIGURING;
499
         */
497
         */
500
         usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
498
         usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
503
       break;
501
       break;
504
     case USB_ATTACHED_SUBSTATE_WAIT_RESET:
502
     case USB_ATTACHED_SUBSTATE_WAIT_RESET:
505
       if ((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING;
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
     case USB_STATE_CONFIGURING:
505
     case USB_STATE_CONFIGURING:
508
 
506
 
509
       //Serial.print("\r\nConf.LS: ");
507
       //Serial.print("\r\nConf.LS: ");
565
   if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) {
563
   if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) {
566
     if (parent == 0) {
564
     if (parent == 0) {
567
       // Send a bus reset on the root interface.
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
     else {
569
     else {
572
-      // reset parent port
570
+      // Reset parent port
573
       devConfig[parent]->ResetHubPort(port);
571
       devConfig[parent]->ResetHubPort(port);
574
     }
572
     }
575
   }
573
   }
592
     // Issue a bus reset, because the device may be in a limbo state
590
     // Issue a bus reset, because the device may be in a limbo state
593
     if (parent == 0) {
591
     if (parent == 0) {
594
       // Send a bus reset on the root interface.
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
     else {
596
     else {
599
-      // reset parent port
597
+      // Reset parent port
600
       devConfig[parent]->ResetHubPort(port);
598
       devConfig[parent]->ResetHubPort(port);
601
     }
599
     }
602
   }
600
   }
623
  * 4: set address
621
  * 4: set address
624
  * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail
622
  * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail
625
  * 6: while (configurations) {
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
  * 7: for (each driver) {
638
  * 7: for (each driver) {
641
  *      7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID
639
  *      7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID
671
   oldep_ptr = p->epinfo;
669
   oldep_ptr = p->epinfo;
672
 
670
 
673
   // Temporary assign new pointer to epInfo to p->epinfo in order to
671
   // Temporary assign new pointer to epInfo to p->epinfo in order to
674
-  // avoid toggle inconsistence
672
+  // Avoid toggle inconsistence
675
 
673
 
676
   p->epinfo = &epInfo;
674
   p->epinfo = &epInfo;
677
 
675
 
687
     return rcode;
685
     return rcode;
688
   }
686
   }
689
 
687
 
690
-  // to-do?
688
+  // To-do?
691
   // Allocate new address according to device class
689
   // Allocate new address according to device class
692
   //bAddress = addrPool.AllocAddress(parent, false, port);
690
   //bAddress = addrPool.AllocAddress(parent, false, port);
693
 
691
 
698
   // Qualify with subclass too.
696
   // Qualify with subclass too.
699
   //
697
   //
700
   // VID/PID & class tests default to false for drivers not yet ported
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
   for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
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
     if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) {
704
     if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) {
707
       rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
705
       rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
708
       if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED)
706
       if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED)
712
 
710
 
713
   if (devConfigIndex < USB_NUMDEVICES) return rcode;
711
   if (devConfigIndex < USB_NUMDEVICES) return rcode;
714
 
712
 
715
-  // blindly attempt to configure
713
+  // Blindly attempt to configure
716
   for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
714
   for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
717
     if (!devConfig[devConfigIndex]) continue;
715
     if (!devConfig[devConfigIndex]) continue;
718
-    if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed
716
+    if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed
719
     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
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
     rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
718
     rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
721
 
719
 
722
     //printf("ERROR ENUMERATING %2.2x\r\n", rcode);
720
     //printf("ERROR ENUMERATING %2.2x\r\n", rcode);
723
     if (!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) {
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
       //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE)
725
       //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE)
728
-      //        devConfigIndex = 0;
726
+      //devConfigIndex = 0;
729
       return rcode;
727
       return rcode;
730
     }
728
     }
731
   }
729
   }
744
   return 0;
742
   return 0;
745
 }
743
 }
746
 
744
 
747
-#if 1 //!defined(USB_METHODS_INLINE)
748
-//get device descriptor
749
-
745
+// Get device descriptor
750
 uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
746
 uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
751
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, nullptr);
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
 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
751
 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
756
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, nullptr);
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
 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) {
761
 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) {
762
   const uint8_t bufSize = 64;
762
   const uint8_t bufSize = 64;
763
   uint8_t buf[bufSize];
763
   uint8_t buf[bufSize];
773
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p);
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
 uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) {
777
 uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) {
779
   return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, ns, ns, dataptr, nullptr);
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
 uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
782
 uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
784
   uint8_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr);
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
   delay(300); // Older spec says you should wait at least 200ms
785
   delay(300); // Older spec says you should wait at least 200ms
787
   return rcode;
786
   return rcode;
788
   //return ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr);
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
 uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
791
 uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
793
   return ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr);
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
 #endif // USB_FLASH_DRIVE_SUPPORT
795
 #endif // USB_FLASH_DRIVE_SUPPORT

Loading…
Cancel
Save