-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Storage.Devices to support ESP32 mount operations (#32)
- Loading branch information
1 parent
fd72f8a
commit 9e23526
Showing
8 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
|
||
namespace Windows.Storage | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IStorageProvider | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
|
||
namespace Windows.Storage.Devices | ||
{ | ||
/// <summary> | ||
/// Class to allow a single SDCard to be mounted on the system. | ||
/// Only allows for 1 device to be mounted, either via MMC or SPI | ||
/// </summary> | ||
public static class SDCard | ||
{ | ||
|
||
#pragma warning disable 0649 | ||
|
||
// this field is set in native code | ||
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] | ||
private static bool _mounted = false; | ||
|
||
#pragma warning restore 0649 | ||
|
||
/// <summary> | ||
/// Indcates if the SDscard has been mounted | ||
/// </summary> | ||
public static bool IsMounted => _mounted; | ||
|
||
/// <summary> | ||
/// Mount the SDcard device on the MMC interface | ||
/// </summary> | ||
/// <param name="Data1bit">If true denotes 1 bit data path will be used otherwise it will be 4 bits.</param> | ||
/// <remarks> | ||
/// This will try to mount the SDCard on the specified interface. | ||
/// If the Card is not present or the card is unable to be read then an exception will be thrown. | ||
/// </remarks> | ||
[System.Diagnostics.DebuggerStepThrough] | ||
public static void MountMMC(bool Data1bit) | ||
{ | ||
MountMMCNative(Data1bit); | ||
_mounted = true; | ||
} | ||
|
||
/// <summary> | ||
/// Mount the SPI SDcard device on the specified SPI bus | ||
/// </summary> | ||
/// <param name="SpiController">The name for the SPI device, i.e "SPI1" </param> | ||
/// <param name="ChipSelect">The GPIO pin used for chip select on SDcard.</param> | ||
/// <remarks> | ||
/// This will try to mount the SDCard on the specified interface. | ||
/// If the Card is not present or the card is unable to be read then an exception will be thrown. | ||
/// </remarks> | ||
[System.Diagnostics.DebuggerStepThrough] | ||
public static void MountSpi(string SpiController, int ChipSelect) | ||
{ | ||
// the SpiDevice is an ASCII string with the format 'SPIn' | ||
// need to grab 'n' from the string and convert that to the integer value from the ASCII code (do this by subtracting 48 from the char value) | ||
int spiBus = SpiController[3] - '0'; | ||
MountSpiNative(spiBus, ChipSelect); | ||
|
||
// If no exception then set mounted flag | ||
_mounted = true; | ||
} | ||
|
||
/// <summary> | ||
/// Unmount the mounted SDcard. | ||
/// </summary> | ||
[System.Diagnostics.DebuggerStepThrough] | ||
public static void Unmount() | ||
{ | ||
UnmountNative(); | ||
|
||
// If no exception then set mounted flag | ||
_mounted = false; | ||
} | ||
|
||
#region Native Calls | ||
|
||
[System.Diagnostics.DebuggerStepThrough] | ||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
private extern static void MountMMCNative(bool Data1bit); | ||
|
||
[System.Diagnostics.DebuggerStepThrough] | ||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
private static extern void MountSpiNative(int SpiBus, int ChipSelect); | ||
|
||
[System.Diagnostics.DebuggerStepThrough] | ||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
private static extern void UnmountNative(); | ||
|
||
#endregion | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters