MCP2221 HID Library  1.0.4
Data Structures | Macros | Enumerations | Functions
libmcp2221.h File Reference
#include <stdint.h>
#include <wchar.h>

Go to the source code of this file.

Data Structures

struct  mcp2221_usbinfo_t
 Contains enumerated USB info about the device. More...
 
struct  mcp2221_t
 TODO. More...
 
struct  mcp2221_i2cpins_t
 Raw I2C pin values. More...
 
struct  mcp2221_gpioconf_t
 GPIO configuration. More...
 
struct  mcp2221_gpioconfset_t
 TODO. More...
 

Macros

#define MCP2221_STR_LEN   31
 
#define MCP2221_GPIO_COUNT   4
 
#define MCP2221_DAC_MAX   31
 
#define MCP2221_ADC_COUNT   3
 
#define MCP2221_DEFAULT_VID   0x04D8
 
#define MCP2221_DEFAULT_PID   0x00DD
 
#define MCP2221_DEFAULT_MANUFACTURER   L"Microchip Technology Inc."
 
#define MCP2221_DEFAULT_PRODUCT   L"MCP2221 USB-I2C/UART Combo"
 
#define MCP2221_REPORT_SIZE   64
 
#define MCP2221_GPIO_MODE_SSPND   MCP2221_GPIO_MODE_DEDI
 
#define MCP2221_GPIO_MODE_ADC   MCP2221_GPIO_MODE_ALT1
 
#define MCP2221_GPIO_MODE_DAC   MCP2221_GPIO_MODE_ALT2
 
#define MCP2221_GPIO_MODE_IOC   MCP2221_GPIO_MODE_ALT3
 

Enumerations

enum  mcp2221_error { MCP2221_SUCCESS = 0, MCP2221_ERROR = -1, MCP2221_INVALID_ARG = -2, MCP2221_ERROR_HID = -3 }
 Error codes. More...
 
enum  mcp2221_i2c_state_t { MCP2221_I2C_IDLE = 0, MCP2221_I2C_ADDRNOTFOUND = 37, MCP2221_I2C_DATAREADY = 85, MCP2221_I2C_UNKNOWN1 = 98 }
 I2C states (TODO: incomplete) More...
 
enum  mcp2221_dac_ref_t {
  MCP2221_DAC_REF_4096 = 7, MCP2221_DAC_REF_2048 = 5, MCP2221_DAC_REF_1024 = 3, MCP2221_DAC_REF_OFF = 1,
  MCP2221_DAC_REF_VDD = 0
}
 Reference voltages for DAC. More...
 
enum  mcp2221_adc_ref_t {
  MCP2221_ADC_REF_4096 = 7, MCP2221_ADC_REF_2048 = 5, MCP2221_ADC_REF_1024 = 3, MCP2221_ADC_REF_OFF = 1,
  MCP2221_ADC_REF_VDD = 0
}
 Reference voltages for ADC. More...
 
enum  mcp2221_int_trig_t { MCP2221_INT_TRIG_INVALID = 0, MCP2221_INT_TRIG_RISING = 0b00001000, MCP2221_INT_TRIG_FALLING = 0b00000010, MCP2221_INT_TRIG_BOTH = 0b00001010 }
 Trigger modes for interrupt. More...
 
enum  mcp2221_gpio_mode_t {
  MCP2221_GPIO_MODE_GPIO = 0, MCP2221_GPIO_MODE_DEDI = 1, MCP2221_GPIO_MODE_ALT1 = 2, MCP2221_GPIO_MODE_ALT2 = 3,
  MCP2221_GPIO_MODE_ALT3 = 4, MCP2221_GPIO_MODE_INVALID = 0xff
}
 GPIO modes (check GP DESIGNATION TABLE in the datasheet for what the dedicated and alternative functions do for each pin) More...
 
enum  mcp2221_gpio_value_t { MCP2221_GPIO_VALUE_HIGH = 1, MCP2221_GPIO_VALUE_LOW = 0, MCP2221_GPIO_VALUE_INVALID = 0xEE }
 GPIO read values. More...
 
enum  mcp2221_gpio_direction_t { MCP2221_GPIO_DIR_INPUT = 1, MCP2221_GPIO_DIR_OUTPUT = 0, MCP2221_GPIO_DIR_INVALID = 0xEF }
 Direction when pin is set to GPIO mode. More...
 
enum  mcp2221_pwrsrc_t { MCP2221_PWRSRC_SELFPOWERED = 0x40, MCP2221_PWRSRC_BUSPOWERED = 0 }
 Power source. More...
 
enum  mcp2221_wakeup_t { MCP2221_WAKEUP_DISABLED = 0, MCP2221_WAKEUP_ENABLED = 0x20 }
 Remote wakeup (wakeup the USB host from sleep mode) More...
 
enum  mcp2221_clkdiv_t {
  MCP2221_CLKDIV_RESERVED = 0, MCP2221_CLKDIV_2 = 1, MCP2221_CLKDIV_4 = 2, MCP2221_CLKDIV_8 = 3,
  MCP2221_CLKDIV_16 = 4, MCP2221_CLKDIV_32 = 5, MCP2221_CLKDIV_64 = 6, MCP2221_CLKDIV_128 = 7
}
 Clock reference output divider from 48MHz. More...
 
enum  mcp2221_clkduty_t { MCP2221_CLKDUTY_0 = 0x00, MCP2221_CLKDUTY_25 = 0x08, MCP2221_CLKDUTY_50 = 0x10, MCP2221_CLKDUTY_75 = 0x18 }
 Clock reference output duty cycle. More...
 
enum  mcp2221_i2crw_t { MCP2221_I2CRW_NORMAL = 0, MCP2221_I2CRW_REPEATED = 1, MCP2221_I2CRW_NOSTOP = 2 }
 TODO. More...
 
enum  mcp2221_dedipin_t {
  MCP2221_DEDIPIN_LEDUARTRX = 6, MCP2221_DEDIPIN_LEDUARTTX = 5, MCP2221_DEDIPIN_LEDI2C = 4, MCP2221_DEDIPIN_SSPND = 3,
  MCP2221_DEDIPIN_USBCFG = 2
}
 Used to select which dedicated pin to operate on (only used for setting/getting polarity) More...
 
enum  mcp2221_gpio_t { MCP2221_GPIO0 = 1, MCP2221_GPIO1 = 2, MCP2221_GPIO2 = 4, MCP2221_GPIO3 = 8 }
 GPIO pins. More...
 

Functions

mcp2221_error mcp2221_init (void)
 Initialise, must be called before anything else! More...
 
void mcp2221_exit (void)
 TODO. More...
 
int mcp2221_find (int vid, int pid, wchar_t *manufacturer, wchar_t *product, wchar_t *serial)
 Find all HIDs matching the supplied parameters, must be called before attempting to open a device. More...
 
int mcp2221_sameDevice (mcp2221_t *dev1, mcp2221_t *dev2)
 TODO. More...
 
mcp2221_tmcp2221_open (void)
 Open first MCP2221 device found. More...
 
mcp2221_tmcp2221_open_byIndex (int idx)
 Open device with specified index number (starting from 0 up to however many devices were found) More...
 
mcp2221_tmcp2221_open_bySerial (wchar_t *serial)
 Open device with specified serial. More...
 
void mcp2221_close (mcp2221_t *device)
 Close device. More...
 
mcp2221_error mcp2221_reset (mcp2221_t *device)
 Perform a reset of the device. More...
 
mcp2221_error mcp2221_isConnected (mcp2221_t *device)
 Check to see if the device is still connected, should return MCP2221_SUCCESS. More...
 
mcp2221_error mcp2221_rawReport (mcp2221_t *device, uint8_t *report)
 Send a custom report, the response is placed in the same buffer. More...
 
mcp2221_gpioconfset_t mcp2221_GPIOConfInit (void)
 TODO. More...
 
mcp2221_error mcp2221_setClockOut (mcp2221_t *device, mcp2221_clkdiv_t div, mcp2221_clkduty_t duty)
 Set the clock reference output divider and duty cycle (SRAM) More...
 
mcp2221_error mcp2221_setDAC (mcp2221_t *device, mcp2221_dac_ref_t ref, int value)
 Set the DAC voltage reference and output value (SRAM) More...
 
mcp2221_error mcp2221_setADC (mcp2221_t *device, mcp2221_adc_ref_t ref)
 Set the ADC voltage reference (SRAM) More...
 
mcp2221_error mcp2221_setInterrupt (mcp2221_t *device, mcp2221_int_trig_t trig, int clearInt)
 Set the interrupt trigger mode and optionally clear pending interrupt (SRAM) More...
 
mcp2221_error mcp2221_setGPIOConf (mcp2221_t *device, mcp2221_gpioconfset_t *confSet)
 Apply GPIO configuration. More...
 
mcp2221_error mcp2221_setGPIO (mcp2221_t *device, mcp2221_gpio_t pins, mcp2221_gpio_value_t value)
 Set GPIO pin output values. More...
 
mcp2221_error mcp2221_getClockOut (mcp2221_t *device, mcp2221_clkdiv_t *div, mcp2221_clkduty_t *duty)
 Get the current clock output divider (SRAM) More...
 
mcp2221_error mcp2221_getDAC (mcp2221_t *device, mcp2221_dac_ref_t *ref, int *value)
 Get the current DAC voltage reference and output value (SRAM) More...
 
mcp2221_error mcp2221_getADC (mcp2221_t *device, mcp2221_adc_ref_t *ref)
 Get the current ADC voltage reference (SRAM) More...
 
mcp2221_error mcp2221_getInterrupt (mcp2221_t *device, mcp2221_int_trig_t *trig)
 Get the current interrupt trigger mode (SRAM) More...
 
mcp2221_error mcp2221_getGPIO (mcp2221_t *device, mcp2221_gpioconfset_t *confGet)
 Get the current GPIO configuration (SRAM) More...
 
mcp2221_error mcp2221_readADC (mcp2221_t *device, int values[MCP2221_ADC_COUNT])
 Read ADC values. More...
 
mcp2221_error mcp2221_readInterrupt (mcp2221_t *device, int *state)
 Read interrupt state. More...
 
mcp2221_error mcp2221_clearInterrupt (mcp2221_t *device)
 Clear interrupt state. More...
 
mcp2221_error mcp2221_readGPIO (mcp2221_t *device, mcp2221_gpio_value_t values[MCP2221_GPIO_COUNT])
 Read GPIO values. More...
 
mcp2221_error mcp2221_saveManufacturer (mcp2221_t *device, wchar_t *buffer)
 Save new manufacturer USB descriptor string to flash (max 30 characters) More...
 
mcp2221_error mcp2221_saveProduct (mcp2221_t *device, wchar_t *buffer)
 Save new product USB descriptor string to flash (max 30 characters) More...
 
mcp2221_error mcp2221_saveSerial (mcp2221_t *device, wchar_t *buffer)
 Save new serial USB descriptor string to flash (max 30 characters) More...
 
mcp2221_error mcp2221_saveVIDPID (mcp2221_t *device, int vid, int pid)
 Save new VID and PID to flash. More...
 
mcp2221_error mcp2221_saveSerialEnumerate (mcp2221_t *device, int enumerate)
 Enable/disable enumerating with serial number. More...
 
mcp2221_error mcp2221_saveMilliamps (mcp2221_t *device, int milliamps)
 Set USB current limit. More...
 
mcp2221_error mcp2221_savePowerSource (mcp2221_t *device, mcp2221_pwrsrc_t source)
 Set power source. More...
 
mcp2221_error mcp2221_saveRemoteWakeup (mcp2221_t *device, mcp2221_wakeup_t wakeup)
 Enable/disable remote host wakeup. More...
 
mcp2221_error mcp2221_savePolarity (mcp2221_t *device, mcp2221_dedipin_t pin, int polarity)
 Save polarity of dedicated pin functions to flash. More...
 
mcp2221_error mcp2221_saveClockOut (mcp2221_t *device, mcp2221_clkdiv_t div, mcp2221_clkduty_t duty)
 Save clock reference output settings to flash. More...
 
mcp2221_error mcp2221_saveDAC (mcp2221_t *device, mcp2221_dac_ref_t ref, int value)
 Save the DAC voltage reference and output value to flash. More...
 
mcp2221_error mcp2221_saveADC (mcp2221_t *device, mcp2221_adc_ref_t ref)
 Save the ADC voltage reference to flash. More...
 
mcp2221_error mcp2221_saveInterrupt (mcp2221_t *device, mcp2221_int_trig_t trig)
 Save the interrupt trigger mode to flash. More...
 
mcp2221_error mcp2221_saveGPIOConf (mcp2221_t *device, mcp2221_gpioconfset_t *confSet)
 Save GPIO configuration to flash. More...
 
mcp2221_error mcp2221_loadManufacturer (mcp2221_t *device, wchar_t *buffer)
 Read manufacturer USB descriptor string from flash. More...
 
mcp2221_error mcp2221_loadProduct (mcp2221_t *device, wchar_t *buffer)
 Read product USB descriptor string from flash. More...
 
mcp2221_error mcp2221_loadSerial (mcp2221_t *device, wchar_t *buffer)
 Read serial USB descriptor string from flash. More...
 
mcp2221_error mcp2221_loadVIDPID (mcp2221_t *device, int *vid, int *pid)
 Read VID and PID from flash. More...
 
mcp2221_error mcp2221_loadSerialEnumerate (mcp2221_t *device, int *enumerate)
 Read serial enumeration setting from flash. More...
 
mcp2221_error mcp2221_loadMilliamps (mcp2221_t *device, int *milliamps)
 Read current limit from flash. More...
 
mcp2221_error mcp2221_loadPowerSource (mcp2221_t *device, mcp2221_pwrsrc_t *source)
 Read power source from flash. More...
 
mcp2221_error mcp2221_loadRemoteWakeup (mcp2221_t *device, mcp2221_wakeup_t *wakeup)
 Read remote USB host wakeup from flash. More...
 
mcp2221_error mcp2221_loadPolarity (mcp2221_t *device, mcp2221_dedipin_t pin, int *polarity)
 Read dedicated pin polarity from flash. More...
 
mcp2221_error mcp2221_loadClockOut (mcp2221_t *device, mcp2221_clkdiv_t *div, mcp2221_clkduty_t *duty)
 Read clock output settings from flash. More...
 
mcp2221_error mcp2221_loadDAC (mcp2221_t *device, mcp2221_dac_ref_t *ref, int *value)
 Read DAC settings from flash. More...
 
mcp2221_error mcp2221_loadADC (mcp2221_t *device, mcp2221_adc_ref_t *ref)
 Read ADC settings from flash. More...
 
mcp2221_error mcp2221_loadInterrupt (mcp2221_t *device, mcp2221_int_trig_t *trig)
 Read interrupt settings from flash. More...
 
mcp2221_error mcp2221_loadGPIOConf (mcp2221_t *device, mcp2221_gpioconfset_t *confSet)
 Read GPIO config from flash. More...
 
mcp2221_error mcp2221_i2cWrite (mcp2221_t *device, int address, void *data, int len, mcp2221_i2crw_t type)
 Perform an I2C write. More...
 
mcp2221_error mcp2221_i2cRead (mcp2221_t *device, int address, int len, mcp2221_i2crw_t type)
 Perform an I2C read. More...
 
mcp2221_error mcp2221_i2cGet (mcp2221_t *device, void *data, int len)
 Get the data that was read. More...
 
mcp2221_error mcp2221_i2cCancel (mcp2221_t *device)
 TODO. More...
 
mcp2221_error mcp2221_i2cState (mcp2221_t *device, mcp2221_i2c_state_t *state)
 TODO. More...
 
mcp2221_error mcp2221_i2cDivider (mcp2221_t *device, int i2cdiv)
 TODO. More...
 
mcp2221_error mcp2221_i2cReadPins (mcp2221_t *device, mcp2221_i2cpins_t *pins)
 Read raw values of I2C pins. Allows using these pins as 2 additional input pins. More...
 

Macro Definition Documentation

#define MCP2221_ADC_COUNT   3

ADC count

#define MCP2221_DAC_MAX   31

Maximum value of DAC output

#define MCP2221_DEFAULT_MANUFACTURER   L"Microchip Technology Inc."

Default manufacturer descriptor

#define MCP2221_DEFAULT_PID   0x00DD

Default PID

#define MCP2221_DEFAULT_PRODUCT   L"MCP2221 USB-I2C/UART Combo"

Default product descriptor

#define MCP2221_DEFAULT_VID   0x04D8

Default VID

#define MCP2221_GPIO_COUNT   4

GPIO pin count

#define MCP2221_GPIO_MODE_ADC   MCP2221_GPIO_MODE_ALT1

TODO

#define MCP2221_GPIO_MODE_DAC   MCP2221_GPIO_MODE_ALT2

TODO

#define MCP2221_GPIO_MODE_IOC   MCP2221_GPIO_MODE_ALT3

TODO

#define MCP2221_GPIO_MODE_SSPND   MCP2221_GPIO_MODE_DEDI

TODO

#define MCP2221_REPORT_SIZE   64

HID Report size

#define MCP2221_STR_LEN   31

Maximum length of wchar_t USB descriptor strings + 1 for null term

Enumeration Type Documentation

Reference voltages for ADC.

Enumerator
MCP2221_ADC_REF_4096 

4096mV Reference

MCP2221_ADC_REF_2048 

2048mV Reference

MCP2221_ADC_REF_1024 

1024mV Reference

MCP2221_ADC_REF_OFF 

No reference

MCP2221_ADC_REF_VDD 

VDD Reference

Clock reference output divider from 48MHz.

Enumerator
MCP2221_CLKDIV_RESERVED 

Invalid

MCP2221_CLKDIV_2 

24MHz

MCP2221_CLKDIV_4 

12MHz

MCP2221_CLKDIV_8 

6MHz

MCP2221_CLKDIV_16 

3MHz

MCP2221_CLKDIV_32 

1.5MHz

MCP2221_CLKDIV_64 

750KHz

MCP2221_CLKDIV_128 

375KHz

Clock reference output duty cycle.

Enumerator
MCP2221_CLKDUTY_0 

0% duty cycle, disabled

MCP2221_CLKDUTY_25 

25%

MCP2221_CLKDUTY_50 

50%

MCP2221_CLKDUTY_75 

75%

Reference voltages for DAC.

Enumerator
MCP2221_DAC_REF_4096 

4096mV Reference

MCP2221_DAC_REF_2048 

2048mV Reference

MCP2221_DAC_REF_1024 

1024mV Reference

MCP2221_DAC_REF_OFF 

No reference

MCP2221_DAC_REF_VDD 

VDD Reference

Used to select which dedicated pin to operate on (only used for setting/getting polarity)

Enumerator
MCP2221_DEDIPIN_LEDUARTRX 
MCP2221_DEDIPIN_LEDUARTTX 
MCP2221_DEDIPIN_LEDI2C 
MCP2221_DEDIPIN_SSPND 
MCP2221_DEDIPIN_USBCFG 

Error codes.

Enumerator
MCP2221_SUCCESS 

All is well

MCP2221_ERROR 

General error

MCP2221_INVALID_ARG 

Invalid argument supplied, probably a null pointer

MCP2221_ERROR_HID 

HIDAPI returned an error

Direction when pin is set to GPIO mode.

Enumerator
MCP2221_GPIO_DIR_INPUT 

Input

MCP2221_GPIO_DIR_OUTPUT 

Output

MCP2221_GPIO_DIR_INVALID 

GPIO is not set as an input or output

GPIO modes (check GP DESIGNATION TABLE in the datasheet for what the dedicated and alternative functions do for each pin)

Note
GP DESIGNATION TABLE has the ALT_FUNC numbered 0-2, should be 1-3 to match the rest of the datasheet
Enumerator
MCP2221_GPIO_MODE_GPIO 

Normal IO, manually set to input/output, high/low

MCP2221_GPIO_MODE_DEDI 

Dedicated function

MCP2221_GPIO_MODE_ALT1 

Alternative function 1

MCP2221_GPIO_MODE_ALT2 

Alternative function 2

MCP2221_GPIO_MODE_ALT3 

Alternative function 3

MCP2221_GPIO_MODE_INVALID 

Invalid

GPIO pins.

Enumerator
MCP2221_GPIO0 

GPIO0

MCP2221_GPIO1 

GPIO1

MCP2221_GPIO2 

GPIO2

MCP2221_GPIO3 

GPIO3

GPIO read values.

Enumerator
MCP2221_GPIO_VALUE_HIGH 

GPIO pin reads HIGH

MCP2221_GPIO_VALUE_LOW 

GPIO pin reads LOW

MCP2221_GPIO_VALUE_INVALID 

GPIO is not set as an input or output

I2C states (TODO: incomplete)

Enumerator
MCP2221_I2C_IDLE 
MCP2221_I2C_ADDRNOTFOUND 
MCP2221_I2C_DATAREADY 
MCP2221_I2C_UNKNOWN1 

TODO.

Enumerator
MCP2221_I2CRW_NORMAL 
MCP2221_I2CRW_REPEATED 
MCP2221_I2CRW_NOSTOP 

Trigger modes for interrupt.

Enumerator
MCP2221_INT_TRIG_INVALID 

Invalid

MCP2221_INT_TRIG_RISING 

Trigger on rising edge

MCP2221_INT_TRIG_FALLING 

Trigger on falling edge

MCP2221_INT_TRIG_BOTH 

Trigger on either rising or falling edge (MCP2221_INT_TRIG_RISING | MCP2221_INT_TRIG_FALLING)

Power source.

Enumerator
MCP2221_PWRSRC_SELFPOWERED 
MCP2221_PWRSRC_BUSPOWERED 

Remote wakeup (wakeup the USB host from sleep mode)

Enumerator
MCP2221_WAKEUP_DISABLED 

Disable USB host wakeup

MCP2221_WAKEUP_ENABLED 

Enable USB host wakeup

Function Documentation

mcp2221_error mcp2221_clearInterrupt ( mcp2221_t device)

Clear interrupt state.

Parameters
[device]Device to operate on
Returns
mcp2221_error error code
void mcp2221_close ( mcp2221_t device)

Close device.

Returns
(none)
void mcp2221_exit ( void  )

TODO.

Returns
(none)
int mcp2221_find ( int  vid,
int  pid,
wchar_t *  manufacturer,
wchar_t *  product,
wchar_t *  serial 
)

Find all HIDs matching the supplied parameters, must be called before attempting to open a device.

Parameters
[vid]VID to match, 0 will match all VIDs
[pid]PID to match, 0 will match all PIDs
[manufacturer]Manufacturer to match, NULL will match all manufacturers
[product]Product to match, NULL will match all products
[serial]Serial to match, NULL will match all serials (enumerating with serial needs to be enabled for this to work - mcp2221_saveSerialEnumerate())
Returns
Number of devices found
mcp2221_error mcp2221_getADC ( mcp2221_t device,
mcp2221_adc_ref_t ref 
)

Get the current ADC voltage reference (SRAM)

Parameters
[device]Device to operate on
[ref]Pointer to mcp2221_adc_ref_t variable where value will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_getClockOut ( mcp2221_t device,
mcp2221_clkdiv_t div,
mcp2221_clkduty_t duty 
)

Get the current clock output divider (SRAM)

Parameters
[device]Device to operate on
[div]Pointer to mcp2221_clkdiv_t variable where value will be placed
[duty]Pointer to mcp2221_clkduty_t variable where value will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_getDAC ( mcp2221_t device,
mcp2221_dac_ref_t ref,
int *  value 
)

Get the current DAC voltage reference and output value (SRAM)

Parameters
[device]Device to operate on
[ref]Pointer to mcp2221_dac_ref_t variable where value will be placed
[value]Pointer to int variable where value will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_getGPIO ( mcp2221_t device,
mcp2221_gpioconfset_t confGet 
)

Get the current GPIO configuration (SRAM)

Parameters
[device]Device to operate on
[confGet]Pointer to mcp2221_gpioconfset_t struct where data will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_getInterrupt ( mcp2221_t device,
mcp2221_int_trig_t trig 
)

Get the current interrupt trigger mode (SRAM)

Parameters
[device]Device to operate on
[trig]Pointer to mcp2221_int_trig_t variable where value will be placed
Returns
mcp2221_error error code
mcp2221_gpioconfset_t mcp2221_GPIOConfInit ( void  )

TODO.

Returns
mcp2221_gpioconfset_t
mcp2221_error mcp2221_i2cCancel ( mcp2221_t device)

TODO.

Parameters
[device]Device to operate on
Returns
mcp2221_error error code
Note
I2C is not fully implemented yet
mcp2221_error mcp2221_i2cDivider ( mcp2221_t device,
int  i2cdiv 
)

TODO.

Parameters
[device]Device to operate on
[i2cdiv]TODO
Returns
mcp2221_error error code
Note
I2C is not fully implemented yet
mcp2221_error mcp2221_i2cGet ( mcp2221_t device,
void *  data,
int  len 
)

Get the data that was read.

Parameters
[device]Device to operate on
[data]Buffer to place data into
[len]Number of bytes to read (max 60)
Returns
mcp2221_error error code
Note
I2C is not fully implemented yet
mcp2221_error mcp2221_i2cRead ( mcp2221_t device,
int  address,
int  len,
mcp2221_i2crw_t  type 
)

Perform an I2C read.

Parameters
[device]Device to operate on
[address]I2C slave address (7 bit addresses only)
[len]Number of bytes to read (max 60)
[type]TODO
Returns
mcp2221_error error code
Note
I2C is not fully implemented yet
mcp2221_error mcp2221_i2cReadPins ( mcp2221_t device,
mcp2221_i2cpins_t pins 
)

Read raw values of I2C pins. Allows using these pins as 2 additional input pins.

Parameters
[device]Device to operate on
[pins]Pointer to mcp2221_i2cpins_t struct to place values into
Returns
mcp2221_error error code
mcp2221_error mcp2221_i2cState ( mcp2221_t device,
mcp2221_i2c_state_t state 
)

TODO.

Parameters
[device]Device to operate on
[state]TODO
Returns
mcp2221_error error code
Note
I2C is not fully implemented yet
mcp2221_error mcp2221_i2cWrite ( mcp2221_t device,
int  address,
void *  data,
int  len,
mcp2221_i2crw_t  type 
)

Perform an I2C write.

Parameters
[device]Device to operate on
[address]I2C slave address (7 bit addresses only)
[data]Data to send
[len]Number of bytes to send (max 60)
[type]TODO
Returns
mcp2221_error error code
Note
I2C is not fully implemented yet
mcp2221_error mcp2221_init ( void  )

Initialise, must be called before anything else!

Returns
mcp2221_error error code
mcp2221_error mcp2221_isConnected ( mcp2221_t device)

Check to see if the device is still connected, should return MCP2221_SUCCESS.

Parameters
[device]Device to operate on
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadADC ( mcp2221_t device,
mcp2221_adc_ref_t ref 
)

Read ADC settings from flash.

Parameters
[device]Device to operate on
[ref]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadClockOut ( mcp2221_t device,
mcp2221_clkdiv_t div,
mcp2221_clkduty_t duty 
)

Read clock output settings from flash.

Parameters
[device]Device to operate on
[div]Pointer to mcp2221_clkdiv_t variable where value will be placed
[duty]Pointer to mcp2221_clkduty_t variable where value will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadDAC ( mcp2221_t device,
mcp2221_dac_ref_t ref,
int *  value 
)

Read DAC settings from flash.

Parameters
[device]Device to operate on
[ref]TODO
[value]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadGPIOConf ( mcp2221_t device,
mcp2221_gpioconfset_t confSet 
)

Read GPIO config from flash.

Parameters
[device]Device to operate on
[confSet]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadInterrupt ( mcp2221_t device,
mcp2221_int_trig_t trig 
)

Read interrupt settings from flash.

Parameters
[device]Device to operate on
[trig]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadManufacturer ( mcp2221_t device,
wchar_t *  buffer 
)

Read manufacturer USB descriptor string from flash.

Parameters
[device]Device to operate on
[buffer]Wide string buffer of at least 31 elements (62 bytes)
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadMilliamps ( mcp2221_t device,
int *  milliamps 
)

Read current limit from flash.

Parameters
[device]Device to operate on
[milliamps]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadPolarity ( mcp2221_t device,
mcp2221_dedipin_t  pin,
int *  polarity 
)

Read dedicated pin polarity from flash.

Parameters
[device]Device to operate on
[pin]The dedicated pin to read
[polarity]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadPowerSource ( mcp2221_t device,
mcp2221_pwrsrc_t source 
)

Read power source from flash.

Parameters
[device]Device to operate on
[source]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadProduct ( mcp2221_t device,
wchar_t *  buffer 
)

Read product USB descriptor string from flash.

Parameters
[device]Device to operate on
[buffer]Wide string buffer of at least 31 elements (62 bytes)
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadRemoteWakeup ( mcp2221_t device,
mcp2221_wakeup_t wakeup 
)

Read remote USB host wakeup from flash.

Parameters
[device]Device to operate on
[wakeup]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadSerial ( mcp2221_t device,
wchar_t *  buffer 
)

Read serial USB descriptor string from flash.

Parameters
[device]Device to operate on
[buffer]Wide string buffer of at least 31 elements (62 bytes)
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadSerialEnumerate ( mcp2221_t device,
int *  enumerate 
)

Read serial enumeration setting from flash.

Parameters
[device]Device to operate on
[enumerate]TODO
Returns
mcp2221_error error code
mcp2221_error mcp2221_loadVIDPID ( mcp2221_t device,
int *  vid,
int *  pid 
)

Read VID and PID from flash.

Parameters
[device]Device to operate on
[vid]TODO
[pid]
Returns
mcp2221_error error code
mcp2221_t* mcp2221_open ( void  )

Open first MCP2221 device found.

Returns
mcp2221_error error code
mcp2221_t* mcp2221_open_byIndex ( int  idx)

Open device with specified index number (starting from 0 up to however many devices were found)

Returns
mcp2221_error error code
mcp2221_t* mcp2221_open_bySerial ( wchar_t *  serial)

Open device with specified serial.

Serial enumeration must be enable for this to work - mcp2221_saveSerialEnumerate()

Returns
mcp2221_error error code
mcp2221_error mcp2221_rawReport ( mcp2221_t device,
uint8_t *  report 
)

Send a custom report, the response is placed in the same buffer.

Parameters
[device]Device to operate on
[report]The report, should be an array with at least MCP2221_REPORT_SIZE elements
Returns
mcp2221_error error code
mcp2221_error mcp2221_readADC ( mcp2221_t device,
int  values[MCP2221_ADC_COUNT] 
)

Read ADC values.

Parameters
[device]Device to operate on
[values]Int array of at least MCP2221_ADC_COUNT elements where values will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_readGPIO ( mcp2221_t device,
mcp2221_gpio_value_t  values[MCP2221_GPIO_COUNT] 
)

Read GPIO values.

Parameters
[device]Device to operate on
[values]mcp2221_gpio_value_t array of at least MCP2221_GPIO_COUNT elements where values will be placed
Returns
mcp2221_error error code
mcp2221_error mcp2221_readInterrupt ( mcp2221_t device,
int *  state 
)

Read interrupt state.

Parameters
[device]Device to operate on
[state]Pointer to variable where state will be placed (0 = not triggered, 1 = triggered)
Returns
mcp2221_error error code
mcp2221_error mcp2221_reset ( mcp2221_t device)

Perform a reset of the device.

Parameters
[device]Device to operate on
Returns
mcp2221_error error code
int mcp2221_sameDevice ( mcp2221_t dev1,
mcp2221_t dev2 
)

TODO.

Returns
1 if devices are the same, 0 if not
mcp2221_error mcp2221_saveADC ( mcp2221_t device,
mcp2221_adc_ref_t  ref 
)

Save the ADC voltage reference to flash.

Parameters
[device]Device to operate on
[ref]Voltage reference
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveClockOut ( mcp2221_t device,
mcp2221_clkdiv_t  div,
mcp2221_clkduty_t  duty 
)

Save clock reference output settings to flash.

Parameters
[device]Device to operate on
[div]Frequency divider from 48MHz
[duty]Duty cycle
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveDAC ( mcp2221_t device,
mcp2221_dac_ref_t  ref,
int  value 
)

Save the DAC voltage reference and output value to flash.

Parameters
[device]Device to operate on
[ref]Voltage reference
[value]Output value (0 - 31)
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveGPIOConf ( mcp2221_t device,
mcp2221_gpioconfset_t confSet 
)

Save GPIO configuration to flash.

Parameters
[device]Device to operate on
[confSet]Pointer to mcp2221_gpioconfset_t struct to place configuration data into
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveInterrupt ( mcp2221_t device,
mcp2221_int_trig_t  trig 
)

Save the interrupt trigger mode to flash.

Parameters
[device]Device to operate on
[trig]Trigger mode
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveManufacturer ( mcp2221_t device,
wchar_t *  buffer 
)

Save new manufacturer USB descriptor string to flash (max 30 characters)

Parameters
[device]Device to operate on
[buffer]The wide string buffer to read from
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveMilliamps ( mcp2221_t device,
int  milliamps 
)

Set USB current limit.

Parameters
[device]Device to operate on
[milliamps]2 - 500
Returns
mcp2221_error error code
mcp2221_error mcp2221_savePolarity ( mcp2221_t device,
mcp2221_dedipin_t  pin,
int  polarity 
)

Save polarity of dedicated pin functions to flash.

Parameters
[device]Device to operate on
[pin]Which dedicated pin
[polarity]0 = Default off, 1 = Default on
Returns
mcp2221_error error code
mcp2221_error mcp2221_savePowerSource ( mcp2221_t device,
mcp2221_pwrsrc_t  source 
)

Set power source.

Parameters
[device]Device to operate on
[source]Power source
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveProduct ( mcp2221_t device,
wchar_t *  buffer 
)

Save new product USB descriptor string to flash (max 30 characters)

Parameters
[device]Device to operate on
[buffer]The wide string buffer to read from
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveRemoteWakeup ( mcp2221_t device,
mcp2221_wakeup_t  wakeup 
)

Enable/disable remote host wakeup.

Parameters
[device]Device to operate on
[wakeup]Enable/disable
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveSerial ( mcp2221_t device,
wchar_t *  buffer 
)

Save new serial USB descriptor string to flash (max 30 characters)

Parameters
[device]Device to operate on
[buffer]The wide string buffer to read from
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveSerialEnumerate ( mcp2221_t device,
int  enumerate 
)

Enable/disable enumerating with serial number.

Parameters
[device]Device to operate on
[enumerate]1 = Enable, 0 = Disable
Returns
mcp2221_error error code
mcp2221_error mcp2221_saveVIDPID ( mcp2221_t device,
int  vid,
int  pid 
)

Save new VID and PID to flash.

Parameters
[device]Device to operate on
[vid]New VID
[pid]New PID
Returns
mcp2221_error error code
mcp2221_error mcp2221_setADC ( mcp2221_t device,
mcp2221_adc_ref_t  ref 
)

Set the ADC voltage reference (SRAM)

Parameters
[device]Device to operate on
[ref]Voltage reference
Returns
mcp2221_error error code
mcp2221_error mcp2221_setClockOut ( mcp2221_t device,
mcp2221_clkdiv_t  div,
mcp2221_clkduty_t  duty 
)

Set the clock reference output divider and duty cycle (SRAM)

Parameters
[device]Device to operate on
[div]Frequency divider from 48MHz
[duty]Duty cycle
Returns
mcp2221_error error code
mcp2221_error mcp2221_setDAC ( mcp2221_t device,
mcp2221_dac_ref_t  ref,
int  value 
)

Set the DAC voltage reference and output value (SRAM)

Parameters
[device]Device to operate on
[ref]Voltage reference
[value]Output value (0 - 31)
Returns
mcp2221_error error code
mcp2221_error mcp2221_setGPIO ( mcp2221_t device,
mcp2221_gpio_t  pins,
mcp2221_gpio_value_t  value 
)

Set GPIO pin output values.

Parameters
[device]Device to operate on
[pins]Which GPIO pins should the new value be applied to
[value]The new value
Returns
mcp2221_error error code
mcp2221_error mcp2221_setGPIOConf ( mcp2221_t device,
mcp2221_gpioconfset_t confSet 
)

Apply GPIO configuration.

Parameters
[device]Device to operate on
[confSet]Pointer to mcp2221_gpioconfset_t struct
Returns
mcp2221_error error code
mcp2221_error mcp2221_setInterrupt ( mcp2221_t device,
mcp2221_int_trig_t  trig,
int  clearInt 
)

Set the interrupt trigger mode and optionally clear pending interrupt (SRAM)

Parameters
[device]Device to operate on
[trig]Trigger mode
[clearInt]Clear pending interrupt (0 = Don't clear, 1 = Clear)
Returns
mcp2221_error error code