提交 833728c8 编写于 作者: G Greg Ingram 提交者: Jose Perez Rodriguez

Rename I2C Drivers Folder (#533)

* Moved to Devices folder

* Moved to Devices folder

* Moved to Devices folder

* Moved to Devices folder

* Moved to Devices folder

* Moved to Devices folder

* Moved to Devices folder

* Updated namespace to Devices

* Updated namespace to Devices

* Updated namespace to Devices

* Updated namespace to Devices

* Revert "Updated namespace to Devices"

This reverts commit 3044f1add3b02b814777cdb7542dbeed76efd915.

* Revert "Updated namespace to Devices"

This reverts commit 9f23b31f033f3cd6934d202516f3c9d0f382d837.

* Revert "Updated namespace to Devices"

This reverts commit 3816d7ad1e7072e48c5b4ed52041dc434d3b7eb4.

* Revert "Revert "Updated namespace to Devices""

This reverts commit 3d8394f074cd192748454caf8821100ae67de3bc.

* Added using
上级 6262d353
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Device.I2c
namespace System.Device.I2c.Devices
{
public partial class I2cDevice
{
......@@ -11,6 +11,6 @@ namespace System.Device.I2c
/// </summary>
/// <param name="settings">The connection settings of a device on an I2C bus.</param>
/// <returns>A communications channel to a device on an I2C bus running on Unix.</returns>
public static I2cDevice Create(I2cConnectionSettings settings) => new Drivers.UnixI2cDevice(settings);
public static I2cDevice Create(I2cConnectionSettings settings) => new UnixI2cDevice(settings);
}
}
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Device.I2c
namespace System.Device.I2c.Devices
{
public partial class I2cDevice
{
......@@ -11,6 +11,6 @@ namespace System.Device.I2c
/// </summary>
/// <param name="settings">The connection settings of a device on an I2C bus.</param>
/// <returns>A communications channel to a device on an I2C bus running on Windows 10 IoT.</returns>
public static I2cDevice Create(I2cConnectionSettings settings) => new Drivers.Windows10I2cDevice(settings);
public static I2cDevice Create(I2cConnectionSettings settings) => new Windows10I2cDevice(settings);
}
}
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Device.I2c
namespace System.Device.I2c.Devices
{
/// <summary>
/// The communications channel to a device on an I2C bus.
......
......@@ -5,7 +5,7 @@
using System.IO;
using System.Runtime.InteropServices;
namespace System.Device.I2c.Drivers
namespace System.Device.I2c.Devices
{
/// <summary>
/// Represents an I2C communication channel running on Unix.
......
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Device.I2c.Drivers
namespace System.Device.I2c.Devices
{
public class UnixI2cDevice : I2cDevice
{
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Device.I2c.Drivers
{
public class Windows10I2cDevice : I2cDevice
{
public Windows10I2cDevice(I2cConnectionSettings settings) =>
throw new PlatformNotSupportedException($"The {GetType().Name} class is not available on Linux.");
public override I2cConnectionSettings ConnectionSettings => throw new PlatformNotSupportedException();
public override byte ReadByte() => throw new PlatformNotSupportedException();
public override void Read(Span<byte> buffer) => throw new PlatformNotSupportedException();
public override void WriteByte(byte value) => throw new PlatformNotSupportedException();
public override void Write(ReadOnlySpan<byte> buffer) => throw new PlatformNotSupportedException();
public override void WriteRead(ReadOnlySpan<byte> writeBuffer, Span<byte> readBuffer) => throw new PlatformNotSupportedException();
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Device.I2c.Devices
{
public class Windows10I2cDevice : I2cDevice
{
public Windows10I2cDevice(I2cConnectionSettings settings) =>
throw new PlatformNotSupportedException($"The {GetType().Name} class is not available on Linux.");
public override I2cConnectionSettings ConnectionSettings => throw new PlatformNotSupportedException();
public override byte ReadByte() => throw new PlatformNotSupportedException();
public override void Read(Span<byte> buffer) => throw new PlatformNotSupportedException();
public override void WriteByte(byte value) => throw new PlatformNotSupportedException();
public override void Write(ReadOnlySpan<byte> buffer) => throw new PlatformNotSupportedException();
public override void WriteRead(ReadOnlySpan<byte> writeBuffer, Span<byte> readBuffer) => throw new PlatformNotSupportedException();
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.Devices.Enumeration;
using WinI2c = Windows.Devices.I2c;
namespace System.Device.I2c.Drivers
{
/// <summary>
/// Represents an I2C communication channel running on Windows 10 IoT.
/// </summary>
public class Windows10I2cDevice : I2cDevice
{
private readonly I2cConnectionSettings _settings;
private WinI2c.I2cDevice _winI2cDevice;
/// <summary>
/// Initializes new instance of Windows10I2cDevice that will use the specified settings to communicate with the I2C device.
/// </summary>
/// <param name="settings">The connection settings of a device on an I2C bus.</param>
public Windows10I2cDevice(I2cConnectionSettings settings)
{
_settings = settings;
var winSettings = new WinI2c.I2cConnectionSettings(settings.DeviceAddress);
string busFriendlyName = $"I2C{settings.BusId}";
string deviceSelector = WinI2c.I2cDevice.GetDeviceSelector(busFriendlyName);
DeviceInformationCollection deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion();
if (deviceInformationCollection.Count == 0)
{
throw new ArgumentException($"No I2C device exists for bus ID {settings.BusId}.", $"{nameof(settings)}.{nameof(settings.BusId)}");
}
_winI2cDevice = WinI2c.I2cDevice.FromIdAsync(deviceInformationCollection[0].Id, winSettings).WaitForCompletion();
if (_winI2cDevice == null)
{
throw new PlatformNotSupportedException($"I2C devices are not supported.");
}
}
/// <summary>
/// The connection settings of a device on an I2C bus.
/// </summary>
public override I2cConnectionSettings ConnectionSettings => _settings;
/// <summary>
/// Reads a byte from the I2C device.
/// </summary>
/// <returns>A byte read from the I2C device.</returns>
public override byte ReadByte()
{
byte[] buffer = new byte[1];
_winI2cDevice.Read(buffer);
return buffer[0];
}
/// <summary>
/// Reads data from the I2C device.
/// </summary>
/// <param name="buffer">
/// The buffer to read the data from the I2C device.
/// The length of the buffer determines how much data to read from the I2C device.
/// </param>
public override void Read(Span<byte> buffer)
{
if (buffer.Length == 0)
throw new ArgumentException($"{nameof(buffer)} cannot be empty.");
byte[] byteArray = new byte[buffer.Length];
_winI2cDevice.Read(byteArray);
new Span<byte>(byteArray).CopyTo(buffer);
}
/// <summary>
/// Writes a byte to the I2C device.
/// </summary>
/// <param name="value">The byte to be written to the I2C device.</param>
public override void WriteByte(byte value)
{
_winI2cDevice.Write(new[] { value });
}
/// <summary>
/// Writes data to the I2C device.
/// </summary>
/// <param name="buffer">
/// The buffer that contains the data to be written to the I2C device.
/// The data should not include the I2C device address.
/// </param>
public override void Write(ReadOnlySpan<byte> buffer)
{
_winI2cDevice.Write(buffer.ToArray());
}
/// <summary>
/// Performs an atomic operation to write data to and then read data from the I2C bus on which the device is connected,
/// and sends a restart condition between the write and read operations.
/// </summary>
/// <param name="writeBuffer">
/// The buffer that contains the data to be written to the I2C device.
/// The data should not include the I2C device address.</param>
/// <param name="readBuffer">
/// The buffer to read the data from the I2C device.
/// The length of the buffer determines how much data to read from the I2C device.
/// </param>
public override void WriteRead(ReadOnlySpan<byte> writeBuffer, Span<byte> readBuffer)
{
if (readBuffer.Length == 0)
throw new ArgumentException($"{nameof(readBuffer)} cannot be empty.");
byte[] byteArray = new byte[readBuffer.Length];
_winI2cDevice.WriteRead(writeBuffer.ToArray(), byteArray);
new Span<byte>(byteArray).CopyTo(readBuffer);
}
public override void Dispose(bool disposing)
{
_winI2cDevice?.Dispose();
_winI2cDevice = null;
base.Dispose(disposing);
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.Devices.Enumeration;
using WinI2c = Windows.Devices.I2c;
namespace System.Device.I2c.Devices
{
/// <summary>
/// Represents an I2C communication channel running on Windows 10 IoT.
/// </summary>
public class Windows10I2cDevice : I2cDevice
{
private readonly I2cConnectionSettings _settings;
private WinI2c.I2cDevice _winI2cDevice;
/// <summary>
/// Initializes new instance of Windows10I2cDevice that will use the specified settings to communicate with the I2C device.
/// </summary>
/// <param name="settings">The connection settings of a device on an I2C bus.</param>
public Windows10I2cDevice(I2cConnectionSettings settings)
{
_settings = settings;
var winSettings = new WinI2c.I2cConnectionSettings(settings.DeviceAddress);
string busFriendlyName = $"I2C{settings.BusId}";
string deviceSelector = WinI2c.I2cDevice.GetDeviceSelector(busFriendlyName);
DeviceInformationCollection deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion();
if (deviceInformationCollection.Count == 0)
{
throw new ArgumentException($"No I2C device exists for bus ID {settings.BusId}.", $"{nameof(settings)}.{nameof(settings.BusId)}");
}
_winI2cDevice = WinI2c.I2cDevice.FromIdAsync(deviceInformationCollection[0].Id, winSettings).WaitForCompletion();
if (_winI2cDevice == null)
{
throw new PlatformNotSupportedException($"I2C devices are not supported.");
}
}
/// <summary>
/// The connection settings of a device on an I2C bus.
/// </summary>
public override I2cConnectionSettings ConnectionSettings => _settings;
/// <summary>
/// Reads a byte from the I2C device.
/// </summary>
/// <returns>A byte read from the I2C device.</returns>
public override byte ReadByte()
{
byte[] buffer = new byte[1];
_winI2cDevice.Read(buffer);
return buffer[0];
}
/// <summary>
/// Reads data from the I2C device.
/// </summary>
/// <param name="buffer">
/// The buffer to read the data from the I2C device.
/// The length of the buffer determines how much data to read from the I2C device.
/// </param>
public override void Read(Span<byte> buffer)
{
if (buffer.Length == 0)
throw new ArgumentException($"{nameof(buffer)} cannot be empty.");
byte[] byteArray = new byte[buffer.Length];
_winI2cDevice.Read(byteArray);
new Span<byte>(byteArray).CopyTo(buffer);
}
/// <summary>
/// Writes a byte to the I2C device.
/// </summary>
/// <param name="value">The byte to be written to the I2C device.</param>
public override void WriteByte(byte value)
{
_winI2cDevice.Write(new[] { value });
}
/// <summary>
/// Writes data to the I2C device.
/// </summary>
/// <param name="buffer">
/// The buffer that contains the data to be written to the I2C device.
/// The data should not include the I2C device address.
/// </param>
public override void Write(ReadOnlySpan<byte> buffer)
{
_winI2cDevice.Write(buffer.ToArray());
}
/// <summary>
/// Performs an atomic operation to write data to and then read data from the I2C bus on which the device is connected,
/// and sends a restart condition between the write and read operations.
/// </summary>
/// <param name="writeBuffer">
/// The buffer that contains the data to be written to the I2C device.
/// The data should not include the I2C device address.</param>
/// <param name="readBuffer">
/// The buffer to read the data from the I2C device.
/// The length of the buffer determines how much data to read from the I2C device.
/// </param>
public override void WriteRead(ReadOnlySpan<byte> writeBuffer, Span<byte> readBuffer)
{
if (readBuffer.Length == 0)
throw new ArgumentException($"{nameof(readBuffer)} cannot be empty.");
byte[] byteArray = new byte[readBuffer.Length];
_winI2cDevice.WriteRead(writeBuffer.ToArray(), byteArray);
new Span<byte>(byteArray).CopyTo(readBuffer);
}
public override void Dispose(bool disposing)
{
_winI2cDevice?.Dispose();
_winI2cDevice = null;
base.Dispose(disposing);
}
}
}
......@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Device.I2c;
using System.Device.I2c.Devices;
using CommandLine;
using DeviceApiTester.Infrastructure;
......
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Device.I2c.Drivers;
using System.Device.I2c.Devices;
using DeviceApiTester.Infrastructure;
namespace DeviceApiTester.Commands.I2c
......
......@@ -4,6 +4,7 @@
using System;
using System.Device.I2c;
using System.Device.I2c.Devices;
using System.Text;
using CommandLine;
using DeviceApiTester.Infrastructure;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册