Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Storage.Devices to support ESP32 mount operations #32

Merged
merged 3 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/Windows.Storage/FileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static void WriteBuffer(IStorageFile file, IBuffer buffer)
[System.Diagnostics.DebuggerStepThrough]

[MethodImpl(MethodImplOptions.InternalCall)]
public extern static void ReadTextNative(IStorageFile file, ref string text);
private extern static void ReadTextNative(IStorageFile file, ref string text);
#endregion

}
Expand Down
3 changes: 3 additions & 0 deletions source/Windows.Storage/IStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace Windows.Storage
{
/// <summary>
///
/// </summary>
public interface IStorageProvider
{
}
Expand Down
6 changes: 6 additions & 0 deletions source/Windows.Storage/KnownFolderId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,11 @@ public enum KnownFolderId
///// Videos library folder.
///// </summary>
//VideosLibrary = 13

/// <summary>
/// Internal devices.
/// </summary>
InternalDevices = 14

}
}
7 changes: 7 additions & 0 deletions source/Windows.Storage/KnownFolders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public static class KnownFolders
/// </summary>
public static StorageFolder RemovableDevices => new StorageFolder(KnownFolderId.RemovableDevices);


/// <summary>
/// Gets the internal devices folder.
/// </summary>
public static StorageFolder InternalDevices => new StorageFolder(KnownFolderId.InternalDevices);


//public static StorageFolder SavedPictures { get; }
//public static StorageFolder VideosLibrary { get; }

Expand Down
93 changes: 93 additions & 0 deletions source/Windows.Storage/StorageDevices.cs
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

}
}

31 changes: 30 additions & 1 deletion source/Windows.Storage/StorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// See LICENSE file in the project root for full license information.
//


using System;
using System.Runtime.CompilerServices;

namespace Windows.Storage
{
Expand Down Expand Up @@ -160,6 +160,27 @@ public string FileType
// public static IAsyncOperation<StorageFile> GetFileFromPathAsync(String path)
// { }

/// <summary>
/// Gets a StorageFile object to represent the file at the specified path.
/// </summary>
/// <param name="path">The path of the file to get a StorageFile to represent.</param>
/// <returns>Returns the file as a StorageFile.</returns>
///<remarks>
///
/// This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be GetFileFromPathAsync(String).
///</remarks>
public static StorageFile GetFileFromPath(String path)
{
StorageFile file = new StorageFile();

CheckFileNative(path);

file._path = path;

return file;
}

// public IAsyncOperation<StorageFolder> GetParentAsync()
// { }

Expand Down Expand Up @@ -202,6 +223,7 @@ public string FileType
// public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode)
// { }


// public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options)
// { }

Expand All @@ -228,5 +250,12 @@ public string FileType

// public static IAsyncOperation<StorageFile> ReplaceWithStreamedFileFromUriAsync(IStorageFile fileToReplace, Uri uri, IRandomAccessStreamReference thumbnail)
// { }


[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void CheckFileNative(string filePath);

}
}
28 changes: 23 additions & 5 deletions source/Windows.Storage/StorageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed class StorageFolder : IStorageFolder//, IStorageFolder2, IStorageI

private const string s_RemovableStorageDevicesName = "Removable Storage Devices";
private const string s_RemovableStorageDevicesDisplayType = "System Folder";
private const string s_InternalStorageDevicesName = "Internal Storage Devices";

#endregion

Expand Down Expand Up @@ -105,14 +106,22 @@ public sealed class StorageFolder : IStorageFolder//, IStorageFolder2, IStorageI

internal StorageFolder(KnownFolderId folderId)
{
// currently there is only support for removable devices
if (folderId != KnownFolderId.RemovableDevices)
// currently there is only support for removable devices
// and internal storage devices
if (folderId == KnownFolderId.RemovableDevices)
{
_name = s_RemovableStorageDevicesName;
}
else if (folderId == KnownFolderId.InternalDevices)
{
_name = s_InternalStorageDevicesName;
}
else
{
throw new NotSupportedException();
}

_knownFolderId = folderId;
_name = s_RemovableStorageDevicesName;
_path = "";
}

Expand Down Expand Up @@ -310,13 +319,17 @@ public StorageFile[] GetFiles(CommonFileQuery query, UInt32 startIndex, UInt32 m
public StorageFolder[] GetFolders()
{
// is this a call for a known folder ID
// RemovableDevices
// RemovableDevices & InternalDevices
// nothing else is implemented, no need to check as this doesn't get pass the constructor StorageFolder(KnownFolderId folderId)
if (_knownFolderId == KnownFolderId.RemovableDevices)
{
return GetRemovableStorageFoldersNative();
}

else if (_knownFolderId == KnownFolderId.InternalDevices)
{
return GetInternalStorageFoldersNative();
}

// regular get folders
return GetStorageFoldersNative();
}
Expand Down Expand Up @@ -401,6 +414,11 @@ public bool IsCommonFileQuerySupported(CommonFileQuery query)
[MethodImpl(MethodImplOptions.InternalCall)]
private extern StorageFolder[] GetRemovableStorageFoldersNative();

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern StorageFolder[] GetInternalStorageFoldersNative();

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down
1 change: 1 addition & 0 deletions source/Windows.Storage/Windows.Storage.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="SetVersionDeferral.cs" />
<Compile Include="SetVersionRequest.cs" />
<Compile Include="StorageDeleteOption.cs" />
<Compile Include="StorageDevices.cs" />
<Compile Include="StorageEventManager.cs" />
<Compile Include="RemovableDeviceEventArgs.cs" />
<Compile Include="StorageFile.cs" />
Expand Down