libeasymcp2221 2.0.3
libeasymcp2221 v2

libeasymcp2221 is a C library for Microchip MCP2221/MCP2221A USB-to-I2C/GPIO bridges. Version 2 provides a C-style API based on explicit device handles, error codes, and function-based interfaces.

Quick start

Installed headers use the libeasymcp2221/ include prefix. The umbrella header provides the complete supported public API:

#include <libeasymcp2221/libeasymcp2221.h>
int main(void) {
mcp2221_t *dev = NULL;
0, NULL, 100000, &dev);
if (err != MCP2221_ERR_OK)
return 1;
return 0;
}
mcp2221_error_code_t mcp2221_open_simple(uint16_t vid, uint16_t pid, int devnum, const char *usbserial, int i2c_speed_hz, mcp2221_t **out_dev)
Open and initialize an MCP2221 using an EasyMCP2221-style setup.
struct mcp2221_device mcp2221_t
Opaque MCP2221 device handle.
Definition: mcp2221.h:28
void mcp2221_close(mcp2221_t *dev)
Close an MCP2221 device handle.
#define MCP2221_DEV_DEFAULT_VID
Default Microchip USB vendor ID for MCP2221 devices.
#define MCP2221_DEV_DEFAULT_PID
Default USB product ID for MCP2221/MCP2221A devices.
mcp2221_error_code_t
Error codes used by libeasymcp2221.
@ MCP2221_ERR_OK

Most operations return MCP2221_ERR_OK on success or another mcp2221_error_code_t value on failure. Each successful mcp2221_open*() call acquires one device reference and must be matched by one mcp2221_close() call.

API reference

The API reference is generated from the public headers in include/. The core device and I2C master API is declared in mcp2221.h; additional headers cover I2C slave and SMBus helpers, GPIO and pin configuration, SRAM and flash settings, ADC/DAC support, clock output, interrupt-on-change, USB attributes and CDC configuration, revision/reset support, and error handling.

Resource ownership

Each successful mcp2221_open*() call acquires one device reference and must be matched by one mcp2221_close() call. A matching device may reuse an already open underlying handle internally.

Higher-level helper objects document their ownership rules in their respective public headers.

Hardware validation

The optional hardware test suite validates the public API against a physical MCP2221 fixture, including GPIO and analog loopbacks, EEPROM-backed I2C transfers, controlled SCL/SDA fault injection, flash persistence/reset and a UTX-to-URX CDC-UART loopback.

libeasymcp2221 hardware test fixture

The exact wiring, test commands and device-selection options are documented in tests/hardware/README.md.

Thread safety

Opening and closing devices is internally serialized for the library's global libusb state. Operations on an already opened mcp2221_t * are not serialized by the library; applications sharing a handle between threads must provide their own synchronization.

Further documentation

The generated documentation also includes:

  • BUILD.md for building, installing, packaging, and generating the API docs.
  • MIGRATION.md for migration from libeasymcp2221 1.x to 2.x.
  • API-Reference.md for the EasyMCP2221-to-libeasymcp2221 concept mapping.
  • tests/hardware/README.md for the optional physical test fixture and suite.

README.md remains the project overview on GitHub, and examples/ contains small programs using the public v2 API.