@@ -58,6 +58,7 @@ Adafruit_FlashTransport_RP2040 flashTransport_v2;
58
58
Adafruit_SPIFlash flash_v2 (&flashTransport_v2); // /< SPIFlash object
59
59
FatVolume wipperFatFs_v2; // /< File system object from Adafruit SDFat library
60
60
Adafruit_USBD_MSC usb_msc_v2; /* !< USB mass storage object */
61
+ Adafruit_USBD_CDC usb_cdc; /* !< USB CDC object */
61
62
static bool _fs_changed = false ;
62
63
63
64
/* *************************************************************************/
@@ -104,10 +105,15 @@ FRESULT format_fs_fat12(void) {
104
105
/* *************************************************************************/
105
106
Wippersnapper_FS::Wippersnapper_FS () {
106
107
_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
+ }
111
117
112
118
// Attempt to initialize the flash chip
113
119
if (!flash_v2.begin ()) {
@@ -282,22 +288,22 @@ void Wippersnapper_FS::InitUsbMsc() {
282
288
usb_msc_v2.setCapacity (flash_v2.pageSize () * flash_v2.numPages () / 512 , 512 );
283
289
284
290
// MSC is ready for read/write
285
- usb_msc_v2.setUnitReady (true );
291
+ usb_msc_v2.setUnitReady (false );
286
292
287
293
// Set callback when MSC ready
288
294
_fs_changed = false ;
289
295
usb_msc_v2.setReadyCallback (0 , msc_ready_callback);
290
296
291
297
// init MSC
292
- usb_msc_v2.begin ();
298
+ // usb_msc_v2.begin();
293
299
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
298
304
TinyUSBDevice.attach ();
299
305
delay (500 );
300
- // #endif
306
+ // #endif
301
307
}
302
308
303
309
/* *************************************************************************/
@@ -382,7 +388,7 @@ void Wippersnapper_FS::CreateFileConfig() {
382
388
if (file_cfg) {
383
389
DeserializationError error = deserializeJson (_doc_cfg, file_cfg);
384
390
// if (error)
385
- // HaltFilesystem("Error unable to parse config.json on WIPPER drive!");
391
+ // HaltFilesystem("Error unable to parse config.json on WIPPER drive!");
386
392
// Remove config from the filesystem
387
393
file_cfg.close ();
388
394
wipperFatFs_v2.remove (" /config.json" );
@@ -488,8 +494,13 @@ bool Wippersnapper_FS::WriteFileConfig() {
488
494
// Re-attach USB-MSC with updated filesystem
489
495
// NOTE: This is required to ensure the filesystem is sync'd between host and
490
496
// 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
+ }
493
504
// TODO: This is debug, we can remove it!
494
505
WS_DEBUG_PRINT (" Bytes written to config.json: " );
495
506
WS_DEBUG_PRINTLN (bytes_written);
0 commit comments