Fixes in code style and comments to conform with project guidelines
This commit is contained in:
Родитель
3735bc6d73
Коммит
695288d0d5
|
@ -13,8 +13,12 @@ namespace System.Device.Spi
|
|||
public sealed class SpiConnectionSettings
|
||||
{
|
||||
private int _csLine;
|
||||
private int _clockFrequency = 500_000; // 500 KHz
|
||||
private int _databitLength = 8; // 1 byte
|
||||
|
||||
// 500 KHz
|
||||
private int _clockFrequency = 500_000;
|
||||
|
||||
// 1 byte
|
||||
private int _databitLength = 8;
|
||||
private SpiMode _spiMode = SpiMode.Mode0;
|
||||
private SpiSharingMode _spiSharingMode;
|
||||
private DataFlow _dataFlow = DataFlow.MsbFirst;
|
||||
|
@ -24,7 +28,6 @@ namespace System.Device.Spi
|
|||
/// <summary>
|
||||
/// Initializes new instance of SpiConnectionSettings.
|
||||
/// </summary>
|
||||
/// <param name="chipSelectLine">The chip select line on which the connection will be made.</param>
|
||||
|
||||
private SpiConnectionSettings()
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace System.Device.Spi
|
|||
private object _syncLock;
|
||||
|
||||
// For the ReadByte and WriteByte operations
|
||||
private byte[] _bufferSingleOperation = new byte[1];
|
||||
private readonly byte[] _bufferSingleOperation = new byte[1];
|
||||
|
||||
/// <summary>
|
||||
/// The connection settings of a device on a SPI bus. The connection settings are immutable after the device is created
|
||||
|
@ -64,6 +64,18 @@ namespace System.Device.Spi
|
|||
NativeTransfer(null, buffer, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads data from the SPI device.
|
||||
/// </summary>
|
||||
/// <param name="buffer">
|
||||
/// The buffer to read the data from the SPI device.
|
||||
/// The length of the buffer determines how much data to read from the SPI device.
|
||||
/// </param>
|
||||
public void Read(ushort[] buffer)
|
||||
{
|
||||
NativeTransfer(null, buffer, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a byte to the SPI device.
|
||||
/// </summary>
|
||||
|
@ -74,6 +86,17 @@ namespace System.Device.Spi
|
|||
NativeTransfer(_bufferSingleOperation, null, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to the SPI device.
|
||||
/// </summary>
|
||||
/// <param name="buffer">
|
||||
/// The buffer that contains the data to be written to the SPI device.
|
||||
/// </param>
|
||||
public void Write(ushort[] buffer)
|
||||
{
|
||||
NativeTransfer(buffer, null, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to the SPI device.
|
||||
/// </summary>
|
||||
|
@ -90,40 +113,17 @@ namespace System.Device.Spi
|
|||
/// </summary>
|
||||
/// <param name="writeBuffer">The buffer that contains the data to be written to the SPI device.</param>
|
||||
/// <param name="readBuffer">The buffer to read the data from the SPI device.</param>
|
||||
public void TransferFullDuplex(SpanByte writeBuffer, SpanByte readBuffer)
|
||||
public void TransferFullDuplex(ushort[] writeBuffer, ushort[] readBuffer)
|
||||
{
|
||||
NativeTransfer(writeBuffer, readBuffer, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads data from the SPI device.
|
||||
/// </summary>
|
||||
/// <param name="buffer">
|
||||
/// The buffer to read the data from the SPI device.
|
||||
/// The length of the buffer determines how much data to read from the SPI device.
|
||||
/// </param>
|
||||
public void Read(ushort[] buffer)
|
||||
{
|
||||
NativeTransfer(null, buffer, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to the SPI device.
|
||||
/// </summary>
|
||||
/// <param name="buffer">
|
||||
/// The buffer that contains the data to be written to the SPI device.
|
||||
/// </param>
|
||||
public void Write(ushort[] buffer)
|
||||
{
|
||||
NativeTransfer(buffer, null, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes and reads data from the SPI device.
|
||||
/// </summary>
|
||||
/// <param name="writeBuffer">The buffer that contains the data to be written to the SPI device.</param>
|
||||
/// <param name="readBuffer">The buffer to read the data from the SPI device.</param>
|
||||
public void TransferFullDuplex(ushort[] writeBuffer, ushort[] readBuffer)
|
||||
public void TransferFullDuplex(SpanByte writeBuffer, SpanByte readBuffer)
|
||||
{
|
||||
NativeTransfer(writeBuffer, readBuffer, true);
|
||||
}
|
||||
|
@ -139,17 +139,17 @@ namespace System.Device.Spi
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a communications channel to a device on a SPI bus running on the current hardware
|
||||
/// Creates a communications channel to a device on a SPI bus running on the current hardware.
|
||||
/// </summary>
|
||||
/// <param name="settings">The connection settings of a device on a SPI bus.</param>
|
||||
/// <returns>A communications channel to a device on a SPI bus running on Windows 10 IoT.</returns>
|
||||
/// <returns>A communications channel to a device on a SPI bus.</returns>
|
||||
public static SpiDevice Create(SpiConnectionSettings settings)
|
||||
{
|
||||
return new SpiDevice(settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a communications channel to a device on a SPI bus running on the current hardware
|
||||
/// Creates a communications channel to a device on a SPI bus running on the current hardware.
|
||||
/// </summary>
|
||||
/// <param name="settings">The connection settings of a device on a SPI bus.</param>
|
||||
public SpiDevice(SpiConnectionSettings settings)
|
||||
|
@ -166,14 +166,11 @@ namespace System.Device.Spi
|
|||
// Device(chip select) already in use
|
||||
throw new SpiDeviceAlreadyInUseException();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ArgumentException
|
||||
// Invalid port or unable to init bus
|
||||
// IndexOutOfRangeException
|
||||
// Too many devices open or spi already in use
|
||||
throw ex;
|
||||
}
|
||||
// these can also be thrown bt the native driver
|
||||
// ArgumentException
|
||||
// Invalid port or unable to init bus
|
||||
// IndexOutOfRangeException
|
||||
// Too many devices open or spi already in use
|
||||
|
||||
// device doesn't exist, create it...
|
||||
_connectionSettings = new SpiConnectionSettings(settings);
|
||||
|
@ -211,6 +208,7 @@ namespace System.Device.Spi
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
~SpiDevice()
|
||||
{
|
||||
Dispose(false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче