Oakrey.Microchip.Mcp2210.Wrapper
2.0.3
See the version list below for details.
dotnet add package Oakrey.Microchip.Mcp2210.Wrapper --version 2.0.3
NuGet\Install-Package Oakrey.Microchip.Mcp2210.Wrapper -Version 2.0.3
<PackageReference Include="Oakrey.Microchip.Mcp2210.Wrapper" Version="2.0.3" />
<PackageVersion Include="Oakrey.Microchip.Mcp2210.Wrapper" Version="2.0.3" />
<PackageReference Include="Oakrey.Microchip.Mcp2210.Wrapper" />
paket add Oakrey.Microchip.Mcp2210.Wrapper --version 2.0.3
#r "nuget: Oakrey.Microchip.Mcp2210.Wrapper, 2.0.3"
#:package Oakrey.Microchip.Mcp2210.Wrapper@2.0.3
#addin nuget:?package=Oakrey.Microchip.Mcp2210.Wrapper&version=2.0.3
#tool nuget:?package=Oakrey.Microchip.Mcp2210.Wrapper&version=2.0.3
Oakrey.Microchip.Mcp2210.Wrapper
Overview
Oakrey.Microchip.Mcp2210.Wrapper is a .NET library for controlling the Microchip MCP2210 USB-to-SPI bridge. It wraps the vendor-supplied native DLLs behind a SafeHandle-based entry point (Mcp2210Handle) and exposes the full device API via C# extension methods, covering SPI data transfer, GPIO pin control, chip and NVRAM settings, EEPROM access, and password-based access control. Bundled x86 and x64 native DLLs are selected automatically at runtime.
Main Features
- SPI data transfer -
SendData()with baud rate, chip-select index, and optionalSpiConfiguration(mode, CS delays, transfer size). - SPI bus management -
GetStatus(),CancelTransfer(),RequestBusRel()for shared-bus scenarios. - GPIO pin values -
GetPinValue(),GetPinsValue(),SetPinsValue()for all 9 GPIO lines. - GPIO pin directions -
GetPinDirection(),SetPinDirection()per pin. - GPIO settings -
GetConfiguration()/SetConfiguration()for pin designation, interrupt mode, remote wake-up, and SPI bus release; targeting either RAM or NVRAM viaConfigurationMemoryType. - Device settings - read/write VID, PID, power source, current, manufacturer string, product name, and serial number.
- SPI configuration -
GetSpiConfiguration()/SetSpiConfiguration()and individual property helpers (baud rate, CS delays, active CS mask, SPI mode). - EEPROM -
ReadEeprom()/WriteEeprom()by byte address. - Access control -
EnterPassword(),GetAccessStatus(),GetAccessControl(),SetAccessControl(). - Device enumeration -
GetConnectedDevicesCount(),GetLibraryVersion(). - Automatic x86/x64 dispatch - all P/Invoke calls branch on
Environment.Is64BitProcesswithout consumer configuration.
Architecture
classDiagram
direction LR
class Mcp2210Handle {
+Mcp2210Handle(vid, pid, index)
+Mcp2210Handle(vid, pid, serialNo)
+Reset()
#ReleaseHandle()
}
class Mcp2210SpiWrapper {
+SendData(data, baudRate, csIndex, ...) byte[]
+GetStatus() SpiStatus
+CancelTransfer() SpiStatus
+RequestBusRel(ackPinVal)
}
class Mcp2210GpioPinValueWrapper {
+GetPinValue(index) GpioValue
+GetPinsValue() uint
+SetPinsValue(values)
}
class Mcp2210GpioSettingsWrapper {
+GetConfiguration(memType) GpioConfig
+SetConfiguration(memType, cfg)
+GetPinsDesignation(memType) PinDesignation[]
+IsRemoteWakeUpEnabled(memType) bool
}
class Mcp2210SettingsWrapper {
+GetManufacturer() string
+GetProduct() string
+GetSerialNumber() string
+GetPid() ushort
+GetPowerSource() PowerSource
}
class McpP2210SpiConfigurationWrapper {
+GetSpiConfiguration(memType) SpiConfiguration
+SetSpiConfiguration(memType, cfg)
+GetBaudRate(memType) uint
+BaudRate(memType, value)
}
class Mcp2210EepromWrapper {
+ReadEeprom(address) byte
+WriteEeprom(address, content)
}
class Mcp2210AccessControlWrapper {
+EnterPassword(passwd)
+GetAccessStatus() AccessControlStatus
+SetAccessControl(mode, passwd)
}
Mcp2210Handle <.. Mcp2210SpiWrapper : extends
Mcp2210Handle <.. Mcp2210GpioPinValueWrapper : extends
Mcp2210Handle <.. Mcp2210GpioSettingsWrapper : extends
Mcp2210Handle <.. Mcp2210SettingsWrapper : extends
Mcp2210Handle <.. McpP2210SpiConfigurationWrapper : extends
Mcp2210Handle <.. Mcp2210EepromWrapper : extends
Mcp2210Handle <.. Mcp2210AccessControlWrapper : extends
Project structure
MicrochipMcp2210Wrapper/
Mcp2210Handle.cs # SafeHandle entry point; open by index or serial number
Mcp2210Exception.cs # Exception type wrapping native error codes
Extensions/
MCP2210SpiWrapper.cs # SPI transfer and bus management
McpP2210SpiConfigurationWrapper.cs # SPI configuration get/set helpers
MCP2210GpioPinValueWrapper.cs # GPIO pin value read/write
MCP2210GpioPinDirectionsWrapper.cs # GPIO pin direction read/write
MCP2210GpioSettingsWrapper.cs # GPIO chip/NVRAM settings
MCP2210SettingsWrapper.cs # Device descriptor and key settings
MCP2210EEpromWrapper.cs # EEPROM byte read/write
MCP2210AccessWrapper.cs # Device enumeration and library version
Mcp2210AccessControlWrapper.cs # Password and access control
DataTypes/
SpiConfiguration.cs # Baud rate, CS delays, mode, transfer size
GpioConfig.cs # Pin designations, direction, interrupt mode
GpioDirection.cs / GpioValue.cs # GPIO enums
PinDesignation.cs # GPIO, CS, or dedicated function
SpiMode.cs / SpiStatus.cs / SpiOwner.cs
AccessControlStatus.cs / KeySettings.cs
ConfigurationMemoryType.cs # Volatile (RAM) vs. non-volatile (NVRAM)
PowerSource.cs / WakeUpMode.cs / InterruptMode.cs
NativeMethods/
Mcp2210LibraryNativeMethods.cs # x86/x64 dispatch + shared helpers
Mcp2210LibraryNativeMethods.SPI.cs
Mcp2210LibraryNativeMethods.GPIO.cs
Mcp2210LibraryNativeMethods.EEPROM.cs
Mcp2210LibraryNativeMethods.Settings.cs
Mcp2210LibraryNativeMethods.AccessControl.cs
lib/
mcp2210_dll_um_x64.dll # Vendor native library (64-bit)
mcp2210_dll_um_x86.dll # Vendor native library (32-bit)
Requirements
- .NET 10 (net10.0), Windows
- No additional NuGet dependencies; native DLLs are bundled in the package under
lib\net10.0 - A connected Microchip MCP2210 USB-to-SPI bridge device
Installation
.NET CLI
dotnet add package Oakrey.Microchip.Mcp2210.Wrapper
Package Manager Console
Install-Package Oakrey.Microchip.Mcp2210.Wrapper
NuGet Package Manager
Search for Oakrey.Microchip.Mcp2210.Wrapper in Tools > NuGet Package Manager > Manage NuGet Packages for Solution and click Install.
Example Usage
Open a device and send SPI data
using Oakrey.Microchip.Mcp2210.Wrapper;
using Oakrey.Microchip.Mcp2210.Wrapper.Extensions;
// Open first device by VID/PID index
using Mcp2210Handle handle = new(vid: 0x04D8, pid: 0x00DE, index: 0);
byte[] txData = [0x01, 0x02, 0x03];
byte[] rxData = handle.SendData(txData, baudRate: 100_000, csIndex: 0, receiveBufferSize: 3);
Console.WriteLine(string.Join(" ", rxData.Select(b => $"0x{b:X2}")));
Open a device by serial number
using Mcp2210Handle handle = new(vid: 0x04D8, pid: 0x00DE, serialNo: "0123456789");
Read and write GPIO pins
using Oakrey.Microchip.Mcp2210.Wrapper.DataTypes;
GpioValue pin2 = handle.GetPinValue(index: 2);
Console.WriteLine($"Pin 2: {pin2}");
// Set pin 0 high, leave others unchanged
uint current = handle.GetPinsValue();
handle.SetPinsValue(current | 0b0000_0001);
Configure SPI baud rate in NVRAM
handle.BaudRate(ConfigurationMemoryType.NVRAM, baudRate: 500_000);
Read and write EEPROM
byte value = handle.ReadEeprom(address: 0x00);
handle.WriteEeprom(address: 0x00, content: 0xAB);
Enumerate connected devices
int count = Mcp2210AccessWrapper.GetConnectedDevicesCount(vid: 0x04D8, pid: 0x00DE);
string version = Mcp2210AccessWrapper.GetLibraryVersion();
Console.WriteLine($"Devices: {count}, Library: {version}");
Development Notes
Mcp2210HandleextendsSafeHandleZeroOrMinusOneIsInvalid; it closes the device inReleaseHandle()and is safe to use withusing.ConfigurationMemoryTypecontrols whether settings are applied to volatile RAM (immediate, lost on power cycle) or NVRAM (persisted across resets).- Chip-select lines in
SendDataare addressed by a zero-based index; the wrapper converts this to a bitmask internally (1 << csIndex). - All extension methods throw
Mcp2210Exceptionon a negative native error code. No error codes are silently swallowed. - Native DLLs are bundled in the package under
lib\net10.0and copied to the output directory automatically. No separate driver installation is required beyond the USB device being recognised by Windows HID. AllowUnsafeBlocksis enabled because several native method signatures use unmanaged structs passed by pointer.- The serial number constructor enforces exactly 10 characters as required by the MCP2210 firmware.
Project Information
| Field | Value |
|---|---|
| Package ID | Oakrey.Microchip.Mcp2210.Wrapper |
| Version | 2.0.1 |
| Author | Oakrey |
| License | MIT |
| Target | net10.0 (Windows) |
| Repository | https://dev.azure.com/oakrey/OpenPackages/_git/Drivers |
| Project URL | https://www.oakrey.cz/opkg_drivers_microchip |
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.