Good Morning all including Paul, mjs513, wwatson ... : (maybe) Probably afternoon by the time I type this
Sorry in advance it probably will be reasonably long.
Now that a lot of the FS only stuff. I was thinking about how best to integrate the MSC functionality into the system and how to then if desired to expose disks or volumes through MTP.
this is integrated and interpreting some previous comments, that were either on forum or email...
@Paul @wwatson @mjs513 - Hopefully I am not too far off and understanding and maybe direction to go.
Currently in the
USBHost library there is a class: msController that is a "normal" USBHost object, that is setup to handle when a Storage device like hard disk, or Memory Stick is plugged in. So the normal USB enumeration stuff happens here and for example if your code is setup to include:
Code:
#include "USBHost_t36.h"
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
msController msDrive1(myusb);
msController msDrive2(myusb);
When the first drive is plugged in, then likely the msDrive1 one will bool function will return true... And the code does all of the necessary stuff to talk to the drive at a low level (SCSI)...
Then there is the code in the library
UsbMscFat (MSC), which deals with the actual storages on the disk, which I subdivide into two (maybe more) pieces
There is the PFsLib - portion, which is very much like the FsLib in SDFat. The main difference is that PFsLib works with Partitions, so for example the formatting code you pass in a partition number and it only formats that partition. Whereas SDFat format code will format the entire drive as one partition regardless of if the drive was previously setup with partitions.
Will be interesting to see where this code should reside.
Then the rest of the library has to do with then taking the one or more logical Drive objects and using them.
In the
mscFS.h file There is the MSCClass which is derived from FS.
The begin method of the MSCClass you pass it in one of the msController objects as well as optionally which partition this object should work with... And from here you have the normal FS capabilities like file open...
So current MTP integration, we do something like define an array of 3 "Drive" objects and lets say 8 of the Volume objects and then we have code we run at loop time, to scan which drives have changed state (connected or removed) and check in the connected state, if this drive has partitions, then we iterate through calling the begin for the next free volume object... If drive went away we check for any volumes that were using that drive and close them...
Another option might be: Sorry if not completely fleshed out:
Suppose we have the sketch setup as:
Code:
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
msController msDrive1(myusb);
msController msDrive2(myusb);
msVolume msVol1(myusb);
msVolume msVol2(myusb);
msVolume msVol3(myusb);
msVolume msVol4(myusb);
msVolume msVol5(myusb);
Each of these drives and volumes at creation time link themselves into lists...
Then when USBHost code detects the new drive, it works like current stuff and finds an unused msController object, and claims it like today. Then potentially this code could in theory, check for MBR and if it has one, it could iterate over the partitions, and if they are types we can handle and we have a free volume object, then volume object would be claimed by that controller object...
And in the end user code can detect if drives or volumes are there by boolean test...
Does this make sense? Should we instead of having to declare Volume object simply have them magically be created? Or should each Controller object have setup lets say 4 such objects...
Then there is the other half of the issue associated with MTP.
So MSC just found a new drive with two partitions. How does MTP get notified of this? Of course this is also similar to how should we handle SD drives which did not have a card in it and we now detected that now there is...
Should the user code call addStorage for all 5 of these volumes at setup time, and have them show up as not valid? Or should the appear when a drive is plugged in...
Lots more to this, but wondering what directions we should aim toward?