//This program is dedicated to creating a communication between a PC and a Terasic DE1-SoC (Altera). //The link between the two entities is a mini-USB //The library that we use is libusb whose version is 1.0 #include #include #include #include #include "./include/libusb-1.0/libusb.h" typedef struct libusb_device libusb_device; typedef struct libusb_device_descriptor libusb_device_descriptor; typedef struct libusb_device_handle libusb_device_handle; typedef struct libusb_config_descriptor libusb_config_descriptor; libusb_device ** list = NULL; libusb_device * myDevice = NULL; libusb_device_descriptor desc; libusb_device_handle * handle = NULL; libusb_config_descriptor * confDesc = NULL; int main(void) { //Initialization if (libusb_init(NULL) == 0) printf("Initialization : success\n"); else printf("Initialization : failed\n"); //Retrieves plugged USB devices in a data structure int cnt = libusb_get_device_list(NULL, &list); printf("%d found devices\n",cnt); //Looks for the one we're interested in int i = 0; bool done = false; while (i < cnt && done == false) { if (libusb_get_device_descriptor (list[i], &desc) != 0) printf("Descriptor : Failed"); printf("Product ID : %d Vendor ID : %d\n",desc.idProduct,desc.idVendor); if((desc.idProduct == 0x6001 && desc.idVendor == 0x0403) == true) done = true; i++; } if (done == true) { i--; printf("Device found\n"); printf("Port : %d\n",libusb_get_port_number (list[i])); myDevice = list[i]; } else printf("Device not found\n"); //Places a handle on a given device int handleReturn = -1; if (done == true) handleReturn = libusb_open(myDevice,&handle); if (handleReturn == 0) printf("Handle : success\n"); else printf("Handle : failed Error code : %d\n",handleReturn); //Frees the list of devices and unereferences the devices for(i=0; i