diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 8cc00fa2..d5b89029 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -46,7 +46,7 @@ body: - type: input attributes: label: TinyUSB Library version - placeholder: "Release version or github latest" + placeholder: "Release version or commit SHA" validations: required: true diff --git a/examples/MassStorage/msc_external_flash_sdcard/msc_external_flash_sdcard.ino b/examples/MassStorage/msc_external_flash_sdcard/msc_external_flash_sdcard.ino index 3d9fc413..4b7b6e15 100644 --- a/examples/MassStorage/msc_external_flash_sdcard/msc_external_flash_sdcard.ino +++ b/examples/MassStorage/msc_external_flash_sdcard/msc_external_flash_sdcard.ino @@ -45,8 +45,13 @@ FatVolume fatfs; #if defined(ARDUINO_PYPORTAL_M4) || defined(ARDUINO_PYPORTAL_M4_TITANO) // PyPortal has on-board card reader - #define SDCARD_CS 32 - #define SDCARD_DETECT 33 + #define SDCARD_CS 32 + #define SDCARD_DETECT 33 + #define SDCARD_DETECT_ACTIVE HIGH +#elif defined(ARDUINO_ADAFRUIT_METRO_RP2040) + #define SDCARD_CS 23 + #define SDCARD_DETECT 15 + #define SDCARD_DETECT_ACTIVE LOW #else #define SDCARD_CS 10 // no detect @@ -113,17 +118,15 @@ void setup() { usb_msc.setUnitReady(1, true); #endif -// while ( !Serial ) delay(10); // wait for native usb + // while ( !Serial ) delay(10); // wait for native usb Serial.println("Adafruit TinyUSB Mass Storage External Flash + SD Card example"); delay(1000); } -bool init_sdcard(void) -{ +bool init_sdcard(void) { Serial.print("Init SDCard ... "); - if ( !sd.begin(SDCARD_CS, SD_SCK_MHZ(50)) ) - { + if (!sd.begin(SDCARD_CS, SD_SCK_MHZ(50))) { Serial.print("Failed "); sd.errorPrint("sd.begin() failed"); @@ -138,33 +141,29 @@ bool init_sdcard(void) block_count = sd.card()->cardSize(); #endif - usb_msc.setCapacity(1, block_count, 512); usb_msc.setReadWriteCallback(1, sdcard_read_cb, sdcard_write_cb, sdcard_flush_cb); sd_changed = true; // to print contents initially Serial.print("OK, Card size = "); - Serial.print((block_count / (1024*1024)) * 512); + Serial.print((block_count / (1024 * 1024)) * 512); Serial.println(" MB"); return true; } -void print_rootdir(File32* rdir) -{ +void print_rootdir(File32* rdir) { File32 file; // Open next file in root. // Warning, openNext starts at the current directory position // so a rewind of the directory may be required. - while ( file.openNext(rdir, O_RDONLY) ) - { + while (file.openNext(rdir, O_RDONLY)) { file.printFileSize(&Serial); Serial.write(' '); file.printName(&Serial); - if ( file.isDir() ) - { + if (file.isDir()) { // Indicate a directory. Serial.write('/'); } @@ -173,18 +172,14 @@ void print_rootdir(File32* rdir) } } -void loop() -{ - if ( flash_changed ) - { - if (!flash_formatted) - { +void loop() { + if (flash_changed) { + if (!flash_formatted) { flash_formatted = fatfs.begin(&flash); } // skip if still not formatted - if (flash_formatted) - { + if (flash_formatted) { File32 root; root = fatfs.open("/"); @@ -198,8 +193,7 @@ void loop() flash_changed = false; } - if ( sd_changed ) - { + if (sd_changed) { File32 root; root = sd.open("/"); @@ -275,18 +269,14 @@ void sdcard_flush_cb (void) #ifdef SDCARD_DETECT // Invoked when received Test Unit Ready command. // return true allowing host to read/write this LUN e.g SD card inserted -bool sdcard_ready_callback(void) -{ +bool sdcard_ready_callback(void) { // Card is inserted - if ( digitalRead(SDCARD_DETECT) == HIGH ) - { + if (digitalRead(SDCARD_DETECT) == SDCARD_DETECT_ACTIVE) { // init SD card if not already - if ( !sd_inited ) - { + if (!sd_inited) { sd_inited = init_sdcard(); } - }else - { + } else { sd_inited = false; usb_msc.setReadWriteCallback(1, NULL, NULL, NULL); } diff --git a/examples/MassStorage/msc_sdfat/msc_sdfat.ino b/examples/MassStorage/msc_sdfat/msc_sdfat.ino index 014dac20..619971eb 100644 --- a/examples/MassStorage/msc_sdfat/msc_sdfat.ino +++ b/examples/MassStorage/msc_sdfat/msc_sdfat.ino @@ -10,14 +10,30 @@ *********************************************************************/ /* This example expose SD card as mass storage using - * SdFat Library + * - SdFat https://github.com/adafruit/SdFat */ #include "SPI.h" #include "SdFat_Adafruit_Fork.h" #include "Adafruit_TinyUSB.h" -const int chipSelect = 10; +//--------------------------------------------------------------------+ +// SDCard Config +//--------------------------------------------------------------------+ + +#if defined(ARDUINO_PYPORTAL_M4) || defined(ARDUINO_PYPORTAL_M4_TITANO) + // PyPortal has on-board card reader + #define SDCARD_CS 32 + #define SDCARD_DETECT 33 + #define SDCARD_DETECT_ACTIVE HIGH +#elif defined(ARDUINO_ADAFRUIT_METRO_RP2040) + #define SDCARD_CS 23 + #define SDCARD_DETECT 15 + #define SDCARD_DETECT_ACTIVE LOW +#else + #define SDCARD_CS 10 + // no detect +#endif // File system on SD Card SdFat sd; @@ -57,16 +73,16 @@ void setup() { TinyUSBDevice.attach(); } - //while ( !Serial ) delay(10); // wait for native usb + while ( !Serial ) delay(10); // wait for native usb Serial.println("Adafruit TinyUSB Mass Storage SD Card example"); Serial.print("\nInitializing SD card ... "); - Serial.print("CS = "); Serial.println(chipSelect); + Serial.print("CS = "); Serial.println(SDCARD_CS); - if ( !sd.begin(chipSelect, SD_SCK_MHZ(50)) ) { + if ( !sd.begin(SDCARD_CS, SD_SCK_MHZ(50)) ) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card inserted?"); Serial.println("* is your wiring correct?"); - Serial.println("* did you change the chipSelect pin to match your shield or module?"); + Serial.println("* did you change the SDCARD_CS pin to match your shield or module?"); while (1) delay(1); } diff --git a/library.json b/library.json index f96b09e9..b4214347 100644 --- a/library.json +++ b/library.json @@ -2,7 +2,7 @@ "name": "Adafruit TinyUSB Library", "keywords": "usb, arduino, tinyusb", "description": "Arduino library for TinyUSB", - "version": "3.4.5", + "version": "3.6.0", "repository": { "type": "git", "url": "https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git" diff --git a/library.properties b/library.properties index 9c8cba2c..96c7c37b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit TinyUSB Library -version=3.5.0 +version=3.6.0 author=Adafruit maintainer=Adafruit sentence=TinyUSB library for Arduino diff --git a/src/arduino/Adafruit_USBD_Device.cpp b/src/arduino/Adafruit_USBD_Device.cpp index b6d10687..b044e15e 100644 --- a/src/arduino/Adafruit_USBD_Device.cpp +++ b/src/arduino/Adafruit_USBD_Device.cpp @@ -186,7 +186,7 @@ void Adafruit_USBD_Device::clearConfiguration(void) { uint8_t const dev_cfg[sizeof(tusb_desc_configuration_t)] = { TUD_CONFIG_DESCRIPTOR(1, 0, 0, sizeof(tusb_desc_configuration_t), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP | TU_BIT(7), - 100), + USB_CONFIG_POWER), }; memcpy(_desc_cfg_buffer, dev_cfg, sizeof(tusb_desc_configuration_t)); diff --git a/src/arduino/Adafruit_USBD_Device.h b/src/arduino/Adafruit_USBD_Device.h index 0033ca96..48c4d384 100644 --- a/src/arduino/Adafruit_USBD_Device.h +++ b/src/arduino/Adafruit_USBD_Device.h @@ -80,6 +80,21 @@ class Adafruit_USBD_Device { // Clear/Reset configuration descriptor void clearConfiguration(void); + // Set configuration attribute + void setConfigurationAttribute(uint8_t attribute) { + _desc_cfg[offsetof(tusb_desc_configuration_t, bmAttributes)] = attribute; + } + + // Set max power consumption in mA (absolute max is 510ma) + bool setConfigurationMaxPower(uint16_t power_ma) { + if (power_ma > 255 * 2u) { + return false; + } + _desc_cfg[offsetof(tusb_desc_configuration_t, bMaxPower)] = + (uint8_t)(power_ma / 2); + return true; + } + // Provide user buffer for configuration descriptor, if total length > 256 void setConfigurationBuffer(uint8_t *buf, uint32_t buflen);