@@ -58,6 +58,7 @@ Adafruit_FlashTransport_RP2040 flashTransport_v2;
5858Adafruit_SPIFlash flash_v2 (&flashTransport_v2); // /< SPIFlash object
5959FatVolume wipperFatFs_v2; // /< File system object from Adafruit SDFat library
6060Adafruit_USBD_MSC usb_msc_v2; /* !< USB mass storage object */
61+ Adafruit_USBD_CDC usb_cdc; /* !< USB CDC object */
6162static bool _fs_changed = false ;
6263
6364/* *************************************************************************/
@@ -104,10 +105,15 @@ FRESULT format_fs_fat12(void) {
104105/* *************************************************************************/
105106Wippersnapper_FS::Wippersnapper_FS () {
106107 _fs_changed = false ;
107- // Detach USB device during init.
108- TinyUSBDevice.detach ();
109- // Wait for detach
110- delay (500 );
108+
109+ usb_cdc.begin (115200 );
110+ // If already enumerated, additional class driver begin() e.g msc, hid, midi
111+ // won't take effect until re-enumeration
112+ if (TinyUSBDevice.mounted ()) {
113+ TinyUSBDevice.detach ();
114+ delay (10 );
115+ TinyUSBDevice.attach ();
116+ }
111117
112118 // Attempt to initialize the flash chip
113119 if (!flash_v2.begin ()) {
@@ -282,22 +288,22 @@ void Wippersnapper_FS::InitUsbMsc() {
282288 usb_msc_v2.setCapacity (flash_v2.pageSize () * flash_v2.numPages () / 512 , 512 );
283289
284290 // MSC is ready for read/write
285- usb_msc_v2.setUnitReady (true );
291+ usb_msc_v2.setUnitReady (false );
286292
287293 // Set callback when MSC ready
288294 _fs_changed = false ;
289295 usb_msc_v2.setReadyCallback (0 , msc_ready_callback);
290296
291297 // init MSC
292- usb_msc_v2.begin ();
298+ // usb_msc_v2.begin();
293299
294- // If already enumerated, additional class driverr begin() e.g msc, hid, midi
295- // won't take effect until re-enumeration
296- // Attach MSC and wait for enumeration
297- // #ifndef BUILD_OFFLINE_ONLY
300+ // If already enumerated, additional class driverr begin() e.g msc, hid, midi
301+ // won't take effect until re-enumeration
302+ // Attach MSC and wait for enumeration
303+ // #ifndef BUILD_OFFLINE_ONLY
298304 TinyUSBDevice.attach ();
299305 delay (500 );
300- // #endif
306+ // #endif
301307}
302308
303309/* *************************************************************************/
@@ -382,7 +388,7 @@ void Wippersnapper_FS::CreateFileConfig() {
382388 if (file_cfg) {
383389 DeserializationError error = deserializeJson (_doc_cfg, file_cfg);
384390 // if (error)
385- // HaltFilesystem("Error unable to parse config.json on WIPPER drive!");
391+ // HaltFilesystem("Error unable to parse config.json on WIPPER drive!");
386392 // Remove config from the filesystem
387393 file_cfg.close ();
388394 wipperFatFs_v2.remove (" /config.json" );
@@ -488,8 +494,13 @@ bool Wippersnapper_FS::WriteFileConfig() {
488494 // Re-attach USB-MSC with updated filesystem
489495 // NOTE: This is required to ensure the filesystem is sync'd between host and
490496 // device
491- // TinyUSBDevice.attach();
492- delay (2500 );
497+ usb_msc_v2.begin ();
498+ usb_msc_v2.setUnitReady (true );
499+ if (TinyUSBDevice.mounted ()) {
500+ TinyUSBDevice.detach ();
501+ delay (10 );
502+ TinyUSBDevice.attach ();
503+ }
493504 // TODO: This is debug, we can remove it!
494505 WS_DEBUG_PRINT (" Bytes written to config.json: " );
495506 WS_DEBUG_PRINTLN (bytes_written);
0 commit comments