electro-smith / libDaisy

Hardware Library for the Daisy Audio Platform
https://www.electro-smith.com/daisy
MIT License
314 stars 131 forks source link

FatFS Integration for USB and/or SDMMC #448

Closed stephenhensley closed 2 years ago

stephenhensley commented 2 years ago

Builds off of the work done by @CorvusPrudens in #434

Made a few changes:

For a usage for SD and/or USB example:

    /** Init the SD card you want to use */
    SdmmcHandler::Config sd_cfg;
    sd_cfg.Defaults();
    sdcard.Init(sd_cfg);

    /** Init USB drive */
    MSDHandle::Config usbcfg;
    usb.Init(usbcfg);
    /** And wait until ready -- this could/should probably turn into a callback? */
    while(!usb.GetReady())
        usb.Process();

    /** Link Daisy to FatFS configured for SD card 
     *  Once this is done, FatFS can be used as usual. */
    FatFSInterface::Config fsi_cfg;
    fsi_cfg.media
        = FatFSInterface::Config::MEDIA_USB | FatFSInterface::Config::MEDIA_SD;
    fs_inf.Init(fsi_cfg);

    /** Get the path to the root directory we want to use:
     *  0:/ is the first, registered path
     *  1:/ is the second registered path .
     * 
     *  volume registration occurs in the order presented in the FatFSInterface::Config::Media enum
     *  i.e. 0:/ is the SD card , and 1:/ is the USB drive if both are used.
     * 
     *  When only one volume is used it will always be at 0:/
     */
    const char* rootpath = fs_inf.GetUSBPath();

    FATFS& fs = fs_inf.GetUSBFileSystem();

    /** Mount the FATFS filesystem */
    f_mount(&fs, rootpath, 1);

I don't necessarily like that the user has to manage all three pieces on their own, but with the ability to configure the SDMMC hardware, I'm not sure there's a better solution.

I'd also like to avoid providing wrappers for all of fatfs since it's well documented on it's own, and very easy to work with.

Open to ideas on simplification, and improvement, but this works.

github-actions[bot] commented 2 years ago

Unit Test Results

    1 files  ±0    15 suites  ±0   0s :stopwatch: ±0s 141 tests ±0  141 :heavy_check_mark: ±0  0 :zzz: ±0  0 :x: ±0 

Results for commit 1f198ce3. ± Comparison against base commit 029bad7a.

:recycle: This comment has been updated with latest results.

stephenhensley commented 2 years ago

TODO: