Smdn.Devices.MCP2221
0.9.4
Prefix Reserved
dotnet add package Smdn.Devices.MCP2221 --version 0.9.4
NuGet\Install-Package Smdn.Devices.MCP2221 -Version 0.9.4
<PackageReference Include="Smdn.Devices.MCP2221" Version="0.9.4" />
<PackageVersion Include="Smdn.Devices.MCP2221" Version="0.9.4" />
<PackageReference Include="Smdn.Devices.MCP2221" />
paket add Smdn.Devices.MCP2221 --version 0.9.4
#r "nuget: Smdn.Devices.MCP2221, 0.9.4"
#:package Smdn.Devices.MCP2221@0.9.4
#addin nuget:?package=Smdn.Devices.MCP2221&version=0.9.4
#tool nuget:?package=Smdn.Devices.MCP2221&version=0.9.4
Smdn.Devices.MCP2221 0.9.4
Smdn.Devices.MCP2221 is a .NET library for the Microchip Technology MCP2221 and MCP2221A, a USB2.0 to I2C/UART Protocol Converter with GPIO.
This library provides APIs that enable .NET applications to access the functions of the MCP2221/MCP2221A via the USB-HID interface.
Usage
This is an example of switching the output of each pin on GP0-GP3 of the MCP2221 at specific intervals to make the connected LED blink.
以下のコードは、MCP2221のGP0-GP3の各ピンの出力を一定間隔で切り替え、接続されているLEDを点滅させる例です。
using System.Device.Gpio;
using Smdn.Devices.MCP2221;
// Find and open the first MCP2221 device connected to the USB port.
using var device = MCP2221.Open();
// Configure the GP pins (GP0-GP3) as GPIO output.
device.GP0.ConfigureAsGPIO(PinMode.Output);
device.GP1.ConfigureAsGPIO(PinMode.Output);
device.GP2.ConfigureAsGPIO(PinMode.Output);
device.GP3.ConfigureAsGPIO(PinMode.Output);
// Blink the configured GPIO pins.
//
// This example assumes an LED is connected to each pin.
// See this code in action in the YouTube video:
// https://www.youtube.com/watch?v=MnIunESm71E
foreach (var gp in device.GPs) {
Console.WriteLine($"Blinking {gp.PinDesignation}");
for (var n = 0; n < 10; n++) {
// Set the pin output to Low (logic 0)
gp.SetValue(false);
Thread.Sleep(100);
// Set the pin output to High (logic 0)
gp.SetValue(true);
Thread.Sleep(100);
}
}
The entire code is available on the GitHub repository.
完全なコードはGitHubリポジトリを参照してください。
Contributing
This project welcomes contributions, feedbacks and suggestions. You can contribute to this project by submitting Issues or Pull Requests on the GitHub repository.
Notice
License
This project is licensed under the terms of the MIT License.
Disclaimer
(An English translation for the reference follows the text written in Japanese.)
本プロジェクトは、MCP2221/MCP2221Aの製造元・供給元・販売元とは無関係の、非公式なものです。
This is an unofficial project that has no affiliation with the manufacturers/vendors/suppliers of MCP2221/MCP2221A.
Credit
This project uses the following components. See ThirdPartyNotices.md for detail.
API List
List of APIs exposed by assembly Smdn.Devices.MCP2221-0.9.4 (net10.0)
// Smdn.Devices.MCP2221.dll (Smdn.Devices.MCP2221-0.9.4)
// Name: Smdn.Devices.MCP2221
// AssemblyVersion: 0.9.4.0
// InformationalVersion: 0.9.4+bcf0f60c80f47181419bd376632a2c0be172ac98
// TargetFramework: .NETCoreApp,Version=v10.0
// Configuration: Release
// Metadata: IsTrimmable=True
// Metadata: RepositoryUrl=https://github.com/smdn/Smdn.Devices.MCP2221
// Metadata: RepositoryBranch=main
// Metadata: RepositoryCommit=bcf0f60c80f47181419bd376632a2c0be172ac98
// Referenced assemblies:
// HidSharp, Version=2.1.0.0, Culture=neutral
// Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// System.Collections, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.ComponentModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Device.Gpio, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// System.Linq, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Memory, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// System.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Threading.Thread, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
using System;
using System.Collections.Generic;
using System.Device.Gpio;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Smdn.Devices.MCP2221;
using Smdn.Devices.UsbHid;
namespace Smdn.Devices.MCP2221 {
public enum I2CBusSpeed : int {
Default = 0,
FastMode = 2,
LowSpeedMode = 1,
Speed100kBitsPerSec = 0,
Speed10kBitsPerSec = 1,
Speed400kBitsPerSec = 2,
StandardMode = 0,
}
public class CommandException : InvalidOperationException {
public CommandException(string message) {}
public CommandException(string message, Exception innerException) {}
}
public class DeviceNotFoundException : InvalidOperationException {
public DeviceNotFoundException() {}
public DeviceNotFoundException(string message) {}
}
public class I2CCommandException : CommandException {
public I2CCommandException(I2CAddress address, string message) {}
public I2CCommandException(I2CAddress address, string message, Exception innerException) {}
public I2CCommandException(string message) {}
public I2CCommandException(string message, Exception innerException) {}
public I2CAddress Address { get; }
}
public class I2CNAckException : I2CCommandException {
public I2CNAckException(I2CAddress address) {}
public I2CNAckException(I2CAddress address, Exception innerException) {}
public I2CNAckException(string message) {}
public I2CNAckException(string message, Exception innerException) {}
}
public class I2CReadException : I2CCommandException {
public I2CReadException(I2CAddress address, string message) {}
public I2CReadException(I2CAddress address, string message, Exception innerException) {}
public I2CReadException(string message) {}
public I2CReadException(string message, Exception innerException) {}
}
public class MCP2221 :
IAsyncDisposable,
IDisposable
{
public sealed class GP0Functionality : GPFunctionality {
public void ConfigureAsLEDURX(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsLEDURXAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsSSPND(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsSSPNDAsync(CancellationToken cancellationToken = default) {}
}
public sealed class GP1Functionality : GPFunctionality {
public void ConfigureAsADC(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsADCAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsClockOutput(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsClockOutputAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsInterruptDetection(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsInterruptDetectionAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsLEDUTX(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsLEDUTXAsync(CancellationToken cancellationToken = default) {}
}
public sealed class GP2Functionality : GPFunctionality {
public void ConfigureAsADC(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsADCAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsDAC(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsDACAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsUSBCFG(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsUSBCFGAsync(CancellationToken cancellationToken = default) {}
}
public sealed class GP3Functionality : GPFunctionality {
public void ConfigureAsADC(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsADCAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsDAC(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsDACAsync(CancellationToken cancellationToken = default) {}
public void ConfigureAsLEDI2C(CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsLEDI2CAsync(CancellationToken cancellationToken = default) {}
}
public abstract class GPFunctionality {
public string PinDesignation { get; }
public string PinName { get; }
public void ConfigureAsGPIO(PinMode initialDirection = PinMode.Output, PinValue initialValue = default, CancellationToken cancellationToken = default) {}
public ValueTask ConfigureAsGPIOAsync(PinMode initialDirection = PinMode.Output, PinValue initialValue = default, CancellationToken cancellationToken = default) {}
public PinMode GetDirection(CancellationToken cancellationToken = default) {}
public ValueTask<PinMode> GetDirectionAsync(CancellationToken cancellationToken = default) {}
public PinValue GetValue(CancellationToken cancellationToken = default) {}
public ValueTask<PinValue> GetValueAsync(CancellationToken cancellationToken = default) {}
public void SetDirection(PinMode newDirection, CancellationToken cancellationToken = default) {}
public ValueTask SetDirectionAsync(PinMode newDirection, CancellationToken cancellationToken = default) {}
public void SetValue(PinValue newValue, CancellationToken cancellationToken = default) {}
public ValueTask SetValueAsync(PinValue newValue, CancellationToken cancellationToken = default) {}
}
public sealed class I2CFunctionality {
public const int MaxBlockLength = 65535;
public I2CBusSpeed BusSpeed { get; set; }
public int Read(I2CAddress address, Span<byte> buffer, CancellationToken cancellationToken = default) {}
public int Read(I2CAddress address, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default) {}
public ValueTask<int> ReadAsync(I2CAddress address, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default) {}
public async ValueTask<int> ReadAsync(I2CAddress address, Memory<byte> buffer, CancellationToken cancellationToken = default) {}
public int ReadByte(I2CAddress address, CancellationToken cancellationToken = default) {}
public async ValueTask<int> ReadByteAsync(I2CAddress address, CancellationToken cancellationToken = default) {}
public (IReadOnlySet<I2CAddress> WriteAddressSet, IReadOnlySet<I2CAddress> ReadAddressSet) ScanBus(I2CAddress addressRangeMin = default, I2CAddress addressRangeMax = default, IProgress<I2CScanBusProgress> progress = null, CancellationToken cancellationToken = default) {}
public async ValueTask<(IReadOnlySet<I2CAddress> WriteAddressSet, IReadOnlySet<I2CAddress> ReadAddressSet)> ScanBusAsync(I2CAddress addressRangeMin = default, I2CAddress addressRangeMax = default, IProgress<I2CScanBusProgress> progress = null, CancellationToken cancellationToken = default) {}
public void Write(I2CAddress address, ReadOnlySpan<byte> buffer, CancellationToken cancellationToken = default) {}
public void Write(I2CAddress address, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default) {}
public ValueTask WriteAsync(I2CAddress address, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default) {}
public async ValueTask WriteAsync(I2CAddress address, ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) {}
public void WriteByte(I2CAddress address, byte @value, CancellationToken cancellationToken = default) {}
public async ValueTask WriteByteAsync(I2CAddress address, byte @value, CancellationToken cancellationToken = default) {}
}
public const int DeviceProductID = 221;
public const int DeviceVendorID = 1240;
public const string FirmwareRevisionMCP2221 = "1.1";
public const string FirmwareRevisionMCP2221A = "1.2";
public const string HardwareRevisionMCP2221 = "A.6";
public const string HardwareRevisionMCP2221A = "A.6";
public static MCP2221 Open(Func<IUsbHidDevice> createHidDevice, IServiceProvider serviceProvider = null) {}
public static MCP2221 Open(IServiceProvider serviceProvider = null) {}
public static MCP2221 Open(Predicate<IUsbHidDevice> findDevicePredicate, IServiceProvider serviceProvider = null) {}
public static ValueTask<MCP2221> OpenAsync(IServiceProvider serviceProvider = null) {}
public static ValueTask<MCP2221> OpenAsync(Predicate<IUsbHidDevice> findDevicePredicate, IServiceProvider serviceProvider = null) {}
public static async ValueTask<MCP2221> OpenAsync(Func<IUsbHidDevice> createHidDevice, IServiceProvider serviceProvider = null) {}
public string ChipFactorySerialNumber { get; }
public string FirmwareRevision { get; }
public MCP2221.GP0Functionality GP0 { get; }
public MCP2221.GP1Functionality GP1 { get; }
public MCP2221.GP2Functionality GP2 { get; }
public MCP2221.GP3Functionality GP3 { get; }
public IReadOnlyList<MCP2221.GPFunctionality> GPs { get; }
public string HardwareRevision { get; }
public IUsbHidDevice HidDevice { get; }
public MCP2221.I2CFunctionality I2C { get; }
public string ManufacturerDescriptor { get; }
public string ProductDescriptor { get; }
public string SerialNumberDescriptor { get; }
public void Dispose() {}
public async ValueTask DisposeAsync() {}
}
public readonly struct I2CAddress :
IComparable<I2CAddress>,
IEquatable<I2CAddress>,
IEquatable<byte>,
IEquatable<int>
{
public static readonly I2CAddress DeviceMaxValue; // = "77"
public static readonly I2CAddress DeviceMinValue; // = "08"
public static readonly I2CAddress Zero; // = "00"
public static bool operator == (I2CAddress x, I2CAddress y) {}
public static explicit operator byte(I2CAddress address) {}
public static explicit operator int(I2CAddress address) {}
public static bool operator > (I2CAddress left, I2CAddress right) {}
public static bool operator >= (I2CAddress left, I2CAddress right) {}
public static implicit operator I2CAddress(byte address) {}
public static bool operator != (I2CAddress x, I2CAddress y) {}
public static bool operator < (I2CAddress left, I2CAddress right) {}
public static bool operator <= (I2CAddress left, I2CAddress right) {}
public I2CAddress(int address) {}
public I2CAddress(int deviceAddressBits, int hardwareAddressBits) {}
public int CompareTo(I2CAddress other) {}
public bool Equals(I2CAddress other) {}
public bool Equals(byte other) {}
public bool Equals(int other) {}
public override bool Equals(object obj) {}
public override int GetHashCode() {}
public override string ToString() {}
}
public readonly struct I2CScanBusProgress {
public I2CAddress AddressRangeMax { get; }
public I2CAddress AddressRangeMin { get; }
public int ProgressInPercent { get; }
public I2CAddress ScanningAddress { get; }
}
}
namespace Smdn.Devices.UsbHid {
public interface IUsbHidDevice :
IAsyncDisposable,
IDisposable
{
string DevicePath { get; }
string FileSystemName { get; }
string Manufacturer { get; }
int ProductID { get; }
string ProductName { get; }
Version ReleaseNumber { get; }
string SerialNumber { get; }
int VendorID { get; }
IUsbHidStream OpenStream();
ValueTask<IUsbHidStream> OpenStreamAsync();
}
public interface IUsbHidStream :
IAsyncDisposable,
IDisposable
{
bool RequiresPacketOnly { get; }
int Read(Span<byte> buffer);
ValueTask<int> ReadAsync(Memory<byte> buffer);
void Write(ReadOnlySpan<byte> buffer);
ValueTask WriteAsync(ReadOnlyMemory<byte> buffer);
}
public static class Log {
public static LogLevel NativeLibraryLogLevel { get; set; }
}
public class UsbHidException : InvalidOperationException {
public UsbHidException() {}
public UsbHidException(string message) {}
}
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.8.1.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.6.1.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- HidSharp (>= 2.1.0 && < 3.0.0)
- Microsoft.Extensions.DependencyInjection (>= 5.0.1)
- Microsoft.Extensions.Logging (>= 5.0.0)
- System.Device.Gpio (>= 1.4.0 && < 4.0.0)
-
net10.0
- HidSharp (>= 2.1.0 && < 3.0.0)
- Microsoft.Extensions.DependencyInjection (>= 5.0.1)
- Microsoft.Extensions.Logging (>= 5.0.0)
- System.Device.Gpio (>= 1.4.0 && < 5.0.0)
-
net8.0
- HidSharp (>= 2.1.0 && < 3.0.0)
- Microsoft.Extensions.DependencyInjection (>= 5.0.1)
- Microsoft.Extensions.Logging (>= 5.0.0)
- System.Device.Gpio (>= 1.4.0 && < 5.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Smdn.Devices.MCP2221:
| Package | Downloads |
|---|---|
|
Smdn.Devices.MCP2221.GpioAdapter
Smdn.Devices.MCP2221.GpioAdapter provides the MCP2221/MCP2221A adapter for System.Device.Gpio. This library enables you to use the many device bindings provided by Iot.Device.Bindings. |
GitHub repositories
This package is not used by any popular GitHub repositories.