Skip to content

Instantly share code, notes, and snippets.

@balazsgrill
Created September 20, 2012 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save balazsgrill/3754350 to your computer and use it in GitHub Desktop.
Save balazsgrill/3754350 to your computer and use it in GitHub Desktop.
MCP2200 user-mode driver getting started
#include <stdio.h>
#include <sys/types.h>
#include <mcp2200.h>
int main(int argc, char** argv){
//Init MCP2200 library
int r = mcp2200_init();
if (r < 0)
return r;
//Count currently connected devices.
int cnt = mcp2200_list_devices(MCP2200_VENDOR_ID, MCP2200_PRODUCT_ID);
if (cnt < 0) return cnt;
if (cnt == 0){
printf("No device found!");
return 0;
}
if (cnt == 1){
//Connect to the only available device
//The address of the device denotes the USB bus/port to which the device is connected
int address = mcp2200_get_address(0);
printf("Opening at address 0x%x\n", address);
int connectionID = mcp2200_connect(0);
if (connectionID < 0){
printf("Connection failed! Error code: %d\n", connectionID);
return 0;
}
//Configure device
r = mcp2200_hid_configure(connectionID, 0, 0, 0, 0, 1000);
if (r != 0){
printf("Configure error: %d\n", r);
}
//Read full contents of the EEPROM
for(i=0;i<=255;i++){
uint8_t data;
r = mcp2200_hid_read_ee(connectionID, address, &data);
if (r != 0){
printf("read error of %d: %d\n",i, r);
}else{
printf("%d: %d\n",i,data);
}
}
//Set GPIO output values
printf("Set\n");
mcp2200_hid_set_clear_output(connectionID, 0xFFu, 0u);
sleep(1);
printf("Clear\n");
mcp2200_hid_set_clear_output(connectionID, 0u, 0xFFu);
sleep(1);
}else{
printf("Multiple devices, couldn't choose..");
}
//Dispose driver before quitting
mcp2200_close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment