From ec23e37a4a31d12febc06922d3fa68446f58d7fb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 24 Oct 2020 17:13:10 -0500 Subject: [PATCH] Clean up comments, USB flash, NULLs --- Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp | 4 +- Marlin/src/HAL/ESP32/i2s.cpp | 4 +- Marlin/src/HAL/LINUX/eeprom.cpp | 4 +- Marlin/src/HAL/LINUX/hardware/Gpio.h | 12 +- Marlin/src/HAL/SAMD51/HAL.cpp | 4 +- Marlin/src/HAL/SAMD51/QSPIFlash.cpp | 4 +- Marlin/src/HAL/STM32/tft/xpt2046.cpp | 2 +- Marlin/src/HAL/STM32/timers.cpp | 2 +- Marlin/src/HAL/STM32F1/HAL.h | 2 +- Marlin/src/HAL/STM32F1/SPI.cpp | 2 +- Marlin/src/HAL/STM32F1/fastio.h | 2 +- Marlin/src/gcode/parser.h | 2 +- Marlin/src/gcode/queue.cpp | 4 +- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 2 +- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 2 +- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 2 +- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 2 +- .../extui/lib/anycubic_chiron/chiron_tft.cpp | 2 +- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 13 +- .../ftdi_eve_lib/extended/unicode/unicode.cpp | 6 +- .../lcd/extui/lib/mks_ui/draw_keyboard.cpp | 12 +- Marlin/src/lcd/menu/menu.cpp | 2 +- Marlin/src/lcd/tft/canvas.cpp | 2 +- Marlin/src/lcd/tft/tft_image.cpp | 2 +- Marlin/src/lcd/tft/tft_queue.cpp | 20 +- Marlin/src/lcd/tft/tft_string.cpp | 2 +- Marlin/src/lcd/tft/touch.cpp | 9 +- Marlin/src/lcd/tft/ui_320x240.cpp | 2 +- Marlin/src/lcd/tft/ui_480x320.cpp | 4 +- .../libs/heatshrink/heatshrink_decoder.cpp | 8 +- Marlin/src/libs/vector_3.cpp | 2 +- Marlin/src/pins/mega/pins_CNCONTROLS_11.h | 2 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 2 +- Marlin/src/sd/SdBaseFile.cpp | 4 +- Marlin/src/sd/SdBaseFile.h | 7 +- Marlin/src/sd/SdFatConfig.h | 3 +- Marlin/src/sd/SdFatStructs.h | 7 +- Marlin/src/sd/SdFatUtil.cpp | 2 + Marlin/src/sd/SdFatUtil.h | 2 + Marlin/src/sd/SdFile.cpp | 2 + Marlin/src/sd/SdFile.h | 9 +- Marlin/src/sd/SdVolume.cpp | 2 + Marlin/src/sd/SdVolume.h | 7 +- Marlin/src/sd/cardreader.cpp | 4 +- Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp | 274 +++++++++--------- 45 files changed, 231 insertions(+), 238 deletions(-) diff --git a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp index ea2936359d..db5e82ec55 100644 --- a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp +++ b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp @@ -84,7 +84,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { card.getSd2Card().readData(sector_buf); // RAM -> USB - if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) { + if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) { card.getSd2Card().readStop(); return CTRL_FAIL; } @@ -120,7 +120,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) { while (nb_sector--) { // USB -> RAM - if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) { + if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) { card.getSd2Card().writeStop(); return CTRL_FAIL; } diff --git a/Marlin/src/HAL/ESP32/i2s.cpp b/Marlin/src/HAL/ESP32/i2s.cpp index 99b2f755e5..e8f3806543 100644 --- a/Marlin/src/HAL/ESP32/i2s.cpp +++ b/Marlin/src/HAL/ESP32/i2s.cpp @@ -184,7 +184,7 @@ int i2s_init() { // Allocate the array of pointers to the buffers dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT); - if (dma.buffers == nullptr) return -1; + if (!dma.buffers) return -1; // Allocate each buffer that can be used by the DMA controller for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) { @@ -194,7 +194,7 @@ int i2s_init() { // Allocate the array of DMA descriptors dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT); - if (dma.desc == nullptr) return -1; + if (!dma.desc) return -1; // Allocate each DMA descriptor that will be used by the DMA controller for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) { diff --git a/Marlin/src/HAL/LINUX/eeprom.cpp b/Marlin/src/HAL/LINUX/eeprom.cpp index 967ca851ab..68fff9c433 100644 --- a/Marlin/src/HAL/LINUX/eeprom.cpp +++ b/Marlin/src/HAL/LINUX/eeprom.cpp @@ -40,7 +40,7 @@ size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; } bool PersistentStore::access_start() { const char eeprom_erase_value = 0xFF; FILE * eeprom_file = fopen(filename, "rb"); - if (eeprom_file == nullptr) return false; + if (!eeprom_file) return false; fseek(eeprom_file, 0L, SEEK_END); std::size_t file_size = ftell(eeprom_file); @@ -59,7 +59,7 @@ bool PersistentStore::access_start() { bool PersistentStore::access_finish() { FILE * eeprom_file = fopen(filename, "wb"); - if (eeprom_file == nullptr) return false; + if (!eeprom_file) return false; fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file); fclose(eeprom_file); return true; diff --git a/Marlin/src/HAL/LINUX/hardware/Gpio.h b/Marlin/src/HAL/LINUX/hardware/Gpio.h index 9255ec1dfc..2d9b1f29eb 100644 --- a/Marlin/src/HAL/LINUX/hardware/Gpio.h +++ b/Marlin/src/HAL/LINUX/hardware/Gpio.h @@ -86,10 +86,10 @@ public: 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; pin_map[pin].value = value; GpioEvent evt(Clock::nanos(), pin, evt_type); - if (pin_map[pin].cb != nullptr) { + if (pin_map[pin].cb) { pin_map[pin].cb->interrupt(evt); } - if (Gpio::logger != nullptr) Gpio::logger->log(evt); + if (Gpio::logger) Gpio::logger->log(evt); } static uint16_t get(pin_type pin) { @@ -105,8 +105,8 @@ public: if (!valid_pin(pin)) return; pin_map[pin].mode = value; GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM); - if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt); - if (Gpio::logger != nullptr) Gpio::logger->log(evt); + if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt); + if (Gpio::logger) Gpio::logger->log(evt); } static uint8_t getMode(pin_type pin) { @@ -118,8 +118,8 @@ public: if (!valid_pin(pin)) return; pin_map[pin].dir = value; GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD); - if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt); - if (Gpio::logger != nullptr) Gpio::logger->log(evt); + if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt); + if (Gpio::logger) Gpio::logger->log(evt); } static uint8_t getDir(pin_type pin) { diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp index 9f24d30071..d985ef3787 100644 --- a/Marlin/src/HAL/SAMD51/HAL.cpp +++ b/Marlin/src/HAL/SAMD51/HAL.cpp @@ -300,7 +300,7 @@ uint16_t HAL_adc_result; DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE DMA_STEPSEL_SRC // STEPSEL ); - if (descriptor != nullptr) + if (descriptor) descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT; adc0DMAProgram.startJob(); } @@ -337,7 +337,7 @@ uint16_t HAL_adc_result; DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE DMA_STEPSEL_SRC // STEPSEL ); - if (descriptor != nullptr) + if (descriptor) descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT; adc1DMAProgram.startJob(); } diff --git a/Marlin/src/HAL/SAMD51/QSPIFlash.cpp b/Marlin/src/HAL/SAMD51/QSPIFlash.cpp index 307eb3fd45..fc21a1ad8c 100644 --- a/Marlin/src/HAL/SAMD51/QSPIFlash.cpp +++ b/Marlin/src/HAL/SAMD51/QSPIFlash.cpp @@ -35,10 +35,10 @@ uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE]; uint32_t QSPIFlash::_addr = INVALID_ADDR; void QSPIFlash::begin() { - if (_flashBase != nullptr) return; + if (_flashBase) return; _flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI()); - _flashBase->begin(NULL); + _flashBase->begin(nullptr); } size_t QSPIFlash::size() { diff --git a/Marlin/src/HAL/STM32/tft/xpt2046.cpp b/Marlin/src/HAL/STM32/tft/xpt2046.cpp index 921e377a9f..8c8d28f66a 100644 --- a/Marlin/src/HAL/STM32/tft/xpt2046.cpp +++ b/Marlin/src/HAL/STM32/tft/xpt2046.cpp @@ -99,7 +99,7 @@ void XPT2046::Init() { #endif } else { - SPIx.Instance = NULL; + SPIx.Instance = nullptr; SET_INPUT(TOUCH_MISO_PIN); SET_OUTPUT(TOUCH_MOSI_PIN); SET_OUTPUT(TOUCH_SCK_PIN); diff --git a/Marlin/src/HAL/STM32/timers.cpp b/Marlin/src/HAL/STM32/timers.cpp index c0ba19abe5..b708c4bdab 100644 --- a/Marlin/src/HAL/STM32/timers.cpp +++ b/Marlin/src/HAL/STM32/timers.cpp @@ -109,7 +109,7 @@ // Private Variables // ------------------------ -HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL }; +HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { nullptr }; // ------------------------ // Public functions diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index c10dea0eaf..eaf6494dfa 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -124,7 +124,7 @@ void HAL_idletask(); #endif #ifndef digitalPinHasPWM - #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr) + #define digitalPinHasPWM(P) !!PIN_MAP[P].timer_device #define NO_COMPILE_TIME_PWM #endif diff --git a/Marlin/src/HAL/STM32F1/SPI.cpp b/Marlin/src/HAL/STM32F1/SPI.cpp index 0452cf6293..ef00b407a8 100644 --- a/Marlin/src/HAL/STM32F1/SPI.cpp +++ b/Marlin/src/HAL/STM32F1/SPI.cpp @@ -656,7 +656,7 @@ static const spi_pins* dev_to_spi_pins(spi_dev *dev) { #if BOARD_NR_SPI >= 3 case RCC_SPI3: return board_spi_pins + 2; #endif - default: return NULL; + default: return nullptr; } } diff --git a/Marlin/src/HAL/STM32F1/fastio.h b/Marlin/src/HAL/STM32F1/fastio.h index e0e2e03a1c..a618fccc57 100644 --- a/Marlin/src/HAL/STM32F1/fastio.h +++ b/Marlin/src/HAL/STM32F1/fastio.h @@ -51,7 +51,7 @@ #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) #define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD) -#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr) +#define PWM_PIN(IO) !!PIN_MAP[IO].timer_device // digitalRead/Write wrappers #define extDigitalRead(IO) digitalRead(IO) diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 42b85ca271..17fb084388 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -245,7 +245,7 @@ public: #endif // The code value pointer was set - FORCE_INLINE static bool has_value() { return value_ptr != nullptr; } + FORCE_INLINE static bool has_value() { return !!value_ptr; } // Seen a parameter with a value static inline bool seenval(const char c) { return seen(c) && has_value(); } diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index 6139e3e2b8..f481052cbf 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -180,7 +180,7 @@ bool GCodeQueue::enqueue_one(const char* cmd) { * Return 'true' if any commands were processed. */ bool GCodeQueue::process_injected_command_P() { - if (injected_commands_P == nullptr) return false; + if (!injected_commands_P) return false; char c; size_t i = 0; @@ -480,7 +480,7 @@ void GCodeQueue::get_serial_commands() { if (npos) { - bool M110 = strstr_P(command, PSTR("M110")) != nullptr; + const bool M110 = !!strstr_P(command, PSTR("M110")); if (M110) { char* n2pos = strchr(command + 4, 'N'); diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 3c7993e375..4b82458398 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -1036,7 +1036,7 @@ void MarlinUI::draw_status_screen() { void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { ui.encoder_direction_normal(); uint8_t n = lcd_put_u8str_ind_P(0, 1, pstr, itemIndex, itemString, LCD_WIDTH - 1); - if (value != nullptr) { + if (value) { lcd_put_wchar(':'); n--; const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 83ebe111ae..c21c2ceb58 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() { lcd.setCursor(0, MIDDLE_Y); lcd.write(COLOR_EDIT); lcd_put_u8str_P(pstr); - if (value != nullptr) { + if (value) { lcd.write(':'); lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces lcd.write(' '); // Overwrite char if value gets shorter diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 53a20476e9..0aba49d564 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -423,7 +423,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop if (onpage) lcd_put_u8str_ind_P(0, baseline, pstr, itemIndex, itemString); // If a value is included, print a colon, then print the value right-justified - if (value != nullptr) { + if (value) { lcd_put_wchar(':'); if (extra_row) { // Assume that value is numeric (with no descender) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 2599b1ad22..106c18cf06 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -346,7 +346,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u switch (msg) { case U8G_DEV_MSG_INIT: - dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL); + dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr); tftio.Init(); tftio.InitTFT(); diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp index 99b2559d70..a1d1217d6e 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp @@ -294,7 +294,7 @@ namespace Anycubic { } void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) { - if (str != nullptr) { + if (str) { #if ACDEBUG(AC_SOME) SERIAL_ECHOPGM("> "); #endif diff --git a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp index efbc57e68a..2aaa0d0e33 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -218,12 +218,12 @@ void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) { } float AnycubicTFTClass::CodeValue() { - return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], NULL)); + return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], nullptr)); } bool AnycubicTFTClass::CodeSeen(char code) { TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code); - return (TFTstrchr_pointer != NULL); // Return True if a character was found + return !!TFTstrchr_pointer; // Return True if a character was found } bool AnycubicTFTClass::IsNozzleHomed() { @@ -536,7 +536,7 @@ void AnycubicTFTClass::OnPrintTimerStopped() { } void AnycubicTFTClass::GetCommandFromTFT() { - char *starpos = NULL; + char *starpos = nullptr; while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) { serial3_char = LCD_SERIAL.read(); if (serial3_char == '\n' || @@ -549,10 +549,10 @@ void AnycubicTFTClass::GetCommandFromTFT() { TFTcmdbuffer[TFTbufindw][serial3_count] = 0; // terminate string - if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) { + if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != nullptr)) { int16_t a_command; TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A'); - a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL)))); + a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], nullptr)))); #if ENABLED(ANYCUBIC_LCD_DEBUG) if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please! @@ -682,8 +682,7 @@ void AnycubicTFTClass::GetCommandFromTFT() { else { SelectedDirectory[0] = 0; - if (starpos != NULL) - *(starpos - 1) = '\0'; + if (starpos) *(starpos - 1) = '\0'; strcpy(SelectedFile, TFTstrchr_pointer + 4); SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp index 09473c1c26..bee3f74cab 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp @@ -146,9 +146,9 @@ uint16_t FTDI::get_utf8_char_width(utf8_char_t c, font_size_t fs) { int x = 0, y = 0; #ifdef TOUCH_UI_UTF8_WESTERN_CHARSET - WesternCharSet::render_glyph(NULL, x, y, fs, c) || + WesternCharSet::render_glyph(nullptr, x, y, fs, c) || #endif - StandardCharSet::render_glyph(NULL, x, y, fs, c); + StandardCharSet::render_glyph(nullptr, x, y, fs, c); return x; } @@ -165,7 +165,7 @@ */ uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs) { - return render_utf8_text(NULL, 0, 0, str, fs); + return render_utf8_text(nullptr, 0, 0, str, fs); } uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp index 7313ed531f..acf1d15325 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp @@ -110,7 +110,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) { draw_return_ui(); } else { - lv_kb_set_ta(kb, nullptr); /*De-assign the text area to hide it cursor if needed*/ + lv_kb_set_ta(kb, nullptr); // De-assign the text area to hide it cursor if needed lv_obj_del(kb); return; } @@ -174,7 +174,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) { return; } - /*Add the characters to the text area if set*/ + // Add the characters to the text area if set if (!ext->ta) return; 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) { void lv_draw_keyboard() { scr = lv_screen_create(KEY_BOARD_UI, ""); - /*Create styles for the keyboard*/ + // Create styles for the keyboard static lv_style_t rel_style, pr_style; lv_style_copy(&rel_style, &lv_style_btn_rel); @@ -229,7 +229,7 @@ void lv_draw_keyboard() { pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15); pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C); - /*Create a keyboard and apply the styles*/ + // Create a keyboard and apply the styles lv_obj_t *kb = lv_kb_create(scr, nullptr); lv_obj_set_event_cb(kb, lv_kb_event_cb); lv_kb_set_cursor_manage(kb, true); @@ -243,7 +243,7 @@ void lv_draw_keyboard() { } #endif - /*Create a text area. The keyboard will write here*/ + // Create a text area. The keyboard will write here lv_obj_t *ta = lv_ta_create(scr, nullptr); lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10); if (keyboard_value == gcodeCommand) { @@ -255,7 +255,7 @@ void lv_draw_keyboard() { lv_ta_set_text(ta, ""); } - /*Assign the text area to the keyboard*/ + // Assign the text area to the keyboard lv_kb_set_ta(kb, ta); } diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 5d67410351..cd94927049 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -129,7 +129,7 @@ void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) { if (ui.should_draw()) draw_edit_screen(strfunc(ui.encoderPosition + minEditValue)); if (ui.lcd_clicked || (liveEdit && ui.should_draw())) { - if (editValue != nullptr) loadfunc(editValue, ui.encoderPosition + minEditValue); + if (editValue) loadfunc(editValue, ui.encoderPosition + minEditValue); if (callbackFunc && (liveEdit || ui.lcd_clicked)) (*callbackFunc)(); if (ui.use_click()) ui.goto_previous_screen(); } diff --git a/Marlin/src/lcd/tft/canvas.cpp b/Marlin/src/lcd/tft/canvas.cpp index f6a5046b8d..061f078b92 100644 --- a/Marlin/src/lcd/tft/canvas.cpp +++ b/Marlin/src/lcd/tft/canvas.cpp @@ -79,7 +79,7 @@ void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, ui void CANVAS::AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors) { uint16_t *data = (uint16_t *)Images[image].data; - if (data == NULL) return; + if (!data) return; uint16_t image_width = Images[image].width, image_height = Images[image].height; diff --git a/Marlin/src/lcd/tft/tft_image.cpp b/Marlin/src/lcd/tft/tft_image.cpp index 27749cb7f3..8f8b610699 100644 --- a/Marlin/src/lcd/tft/tft_image.cpp +++ b/Marlin/src/lcd/tft/tft_image.cpp @@ -23,7 +23,7 @@ #include "tft_image.h" #include -const tImage NoLogo = { (void *)NULL, 0, 0, NOCOLORS }; +const tImage NoLogo = { nullptr, 0, 0, NOCOLORS }; const tImage MarlinLogo112x38x1 = { (void *)marlin_logo_112x38x1, 112, 38, GREYSCALE1 }; const tImage MarlinLogo228x255x2 = { (void *)marlin_logo_228x255x2, 228, 255, GREYSCALE2 }; diff --git a/Marlin/src/lcd/tft/tft_queue.cpp b/Marlin/src/lcd/tft/tft_queue.cpp index e77afaf716..e178a59a2d 100644 --- a/Marlin/src/lcd/tft/tft_queue.cpp +++ b/Marlin/src/lcd/tft/tft_queue.cpp @@ -30,19 +30,19 @@ uint8_t TFT_Queue::queue[]; uint8_t *TFT_Queue::end_of_queue = queue; -uint8_t *TFT_Queue::current_task = NULL; -uint8_t *TFT_Queue::last_task = NULL; +uint8_t *TFT_Queue::current_task = nullptr; +uint8_t *TFT_Queue::last_task = nullptr; void TFT_Queue::reset() { tft.abort(); end_of_queue = queue; - current_task = NULL; - last_task = NULL; + current_task = nullptr; + last_task = nullptr; } void TFT_Queue::async() { - if (current_task == NULL) return; + if (!current_task) return; queueTask_t *task = (queueTask_t *)current_task; // Check IO busy status @@ -63,7 +63,7 @@ void TFT_Queue::async() { } void TFT_Queue::finish_sketch() { - if (last_task == NULL) return; + if (!last_task) return; queueTask_t *task = (queueTask_t *)last_task; if (task->state == TASK_STATE_SKETCH) { @@ -71,7 +71,7 @@ void TFT_Queue::finish_sketch() { task->nextTask = end_of_queue; task->state = TASK_STATE_READY; - if (current_task == NULL) current_task = (uint8_t *)task; + if (!current_task) current_task = (uint8_t *)task; } } @@ -184,7 +184,7 @@ void TFT_Queue::fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui task->state = TASK_STATE_READY; task->type = TASK_FILL; - if (current_task == NULL) current_task = (uint8_t *)task; + if (!current_task) current_task = (uint8_t *)task; } 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) task->state = TASK_STATE_SKETCH; task->type = TASK_CANVAS; - task->nextTask = NULL; + task->nextTask = nullptr; end_of_queue += sizeof(queueTask_t); 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) task_parameters->height = height; task_parameters->count = 0; - if (current_task == NULL) current_task = (uint8_t *)task; + if (!current_task) current_task = (uint8_t *)task; } void TFT_Queue::set_background(uint16_t color) { diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index 663ed97c36..b707596bb3 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -42,7 +42,7 @@ void TFT_String::set_font(const uint8_t *font) { font_header = (font_t *)font; uint32_t glyph; - for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = NULL; + for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = nullptr; DEBUG_ECHOLNPAIR("Format: ", font_header->Format); DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth); diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 3e0945b227..93f8f64a2d 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -119,9 +119,8 @@ void Touch::idle() { NOMORE(y, current_control->y + current_control->height); touch(current_control); } - else { - current_control = NULL; - } + else + current_control = nullptr; } else { for (i = 0; i < controls_count; i++) { @@ -133,7 +132,7 @@ void Touch::idle() { } } - if (current_control == NULL) + if (!current_control) touch_time = last_touch_ms; } x = _x; @@ -141,7 +140,7 @@ void Touch::idle() { } else { x = y = 0; - current_control = NULL; + current_control = nullptr; touch_time = 0; touch_control_type = NONE; time_to_hold = 0; diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index 339c26cca2..45eab34665 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -452,7 +452,7 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu 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*/) { uint16_t line = 1; - if (string == NULL) line++; + if (!string) line++; menu_line(line++); tft_string.set(pref); diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index b67e041349..1003f32e7c 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -457,7 +457,7 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu 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*/) { uint16_t line = 1; - if (string == NULL) line++; + if (!string) line++; menu_line(line++); tft_string.set(pref); @@ -945,7 +945,7 @@ static void drawBtn(int x, int y, const char* label, int32_t data, MarlinImage i tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); // TODO: Make an add_text() taking a font arg - if (label != NULL) { + if (label) { tft_string.set(label); tft_string.trim(); tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string); diff --git a/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp b/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp index 3f0f828cd7..073a7ed0b6 100644 --- a/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp +++ b/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp @@ -89,7 +89,7 @@ heatshrink_decoder *heatshrink_decoder_alloc(uint16_t input_buffer_size, uint8_t size_t buffers_sz = (1 << window_sz2) + input_buffer_size; size_t sz = sizeof(heatshrink_decoder) + buffers_sz; heatshrink_decoder *hsd = HEATSHRINK_MALLOC(sz); - if (hsd == nullptr) return nullptr; + if (!hsd) return nullptr; hsd->input_buffer_size = input_buffer_size; hsd->window_sz2 = window_sz2; hsd->lookahead_sz2 = lookahead_sz2; @@ -124,7 +124,7 @@ void heatshrink_decoder_reset(heatshrink_decoder *hsd) { /* Copy SIZE bytes into the decoder's input buffer, if it will fit. */ HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, uint8_t *in_buf, size_t size, size_t *input_size) { - if (hsd == nullptr || in_buf == nullptr || input_size == nullptr) + if (!hsd || !in_buf || !input_size) return HSDR_SINK_ERROR_NULL; 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); static HSD_state st_yield_backref(heatshrink_decoder *hsd, output_info *oi); HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size) { - if (hsd == nullptr || out_buf == nullptr || output_size == nullptr) + if (!hsd || !out_buf || !output_size) return HSDR_POLL_ERROR_NULL; *output_size = 0; @@ -351,7 +351,7 @@ static uint16_t get_bits(heatshrink_decoder *hsd, uint8_t count) { } HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd) { - if (hsd == nullptr) { return HSDR_FINISH_ERROR_NULL; } + if (!hsd) return HSDR_FINISH_ERROR_NULL; switch (hsd->state) { case HSDS_TAG_BIT: return hsd->input_size == 0 ? HSDR_FINISH_DONE : HSDR_FINISH_MORE; diff --git a/Marlin/src/libs/vector_3.cpp b/Marlin/src/libs/vector_3.cpp index 75a30aef82..fd93ba09ad 100644 --- a/Marlin/src/libs/vector_3.cpp +++ b/Marlin/src/libs/vector_3.cpp @@ -141,7 +141,7 @@ matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) { } void matrix_3x3::debug(PGM_P const title) { - if (title != nullptr) { + if (title) { serialprintPGM(title); SERIAL_EOL(); } diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h index 675d4b7262..0e75aa4a37 100644 --- a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h +++ b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h @@ -141,7 +141,7 @@ // Pins for DOGM SPI LCD Support #define DOGLCD_A0 26 #define DOGLCD_CS 24 -#define DOGLCD_MOSI -1 +#define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 #define BTN_EN1 23 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 86dab41121..7f2ae61aae 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -171,7 +171,7 @@ // Shared FSMC Configs #if HAS_FSMC_TFT - #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h + #define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 #define FSMC_CS_PIN PD7 // NE4 diff --git a/Marlin/src/sd/SdBaseFile.cpp b/Marlin/src/sd/SdBaseFile.cpp index 2bc9f96e8c..46ed9372ab 100644 --- a/Marlin/src/sd/SdBaseFile.cpp +++ b/Marlin/src/sd/SdBaseFile.cpp @@ -21,12 +21,12 @@ */ #if __GNUC__ > 8 - // The NXP platform updated GCC from 7.2.1 to 9.2.1 - // and this new warning apparently can be ignored. #pragma GCC diagnostic ignored "-Waddress-of-packed-member" #endif /** + * sd/SdBaseFile.cpp + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdBaseFile.h b/Marlin/src/sd/SdBaseFile.h index 13a1be863d..2f7dfb9f3b 100644 --- a/Marlin/src/sd/SdBaseFile.h +++ b/Marlin/src/sd/SdBaseFile.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief SdBaseFile class - */ - -/** + * sd/SdBaseFile.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFatConfig.h b/Marlin/src/sd/SdFatConfig.h index 2e03a4181f..8f0596c5dd 100644 --- a/Marlin/src/sd/SdFatConfig.h +++ b/Marlin/src/sd/SdFatConfig.h @@ -22,7 +22,8 @@ #pragma once /** - * SdFatConfig.h + * sd/SdFatConfig.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFatStructs.h b/Marlin/src/sd/SdFatStructs.h index 484d4e50c6..ac81f1d64e 100644 --- a/Marlin/src/sd/SdFatStructs.h +++ b/Marlin/src/sd/SdFatStructs.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief FAT file structures - */ - -/** + * sd/SdFatStructs.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFatUtil.cpp b/Marlin/src/sd/SdFatUtil.cpp index e2c467c5b6..7d9f33dc50 100644 --- a/Marlin/src/sd/SdFatUtil.cpp +++ b/Marlin/src/sd/SdFatUtil.cpp @@ -21,6 +21,8 @@ */ /** + * sd/SdFatUtil.cpp + * * Arduino SdFat Library * Copyright (c) 2008 by William Greiman * diff --git a/Marlin/src/sd/SdFatUtil.h b/Marlin/src/sd/SdFatUtil.h index 7afed2ede0..f1bb65747e 100644 --- a/Marlin/src/sd/SdFatUtil.h +++ b/Marlin/src/sd/SdFatUtil.h @@ -22,6 +22,8 @@ #pragma once /** + * sd/SdFatUtil.h + * * Arduino SdFat Library * Copyright (c) 2008 by William Greiman * diff --git a/Marlin/src/sd/SdFile.cpp b/Marlin/src/sd/SdFile.cpp index c82fe2c5ed..cba67e2bba 100644 --- a/Marlin/src/sd/SdFile.cpp +++ b/Marlin/src/sd/SdFile.cpp @@ -21,6 +21,8 @@ */ /** + * sd/SdFile.cpp + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFile.h b/Marlin/src/sd/SdFile.h index 52c8f1f0db..17256b47c8 100644 --- a/Marlin/src/sd/SdFile.h +++ b/Marlin/src/sd/SdFile.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief SdFile class - */ - -/** + * sd/SdFile.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * @@ -42,7 +39,7 @@ * \class SdFile * \brief SdBaseFile with Print. */ -class SdFile : public SdBaseFile/*, public Print*/ { +class SdFile : public SdBaseFile { public: SdFile() {} SdFile(const char* name, uint8_t oflag); diff --git a/Marlin/src/sd/SdVolume.cpp b/Marlin/src/sd/SdVolume.cpp index 63731f728c..e262c8867a 100644 --- a/Marlin/src/sd/SdVolume.cpp +++ b/Marlin/src/sd/SdVolume.cpp @@ -21,6 +21,8 @@ */ /** + * sd/SdVolume.cpp + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdVolume.h b/Marlin/src/sd/SdVolume.h index 1ffa888468..2d57c681c4 100644 --- a/Marlin/src/sd/SdVolume.h +++ b/Marlin/src/sd/SdVolume.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief SdVolume class - */ - -/** + * sd/SdVolume.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index b809b2c10f..a633440ff6 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -639,7 +639,7 @@ bool CardReader::fileExists(const char * const path) { selectByName(*diveDir, fname); diveDir->close(); } - return fname != nullptr; + return !!fname; } // @@ -684,7 +684,7 @@ void CardReader::write_command(char * const buf) { char* end = buf + strlen(buf) - 1; file.writeError = false; - if ((npos = strchr(buf, 'N')) != nullptr) { + if ((npos = strchr(buf, 'N'))) { begin = strchr(npos, ' ') + 1; end = strchr(npos, '*') - 1; } diff --git a/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp b/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp index 8a989157b4..f26e82b9c7 100644 --- a/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp +++ b/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp @@ -22,7 +22,10 @@ * Web : https://www.circuitsathome.com * e-mail : support@circuitsathome.com */ -/* USB functions */ + +// +// USB functions supporting Flash Drive +// #include "../../../inc/MarlinConfigPre.h" @@ -35,7 +38,7 @@ static uint8_t usb_task_state; /* constructor */ USB::USB() : bmHubPre(0) { - usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; //set up state machine + usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; // Set up state machine init(); } @@ -45,13 +48,8 @@ void USB::init() { bmHubPre = 0; } -uint8_t USB::getUsbTaskState() { - return usb_task_state; -} - -void USB::setUsbTaskState(uint8_t state) { - usb_task_state = state; -} +uint8_t USB::getUsbTaskState() { return usb_task_state; } +void USB::setUsbTaskState(uint8_t state) { usb_task_state = state; } EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) { UsbDevice *p = addrPool.GetUsbDevicePtr(addr); @@ -70,9 +68,11 @@ EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) { return nullptr; } -/* set device table entry */ - -/* each device is different and has different number of endpoints. This function plugs endpoint record structure, defined in application, to devtable */ +/** + * Set device table entry + * Each device is different and has different number of endpoints. + * This function plugs endpoint record structure, defined in application, to devtable + */ uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr) { if (!eprecord_ptr) 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 USBTRACE2(" NAK Limit: ", nak_limit); USBTRACE("\r\n"); */ - regWr(rPERADDR, addr); //set peripheral address + regWr(rPERADDR, addr); // Set peripheral address uint8_t mode = regRd(rMODE); @@ -121,8 +121,6 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l //Serial.print("\r\nLS: "); //Serial.println(p->lowspeed, HEX); - - // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED)); @@ -133,11 +131,10 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l /* depending on request. Actual requests are defined as inlines */ /* return codes: */ /* 00 = success */ - /* 01-0f = non-zero HRSLT */ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p) { - bool direction = false; //request direction, IN or OUT + bool direction = false; // Request direction, IN or OUT uint8_t rcode; SETUP_PKT setup_pkt; @@ -157,15 +154,15 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque setup_pkt.wIndex = wInd; setup_pkt.wLength = total; - bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); //transfer to setup packet FIFO + bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); // Transfer to setup packet FIFO - rcode = dispatchPkt(tokSETUP, ep, nak_limit); //dispatch packet + rcode = dispatchPkt(tokSETUP, ep, nak_limit); // Dispatch packet if (rcode) return rcode; // Return HRSLT if not zero - if (dataptr != nullptr) { //data stage, if present - if (direction) { //IN transfer + if (dataptr) { // Data stage, if present + if (direction) { // IN transfer uint16_t left = total; - pep->bmRcvToggle = 1; //bmRCVTOG1; + pep->bmRcvToggle = 1; // BmRCVTOG1; while (left) { // Bytes read into buffer @@ -174,7 +171,7 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque rcode = InTransfer(pep, nak_limit, &read, dataptr); if (rcode == hrTOGERR) { - // yes, we flip it wrong here so that next time it is actually correct! + // Yes, we flip it wrong here so that next time it is actually correct! pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; continue; } @@ -189,21 +186,21 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque if (read < nbytes) break; } } - else { //OUT transfer - pep->bmSndToggle = 1; //bmSNDTOG1; + else { // OUT transfer + pep->bmSndToggle = 1; // BmSNDTOG1; rcode = OutTransfer(pep, nak_limit, nbytes, dataptr); } - if (rcode) return rcode; // return error + if (rcode) return rcode; // Return error } // Status stage - return dispatchPkt((direction) ? tokOUTHS : tokINHS, ep, nak_limit); //GET if direction + return dispatchPkt((direction) ? tokOUTHS : tokINHS, ep, nak_limit); // GET if direction } -/* IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ -/* Keep sending INs and writes data to memory area pointed by 'data' */ - -/* rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, - fe USB xfer timeout */ +/** + * IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. + * Keep sending INs and writes data to memory area pointed by 'data' + * rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, fe = USB xfer timeout + */ uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) { EpInfo *pep = nullptr; uint16_t nak_limit = 0; @@ -227,29 +224,29 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui uint8_t maxpktsize = pep->maxPktSize; *nbytesptr = 0; - regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value + regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); // Set toggle value - // use a 'break' to exit this loop + // Use a 'break' to exit this loop for (;;) { - rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS. + rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); // IN packet to EP-'endpoint'. Function takes care of NAKS. if (rcode == hrTOGERR) { - // yes, we flip it wrong here so that next time it is actually correct! + // Yes, we flip it wrong here so that next time it is actually correct! pep->bmRcvToggle = (regRd(rHRSL) & bmRCVTOGRD) ? 0 : 1; - regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value + regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); // Set toggle value continue; } if (rcode) { //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode); - break; //should be 0, indicating ACK. Else return error code. + break; // Should be 0, indicating ACK. Else return error code. } /* check for RCVDAVIRQ and generate error if not present */ /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */ if ((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) { //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n"); - rcode = 0xF0; //receive error + rcode = 0xF0; // Receive error break; } - pktsize = regRd(rRCVBC); //number of received bytes + pktsize = regRd(rRCVBC); // Number of received bytes //printf("Got %i bytes \r\n", pktsize); // This would be OK, but... //assert(pktsize <= nbytes); @@ -266,7 +263,7 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data); regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer - *nbytesptr += pktsize; // add this packet's byte count to total transfer length + *nbytesptr += pktsize; // Add this packet's byte count to total transfer length /* The transfer is complete under two conditions: */ /* 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 return rcode; } -/* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ -/* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer */ - -/* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */ +/** + * OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. + * Handles NAK bug per Maxim Application Note 4000 for single buffer transfer + * rcode 0 if no errors. rcode 01-0f is relayed from HRSL + */ uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) { EpInfo *pep = nullptr; 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 uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) { uint8_t rcode = hrSUCCESS, retry_count; - uint8_t *data_p = data; //local copy of the data pointer + uint8_t *data_p = data; // Local copy of the data pointer uint16_t bytes_tosend, nak_count; uint16_t bytes_left = nbytes; @@ -311,17 +309,17 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT; - regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value + regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); // Set toggle value while (bytes_left) { retry_count = 0; nak_count = 0; bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left; - bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO - regWr(rSNDBC, bytes_tosend); //set number of bytes - regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet - while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ - regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ + bytesWr(rSNDFIFO, bytes_tosend, data_p); // Filling output FIFO + regWr(rSNDBC, bytes_tosend); // Set number of bytes + regWr(rHXFR, (tokOUT | pep->epAddr)); // Dispatch packet + while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); // Wait for the completion IRQ + regWr(rHIRQ, bmHXFRDNIRQ); // Clear IRQ rcode = (regRd(rHRSL) & 0x0F); 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 nak_count++; if (nak_limit && (nak_count == nak_limit)) goto breakout; - //return ( rcode); + //return rcode; break; case hrTIMEOUT: retry_count++; if (retry_count == USB_RETRY_LIMIT) goto breakout; - //return ( rcode); + //return rcode; break; case hrTOGERR: - // yes, we flip it wrong here so that next time it is actually correct! + // Yes, we flip it wrong here so that next time it is actually correct! pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; - regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value + regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); // Set toggle value break; default: goto breakout; @@ -351,26 +349,27 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 regWr(rSNDBC, 0); regWr(rSNDFIFO, *data_p); regWr(rSNDBC, bytes_tosend); - regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet - while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ - regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ + regWr(rHXFR, (tokOUT | pep->epAddr)); // Dispatch packet + while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); // Wait for the completion IRQ + regWr(rHIRQ, bmHXFRDNIRQ); // Clear IRQ rcode = (regRd(rHRSL) & 0x0F); - } // while rcode && .... + } // While rcode && .... bytes_left -= bytes_tosend; data_p += bytes_tosend; - } // while bytes_left... + } // While bytes_left... breakout: - pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; //bmSNDTOG1 : bmSNDTOG0; //update toggle - return ( rcode); //should be 0 in all cases + pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; // BmSNDTOG1 : bmSNDTOG0; // Update toggle + return ( rcode); // Should be 0 in all cases } -/* dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty */ -/* If NAK, tries to re-send up to nak_limit times */ -/* If nak_limit == 0, do not count NAKs, exit after timeout */ -/* If bus timeout, re-sends up to USB_RETRY_LIMIT times */ - -/* return codes 0x00-0x0F are HRSLT( 0x00 being success ), 0xFF means timeout */ +/** + * Dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty + * If NAK, tries to re-send up to nak_limit times + * If nak_limit == 0, do not count NAKs, exit after timeout + * If bus timeout, re-sends up to USB_RETRY_LIMIT times + * return codes 0x00-0x0F are HRSLT( 0x00 being success ), 0xFF means timeout + */ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT; uint8_t tmpdata; @@ -380,29 +379,28 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { while ((int32_t)((uint32_t)millis() - timeout) < 0L) { #if defined(ESP8266) || defined(ESP32) - yield(); // needed in order to reset the watchdog timer on the ESP8266 + yield(); // Needed in order to reset the watchdog timer on the ESP8266 #endif - regWr(rHXFR, (token | ep)); //launch the transfer + regWr(rHXFR, (token | ep)); // Launch the transfer rcode = USB_ERROR_TRANSFER_TIMEOUT; - while ((int32_t)((uint32_t)millis() - timeout) < 0L) { //wait for transfer completion + while ((int32_t)((uint32_t)millis() - timeout) < 0L) { // Wait for transfer completion #if defined(ESP8266) || defined(ESP32) - yield(); // needed to reset the watchdog timer on the ESP8266 + yield(); // Needed to reset the watchdog timer on the ESP8266 #endif tmpdata = regRd(rHIRQ); if (tmpdata & bmHXFRDNIRQ) { - regWr(rHIRQ, bmHXFRDNIRQ); //clear the interrupt + regWr(rHIRQ, bmHXFRDNIRQ); // Clear the interrupt rcode = 0x00; break; } - } // while millis() < timeout + } // While millis() < timeout - //if (rcode != 0x00) //exit if timeout - // return ( rcode); + //if (rcode != 0x00) return rcode; // Exit if timeout - rcode = (regRd(rHRSL) & 0x0F); //analyze transfer result + rcode = (regRd(rHRSL) & 0x0F); // Analyze transfer result switch (rcode) { case hrNAK: @@ -419,12 +417,12 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { return (rcode); } - } // while timeout > millis() + } // While timeout > millis() return rcode; } -/* USB main task. Performs enumeration/cleanup */ -void USB::Task() { //USB state machine +// USB main task. Performs enumeration/cleanup +void USB::Task() { // USB state machine uint8_t rcode; uint8_t tmpdata; static uint32_t delay = 0; @@ -437,19 +435,19 @@ void USB::Task() { //USB state machine /* modify USB task state if Vbus changed */ switch (tmpdata) { - case SE1: //illegal state + case SE1: // Illegal state usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL; lowspeed = false; break; - case SE0: //disconnected + case SE0: // Disconnected if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED) usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; lowspeed = false; break; case LSHOST: lowspeed = true; - //intentional fallthrough - case FSHOST: //attached + // Intentional fallthrough + case FSHOST: // Attached if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) { delay = (uint32_t)millis() + USB_SETTLE_DELAY; usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE; @@ -470,31 +468,31 @@ void USB::Task() { //USB state machine usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE; break; - case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: //just sit here + case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: // Just sit here break; - case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here + case USB_DETACHED_SUBSTATE_ILLEGAL: // Just sit here break; - case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device + case USB_ATTACHED_SUBSTATE_SETTLE: // Settle time for just attached device if ((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE; - else break; // don't fall through + else break; // Don't fall through case USB_ATTACHED_SUBSTATE_RESET_DEVICE: - regWr(rHCTL, bmBUSRST); //issue bus reset + regWr(rHCTL, bmBUSRST); // Issue bus reset usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE; break; case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE: if ((regRd(rHCTL) & bmBUSRST) == 0) { - tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation + tmpdata = regRd(rMODE) | bmSOFKAENAB; // Start SOF generation regWr(rMODE, tmpdata); usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF; - //delay = (uint32_t)millis() + 20; //20ms wait after reset per USB spec + //delay = (uint32_t)millis() + 20; // 20ms wait after reset per USB spec } break; - case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order + case USB_ATTACHED_SUBSTATE_WAIT_SOF: // Todo: change check order if (regRd(rHIRQ) & bmFRAMEIRQ) { - //when first SOF received _and_ 20ms has passed we can continue + // When first SOF received _and_ 20ms has passed we can continue /* - if (delay < (uint32_t)millis()) //20ms passed + if (delay < (uint32_t)millis()) // 20ms passed usb_task_state = USB_STATE_CONFIGURING; */ usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET; @@ -503,7 +501,7 @@ void USB::Task() { //USB state machine break; case USB_ATTACHED_SUBSTATE_WAIT_RESET: if ((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; - else break; // don't fall through + else break; // Don't fall through case USB_STATE_CONFIGURING: //Serial.print("\r\nConf.LS: "); @@ -565,11 +563,11 @@ again: if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) { if (parent == 0) { // Send a bus reset on the root interface. - regWr(rHCTL, bmBUSRST); //issue bus reset - delay(102); // delay 102ms, compensate for clock inaccuracy. + regWr(rHCTL, bmBUSRST); // Issue bus reset + delay(102); // Delay 102ms, compensate for clock inaccuracy. } else { - // reset parent port + // Reset parent port devConfig[parent]->ResetHubPort(port); } } @@ -592,11 +590,11 @@ again: // Issue a bus reset, because the device may be in a limbo state if (parent == 0) { // Send a bus reset on the root interface. - regWr(rHCTL, bmBUSRST); //issue bus reset - delay(102); // delay 102ms, compensate for clock inaccuracy. + regWr(rHCTL, bmBUSRST); // Issue bus reset + delay(102); // Delay 102ms, compensate for clock inaccuracy. } else { - // reset parent port + // Reset parent port devConfig[parent]->ResetHubPort(port); } } @@ -623,19 +621,19 @@ again: * 4: set address * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail * 6: while (configurations) { - * for (each configuration) { - * for (each driver) { - * 6a: Ask device if it likes configuration. Returns 0 on OK. - * If successful, the driver configured device. - * The driver now owns the endpoints, and takes over managing them. - * The following will need codes: - * Everything went well, instance consumed, exit with success. - * Instance already in use, ignore it, try next driver. - * Not a supported device, ignore it, try next driver. - * Not a supported configuration for this device, ignore it, try next driver. - * Could not configure device, fatal, exit with fail. - * } - * } + * for (each configuration) { + * for (each driver) { + * 6a: Ask device if it likes configuration. Returns 0 on OK. + * If successful, the driver configured device. + * The driver now owns the endpoints, and takes over managing them. + * The following will need codes: + * Everything went well, instance consumed, exit with success. + * Instance already in use, ignore it, try next driver. + * Not a supported device, ignore it, try next driver. + * Not a supported configuration for this device, ignore it, try next driver. + * Could not configure device, fatal, exit with fail. + * } + * } * } * 7: for (each driver) { * 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) { oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to - // avoid toggle inconsistence + // Avoid toggle inconsistence p->epinfo = &epInfo; @@ -687,7 +685,7 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { return rcode; } - // to-do? + // To-do? // Allocate new address according to device class //bAddress = addrPool.AllocAddress(parent, false, port); @@ -698,11 +696,11 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { // Qualify with subclass too. // // VID/PID & class tests default to false for drivers not yet ported - // subclass defaults to true, so you don't have to define it if you don't have to. + // Subclass defaults to true, so you don't have to define it if you don't have to. // for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { - if (!devConfig[devConfigIndex]) continue; // no driver - if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed + if (!devConfig[devConfigIndex]) continue; // No driver + if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) { rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); 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) { if (devConfigIndex < USB_NUMDEVICES) return rcode; - // blindly attempt to configure + // Blindly attempt to configure for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { if (!devConfig[devConfigIndex]) continue; - if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed + if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed 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 rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); //printf("ERROR ENUMERATING %2.2x\r\n", rcode); if (!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) { - // in case of an error dev_index should be reset to 0 - // in order to start from the very beginning the - // next time the program gets here + // In case of an error dev_index should be reset to 0 + // in order to start from the very beginning the + // next time the program gets here //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE) - // devConfigIndex = 0; + //devConfigIndex = 0; return rcode; } } @@ -744,20 +742,22 @@ uint8_t USB::ReleaseDevice(uint8_t addr) { return 0; } -#if 1 //!defined(USB_METHODS_INLINE) -//get device descriptor - +// Get device descriptor uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) { return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, nullptr); } -//get configuration descriptor +// Get configuration descriptor uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) { return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, nullptr); } -/* 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 - 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 */ +/** + * 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 + * 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. + */ uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) { const uint8_t bufSize = 64; uint8_t buf[bufSize]; @@ -773,25 +773,23 @@ uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p); } -//get string descriptor - +// Get string descriptor uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) { return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, ns, ns, dataptr, nullptr); } -//set address +// Set address uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) { uint8_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr); - //delay(2); //per USB 2.0 sect.9.2.6.3 + //delay(2); // Per USB 2.0 sect.9.2.6.3 delay(300); // Older spec says you should wait at least 200ms return rcode; //return ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr); } -//set configuration +// Set configuration uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) { return ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr); } -#endif // defined(USB_METHODS_INLINE) #endif // USB_FLASH_DRIVE_SUPPORT