MCP2210 Library
An Open Source MCP2210 Library for Linux.
mcp2210.cpp File Reference
#include "mcp2210.h"

Functions

int SendUSBCmd (hid_device *handle, byte *cmdBuf, byte *responseBuf)
SPITransferSettingsDef GetSPITransferSettings (hid_device *handle, bool isVolatile)
int SetSPITransferSettings (hid_device *handle, SPITransferSettingsDef def, bool isVolatile)
ChipSettingsDef GetChipSettings (hid_device *handle, bool isVolatile)
int SetChipSettings (hid_device *handle, ChipSettingsDef def, bool isVolatile)
USBKeyParametersDef GetUSBKeyParameters (hid_device *handle)
int SetUSBKeyParameters (hid_device *handle, USBKeyParametersDef def)
ManufacturerProductNameDef GetManufacturerProductName (hid_device *handle, unsigned int subCmdCode)
int SetManufacturerProductName (hid_device *handle, unsigned int subCmdCode, ManufacturerProductNameDef def)
int SendAccessPassword (hid_device *handle, char *pwd, int pwdLength)
int ReadEEPROM (hid_device *handle, byte addr, byte *val)
int WriteEEPROM (hid_device *handle, byte addr, byte val)
int RequestSPIBusRelease (hid_device *handle, byte val)
ChipStatusDef GetChipStatus (hid_device *handle)
ChipStatusDef CancelSPITransfer (hid_device *handle)
SPIDataTransferStatusDef SPIDataTransfer (hid_device *handle, byte *data, int length)
SPIDataTransferStatusDef SPISendReceive (hid_device *handle, byte *data, int cmdBufferLength, int dataLength)
ExternalInterruptPinStatusDef GetNumOfEventsFromInterruptPin (hid_device *handle, byte resetCounter)
GPPinDef GetGPIOPinDirection (hid_device *handle)
int SetGPIOPinDirection (hid_device *handle, GPPinDef def)
GPPinDef GetGPIOPinValue (hid_device *handle)
int SetGPIOPinVal (hid_device *handle, GPPinDef def)
hid_device_infoEnumerateMCP2210 ()
hid_deviceInitMCP2210 (unsigned short vid, unsigned short pid, wchar_t *serialNumber)
hid_deviceInitMCP2210 (wchar_t *serialNumber)
hid_deviceInitMCP2210 ()
void ReleaseMCP2210 (hid_device *handle)

Function Documentation

Cancel the current SPI transfer

Parameters:
handleThe handle to the MCP2210 device
Returns:
See also:
ChipStatusDef

Enumerate the connected MCP2210's

Returns:
a pointer to hid_device_info
ChipSettingsDef GetChipSettings ( hid_device handle,
bool  isVolatile = true 
)

Get power-up settings

Parameters:
handleThe handle to the MCP2210 device
isVolatile(default true) Whether to make change permanently or in memory only.
Returns:
See also:
ChipSettingsDef

Get MCP2210 status

Parameters:
handleThe handle to the MCP2210 device
Returns:
See also:
ChipStatusDef

Get GPIO current pin direction from volatile memory

Parameters:
handleThe handle to the MCP2210 device
Returns:
See also:
GPPinDef note, only the direction member variable is affected.

Get GPIO current pin value

Parameters:
handleThe handle to the MCP2210 device
Returns:
See also:
GPPinDef note, only the value member variable is affected.
ManufacturerProductNameDef GetManufacturerProductName ( hid_device handle,
unsigned int  subCmdCode 
)

Set USB manufacturer name or product name

Parameters:
handleThe handle to the MCP2210 device
subCmdCodeThe sub command code which determines whether the action is to set manufacturer name or product name:

CMDSUB_USB_MANUFACTURER_NAME: set manufacturer name CMDSUB_USB_PRODUCT_NAME: set product name

Returns:
See also:
USBManufacturerProductNameDef

Get the current number of events from the interrupt pin

Note, GP6 must be configured to have its dedicated function active.

Parameters:
handleThe handle to the MCP2210 device
resetCounter0x0: reads, then resets the event counter >0: the event counter is read, however the counter is not reset
Returns:
0: Operation was successful <0: Other device errors (see error codes)
SPITransferSettingsDef GetSPITransferSettings ( hid_device handle,
bool  isVolatile = true 
)

Get SPI power-up transfer settings

Parameters:
handleThe handle to the MCP2210 device
isVolatile(default true) Whether to make change permanently or in memory only.

ture: in memory only. false: changes are written to NVRAM

Returns:
See also:
SPITransferSettingsDef

Get USB power-up key parameters

Parameters:
handleThe handle to the MCP2210 device
Returns:
See also:
USBKeyParametersDef
hid_device* InitMCP2210 ( unsigned short  vid,
unsigned short  pid,
wchar_t *  serialNumber 
)

Initialize MCP2210 (using all parameters)

Parameters:
vidVender ID
pidProduct ID
serialNumberSerial number
Returns:
The handle to the MCP2210 device
hid_device* InitMCP2210 ( wchar_t *  serialNumber)

Initialize MCP2210 (if more than one is present) Vendor ID: 0x04d8 Product ID: 0x00de

Parameters:
serialNumberThe serial number of the MCP2210 device
Returns:
The handle to the MCP2210 device

Initialize MCP2210 Vendor ID: 0x04d8 Product ID: 0x00de

Returns:
The handle to the MCP2210 device
int ReadEEPROM ( hid_device handle,
byte  addr,
byte val 
)

Read EEPROM Memory

Parameters:
handleThe handle to the MCP2210 device
addrThe address to be accessed (0-255)
valThe byte read at the specified address
Returns:
0: Operation was successful <0: Other device errors (see error codes)
void ReleaseMCP2210 ( hid_device handle)

Release the device handle and close the device

Parameters:
handleThe handle to the MCP2210 device
int RequestSPIBusRelease ( hid_device handle,
byte  val 
)

Request SPI bus release

Parameters:
handleThe handle to the MCP2210 device
valThe value of the SPI bus release ACK pin (only if GP7 is assigned to this dedicated function)
Returns:
0: Operation was successful 0xF8: SPI transfer in process (BUS not released) <0: Other device errors (see error codes)
int SendAccessPassword ( hid_device handle,
char *  pwd,
int  pwdLength 
)

Send access password

Parameters:
handleThe handle to the MCP2210 device
pwdpassword
pwdLengthpassword length (<=8)
Returns:
0: Operation was successful 0xFB: Chip conditional access is on, the password does not match and the number of attempts is above the accepted threshold of 5. The Access Password mechanism is temporarily blocked and no further password will be accepted until the next power-up. 0xFC: Access rejected 0XFD: Chip conditional access is on, the password does not match and the number of attempts is less than the accepted threshold of 5.
int SendUSBCmd ( hid_device handle,
byte cmdBuf,
byte responseBuf 
)

Send a USB command

Parameters:
handleThe handle to the MCP2210 device
cmdBufcommand buffer (64 bytes), unused/reserved entries must be filled with zero.
responseBufthe buffer (64 bytes) that contains the response.
Returns:
0: Operation was successful <0: Other device errors (see error codes)
int SetChipSettings ( hid_device handle,
ChipSettingsDef  def,
bool  isVolatile = true 
)

Set chip settings power-up default

Parameters:
handleThe handle to the MCP2210 device
def
See also:
ChipSettingDef
Parameters:
isVolatile(default true) Whether to make change permanently or in memory only.

ture: in memory only. false: changes are written to NVRAM

Returns:
0: Operation was successful 0xFB: The provided password does not match the one stored in the chip or the settings are permanently locked. <0: Other device errors (see error codes)
int SetGPIOPinDirection ( hid_device handle,
GPPinDef  def 
)

Set GPIO current pin direction in volatile memory

Parameters:
handleThe handle to the MCP2210 device
def
See also:
GPPinDef note, only the direction member variable is used.
Returns:
0: Operation was successful <0: Other device errors (see error codes)
int SetGPIOPinVal ( hid_device handle,
GPPinDef  def 
)

Set GPIO current pin value

Parameters:
handleThe handle to the MCP2210 device
def
See also:
GPPinDef note, only the value member variable is used.
Returns:
0: Operation was successful <0: Other device errors (see error codes)
int SetManufacturerProductName ( hid_device handle,
unsigned int  subCmdCode,
ManufacturerProductNameDef  def 
)

Set USB manufacturer name or product name

Parameters:
handleThe handle to the MCP2210 device
subCmdCodeThe sub command code which determines whether the action is to set manufacturer name or product name:

CMDSUB_USB_MANUFACTURER_NAME: set manufacturer name CMDSUB_USB_PRODUCT_NAME: set product name

Parameters:
def
See also:
USBManufacturerProductNameDef
Returns:
0: Operation was successful 0xFB: The provided password does not match the one stored in the chip or the settings are permanently locked. <0: Other device errors (see error codes)
int SetSPITransferSettings ( hid_device handle,
SPITransferSettingsDef  def,
bool  isVolatile = true 
)

Set SPI power-up transfer settings

Parameters:
handleThe handle to the MCP2210 device
def
See also:
SPITransferSettingsDef
Parameters:
isVolatile(default true) Whether to make change permanently or in memory only.

ture: in memory only. false: changes are written to NVRAM

Returns:
0: Operation was successful 0xFB: The provided password does not match the one stored in the chip or the settings are permanently locked. <0: Other device errors (see error codes)
int SetUSBKeyParameters ( hid_device handle,
USBKeyParametersDef  def 
)

Set USB power-up key parameters

Parameters:
handleThe handle to the MCP2210 device
def
See also:
USBKeyParametersDef
Returns:
0: Operation was successful 0xFB: The provided password does not match the one stored in the chip or the settings are permanently locked. <0: Other device errors (see error codes)
SPIDataTransferStatusDef SPIDataTransfer ( hid_device handle,
byte data,
int  length 
)

SPI Data Transfer

Parameters:
handleThe handle to the MCP2210 device
dataa pointer to the data array to be transfered
lengthnumber of bytes to be transfered
Returns:
See also:
SPIDataTransferStatusDef ErrorCode meaning: 0xF7: SPI bus not available 0xF8: SPI transfer in progress (cannot accept any data for the moment)
SPIDataTransferStatusDef SPISendReceive ( hid_device handle,
byte data,
int  cmdBufferLength,
int  dataLength = -1 
)

Send data and wait till results are received from the SPI bus.

Note: this method differers from SPIDataTransfer in that it also waits till the transfer is finished. In SPIDataTransfer, the SPIEngineStatus in the returned data structure tells the status of the SPI engine, and the call returns after the data is sent, regardless of whether the data has been received.

Parameters:
handleThe handle to the MCP2210 device
dataa pointer to the data array to be transfered
cmdBufferLengthnumber of command bytes to be transfered
dataLength(optional) number of data elements to be returned

if this parameter is not supplied the default length is set to be the same as the command buffer length

Returns:
See also:
SPIDataTransferStatusDef ErrorCode meaning: 0xF7: SPI bus not available 0xF8: SPI transfer in progress (cannot accept any data for the moment)
int WriteEEPROM ( hid_device handle,
byte  addr,
byte  val 
)

Write EEPROM Memory

Parameters:
handleThe handle to the MCP2210 device
addrThe address to be accessed (0-255)
valThe byte to be written to the specified address.
Returns:
0: Operation was successful 0xFA: EEPROM Write failure 0xFB: EEPROM is password protected or permanently locked. <0: Other device errors (see error codes)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines